@tidal-ts/chart 0.2.0 → 0.2.1

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.
@@ -794,20 +794,40 @@ function TimeSeriesChartInner({ rows, sources, ohlcSources = [], calendarDays =
794
794
  const breaksFor = (c) => intraday && settings.sessions.breaks && !coarse.has(c.source ?? '');
795
795
  /** …and whether a FILL has to be split to do so: only when there are seams. */
796
796
  const splitsFor = (c) => breaksFor(c) && sessions.length > 1;
797
- // One sub-series per live segment, for the layers pond gives no `sessionBreaks`
798
- // (`<BandChart>`, `<AreaChart>`). Lazy and cached on the series object: slicing
799
- // a 250k-row series into ~250 sessions is real work, and most renders draw no
800
- // fill at all. The cache resets with the segments.
801
- const segmentsFor = useMemo(() => {
802
- const cache = new Map();
803
- return (series) => {
804
- let slices = cache.get(series);
797
+ // One sub-series per live segment, for the one layer pond gives no
798
+ // `sessionBreaks` (`<AreaChart>`; `<BandChart>` got it in charts 0.70.0).
799
+ // Lazy and cached on the series object: slicing a 250k-row series into ~250
800
+ // sessions is real work, and most renders draw no fill at all. The cache
801
+ // resets with the segments.
802
+ const { segmentsFor, endSegmentsFor } = useMemo(() => {
803
+ const raw = new Map();
804
+ const end = new Map();
805
+ const segmentsFor = (series) => {
806
+ let slices = raw.get(series);
805
807
  if (!slices) {
806
808
  slices = sliceBySegments(series, sessions);
807
- cache.set(series, slices);
809
+ raw.set(series, slices);
808
810
  }
809
811
  return slices;
810
812
  };
813
+ // The same slices moved to the bar's END — cut first, shifted after, and
814
+ // cached like the raw ones: a fill that is re-shifted on every frame of a
815
+ // pan hands pond a fresh series identity per slice per frame. Only the area
816
+ // still needs these — `<AreaChart>` has no `sessionBreaks` (F-charts-20);
817
+ // `<BandChart>` gained it in charts 0.70.0.
818
+ const endSegmentsFor = (series) => {
819
+ let slices = end.get(series);
820
+ if (!slices) {
821
+ const native = nativeMs(series);
822
+ slices =
823
+ native === undefined
824
+ ? segmentsFor(series)
825
+ : segmentsFor(series).map((slice) => shiftKeys(slice, native));
826
+ end.set(series, slices);
827
+ }
828
+ return slices;
829
+ };
830
+ return { segmentsFor, endSegmentsFor };
811
831
  }, [sessions]);
812
832
  const discontinuities = useMemo(() => !collapseWeekends
813
833
  ? undefined
@@ -826,13 +846,23 @@ function TimeSeriesChartInner({ rows, sources, ohlcSources = [], calendarDays =
826
846
  // own z slot. Keys are explicit for the same reason.
827
847
  const layer = (c, panelSeries, axis, candleable) => {
828
848
  const col = c.column;
829
- // A line/area draws CLOSES, which belong at their bar's end — see `shifted`.
830
- // For the price column of an OHLC source it can do better still and start at
831
- // the session's open (`openLine`). Both fall back to the raw series when there
832
- // is nothing to shift, which is daily data.
849
+ // A line/area draws CLOSES, which belong at their bar's end — see `shifted`,
850
+ // and daily is not exempt. For the price column of an OHLC source it can do
851
+ // better still and start at the session's open (`openLine`). Both fall back
852
+ // to the raw series only when no bar interval can be inferred.
833
853
  const closeSeries = (c.source && col === 'close' ? openLine.get(c.source) : undefined) ??
834
854
  (c.source ? shifted.get(c.source) : undefined) ??
835
855
  panelSeries;
856
+ // Every OTHER line-like mark belongs at its bar's end too — a band's edges
857
+ // and middle, a study's outputs — or a banded curve leads the plain line
858
+ // beside it by one bar, visibly at every seam. Same shift as `closeSeries`,
859
+ // minus the open-line case: only a price column has an open to start from.
860
+ // Per-segment slices come from `endSegmentsFor`: cut from the RAW series
861
+ // and shifted after (shifted first, a session's last close sits on the
862
+ // segment end), and cached.
863
+ const src = c.source ? sources[c.source] : undefined;
864
+ const native = src ? nativeMs(src) : undefined;
865
+ const endSeries = (c.source ? shifted.get(c.source) : undefined) ?? panelSeries;
836
866
  switch (c.style) {
837
867
  case 'area': {
838
868
  // No `sessionBreaks` on `<AreaChart>` — the prop is LineChart-only
@@ -848,15 +878,13 @@ function TimeSeriesChartInner({ rows, sources, ohlcSources = [], calendarDays =
848
878
  if (!splitsFor(c)) {
849
879
  return [_jsx(AreaChart, { series: closeSeries, column: col, as: c.id, axis: axis }, c.id)];
850
880
  }
851
- const native = c.source ? nativeMs(sources[c.source]) : undefined;
852
- const atClose = (slice) => {
853
- if (native === undefined)
854
- return slice;
855
- if (c.source && col === 'close' && ohlc.has(c.source))
856
- return sessionOpenLine(slice, native, { open: 'open', close: 'close' });
857
- return shiftKeys(slice, native);
858
- };
859
- return segmentsFor(panelSeries).map((slice, i) => (_jsx(AreaChart, { series: atClose(slice), column: col, as: c.id, axis: axis }, `${c.id}__s${i}`)));
881
+ // The price close gets the open-line treatment per slice (one source,
882
+ // so uncached is cheap); everything else takes the cached end-shifted
883
+ // slices.
884
+ const slices = native !== undefined && c.source && col === 'close' && ohlc.has(c.source)
885
+ ? segmentsFor(panelSeries).map((slice) => sessionOpenLine(slice, native, { open: 'open', close: 'close' }))
886
+ : endSegmentsFor(panelSeries);
887
+ return slices.map((slice, i) => (_jsx(AreaChart, { series: slice, column: col, as: c.id, axis: axis }, `${c.id}__s${i}`)));
860
888
  }
861
889
  case 'bar': {
862
890
  const s = derived.bar.get(c.id);
@@ -890,7 +918,7 @@ function TimeSeriesChartInner({ rows, sources, ohlcSources = [], calendarDays =
890
918
  showOHLC: true }, c.id),
891
919
  ]
892
920
  : [
893
- _jsx(LineChart, { series: panelSeries, column: col, as: c.id, axis: axis, sessionBreaks: intraday && settings.sessions.breaks && !coarse.has(c.source ?? '') }, c.id),
921
+ _jsx(LineChart, { series: closeSeries, column: col, as: c.id, axis: axis, sessionBreaks: intraday && settings.sessions.breaks && !coarse.has(c.source ?? '') }, c.id),
894
922
  ];
895
923
  case 'band': {
896
924
  // A band is TWO layers for ONE config — the wash between the edges, and
@@ -905,18 +933,13 @@ function TimeSeriesChartInner({ rows, sources, ohlcSources = [], calendarDays =
905
933
  // three columns off it (`bandColumns`). Reading `col` itself would find
906
934
  // nothing.
907
935
  //
908
- // The wash has no `sessionBreaks` either, so on a collapsing axis it is
909
- // one `<BandChart>` per live segment over that segment's slice — else a
910
- // filled envelope bridges the overnight gap its own centre line honours.
936
+ // Both break at the session seams together — `<BandChart sessionBreaks>`
937
+ // arrived in charts 0.70.0 with the same semantics as the line's, which
938
+ // retired this chart's one-wash-per-segment workaround (0.2.0).
911
939
  const b = bandColumns(col);
912
- const washes = splitsFor(c)
913
- ? segmentsFor(panelSeries).map((slice, i) => (_jsx(BandChart, { series: slice, lower: b.lower, upper: b.upper, as: c.id, axis: axis }, `${c.id}__band${i}`)))
914
- : [
915
- _jsx(BandChart, { series: panelSeries, lower: b.lower, upper: b.upper, as: c.id, axis: axis }, `${c.id}__band`),
916
- ];
917
940
  return [
918
- ...washes,
919
- _jsx(LineChart, { series: panelSeries, column: b.middle, as: c.id, axis: axis, sessionBreaks: breaksFor(c) }, c.id),
941
+ _jsx(BandChart, { series: endSeries, lower: b.lower, upper: b.upper, as: c.id, axis: axis, sessionBreaks: breaksFor(c) }, `${c.id}__band`),
942
+ _jsx(LineChart, { series: endSeries, column: b.middle, as: c.id, axis: axis, sessionBreaks: breaksFor(c) }, c.id),
920
943
  ];
921
944
  }
922
945
  case 'lines': {
@@ -930,11 +953,16 @@ function TimeSeriesChartInner({ rows, sources, ohlcSources = [], calendarDays =
930
953
  const histSplit = effectiveSplit(c, settings);
931
954
  const layers = opOutputs(op).map((suffix, i) => ({
932
955
  mark: outputMark(op, suffix),
933
- node: outputMark(op, suffix) === 'bar' ? (_jsx(BarChart, { series: panelSeries, column: `${col}${suffix}`, as: outputKey(c.id, i), axis: axis, ...(histSplit.mode === 'split'
956
+ node: outputMark(op, suffix) === 'bar' ? (
957
+ // On the SAME series as the study's lines: a point-keyed bar is
958
+ // centred on its key, so a histogram left on the raw keys would
959
+ // put its zero-cross one bar left of the line-cross it exists to
960
+ // mark.
961
+ _jsx(BarChart, { series: endSeries, column: `${col}${suffix}`, as: outputKey(c.id, i), axis: axis, ...(histSplit.mode === 'split'
934
962
  ? {
935
- binColors: signColors(panelSeries, `${col}${suffix}`, resolveColor(histSplit.rise), resolveColor(histSplit.fall)),
963
+ binColors: signColors(endSeries, `${col}${suffix}`, resolveColor(histSplit.rise), resolveColor(histSplit.fall)),
936
964
  }
937
- : {}) }, `${c.id}__o${i}`)) : (_jsx(LineChart, { series: panelSeries, column: `${col}${suffix}`, as: outputKey(c.id, i), axis: axis, sessionBreaks: intraday && settings.sessions.breaks && !coarse.has(c.source ?? '') }, `${c.id}__o${i}`)),
965
+ : {}) }, `${c.id}__o${i}`)) : (_jsx(LineChart, { series: endSeries, column: `${col}${suffix}`, as: outputKey(c.id, i), axis: axis, sessionBreaks: intraday && settings.sessions.breaks && !coarse.has(c.source ?? '') }, `${c.id}__o${i}`)),
938
966
  }));
939
967
  // Bars UNDER lines. `<Layers>` z-orders by position, and a MACD's
940
968
  // histogram is context for its two lines — drawn over them it would
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tidal-ts/chart",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "private": false,
5
5
  "description": "TimeSeriesChart — a multi-row time-series chart on @pond-ts/charts, plus the series and settings vocabulary and the prepare step. Theme, colours and settings arrive as props.",
6
6
  "license": "MIT",
@@ -31,25 +31,27 @@
31
31
  "access": "public"
32
32
  },
33
33
  "peerDependencies": {
34
- "@pond-ts/charts": "^0.69.0",
35
- "@pond-ts/financial": "^0.69.0",
36
- "pond-ts": "^0.69.0",
34
+ "@pond-ts/charts": "^0.70.0",
35
+ "@pond-ts/financial": "^0.70.0",
36
+ "@pond-ts/react": "^0.70.0",
37
+ "pond-ts": "^0.70.0",
37
38
  "react": "^18.2.0 || ^19.0.0"
38
39
  },
39
40
  "dependencies": {
40
- "@tidal-ts/core": "0.2.0"
41
+ "@tidal-ts/core": "0.2.1"
41
42
  },
42
43
  "devDependencies": {
43
- "@pond-ts/charts": "^0.69.0",
44
- "@pond-ts/financial": "^0.69.0",
45
- "@pond-ts/process": "0.69.0",
44
+ "@pond-ts/charts": "^0.70.0",
45
+ "@pond-ts/financial": "^0.70.0",
46
+ "@pond-ts/process": "0.70.0",
47
+ "@pond-ts/react": "^0.70.0",
46
48
  "@storybook/addon-essentials": "^8.5.0",
47
49
  "@storybook/react": "^8.5.0",
48
50
  "@storybook/react-vite": "^8.5.0",
49
51
  "@types/react": "^18.3.18",
50
52
  "@types/react-dom": "^18.3.5",
51
53
  "@vitejs/plugin-react": "^4.3.4",
52
- "pond-ts": "^0.69.0",
54
+ "pond-ts": "^0.70.0",
53
55
  "react": "^18.3.1",
54
56
  "react-dom": "^18.3.1",
55
57
  "storybook": "^8.5.0",