hyperprop-charting-library 0.1.72 → 0.1.73

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -21,9 +21,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
23
  FIB_DEFAULT_PALETTE: () => FIB_DEFAULT_PALETTE,
24
+ POSITION_DEFAULT_COLORS: () => POSITION_DEFAULT_COLORS,
24
25
  createChart: () => createChart
25
26
  });
26
27
  module.exports = __toCommonJS(index_exports);
28
+ var POSITION_DEFAULT_COLORS = ["#26a69a", "#ef5350", "#ffffff"];
27
29
  var FIB_DEFAULT_PALETTE = [
28
30
  "#787b86",
29
31
  "#f23645",
@@ -2405,10 +2407,14 @@ function createChart(element, options = {}) {
2405
2407
  const entryY = yFromPrice(entry.price);
2406
2408
  const targetY = yFromPrice(target.price);
2407
2409
  const stopY = yFromPrice(stop.price);
2408
- const profitFill = "rgba(38,166,154,0.16)";
2409
- const lossFill = "rgba(239,83,80,0.16)";
2410
- const profitLine = "rgba(38,166,154,0.9)";
2411
- const lossLine = "rgba(239,83,80,0.9)";
2410
+ const isHex6 = (value) => !!value && /^#[0-9a-fA-F]{6}$/.test(value);
2411
+ const profitColor = isHex6(drawing.colors[0]) ? drawing.colors[0] : "#26a69a";
2412
+ const lossColor = isHex6(drawing.colors[1]) ? drawing.colors[1] : "#ef5350";
2413
+ const labelTextColor = isHex6(drawing.colors[2]) ? drawing.colors[2] : "#ffffff";
2414
+ const profitFill = hexToRgba(profitColor, 0.16);
2415
+ const lossFill = hexToRgba(lossColor, 0.16);
2416
+ const profitLine = profitColor;
2417
+ const lossLine = lossColor;
2412
2418
  ctx.save();
2413
2419
  ctx.globalAlpha = draft ? 0.6 : 1;
2414
2420
  ctx.fillStyle = profitFill;
@@ -2460,7 +2466,7 @@ function createChart(element, options = {}) {
2460
2466
  const pillY = centerY - pillH / 2;
2461
2467
  ctx.fillStyle = bg;
2462
2468
  fillRoundedRect(pillX, pillY, pillW, pillH, 4);
2463
- ctx.fillStyle = "#ffffff";
2469
+ ctx.fillStyle = labelTextColor;
2464
2470
  ctx.textAlign = "center";
2465
2471
  ctx.textBaseline = "middle";
2466
2472
  ctx.fillText(text, centerX, pillY + pillH / 2);
@@ -3909,7 +3915,8 @@ function createChart(element, options = {}) {
3909
3915
  normalizeDrawingPoint(point.index, stopPrice),
3910
3916
  normalizeDrawingPoint(point.index + width2, entryPrice)
3911
3917
  ],
3912
- color: defaults.color ?? "#2563eb",
3918
+ color: defaults.color ?? (isLong ? "#26a69a" : "#ef5350"),
3919
+ colors: defaults.colors ?? POSITION_DEFAULT_COLORS,
3913
3920
  style: defaults.style ?? "solid",
3914
3921
  width: defaults.width ?? 1
3915
3922
  })
@@ -4858,5 +4865,6 @@ function createChart(element, options = {}) {
4858
4865
  // Annotate the CommonJS export names for ESM import in node:
4859
4866
  0 && (module.exports = {
4860
4867
  FIB_DEFAULT_PALETTE,
4868
+ POSITION_DEFAULT_COLORS,
4861
4869
  createChart
4862
4870
  });
@@ -67,6 +67,8 @@ interface DrawingObjectOptions {
67
67
  label?: string;
68
68
  locked?: boolean;
69
69
  }
70
+ /** Default colors for position tools: [profit, loss, label text]. */
71
+ declare const POSITION_DEFAULT_COLORS: string[];
70
72
  /** Default multi-color palette for fib-retracement levels. */
71
73
  declare const FIB_DEFAULT_PALETTE: string[];
72
74
  interface DrawingSelectEvent {
@@ -455,4 +457,4 @@ interface ViewportState {
455
457
  }
456
458
  declare function createChart(element: HTMLElement, options?: ChartOptions): ChartInstance;
457
459
 
458
- export { type AxisOptions, type BuiltInIndicatorInfo, type ChartClickEvent, type ChartInstance, type ChartOptions, type CrosshairMoveEvent, type CrosshairOptions, type CrosshairPriceActionEvent, type DashPatternOptions, type DrawingDefaults, type DrawingHoverEvent, type DrawingObjectOptions, type DrawingPoint, type DrawingSelectEvent, type DrawingToolType, FIB_DEFAULT_PALETTE, type GridOptions, type IndicatorInstanceOptions, type IndicatorPane, type IndicatorPaneAxisOptions, type IndicatorPaneGuideLine, type IndicatorPaneRenderInfo, type IndicatorPaneValue, type IndicatorPaneValueLabel, type IndicatorPlugin, type IndicatorRenderContext, type LabelsOptions, type OhlcDataPoint, type OrderActionButton, type OrderActionEvent, type OrderLineOptions, type PriceLineOptions, type TickerLineOptions, type ViewportState, type WatermarkOptions, createChart };
460
+ export { type AxisOptions, type BuiltInIndicatorInfo, type ChartClickEvent, type ChartInstance, type ChartOptions, type CrosshairMoveEvent, type CrosshairOptions, type CrosshairPriceActionEvent, type DashPatternOptions, type DrawingDefaults, type DrawingHoverEvent, type DrawingObjectOptions, type DrawingPoint, type DrawingSelectEvent, type DrawingToolType, FIB_DEFAULT_PALETTE, type GridOptions, type IndicatorInstanceOptions, type IndicatorPane, type IndicatorPaneAxisOptions, type IndicatorPaneGuideLine, type IndicatorPaneRenderInfo, type IndicatorPaneValue, type IndicatorPaneValueLabel, type IndicatorPlugin, type IndicatorRenderContext, type LabelsOptions, type OhlcDataPoint, type OrderActionButton, type OrderActionEvent, type OrderLineOptions, POSITION_DEFAULT_COLORS, type PriceLineOptions, type TickerLineOptions, type ViewportState, type WatermarkOptions, createChart };
@@ -1,4 +1,5 @@
1
1
  // src/index.ts
2
+ var POSITION_DEFAULT_COLORS = ["#26a69a", "#ef5350", "#ffffff"];
2
3
  var FIB_DEFAULT_PALETTE = [
3
4
  "#787b86",
4
5
  "#f23645",
@@ -2380,10 +2381,14 @@ function createChart(element, options = {}) {
2380
2381
  const entryY = yFromPrice(entry.price);
2381
2382
  const targetY = yFromPrice(target.price);
2382
2383
  const stopY = yFromPrice(stop.price);
2383
- const profitFill = "rgba(38,166,154,0.16)";
2384
- const lossFill = "rgba(239,83,80,0.16)";
2385
- const profitLine = "rgba(38,166,154,0.9)";
2386
- const lossLine = "rgba(239,83,80,0.9)";
2384
+ const isHex6 = (value) => !!value && /^#[0-9a-fA-F]{6}$/.test(value);
2385
+ const profitColor = isHex6(drawing.colors[0]) ? drawing.colors[0] : "#26a69a";
2386
+ const lossColor = isHex6(drawing.colors[1]) ? drawing.colors[1] : "#ef5350";
2387
+ const labelTextColor = isHex6(drawing.colors[2]) ? drawing.colors[2] : "#ffffff";
2388
+ const profitFill = hexToRgba(profitColor, 0.16);
2389
+ const lossFill = hexToRgba(lossColor, 0.16);
2390
+ const profitLine = profitColor;
2391
+ const lossLine = lossColor;
2387
2392
  ctx.save();
2388
2393
  ctx.globalAlpha = draft ? 0.6 : 1;
2389
2394
  ctx.fillStyle = profitFill;
@@ -2435,7 +2440,7 @@ function createChart(element, options = {}) {
2435
2440
  const pillY = centerY - pillH / 2;
2436
2441
  ctx.fillStyle = bg;
2437
2442
  fillRoundedRect(pillX, pillY, pillW, pillH, 4);
2438
- ctx.fillStyle = "#ffffff";
2443
+ ctx.fillStyle = labelTextColor;
2439
2444
  ctx.textAlign = "center";
2440
2445
  ctx.textBaseline = "middle";
2441
2446
  ctx.fillText(text, centerX, pillY + pillH / 2);
@@ -3884,7 +3889,8 @@ function createChart(element, options = {}) {
3884
3889
  normalizeDrawingPoint(point.index, stopPrice),
3885
3890
  normalizeDrawingPoint(point.index + width2, entryPrice)
3886
3891
  ],
3887
- color: defaults.color ?? "#2563eb",
3892
+ color: defaults.color ?? (isLong ? "#26a69a" : "#ef5350"),
3893
+ colors: defaults.colors ?? POSITION_DEFAULT_COLORS,
3888
3894
  style: defaults.style ?? "solid",
3889
3895
  width: defaults.width ?? 1
3890
3896
  })
@@ -4832,5 +4838,6 @@ function createChart(element, options = {}) {
4832
4838
  }
4833
4839
  export {
4834
4840
  FIB_DEFAULT_PALETTE,
4841
+ POSITION_DEFAULT_COLORS,
4835
4842
  createChart
4836
4843
  };
package/dist/index.cjs CHANGED
@@ -21,9 +21,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
23
  FIB_DEFAULT_PALETTE: () => FIB_DEFAULT_PALETTE,
24
+ POSITION_DEFAULT_COLORS: () => POSITION_DEFAULT_COLORS,
24
25
  createChart: () => createChart
25
26
  });
26
27
  module.exports = __toCommonJS(index_exports);
28
+ var POSITION_DEFAULT_COLORS = ["#26a69a", "#ef5350", "#ffffff"];
27
29
  var FIB_DEFAULT_PALETTE = [
28
30
  "#787b86",
29
31
  "#f23645",
@@ -2405,10 +2407,14 @@ function createChart(element, options = {}) {
2405
2407
  const entryY = yFromPrice(entry.price);
2406
2408
  const targetY = yFromPrice(target.price);
2407
2409
  const stopY = yFromPrice(stop.price);
2408
- const profitFill = "rgba(38,166,154,0.16)";
2409
- const lossFill = "rgba(239,83,80,0.16)";
2410
- const profitLine = "rgba(38,166,154,0.9)";
2411
- const lossLine = "rgba(239,83,80,0.9)";
2410
+ const isHex6 = (value) => !!value && /^#[0-9a-fA-F]{6}$/.test(value);
2411
+ const profitColor = isHex6(drawing.colors[0]) ? drawing.colors[0] : "#26a69a";
2412
+ const lossColor = isHex6(drawing.colors[1]) ? drawing.colors[1] : "#ef5350";
2413
+ const labelTextColor = isHex6(drawing.colors[2]) ? drawing.colors[2] : "#ffffff";
2414
+ const profitFill = hexToRgba(profitColor, 0.16);
2415
+ const lossFill = hexToRgba(lossColor, 0.16);
2416
+ const profitLine = profitColor;
2417
+ const lossLine = lossColor;
2412
2418
  ctx.save();
2413
2419
  ctx.globalAlpha = draft ? 0.6 : 1;
2414
2420
  ctx.fillStyle = profitFill;
@@ -2460,7 +2466,7 @@ function createChart(element, options = {}) {
2460
2466
  const pillY = centerY - pillH / 2;
2461
2467
  ctx.fillStyle = bg;
2462
2468
  fillRoundedRect(pillX, pillY, pillW, pillH, 4);
2463
- ctx.fillStyle = "#ffffff";
2469
+ ctx.fillStyle = labelTextColor;
2464
2470
  ctx.textAlign = "center";
2465
2471
  ctx.textBaseline = "middle";
2466
2472
  ctx.fillText(text, centerX, pillY + pillH / 2);
@@ -3909,7 +3915,8 @@ function createChart(element, options = {}) {
3909
3915
  normalizeDrawingPoint(point.index, stopPrice),
3910
3916
  normalizeDrawingPoint(point.index + width2, entryPrice)
3911
3917
  ],
3912
- color: defaults.color ?? "#2563eb",
3918
+ color: defaults.color ?? (isLong ? "#26a69a" : "#ef5350"),
3919
+ colors: defaults.colors ?? POSITION_DEFAULT_COLORS,
3913
3920
  style: defaults.style ?? "solid",
3914
3921
  width: defaults.width ?? 1
3915
3922
  })
@@ -4858,5 +4865,6 @@ function createChart(element, options = {}) {
4858
4865
  // Annotate the CommonJS export names for ESM import in node:
4859
4866
  0 && (module.exports = {
4860
4867
  FIB_DEFAULT_PALETTE,
4868
+ POSITION_DEFAULT_COLORS,
4861
4869
  createChart
4862
4870
  });
package/dist/index.d.cts CHANGED
@@ -67,6 +67,8 @@ interface DrawingObjectOptions {
67
67
  label?: string;
68
68
  locked?: boolean;
69
69
  }
70
+ /** Default colors for position tools: [profit, loss, label text]. */
71
+ declare const POSITION_DEFAULT_COLORS: string[];
70
72
  /** Default multi-color palette for fib-retracement levels. */
71
73
  declare const FIB_DEFAULT_PALETTE: string[];
72
74
  interface DrawingSelectEvent {
@@ -455,4 +457,4 @@ interface ViewportState {
455
457
  }
456
458
  declare function createChart(element: HTMLElement, options?: ChartOptions): ChartInstance;
457
459
 
458
- export { type AxisOptions, type BuiltInIndicatorInfo, type ChartClickEvent, type ChartInstance, type ChartOptions, type CrosshairMoveEvent, type CrosshairOptions, type CrosshairPriceActionEvent, type DashPatternOptions, type DrawingDefaults, type DrawingHoverEvent, type DrawingObjectOptions, type DrawingPoint, type DrawingSelectEvent, type DrawingToolType, FIB_DEFAULT_PALETTE, type GridOptions, type IndicatorInstanceOptions, type IndicatorPane, type IndicatorPaneAxisOptions, type IndicatorPaneGuideLine, type IndicatorPaneRenderInfo, type IndicatorPaneValue, type IndicatorPaneValueLabel, type IndicatorPlugin, type IndicatorRenderContext, type LabelsOptions, type OhlcDataPoint, type OrderActionButton, type OrderActionEvent, type OrderLineOptions, type PriceLineOptions, type TickerLineOptions, type ViewportState, type WatermarkOptions, createChart };
460
+ export { type AxisOptions, type BuiltInIndicatorInfo, type ChartClickEvent, type ChartInstance, type ChartOptions, type CrosshairMoveEvent, type CrosshairOptions, type CrosshairPriceActionEvent, type DashPatternOptions, type DrawingDefaults, type DrawingHoverEvent, type DrawingObjectOptions, type DrawingPoint, type DrawingSelectEvent, type DrawingToolType, FIB_DEFAULT_PALETTE, type GridOptions, type IndicatorInstanceOptions, type IndicatorPane, type IndicatorPaneAxisOptions, type IndicatorPaneGuideLine, type IndicatorPaneRenderInfo, type IndicatorPaneValue, type IndicatorPaneValueLabel, type IndicatorPlugin, type IndicatorRenderContext, type LabelsOptions, type OhlcDataPoint, type OrderActionButton, type OrderActionEvent, type OrderLineOptions, POSITION_DEFAULT_COLORS, type PriceLineOptions, type TickerLineOptions, type ViewportState, type WatermarkOptions, createChart };
package/dist/index.d.ts CHANGED
@@ -67,6 +67,8 @@ interface DrawingObjectOptions {
67
67
  label?: string;
68
68
  locked?: boolean;
69
69
  }
70
+ /** Default colors for position tools: [profit, loss, label text]. */
71
+ declare const POSITION_DEFAULT_COLORS: string[];
70
72
  /** Default multi-color palette for fib-retracement levels. */
71
73
  declare const FIB_DEFAULT_PALETTE: string[];
72
74
  interface DrawingSelectEvent {
@@ -455,4 +457,4 @@ interface ViewportState {
455
457
  }
456
458
  declare function createChart(element: HTMLElement, options?: ChartOptions): ChartInstance;
457
459
 
458
- export { type AxisOptions, type BuiltInIndicatorInfo, type ChartClickEvent, type ChartInstance, type ChartOptions, type CrosshairMoveEvent, type CrosshairOptions, type CrosshairPriceActionEvent, type DashPatternOptions, type DrawingDefaults, type DrawingHoverEvent, type DrawingObjectOptions, type DrawingPoint, type DrawingSelectEvent, type DrawingToolType, FIB_DEFAULT_PALETTE, type GridOptions, type IndicatorInstanceOptions, type IndicatorPane, type IndicatorPaneAxisOptions, type IndicatorPaneGuideLine, type IndicatorPaneRenderInfo, type IndicatorPaneValue, type IndicatorPaneValueLabel, type IndicatorPlugin, type IndicatorRenderContext, type LabelsOptions, type OhlcDataPoint, type OrderActionButton, type OrderActionEvent, type OrderLineOptions, type PriceLineOptions, type TickerLineOptions, type ViewportState, type WatermarkOptions, createChart };
460
+ export { type AxisOptions, type BuiltInIndicatorInfo, type ChartClickEvent, type ChartInstance, type ChartOptions, type CrosshairMoveEvent, type CrosshairOptions, type CrosshairPriceActionEvent, type DashPatternOptions, type DrawingDefaults, type DrawingHoverEvent, type DrawingObjectOptions, type DrawingPoint, type DrawingSelectEvent, type DrawingToolType, FIB_DEFAULT_PALETTE, type GridOptions, type IndicatorInstanceOptions, type IndicatorPane, type IndicatorPaneAxisOptions, type IndicatorPaneGuideLine, type IndicatorPaneRenderInfo, type IndicatorPaneValue, type IndicatorPaneValueLabel, type IndicatorPlugin, type IndicatorRenderContext, type LabelsOptions, type OhlcDataPoint, type OrderActionButton, type OrderActionEvent, type OrderLineOptions, POSITION_DEFAULT_COLORS, type PriceLineOptions, type TickerLineOptions, type ViewportState, type WatermarkOptions, createChart };
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  // src/index.ts
2
+ var POSITION_DEFAULT_COLORS = ["#26a69a", "#ef5350", "#ffffff"];
2
3
  var FIB_DEFAULT_PALETTE = [
3
4
  "#787b86",
4
5
  "#f23645",
@@ -2380,10 +2381,14 @@ function createChart(element, options = {}) {
2380
2381
  const entryY = yFromPrice(entry.price);
2381
2382
  const targetY = yFromPrice(target.price);
2382
2383
  const stopY = yFromPrice(stop.price);
2383
- const profitFill = "rgba(38,166,154,0.16)";
2384
- const lossFill = "rgba(239,83,80,0.16)";
2385
- const profitLine = "rgba(38,166,154,0.9)";
2386
- const lossLine = "rgba(239,83,80,0.9)";
2384
+ const isHex6 = (value) => !!value && /^#[0-9a-fA-F]{6}$/.test(value);
2385
+ const profitColor = isHex6(drawing.colors[0]) ? drawing.colors[0] : "#26a69a";
2386
+ const lossColor = isHex6(drawing.colors[1]) ? drawing.colors[1] : "#ef5350";
2387
+ const labelTextColor = isHex6(drawing.colors[2]) ? drawing.colors[2] : "#ffffff";
2388
+ const profitFill = hexToRgba(profitColor, 0.16);
2389
+ const lossFill = hexToRgba(lossColor, 0.16);
2390
+ const profitLine = profitColor;
2391
+ const lossLine = lossColor;
2387
2392
  ctx.save();
2388
2393
  ctx.globalAlpha = draft ? 0.6 : 1;
2389
2394
  ctx.fillStyle = profitFill;
@@ -2435,7 +2440,7 @@ function createChart(element, options = {}) {
2435
2440
  const pillY = centerY - pillH / 2;
2436
2441
  ctx.fillStyle = bg;
2437
2442
  fillRoundedRect(pillX, pillY, pillW, pillH, 4);
2438
- ctx.fillStyle = "#ffffff";
2443
+ ctx.fillStyle = labelTextColor;
2439
2444
  ctx.textAlign = "center";
2440
2445
  ctx.textBaseline = "middle";
2441
2446
  ctx.fillText(text, centerX, pillY + pillH / 2);
@@ -3884,7 +3889,8 @@ function createChart(element, options = {}) {
3884
3889
  normalizeDrawingPoint(point.index, stopPrice),
3885
3890
  normalizeDrawingPoint(point.index + width2, entryPrice)
3886
3891
  ],
3887
- color: defaults.color ?? "#2563eb",
3892
+ color: defaults.color ?? (isLong ? "#26a69a" : "#ef5350"),
3893
+ colors: defaults.colors ?? POSITION_DEFAULT_COLORS,
3888
3894
  style: defaults.style ?? "solid",
3889
3895
  width: defaults.width ?? 1
3890
3896
  })
@@ -4832,5 +4838,6 @@ function createChart(element, options = {}) {
4832
4838
  }
4833
4839
  export {
4834
4840
  FIB_DEFAULT_PALETTE,
4841
+ POSITION_DEFAULT_COLORS,
4835
4842
  createChart
4836
4843
  };
package/docs/API.md CHANGED
@@ -422,7 +422,7 @@ Drawings are user-created chart tools, separate from indicators. They are intera
422
422
  - `ray`: two-point line that extends infinitely past the second point
423
423
  - `fib-retracement`: two-point retracement with levels/bands
424
424
  - `fib-extension`: trend-based three-point extension (click trend start, trend end, then the projection origin); levels project from the third point by the first→second move
425
- - `long-position` / `short-position`: risk/reward forecasting box (single click drops a default box). Points are `[entry, target, stop, rightEdge]`; anchors are target/entry/stop on the left and a time-width handle on the right. Labels show price, % move, ticks, and risk/reward ratio.
425
+ - `long-position` / `short-position`: risk/reward forecasting box (single click drops a default box). Points are `[entry, target, stop, rightEdge]`; anchors are target/entry/stop on the left and a time-width handle on the right. Labels show price, % move, ticks, and risk/reward ratio. `color` sets the entry line; `colors` is `[profitColor, lossColor, labelTextColor]` (defaults `POSITION_DEFAULT_COLORS`).
426
426
  - `points: DrawingPoint[]`
427
427
  - `visible?: boolean`
428
428
  - `color?: string`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hyperprop-charting-library",
3
- "version": "0.1.72",
3
+ "version": "0.1.73",
4
4
  "description": "Lightweight TypeScript charting core",
5
5
  "type": "module",
6
6
  "main": "./dist/hyperprop-charting-library.cjs",