@tidal-ts/chart 0.10.0 → 0.12.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.
@@ -266,6 +266,33 @@ export interface TimeSeriesChartProps {
266
266
  * the same manual pin and can never disagree about which axis is manual.
267
267
  */
268
268
  onAxisBounds?: (axisId: string, bounds: readonly [number, number] | null) => void;
269
+ /**
270
+ * The series each **bar** config is actually drawn from, keyed by config id —
271
+ * the roll-up, not the source.
272
+ *
273
+ * A bar does not draw its source column. It draws an aggregate built here:
274
+ * `avg` per window, or `sum` for `volume`, over a window that in Auto is
275
+ * chosen from the plot width and the view. So a host that measures an axis
276
+ * itself (to pin a fit, or to print the range in a readout) and reads the raw
277
+ * column gets the wrong number for a bar. For `avg` the raw extent is merely
278
+ * loose; for `sum` it is far too small — 1-minute volumes against bars that
279
+ * are daily sums — and an axis pinned to it clips every bar. Measure these
280
+ * instead: the summed column keeps its name (`config.column`), and the split
281
+ * halves (`<col>__up` / `<col>__dn`) ride beside it.
282
+ *
283
+ * Each series is the roll-up of the WHOLE source, keyed by bucket START. A
284
+ * host measuring the visible window should keep a bucket that overlaps the
285
+ * view's left edge, or it can drop the tallest bar on screen.
286
+ *
287
+ * Fires after a render whose roll-up changed: new data (a new `sources`
288
+ * object counts — keep it stable), a new window, or an Auto window that moved
289
+ * with a resize or a zoom. Not on hover or pan within one window, and not
290
+ * before the chart has measured its width (the Auto window is meaningless
291
+ * until then). A config that draws no bars (hidden, or its column absent) is
292
+ * not in the map. The map is the one the chart draws from: read it, never
293
+ * mutate it.
294
+ */
295
+ onBarSeries?: (bars: ReadonlyMap<string, ChartSeries>) => void;
269
296
  /** A CLICK on a y-axis gutter (pond 0.61 `onMouseEvent`), with the row/side
270
297
  * it landed on and the viewport point — the axis panel's anchor. Row + side
271
298
  * are passed apart because axis ids embed config ids (engine specIds with
@@ -323,7 +350,7 @@ export declare function splitBarColumns(agg: ChartSeries, col: string, src: Char
323
350
  * chips can track the hovered point. Memoized — the caller's hover state re-renders
324
351
  * chips, not the canvas (keep prop identities stable).
325
352
  */
326
- declare function TimeSeriesChartInner({ rows, sources, ohlcSources, calendarDays, annotations, coarseSources, dimmed, splitters, onTracker, onStats, pricePill, collapseWeekends, settings, timeZone, theme: base, resolveColor, colorScheme, viewRange, onViewRangeChange, axisOptions, onAxisClick, onAxisBounds, }: TimeSeriesChartProps): import("react").JSX.Element;
353
+ declare function TimeSeriesChartInner({ rows, sources, ohlcSources, calendarDays, annotations, coarseSources, dimmed, splitters, onTracker, onStats, pricePill, collapseWeekends, settings, timeZone, theme: base, resolveColor, colorScheme, viewRange, onViewRangeChange, axisOptions, onAxisClick, onAxisBounds, onBarSeries, }: TimeSeriesChartProps): import("react").JSX.Element;
327
354
  /** Memoized export — hover state in the terminal re-renders the chips, not the
328
355
  * canvas. */
329
356
  export declare const TimeSeriesChart: import("react").MemoExoticComponent<typeof TimeSeriesChartInner>;
@@ -310,13 +310,18 @@ export function splitBarColumns(agg, col, src, hasOhlc, window, sessions) {
310
310
  * chips can track the hovered point. Memoized — the caller's hover state re-renders
311
311
  * chips, not the canvas (keep prop identities stable).
312
312
  */
313
- function TimeSeriesChartInner({ rows, sources, ohlcSources = [], calendarDays = EMPTY_DAYS, annotations = EMPTY_ANNOTATIONS, coarseSources = EMPTY_SOURCES, dimmed = [], splitters, onTracker, onStats, pricePill, collapseWeekends, settings = DEFAULT_CHART_SETTINGS, timeZone, theme: base, resolveColor = sameColor, colorScheme = 'dark', viewRange, onViewRangeChange, axisOptions, onAxisClick, onAxisBounds, }) {
313
+ function TimeSeriesChartInner({ rows, sources, ohlcSources = EMPTY_SOURCES, calendarDays = EMPTY_DAYS, annotations = EMPTY_ANNOTATIONS, coarseSources = EMPTY_SOURCES, dimmed = [], splitters, onTracker, onStats, pricePill, collapseWeekends, settings = DEFAULT_CHART_SETTINGS, timeZone, theme: base, resolveColor = sameColor, colorScheme = 'dark', viewRange, onViewRangeChange, axisOptions, onAxisClick, onAxisBounds, onBarSeries, }) {
314
314
  const [ref, width] = useMeasuredWidth();
315
315
  // Which y-axis gutter the pointer is over (the hover affordance). Axis
316
316
  // chrome is DOM, so this repaints the gutter only — never the canvas.
317
317
  const [hoverAxis, setHoverAxis] = useState(null);
318
318
  const allConfigs = useMemo(() => rows.flatMap((r) => r.configs), [rows]);
319
- const ohlc = useMemo(() => new Set(ohlcSources), [ohlcSources]);
319
+ // Keyed on CONTENT, not identity: an inline `ohlcSources={['price']}` is a new
320
+ // array every render, and it feeds the bar roll-up — which `onBarSeries`
321
+ // reports, and a host may feed back into its own state.
322
+ const ohlcKey = ohlcSources.join('\u0000');
323
+ // eslint-disable-next-line react-hooks/exhaustive-deps
324
+ const ohlc = useMemo(() => new Set(ohlcSources), [ohlcKey]);
320
325
  const dimKey = dimmed.join(',');
321
326
  // The category styles + split defaults shape the theme too — one compact key
322
327
  // for all of it, so a settings change repaints and a hover doesn't.
@@ -664,6 +669,21 @@ function TimeSeriesChartInner({ rows, sources, ohlcSources = [], calendarDays =
664
669
  return { bar, candle };
665
670
  // eslint-disable-next-line react-hooks/exhaustive-deps
666
671
  }, [sources, ohlc, sessionsFor, aggSig]);
672
+ // Report the roll-up to a host that measures axes (`onBarSeries`). Keyed on
673
+ // the memo's identity, so it fires when the bars change and not on every
674
+ // render; the callback rides a ref so a host passing an inline function does
675
+ // not re-fire it. Held until the width is measured: before that Auto picks the
676
+ // finest window, a roll-up that is never drawn. Re-fires when a callback is
677
+ // newly attached, so a host that starts listening is not left waiting for the
678
+ // next window change.
679
+ const onBarSeriesRef = useRef(onBarSeries);
680
+ onBarSeriesRef.current = onBarSeries;
681
+ const measured = width > 0;
682
+ const listening = onBarSeries !== undefined;
683
+ useEffect(() => {
684
+ if (measured)
685
+ onBarSeriesRef.current?.(derived.bar);
686
+ }, [derived.bar, measured, listening]);
667
687
  // A line through `close` belongs at the bar's END, not its start.
668
688
  //
669
689
  // The archive stamps a bar by its OPEN — the row stamped 13:30 covers 13:30–13:31
package/dist/series.js CHANGED
@@ -125,7 +125,7 @@ export function configColumns(c) {
125
125
  // `@tidal-ts/core` (where the windowing + derive seam live) — imported for
126
126
  // `SeriesConfig` below and re-exported so UI code has one import site for the
127
127
  // series vocabulary.
128
- import { BAND_OUTPUTS, COMPARE_PREFIX, deriveId, inputNames, opOutputs, opParams, outputMark, studyLevels, usesCompare, withFanOutput, } from '@tidal-ts/core';
128
+ import { BAND_OUTPUTS, BAR_PRICE_COLUMNS, COMPARE_PREFIX, deriveId, inputNames, isPairOp, opOutputs, opParams, outputMark, studyLevels, usesCompare, withFanOutput, } from '@tidal-ts/core';
129
129
  // The app-wide presentation defaults the category resolvers below read.
130
130
  import { DEFAULT_CHART_SETTINGS, } from './chartSettings.js';
131
131
  /** The textures in display order. */
@@ -554,7 +554,11 @@ export function sourcesOf(configs, c) {
554
554
  const recorded = configs.find((x) => x.id === byId);
555
555
  if (!recorded)
556
556
  return; // its parent is gone — an orphan, not a re-bind
557
- if (publishes(recorded, name)) {
557
+ // A DATA node offers every column of its source, not only the one it
558
+ // draws: a Bollinger of a price's HIGH is still built on that price
559
+ // (Peter, 2026-10-12). Only through the recorded parent, so a study is
560
+ // never re-bound to some other node on the same source.
561
+ if (publishes(recorded, name) || offersRaw(recorded, c, i)) {
558
562
  out.push(recorded);
559
563
  return;
560
564
  }
@@ -566,6 +570,20 @@ export function sourcesOf(configs, c) {
566
570
  });
567
571
  return out;
568
572
  }
573
+ /** Whether data node `p` feeds study `c`'s raw input `i`: `p` draws one of a
574
+ * bar's price columns on the study's own source, and the input reads another.
575
+ * Only a BAR offers its siblings — a vol source's `iv21` and `iv63` are two
576
+ * metrics, each its own node, not two columns of one. */
577
+ const offersRaw = (p, c, i) => {
578
+ if (p.derive || p.source == null || p.source !== c.source || !c.derive)
579
+ return false;
580
+ if (isPairOp(c.derive.op))
581
+ return false;
582
+ const input = c.derive.inputs[i];
583
+ return (typeof input === 'string' &&
584
+ BAR_PRICE_COLUMNS.includes(p.column) &&
585
+ BAR_PRICE_COLUMNS.includes(input));
586
+ };
569
587
  /** Whether `c` computes the column `name` — its own, or one of its fanned
570
588
  * lines' ({@link publishedColumns}). The cheap test first: a fan is rare. */
571
589
  const publishes = (c, name) => c.column === name || (!!c.fan && publishedColumns(c).includes(name));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tidal-ts/chart",
3
- "version": "0.10.0",
3
+ "version": "0.12.0",
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",
@@ -38,7 +38,7 @@
38
38
  "react": "^18.2.0 || ^19.0.0"
39
39
  },
40
40
  "dependencies": {
41
- "@tidal-ts/core": "0.10.0"
41
+ "@tidal-ts/core": "0.12.0"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@pond-ts/charts": "^0.73.0",
@@ -50,10 +50,12 @@
50
50
  "@storybook/react-vite": "^8.5.0",
51
51
  "@types/react": "^18.3.18",
52
52
  "@types/react-dom": "^18.3.5",
53
+ "@types/react-test-renderer": "^18.3.1",
53
54
  "@vitejs/plugin-react": "^4.3.4",
54
55
  "pond-ts": "^0.73.0",
55
56
  "react": "^18.3.1",
56
57
  "react-dom": "^18.3.1",
58
+ "react-test-renderer": "^18.3.1",
57
59
  "storybook": "^8.5.0",
58
60
  "typescript": "^5.7.2",
59
61
  "vite": "^5.4.11",