@dwlf/charting 1.0.0 → 1.1.0

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 (50) hide show
  1. package/README.md +184 -19
  2. package/dist/charting/__tests__/chartSpec.test.d.ts +1 -0
  3. package/dist/charting/scales.d.ts +14 -0
  4. package/dist/charting/types.d.ts +454 -0
  5. package/dist/charting.css +1 -1
  6. package/dist/components/DWLFChart.d.ts +119 -0
  7. package/dist/components/index.d.ts +2 -0
  8. package/dist/components/overlays/AlertLineAnnotationView.d.ts +14 -0
  9. package/dist/components/overlays/AnnotationLayer.d.ts +55 -0
  10. package/dist/components/overlays/ArrowAnnotationView.d.ts +24 -0
  11. package/dist/components/overlays/BosLineAnnotationView.d.ts +22 -0
  12. package/dist/components/overlays/BrushAnnotationView.d.ts +20 -0
  13. package/dist/components/overlays/ChannelAnnotationView.d.ts +23 -0
  14. package/dist/components/overlays/CrossLineAnnotationView.d.ts +29 -0
  15. package/dist/components/overlays/DiagonalLineOverlay.d.ts +31 -0
  16. package/dist/components/overlays/EmojiAnnotationView.d.ts +22 -0
  17. package/dist/components/overlays/FairValueGapAnnotationView.d.ts +23 -0
  18. package/dist/components/overlays/FibExtensionAnnotationView.d.ts +19 -0
  19. package/dist/components/overlays/FibRetracementAnnotationView.d.ts +19 -0
  20. package/dist/components/overlays/HLineAnnotationView.d.ts +15 -0
  21. package/dist/components/overlays/HorizontalLineOverlay.d.ts +23 -0
  22. package/dist/components/overlays/MarkerOverlay.d.ts +66 -0
  23. package/dist/components/overlays/MeasureAnnotationView.d.ts +25 -0
  24. package/dist/components/overlays/MessageBubbleOverlay.d.ts +55 -0
  25. package/dist/components/overlays/OrderBlockAnnotationView.d.ts +23 -0
  26. package/dist/components/overlays/PitchforkAnnotationView.d.ts +19 -0
  27. package/dist/components/overlays/PositionOverlay.d.ts +52 -0
  28. package/dist/components/overlays/RayAnnotationView.d.ts +30 -0
  29. package/dist/components/overlays/RectangleAnnotationView.d.ts +23 -0
  30. package/dist/components/overlays/SMAOverlay.d.ts +20 -0
  31. package/dist/components/overlays/TextAnnotationView.d.ts +24 -0
  32. package/dist/components/overlays/TimeRangeAnnotationView.d.ts +22 -0
  33. package/dist/components/overlays/TrendLineAnnotationView.d.ts +23 -0
  34. package/dist/components/overlays/VLineAnnotationView.d.ts +26 -0
  35. package/dist/components/overlays/annotationConstants.d.ts +21 -0
  36. package/dist/components/overlays/annotationUtils.d.ts +13 -0
  37. package/dist/components/overlays/useAnnotationDrag.d.ts +18 -0
  38. package/dist/components/overlays/usePointAnnotationDrag.d.ts +23 -0
  39. package/dist/hooks/useCandlestickChart.d.ts +18 -0
  40. package/dist/hooks/useChartAnimations.d.ts +49 -0
  41. package/dist/hooks/useChartLayout.d.ts +12 -0
  42. package/dist/hooks/useChartPanZoom.d.ts +7 -0
  43. package/dist/hooks/useChartPanZoomVirtual.d.ts +24 -0
  44. package/dist/hooks/useContainerSize.d.ts +4 -0
  45. package/dist/hooks/useOverlayToggles.d.ts +19 -0
  46. package/dist/index.cjs +1 -1
  47. package/dist/index.d.ts +56 -0
  48. package/dist/index.js +13 -13
  49. package/dist/utils/indicators.d.ts +40 -0
  50. package/package.json +4 -1
@@ -0,0 +1,56 @@
1
+ export { default as DWLFChart } from './components/DWLFChart';
2
+ export type { DwlfChartHandle, DWLFChartProps, AxisColorConfig } from './components/DWLFChart';
3
+ export type { Candle, ChartSpec, LinePoint, OhlcPoint, PaneGuide, PaneSpec, SeriesSpec, SeriesType, SeriesStyle, TooltipFormatter, PaneComputedScale, AnnotationType, LineStyle, AnnotationBase, HLineAnnotation, VLineAnnotation, TextAnnotation, TrendLineAnnotation, RayAnnotation, CrossLineAnnotation, RectangleAnnotation, EmojiAnnotation, TimeRangeAnnotation, ArrowAnnotation, ChannelAnnotation, FibRetracementAnnotation, MeasureAnnotation, AlertLineAnnotation, BrushPoint, BrushAnnotation, PitchforkAnnotation, FibExtensionAnnotation, OrderBlockAnnotation, FairValueGapAnnotation, BosLineAnnotation, Annotation, } from './charting/types';
4
+ export { FIB_LEVELS_DEFAULT, FIB_EXTENSIONS_DEFAULT } from './charting/types';
5
+ export { default as useCandlestickChart } from './hooks/useCandlestickChart.js';
6
+ export { default as useChartLayout } from './hooks/useChartLayout.js';
7
+ export { default as useChartPanZoom } from './hooks/useChartPanZoom.js';
8
+ export { default as useChartPanZoomVirtual } from './hooks/useChartPanZoomVirtual.js';
9
+ export { default as useContainerSize } from './hooks/useContainerSize.js';
10
+ export { default as useOverlayToggles } from './hooks/useOverlayToggles.js';
11
+ export { default as useChartAnimations, INDICATOR_ANIMATION_ORDER } from './hooks/useChartAnimations';
12
+ export type { ChartAnimationPhase, ChartAnimationState, ChartAnimationControls, UseChartAnimationsOptions, } from './hooks/useChartAnimations';
13
+ export * from './utils/indicators.js';
14
+ export { default as AnnotationLayer } from './components/overlays/AnnotationLayer';
15
+ export { createHLineAnnotation, createVLineAnnotation, createTextAnnotation, createTrendLineAnnotation, createRayAnnotation, createCrossLineAnnotation, createRectangleAnnotation, createEmojiAnnotation, createTimeRangeAnnotation, createArrowAnnotation, createChannelAnnotation, createFibRetracementAnnotation, createMeasureAnnotation, createAlertLineAnnotation, createBrushAnnotation, createPitchforkAnnotation, createFibExtensionAnnotation, createOrderBlockAnnotation, createFairValueGapAnnotation, createBosLineAnnotation, ANNOTATION_COLORS, } from './components/overlays/AnnotationLayer';
16
+ export type { AnnotationLayerProps } from './components/overlays/AnnotationLayer';
17
+ export { default as HLineAnnotationView } from './components/overlays/HLineAnnotationView';
18
+ export type { HLineAnnotationViewProps } from './components/overlays/HLineAnnotationView';
19
+ export { default as VLineAnnotationView } from './components/overlays/VLineAnnotationView';
20
+ export type { VLineAnnotationViewProps } from './components/overlays/VLineAnnotationView';
21
+ export { default as TextAnnotationView } from './components/overlays/TextAnnotationView';
22
+ export type { TextAnnotationViewProps } from './components/overlays/TextAnnotationView';
23
+ export { default as TrendLineAnnotationView } from './components/overlays/TrendLineAnnotationView';
24
+ export type { TrendLineAnnotationViewProps } from './components/overlays/TrendLineAnnotationView';
25
+ export { default as RayAnnotationView } from './components/overlays/RayAnnotationView';
26
+ export type { RayAnnotationViewProps } from './components/overlays/RayAnnotationView';
27
+ export { default as CrossLineAnnotationView } from './components/overlays/CrossLineAnnotationView';
28
+ export type { CrossLineAnnotationViewProps } from './components/overlays/CrossLineAnnotationView';
29
+ export { default as RectangleAnnotationView } from './components/overlays/RectangleAnnotationView';
30
+ export type { RectangleAnnotationViewProps } from './components/overlays/RectangleAnnotationView';
31
+ export { default as EmojiAnnotationView } from './components/overlays/EmojiAnnotationView';
32
+ export type { EmojiAnnotationViewProps } from './components/overlays/EmojiAnnotationView';
33
+ export { default as TimeRangeAnnotationView } from './components/overlays/TimeRangeAnnotationView';
34
+ export type { TimeRangeAnnotationViewProps } from './components/overlays/TimeRangeAnnotationView';
35
+ export { default as ArrowAnnotationView } from './components/overlays/ArrowAnnotationView';
36
+ export type { ArrowAnnotationViewProps } from './components/overlays/ArrowAnnotationView';
37
+ export { default as ChannelAnnotationView } from './components/overlays/ChannelAnnotationView';
38
+ export type { ChannelAnnotationViewProps } from './components/overlays/ChannelAnnotationView';
39
+ export { default as FibRetracementAnnotationView } from './components/overlays/FibRetracementAnnotationView';
40
+ export type { FibRetracementAnnotationViewProps } from './components/overlays/FibRetracementAnnotationView';
41
+ export { default as MeasureAnnotationView } from './components/overlays/MeasureAnnotationView';
42
+ export type { MeasureAnnotationViewProps } from './components/overlays/MeasureAnnotationView';
43
+ export { default as AlertLineAnnotationView } from './components/overlays/AlertLineAnnotationView';
44
+ export type { AlertLineAnnotationViewProps } from './components/overlays/AlertLineAnnotationView';
45
+ export { default as BrushAnnotationView } from './components/overlays/BrushAnnotationView';
46
+ export type { BrushAnnotationViewProps } from './components/overlays/BrushAnnotationView';
47
+ export { default as PitchforkAnnotationView } from './components/overlays/PitchforkAnnotationView';
48
+ export type { PitchforkAnnotationViewProps } from './components/overlays/PitchforkAnnotationView';
49
+ export { default as FibExtensionAnnotationView } from './components/overlays/FibExtensionAnnotationView';
50
+ export type { FibExtensionAnnotationViewProps } from './components/overlays/FibExtensionAnnotationView';
51
+ export { default as OrderBlockAnnotationView } from './components/overlays/OrderBlockAnnotationView';
52
+ export type { OrderBlockAnnotationViewProps } from './components/overlays/OrderBlockAnnotationView';
53
+ export { default as FairValueGapAnnotationView } from './components/overlays/FairValueGapAnnotationView';
54
+ export type { FairValueGapAnnotationViewProps } from './components/overlays/FairValueGapAnnotationView';
55
+ export { default as BosLineAnnotationView } from './components/overlays/BosLineAnnotationView';
56
+ export type { BosLineAnnotationViewProps } from './components/overlays/BosLineAnnotationView';
package/dist/index.js CHANGED
@@ -5963,7 +5963,7 @@ const pi = {
5963
5963
  return !Number.isFinite(c) || c === 1 / 0 ? 6 : Math.max(4, Math.min(18, c * 0.5));
5964
5964
  }, Li = (e, t, r, c, n) => {
5965
5965
  var P;
5966
- const l = e.style ?? {}, s = l.lineWidth ?? 1.5, u = l.color ?? "#6b7280", i = l.opacity ?? 1, o = l.dashed ? "4 4" : void 0, m = n && n.phase !== "complete", a = ((P = n == null ? void 0 : n.layerOpacities) == null ? void 0 : P[e.key]) ?? (m ? 0 : 1), p = i * a;
5966
+ const l = e.style ?? {}, s = l.lineWidth ?? 1.5, u = l.color ?? e.color ?? "#6b7280", i = l.opacity ?? 1, o = l.dashed ? "4 4" : void 0, m = n && n.phase !== "complete", a = ((P = n == null ? void 0 : n.layerOpacities) == null ? void 0 : P[e.key]) ?? (m ? 0 : 1), p = i * a;
5967
5967
  if (e.type === "hist") {
5968
5968
  let D = 1 / 0;
5969
5969
  for (let M = 1; M < t.length; M += 1) {
@@ -5991,7 +5991,7 @@ const pi = {
5991
5991
  const l = n == null ? void 0 : n.phase;
5992
5992
  if (l && l !== "events" && l !== "annotations" && l !== "complete")
5993
5993
  return null;
5994
- const s = hr(t, c), u = ((M = e.style) == null ? void 0 : M.markerShape) ?? "circle", i = ((L = e.style) == null ? void 0 : L.markerSize) ?? 6, o = ((N = e.style) == null ? void 0 : N.color) ?? "#fbbf24", m = ((x = e.style) == null ? void 0 : x.markerOffsetY) ?? 0, a = ((f = e.style) == null ? void 0 : f.markerFontSize) ?? 10, p = ((Y = e.style) == null ? void 0 : Y.markerTextColor) ?? o, g = ((_ = e.style) == null ? void 0 : _.markerTextOffsetY) ?? 0, h = /* @__PURE__ */ new Map(), P = /* @__PURE__ */ new Map();
5994
+ const s = hr(t, c), u = ((M = e.style) == null ? void 0 : M.markerShape) ?? "circle", i = ((L = e.style) == null ? void 0 : L.markerSize) ?? 6, o = ((N = e.style) == null ? void 0 : N.color) ?? e.color ?? "#fbbf24", m = ((x = e.style) == null ? void 0 : x.markerOffsetY) ?? 0, a = ((f = e.style) == null ? void 0 : f.markerFontSize) ?? 10, p = ((Y = e.style) == null ? void 0 : Y.markerTextColor) ?? o, g = ((_ = e.style) == null ? void 0 : _.markerTextOffsetY) ?? 0, h = /* @__PURE__ */ new Map(), P = /* @__PURE__ */ new Map();
5995
5995
  let D = 0;
5996
5996
  if (t.forEach((w) => {
5997
5997
  if (!Number.isFinite(w == null ? void 0 : w.t) || !Number.isFinite(w == null ? void 0 : w.v))
@@ -6080,7 +6080,7 @@ const pi = {
6080
6080
  }) });
6081
6081
  }, Ai = (e, t, r, c, n, l, s) => {
6082
6082
  var L;
6083
- const i = Si(t, c, n) / 2, o = ((L = e.style) == null ? void 0 : L.color) ?? (l ? "#22c55e" : "#16a34a"), m = ze.color(o), p = m ? m.darker(1.2).formatHex() : l ? "#ef4444" : "#b91c1c", g = o;
6083
+ const i = Si(t, c, n) / 2, o = ((L = e.style) == null ? void 0 : L.color) ?? e.color ?? (l ? "#22c55e" : "#16a34a"), m = ze.color(o), p = m ? m.darker(1.2).formatHex() : l ? "#ef4444" : "#b91c1c", g = o;
6084
6084
  let h = t;
6085
6085
  (s == null ? void 0 : s.phase) === "background" || (s == null ? void 0 : s.phase) === "idle" ? h = [] : (s == null ? void 0 : s.phase) === "candles" && (h = t.slice(0, s.candleRevealIndex + 1));
6086
6086
  const P = (N) => {
@@ -6182,28 +6182,28 @@ const pi = {
6182
6182
  }, Bi = (e, t, r, c, n, l) => !Array.isArray(e.data) || e.data.length === 0 || (l == null ? void 0 : l.phase) === "loading" ? null : e.type === "ohlc" && dr(e.data) ? Ai(e, e.data, t, r, c, n, l) : e.type === "marker" ? Vi(e, e.data, t, r, l) : e.type === "position" ? _i(e, e.data, t, r, c) : ur(e.data) ? Li(e, e.data, t, r, l) : null, zt = (e, t) => {
6183
6183
  var n, l, s, u, i, o, m, a, p, g, h, P, D;
6184
6184
  if (!Array.isArray(e.data) || e.data.length === 0)
6185
- return { key: e.key, color: (n = e.style) == null ? void 0 : n.color, value: null, display: "—", raw: null };
6185
+ return { key: e.key, color: ((n = e.style) == null ? void 0 : n.color) ?? e.color, value: null, display: "—", raw: null };
6186
6186
  if (e.type === "ohlc" && dr(e.data)) {
6187
6187
  const F = Ei(e.data, t);
6188
6188
  if (!F)
6189
- return { key: e.key, color: (l = e.style) == null ? void 0 : l.color, value: null, display: "—", raw: null };
6189
+ return { key: e.key, color: ((l = e.style) == null ? void 0 : l.color) ?? e.color, value: null, display: "—", raw: null };
6190
6190
  const b = e.tooltipFormatter ? e.tooltipFormatter(F) : `O ${et(F.o)} H ${et(F.h)} L ${et(F.l)} C ${et(F.c)}`;
6191
- return { key: e.key, color: (s = e.style) == null ? void 0 : s.color, value: F.c ?? null, display: b, raw: F };
6191
+ return { key: e.key, color: ((s = e.style) == null ? void 0 : s.color) ?? e.color, value: F.c ?? null, display: b, raw: F };
6192
6192
  }
6193
6193
  if (e.type === "marker") {
6194
6194
  const F = e.data.filter((f) => Number.isFinite(f == null ? void 0 : f.t) && Number.isFinite(f == null ? void 0 : f.v));
6195
6195
  if (!F.length)
6196
- return { key: e.key, color: (u = e.style) == null ? void 0 : u.color, value: null, display: "—", raw: null };
6196
+ return { key: e.key, color: ((u = e.style) == null ? void 0 : u.color) ?? e.color, value: null, display: "—", raw: null };
6197
6197
  const b = F.map((f) => ({ t: f.t, v: f.v })), M = tr(b, t);
6198
6198
  if (!M)
6199
- return { key: e.key, color: (i = e.style) == null ? void 0 : i.color, value: null, display: "—", raw: null };
6199
+ return { key: e.key, color: ((i = e.style) == null ? void 0 : i.color) ?? e.color, value: null, display: "—", raw: null };
6200
6200
  const L = F.find((f) => f.t === M.t && f.v === M.v) ?? null, N = e.tooltipFormatter ? e.tooltipFormatter(L ?? M) : L != null && L.label ? `${L.label} ${et(M.v)}` : et(M.v), x = (L == null ? void 0 : L.color) ?? ((o = e.style) == null ? void 0 : o.color);
6201
6201
  return { key: e.key, color: x, value: M.v ?? null, display: N, raw: L ?? M };
6202
6202
  }
6203
6203
  if (e.type === "position") {
6204
6204
  const F = e.data.filter((N) => Number.isFinite(N == null ? void 0 : N.start) && Number.isFinite(N == null ? void 0 : N.entry) && Number.isFinite(N == null ? void 0 : N.stop) && Number.isFinite(N == null ? void 0 : N.target));
6205
6205
  if (!F.length)
6206
- return { key: e.key, color: (m = e.style) == null ? void 0 : m.color, value: null, display: "—", raw: null };
6206
+ return { key: e.key, color: ((m = e.style) == null ? void 0 : m.color) ?? e.color, value: null, display: "—", raw: null };
6207
6207
  const b = F.reduce((N, x) => {
6208
6208
  const f = Math.abs(x.start - t), Y = Number.isFinite(x.end ?? NaN) ? Math.abs(x.end - t) : f, _ = Math.min(f, Y);
6209
6209
  if (!N)
@@ -6212,19 +6212,19 @@ const pi = {
6212
6212
  return _ < E ? x : N;
6213
6213
  }, null);
6214
6214
  if (!b)
6215
- return { key: e.key, color: (a = e.style) == null ? void 0 : a.color, value: null, display: "—", raw: null };
6215
+ return { key: e.key, color: ((a = e.style) == null ? void 0 : a.color) ?? e.color, value: null, display: "—", raw: null };
6216
6216
  const M = e.tooltipFormatter ? e.tooltipFormatter(b) : `Entry ${et(b.entry)} Stop ${et(b.stop)} Target ${et(b.target)}`, L = ((p = e.style) == null ? void 0 : p.color) ?? ((g = e.style) == null ? void 0 : g.riskColor) ?? "rgba(239, 68, 68, 0.8)";
6217
6217
  return { key: e.key, color: L, value: b.entry ?? null, display: M, raw: b };
6218
6218
  }
6219
6219
  if (ur(e.data)) {
6220
6220
  const F = tr(e.data, t);
6221
6221
  if (!F)
6222
- return { key: e.key, color: (h = e.style) == null ? void 0 : h.color, value: null, display: "—", raw: null };
6222
+ return { key: e.key, color: ((h = e.style) == null ? void 0 : h.color) ?? e.color, value: null, display: "—", raw: null };
6223
6223
  const b = e.tooltipFormatter ? e.tooltipFormatter(F) : et(F.v);
6224
- return { key: e.key, color: (P = e.style) == null ? void 0 : P.color, value: F.v ?? null, display: b, raw: F };
6224
+ return { key: e.key, color: ((P = e.style) == null ? void 0 : P.color) ?? e.color, value: F.v ?? null, display: b, raw: F };
6225
6225
  }
6226
6226
  const r = e.data.find((F) => F && typeof F.t == "number"), c = e.tooltipFormatter ? e.tooltipFormatter(r) : "—";
6227
- return { key: e.key, color: (D = e.style) == null ? void 0 : D.color, value: null, display: c, raw: r };
6227
+ return { key: e.key, color: ((D = e.style) == null ? void 0 : D.color) ?? e.color, value: null, display: c, raw: r };
6228
6228
  }, gs = pr(function({
6229
6229
  spec: t,
6230
6230
  darkMode: r = !1,
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Technical Indicator Calculations
3
+ * Pure utility functions for calculating various technical indicators
4
+ */
5
+ /**
6
+ * Calculate Simple Moving Average values for chart data.
7
+ * This function is intended to be used externally to calculate SMA data
8
+ * before passing it to the chart component.
9
+ *
10
+ * @param {Array<{ date: string, open: number, high: number, low: number, close: number }>} data
11
+ * @param {number} period
12
+ * @returns {Array<{ x: string, y: number }>}
13
+ */
14
+ export function calculateSMA(data: Array<{
15
+ date: string;
16
+ open: number;
17
+ high: number;
18
+ low: number;
19
+ close: number;
20
+ }>, period: number): Array<{
21
+ x: string;
22
+ y: number;
23
+ }>;
24
+ /**
25
+ * Calculate Exponential Moving Average values for chart data.
26
+ *
27
+ * @param {Array<{ date: string, open: number, high: number, low: number, close: number }>} data
28
+ * @param {number} period
29
+ * @returns {Array<{ x: string, y: number }>}
30
+ */
31
+ export function calculateEMA(data: Array<{
32
+ date: string;
33
+ open: number;
34
+ high: number;
35
+ low: number;
36
+ close: number;
37
+ }>, period: number): Array<{
38
+ x: string;
39
+ y: number;
40
+ }>;
package/package.json CHANGED
@@ -1,12 +1,14 @@
1
1
  {
2
2
  "name": "@dwlf/charting",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "React charting library for financial data — candlestick charts, annotations, overlays, and interaction hooks.",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
7
7
  "module": "dist/index.js",
8
+ "types": "dist/index.d.ts",
8
9
  "exports": {
9
10
  ".": {
11
+ "types": "./dist/index.d.ts",
10
12
  "import": "./dist/index.js",
11
13
  "require": "./dist/index.cjs"
12
14
  },
@@ -81,6 +83,7 @@
81
83
  "semantic-release": "^23.1.1",
82
84
  "typescript": "^5.6.3",
83
85
  "vite": "^6.0.0",
86
+ "vite-plugin-dts": "^4.5.4",
84
87
  "vitest": "^2.1.3"
85
88
  }
86
89
  }