@tidal-ts/chart 0.26.0 → 0.27.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.
package/dist/prepare.d.ts CHANGED
@@ -9,8 +9,9 @@ import type { ChartSeries } from './types.js';
9
9
  *
10
10
  * Three moves, in order:
11
11
  *
12
- * 1. {@link foldSources} — join the comparison series under the compare prefix
13
- * where a config asks for it, then fold every study spec onto its source so
12
+ * 1. {@link foldSources} — join the other symbols' series (the comparison, a
13
+ * locked symbol) where a config asks for them, then fold every study spec
14
+ * onto its source so
14
15
  * the derived columns exist before the chart reads them. A source coarser
15
16
  * than the axis is folded at its own grain and then held across the axis
16
17
  * ({@link SourceHold}).
@@ -58,10 +59,13 @@ export interface SourceInput {
58
59
  * - **A restated row wins before anything reads it.** Rows sharing a key are
59
60
  * reduced to the last one before the join and the studies, so a study never
60
61
  * counts a restatement as an extra bar.
61
- * - **The comparison joins on the coarse keys**, exactly as it does unheld: a
62
- * day the source has no row for is a gap in the comparison too, and a
63
- * comparison keyed at another time of day (04:00 against 00:00) matches
64
- * nothing. Pass both at the same grain, keyed the same way.
62
+ * - **The comparison joins on the coarse keys**, exactly as it does unheld:
63
+ * each source row takes the comparison's latest row at or before it, so a
64
+ * day the comparison has no row for carries its previous day. That is also
65
+ * why both must be keyed the same way: a comparison keyed at another time of
66
+ * day (04:00 against 00:00) would pair every day with the comparison's day
67
+ * BEFORE, with nothing to show it. Pass both at the same grain, keyed the
68
+ * same way.
65
69
  * - **Warm-up comes from the coarse rows.** A 20-day study needs 20 coarse
66
70
  * rows before the grid starts; rows before the grid cost nothing in the
67
71
  * result. Pass the source with the look-back its longest study needs.
@@ -107,8 +111,9 @@ export interface SourceFacts {
107
111
  */
108
112
  export declare function foldKey(configs: readonly SeriesConfig[]): string;
109
113
  /**
110
- * The fold: each source, joined with its comparison under the compare prefix
111
- * when any config on it asks (a compare-bound spec, or a raw compare leg), then
114
+ * The fold: each source, joined with the other symbols' series it reads (its
115
+ * comparison under the compare prefix when a compare-bound spec or a raw
116
+ * compare leg asks, each locked symbol under its own), as of each row, then
112
117
  * every study spec on it applied so the derived columns exist, then, for a
113
118
  * source with a {@link SourceHold}, held across the axis. A spec whose
114
119
  * inputs are missing is skipped by the engine and simply yields no column — the
package/dist/prepare.js CHANGED
@@ -1,4 +1,4 @@
1
- import { applyDerivedReport, COMPARE_PREFIX, holdAcrossGrid, isPinnableSymbol, joinUnderPrefix, pinnedPrefix, readsColumn, readsPrefix, } from '@tidal-ts/core';
1
+ import { applyDerivedReport, COMPARE_PREFIX, holdAcrossGrid, isPinnableSymbol, pinnedPrefix, readsColumn, readsPrefix, } from '@tidal-ts/core';
2
2
  import { configColumns, configSpecs } from './series.js';
3
3
  import { finiteColumns, lastRow } from './seriesFacts.js';
4
4
  /** The series with one row per key, the last of each run: a restatement
@@ -68,8 +68,9 @@ export function foldKey(configs) {
68
68
  return JSON.stringify([sorted, rawCompareColumns(configs)]);
69
69
  }
70
70
  /**
71
- * The fold: each source, joined with its comparison under the compare prefix
72
- * when any config on it asks (a compare-bound spec, or a raw compare leg), then
71
+ * The fold: each source, joined with the other symbols' series it reads (its
72
+ * comparison under the compare prefix when a compare-bound spec or a raw
73
+ * compare leg asks, each locked symbol under its own), as of each row, then
73
74
  * every study spec on it applied so the derived columns exist, then, for a
74
75
  * source with a {@link SourceHold}, held across the axis. A spec whose
75
76
  * inputs are missing is skipped by the engine and simply yields no column — the
@@ -99,31 +100,29 @@ export function foldSourcesReport(inputs, configs) {
99
100
  // A coarse source is folded before it is held, so a restated row has to go
100
101
  // first, or the join pairs it with nothing and a study counts it as a bar
101
102
  // (the hold alone would only pick the later row after both had happened).
102
- let series = input.hold ? lastPerKey(input.series) : input.series;
103
- const compare = input.hold && input.compare ? lastPerKey(input.compare) : input.compare;
104
- // A compare-bound leg needs the compare entity's columns on the PRIMARY
105
- // series before the fold — a left exact-key join, every conflicting column
106
- // prefixed. Only when asked and the compare series exists; otherwise the
107
- // fold's own skip leaves the spread as a gap (compare off ⇒ not drawn).
108
- // Rename-then-join lives in core (`joinUnderPrefix`; F-charts-14 for why
109
- // not the library's `onConflict: 'prefix'`).
110
- if (compare && (rawCompare.has(key) || mine.some(specReadsComparison)))
111
- series = joinUnderPrefix(series, compare);
112
- // Each locked symbol the same way, under its own prefix, and only when a
113
- // config reads that prefix: a symbol the host still holds but nothing
114
- // reads any more costs no join.
103
+ const series = input.hold ? lastPerKey(input.series) : input.series;
104
+ // The other symbols' series this source's configs read, keyed by the
105
+ // prefix their columns carry, for the engine's as-of join (core's
106
+ // `applyDerivedReport`). Each only when asked: the comparison when a
107
+ // compare-bound spec or a raw compare leg reads it (otherwise the fold's
108
+ // own skip leaves the spread as a gap — compare off ⇒ not drawn), a locked
109
+ // symbol when a config reads its prefix, so a symbol the host still holds
110
+ // but nothing reads any more costs no join. The as-of join takes the latest
111
+ // row at or before each of this source's rows, so a restated row on the
112
+ // other side resolves to its last version with no `lastPerKey` of its own.
113
+ const others = {};
114
+ if (input.compare && (rawCompare.has(key) || mine.some(specReadsComparison)))
115
+ others[COMPARE_PREFIX] = input.compare;
115
116
  for (const symbol of Object.keys(input.pinned ?? {}).sort()) {
116
117
  if (!isPinnableSymbol(symbol))
117
118
  continue;
118
119
  const prefix = pinnedPrefix(symbol);
119
120
  const asked = (rawColumns[key] ?? []).some((col) => col.startsWith(prefix)) ||
120
121
  mine.some((spec) => readsPrefix(spec, prefix));
121
- if (!asked)
122
- continue;
123
- const other = input.pinned[symbol];
124
- series = joinUnderPrefix(series, input.hold ? lastPerKey(other) : other, prefix);
122
+ if (asked)
123
+ others[prefix] = input.pinned[symbol];
125
124
  }
126
- const folded = applyDerivedReport(series, mine);
125
+ const folded = applyDerivedReport(series, mine, undefined, others);
127
126
  const out = input.hold
128
127
  ? holdAcrossGrid(folded.series, input.hold.grid, input.hold.grainMs)
129
128
  : folded.series;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tidal-ts/chart",
3
- "version": "0.26.0",
3
+ "version": "0.27.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.26.0"
41
+ "@tidal-ts/core": "0.27.0"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@pond-ts/charts": "^0.78.0",