@tidal-ts/chart 0.24.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/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/prepare.d.ts +9 -0
- package/dist/prepare.js +45 -8
- package/dist/series.d.ts +41 -3
- package/dist/series.js +26 -0
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
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
16
|
export { levelRole, levelRoles, rowLevelMarks, type ChartLevel, type ChartLevelLine, type ChartLevelRange, type ChartLevelStyle, type LevelLineMark, type LevelRoleStyle, type LevelWashMark, } from './levels.js';
|
|
17
|
-
export { configAxisId, effectiveSplit, formatSeriesValue, isStudySeries, LINE_WIDTHS, PAIR_JOINS, PAIR_LENSES, seriesAxisId, readsCompare, drawsAsCompare, isCompareSide, seriesDrawn, seriesCategoryStyle, seriesLineDashArray, seriesLineWidth, sharedAxisId, type AxisRange, effectiveAxisBounds, clampBoundsToLocks, barZeroLock, centerOnZero, axisRangeIsEmpty, axisFormat, fractionTicks, bandColumns, configBand, configColumns, configOutputs, configSpecs, dashPattern, fanIsBand, LINE_DASHES, OUTPUT_DASHES, outputKey, outputLook, publishedColumns, type ConfigOutput, type OutputLook, type OutputStyle, hasBarOutput, offersOutputBars, logAllowed, AXIS_PRECISIONS, type PairJoinOp, type PairLensOp, type SeriesGroup, type PairPartView, type PairView, type SeriesBinding, type SeriesConfig, type CompareWith, type SeriesAxis, type SeriesStyle, type SeriesWindow, type CandleVariant, type ColorBy, readsFrom, sourcesOf, } from './series.js';
|
|
17
|
+
export { configAxisId, effectiveSplit, formatSeriesValue, isStudySeries, LINE_WIDTHS, PAIR_JOINS, PAIR_LENSES, seriesAxisId, readsCompare, drawsAsCompare, isCompareSide, seriesDrawn, seriesCategoryStyle, seriesLineDashArray, seriesLineWidth, sharedAxisId, type AxisRange, effectiveAxisBounds, clampBoundsToLocks, barZeroLock, centerOnZero, axisRangeIsEmpty, axisFormat, fractionTicks, bandColumns, configBand, configColumns, configOutputs, configSpecs, dashPattern, fanIsBand, LINE_DASHES, OUTPUT_DASHES, outputKey, outputLook, publishedColumns, type ConfigOutput, type OutputLook, type OutputStyle, hasBarOutput, offersOutputBars, logAllowed, AXIS_PRECISIONS, type PairJoinOp, type PairLensOp, type SeriesGroup, type PairPartView, type PairView, type SeriesBinding, type SeriesConfig, type CompareWith, compareWithInput, type SeriesAxis, type SeriesStyle, type SeriesWindow, type CandleVariant, type ColorBy, readsFrom, sourcesOf, } from './series.js';
|
|
18
18
|
export { DEFAULT_CHART_SETTINGS, mergeChartSettings, type AnnotationOverride, type ChartSettings, type CategoryLineStyle, type SessionDividers, type SplitColorDefault, type LineDash, } from './chartSettings.js';
|
|
19
19
|
export { useMeasuredWidth, useMeasuredSize } from './useMeasuredWidth.js';
|
|
20
20
|
export { assembleRows, carries, foldKey, foldSources, foldSourcesReport, type SourceFoldReport, prepareChart, sourceFacts, type ConfigRow, type PreparedRow, type SourceFacts, type SourceHold, type SourceInput, type SourceInputs, } from './prepare.js';
|
package/dist/index.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
*/
|
|
14
14
|
export { TimeSeriesChart, annotationInView, } from './TimeSeriesChart.js';
|
|
15
15
|
export { levelRole, levelRoles, rowLevelMarks, } from './levels.js';
|
|
16
|
-
export { configAxisId, effectiveSplit, formatSeriesValue, isStudySeries, LINE_WIDTHS, PAIR_JOINS, PAIR_LENSES, seriesAxisId, readsCompare, drawsAsCompare, isCompareSide, seriesDrawn, seriesCategoryStyle, seriesLineDashArray, seriesLineWidth, sharedAxisId, effectiveAxisBounds, clampBoundsToLocks, barZeroLock, centerOnZero, axisRangeIsEmpty, axisFormat, fractionTicks, bandColumns, configBand, configColumns, configOutputs, configSpecs, dashPattern, fanIsBand, LINE_DASHES, OUTPUT_DASHES, outputKey, outputLook, publishedColumns, hasBarOutput, offersOutputBars, logAllowed, AXIS_PRECISIONS, readsFrom, sourcesOf, } from './series.js';
|
|
16
|
+
export { configAxisId, effectiveSplit, formatSeriesValue, isStudySeries, LINE_WIDTHS, PAIR_JOINS, PAIR_LENSES, seriesAxisId, readsCompare, drawsAsCompare, isCompareSide, seriesDrawn, seriesCategoryStyle, seriesLineDashArray, seriesLineWidth, sharedAxisId, effectiveAxisBounds, clampBoundsToLocks, barZeroLock, centerOnZero, axisRangeIsEmpty, axisFormat, fractionTicks, bandColumns, configBand, configColumns, configOutputs, configSpecs, dashPattern, fanIsBand, LINE_DASHES, OUTPUT_DASHES, outputKey, outputLook, publishedColumns, hasBarOutput, offersOutputBars, logAllowed, AXIS_PRECISIONS, compareWithInput, readsFrom, sourcesOf, } from './series.js';
|
|
17
17
|
export { DEFAULT_CHART_SETTINGS, mergeChartSettings, } from './chartSettings.js';
|
|
18
18
|
export { useMeasuredWidth, useMeasuredSize } from './useMeasuredWidth.js';
|
|
19
19
|
export { assembleRows, carries, foldKey, foldSources, foldSourcesReport, prepareChart, sourceFacts, } from './prepare.js';
|
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
|
@@ -125,7 +125,7 @@ export declare function configColumns(c: {
|
|
|
125
125
|
fan?: readonly string[];
|
|
126
126
|
bandMiddle?: boolean;
|
|
127
127
|
}): string[];
|
|
128
|
-
import type { DeriveSpec, PairOp, SeriesWindow } from '@tidal-ts/core';
|
|
128
|
+
import type { DeriveInput, DeriveSpec, PairOp, SeriesWindow } from '@tidal-ts/core';
|
|
129
129
|
export type { DeriveSpec, SeriesWindow };
|
|
130
130
|
import type { CandleVariant, ColorBy } from '@pond-ts/charts';
|
|
131
131
|
export type { CandleVariant, ColorBy };
|
|
@@ -327,14 +327,32 @@ export interface SeriesConfig {
|
|
|
327
327
|
* function, it sleeps until there is a comparison again. The host does the
|
|
328
328
|
* wiring at render time and treats an `id` that no longer exists as
|
|
329
329
|
* automatic. The terminal machine drops a wiring as soon as the other side
|
|
330
|
-
* is removed or stops being
|
|
331
|
-
*
|
|
330
|
+
* is removed or the line it reads stops being drawn: it joins a pair, or a
|
|
331
|
+
* wiring with no {@link CompareWith.output} finds it drawing several lines,
|
|
332
|
+
* or the named line is no longer one of its lines.
|
|
332
333
|
*
|
|
333
334
|
* The other side is read as its own PLAIN output, never its compare — so
|
|
334
335
|
* two metrics wired to each other, or a metric wired to its own study, form
|
|
335
336
|
* no cycle.
|
|
336
337
|
*/
|
|
337
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;
|
|
338
356
|
}
|
|
339
357
|
/** A compare's hand-wired other side — see {@link SeriesConfig.compareWith}. */
|
|
340
358
|
export interface CompareWith {
|
|
@@ -342,7 +360,27 @@ export interface CompareWith {
|
|
|
342
360
|
id: string;
|
|
343
361
|
/** Read on the primary symbol, or on the comparison. */
|
|
344
362
|
side: 'primary' | 'comparison';
|
|
363
|
+
/**
|
|
364
|
+
* Which of its lines, when the other config draws several — a Bollinger's
|
|
365
|
+
* `Upper`, one column of a data node drawing open and close, one output of
|
|
366
|
+
* a fanned study — by the name {@link configOutputs} gives it. Absent for a
|
|
367
|
+
* config with one line.
|
|
368
|
+
*/
|
|
369
|
+
output?: string;
|
|
345
370
|
}
|
|
371
|
+
/**
|
|
372
|
+
* What a compare reads as its other side from `other` — the input a spec
|
|
373
|
+
* names it by ({@link CompareWith}): its spec or its raw column for one line;
|
|
374
|
+
* for one line of several, the column, the fanned spec or the PICKED output
|
|
375
|
+
* that is that line. Only a line the config DRAWS ({@link configColumns}):
|
|
376
|
+
* not a Bollinger's hidden middle, nor a third column of a two-line band.
|
|
377
|
+
*
|
|
378
|
+
* `null` when `output` names none of its drawn lines, or is missing for a
|
|
379
|
+
* config that draws several. A data node back to ONE column still answers to
|
|
380
|
+
* that column's name, so a wiring on `close` survives the node dropping
|
|
381
|
+
* `open`.
|
|
382
|
+
*/
|
|
383
|
+
export declare function compareWithInput(other: Pick<SeriesConfig, 'column' | 'derive' | 'fan' | 'style' | 'bandMiddle'>, output?: string): DeriveInput | null;
|
|
346
384
|
/** The textures in display order. */
|
|
347
385
|
export declare const LINE_DASHES: readonly LineDash[];
|
|
348
386
|
/** Ink for ONE output of a multi-output config — see
|
package/dist/series.js
CHANGED
|
@@ -154,6 +154,32 @@ export function configColumns(c) {
|
|
|
154
154
|
import { BAND_OUTPUTS, BAR_PRICE_COLUMNS, COMPARE_PREFIX, deriveId, hasPairOp, inputNames, isPairOp, isPickedInput, isStudyOp, opOutputs, opParams, outputMark, studyLevels, usesCompare, withFanOutput, } from '@tidal-ts/core';
|
|
155
155
|
// The app-wide presentation defaults the category resolvers below read.
|
|
156
156
|
import { DEFAULT_CHART_SETTINGS, } from './chartSettings.js';
|
|
157
|
+
/**
|
|
158
|
+
* What a compare reads as its other side from `other` — the input a spec
|
|
159
|
+
* names it by ({@link CompareWith}): its spec or its raw column for one line;
|
|
160
|
+
* for one line of several, the column, the fanned spec or the PICKED output
|
|
161
|
+
* that is that line. Only a line the config DRAWS ({@link configColumns}):
|
|
162
|
+
* not a Bollinger's hidden middle, nor a third column of a two-line band.
|
|
163
|
+
*
|
|
164
|
+
* `null` when `output` names none of its drawn lines, or is missing for a
|
|
165
|
+
* config that draws several. A data node back to ONE column still answers to
|
|
166
|
+
* that column's name, so a wiring on `close` survives the node dropping
|
|
167
|
+
* `open`.
|
|
168
|
+
*/
|
|
169
|
+
export function compareWithInput(other, output) {
|
|
170
|
+
const drawn = new Set(configColumns(other));
|
|
171
|
+
const lines = configOutputs(other).filter((o) => drawn.has(o.column));
|
|
172
|
+
const several = lines.length > 1 || other.style === 'band' || other.style === 'lines';
|
|
173
|
+
if (output === undefined)
|
|
174
|
+
return several ? null : (other.derive ?? other.column);
|
|
175
|
+
if (!several)
|
|
176
|
+
return !other.derive && output === other.column ? other.column : null;
|
|
177
|
+
if (!lines.some((o) => o.name === output))
|
|
178
|
+
return null;
|
|
179
|
+
if (other.fan && other.fan.length > 0)
|
|
180
|
+
return other.derive ? withFanOutput(other.derive, output) : output;
|
|
181
|
+
return other.derive ? { from: other.derive, output } : null;
|
|
182
|
+
}
|
|
157
183
|
/** The textures in display order. */
|
|
158
184
|
export const LINE_DASHES = ['solid', 'dashed', 'dotted'];
|
|
159
185
|
// --- Axis identity ------------------------------------------------------------
|
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",
|