@tidal-ts/chart 0.28.0 → 0.30.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.
@@ -8,7 +8,7 @@ import { useMeasuredWidth } from './useMeasuredWidth.js';
8
8
  import { withAlpha } from './withAlpha.js';
9
9
  import { levelRoles, levelsSig, rowLevelMarks } from './levels.js';
10
10
  import { DEFAULT_CHART_SETTINGS } from './chartSettings.js';
11
- import { configAxisId, guideLevels, seriesDrawn, configBand, configOutputs, dashPattern, outputLook, effectiveSplit, seriesAxisId, seriesLineDashArray, seriesLineWidth, isCompareSide, drawsAsCompare, sharedAxisId, axisFormat, fractionTicks, outputKey, configColumns, } from './series.js';
11
+ import { configAxisId, guideLevels, seriesDrawn, configBand, configOutputs, dashPattern, outputLook, effectiveSplit, seriesAxisId, seriesLineDashArray, seriesLineWidth, seriesOpacity, compareStyleOf, isCompareSide, drawsAsCompare, sharedAxisId, axisFormat, fractionTicks, outputKey, configColumns, } from './series.js';
12
12
  /** The schema-erased series type every layer reads. Rows carry heterogeneous
13
13
  * sources (vol `%`, price `$`), so the chart works in the erased schema and each
14
14
  * config names its `column`. Callers build the {@link TimeSeriesChartProps.sources} map
@@ -347,7 +347,7 @@ function TimeSeriesChartInner({ rows, sources, ohlcSources = EMPTY_SOURCES, cale
347
347
  // the before ink (`isCompareSide`) both turn on the column and spec,
348
348
  // which a study re-pointed at the other symbol changes under one id.
349
349
  const side = `${drawsAsCompare(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) : ''}`;
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) : ''}:${c.compareStyle ? JSON.stringify(c.compareStyle) : ''}`;
351
351
  })
352
352
  .join('|') +
353
353
  '#' +
@@ -378,13 +378,16 @@ function TimeSeriesChartInner({ rows, sources, ohlcSources = EMPTY_SOURCES, cale
378
378
  // The compared side draws in the host's BEFORE ink (`compareInk`); every
379
379
  // other series in its own. Its outputs follow it, so a study on the
380
380
  // compared leg is "before" too.
381
- const before = compareInk !== undefined && isCompareSide(c);
381
+ // A colour picked for the one compared line (`compareStyle.color`)
382
+ // overrides the theme's before ink, as it does the config's own.
383
+ const picked = compareStyleOf(c)?.color;
384
+ const before = !picked && compareInk !== undefined && isCompareSide(c);
382
385
  const inkOf = (color) => (before ? compareInk : resolveColor(color));
383
- const stroke = inkOf(c.color);
386
+ const stroke = inkOf(picked ?? c.color);
384
387
  const isDim = dim.has(c.id);
385
388
  // The user's opacity and the chart's dimming compose: a half-opaque line
386
389
  // that is also dimmed is fainter still, never back to full strength.
387
- const own = opacityOf(c.opacity);
390
+ const own = opacityOf(seriesOpacity(c));
388
391
  const alpha = own * (isDim ? 0.22 : 1);
389
392
  const color = withAlpha(stroke, alpha);
390
393
  const width = seriesLineWidth(c, settings);
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, compareWithInput, 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, seriesOpacity, compareStyleOf, 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, lineInput, 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, compareWithInput, 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, seriesOpacity, compareStyleOf, 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, lineInput, 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/series.d.ts CHANGED
@@ -269,6 +269,19 @@ export interface SeriesConfig {
269
269
  * been told otherwise about.
270
270
  */
271
271
  outputStyles?: Readonly<Record<string, OutputStyle>>;
272
+ /**
273
+ * How this config draws when it draws AS a comparison ({@link drawsAsCompare}
274
+ * — the dashed copy of a metric on the other symbol, or a study on it). Each
275
+ * field overrides that one line's default and nothing else: its weight and
276
+ * texture (else the config's own `lineWidth` for the weight, then the
277
+ * settings' `comparisons` category), its colour (else
278
+ * {@link TimeSeriesChartProps.compareInk} on the compared side, else the
279
+ * config's own) and its opacity (else the config's own). An empty entry
280
+ * changes nothing. Ignored on a series that does not draw as a comparison,
281
+ * so a host may keep it on a metric whose copy it builds by spreading the
282
+ * metric, and the copy picks it up.
283
+ */
284
+ compareStyle?: OutputStyle;
272
285
  /**
273
286
  * The outputs of its multi-output source this study runs on, when it runs on
274
287
  * MORE than one — an SMA of a band's `Upper` and `Lower` is one study drawing
@@ -314,79 +327,37 @@ export interface SeriesConfig {
314
327
  * the comparison, has nothing to restore.
315
328
  */
316
329
  compareFn?: PairOp;
317
- /**
318
- * What a compare reads as its other side (inB), when it is **wired by hand**
319
- * rather than automatic. Absent ⇒ automatic: the same chain on the
320
- * comparison symbol. Set ⇒ the output of the config `id`, read on the
321
- * primary symbol or on the comparison (`side`) — `iv21` against `hv21`, or
322
- * against `close` with a `ratio`. Set on the ROOT of a chain, like
323
- * {@link compareFn}; the studies on the metric mirror onto this input, and a
324
- * function joins the metric with it.
325
- *
326
- * Saved with the config, and kept when the comparison goes away: like the
327
- * function, it sleeps until there is a comparison again. The host does the
328
- * wiring at render time and treats an `id` that no longer exists as
329
- * automatic. The terminal machine drops a wiring as soon as the other side
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.
333
- *
334
- * The other side is read as its own PLAIN output, never its compare — so
335
- * two metrics wired to each other, or a metric wired to its own study, form
336
- * no cycle.
337
- *
338
- * The other config may be on **another source** (ATM vol against realized
339
- * vol on price). The host rebinds its input under `sourcePrefix(source)`
340
- * (`~price_close`) before any symbol prefix, and the fold joins that
341
- * source's raw columns onto the metric's rows; its spec runs there, on the
342
- * metric's rows, like every other part of a compare.
343
- */
344
- compareWith?: CompareWith;
345
330
  /**
346
331
  * The symbol a compare's other side (inB) is **locked** to — `SPY` — in
347
- * place of the bar's comparison. Absent ⇒ inB reads the comparison, as
348
- * before. Set on the ROOT of a chain, like {@link compareFn}. What it means,
349
- * which the HOST builds at render time as it does the rest of a compare: the
350
- * automatic other side is the same chain on this symbol, and a wiring with
351
- * `side: 'comparison'` reads the wired config on this symbol. A wiring with
352
- * `side: 'primary'` reads no other symbol, so the lock changes nothing there.
332
+ * place of the bar's comparison. Absent ⇒ inB reads the comparison. A lock
333
+ * belongs to a DATA SOURCE, not a line (the terminal's `sourceLocks`): the
334
+ * host stamps it at render time onto every line of a locked source, so
335
+ * nothing here is saved with the config. What it means, which the host
336
+ * builds as it does the rest of a compare: the other side is the same chain
337
+ * on this symbol.
353
338
  *
354
339
  * Unlike the rest of a compare it never SLEEPS: it does not depend on the
355
340
  * bar, so it draws with no comparison named. The host fetches the symbol,
356
341
  * hands it to the fold as `SourceInput.pinned`, and rebinds the chain onto
357
342
  * its columns with `underPrefix(input, pinnedPrefix(symbol))`
358
- * (`cmp_@SPY_close`). Saved with the config and
359
- * carried by a preset, the one symbol a preset carries.
343
+ * (`cmp_@SPY_close`).
360
344
  */
361
345
  compareOn?: string;
362
346
  }
363
- /** A compare's hand-wired other side — see {@link SeriesConfig.compareWith}. */
364
- export interface CompareWith {
365
- /** The config whose output is the other side. */
366
- id: string;
367
- /** Read on the primary symbol, or on the comparison. */
368
- side: 'primary' | 'comparison';
369
- /**
370
- * Which of its lines, when the other config draws several — a Bollinger's
371
- * `Upper`, one column of a data node drawing open and close, one output of
372
- * a fanned study — by the name {@link configOutputs} gives it. Absent for a
373
- * config with one line.
374
- */
375
- output?: string;
376
- }
377
347
  /**
378
- * What a compare reads as its other side from `other` — the input a spec
379
- * names it by ({@link CompareWith}): its spec or its raw column for one line;
348
+ * The input that reads ONE drawn line of `other` — what a spec names it by
349
+ * when it reads that line (a compare's side): its spec or its raw column for
350
+ * one line;
380
351
  * for one line of several, the column, the fanned spec or the PICKED output
381
352
  * that is that line. Only a line the config DRAWS ({@link configColumns}):
382
353
  * not a Bollinger's hidden middle, nor a third column of a two-line band.
383
354
  *
384
355
  * `null` when `output` names none of its drawn lines, or is missing for a
385
356
  * config that draws several. A data node back to ONE column still answers to
386
- * that column's name, so a wiring on `close` survives the node dropping
357
+ * that column's name, so a reader of `close` survives the node dropping
387
358
  * `open`.
388
359
  */
389
- export declare function compareWithInput(other: Pick<SeriesConfig, 'column' | 'derive' | 'fan' | 'style' | 'bandMiddle'>, output?: string): DeriveInput | null;
360
+ export declare function lineInput(other: Pick<SeriesConfig, 'column' | 'derive' | 'fan' | 'style' | 'bandMiddle'>, output?: string): DeriveInput | null;
390
361
  /** The textures in display order. */
391
362
  export declare const LINE_DASHES: readonly LineDash[];
392
363
  /** Ink for ONE output of a multi-output config — see
@@ -722,14 +693,22 @@ export declare function seriesCategoryStyle(s: SeriesConfig, settings: ChartSett
722
693
  /** A series' stroke width: its explicit `lineWidth` override, else its category
723
694
  * default from the settings (metrics vs studies). */
724
695
  export declare function seriesLineWidth(s: SeriesConfig, settings?: ChartSettings): number;
696
+ /** A comparison-drawing series' own {@link SeriesConfig.compareStyle}, or
697
+ * `undefined` on any other series (where the field is ignored). */
698
+ export declare function compareStyleOf(s: SeriesConfig): OutputStyle | undefined;
699
+ /** A series' opacity, `0..1`: a comparison's own (`compareStyle.opacity`),
700
+ * else the config's, else full strength. */
701
+ export declare function seriesOpacity(s: SeriesConfig): number;
725
702
  /** The dash pattern a `'dotted'` line draws with — short enough to read as
726
703
  * dots at every weight the panel offers, spaced so it never reads as a dash. */
727
704
  export declare const DOT_PATTERN: readonly [number, number];
728
705
  /** A texture as a dash pattern — `undefined` for solid. */
729
706
  export declare function dashPattern(dash: LineDash | undefined): readonly [number, number] | undefined;
730
707
  /** A series' dash pattern (`undefined` = solid): its own `lineDash`, else its
731
- * category's style. A comparison-reading series always takes its category's:
732
- * there the texture is not decoration but the symbol it reads. */
708
+ * category's style. A comparison-reading series ignores `lineDash` — there the
709
+ * texture is the symbol it reads, and a copy built by spreading its metric
710
+ * would otherwise inherit the metric's — and takes its category's unless its
711
+ * own `compareStyle` names one: a texture picked for that one line. */
733
712
  export declare function seriesLineDashArray(s: SeriesConfig, settings?: ChartSettings): readonly [number, number] | undefined;
734
713
  /** Dash ladders for a multi-output config's 2nd..Nth line, by default.
735
714
  * Distinguishable at a glance and ordered so a longer dash reads as "further
package/dist/series.js CHANGED
@@ -155,18 +155,19 @@ import { BAND_OUTPUTS, BAR_PRICE_COLUMNS, COMPARE_PREFIX, deriveId, hasPairOp, i
155
155
  // The app-wide presentation defaults the category resolvers below read.
156
156
  import { DEFAULT_CHART_SETTINGS, } from './chartSettings.js';
157
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;
158
+ * The input that reads ONE drawn line of `other` — what a spec names it by
159
+ * when it reads that line (a compare's side): its spec or its raw column for
160
+ * one line;
160
161
  * for one line of several, the column, the fanned spec or the PICKED output
161
162
  * that is that line. Only a line the config DRAWS ({@link configColumns}):
162
163
  * not a Bollinger's hidden middle, nor a third column of a two-line band.
163
164
  *
164
165
  * `null` when `output` names none of its drawn lines, or is missing for a
165
166
  * 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
+ * that column's name, so a reader of `close` survives the node dropping
167
168
  * `open`.
168
169
  */
169
- export function compareWithInput(other, output) {
170
+ export function lineInput(other, output) {
170
171
  const drawn = new Set(configColumns(other));
171
172
  const lines = configOutputs(other).filter((o) => drawn.has(o.column));
172
173
  const several = lines.length > 1 || other.style === 'band' || other.style === 'lines';
@@ -487,7 +488,17 @@ export function seriesCategoryStyle(s, settings) {
487
488
  /** A series' stroke width: its explicit `lineWidth` override, else its category
488
489
  * default from the settings (metrics vs studies). */
489
490
  export function seriesLineWidth(s, settings = DEFAULT_CHART_SETTINGS) {
490
- return s.lineWidth ?? seriesCategoryStyle(s, settings).weight;
491
+ return compareStyleOf(s)?.lineWidth ?? s.lineWidth ?? seriesCategoryStyle(s, settings).weight;
492
+ }
493
+ /** A comparison-drawing series' own {@link SeriesConfig.compareStyle}, or
494
+ * `undefined` on any other series (where the field is ignored). */
495
+ export function compareStyleOf(s) {
496
+ return s.compareStyle && drawsAsCompare(s) ? s.compareStyle : undefined;
497
+ }
498
+ /** A series' opacity, `0..1`: a comparison's own (`compareStyle.opacity`),
499
+ * else the config's, else full strength. */
500
+ export function seriesOpacity(s) {
501
+ return compareStyleOf(s)?.opacity ?? s.opacity ?? 1;
491
502
  }
492
503
  /** The dash pattern a `'dotted'` line draws with — short enough to read as
493
504
  * dots at every weight the panel offers, spaced so it never reads as a dash. */
@@ -497,10 +508,14 @@ export function dashPattern(dash) {
497
508
  return dash === 'dashed' ? DASH_PATTERN : dash === 'dotted' ? DOT_PATTERN : undefined;
498
509
  }
499
510
  /** A series' dash pattern (`undefined` = solid): its own `lineDash`, else its
500
- * category's style. A comparison-reading series always takes its category's:
501
- * there the texture is not decoration but the symbol it reads. */
511
+ * category's style. A comparison-reading series ignores `lineDash` — there the
512
+ * texture is the symbol it reads, and a copy built by spreading its metric
513
+ * would otherwise inherit the metric's — and takes its category's unless its
514
+ * own `compareStyle` names one: a texture picked for that one line. */
502
515
  export function seriesLineDashArray(s, settings = DEFAULT_CHART_SETTINGS) {
503
- if (s.lineDash && !drawsAsCompare(s))
516
+ if (drawsAsCompare(s))
517
+ return dashPattern(compareStyleOf(s)?.lineDash ?? seriesCategoryStyle(s, settings).dash);
518
+ if (s.lineDash)
504
519
  return dashPattern(s.lineDash);
505
520
  return dashPattern(seriesCategoryStyle(s, settings).dash);
506
521
  }
@@ -542,10 +557,10 @@ export function outputLook(c, index, settings = DEFAULT_CHART_SETTINGS) {
542
557
  : undefined
543
558
  : OUTPUT_DASHES[(index - 1) % OUTPUT_DASHES.length];
544
559
  return {
545
- color: own?.color ?? c.color,
560
+ color: own?.color ?? compareStyleOf(c)?.color ?? c.color,
546
561
  width: own?.lineWidth ?? (lead ? width : Math.max(1, width - 0.5)),
547
562
  ...(dash ? { dash } : {}),
548
- opacity: own?.opacity ?? c.opacity ?? 1,
563
+ opacity: own?.opacity ?? seriesOpacity(c),
549
564
  };
550
565
  }
551
566
  /** The effective direction-coloring of a `bar`/`candle` series: the per-series
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tidal-ts/chart",
3
- "version": "0.28.0",
3
+ "version": "0.30.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.28.0"
41
+ "@tidal-ts/core": "0.30.0"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@pond-ts/charts": "^0.78.0",