@tidal-ts/chart 0.19.0 → 0.21.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/README.md +2 -2
- package/dist/TimeSeriesChart.js +12 -5
- package/dist/levels.d.ts +29 -35
- package/dist/levels.js +27 -37
- package/package.json +11 -11
package/README.md
CHANGED
|
@@ -20,8 +20,8 @@ version number.
|
|
|
20
20
|
## Install
|
|
21
21
|
|
|
22
22
|
```bash
|
|
23
|
-
npm install --save-exact @tidal-ts/core @tidal-ts/chart @pond-ts/process@0.
|
|
24
|
-
npm install pond-ts@~0.
|
|
23
|
+
npm install --save-exact @tidal-ts/core @tidal-ts/chart @pond-ts/process@0.78.0
|
|
24
|
+
npm install pond-ts@~0.78.0 @pond-ts/financial@~0.78.0 @pond-ts/charts@~0.78.0 @pond-ts/react@~0.78.0
|
|
25
25
|
```
|
|
26
26
|
|
|
27
27
|
React 18 or 19. The pond packages are peer dependencies: install them once, on
|
package/dist/TimeSeriesChart.js
CHANGED
|
@@ -6,7 +6,7 @@ import { resolveTimeZone, aggregateColumn, hasPairOp, inferBarMs, liveWindowMs,
|
|
|
6
6
|
import { candleStyleForColor, candleStyleForPair } from './candleStyle.js';
|
|
7
7
|
import { useMeasuredWidth } from './useMeasuredWidth.js';
|
|
8
8
|
import { withAlpha } from './withAlpha.js';
|
|
9
|
-
import {
|
|
9
|
+
import { levelRoles, levelsSig, rowLevelMarks } from './levels.js';
|
|
10
10
|
import { DEFAULT_CHART_SETTINGS } from './chartSettings.js';
|
|
11
11
|
import { configAxisId, guideLevels, seriesDrawn, configBand, configOutputs, dashPattern, outputLook, effectiveSplit, seriesAxisId, seriesLineDashArray, seriesLineWidth, isCompareSide, readsCompare, sharedAxisId, axisFormat, fractionTicks, outputKey, configColumns, } from './series.js';
|
|
12
12
|
/** The schema-erased series type every layer reads. Rows carry heterogeneous
|
|
@@ -401,12 +401,19 @@ function TimeSeriesChartInner({ rows, sources, ohlcSources = EMPTY_SOURCES, cale
|
|
|
401
401
|
};
|
|
402
402
|
// Area fill wants a solid hex for its gradient, so dim via fillOpacity (not
|
|
403
403
|
// an rgba fill); the outline still carries the dim.
|
|
404
|
+
//
|
|
405
|
+
// The outline takes the series' dash exactly as a line does (charts
|
|
406
|
+
// 0.78 `AreaStyle.dash` dashes the top edge, never the fill). That is
|
|
407
|
+
// what lets a comparison keep an area as an area: the compared side is
|
|
408
|
+
// the same shape with a dashed rim, the "before" of before / after. A
|
|
409
|
+
// user-picked texture on an area reaches the canvas by the same road.
|
|
404
410
|
area[c.id] = {
|
|
405
411
|
...base.area.default,
|
|
406
412
|
color,
|
|
407
413
|
width,
|
|
408
414
|
fill: stroke,
|
|
409
415
|
fillOpacity: (isDim ? 0.04 : 0.14) * own,
|
|
416
|
+
...(dash ? { dash: [...dash] } : {}),
|
|
410
417
|
};
|
|
411
418
|
// A band is a WASH, not a fill under a line: it carries no outline of its
|
|
412
419
|
// own (the middle band draws that, as an ordinary line under the same
|
|
@@ -477,11 +484,11 @@ function TimeSeriesChartInner({ rows, sources, ohlcSources = EMPTY_SOURCES, cale
|
|
|
477
484
|
// `dash` survives: hue is the user's, texture stays ours (it is what tells
|
|
478
485
|
// the two kinds apart).
|
|
479
486
|
// Host levels (`TimeSeriesChartRow.levels`) take the same route, one role
|
|
480
|
-
// per level. A base theme with no register
|
|
481
|
-
//
|
|
482
|
-
//
|
|
487
|
+
// per level. A base theme with no register gets one holding only those
|
|
488
|
+
// roles: charts fills every field it leaves out from `defaultAnnotation`,
|
|
489
|
+
// the ink every other mark already draws in there.
|
|
483
490
|
const levelRoleMap = levelRoles(rows, resolveColor, dim);
|
|
484
|
-
const register = base.annotation ?? (Object.keys(levelRoleMap).length > 0 ?
|
|
491
|
+
const register = base.annotation ?? (Object.keys(levelRoleMap).length > 0 ? {} : undefined);
|
|
485
492
|
const annotation = register
|
|
486
493
|
? {
|
|
487
494
|
...register,
|
package/dist/levels.d.ts
CHANGED
|
@@ -10,47 +10,42 @@
|
|
|
10
10
|
* level outside the window is off the plot. A level that should be on screen
|
|
11
11
|
* is the host's to frame (`axisOptions`).
|
|
12
12
|
*
|
|
13
|
-
*
|
|
13
|
+
* How it meets charts' annotation register:
|
|
14
14
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
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.
|
|
15
|
+
* - **Ink by role.** `<Baseline>` / `<Zone>` take colour from
|
|
16
|
+
* `theme.annotation.roles[role]` ("colour is a theme concern"), so each level
|
|
17
|
+
* gets its own role ({@link levelRole}), folded into the theme by
|
|
18
|
+
* {@link levelRoles}, the same route `ChartAnnotation.color` takes. The role
|
|
19
|
+
* carries the level's dash, `lineWidth` and wash too.
|
|
20
|
+
* - **`opacity` is the line's opacity.** An inert mark paints at its role's
|
|
21
|
+
* `depth[2]`, so each level's role sets its depth to `[1, 1, 1]`: the line
|
|
22
|
+
* reads at the level's own `opacity`, not at that times the register's
|
|
23
|
+
* resting depth (0.4 in charts' themes) as it did before charts 0.76.
|
|
24
|
+
* - **A chip stays in its row.** Since charts 0.77 `<Baseline>` hides a line
|
|
25
|
+
* and its chip when the value is off the visible y-range, and keeps a chip
|
|
26
|
+
* near the edge inside the row.
|
|
27
|
+
* - **A bare theme keeps its ink.** A theme with no `annotation` gets one
|
|
28
|
+
* holding only the level roles; charts fills the rest from its
|
|
29
|
+
* `defaultAnnotation`, which is what it drew in anyway.
|
|
30
|
+
*
|
|
31
|
+
* Still open upstream: no per-mark colour prop, so a level is one theme role.
|
|
39
32
|
*
|
|
40
33
|
* @module
|
|
41
34
|
*/
|
|
42
35
|
import { type SeriesConfig } from './series.js';
|
|
43
36
|
import type { LineDash } from './chartSettings.js';
|
|
44
|
-
import type { ChartTheme } from '@pond-ts/charts';
|
|
45
37
|
/** How a level draws. Every field but `color` is optional. */
|
|
46
38
|
export interface ChartLevelStyle {
|
|
47
39
|
/** A palette key (resolved by the chart's `resolveColor`) or raw CSS. */
|
|
48
40
|
color: string;
|
|
49
41
|
/** Texture. Omitted ⇒ `solid`, whatever the theme's register dash is. */
|
|
50
42
|
lineDash?: LineDash;
|
|
51
|
-
/** `0..1`, folded into the colour
|
|
52
|
-
*
|
|
43
|
+
/** `0..1`, folded into the colour: the line's own opacity (see the module
|
|
44
|
+
* note). Composes with the series' dimming. Omitted ⇒ `1`. */
|
|
53
45
|
opacity?: number;
|
|
46
|
+
/** Stroke width in px, for the line (or both edges of a range). Omitted ⇒
|
|
47
|
+
* the theme's annotation `lineWidth`, else `1`. */
|
|
48
|
+
lineWidth?: number;
|
|
54
49
|
}
|
|
55
50
|
/** Shared by both kinds. */
|
|
56
51
|
interface ChartLevelBase extends ChartLevelStyle {
|
|
@@ -92,12 +87,6 @@ export interface ChartLevelRange extends ChartLevelBase {
|
|
|
92
87
|
export type ChartLevel = ChartLevelLine | ChartLevelRange;
|
|
93
88
|
/** The theme role a level draws in. Unique per (row, level id). */
|
|
94
89
|
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
90
|
/** One `<Baseline>` to draw. */
|
|
102
91
|
export interface LevelLineMark {
|
|
103
92
|
key: string;
|
|
@@ -132,6 +121,10 @@ export declare function rowLevelMarks(levels: readonly ChartLevel[] | undefined,
|
|
|
132
121
|
export interface LevelRoleStyle {
|
|
133
122
|
color: string;
|
|
134
123
|
dash: readonly number[];
|
|
124
|
+
/** Always `[1, 1, 1]`: an inert mark paints at `depth[2]`, and a level's
|
|
125
|
+
* strength is its `opacity`, already in `color`. */
|
|
126
|
+
depth: readonly [number, number, number];
|
|
127
|
+
lineWidth?: number;
|
|
135
128
|
fillOpacity?: number;
|
|
136
129
|
}
|
|
137
130
|
/**
|
|
@@ -139,7 +132,8 @@ export interface LevelRoleStyle {
|
|
|
139
132
|
* colour is resolved and carries the level's `opacity` (and the chart's
|
|
140
133
|
* dimming, when the series it rides on is dimmed, at the same `0.22` a series
|
|
141
134
|
* takes). `dash` is always stated, so a `solid` level stays solid on a theme
|
|
142
|
-
* whose register is dashed
|
|
135
|
+
* whose register is dashed, and `depth` is always `[1, 1, 1]`, so the line
|
|
136
|
+
* reads at that colour. `lineWidth` is set only when the level gives one.
|
|
143
137
|
*/
|
|
144
138
|
export declare function levelRoles(rows: readonly {
|
|
145
139
|
id: string;
|
package/dist/levels.js
CHANGED
|
@@ -10,32 +10,25 @@
|
|
|
10
10
|
* level outside the window is off the plot. A level that should be on screen
|
|
11
11
|
* is the host's to frame (`axisOptions`).
|
|
12
12
|
*
|
|
13
|
-
*
|
|
13
|
+
* How it meets charts' annotation register:
|
|
14
14
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
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.
|
|
15
|
+
* - **Ink by role.** `<Baseline>` / `<Zone>` take colour from
|
|
16
|
+
* `theme.annotation.roles[role]` ("colour is a theme concern"), so each level
|
|
17
|
+
* gets its own role ({@link levelRole}), folded into the theme by
|
|
18
|
+
* {@link levelRoles}, the same route `ChartAnnotation.color` takes. The role
|
|
19
|
+
* carries the level's dash, `lineWidth` and wash too.
|
|
20
|
+
* - **`opacity` is the line's opacity.** An inert mark paints at its role's
|
|
21
|
+
* `depth[2]`, so each level's role sets its depth to `[1, 1, 1]`: the line
|
|
22
|
+
* reads at the level's own `opacity`, not at that times the register's
|
|
23
|
+
* resting depth (0.4 in charts' themes) as it did before charts 0.76.
|
|
24
|
+
* - **A chip stays in its row.** Since charts 0.77 `<Baseline>` hides a line
|
|
25
|
+
* and its chip when the value is off the visible y-range, and keeps a chip
|
|
26
|
+
* near the edge inside the row.
|
|
27
|
+
* - **A bare theme keeps its ink.** A theme with no `annotation` gets one
|
|
28
|
+
* holding only the level roles; charts fills the rest from its
|
|
29
|
+
* `defaultAnnotation`, which is what it drew in anyway.
|
|
30
|
+
*
|
|
31
|
+
* Still open upstream: no per-mark colour prop, so a level is one theme role.
|
|
39
32
|
*
|
|
40
33
|
* @module
|
|
41
34
|
*/
|
|
@@ -43,16 +36,6 @@ import { configAxisId, dashPattern } from './series.js';
|
|
|
43
36
|
import { withAlpha } from './withAlpha.js';
|
|
44
37
|
/** The theme role a level draws in. Unique per (row, level id). */
|
|
45
38
|
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
39
|
/**
|
|
57
40
|
* What a row's host levels draw: one line per level, two per range, and a
|
|
58
41
|
* wash per range with a `fill`. Only levels whose `series` is in `drawn` (the
|
|
@@ -106,13 +89,16 @@ export function rowLevelMarks(levels, drawn, rowId, isLog = () => false) {
|
|
|
106
89
|
}
|
|
107
90
|
return { lines, washes };
|
|
108
91
|
}
|
|
92
|
+
/** A level's depth ramp: every level at full strength, so `opacity` rules. */
|
|
93
|
+
const LEVEL_DEPTH = [1, 1, 1];
|
|
109
94
|
const unit = (o) => typeof o === 'number' && Number.isFinite(o) ? Math.min(1, Math.max(0, o)) : 1;
|
|
110
95
|
/**
|
|
111
96
|
* The theme roles every host level draws in, keyed by {@link levelRole}. Its
|
|
112
97
|
* colour is resolved and carries the level's `opacity` (and the chart's
|
|
113
98
|
* dimming, when the series it rides on is dimmed, at the same `0.22` a series
|
|
114
99
|
* takes). `dash` is always stated, so a `solid` level stays solid on a theme
|
|
115
|
-
* whose register is dashed
|
|
100
|
+
* whose register is dashed, and `depth` is always `[1, 1, 1]`, so the line
|
|
101
|
+
* reads at that colour. `lineWidth` is set only when the level gives one.
|
|
116
102
|
*/
|
|
117
103
|
export function levelRoles(rows, resolveColor, dimmed = new Set()) {
|
|
118
104
|
const out = {};
|
|
@@ -123,6 +109,10 @@ export function levelRoles(rows, resolveColor, dimmed = new Set()) {
|
|
|
123
109
|
out[levelRole(r.id, l.id)] = {
|
|
124
110
|
color: withAlpha(resolveColor(l.color), alpha),
|
|
125
111
|
dash: dash ? [...dash] : [],
|
|
112
|
+
depth: LEVEL_DEPTH,
|
|
113
|
+
...(typeof l.lineWidth === 'number' && Number.isFinite(l.lineWidth) && l.lineWidth > 0
|
|
114
|
+
? { lineWidth: l.lineWidth }
|
|
115
|
+
: {}),
|
|
126
116
|
...(l.kind === 'range' && l.fill !== undefined && l.fill > 0
|
|
127
117
|
? { fillOpacity: unit(l.fill) }
|
|
128
118
|
: {}),
|
|
@@ -134,6 +124,6 @@ export function levelRoles(rows, resolveColor, dimmed = new Set()) {
|
|
|
134
124
|
/** The theme-shaping fields of every row's levels, as one memo key. */
|
|
135
125
|
export function levelsSig(rows) {
|
|
136
126
|
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 ?? '') : ''}`))
|
|
127
|
+
.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.lineWidth ?? ''}\u0000${l.kind === 'range' ? (l.fill ?? '') : ''}`))
|
|
138
128
|
.join('|');
|
|
139
129
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tidal-ts/chart",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.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",
|
|
@@ -31,20 +31,20 @@
|
|
|
31
31
|
"access": "public"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"@pond-ts/charts": "^0.
|
|
35
|
-
"@pond-ts/financial": "^0.
|
|
36
|
-
"@pond-ts/react": "^0.
|
|
37
|
-
"pond-ts": "^0.
|
|
34
|
+
"@pond-ts/charts": "^0.78.0",
|
|
35
|
+
"@pond-ts/financial": "^0.78.0",
|
|
36
|
+
"@pond-ts/react": "^0.78.0",
|
|
37
|
+
"pond-ts": "^0.78.0",
|
|
38
38
|
"react": "^18.2.0 || ^19.0.0"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@tidal-ts/core": "0.
|
|
41
|
+
"@tidal-ts/core": "0.21.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@pond-ts/charts": "^0.
|
|
45
|
-
"@pond-ts/financial": "^0.
|
|
46
|
-
"@pond-ts/process": "0.
|
|
47
|
-
"@pond-ts/react": "^0.
|
|
44
|
+
"@pond-ts/charts": "^0.78.0",
|
|
45
|
+
"@pond-ts/financial": "^0.78.0",
|
|
46
|
+
"@pond-ts/process": "0.78.0",
|
|
47
|
+
"@pond-ts/react": "^0.78.0",
|
|
48
48
|
"@storybook/addon-essentials": "^8.5.0",
|
|
49
49
|
"@storybook/react": "^8.5.0",
|
|
50
50
|
"@storybook/react-vite": "^8.5.0",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"@types/react-dom": "^18.3.5",
|
|
53
53
|
"@types/react-test-renderer": "^18.3.1",
|
|
54
54
|
"@vitejs/plugin-react": "^4.3.4",
|
|
55
|
-
"pond-ts": "^0.
|
|
55
|
+
"pond-ts": "^0.78.0",
|
|
56
56
|
"react": "^18.3.1",
|
|
57
57
|
"react-dom": "^18.3.1",
|
|
58
58
|
"react-test-renderer": "^18.3.1",
|