@tidal-ts/chart 0.17.0 → 0.19.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/TimeSeriesChart.d.ts +23 -1
- package/dist/TimeSeriesChart.js +43 -15
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/levels.d.ts +153 -0
- package/dist/levels.js +139 -0
- package/dist/series.d.ts +9 -0
- package/dist/series.js +24 -1
- package/package.json +2 -2
|
@@ -2,6 +2,7 @@ import { type ReactNode } from 'react';
|
|
|
2
2
|
import type { ChartSeries } from './types.js';
|
|
3
3
|
import type { ChartContainerProps, ChartTheme, LiveValue, TrackerInfo } from '@pond-ts/charts';
|
|
4
4
|
import { aggregateColumn, type Segment } from '@tidal-ts/core';
|
|
5
|
+
import { type ChartLevel } from './levels.js';
|
|
5
6
|
import { type ChartSettings } from './chartSettings.js';
|
|
6
7
|
import { type SeriesAxis, type SeriesConfig } from './series.js';
|
|
7
8
|
/** One time marker. */
|
|
@@ -78,6 +79,13 @@ export interface TimeSeriesChartRow {
|
|
|
78
79
|
id: string;
|
|
79
80
|
height: number;
|
|
80
81
|
configs: SeriesConfig[];
|
|
82
|
+
/**
|
|
83
|
+
* Host levels: a value (or a low and a high) drawn across the plot on the
|
|
84
|
+
* axis of one of this row's series, in an ink the host chooses. Beside the
|
|
85
|
+
* study guides, never instead of them. They do not move the axis, and they
|
|
86
|
+
* hide with the series they ride on. See {@link ChartLevel}.
|
|
87
|
+
*/
|
|
88
|
+
levels?: readonly ChartLevel[];
|
|
81
89
|
}
|
|
82
90
|
export interface TimeSeriesChartProps {
|
|
83
91
|
/** The stacked rows (top → bottom), each with a resolved px `height` + configs.
|
|
@@ -197,6 +205,20 @@ export interface TimeSeriesChartProps {
|
|
|
197
205
|
* Keep the identity stable (module-level or memoised): it keys the theme memo.
|
|
198
206
|
*/
|
|
199
207
|
resolveColor?: (color: string) => string;
|
|
208
|
+
/**
|
|
209
|
+
* The **BEFORE ink** of a comparison: a concrete canvas colour that the
|
|
210
|
+
* compared side ({@link isCompareSide} — a series whose every leaf is on the
|
|
211
|
+
* comparison symbol) draws in, in place of its own. The reference keeps its
|
|
212
|
+
* own colour, so the answer is always the solid line in its own ink and the
|
|
213
|
+
* thing compared is the muted, dashed one ("before / after").
|
|
214
|
+
*
|
|
215
|
+
* The canvas only: the config keeps its colour, so an axis still takes its
|
|
216
|
+
* members' colour when they agree (a mirror and its primary share one), and
|
|
217
|
+
* a host's legend and swatches are untouched. A joined pair reads both
|
|
218
|
+
* symbols and keeps its colour. Absent (the default), colour = series, as
|
|
219
|
+
* before.
|
|
220
|
+
*/
|
|
221
|
+
compareInk?: string;
|
|
200
222
|
/**
|
|
201
223
|
* Which way a hovered axis's ink lifts: toward white on a dark surface, toward
|
|
202
224
|
* black on a light one. The one presentation fact the theme object does not
|
|
@@ -358,7 +380,7 @@ export declare function splitBarColumns(agg: ChartSeries, col: string, src: Char
|
|
|
358
380
|
* chips can track the hovered point. Memoized — the caller's hover state re-renders
|
|
359
381
|
* chips, not the canvas (keep prop identities stable).
|
|
360
382
|
*/
|
|
361
|
-
declare function TimeSeriesChartInner({ rows, sources, ohlcSources, calendarDays, annotations, coarseSources, dimmed, splitters, onTracker, onStats, pricePill, collapseWeekends, settings, timeZone, theme: base, resolveColor, colorScheme, viewRange, onViewRangeChange, panZoom, axisOptions, onAxisClick, onAxisBounds, onBarSeries, }: TimeSeriesChartProps): import("react").JSX.Element;
|
|
383
|
+
declare function TimeSeriesChartInner({ rows, sources, ohlcSources, calendarDays, annotations, coarseSources, dimmed, splitters, onTracker, onStats, pricePill, collapseWeekends, settings, timeZone, theme: base, resolveColor, compareInk, colorScheme, viewRange, onViewRangeChange, panZoom, axisOptions, onAxisClick, onAxisBounds, onBarSeries, }: TimeSeriesChartProps): import("react").JSX.Element;
|
|
362
384
|
/** Memoized export — hover state in the terminal re-renders the chips, not the
|
|
363
385
|
* canvas. */
|
|
364
386
|
export declare const TimeSeriesChart: import("react").MemoExoticComponent<typeof TimeSeriesChartInner>;
|
package/dist/TimeSeriesChart.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useRef, useCallback, Fragment, memo, useEffect, useMemo, useState, } from 'react';
|
|
3
|
-
import { AreaChart, BandChart, BarChart, Candlestick, ChartContainer, ChartRow, CrosshairCursor, Layers, LineChart, Baseline, Marker, Region, TimeAxis, YAxis, YAxisIndicator, } from '@pond-ts/charts';
|
|
3
|
+
import { AreaChart, BandChart, BarChart, Candlestick, ChartContainer, ChartRow, CrosshairCursor, Layers, LineChart, Baseline, Marker, Region, TimeAxis, YAxis, YAxisIndicator, Zone, } from '@pond-ts/charts';
|
|
4
4
|
import { segmentDiscontinuity, weekendSkip } from '@pond-ts/financial';
|
|
5
5
|
import { resolveTimeZone, aggregateColumn, hasPairOp, inferBarMs, liveWindowMs, ohlcWindow, readNumericColumn, sessionOpenLine, exactSessionSegments, sessionSegments, shiftKeys, WINDOW_MS, autoBarWindow, } from '@tidal-ts/core';
|
|
6
6
|
import { candleStyleForColor, candleStyleForPair } from './candleStyle.js';
|
|
7
7
|
import { useMeasuredWidth } from './useMeasuredWidth.js';
|
|
8
8
|
import { withAlpha } from './withAlpha.js';
|
|
9
|
+
import { FALLBACK_REGISTER, levelRoles, levelsSig, rowLevelMarks, } from './levels.js';
|
|
9
10
|
import { DEFAULT_CHART_SETTINGS } from './chartSettings.js';
|
|
10
|
-
import { configAxisId, guideLevels, seriesDrawn, configBand, configOutputs, dashPattern, outputLook, effectiveSplit, seriesAxisId, seriesLineDashArray, seriesLineWidth, sharedAxisId, axisFormat, fractionTicks, outputKey, configColumns, } from './series.js';
|
|
11
|
+
import { configAxisId, guideLevels, seriesDrawn, configBand, configOutputs, dashPattern, outputLook, effectiveSplit, seriesAxisId, seriesLineDashArray, seriesLineWidth, isCompareSide, readsCompare, sharedAxisId, axisFormat, fractionTicks, outputKey, configColumns, } from './series.js';
|
|
11
12
|
/** The schema-erased series type every layer reads. Rows carry heterogeneous
|
|
12
13
|
* sources (vol `%`, price `$`), so the chart works in the erased schema and each
|
|
13
14
|
* config names its `column`. Callers build the {@link TimeSeriesChartProps.sources} map
|
|
@@ -310,7 +311,7 @@ export function splitBarColumns(agg, col, src, hasOhlc, window, sessions) {
|
|
|
310
311
|
* chips can track the hovered point. Memoized — the caller's hover state re-renders
|
|
311
312
|
* chips, not the canvas (keep prop identities stable).
|
|
312
313
|
*/
|
|
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, panZoom = true, axisOptions, onAxisClick, onAxisBounds, onBarSeries, }) {
|
|
314
|
+
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, compareInk, colorScheme = 'dark', viewRange, onViewRangeChange, panZoom = true, axisOptions, onAxisClick, onAxisBounds, onBarSeries, }) {
|
|
314
315
|
const [ref, width] = useMeasuredWidth();
|
|
315
316
|
// Which y-axis gutter the pointer is over (the hover affordance). Axis
|
|
316
317
|
// chrome is DOM, so this repaints the gutter only — never the canvas.
|
|
@@ -342,7 +343,11 @@ function TimeSeriesChartInner({ rows, sources, ohlcSources = EMPTY_SOURCES, cale
|
|
|
342
343
|
const marks = configOutputs(c)
|
|
343
344
|
.map((o) => o.mark[0])
|
|
344
345
|
.join('');
|
|
345
|
-
|
|
346
|
+
// Which SIDE of a comparison it reads: the dash (`readsCompare`) and
|
|
347
|
+
// the before ink (`isCompareSide`) both turn on the column and spec,
|
|
348
|
+
// which a study re-pointed at the other symbol changes under one id.
|
|
349
|
+
const side = `${readsCompare(c) ? 'c' : ''}${isCompareSide(c) ? 's' : ''}`;
|
|
350
|
+
return `${c.id}:${side}:${c.color}:${sp.mode}:${sp.rise}:${sp.fall}:${c.style}:${seriesLineWidth(c, settings)}:${c.lineDash ?? ''}:${c.opacity ?? ''}:${c.fan?.join(',') ?? ''}:${marks}:${c.outputStyles ? JSON.stringify(c.outputStyles) : ''}`;
|
|
346
351
|
})
|
|
347
352
|
.join('|') +
|
|
348
353
|
'#' +
|
|
@@ -355,6 +360,9 @@ function TimeSeriesChartInner({ rows, sources, ohlcSources = EMPTY_SOURCES, cale
|
|
|
355
360
|
const annotationSig = [...new Set(annotations.map((a) => `${a.role}:${a.color}`))]
|
|
356
361
|
.sort()
|
|
357
362
|
.join('|');
|
|
363
|
+
// Each host level's ink is a theme role (the library's only channel for a
|
|
364
|
+
// mark's colour), so its style fields key the theme too.
|
|
365
|
+
const levelSig = levelsSig(rows);
|
|
358
366
|
const theme = useMemo(() => {
|
|
359
367
|
const dim = new Set(dimmed);
|
|
360
368
|
// One entry per series per draw kind — the canvas can't read the host's
|
|
@@ -367,7 +375,12 @@ function TimeSeriesChartInner({ rows, sources, ohlcSources = EMPTY_SOURCES, cale
|
|
|
367
375
|
const candle = { ...base.candle };
|
|
368
376
|
const band = { ...base.band };
|
|
369
377
|
for (const c of allConfigs) {
|
|
370
|
-
|
|
378
|
+
// The compared side draws in the host's BEFORE ink (`compareInk`); every
|
|
379
|
+
// other series in its own. Its outputs follow it, so a study on the
|
|
380
|
+
// compared leg is "before" too.
|
|
381
|
+
const before = compareInk !== undefined && isCompareSide(c);
|
|
382
|
+
const inkOf = (color) => (before ? compareInk : resolveColor(color));
|
|
383
|
+
const stroke = inkOf(c.color);
|
|
371
384
|
const isDim = dim.has(c.id);
|
|
372
385
|
// The user's opacity and the chart's dimming compose: a half-opaque line
|
|
373
386
|
// that is also dimmed is fainter still, never back to full strength.
|
|
@@ -411,7 +424,7 @@ function TimeSeriesChartInner({ rows, sources, ohlcSources = EMPTY_SOURCES, cale
|
|
|
411
424
|
c.style === 'band') {
|
|
412
425
|
configOutputs(c).forEach((out, i) => {
|
|
413
426
|
const look = outputLook(c, i, settings);
|
|
414
|
-
const ink = withAlpha(
|
|
427
|
+
const ink = withAlpha(inkOf(look.color), opacityOf(look.opacity) * (isDim ? 0.22 : 1));
|
|
415
428
|
const style = {
|
|
416
429
|
color: ink,
|
|
417
430
|
width: look.width,
|
|
@@ -463,15 +476,24 @@ function TimeSeriesChartInner({ rows, sources, ohlcSources = EMPTY_SOURCES, cale
|
|
|
463
476
|
// role, so N marks of one kind cost one entry, and the theme's own per-role
|
|
464
477
|
// `dash` survives: hue is the user's, texture stays ours (it is what tells
|
|
465
478
|
// the two kinds apart).
|
|
466
|
-
|
|
479
|
+
// Host levels (`TimeSeriesChartRow.levels`) take the same route, one role
|
|
480
|
+
// per level. A base theme with no register would leave their roles
|
|
481
|
+
// nowhere to live, so they fall back to a copy of charts' own default
|
|
482
|
+
// register: the ink every other mark already draws in there.
|
|
483
|
+
const levelRoleMap = levelRoles(rows, resolveColor, dim);
|
|
484
|
+
const register = base.annotation ?? (Object.keys(levelRoleMap).length > 0 ? FALLBACK_REGISTER : undefined);
|
|
485
|
+
const annotation = register
|
|
467
486
|
? {
|
|
468
|
-
...
|
|
469
|
-
roles:
|
|
470
|
-
...acc,
|
|
471
|
-
|
|
472
|
-
|
|
487
|
+
...register,
|
|
488
|
+
roles: {
|
|
489
|
+
...annotations.reduce((acc, a) => ({
|
|
490
|
+
...acc,
|
|
491
|
+
[a.role]: { ...acc?.[a.role], color: resolveColor(a.color) },
|
|
492
|
+
}), register.roles ?? {}),
|
|
493
|
+
...levelRoleMap,
|
|
494
|
+
},
|
|
473
495
|
}
|
|
474
|
-
:
|
|
496
|
+
: register;
|
|
475
497
|
return {
|
|
476
498
|
...base,
|
|
477
499
|
line: line,
|
|
@@ -482,7 +504,7 @@ function TimeSeriesChartInner({ rows, sources, ohlcSources = EMPTY_SOURCES, cale
|
|
|
482
504
|
annotation,
|
|
483
505
|
};
|
|
484
506
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
485
|
-
}, [base, resolveColor, themeSig, annotationSig]);
|
|
507
|
+
}, [base, resolveColor, compareInk, themeSig, annotationSig, levelSig]);
|
|
486
508
|
// The trading sessions on this axis, derived from the data rather than from a
|
|
487
509
|
// calendar. ONE session model with TWO consumers — the axis (which collapses
|
|
488
510
|
// everything between sessions) and the roll-up grid below (whose buckets must
|
|
@@ -1212,7 +1234,13 @@ function TimeSeriesChartInner({ rows, sources, ohlcSources = EMPTY_SOURCES, cale
|
|
|
1212
1234
|
// density problem — 16 across the top at 1Y, two of them
|
|
1213
1235
|
// behind our own legend. `false` (not omitted) is required:
|
|
1214
1236
|
// omitting it auto-labels with the axis formatter.
|
|
1215
|
-
label: false, role: a.role, selectable: false }, a.id))), guideLevels(drawable, row.id, (a) => axisOptions?.[a]?.scaleType === 'log').map((g) => (_jsx(Baseline, { id: g.key, value: g.value, axis: g.axis, label: false, selectable: false, role: "guide" }, g.key))),
|
|
1237
|
+
label: false, role: a.role, selectable: false }, a.id))), guideLevels(drawable, row.id, (a) => axisOptions?.[a]?.scaleType === 'log').map((g) => (_jsx(Baseline, { id: g.key, value: g.value, axis: g.axis, label: false, selectable: false, role: "guide" }, g.key))), (() => {
|
|
1238
|
+
const marks = rowLevelMarks(row.levels, drawable, row.id, (a) => axisOptions?.[a]?.scaleType === 'log');
|
|
1239
|
+
return [
|
|
1240
|
+
...marks.washes.map((w) => (_jsx(Zone, { id: w.key, from: w.from, to: w.to, axis: w.axis, role: w.role }, w.key))),
|
|
1241
|
+
...marks.lines.map((l) => (_jsx(Baseline, { id: l.key, value: l.value, axis: l.axis, label: l.label, selectable: false, role: l.role }, l.key))),
|
|
1242
|
+
];
|
|
1243
|
+
})(), [...visible].reverse().flatMap((c) => {
|
|
1216
1244
|
const src = c.source ? sources[c.source] : undefined;
|
|
1217
1245
|
// Column-level "show only what the data carries": a config
|
|
1218
1246
|
// whose column is absent from its (folded) series draws
|
package/dist/index.d.ts
CHANGED
|
@@ -13,7 +13,8 @@
|
|
|
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 {
|
|
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, 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 SeriesAxis, type SeriesStyle, type SeriesWindow, type CandleVariant, type ColorBy, readsFrom, sourcesOf, } from './series.js';
|
|
17
18
|
export { DEFAULT_CHART_SETTINGS, mergeChartSettings, type AnnotationOverride, type ChartSettings, type CategoryLineStyle, type SessionDividers, type SplitColorDefault, type LineDash, } from './chartSettings.js';
|
|
18
19
|
export { useMeasuredWidth, useMeasuredSize } from './useMeasuredWidth.js';
|
|
19
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
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
* style builders) stay internal until a consumer asks.
|
|
13
13
|
*/
|
|
14
14
|
export { TimeSeriesChart, annotationInView, } from './TimeSeriesChart.js';
|
|
15
|
-
export {
|
|
15
|
+
export { levelRole, levelRoles, rowLevelMarks, } from './levels.js';
|
|
16
|
+
export { configAxisId, effectiveSplit, formatSeriesValue, isStudySeries, LINE_WIDTHS, PAIR_JOINS, PAIR_LENSES, seriesAxisId, readsCompare, 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
17
|
export { DEFAULT_CHART_SETTINGS, mergeChartSettings, } from './chartSettings.js';
|
|
17
18
|
export { useMeasuredWidth, useMeasuredSize } from './useMeasuredWidth.js';
|
|
18
19
|
export { assembleRows, carries, foldKey, foldSources, foldSourcesReport, prepareChart, sourceFacts, } from './prepare.js';
|
package/dist/levels.d.ts
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* **Host levels** — horizontal lines a host places on a row, beside the
|
|
3
|
+
* study-catalog guides (`guideLevels`). A level is a value the host already
|
|
4
|
+
* holds, such as the last value of a series or the low and high of a window,
|
|
5
|
+
* drawn across the plot on the axis of a series in that row.
|
|
6
|
+
*
|
|
7
|
+
* Drawn with `@pond-ts/charts`' `<Baseline>` (a level, each edge of a range)
|
|
8
|
+
* and `<Zone>` (a range's wash). Like the guides, they never move an axis:
|
|
9
|
+
* the marks read the axis's scale and do not feed its extent, so the line of a
|
|
10
|
+
* level outside the window is off the plot. A level that should be on screen
|
|
11
|
+
* is the host's to frame (`axisOptions`).
|
|
12
|
+
*
|
|
13
|
+
* Library friction, recorded here for upstream (charts' annotation register):
|
|
14
|
+
*
|
|
15
|
+
* 1. **No per-mark ink.** `<Baseline>` / `<Zone>` take colour and dash only from
|
|
16
|
+
* `theme.annotation.roles[role]` ("colour is a theme concern"). Each level
|
|
17
|
+
* therefore gets its own role ({@link levelRole}), folded into the theme by
|
|
18
|
+
* {@link levelRoles} — the same route `ChartAnnotation.color` takes.
|
|
19
|
+
* 2. **No stroke width.** A baseline is always 1px, and a role cannot change
|
|
20
|
+
* it. So a level takes no `lineWidth` yet; adding one that is silently
|
|
21
|
+
* ignored would be worse than leaving it out.
|
|
22
|
+
* 3. **An inert mark is always at the back.** `selectable={false}` paints at
|
|
23
|
+
* the register's `depth[2]` (0.4 in charts' shipped themes), and a role
|
|
24
|
+
* cannot override depth. A level's `opacity` is folded into its colour, so
|
|
25
|
+
* the line reads at `opacity × depth[2]`, as the guides and the date
|
|
26
|
+
* markers do. A host wanting a level at full strength today has to raise
|
|
27
|
+
* `depth[2]` for every mark. Asked for: a per-role depth, or a per-mark
|
|
28
|
+
* opacity.
|
|
29
|
+
* 4. **A baseline's chip is not culled.** The line is clipped to the row, but
|
|
30
|
+
* `<Baseline>` places its label chip at the line's y with no clamp (`<Zone>`
|
|
31
|
+
* clamps, `<Marker>` culls). So a LABELLED level panned or pinned off the
|
|
32
|
+
* axis prints its chip over the next row or the time axis. Culling it here
|
|
33
|
+
* would need the axis domain, which the chart does not hold. Asked for: cull
|
|
34
|
+
* or clamp the chip like the rest of the family. Until then, label sparingly.
|
|
35
|
+
* 5. **The default register is private.** A base theme with no `annotation`
|
|
36
|
+
* makes charts draw in its internal default, which is not exported. The
|
|
37
|
+
* level roles need a register to live in, so {@link FALLBACK_REGISTER}
|
|
38
|
+
* copies it, and adding a level does not recolour every other mark.
|
|
39
|
+
*
|
|
40
|
+
* @module
|
|
41
|
+
*/
|
|
42
|
+
import { type SeriesConfig } from './series.js';
|
|
43
|
+
import type { LineDash } from './chartSettings.js';
|
|
44
|
+
import type { ChartTheme } from '@pond-ts/charts';
|
|
45
|
+
/** How a level draws. Every field but `color` is optional. */
|
|
46
|
+
export interface ChartLevelStyle {
|
|
47
|
+
/** A palette key (resolved by the chart's `resolveColor`) or raw CSS. */
|
|
48
|
+
color: string;
|
|
49
|
+
/** Texture. Omitted ⇒ `solid`, whatever the theme's register dash is. */
|
|
50
|
+
lineDash?: LineDash;
|
|
51
|
+
/** `0..1`, folded into the colour. Composes with the register's resting
|
|
52
|
+
* depth (see the module note) and with the series' dimming. */
|
|
53
|
+
opacity?: number;
|
|
54
|
+
}
|
|
55
|
+
/** Shared by both kinds. */
|
|
56
|
+
interface ChartLevelBase extends ChartLevelStyle {
|
|
57
|
+
/** Unique within its row. */
|
|
58
|
+
id: string;
|
|
59
|
+
/**
|
|
60
|
+
* The id of the config in THIS row whose axis the level rides on. It scales
|
|
61
|
+
* with that series, and is hidden while that series is not drawn (hidden, or
|
|
62
|
+
* its column absent). A config in another row draws nothing.
|
|
63
|
+
*/
|
|
64
|
+
series: string;
|
|
65
|
+
}
|
|
66
|
+
/** One value: a horizontal line across the plot. */
|
|
67
|
+
export interface ChartLevelLine extends ChartLevelBase {
|
|
68
|
+
kind: 'level';
|
|
69
|
+
value: number;
|
|
70
|
+
/** A chip at the line's left end. Omitted ⇒ no chip. */
|
|
71
|
+
label?: string;
|
|
72
|
+
}
|
|
73
|
+
/** A low and a high: two lines, optionally with a wash between them. */
|
|
74
|
+
export interface ChartLevelRange extends ChartLevelBase {
|
|
75
|
+
kind: 'range';
|
|
76
|
+
low: number;
|
|
77
|
+
high: number;
|
|
78
|
+
/** A chip on each edge. Omitted ⇒ none. */
|
|
79
|
+
labels?: {
|
|
80
|
+
low?: string;
|
|
81
|
+
high?: string;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Opacity (`0..1`) of a wash between the two lines, in the level's colour.
|
|
85
|
+
* Omitted (or `0`) ⇒ the two lines alone. Keep it light: the wash paints
|
|
86
|
+
* over the data, like every annotation. `0.1` is the register's own fill.
|
|
87
|
+
* The level's `opacity` scales it too; the register's depth does not.
|
|
88
|
+
*/
|
|
89
|
+
fill?: number;
|
|
90
|
+
}
|
|
91
|
+
/** A host level on a row: one value, or a range. */
|
|
92
|
+
export type ChartLevel = ChartLevelLine | ChartLevelRange;
|
|
93
|
+
/** The theme role a level draws in. Unique per (row, level id). */
|
|
94
|
+
export declare const levelRole: (rowId: string, levelId: string) => string;
|
|
95
|
+
/**
|
|
96
|
+
* charts' internal annotation register (`DEFAULT_ANNOTATION`, not exported):
|
|
97
|
+
* what a base theme with no `annotation` draws in. The chart supplies it only
|
|
98
|
+
* when it must add level roles, so the guides and date markers keep their ink.
|
|
99
|
+
*/
|
|
100
|
+
export declare const FALLBACK_REGISTER: NonNullable<ChartTheme['annotation']>;
|
|
101
|
+
/** One `<Baseline>` to draw. */
|
|
102
|
+
export interface LevelLineMark {
|
|
103
|
+
key: string;
|
|
104
|
+
role: string;
|
|
105
|
+
axis: string;
|
|
106
|
+
value: number;
|
|
107
|
+
/** `false` ⇒ no chip. */
|
|
108
|
+
label: string | false;
|
|
109
|
+
}
|
|
110
|
+
/** One `<Zone>` (a range's wash) to draw. */
|
|
111
|
+
export interface LevelWashMark {
|
|
112
|
+
key: string;
|
|
113
|
+
role: string;
|
|
114
|
+
axis: string;
|
|
115
|
+
from: number;
|
|
116
|
+
to: number;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* What a row's host levels draw: one line per level, two per range, and a
|
|
120
|
+
* wash per range with a `fill`. Only levels whose `series` is in `drawn` (the
|
|
121
|
+
* row's drawn configs); each on that config's axis ({@link configAxisId}).
|
|
122
|
+
*
|
|
123
|
+
* A non-finite value draws nothing. On a log axis a value at or below zero
|
|
124
|
+
* draws nothing (as the guides skip theirs), and a range with such an edge
|
|
125
|
+
* keeps its other line but loses its wash.
|
|
126
|
+
*/
|
|
127
|
+
export declare function rowLevelMarks(levels: readonly ChartLevel[] | undefined, drawn: readonly SeriesConfig[], rowId: string, isLog?: (axisId: string) => boolean): {
|
|
128
|
+
lines: LevelLineMark[];
|
|
129
|
+
washes: LevelWashMark[];
|
|
130
|
+
};
|
|
131
|
+
/** A role entry, as `theme.annotation.roles` takes it. */
|
|
132
|
+
export interface LevelRoleStyle {
|
|
133
|
+
color: string;
|
|
134
|
+
dash: readonly number[];
|
|
135
|
+
fillOpacity?: number;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* The theme roles every host level draws in, keyed by {@link levelRole}. Its
|
|
139
|
+
* colour is resolved and carries the level's `opacity` (and the chart's
|
|
140
|
+
* dimming, when the series it rides on is dimmed, at the same `0.22` a series
|
|
141
|
+
* takes). `dash` is always stated, so a `solid` level stays solid on a theme
|
|
142
|
+
* whose register is dashed.
|
|
143
|
+
*/
|
|
144
|
+
export declare function levelRoles(rows: readonly {
|
|
145
|
+
id: string;
|
|
146
|
+
levels?: readonly ChartLevel[];
|
|
147
|
+
}[], resolveColor: (color: string) => string, dimmed?: ReadonlySet<string>): Record<string, LevelRoleStyle>;
|
|
148
|
+
/** The theme-shaping fields of every row's levels, as one memo key. */
|
|
149
|
+
export declare function levelsSig(rows: readonly {
|
|
150
|
+
id: string;
|
|
151
|
+
levels?: readonly ChartLevel[];
|
|
152
|
+
}[]): string;
|
|
153
|
+
export {};
|
package/dist/levels.js
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* **Host levels** — horizontal lines a host places on a row, beside the
|
|
3
|
+
* study-catalog guides (`guideLevels`). A level is a value the host already
|
|
4
|
+
* holds, such as the last value of a series or the low and high of a window,
|
|
5
|
+
* drawn across the plot on the axis of a series in that row.
|
|
6
|
+
*
|
|
7
|
+
* Drawn with `@pond-ts/charts`' `<Baseline>` (a level, each edge of a range)
|
|
8
|
+
* and `<Zone>` (a range's wash). Like the guides, they never move an axis:
|
|
9
|
+
* the marks read the axis's scale and do not feed its extent, so the line of a
|
|
10
|
+
* level outside the window is off the plot. A level that should be on screen
|
|
11
|
+
* is the host's to frame (`axisOptions`).
|
|
12
|
+
*
|
|
13
|
+
* Library friction, recorded here for upstream (charts' annotation register):
|
|
14
|
+
*
|
|
15
|
+
* 1. **No per-mark ink.** `<Baseline>` / `<Zone>` take colour and dash only from
|
|
16
|
+
* `theme.annotation.roles[role]` ("colour is a theme concern"). Each level
|
|
17
|
+
* therefore gets its own role ({@link levelRole}), folded into the theme by
|
|
18
|
+
* {@link levelRoles} — the same route `ChartAnnotation.color` takes.
|
|
19
|
+
* 2. **No stroke width.** A baseline is always 1px, and a role cannot change
|
|
20
|
+
* it. So a level takes no `lineWidth` yet; adding one that is silently
|
|
21
|
+
* ignored would be worse than leaving it out.
|
|
22
|
+
* 3. **An inert mark is always at the back.** `selectable={false}` paints at
|
|
23
|
+
* the register's `depth[2]` (0.4 in charts' shipped themes), and a role
|
|
24
|
+
* cannot override depth. A level's `opacity` is folded into its colour, so
|
|
25
|
+
* the line reads at `opacity × depth[2]`, as the guides and the date
|
|
26
|
+
* markers do. A host wanting a level at full strength today has to raise
|
|
27
|
+
* `depth[2]` for every mark. Asked for: a per-role depth, or a per-mark
|
|
28
|
+
* opacity.
|
|
29
|
+
* 4. **A baseline's chip is not culled.** The line is clipped to the row, but
|
|
30
|
+
* `<Baseline>` places its label chip at the line's y with no clamp (`<Zone>`
|
|
31
|
+
* clamps, `<Marker>` culls). So a LABELLED level panned or pinned off the
|
|
32
|
+
* axis prints its chip over the next row or the time axis. Culling it here
|
|
33
|
+
* would need the axis domain, which the chart does not hold. Asked for: cull
|
|
34
|
+
* or clamp the chip like the rest of the family. Until then, label sparingly.
|
|
35
|
+
* 5. **The default register is private.** A base theme with no `annotation`
|
|
36
|
+
* makes charts draw in its internal default, which is not exported. The
|
|
37
|
+
* level roles need a register to live in, so {@link FALLBACK_REGISTER}
|
|
38
|
+
* copies it, and adding a level does not recolour every other mark.
|
|
39
|
+
*
|
|
40
|
+
* @module
|
|
41
|
+
*/
|
|
42
|
+
import { configAxisId, dashPattern } from './series.js';
|
|
43
|
+
import { withAlpha } from './withAlpha.js';
|
|
44
|
+
/** The theme role a level draws in. Unique per (row, level id). */
|
|
45
|
+
export const levelRole = (rowId, levelId) => `level\u0000${rowId}\u0000${levelId}`;
|
|
46
|
+
/**
|
|
47
|
+
* charts' internal annotation register (`DEFAULT_ANNOTATION`, not exported):
|
|
48
|
+
* what a base theme with no `annotation` draws in. The chart supplies it only
|
|
49
|
+
* when it must add level roles, so the guides and date markers keep their ink.
|
|
50
|
+
*/
|
|
51
|
+
export const FALLBACK_REGISTER = {
|
|
52
|
+
color: '#14b8a6',
|
|
53
|
+
fillOpacity: 0.1,
|
|
54
|
+
depth: [1, 0.7, 0.4],
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* What a row's host levels draw: one line per level, two per range, and a
|
|
58
|
+
* wash per range with a `fill`. Only levels whose `series` is in `drawn` (the
|
|
59
|
+
* row's drawn configs); each on that config's axis ({@link configAxisId}).
|
|
60
|
+
*
|
|
61
|
+
* A non-finite value draws nothing. On a log axis a value at or below zero
|
|
62
|
+
* draws nothing (as the guides skip theirs), and a range with such an edge
|
|
63
|
+
* keeps its other line but loses its wash.
|
|
64
|
+
*/
|
|
65
|
+
export function rowLevelMarks(levels, drawn, rowId, isLog = () => false) {
|
|
66
|
+
const lines = [];
|
|
67
|
+
const washes = [];
|
|
68
|
+
if (!levels || levels.length === 0)
|
|
69
|
+
return { lines, washes };
|
|
70
|
+
const byId = new Map(drawn.map((c) => [c.id, c]));
|
|
71
|
+
for (const l of levels) {
|
|
72
|
+
const c = byId.get(l.series);
|
|
73
|
+
if (!c)
|
|
74
|
+
continue;
|
|
75
|
+
const axis = configAxisId(rowId, c);
|
|
76
|
+
const log = isLog(axis);
|
|
77
|
+
const ok = (v) => Number.isFinite(v) && !(log && v <= 0);
|
|
78
|
+
const role = levelRole(rowId, l.id);
|
|
79
|
+
// The role doubles as the key: NUL-separated, so no row or level id can
|
|
80
|
+
// collide with another's, nor with a host's own annotation role or id.
|
|
81
|
+
const key = role;
|
|
82
|
+
if (l.kind === 'level') {
|
|
83
|
+
if (ok(l.value))
|
|
84
|
+
lines.push({ key, role, axis, value: l.value, label: l.label || false });
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
if (ok(l.low))
|
|
88
|
+
lines.push({
|
|
89
|
+
key: `${key}\u0000low`,
|
|
90
|
+
role,
|
|
91
|
+
axis,
|
|
92
|
+
value: l.low,
|
|
93
|
+
label: l.labels?.low || false,
|
|
94
|
+
});
|
|
95
|
+
if (ok(l.high))
|
|
96
|
+
lines.push({
|
|
97
|
+
key: `${key}\u0000high`,
|
|
98
|
+
role,
|
|
99
|
+
axis,
|
|
100
|
+
value: l.high,
|
|
101
|
+
label: l.labels?.high || false,
|
|
102
|
+
});
|
|
103
|
+
if (l.fill !== undefined && l.fill > 0 && ok(l.low) && ok(l.high)) {
|
|
104
|
+
washes.push({ key: `${key}\u0000fill`, role, axis, from: l.low, to: l.high });
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return { lines, washes };
|
|
108
|
+
}
|
|
109
|
+
const unit = (o) => typeof o === 'number' && Number.isFinite(o) ? Math.min(1, Math.max(0, o)) : 1;
|
|
110
|
+
/**
|
|
111
|
+
* The theme roles every host level draws in, keyed by {@link levelRole}. Its
|
|
112
|
+
* colour is resolved and carries the level's `opacity` (and the chart's
|
|
113
|
+
* dimming, when the series it rides on is dimmed, at the same `0.22` a series
|
|
114
|
+
* takes). `dash` is always stated, so a `solid` level stays solid on a theme
|
|
115
|
+
* whose register is dashed.
|
|
116
|
+
*/
|
|
117
|
+
export function levelRoles(rows, resolveColor, dimmed = new Set()) {
|
|
118
|
+
const out = {};
|
|
119
|
+
for (const r of rows) {
|
|
120
|
+
for (const l of r.levels ?? []) {
|
|
121
|
+
const alpha = unit(l.opacity) * (dimmed.has(l.series) ? 0.22 : 1);
|
|
122
|
+
const dash = dashPattern(l.lineDash);
|
|
123
|
+
out[levelRole(r.id, l.id)] = {
|
|
124
|
+
color: withAlpha(resolveColor(l.color), alpha),
|
|
125
|
+
dash: dash ? [...dash] : [],
|
|
126
|
+
...(l.kind === 'range' && l.fill !== undefined && l.fill > 0
|
|
127
|
+
? { fillOpacity: unit(l.fill) }
|
|
128
|
+
: {}),
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return out;
|
|
133
|
+
}
|
|
134
|
+
/** The theme-shaping fields of every row's levels, as one memo key. */
|
|
135
|
+
export function levelsSig(rows) {
|
|
136
|
+
return rows
|
|
137
|
+
.flatMap((r) => (r.levels ?? []).map((l) => `${r.id}\u0000${l.id}\u0000${l.series}\u0000${l.color}\u0000${l.lineDash ?? ''}\u0000${l.opacity ?? ''}\u0000${l.kind === 'range' ? (l.fill ?? '') : ''}`))
|
|
138
|
+
.join('|');
|
|
139
|
+
}
|
package/dist/series.d.ts
CHANGED
|
@@ -610,6 +610,15 @@ export declare function isStudySeries(s: SeriesConfig): boolean;
|
|
|
610
610
|
/** True if a series reads the COMPARISON symbol — a spec whose leaves are
|
|
611
611
|
* `cmp_`-prefixed, or (an unjoined pair's leg) a raw `cmp_` column. */
|
|
612
612
|
export declare function readsCompare(s: Pick<SeriesConfig, 'derive' | 'column'>): boolean;
|
|
613
|
+
/**
|
|
614
|
+
* True if a series is the **compared side** of a comparison: every leaf it
|
|
615
|
+
* reads is on the comparison symbol (a raw `cmp_` column, or a study whose
|
|
616
|
+
* inputs are all `cmp_`). Narrower than {@link readsCompare}: a joined pair
|
|
617
|
+
* such as `ratio(iv21, cmp_iv21)` reads both symbols, so it is the ANSWER of
|
|
618
|
+
* the comparison, not its "before" — it is dashed (it reads the compare) but
|
|
619
|
+
* keeps its own colour under {@link TimeSeriesChartProps.compareInk}.
|
|
620
|
+
*/
|
|
621
|
+
export declare function isCompareSide(s: Pick<SeriesConfig, 'derive' | 'column'>): boolean;
|
|
613
622
|
/** The style category a series' line defaults come from. A comparison-reading
|
|
614
623
|
* series takes the `comparisons` category (dashed) whatever else it is — the
|
|
615
624
|
* texture encodes the SYMBOL, so a study of a compare leg is dashed too. */
|
package/dist/series.js
CHANGED
|
@@ -151,7 +151,7 @@ export function configColumns(c) {
|
|
|
151
151
|
// `@tidal-ts/core` (where the windowing + derive seam live) — imported for
|
|
152
152
|
// `SeriesConfig` below and re-exported so UI code has one import site for the
|
|
153
153
|
// series vocabulary.
|
|
154
|
-
import { BAND_OUTPUTS, BAR_PRICE_COLUMNS, COMPARE_PREFIX, deriveId, inputNames, isPairOp, isStudyOp, opOutputs, opParams, outputMark, studyLevels, usesCompare, withFanOutput, } from '@tidal-ts/core';
|
|
154
|
+
import { BAND_OUTPUTS, BAR_PRICE_COLUMNS, COMPARE_PREFIX, deriveId, 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
157
|
/** The textures in display order. */
|
|
@@ -416,6 +416,29 @@ export function isStudySeries(s) {
|
|
|
416
416
|
export function readsCompare(s) {
|
|
417
417
|
return s.derive ? usesCompare(s.derive) : s.column.startsWith(COMPARE_PREFIX);
|
|
418
418
|
}
|
|
419
|
+
/**
|
|
420
|
+
* True if a series is the **compared side** of a comparison: every leaf it
|
|
421
|
+
* reads is on the comparison symbol (a raw `cmp_` column, or a study whose
|
|
422
|
+
* inputs are all `cmp_`). Narrower than {@link readsCompare}: a joined pair
|
|
423
|
+
* such as `ratio(iv21, cmp_iv21)` reads both symbols, so it is the ANSWER of
|
|
424
|
+
* the comparison, not its "before" — it is dashed (it reads the compare) but
|
|
425
|
+
* keeps its own colour under {@link TimeSeriesChartProps.compareInk}.
|
|
426
|
+
*/
|
|
427
|
+
export function isCompareSide(s) {
|
|
428
|
+
return s.derive ? onlyCompare(s.derive) : s.column.startsWith(COMPARE_PREFIX);
|
|
429
|
+
}
|
|
430
|
+
/** Every leaf of a spec is on the comparison symbol (and it has one) — the
|
|
431
|
+
* "all" twin of core's `usesCompare`, walked the same way. */
|
|
432
|
+
function onlyCompare(spec) {
|
|
433
|
+
// Safe on any persisted shape, as `usesCompare` is.
|
|
434
|
+
if (!spec || typeof spec !== 'object')
|
|
435
|
+
return false;
|
|
436
|
+
const leaves = (spec.inputs ?? []).filter((i) => typeof i === 'string' || (typeof i === 'object' && i !== null));
|
|
437
|
+
return (leaves.length > 0 &&
|
|
438
|
+
leaves.every((i) => typeof i === 'string'
|
|
439
|
+
? i.startsWith(COMPARE_PREFIX)
|
|
440
|
+
: onlyCompare(isPickedInput(i) ? i.from : i)));
|
|
441
|
+
}
|
|
419
442
|
/** The style category a series' line defaults come from. A comparison-reading
|
|
420
443
|
* series takes the `comparisons` category (dashed) whatever else it is — the
|
|
421
444
|
* texture encodes the SYMBOL, so a study of a compare leg is dashed too. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tidal-ts/chart",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.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.19.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@pond-ts/charts": "^0.75.0",
|