@forgecharts/sdk 1.1.23

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.
Files changed (101) hide show
  1. package/package.json +50 -0
  2. package/src/__tests__/backwardCompatibility.test.ts +191 -0
  3. package/src/__tests__/candleInvariant.test.ts +500 -0
  4. package/src/__tests__/public-api-surface.ts +76 -0
  5. package/src/__tests__/timeframeBoundary.test.ts +583 -0
  6. package/src/api/DrawingManager.ts +188 -0
  7. package/src/api/EventBus.ts +53 -0
  8. package/src/api/IndicatorDAG.ts +389 -0
  9. package/src/api/IndicatorRegistry.ts +47 -0
  10. package/src/api/LayoutManager.ts +72 -0
  11. package/src/api/PaneManager.ts +129 -0
  12. package/src/api/ReferenceAPI.ts +195 -0
  13. package/src/api/TChart.ts +881 -0
  14. package/src/api/createChart.ts +43 -0
  15. package/src/api/drawing tools/fib gann menu/fibRetracement.ts +27 -0
  16. package/src/api/drawing tools/lines menu/crossLine.ts +21 -0
  17. package/src/api/drawing tools/lines menu/disjointChannel.ts +74 -0
  18. package/src/api/drawing tools/lines menu/extendedLine.ts +22 -0
  19. package/src/api/drawing tools/lines menu/flatTopBottom.ts +45 -0
  20. package/src/api/drawing tools/lines menu/horizontal.ts +24 -0
  21. package/src/api/drawing tools/lines menu/horizontalRay.ts +25 -0
  22. package/src/api/drawing tools/lines menu/infoLine.ts +127 -0
  23. package/src/api/drawing tools/lines menu/insidePitchfork.ts +21 -0
  24. package/src/api/drawing tools/lines menu/modifiedSchiffPitchfork.ts +18 -0
  25. package/src/api/drawing tools/lines menu/parallelChannel.ts +47 -0
  26. package/src/api/drawing tools/lines menu/pitchfork.ts +15 -0
  27. package/src/api/drawing tools/lines menu/ray.ts +28 -0
  28. package/src/api/drawing tools/lines menu/regressionTrend.ts +157 -0
  29. package/src/api/drawing tools/lines menu/schiffPitchfork.ts +18 -0
  30. package/src/api/drawing tools/lines menu/trendAngle.ts +64 -0
  31. package/src/api/drawing tools/lines menu/trendline.ts +16 -0
  32. package/src/api/drawing tools/lines menu/vertical.ts +16 -0
  33. package/src/api/drawing tools/pointers menu/crosshair.ts +17 -0
  34. package/src/api/drawing tools/pointers menu/cursor.ts +16 -0
  35. package/src/api/drawing tools/pointers menu/demonstration.ts +35 -0
  36. package/src/api/drawing tools/pointers menu/dot.ts +26 -0
  37. package/src/api/drawing tools/shapes menu/rectangle.ts +24 -0
  38. package/src/api/drawing tools/shapes menu/text.ts +30 -0
  39. package/src/api/drawingUtils.ts +82 -0
  40. package/src/core/CanvasLayer.ts +77 -0
  41. package/src/core/Chart.ts +917 -0
  42. package/src/core/CoordTransform.ts +282 -0
  43. package/src/core/Crosshair.ts +207 -0
  44. package/src/core/IndicatorEngine.ts +216 -0
  45. package/src/core/InteractionManager.ts +899 -0
  46. package/src/core/PriceScale.ts +133 -0
  47. package/src/core/Series.ts +132 -0
  48. package/src/core/TimeScale.ts +175 -0
  49. package/src/datafeed/DatafeedConnector.ts +300 -0
  50. package/src/engine/CandleEngine.ts +458 -0
  51. package/src/engine/__tests__/CandleEngine.test.ts +402 -0
  52. package/src/engine/candleInvariants.ts +172 -0
  53. package/src/engine/mergeUtils.ts +93 -0
  54. package/src/engine/timeframeUtils.ts +118 -0
  55. package/src/index.ts +190 -0
  56. package/src/internal.ts +41 -0
  57. package/src/licensing/ChartRuntimeResolver.ts +380 -0
  58. package/src/licensing/LicenseManager.ts +131 -0
  59. package/src/licensing/__tests__/ChartRuntimeResolver.test.ts +207 -0
  60. package/src/licensing/__tests__/LicenseManager.test.ts +180 -0
  61. package/src/licensing/licenseTypes.ts +19 -0
  62. package/src/pine/PineCompiler.ts +68 -0
  63. package/src/pine/diagnostics.ts +30 -0
  64. package/src/pine/index.ts +7 -0
  65. package/src/pine/pine-ast.ts +163 -0
  66. package/src/pine/pine-lexer.ts +265 -0
  67. package/src/pine/pine-parser.ts +439 -0
  68. package/src/pine/pine-transpiler.ts +301 -0
  69. package/src/pixi/LayerName.ts +35 -0
  70. package/src/pixi/PixiCandlestickRenderer.ts +125 -0
  71. package/src/pixi/PixiChart.ts +425 -0
  72. package/src/pixi/PixiCrosshairRenderer.ts +134 -0
  73. package/src/pixi/PixiDrawingRenderer.ts +121 -0
  74. package/src/pixi/PixiGridRenderer.ts +136 -0
  75. package/src/pixi/PixiLayerManager.ts +102 -0
  76. package/src/renderers/CandlestickRenderer.ts +130 -0
  77. package/src/renderers/HistogramRenderer.ts +63 -0
  78. package/src/renderers/LineRenderer.ts +77 -0
  79. package/src/theme/colors.ts +21 -0
  80. package/src/tools/barDivergenceCheck.ts +305 -0
  81. package/src/trading/TradingOverlayStore.ts +161 -0
  82. package/src/trading/UnmanagedIngestion.ts +156 -0
  83. package/src/trading/__tests__/ManagedTradingController.test.ts +338 -0
  84. package/src/trading/__tests__/TradingOverlayStore.test.ts +323 -0
  85. package/src/trading/__tests__/UnmanagedIngestion.test.ts +205 -0
  86. package/src/trading/managed/ManagedTradingController.ts +292 -0
  87. package/src/trading/managed/managedCapabilities.ts +98 -0
  88. package/src/trading/managed/managedTypes.ts +151 -0
  89. package/src/trading/tradingTypes.ts +135 -0
  90. package/src/tscript/TScriptIndicator.ts +54 -0
  91. package/src/tscript/ast.ts +105 -0
  92. package/src/tscript/lexer.ts +190 -0
  93. package/src/tscript/parser.ts +334 -0
  94. package/src/tscript/runtime.ts +525 -0
  95. package/src/tscript/series.ts +84 -0
  96. package/src/types/IChart.ts +56 -0
  97. package/src/types/IRenderer.ts +16 -0
  98. package/src/types/ISeries.ts +30 -0
  99. package/tsconfig.json +22 -0
  100. package/tsup.config.ts +15 -0
  101. package/vitest.config.ts +25 -0
@@ -0,0 +1,43 @@
1
+ import type { ChartConfig } from '@forgecharts/types';
2
+ import { TChart } from './TChart';
3
+
4
+ /**
5
+ * Creates a new ForgeCharts chart instance and mounts it into the provided container.
6
+ *
7
+ * This is the primary entry point for the ForgeCharts SDK. The returned `TChart`
8
+ * instance exposes the full public API — including data loading hooks, indicators,
9
+ * drawings, layout persistence, and the typed event bus.
10
+ *
11
+ * @param config - Chart configuration. `container` and `symbol` are required.
12
+ * @returns A fully initialised `TChart` instance.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * import { createChart } from '@forgecharts/sdk';
17
+ *
18
+ * const chart = createChart({
19
+ * container: document.getElementById('chart')!,
20
+ * symbol: 'BTCUSDT',
21
+ * interval: '5m',
22
+ * theme: 'dark',
23
+ * });
24
+ *
25
+ * chart.on('symbolChanged', ({ symbol }) => {
26
+ * document.title = symbol;
27
+ * });
28
+ *
29
+ * chart.addIndicator({ type: 'ema', params: { period: 20 }, overlay: true });
30
+ *
31
+ * const layout = chart.saveLayout();
32
+ * localStorage.setItem('layout', JSON.stringify(layout));
33
+ *
34
+ * // Later...
35
+ * chart.destroy();
36
+ * ```
37
+ */
38
+ export function createChart(config: ChartConfig): TChart {
39
+ if (!config.container) {
40
+ throw new Error('[ForgeCharts] createChart() requires a valid container element.');
41
+ }
42
+ return new TChart(config);
43
+ }
@@ -0,0 +1,27 @@
1
+ import type { Drawing } from '@forgecharts/types';
2
+ import type { CoordTransform } from '../../../core/CoordTransform';
3
+
4
+ export function renderFibRetracement(
5
+ ctx: CanvasRenderingContext2D,
6
+ d: Drawing,
7
+ t: CoordTransform,
8
+ ): void {
9
+ const p0 = d.points[0];
10
+ const p1 = d.points[1];
11
+ if (!p0 || !p1) return;
12
+ const priceHigh = Math.max(p0.price, p1.price);
13
+ const priceLow = Math.min(p0.price, p1.price);
14
+ const span = priceHigh - priceLow;
15
+ const x0 = Math.min(t.timeToX(p0.time), t.timeToX(p1.time));
16
+ const x1 = Math.max(t.timeToX(p0.time), t.timeToX(p1.time));
17
+ ctx.save();
18
+ for (const ratio of [0, 0.236, 0.382, 0.5, 0.618, 0.786, 1]) {
19
+ const ly = t.priceToY(priceLow + span * (1 - ratio));
20
+ ctx.globalAlpha = 0.6;
21
+ ctx.beginPath();
22
+ ctx.moveTo(x0, ly);
23
+ ctx.lineTo(x1, ly);
24
+ ctx.stroke();
25
+ }
26
+ ctx.restore();
27
+ }
@@ -0,0 +1,21 @@
1
+ import type { Drawing } from '@forgecharts/types';
2
+ import type { CoordTransform } from '../../../core/CoordTransform';
3
+
4
+ export function renderCrossLine(
5
+ ctx: CanvasRenderingContext2D,
6
+ d: Drawing,
7
+ t: CoordTransform,
8
+ ): void {
9
+ const p0 = d.points[0];
10
+ if (!p0) return;
11
+ const x = t.timeToX(p0.time);
12
+ const y = t.priceToY(p0.price);
13
+ ctx.beginPath();
14
+ ctx.moveTo(0, y);
15
+ ctx.lineTo(t.plotWidth, y);
16
+ ctx.stroke();
17
+ ctx.beginPath();
18
+ ctx.moveTo(x, 0);
19
+ ctx.lineTo(x, t.plotHeight);
20
+ ctx.stroke();
21
+ }
@@ -0,0 +1,74 @@
1
+ import type { Drawing } from '@forgecharts/types';
2
+ import type { CoordTransform } from '../../../core/CoordTransform';
3
+
4
+ // ─── Renderer ─────────────────────────────────────────────────────────────────
5
+
6
+ /**
7
+ * Disjoint Channel — two fully independent trend lines forming a channel.
8
+ *
9
+ * Anchors (4 points):
10
+ * p0 — left endpoint of line 1 (top-left)
11
+ * p1 — right endpoint of line 1 (top-right)
12
+ * p2 — left endpoint of line 2 (bottom-left)
13
+ * p3 — right endpoint of line 2 (bottom-right)
14
+ *
15
+ * The tool places p2/p3 automatically when p0→p1 is drawn (offset downward).
16
+ * The user can then drag any of the 4 handles to reshape freely — including
17
+ * crossing the lines to create a bowtie / expanding wedge shape.
18
+ */
19
+ export function renderDisjointChannel(
20
+ ctx: CanvasRenderingContext2D,
21
+ d: Drawing,
22
+ t: CoordTransform,
23
+ ): void {
24
+ const p0 = d.points[0];
25
+ const p1 = d.points[1];
26
+ if (!p0 || !p1) return;
27
+
28
+ const x0 = t.timeToX(p0.time), y0 = t.priceToY(p0.price);
29
+ const x1 = t.timeToX(p1.time), y1 = t.priceToY(p1.price);
30
+
31
+ const p2 = d.points[2];
32
+ const p3 = d.points[3];
33
+
34
+ // During drawing (only 2 points placed yet) — show just the first segment
35
+ if (!p2 || !p3) {
36
+ ctx.beginPath();
37
+ ctx.moveTo(x0, y0);
38
+ ctx.lineTo(x1, y1);
39
+ ctx.stroke();
40
+ return;
41
+ }
42
+
43
+ const x2 = t.timeToX(p2.time), y2 = t.priceToY(p2.price);
44
+ const x3 = t.timeToX(p3.time), y3 = t.priceToY(p3.price);
45
+
46
+ const color = d.color ?? '#2196f3';
47
+ ctx.strokeStyle = color;
48
+
49
+ // Fill the quadrilateral first (behind the lines)
50
+ ctx.save();
51
+ ctx.globalAlpha = 0.07;
52
+ ctx.fillStyle = color;
53
+ ctx.beginPath();
54
+ ctx.moveTo(x0, y0);
55
+ ctx.lineTo(x1, y1);
56
+ ctx.lineTo(x3, y3);
57
+ ctx.lineTo(x2, y2);
58
+ ctx.closePath();
59
+ ctx.fill();
60
+ ctx.restore();
61
+
62
+ // Line 1: p0 → p1
63
+ ctx.beginPath();
64
+ ctx.moveTo(x0, y0);
65
+ ctx.lineTo(x1, y1);
66
+ ctx.stroke();
67
+
68
+ // Line 2: p2 → p3
69
+ ctx.beginPath();
70
+ ctx.moveTo(x2, y2);
71
+ ctx.lineTo(x3, y3);
72
+ ctx.stroke();
73
+ }
74
+
@@ -0,0 +1,22 @@
1
+ import type { Drawing } from '@forgecharts/types';
2
+ import type { CoordTransform } from '../../../core/CoordTransform';
3
+ import { rayExit } from '../../drawingUtils';
4
+
5
+ export function renderExtendedLine(
6
+ ctx: CanvasRenderingContext2D,
7
+ d: Drawing,
8
+ t: CoordTransform,
9
+ ): void {
10
+ const p0 = d.points[0];
11
+ const p1 = d.points[1];
12
+ if (!p0 || !p1) return;
13
+ const x0 = t.timeToX(p0.time), y0 = t.priceToY(p0.price);
14
+ const x1 = t.timeToX(p1.time), y1 = t.priceToY(p1.price);
15
+ const dx = x1 - x0, dy = y1 - y0;
16
+ const exitFwd = rayExit(t.plotWidth, t.plotHeight, x1, y1, dx, dy);
17
+ const exitBack = rayExit(t.plotWidth, t.plotHeight, x0, y0, -dx, -dy);
18
+ ctx.beginPath();
19
+ ctx.moveTo(exitBack.x, exitBack.y);
20
+ ctx.lineTo(exitFwd.x, exitFwd.y);
21
+ ctx.stroke();
22
+ }
@@ -0,0 +1,45 @@
1
+ import type { Drawing } from '@forgecharts/types';
2
+ import type { CoordTransform } from '../../../core/CoordTransform';
3
+
4
+ export function renderFlatTopBottom(
5
+ ctx: CanvasRenderingContext2D,
6
+ d: Drawing,
7
+ t: CoordTransform,
8
+ ): void {
9
+ const p0 = d.points[0];
10
+ const p1 = d.points[1];
11
+ if (!p0 || !p1) return;
12
+ const x0 = t.timeToX(p0.time), y0 = t.priceToY(p0.price);
13
+ const x1 = t.timeToX(p1.time), y1 = t.priceToY(p1.price);
14
+ ctx.beginPath();
15
+ ctx.moveTo(x0, y0);
16
+ ctx.lineTo(x1, y1);
17
+ ctx.stroke();
18
+ const p2 = d.points[2];
19
+ if (!p2) return;
20
+ const yFlat = t.priceToY(p2.price);
21
+ ctx.beginPath();
22
+ ctx.moveTo(x0, yFlat);
23
+ ctx.lineTo(x1, yFlat);
24
+ ctx.stroke();
25
+ ctx.save();
26
+ ctx.globalAlpha = 0.35;
27
+ ctx.beginPath();
28
+ ctx.moveTo(x0, y0);
29
+ ctx.lineTo(x0, yFlat);
30
+ ctx.stroke();
31
+ ctx.beginPath();
32
+ ctx.moveTo(x1, y1);
33
+ ctx.lineTo(x1, yFlat);
34
+ ctx.stroke();
35
+ ctx.globalAlpha = 0.07;
36
+ ctx.fillStyle = d.color ?? '#2196f3';
37
+ ctx.beginPath();
38
+ ctx.moveTo(x0, y0);
39
+ ctx.lineTo(x1, y1);
40
+ ctx.lineTo(x1, yFlat);
41
+ ctx.lineTo(x0, yFlat);
42
+ ctx.closePath();
43
+ ctx.fill();
44
+ ctx.restore();
45
+ }
@@ -0,0 +1,24 @@
1
+ import type { Drawing } from '@forgecharts/types';
2
+ import type { CoordTransform } from '../../../core/CoordTransform';
3
+
4
+ export function renderHorizontal(
5
+ ctx: CanvasRenderingContext2D,
6
+ d: Drawing,
7
+ t: CoordTransform,
8
+ ): void {
9
+ const p0 = d.points[0];
10
+ if (!p0) return;
11
+ const y = t.priceToY(p0.price);
12
+ ctx.beginPath();
13
+ ctx.moveTo(0, y);
14
+ ctx.lineTo(t.plotWidth, y);
15
+ ctx.stroke();
16
+ // Price label
17
+ ctx.save();
18
+ ctx.font = '10px -apple-system, sans-serif';
19
+ ctx.fillStyle = d.color ?? '#2196f3';
20
+ ctx.textAlign = 'left';
21
+ ctx.textBaseline = 'middle';
22
+ ctx.fillText(p0.price.toFixed(2), t.plotWidth + 4, y);
23
+ ctx.restore();
24
+ }
@@ -0,0 +1,25 @@
1
+ import type { Drawing } from '@forgecharts/types';
2
+ import type { CoordTransform } from '../../../core/CoordTransform';
3
+
4
+ export function renderHorizontalRay(
5
+ ctx: CanvasRenderingContext2D,
6
+ d: Drawing,
7
+ t: CoordTransform,
8
+ ): void {
9
+ const p0 = d.points[0];
10
+ if (!p0) return;
11
+ const x0 = t.timeToX(p0.time);
12
+ const y = t.priceToY(p0.price);
13
+ ctx.beginPath();
14
+ ctx.moveTo(x0, y);
15
+ ctx.lineTo(t.plotWidth, y);
16
+ ctx.stroke();
17
+ // Price label
18
+ ctx.save();
19
+ ctx.font = '10px -apple-system, sans-serif';
20
+ ctx.fillStyle = d.color ?? '#2196f3';
21
+ ctx.textAlign = 'left';
22
+ ctx.textBaseline = 'middle';
23
+ ctx.fillText(p0.price.toFixed(2), t.plotWidth + 4, y);
24
+ ctx.restore();
25
+ }
@@ -0,0 +1,127 @@
1
+ import type { Drawing } from '@forgecharts/types';
2
+ import type { CoordTransform } from '../../../core/CoordTransform';
3
+ import { TF_SECS, formatDuration } from '../../drawingUtils';
4
+
5
+ export function renderInfoLine(
6
+ ctx: CanvasRenderingContext2D,
7
+ d: Drawing,
8
+ t: CoordTransform,
9
+ interval = '1h',
10
+ ): void {
11
+ const p0 = d.points[0];
12
+ const p1 = d.points[1];
13
+ if (!p0 || !p1) return;
14
+
15
+ const x0 = t.timeToX(p0.time), y0 = t.priceToY(p0.price);
16
+ const x1 = t.timeToX(p1.time), y1 = t.priceToY(p1.price);
17
+ const dx = x1 - x0;
18
+ const dy = y1 - y0;
19
+ const len = Math.sqrt(dx * dx + dy * dy) || 1;
20
+ const ux = dx / len;
21
+ const uy = dy / len;
22
+
23
+ const color = d.color ?? '#2196f3';
24
+ ctx.strokeStyle = color;
25
+ ctx.fillStyle = color;
26
+
27
+ // ── Line segment from p0 to p1 ────────────────────────────────────────────
28
+ ctx.beginPath();
29
+ ctx.moveTo(x0, y0);
30
+ ctx.lineTo(x1, y1);
31
+ ctx.stroke();
32
+
33
+ // ── Stats banner ─────────────────────────────────────────────────────────
34
+ const priceDiff = p1.price - p0.price;
35
+ const pctChange = p0.price !== 0 ? (priceDiff / p0.price) * 100 : 0;
36
+ const timeDiff = Math.abs(p1.time - p0.time);
37
+ const tfSecs = TF_SECS[interval] ?? 3600;
38
+ const bars = Math.round(timeDiff / tfSecs);
39
+ const duration = formatDuration(timeDiff);
40
+ const pixDist = Math.round(len);
41
+ const angleRad = Math.atan2(-(y1 - y0), x1 - x0);
42
+ const angleDeg = (angleRad * 180 / Math.PI).toFixed(2);
43
+ const sign = priceDiff >= 0 ? '+' : '';
44
+ const decimals = p0.price < 1 ? 6 : 2;
45
+ const priceStr = `${sign}${priceDiff.toFixed(decimals)} (${sign}${pctChange.toFixed(2)}%)`;
46
+ const barsStr = `\u2194 ${bars} bars (${duration}), distance: ${pixDist} px`;
47
+ const angleStr = `\u25b3 ${angleDeg}\u00b0`;
48
+ const labels = [priceStr, barsStr, angleStr];
49
+ const icons = ['\u21d5', '', ''];
50
+
51
+ const PAD_X = 8;
52
+ const PAD_Y = 6;
53
+ const LINE_H = 16;
54
+ const BANNER_W = 240;
55
+ const BANNER_H = PAD_Y * 2 + labels.length * LINE_H;
56
+
57
+ // Place banner perpendicular to the line, offset from the midpoint
58
+ const midX = (x0 + x1) / 2;
59
+ const midY = (y0 + y1) / 2;
60
+ // Perpendicular unit vector (rotated 90° counter-clockwise)
61
+ const px = -uy;
62
+ const py = ux;
63
+ const OFFSET = BANNER_H / 2 + 12; // enough to clear the line
64
+
65
+ // Try offset in the "up" perpendicular direction first
66
+ let bx = midX + px * OFFSET - BANNER_W / 2;
67
+ let by = midY + py * OFFSET - BANNER_H / 2;
68
+
69
+ // If that clips vertically, flip to the other side
70
+ if (by < 2 || by + BANNER_H > t.plotHeight - 2) {
71
+ bx = midX - px * OFFSET - BANNER_W / 2;
72
+ by = midY - py * OFFSET - BANNER_H / 2;
73
+ }
74
+
75
+ // Clamp to plot area
76
+ bx = Math.max(2, Math.min(bx, t.plotWidth - BANNER_W - 2));
77
+ by = Math.max(2, Math.min(by, t.plotHeight - BANNER_H - 2));
78
+
79
+ ctx.save();
80
+
81
+ const hex = color.replace('#', '');
82
+ const r = parseInt(hex.slice(0, 2), 16);
83
+ const g = parseInt(hex.slice(2, 4), 16);
84
+ const b = parseInt(hex.slice(4, 6), 16);
85
+
86
+ // Background
87
+ ctx.fillStyle = `rgba(${r},${g},${b},0.12)`;
88
+ ctx.beginPath();
89
+ const radius = 4;
90
+ ctx.moveTo(bx + radius, by);
91
+ ctx.lineTo(bx + BANNER_W - radius, by);
92
+ ctx.arcTo(bx + BANNER_W, by, bx + BANNER_W, by + radius, radius);
93
+ ctx.lineTo(bx + BANNER_W, by + BANNER_H - radius);
94
+ ctx.arcTo(bx + BANNER_W, by + BANNER_H, bx + BANNER_W - radius, by + BANNER_H, radius);
95
+ ctx.lineTo(bx + radius, by + BANNER_H);
96
+ ctx.arcTo(bx, by + BANNER_H, bx, by + BANNER_H - radius, radius);
97
+ ctx.lineTo(bx, by + radius);
98
+ ctx.arcTo(bx, by, bx + radius, by, radius);
99
+ ctx.closePath();
100
+ ctx.fill();
101
+
102
+ // Border
103
+ ctx.strokeStyle = `rgba(${r},${g},${b},0.5)`;
104
+ ctx.lineWidth = 1;
105
+ ctx.setLineDash([]);
106
+ ctx.stroke();
107
+
108
+ // Text rows
109
+ const FONT = '11px -apple-system, BlinkMacSystemFont, sans-serif';
110
+ ctx.font = FONT;
111
+ ctx.textAlign = 'left';
112
+ ctx.textBaseline = 'top';
113
+ labels.forEach((line, i) => {
114
+ const ty = by + PAD_Y + i * LINE_H;
115
+ if (icons[i]) {
116
+ ctx.fillStyle = `rgba(${r},${g},${b},0.7)`;
117
+ ctx.fillText(icons[i], bx + PAD_X, ty + 1);
118
+ ctx.fillStyle = color;
119
+ ctx.fillText(line, bx + PAD_X + 14, ty + 1);
120
+ } else {
121
+ ctx.fillStyle = color;
122
+ ctx.fillText(line, bx + PAD_X, ty + 1);
123
+ }
124
+ });
125
+
126
+ ctx.restore();
127
+ }
@@ -0,0 +1,21 @@
1
+ import type { Drawing } from '@forgecharts/types';
2
+ import type { CoordTransform } from '../../../core/CoordTransform';
3
+ import { getPF3 } from '../../drawingUtils';
4
+ import { renderTrendline } from './trendline';
5
+
6
+ export function renderInsidePitchfork(
7
+ ctx: CanvasRenderingContext2D,
8
+ d: Drawing,
9
+ t: CoordTransform,
10
+ ): void {
11
+ const pf = getPF3(d, t);
12
+ if (!pf) { renderTrendline(ctx, d, t); return; }
13
+ const { x0, y0, x1, y1, x2, y2 } = pf;
14
+ const midX = (x1 + x2) / 2, midY = (y1 + y2) / 2;
15
+ ctx.beginPath(); ctx.moveTo(x0, y0); ctx.lineTo(midX, midY); ctx.stroke();
16
+ ctx.beginPath(); ctx.moveTo(x0, y0); ctx.lineTo(x1, y1); ctx.stroke();
17
+ ctx.beginPath(); ctx.moveTo(x0, y0); ctx.lineTo(x2, y2); ctx.stroke();
18
+ ctx.save(); ctx.globalAlpha = 0.4;
19
+ ctx.beginPath(); ctx.moveTo(x1, y1); ctx.lineTo(x2, y2); ctx.stroke();
20
+ ctx.restore();
21
+ }
@@ -0,0 +1,18 @@
1
+ import type { Drawing } from '@forgecharts/types';
2
+ import type { CoordTransform } from '../../../core/CoordTransform';
3
+ import { getPF3, drawPitchforkLines } from '../../drawingUtils';
4
+ import { renderTrendline } from './trendline';
5
+
6
+ export function renderModifiedSchiffPitchfork(
7
+ ctx: CanvasRenderingContext2D,
8
+ d: Drawing,
9
+ t: CoordTransform,
10
+ ): void {
11
+ const pf = getPF3(d, t);
12
+ if (!pf) { renderTrendline(ctx, d, t); return; }
13
+ const { x0, y0, x1, y1, x2, y2 } = pf;
14
+ const midX = (x1 + x2) / 2, midY = (y1 + y2) / 2;
15
+ const pivX = (x0 + x1) / 2;
16
+ const pivY = (y0 + y1) / 2;
17
+ drawPitchforkLines(ctx, t, pivX, pivY, midX, midY, x1, y1, x2, y2);
18
+ }
@@ -0,0 +1,47 @@
1
+ import type { Drawing } from '@forgecharts/types';
2
+ import type { CoordTransform } from '../../../core/CoordTransform';
3
+
4
+ export function renderParallelChannel(
5
+ ctx: CanvasRenderingContext2D,
6
+ d: Drawing,
7
+ t: CoordTransform,
8
+ ): void {
9
+ const p0 = d.points[0];
10
+ const p1 = d.points[1];
11
+ if (!p0 || !p1) return;
12
+ const x0 = t.timeToX(p0.time), y0 = t.priceToY(p0.price);
13
+ const x1 = t.timeToX(p1.time), y1 = t.priceToY(p1.price);
14
+ ctx.beginPath();
15
+ ctx.moveTo(x0, y0);
16
+ ctx.lineTo(x1, y1);
17
+ ctx.stroke();
18
+ const p2 = d.points[2];
19
+ if (!p2) return;
20
+ // Offset from y1 so dragging from p1 starts with zero width
21
+ const off = t.priceToY(p2.price) - y1;
22
+ // Parallel line
23
+ ctx.beginPath();
24
+ ctx.moveTo(x0, y0 + off);
25
+ ctx.lineTo(x1, y1 + off);
26
+ ctx.stroke();
27
+ // Midline (dashed)
28
+ ctx.save();
29
+ ctx.globalAlpha = 0.5;
30
+ ctx.setLineDash([4, 4]);
31
+ ctx.beginPath();
32
+ ctx.moveTo(x0, y0 + off / 2);
33
+ ctx.lineTo(x1, y1 + off / 2);
34
+ ctx.stroke();
35
+ ctx.setLineDash([]);
36
+ // Fill
37
+ ctx.globalAlpha = 0.07;
38
+ ctx.fillStyle = d.color ?? '#2196f3';
39
+ ctx.beginPath();
40
+ ctx.moveTo(x0, y0);
41
+ ctx.lineTo(x1, y1);
42
+ ctx.lineTo(x1, y1 + off);
43
+ ctx.lineTo(x0, y0 + off);
44
+ ctx.closePath();
45
+ ctx.fill();
46
+ ctx.restore();
47
+ }
@@ -0,0 +1,15 @@
1
+ import type { Drawing } from '@forgecharts/types';
2
+ import type { CoordTransform } from '../../../core/CoordTransform';
3
+ import { getPF3, drawPitchforkLines } from '../../drawingUtils';
4
+ import { renderTrendline } from './trendline';
5
+
6
+ export function renderPitchfork(
7
+ ctx: CanvasRenderingContext2D,
8
+ d: Drawing,
9
+ t: CoordTransform,
10
+ ): void {
11
+ const pf = getPF3(d, t);
12
+ if (!pf) { renderTrendline(ctx, d, t); return; }
13
+ const { x0, y0, x1, y1, x2, y2 } = pf;
14
+ drawPitchforkLines(ctx, t, x0, y0, (x1 + x2) / 2, (y1 + y2) / 2, x1, y1, x2, y2);
15
+ }
@@ -0,0 +1,28 @@
1
+ import type { Drawing } from '@forgecharts/types';
2
+ import type { CoordTransform } from '../../../core/CoordTransform';
3
+ import { rayExit } from '../../drawingUtils';
4
+
5
+ export function renderRay(
6
+ ctx: CanvasRenderingContext2D,
7
+ d: Drawing,
8
+ t: CoordTransform,
9
+ ): void {
10
+ const p0 = d.points[0];
11
+ const p1 = d.points[1];
12
+ if (!p0) return;
13
+ const x0 = t.timeToX(p0.time);
14
+ const y0 = t.priceToY(p0.price);
15
+ if (!p1) {
16
+ ctx.beginPath();
17
+ ctx.arc(x0, y0, 3, 0, Math.PI * 2);
18
+ ctx.fill();
19
+ return;
20
+ }
21
+ const dx = t.timeToX(p1.time) - x0;
22
+ const dy = t.priceToY(p1.price) - y0;
23
+ const exit = rayExit(t.plotWidth, t.plotHeight, x0, y0, dx, dy);
24
+ ctx.beginPath();
25
+ ctx.moveTo(x0, y0);
26
+ ctx.lineTo(exit.x, exit.y);
27
+ ctx.stroke();
28
+ }