@tidal-ts/chart 0.2.0 → 0.2.2

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/dist/index.d.ts CHANGED
@@ -13,7 +13,7 @@
13
13
  */
14
14
  export { TimeSeriesChart, annotationInView, type ChartAnnotation, type ChartStats, type TimeSeriesChartProps, type TimeSeriesChartRow, } from './TimeSeriesChart.js';
15
15
  export type { ChartSeries } from './types.js';
16
- export { configAxisId, effectiveSplit, formatSeriesValue, isStudySeries, LINE_WIDTHS, PAIR_JOINS, PAIR_LENSES, seriesAxisId, readsCompare, seriesDrawn, seriesLineDashArray, seriesLineWidth, sharedAxisId, type AxisRange, effectiveAxisBounds, clampBoundsToLocks, barZeroLock, centerOnZero, axisRangeIsEmpty, axisFormat, fractionTicks, bandColumns, configColumns, hasBarOutput, logAllowed, AXIS_PRECISIONS, type PairJoinOp, type PairLensOp, type SeriesGroup, type PairPartView, type PairView, type SeriesBinding, type SeriesConfig, type SeriesAxis, type SeriesStyle, type SeriesWindow, type CandleVariant, type ColorBy, } from './series.js';
16
+ export { configAxisId, effectiveSplit, formatSeriesValue, isStudySeries, LINE_WIDTHS, PAIR_JOINS, PAIR_LENSES, seriesAxisId, readsCompare, seriesDrawn, seriesLineDashArray, seriesLineWidth, sharedAxisId, type AxisRange, effectiveAxisBounds, clampBoundsToLocks, barZeroLock, centerOnZero, axisRangeIsEmpty, axisFormat, fractionTicks, bandColumns, configColumns, hasBarOutput, logAllowed, AXIS_PRECISIONS, type PairJoinOp, type PairLensOp, type SeriesGroup, type PairPartView, type PairView, type SeriesBinding, type SeriesConfig, type SeriesAxis, type SeriesStyle, type SeriesWindow, type CandleVariant, type ColorBy, readsFrom, sourcesOf, } from './series.js';
17
17
  export { DEFAULT_CHART_SETTINGS, mergeChartSettings, type AnnotationOverride, type ChartSettings, type CategoryLineStyle, type SessionDividers, type SplitColorDefault, type LineDash, } from './chartSettings.js';
18
18
  export { useMeasuredWidth, useMeasuredSize } from './useMeasuredWidth.js';
19
19
  export { assembleRows, carries, foldKey, foldSources, prepareChart, sourceFacts, type ConfigRow, type PreparedRow, type SourceFacts, type SourceInput, type SourceInputs, } from './prepare.js';
package/dist/index.js CHANGED
@@ -12,7 +12,7 @@
12
12
  * style builders) stay internal until a consumer asks.
13
13
  */
14
14
  export { TimeSeriesChart, annotationInView, } from './TimeSeriesChart.js';
15
- export { configAxisId, effectiveSplit, formatSeriesValue, isStudySeries, LINE_WIDTHS, PAIR_JOINS, PAIR_LENSES, seriesAxisId, readsCompare, seriesDrawn, seriesLineDashArray, seriesLineWidth, sharedAxisId, effectiveAxisBounds, clampBoundsToLocks, barZeroLock, centerOnZero, axisRangeIsEmpty, axisFormat, fractionTicks, bandColumns, configColumns, hasBarOutput, logAllowed, AXIS_PRECISIONS, } from './series.js';
15
+ export { configAxisId, effectiveSplit, formatSeriesValue, isStudySeries, LINE_WIDTHS, PAIR_JOINS, PAIR_LENSES, seriesAxisId, readsCompare, seriesDrawn, seriesLineDashArray, seriesLineWidth, sharedAxisId, effectiveAxisBounds, clampBoundsToLocks, barZeroLock, centerOnZero, axisRangeIsEmpty, axisFormat, fractionTicks, bandColumns, configColumns, hasBarOutput, logAllowed, AXIS_PRECISIONS, readsFrom, sourcesOf, } from './series.js';
16
16
  export { DEFAULT_CHART_SETTINGS, mergeChartSettings, } from './chartSettings.js';
17
17
  export { useMeasuredWidth, useMeasuredSize } from './useMeasuredWidth.js';
18
18
  export { assembleRows, carries, foldKey, foldSources, prepareChart, sourceFacts, } from './prepare.js';
package/dist/series.d.ts CHANGED
@@ -150,6 +150,27 @@ export interface SeriesConfig {
150
150
  * spec, while `id` stands still. The render folds the op onto the source
151
151
  * series via `applyDerived`. Absent ⇒ raw. */
152
152
  derive?: DeriveSpec;
153
+ /**
154
+ * The configs this one is BUILT ON, index-aligned with its spec's inputs
155
+ * (`inputNames(derive)`) — a study's one parent, a joined pair's two legs.
156
+ *
157
+ * The spec names its inputs by COLUMN, and that stays: the column is the
158
+ * DATA, content-addressed, computed once however many configs read it. What
159
+ * a column cannot say is WHICH config a derived one belongs to, and once the
160
+ * same metric can be seated twice — price on two rows, each with its own
161
+ * chain of studies — two configs share a column and "which one is this
162
+ * study on" has two answers. This is the answer, recorded when it was known:
163
+ * at the moment the study was added from one particular config's button.
164
+ *
165
+ * An entry is honoured only while it still names a config that PUBLISHES
166
+ * that input's column. An entry absent, or naming a config that computes
167
+ * something else now (a stale record), falls back to the column — which is
168
+ * how every config written before this field is read. An entry naming a
169
+ * config that is GONE resolves to nothing: the parent was removed, and
170
+ * re-binding its orphan to whichever other config shares the column would
171
+ * hand it to a copy it was never on.
172
+ */
173
+ parentIds?: readonly (string | undefined)[];
153
174
  /** Stroke width (px) for `line`/`area`. Omitted ⇒ the category default from
154
175
  * the chart settings (see {@link seriesLineWidth}). */
155
176
  lineWidth?: number;
@@ -489,3 +510,28 @@ export declare const formatCurrency: (v: number, digits: number) => string;
489
510
  * `-0.23log` (the unit still keeps it off a unitless axis); a percent /
490
511
  * unitless suffix trails the value (`22.65%`). */
491
512
  export declare function formatSeriesValue(value: number | null, unit?: string): string;
513
+ /**
514
+ * The configs `c` is BUILT ON — the one question every dependency walk asks,
515
+ * in the machine and in any host that draws the graph, answered in one place.
516
+ *
517
+ * By RECORDED PARENT first (`parentIds`, index-aligned with the spec's
518
+ * inputs), and by COLUMN only where no parent was recorded. The spec names its
519
+ * inputs by column, and for the data that is exactly right — but the column
520
+ * cannot say which config a study belongs to once a metric is seated twice,
521
+ * and every walk used to answer by column: removal cascaded through whichever
522
+ * copy a Map kept last, and retuning one study re-pointed the OTHER copy's
523
+ * children at it (`TDL-CMPDUP`). The column fallback is kept for configs
524
+ * written before `parentIds` and for inputs no config was recorded for (a
525
+ * study's bar columns, a pair leg that was not seated). It is a best guess
526
+ * where a column is seated twice — the first config publishing it wins —
527
+ * which is exactly the ambiguity recording a parent exists to remove.
528
+ *
529
+ * A recorded parent that is gone resolves to NOTHING rather than re-binding
530
+ * by column: see {@link SeriesConfig.parentIds}.
531
+ *
532
+ * An input with no config behind it (a raw feed column no one displays)
533
+ * contributes nothing, as before.
534
+ */
535
+ export declare function sourcesOf(configs: readonly SeriesConfig[], c: SeriesConfig): SeriesConfig[];
536
+ /** Whether `c` is built on `p` — `sourcesOf`, asked the other way round. */
537
+ export declare const readsFrom: (configs: readonly SeriesConfig[], c: SeriesConfig, p: SeriesConfig) => boolean;
package/dist/series.js CHANGED
@@ -59,7 +59,7 @@ export function configColumns(c) {
59
59
  // `@tidal-ts/core` (where the windowing + derive seam live) — imported for
60
60
  // `SeriesConfig` below and re-exported so UI code has one import site for the
61
61
  // series vocabulary.
62
- import { BAND_OUTPUTS, COMPARE_PREFIX, opOutputs, opParams, outputMark, usesCompare, } from '@tidal-ts/core';
62
+ import { BAND_OUTPUTS, COMPARE_PREFIX, inputNames, opOutputs, opParams, outputMark, usesCompare, } from '@tidal-ts/core';
63
63
  // The app-wide presentation defaults the category resolvers below read.
64
64
  import { DEFAULT_CHART_SETTINGS, } from './chartSettings.js';
65
65
  // --- Axis identity ------------------------------------------------------------
@@ -374,3 +374,49 @@ export function formatSeriesValue(value, unit = '') {
374
374
  return formatCurrency(value, 2);
375
375
  return `${value.toFixed(2)}${unit}`;
376
376
  }
377
+ /**
378
+ * The configs `c` is BUILT ON — the one question every dependency walk asks,
379
+ * in the machine and in any host that draws the graph, answered in one place.
380
+ *
381
+ * By RECORDED PARENT first (`parentIds`, index-aligned with the spec's
382
+ * inputs), and by COLUMN only where no parent was recorded. The spec names its
383
+ * inputs by column, and for the data that is exactly right — but the column
384
+ * cannot say which config a study belongs to once a metric is seated twice,
385
+ * and every walk used to answer by column: removal cascaded through whichever
386
+ * copy a Map kept last, and retuning one study re-pointed the OTHER copy's
387
+ * children at it (`TDL-CMPDUP`). The column fallback is kept for configs
388
+ * written before `parentIds` and for inputs no config was recorded for (a
389
+ * study's bar columns, a pair leg that was not seated). It is a best guess
390
+ * where a column is seated twice — the first config publishing it wins —
391
+ * which is exactly the ambiguity recording a parent exists to remove.
392
+ *
393
+ * A recorded parent that is gone resolves to NOTHING rather than re-binding
394
+ * by column: see {@link SeriesConfig.parentIds}.
395
+ *
396
+ * An input with no config behind it (a raw feed column no one displays)
397
+ * contributes nothing, as before.
398
+ */
399
+ export function sourcesOf(configs, c) {
400
+ if (!c.derive)
401
+ return [];
402
+ const out = [];
403
+ inputNames(c.derive).forEach((name, i) => {
404
+ const byId = c.parentIds?.[i];
405
+ if (byId != null && byId !== c.id) {
406
+ const recorded = configs.find((x) => x.id === byId);
407
+ if (!recorded)
408
+ return; // its parent is gone — an orphan, not a re-bind
409
+ if (recorded.column === name) {
410
+ out.push(recorded);
411
+ return;
412
+ }
413
+ // Stale: that config computes something else now. Fall through.
414
+ }
415
+ const src = configs.find((x) => x.id !== c.id && x.column === name);
416
+ if (src)
417
+ out.push(src);
418
+ });
419
+ return out;
420
+ }
421
+ /** Whether `c` is built on `p` — `sourcesOf`, asked the other way round. */
422
+ export const readsFrom = (configs, c, p) => sourcesOf(configs, c).some((s) => s.id === p.id);
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.2",
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.2"
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",