@tidal-ts/chart 0.5.1 → 0.7.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.
@@ -1,12 +1,12 @@
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, Layers, LineChart, Marker, Region, TimeAxis, YAxis, YAxisIndicator, } from '@pond-ts/charts';
3
+ import { AreaChart, BandChart, BarChart, Candlestick, ChartContainer, ChartRow, Layers, LineChart, Baseline, Marker, Region, TimeAxis, YAxis, YAxisIndicator, } 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, sliceBySegments, WINDOW_MS, autoBarWindow, opOutputs, outputMark, } from '@tidal-ts/core';
6
6
  import { candleStyleForColor, candleStyleForPair } from './candleStyle.js';
7
7
  import { useMeasuredWidth } from './useMeasuredWidth.js';
8
8
  import { DEFAULT_CHART_SETTINGS } from './chartSettings.js';
9
- import { configAxisId, seriesDrawn, DASH_PATTERN, effectiveSplit, seriesAxisId, seriesLineDashArray, seriesLineWidth, sharedAxisId, axisFormat, fractionTicks, bandColumns, outputKey, configColumns, } from './series.js';
9
+ import { configAxisId, guideLevels, seriesDrawn, DASH_PATTERN, effectiveSplit, seriesAxisId, seriesLineDashArray, seriesLineWidth, sharedAxisId, axisFormat, fractionTicks, bandColumns, outputKey, configColumns, } from './series.js';
10
10
  /** The schema-erased series type every layer reads. Rows carry heterogeneous
11
11
  * sources (vol `%`, price `$`), so the chart works in the erased schema and each
12
12
  * config names its `column`. Callers build the {@link TimeSeriesChartProps.sources} map
@@ -636,6 +636,11 @@ function TimeSeriesChartInner({ rows, sources, ohlcSources = [], calendarDays =
636
636
  continue;
637
637
  if (c.style === 'bar') {
638
638
  const col = c.column;
639
+ // A column the data does not carry (a study the engine skipped, a
640
+ // volume study on a series with no volume) draws nothing, as it would
641
+ // as a line: aggregating it throws and takes the whole chart down.
642
+ if (!src.schema.some((sc) => sc.name === col))
643
+ continue;
639
644
  const window = windowFor(c, src);
640
645
  const grid = sessionsFor(src);
641
646
  let agg = aggregateColumn(src, col, window, reducerFor(c), grid);
@@ -643,7 +648,9 @@ function TimeSeriesChartInner({ rows, sources, ohlcSources = [], calendarDays =
643
648
  // (one fill per series; F-charts-12) — split the column into `__up`/`__dn`
644
649
  // halves and draw them as two layers. Same grid, or the halves misalign.
645
650
  if (effectiveSplit(c, settings).mode === 'split')
646
- agg = splitBarColumns(agg, col, src, ohlc.has(c.source), window, grid);
651
+ // A study's bars rise and fall with the STUDY, never with the price
652
+ // candle under them: only a raw column reads the source's open/close.
653
+ agg = splitBarColumns(agg, col, src, ohlc.has(c.source) && !c.derive, window, grid);
647
654
  bar.set(c.id, agg);
648
655
  }
649
656
  // A candle at the data's NATIVE interval feeds the raw point-keyed series
@@ -1214,7 +1221,7 @@ function TimeSeriesChartInner({ rows, sources, ohlcSources = [], calendarDays =
1214
1221
  // density problem — 16 across the top at 1Y, two of them
1215
1222
  // behind our own legend. `false` (not omitted) is required:
1216
1223
  // omitting it auto-labels with the axis formatter.
1217
- label: false, role: a.role, selectable: false }, a.id))), [...visible].reverse().flatMap((c) => {
1224
+ 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))), [...visible].reverse().flatMap((c) => {
1218
1225
  const src = c.source ? sources[c.source] : undefined;
1219
1226
  // Column-level "show only what the data carries": a config
1220
1227
  // whose column is absent from its (folded) series draws
package/dist/series.d.ts CHANGED
@@ -189,6 +189,14 @@ export declare const sharedAxisId: (rowId: string, side: SeriesAxis) => string;
189
189
  export declare const seriesAxisId: (rowId: string, side: SeriesAxis, group: string) => string;
190
190
  /** The axis a config actually scales on: its own when unlinked, else the shared. */
191
191
  export declare const configAxisId: (rowId: string, c: Pick<SeriesConfig, "axis" | "axisGroup">) => string;
192
+ /** The guide levels a row draws: each drawn study's {@link studyLevels} on its
193
+ * own axis, once per (axis, value) — two RSIs sharing an axis draw one 30
194
+ * and one 70. Drawn as `<Baseline role="guide">`; a host styles the role. */
195
+ export declare function guideLevels(drawn: readonly SeriesConfig[], rowId: string, isLog?: (axisId: string) => boolean): {
196
+ key: string;
197
+ axis: string;
198
+ value: number;
199
+ }[];
192
200
  /** Per-axis range state (the terminal machine's `axisRanges` values): `manual`
193
201
  * pins the axis to `[min, max]`; `auto` with values present is the **preserved
194
202
  * manual memory** (the legacy triple — "Auto fit was …" / re-manual restores).
package/dist/series.js CHANGED
@@ -59,7 +59,7 @@ export function configColumns(c) {
59
59
  // `@tidal-ts/core` (where the windowing + derive seam live) — imported for
60
60
  // `SeriesConfig` below and re-exported so UI code has one import site for the
61
61
  // series vocabulary.
62
- import { BAND_OUTPUTS, COMPARE_PREFIX, inputNames, opOutputs, opParams, outputMark, usesCompare, } from '@tidal-ts/core';
62
+ import { BAND_OUTPUTS, COMPARE_PREFIX, inputNames, opOutputs, opParams, outputMark, studyLevels, usesCompare, } from '@tidal-ts/core';
63
63
  // The app-wide presentation defaults the category resolvers below read.
64
64
  import { DEFAULT_CHART_SETTINGS, } from './chartSettings.js';
65
65
  // --- Axis identity ------------------------------------------------------------
@@ -74,6 +74,26 @@ export const sharedAxisId = (rowId, side) => `${rowId}:${side === 'R' ? 'R' : 'L
74
74
  export const seriesAxisId = (rowId, side, group) => `${sharedAxisId(rowId, side)}:${group}`;
75
75
  /** The axis a config actually scales on: its own when unlinked, else the shared. */
76
76
  export const configAxisId = (rowId, c) => c.axisGroup ? seriesAxisId(rowId, c.axis, c.axisGroup) : sharedAxisId(rowId, c.axis);
77
+ /** The guide levels a row draws: each drawn study's {@link studyLevels} on its
78
+ * own axis, once per (axis, value) — two RSIs sharing an axis draw one 30
79
+ * and one 70. Drawn as `<Baseline role="guide">`; a host styles the role. */
80
+ export function guideLevels(drawn, rowId, isLog = () => false) {
81
+ const out = new Map();
82
+ for (const c of drawn) {
83
+ if (!c.derive)
84
+ continue;
85
+ const axis = configAxisId(rowId, c);
86
+ for (const value of studyLevels(c.derive.op)) {
87
+ // A log scale has no 0 or below (%B's 0, a zero line): skip, not NaN.
88
+ if (value <= 0 && isLog(axis))
89
+ continue;
90
+ const key = `guide:${axis}:${value}`;
91
+ if (!out.has(key))
92
+ out.set(key, { key, axis, value });
93
+ }
94
+ }
95
+ return [...out.values()];
96
+ }
77
97
  /**
78
98
  * Whether an axis's entry says nothing — no lock, no pin, no memory, no format
79
99
  * or fit choice — and can therefore be dropped rather than accumulate an empty
@@ -338,9 +358,14 @@ export function effectiveSplit(s, settings = DEFAULT_CHART_SETTINGS) {
338
358
  // because green/red is reserved for market data and an indicator is not
339
359
  // that. The toggle is the asking.
340
360
  (s.colorMode ?? 'single')
341
- : s.style === 'bar' || s.style === 'candle'
342
- ? (s.colorMode ?? legacy ?? (def.split ? 'split' : 'single'))
343
- : 'single';
361
+ : s.style === 'bar' && s.derive && outputMark(s.derive.op, '') === 'bar'
362
+ ? // The same rule for a histogram study (an Awesome Oscillator): an
363
+ // indicator, so its own colour until asked. Only those: a derived
364
+ // metric drawn as bars (realized vol) keeps the app's bar default.
365
+ (s.colorMode ?? 'single')
366
+ : s.style === 'bar' || s.style === 'candle'
367
+ ? (s.colorMode ?? legacy ?? (def.split ? 'split' : 'single'))
368
+ : 'single';
344
369
  return { mode, rise: s.riseColor ?? def.rise, fall: s.fallColor ?? def.fall };
345
370
  }
346
371
  const COMPACT = new Intl.NumberFormat('en', { notation: 'compact', maximumFractionDigits: 2 });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tidal-ts/chart",
3
- "version": "0.5.1",
3
+ "version": "0.7.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.5.1"
41
+ "@tidal-ts/core": "0.7.0"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@pond-ts/charts": "^0.70.0",