@tidal-ts/chart 0.25.0 → 0.26.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 +9 -0
- package/dist/prepare.js +45 -8
- package/dist/series.d.ts +17 -0
- package/package.json +2 -2
package/dist/prepare.d.ts
CHANGED
|
@@ -28,6 +28,15 @@ import type { ChartSeries } from './types.js';
|
|
|
28
28
|
export interface SourceInput {
|
|
29
29
|
series: ChartSeries;
|
|
30
30
|
compare?: ChartSeries | null;
|
|
31
|
+
/**
|
|
32
|
+
* The series of each **locked symbol** a compare on this source reads
|
|
33
|
+
* (`SeriesConfig.compareOn`), keyed by the symbol: `{ SPY: … }`. Each is
|
|
34
|
+
* joined like the comparison, under `pinnedPrefix(symbol)` (`cmp_@SPY_close`),
|
|
35
|
+
* and only when a config on the source reads that prefix. Same grain and
|
|
36
|
+
* keys as `series`, as for `compare`; a key `isPinnableSymbol` refuses is
|
|
37
|
+
* never joined.
|
|
38
|
+
*/
|
|
39
|
+
pinned?: Readonly<Record<string, ChartSeries>>;
|
|
31
40
|
/** Set when `series` (and `compare`) are coarser than the axis: a daily
|
|
32
41
|
* curve on an intraday chart. Pass them at their own grain. */
|
|
33
42
|
hold?: SourceHold;
|
package/dist/prepare.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { applyDerivedReport, COMPARE_PREFIX, holdAcrossGrid, joinUnderPrefix,
|
|
1
|
+
import { applyDerivedReport, COMPARE_PREFIX, holdAcrossGrid, isPinnableSymbol, joinUnderPrefix, 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
|
|
@@ -19,16 +19,35 @@ const specsBySource = (configs) => {
|
|
|
19
19
|
(m[c.source] ??= []).push(...configSpecs(c));
|
|
20
20
|
return m;
|
|
21
21
|
};
|
|
22
|
+
/** Per source, the RAW compare columns its configs read, sorted: what decides
|
|
23
|
+
* which joins a spec-less config needs (the comparison's, a locked symbol's). */
|
|
24
|
+
const rawCompareColumns = (configs) => {
|
|
25
|
+
const m = {};
|
|
26
|
+
for (const c of configs)
|
|
27
|
+
if (c.source && !c.derive && c.column.startsWith(COMPARE_PREFIX))
|
|
28
|
+
(m[c.source] ??= new Set()).add(c.column);
|
|
29
|
+
return Object.fromEntries(Object.keys(m)
|
|
30
|
+
.sort()
|
|
31
|
+
.map((k) => [k, [...m[k]].sort()]));
|
|
32
|
+
};
|
|
22
33
|
/** Sources with a config reading a RAW compare column — a split pair's leg,
|
|
23
34
|
* which carries no spec at all but needs the compare join exactly as a
|
|
24
35
|
* compare-bound spec does. (Asking only the specs left such a leg reading a
|
|
25
36
|
* column nothing ever joined on: it drew nothing and, having no `derive`, was
|
|
26
37
|
* filtered out of the panel too — an invisible, unremovable leg.) */
|
|
27
|
-
const rawCompareSources = (configs) =>
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
38
|
+
const rawCompareSources = (configs) => Object.entries(rawCompareColumns(configs))
|
|
39
|
+
.filter(([, cols]) => cols.some(readsComparison))
|
|
40
|
+
.map(([source]) => source);
|
|
41
|
+
/** The prefix every locked symbol's columns share (`cmp_@`), which the
|
|
42
|
+
* comparison's own columns never start with. */
|
|
43
|
+
const PINNED_ANY = pinnedPrefix('').slice(0, -1);
|
|
44
|
+
/** Whether a column is the bar's COMPARISON's — under the compare prefix but
|
|
45
|
+
* not a locked symbol's, which has a join of its own. */
|
|
46
|
+
const readsComparison = (column) => column.startsWith(COMPARE_PREFIX) && !column.startsWith(PINNED_ANY);
|
|
47
|
+
/** Whether a spec reads the comparison anywhere — `usesCompare` minus the
|
|
48
|
+
* locked symbols' columns, so a compare locked to `SPY` does not pull the
|
|
49
|
+
* bar's comparison onto the series too. */
|
|
50
|
+
const specReadsComparison = (spec) => readsColumn(spec, readsComparison);
|
|
32
51
|
/**
|
|
33
52
|
* A stable string of everything {@link foldSources} depends on in the configs —
|
|
34
53
|
* the specs per source and the raw-compare set — so a host can key its fold
|
|
@@ -43,7 +62,10 @@ export function foldKey(configs) {
|
|
|
43
62
|
const sorted = Object.fromEntries(Object.keys(bySource)
|
|
44
63
|
.sort()
|
|
45
64
|
.map((source) => [source, bySource[source].map((spec) => JSON.stringify(spec)).sort()]));
|
|
46
|
-
|
|
65
|
+
// The raw compare COLUMNS, not just the sources: a raw leg reading a locked
|
|
66
|
+
// symbol (`cmp_@SPY_close`) needs that symbol's join, which a source already
|
|
67
|
+
// joining the comparison would not otherwise re-fold for.
|
|
68
|
+
return JSON.stringify([sorted, rawCompareColumns(configs)]);
|
|
47
69
|
}
|
|
48
70
|
/**
|
|
49
71
|
* The fold: each source, joined with its comparison under the compare prefix
|
|
@@ -68,6 +90,7 @@ export function foldSources(inputs, configs) {
|
|
|
68
90
|
export function foldSourcesReport(inputs, configs) {
|
|
69
91
|
const specs = specsBySource(configs);
|
|
70
92
|
const rawCompare = new Set(rawCompareSources(configs));
|
|
93
|
+
const rawColumns = rawCompareColumns(configs);
|
|
71
94
|
const sources = {};
|
|
72
95
|
const reports = {};
|
|
73
96
|
for (const [key, input] of Object.entries(inputs)) {
|
|
@@ -84,8 +107,22 @@ export function foldSourcesReport(inputs, configs) {
|
|
|
84
107
|
// fold's own skip leaves the spread as a gap (compare off ⇒ not drawn).
|
|
85
108
|
// Rename-then-join lives in core (`joinUnderPrefix`; F-charts-14 for why
|
|
86
109
|
// not the library's `onConflict: 'prefix'`).
|
|
87
|
-
if (compare && (rawCompare.has(key) || mine.some(
|
|
110
|
+
if (compare && (rawCompare.has(key) || mine.some(specReadsComparison)))
|
|
88
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.
|
|
115
|
+
for (const symbol of Object.keys(input.pinned ?? {}).sort()) {
|
|
116
|
+
if (!isPinnableSymbol(symbol))
|
|
117
|
+
continue;
|
|
118
|
+
const prefix = pinnedPrefix(symbol);
|
|
119
|
+
const asked = (rawColumns[key] ?? []).some((col) => col.startsWith(prefix)) ||
|
|
120
|
+
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);
|
|
125
|
+
}
|
|
89
126
|
const folded = applyDerivedReport(series, mine);
|
|
90
127
|
const out = input.hold
|
|
91
128
|
? holdAcrossGrid(folded.series, input.hold.grid, input.hold.grainMs)
|
package/dist/series.d.ts
CHANGED
|
@@ -336,6 +336,23 @@ export interface SeriesConfig {
|
|
|
336
336
|
* no cycle.
|
|
337
337
|
*/
|
|
338
338
|
compareWith?: CompareWith;
|
|
339
|
+
/**
|
|
340
|
+
* The symbol a compare's other side (inB) is **locked** to — `SPY` — in
|
|
341
|
+
* place of the bar's comparison. Absent ⇒ inB reads the comparison, as
|
|
342
|
+
* before. Set on the ROOT of a chain, like {@link compareFn}. What it means,
|
|
343
|
+
* which the HOST builds at render time as it does the rest of a compare: the
|
|
344
|
+
* automatic other side is the same chain on this symbol, and a wiring with
|
|
345
|
+
* `side: 'comparison'` reads the wired config on this symbol. A wiring with
|
|
346
|
+
* `side: 'primary'` reads no other symbol, so the lock changes nothing there.
|
|
347
|
+
*
|
|
348
|
+
* Unlike the rest of a compare it never SLEEPS: it does not depend on the
|
|
349
|
+
* bar, so it draws with no comparison named. The host fetches the symbol,
|
|
350
|
+
* hands it to the fold as `SourceInput.pinned`, and rebinds the chain onto
|
|
351
|
+
* its columns with `underPrefix(input, pinnedPrefix(symbol))`
|
|
352
|
+
* (`cmp_@SPY_close`). Saved with the config and
|
|
353
|
+
* carried by a preset, the one symbol a preset carries.
|
|
354
|
+
*/
|
|
355
|
+
compareOn?: string;
|
|
339
356
|
}
|
|
340
357
|
/** A compare's hand-wired other side — see {@link SeriesConfig.compareWith}. */
|
|
341
358
|
export interface CompareWith {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tidal-ts/chart",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.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.
|
|
41
|
+
"@tidal-ts/core": "0.26.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@pond-ts/charts": "^0.78.0",
|