@tidal-ts/terminal 0.12.1 → 0.14.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/context.d.ts +3 -0
- package/dist/context.js +6 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/terminalMachine.d.ts +27 -0
- package/dist/terminalMachine.js +159 -8
- package/package.json +3 -3
package/dist/context.d.ts
CHANGED
|
@@ -51,6 +51,9 @@ export declare function useSetStudyParam(): (id: string, name: string, value: nu
|
|
|
51
51
|
/** Switch which output of a multi-output source a study reads (the output
|
|
52
52
|
* picker). Pair it with `outputAllowed` to render refused choices disabled. */
|
|
53
53
|
export declare function useSetStudyOutput(): (id: string, output: string) => void;
|
|
54
|
+
/** Which columns of its bar a data node draws (`series.setDataColumns`). Pair
|
|
55
|
+
* it with `dataColumnsAllowed`. */
|
|
56
|
+
export declare function useSetDataColumns(): (id: string, columns: readonly string[]) => void;
|
|
54
57
|
/** Switch which column of its source a study reads (`series.setStudyInput`) —
|
|
55
58
|
* the data node's output picker. Pair it with `inputAllowed`. */
|
|
56
59
|
export declare function useSetStudyInput(): (id: string, column: string) => void;
|
package/dist/context.js
CHANGED
|
@@ -92,6 +92,12 @@ export function useSetStudyOutput() {
|
|
|
92
92
|
const ref = TerminalContext.useActorRef();
|
|
93
93
|
return useCallback((id, output) => ref.send({ type: 'series.setStudyOutput', id, output }), [ref]);
|
|
94
94
|
}
|
|
95
|
+
/** Which columns of its bar a data node draws (`series.setDataColumns`). Pair
|
|
96
|
+
* it with `dataColumnsAllowed`. */
|
|
97
|
+
export function useSetDataColumns() {
|
|
98
|
+
const ref = TerminalContext.useActorRef();
|
|
99
|
+
return useCallback((id, columns) => ref.send({ type: 'series.setDataColumns', id, columns }), [ref]);
|
|
100
|
+
}
|
|
95
101
|
/** Switch which column of its source a study reads (`series.setStudyInput`) —
|
|
96
102
|
* the data node's output picker. Pair it with `inputAllowed`. */
|
|
97
103
|
export function useSetStudyInput() {
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,6 @@
|
|
|
5
5
|
* union — the pre-paid bus contract. The actor context + machine internals stay
|
|
6
6
|
* private to the module.
|
|
7
7
|
*/
|
|
8
|
-
export { TerminalProvider, useRows, useSelectedSeries, useExpandedSeries, useControlsOpen, usePresetSaved, useActiveSlot, useAddSeries, useAddPair, useCompareAll, useAddStudy, useSetStudyParam, useSetStudyOutput, useSetStudyInput, useSetStudyOutputs, useOrderSeries, useReindexSeries, useMoveSeriesToRow, useMoveToAxis, useRemoveSeries, usePatchSeries, useToggleVisible, useToggleGroupVisible, useRemoveGroup, useSelectSeries, useExpandSeries, useSetControlsOpen, useSelectPreset, useSavePreset, useSetRowHeights, useAddRow, useRemoveRow, useAxisRanges, useToggleAxisLink, useSwapAxisSide, useSetAxisRange, useSetAxisAuto, useSetAxisLocks, useSetAxisAutoOpts, useSetAxisFormat, useTerminalHotkeys, type TerminalProviderProps, } from './context.js';
|
|
9
|
-
export { PRESET_SLOTS, MAX_ROWS, activeSlot, canonRows, columnLabel, columnUnits, entryColumn, groupMembers, mintId, axisMoveAllowed, linkToggleAllowed, respecAllowed, outputAllowed, inputAllowed, outputsAllowed, studyOutputChoices, studyOutputsOf, studyOutputsRead, defaultStudyOutputs, studyChainTail, studyOfferable, SOURCE_COLUMNS, swapAllowed, type EditScope, type RowState, type TerminalPreset, type MetricEntry, type PairLegInput, type PresetStorage, type TerminalEvent, type TerminalInput, } from './terminalMachine.js';
|
|
8
|
+
export { TerminalProvider, useRows, useSelectedSeries, useExpandedSeries, useControlsOpen, usePresetSaved, useActiveSlot, useAddSeries, useAddPair, useCompareAll, useAddStudy, useSetStudyParam, useSetStudyOutput, useSetStudyInput, useSetDataColumns, useSetStudyOutputs, useOrderSeries, useReindexSeries, useMoveSeriesToRow, useMoveToAxis, useRemoveSeries, usePatchSeries, useToggleVisible, useToggleGroupVisible, useRemoveGroup, useSelectSeries, useExpandSeries, useSetControlsOpen, useSelectPreset, useSavePreset, useSetRowHeights, useAddRow, useRemoveRow, useAxisRanges, useToggleAxisLink, useSwapAxisSide, useSetAxisRange, useSetAxisAuto, useSetAxisLocks, useSetAxisAutoOpts, useSetAxisFormat, useTerminalHotkeys, type TerminalProviderProps, } from './context.js';
|
|
9
|
+
export { PRESET_SLOTS, MAX_ROWS, activeSlot, canonRows, columnLabel, columnUnits, entryColumn, groupMembers, mintId, axisMoveAllowed, linkToggleAllowed, respecAllowed, outputAllowed, inputAllowed, dataColumnsAllowed, outputsAllowed, studyOutputChoices, studyOutputsOf, studyOutputsRead, defaultStudyOutputs, studyChainTail, studyOfferable, SOURCE_COLUMNS, swapAllowed, type EditScope, type RowState, type TerminalPreset, type MetricEntry, type PairLegInput, type PresetStorage, type TerminalEvent, type TerminalInput, } from './terminalMachine.js';
|
|
10
10
|
export { axisBindings, allowedAxes, canAddUnit, axisForAdd, type AxisMember, } from './axisPolicy.js';
|
package/dist/index.js
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* union — the pre-paid bus contract. The actor context + machine internals stay
|
|
6
6
|
* private to the module.
|
|
7
7
|
*/
|
|
8
|
-
export { TerminalProvider, useRows, useSelectedSeries, useExpandedSeries, useControlsOpen, usePresetSaved, useActiveSlot, useAddSeries, useAddPair, useCompareAll, useAddStudy, useSetStudyParam, useSetStudyOutput, useSetStudyInput, useSetStudyOutputs, useOrderSeries, useReindexSeries, useMoveSeriesToRow, useMoveToAxis, useRemoveSeries, usePatchSeries, useToggleVisible, useToggleGroupVisible, useRemoveGroup, useSelectSeries, useExpandSeries, useSetControlsOpen, useSelectPreset, useSavePreset, useSetRowHeights, useAddRow, useRemoveRow, useAxisRanges, useToggleAxisLink, useSwapAxisSide, useSetAxisRange, useSetAxisAuto, useSetAxisLocks, useSetAxisAutoOpts, useSetAxisFormat, useTerminalHotkeys, } from './context.js';
|
|
9
|
-
export { PRESET_SLOTS, MAX_ROWS, activeSlot, canonRows, columnLabel, columnUnits, entryColumn, groupMembers, mintId, axisMoveAllowed, linkToggleAllowed, respecAllowed, outputAllowed, inputAllowed, outputsAllowed, studyOutputChoices, studyOutputsOf, studyOutputsRead, defaultStudyOutputs, studyChainTail, studyOfferable, SOURCE_COLUMNS, swapAllowed, } from './terminalMachine.js';
|
|
8
|
+
export { TerminalProvider, useRows, useSelectedSeries, useExpandedSeries, useControlsOpen, usePresetSaved, useActiveSlot, useAddSeries, useAddPair, useCompareAll, useAddStudy, useSetStudyParam, useSetStudyOutput, useSetStudyInput, useSetDataColumns, useSetStudyOutputs, useOrderSeries, useReindexSeries, useMoveSeriesToRow, useMoveToAxis, useRemoveSeries, usePatchSeries, useToggleVisible, useToggleGroupVisible, useRemoveGroup, useSelectSeries, useExpandSeries, useSetControlsOpen, useSelectPreset, useSavePreset, useSetRowHeights, useAddRow, useRemoveRow, useAxisRanges, useToggleAxisLink, useSwapAxisSide, useSetAxisRange, useSetAxisAuto, useSetAxisLocks, useSetAxisAutoOpts, useSetAxisFormat, useTerminalHotkeys, } from './context.js';
|
|
9
|
+
export { PRESET_SLOTS, MAX_ROWS, activeSlot, canonRows, columnLabel, columnUnits, entryColumn, groupMembers, mintId, axisMoveAllowed, linkToggleAllowed, respecAllowed, outputAllowed, inputAllowed, dataColumnsAllowed, outputsAllowed, studyOutputChoices, studyOutputsOf, studyOutputsRead, defaultStudyOutputs, studyChainTail, studyOfferable, SOURCE_COLUMNS, swapAllowed, } from './terminalMachine.js';
|
|
10
10
|
// The axis policy a host's MENUS gate on — the same predicates the machine's
|
|
11
11
|
// guards enforce, exported so the two cannot disagree (0.1.0 left them internal;
|
|
12
12
|
// a host had to keep its own copy).
|
|
@@ -172,6 +172,14 @@ export type TerminalEvent = {
|
|
|
172
172
|
id: string;
|
|
173
173
|
column: string;
|
|
174
174
|
}
|
|
175
|
+
/** Which columns of its bar a DATA node draws — one (the price drawn from
|
|
176
|
+
* the low), or several (its open and close, as lines or a band between
|
|
177
|
+
* them). The first is the node's `column`; more than one is its `fan`. */
|
|
178
|
+
| {
|
|
179
|
+
type: 'series.setDataColumns';
|
|
180
|
+
id: string;
|
|
181
|
+
columns: readonly string[];
|
|
182
|
+
}
|
|
175
183
|
/** Which outputs of its multi-output source a study runs on — one, several
|
|
176
184
|
* (a FAN: one study drawing a line per output), or all. Generalises
|
|
177
185
|
* `series.setStudyOutput`, and reaches a study of a fanned study too. */
|
|
@@ -492,6 +500,15 @@ export declare function outputAllowed(scope: EditScope, id: string, output: stri
|
|
|
492
500
|
* Total: it runs in a guard, where a throw kills the actor.
|
|
493
501
|
*/
|
|
494
502
|
export declare function inputAllowed(scope: EditScope, id: string, column: string): boolean;
|
|
503
|
+
/**
|
|
504
|
+
* Whether data node `id` can draw `columns` of its bar (`series.setDataColumns`).
|
|
505
|
+
*
|
|
506
|
+
* A seated DATA node (no `derive`, not a pair leg's group) drawing one of a
|
|
507
|
+
* bar's price columns, re-pointed at one or more of them, distinct, and not
|
|
508
|
+
* already exactly those. Which columns a source HAS is the host's to offer; the
|
|
509
|
+
* machine knows a bar's price columns and nothing else of a series' schema.
|
|
510
|
+
*/
|
|
511
|
+
export declare function dataColumnsAllowed(scope: EditScope, id: string, columns: readonly string[]): boolean;
|
|
495
512
|
/**
|
|
496
513
|
* The outputs a study can be set to run on — its PARENT's
|
|
497
514
|
* ({@link studyOutputsOf}), or, with no seated parent, every output its chain's
|
|
@@ -589,6 +606,10 @@ export declare const terminalMachine: import("xstate").StateMachine<TerminalCont
|
|
|
589
606
|
type: "series.setStudyInput";
|
|
590
607
|
id: string;
|
|
591
608
|
column: string;
|
|
609
|
+
} | {
|
|
610
|
+
type: "series.setDataColumns";
|
|
611
|
+
id: string;
|
|
612
|
+
columns: readonly string[];
|
|
592
613
|
} | {
|
|
593
614
|
type: "series.setStudyOutputs";
|
|
594
615
|
id: string;
|
|
@@ -694,6 +715,9 @@ export declare const terminalMachine: import("xstate").StateMachine<TerminalCont
|
|
|
694
715
|
} | {
|
|
695
716
|
type: "setStudyInput";
|
|
696
717
|
params: import("xstate").NonReducibleUnknown;
|
|
718
|
+
} | {
|
|
719
|
+
type: "setDataColumns";
|
|
720
|
+
params: import("xstate").NonReducibleUnknown;
|
|
697
721
|
} | {
|
|
698
722
|
type: "setStudyOutputs";
|
|
699
723
|
params: import("xstate").NonReducibleUnknown;
|
|
@@ -793,6 +817,9 @@ export declare const terminalMachine: import("xstate").StateMachine<TerminalCont
|
|
|
793
817
|
} | {
|
|
794
818
|
type: "canSetStudyInput";
|
|
795
819
|
params: unknown;
|
|
820
|
+
} | {
|
|
821
|
+
type: "canSetDataColumns";
|
|
822
|
+
params: unknown;
|
|
796
823
|
} | {
|
|
797
824
|
type: "canSetStudyOutputs";
|
|
798
825
|
params: unknown;
|
package/dist/terminalMachine.js
CHANGED
|
@@ -31,7 +31,7 @@ function hidesPointer(context, toggledId, pointer) {
|
|
|
31
31
|
: new Set([toggledId]);
|
|
32
32
|
return cascade.has(pointer);
|
|
33
33
|
}
|
|
34
|
-
import { axisRangeIsEmpty, logAllowed, isStudySeries, readsFrom, sourcesOf, fanIsBand, publishedColumns, } from '@tidal-ts/chart';
|
|
34
|
+
import { axisRangeIsEmpty, logAllowed, isStudySeries, readsFrom, sourcesOf, fanIsBand, offersOutputBars, publishedColumns, } from '@tidal-ts/chart';
|
|
35
35
|
import { configAxisId, seriesAxisId, sharedAxisId, } from '@tidal-ts/chart';
|
|
36
36
|
import { axisForAdd, canAddUnit } from './axisPolicy.js';
|
|
37
37
|
export const PRESET_SLOTS = 5;
|
|
@@ -432,7 +432,8 @@ function toConfig(e, id, axis = e.axis) {
|
|
|
432
432
|
* else offers none: it is one line, and a study of it reads that.
|
|
433
433
|
*/
|
|
434
434
|
export function studyOutputsOf(target) {
|
|
435
|
-
|
|
435
|
+
// A DATA node's fan is columns, not outputs: a study of it reads its column.
|
|
436
|
+
if (target.derive && target.fan && target.fan.length > 0)
|
|
436
437
|
return [...target.fan];
|
|
437
438
|
if (target.derive && opOutputs(target.derive.op).length > 1)
|
|
438
439
|
return opOutputs(target.derive.op);
|
|
@@ -445,7 +446,7 @@ export function studyOutputsOf(target) {
|
|
|
445
446
|
* named for. Empty for a single-output target.
|
|
446
447
|
*/
|
|
447
448
|
export function defaultStudyOutputs(target) {
|
|
448
|
-
if (target.fan && target.fan.length > 0)
|
|
449
|
+
if (target.derive && target.fan && target.fan.length > 0)
|
|
449
450
|
return [...target.fan];
|
|
450
451
|
const primary = target.derive ? primaryOutput(target.derive.op) : undefined;
|
|
451
452
|
return primary ? [primary] : [];
|
|
@@ -550,7 +551,7 @@ function studyConfig(target, op, period, id, unitOf, requested) {
|
|
|
550
551
|
// group landed on the row's shared axis instead, a line near zero drawn on
|
|
551
552
|
// the price's scale.
|
|
552
553
|
...(shares ? (target.axisGroup ? { axisGroup: target.axisGroup } : {}) : { axisGroup: id }),
|
|
553
|
-
label: `${target
|
|
554
|
+
label: `${studyBaseLabel(target, derive)}${segment ? ` · ${segment}` : ''} · ${studyTag(derive)}`, // legend chip
|
|
554
555
|
family: target.family ?? target.label, // main line = the source's name
|
|
555
556
|
tenor: target.tenor, // carry the source's tenor into the params sub-line
|
|
556
557
|
// A study is the same reading, smoothed — so it takes its metric's COLOUR
|
|
@@ -1009,7 +1010,7 @@ export function inputAllowed(scope, id, column) {
|
|
|
1009
1010
|
return false;
|
|
1010
1011
|
if (!isValidSpec(withStudyColumn(target.derive, column)))
|
|
1011
1012
|
return false;
|
|
1012
|
-
const next = propagateRespec(configs, id, respecInput(target, column, home
|
|
1013
|
+
const next = propagateRespec(configs, id, respecInput(target, column, barHome(home)), unitOfColumn(scope));
|
|
1013
1014
|
if (next === null || !unitsStayCoherent(scope.rows, next))
|
|
1014
1015
|
return false;
|
|
1015
1016
|
const borrowed = target.axisGroup != null && target.axisGroup !== target.id;
|
|
@@ -1019,6 +1020,109 @@ export function inputAllowed(scope, id, column) {
|
|
|
1019
1020
|
return false;
|
|
1020
1021
|
}
|
|
1021
1022
|
}
|
|
1023
|
+
/**
|
|
1024
|
+
* Whether data node `id` can draw `columns` of its bar (`series.setDataColumns`).
|
|
1025
|
+
*
|
|
1026
|
+
* A seated DATA node (no `derive`, not a pair leg's group) drawing one of a
|
|
1027
|
+
* bar's price columns, re-pointed at one or more of them, distinct, and not
|
|
1028
|
+
* already exactly those. Which columns a source HAS is the host's to offer; the
|
|
1029
|
+
* machine knows a bar's price columns and nothing else of a series' schema.
|
|
1030
|
+
*/
|
|
1031
|
+
export function dataColumnsAllowed(scope, id, columns) {
|
|
1032
|
+
try {
|
|
1033
|
+
const node = flatConfigs(scope.rows).find((c) => c.id === id);
|
|
1034
|
+
if (!node || node.derive || node.group)
|
|
1035
|
+
return false;
|
|
1036
|
+
if (!BAR_PRICE_COLUMNS.includes(node.column))
|
|
1037
|
+
return false;
|
|
1038
|
+
if (columns.length === 0 || new Set(columns).size !== columns.length)
|
|
1039
|
+
return false;
|
|
1040
|
+
if (!columns.every((c) => BAR_PRICE_COLUMNS.includes(c)))
|
|
1041
|
+
return false;
|
|
1042
|
+
// In the bar's own order, so `['close', 'open']` is the same as
|
|
1043
|
+
// `['open', 'close']` and not a change that swaps the band's edges.
|
|
1044
|
+
const now = node.fan && node.fan.length > 0 ? node.fan : [node.column];
|
|
1045
|
+
const next = barOrder(columns);
|
|
1046
|
+
return !(now.length === next.length && now.every((c, i) => c === next[i]));
|
|
1047
|
+
}
|
|
1048
|
+
catch {
|
|
1049
|
+
return false;
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
/**
|
|
1053
|
+
* A config patched, kept drawable (PR #35 review): a DATA node's `fan` means
|
|
1054
|
+
* something only as `lines` or a `band`, so a patch to another style drops it
|
|
1055
|
+
* (the node keeps its first column); a `band` needs a band to draw, so a
|
|
1056
|
+
* one-column data node keeps its style. `parentIds` is the graph, not a
|
|
1057
|
+
* presentation field: a patch may not rewrite which config a study is on.
|
|
1058
|
+
*/
|
|
1059
|
+
function coherentPatch(c, patch) {
|
|
1060
|
+
const next = { ...c, ...patch, parentIds: c.parentIds };
|
|
1061
|
+
if (next.derive)
|
|
1062
|
+
return next;
|
|
1063
|
+
const fanned = !!next.fan && next.fan.length > 0;
|
|
1064
|
+
if (fanned && next.style !== 'lines' && next.style !== 'band') {
|
|
1065
|
+
const { fan: _fan, ...rest } = next;
|
|
1066
|
+
return rest;
|
|
1067
|
+
}
|
|
1068
|
+
if (!fanned && next.style === 'band')
|
|
1069
|
+
return { ...next, style: c.style === 'band' ? 'line' : c.style };
|
|
1070
|
+
return next;
|
|
1071
|
+
}
|
|
1072
|
+
/** Bar price columns in the bar's own order. */
|
|
1073
|
+
const barOrder = (columns) => [...columns].sort((a, b) => BAR_PRICE_COLUMNS.indexOf(a) - BAR_PRICE_COLUMNS.indexOf(b));
|
|
1074
|
+
/**
|
|
1075
|
+
* A data node drawing `columns`: the first is its `column`, more than one its
|
|
1076
|
+
* `fan`. The style follows what the columns can draw — several draw as `lines`
|
|
1077
|
+
* unless two are a `band`; one draws as it did, or as a `line` if it was drawing
|
|
1078
|
+
* several. The label names the columns off the close (`Price · Open, Close`).
|
|
1079
|
+
*/
|
|
1080
|
+
function dataColumnsConfig(node, wanted) {
|
|
1081
|
+
const columns = barOrder(wanted);
|
|
1082
|
+
const many = columns.length > 1;
|
|
1083
|
+
// A candle draws the whole bar whatever `column` says, so drawn from one
|
|
1084
|
+
// other column it becomes that column's line — or the change shows nothing.
|
|
1085
|
+
const style = many
|
|
1086
|
+
? node.style === 'band' && columns.length === 2
|
|
1087
|
+
? 'band'
|
|
1088
|
+
: 'lines'
|
|
1089
|
+
: node.style === 'band' || node.style === 'lines'
|
|
1090
|
+
? 'line'
|
|
1091
|
+
: node.style === 'candle' && columns[0] !== 'close'
|
|
1092
|
+
? 'line'
|
|
1093
|
+
: node.style;
|
|
1094
|
+
const label = typeof node.label === 'string' ? node.label : '';
|
|
1095
|
+
const base = label.replace(BAR_SEGMENT, '');
|
|
1096
|
+
const named = columns.length === 1 && columns[0] === 'close';
|
|
1097
|
+
const { fan: _fan, ...rest } = node;
|
|
1098
|
+
return {
|
|
1099
|
+
...rest,
|
|
1100
|
+
column: columns[0],
|
|
1101
|
+
...(many ? { fan: [...columns] } : {}),
|
|
1102
|
+
style,
|
|
1103
|
+
label: named ? base : `${base} · ${columns.map(columnSegment).join(', ')}`,
|
|
1104
|
+
};
|
|
1105
|
+
}
|
|
1106
|
+
/** The column a bar data node's label is named off — its close; a study of
|
|
1107
|
+
* any other of its columns names that column (`Price · High · SMA(20)`). A
|
|
1108
|
+
* non-bar node's own column. */
|
|
1109
|
+
const barHome = (node) => BAR_PRICE_COLUMNS.includes(node.column) ? 'close' : node.column;
|
|
1110
|
+
/** A label with its bar-column segment (`· Low`, `· Open, Close`) removed. */
|
|
1111
|
+
const BAR_SEGMENT = / · (Open|High|Low|Close)(, (Open|High|Low|Close))*$/;
|
|
1112
|
+
/**
|
|
1113
|
+
* What a new study's label starts with: its target's label — except on a bar
|
|
1114
|
+
* data node, whose label names the columns IT draws: the study names the column
|
|
1115
|
+
* IT reads, off the close (a study added on `Price · Open, Close` reading the
|
|
1116
|
+
* open is `Price · Open · SMA(20)`, not `Price · Open, Close · SMA(20)`).
|
|
1117
|
+
*/
|
|
1118
|
+
function studyBaseLabel(target, derive) {
|
|
1119
|
+
const label = typeof target.label === 'string' ? target.label : '';
|
|
1120
|
+
if (target.derive || !BAR_PRICE_COLUMNS.includes(target.column))
|
|
1121
|
+
return label;
|
|
1122
|
+
const read = studyColumn(derive)?.column;
|
|
1123
|
+
const base = label.replace(BAR_SEGMENT, '');
|
|
1124
|
+
return read && read !== 'close' ? `${base} · ${columnSegment(read)}` : base;
|
|
1125
|
+
}
|
|
1022
1126
|
/** The seated DATA node a study reads its raw column off — a node with no
|
|
1023
1127
|
* derive of its own, on the study's source. */
|
|
1024
1128
|
function dataParent(configs, study) {
|
|
@@ -1043,7 +1147,8 @@ export function studyOutputChoices(scope, id) {
|
|
|
1043
1147
|
}
|
|
1044
1148
|
/** The outputs a study runs on now: its fan, else the one its chain picks. */
|
|
1045
1149
|
export function studyOutputsRead(study) {
|
|
1046
|
-
|
|
1150
|
+
// A DATA node's fan is columns, not outputs of a source.
|
|
1151
|
+
if (study.derive && study.fan && study.fan.length > 0)
|
|
1047
1152
|
return [...study.fan];
|
|
1048
1153
|
const pick = study.derive ? fanPick(study.derive) : undefined;
|
|
1049
1154
|
return pick ? [pick.output] : [];
|
|
@@ -1711,6 +1816,10 @@ export function canonRows(rows) {
|
|
|
1711
1816
|
c.group ? [groupSlot(c.group.id), c.group.side, c.group.hidden ?? false] : null,
|
|
1712
1817
|
c.lineDash ?? null,
|
|
1713
1818
|
c.opacity ?? null,
|
|
1819
|
+
c.bandMiddle ?? null,
|
|
1820
|
+
// Identity only where it draws something different: `true` is the
|
|
1821
|
+
// default, and `false` on a study with no bars changes nothing.
|
|
1822
|
+
c.outputBars === false && offersOutputBars(c) ? false : null,
|
|
1714
1823
|
// Per-output ink, key-sorted so two equal maps written in different
|
|
1715
1824
|
// orders hash alike. A fan is composition: which lines a study draws.
|
|
1716
1825
|
c.outputStyles
|
|
@@ -1893,6 +2002,8 @@ export const terminalMachine = setup({
|
|
|
1893
2002
|
// actor, and the `>= 2` pre-check does not cover the registry's max).
|
|
1894
2003
|
canSetStudyOutput: ({ context, event }) => event.type === 'series.setStudyOutput' && outputAllowed(context, event.id, event.output),
|
|
1895
2004
|
canSetStudyInput: ({ context, event }) => event.type === 'series.setStudyInput' && inputAllowed(context, event.id, event.column),
|
|
2005
|
+
canSetDataColumns: ({ context, event }) => event.type === 'series.setDataColumns' &&
|
|
2006
|
+
dataColumnsAllowed(context, event.id, event.columns),
|
|
1896
2007
|
canSetStudyOutputs: ({ context, event }) => event.type === 'series.setStudyOutputs' && outputsAllowed(context, event.id, event.outputs),
|
|
1897
2008
|
canSetStudyParam: ({ context, event }) => event.type === 'series.setStudyParam' &&
|
|
1898
2009
|
respecAllowed(context, event.id, event.name, event.value),
|
|
@@ -2106,7 +2217,7 @@ export const terminalMachine = setup({
|
|
|
2106
2217
|
const at = target?.derive && studyColumn(target.derive);
|
|
2107
2218
|
if (!target || !home || !at)
|
|
2108
2219
|
return context.rows;
|
|
2109
|
-
const rows = applyRespec(context, event.id, respecInput(target, event.column, home
|
|
2220
|
+
const rows = applyRespec(context, event.id, respecInput(target, event.column, barHome(home)));
|
|
2110
2221
|
if (rows === context.rows)
|
|
2111
2222
|
return rows; // refused: never half-apply
|
|
2112
2223
|
// Off its home column the study finds its data node only through
|
|
@@ -2131,6 +2242,45 @@ export const terminalMachine = setup({
|
|
|
2131
2242
|
}));
|
|
2132
2243
|
},
|
|
2133
2244
|
}),
|
|
2245
|
+
setDataColumns: assign({
|
|
2246
|
+
rows: ({ context, event }) => {
|
|
2247
|
+
if (event.type !== 'series.setDataColumns')
|
|
2248
|
+
return context.rows;
|
|
2249
|
+
const configs = flatConfigs(context.rows);
|
|
2250
|
+
const node = configs.find((c) => c.id === event.id);
|
|
2251
|
+
if (!node)
|
|
2252
|
+
return context.rows;
|
|
2253
|
+
// What is built on this node finds it by COLUMN unless it records it;
|
|
2254
|
+
// the column is about to move, so record it first — where the match
|
|
2255
|
+
// is unambiguous (one seated node draws that column).
|
|
2256
|
+
const sameColumn = configs.filter((c) => !c.derive &&
|
|
2257
|
+
c.source === node.source &&
|
|
2258
|
+
(c.column === node.column || !!c.fan?.includes(node.column)));
|
|
2259
|
+
const orphans = new Map();
|
|
2260
|
+
if (sameColumn.length === 1)
|
|
2261
|
+
for (const c of configs) {
|
|
2262
|
+
if (!c.derive || c.source !== node.source)
|
|
2263
|
+
continue;
|
|
2264
|
+
const i = inputNames(c.derive).findIndex((n, k) => n === node.column && typeof c.derive.inputs[k] === 'string');
|
|
2265
|
+
if (i >= 0 && c.parentIds?.[i] == null)
|
|
2266
|
+
orphans.set(c.id, i);
|
|
2267
|
+
}
|
|
2268
|
+
const next = dataColumnsConfig(node, event.columns);
|
|
2269
|
+
return context.rows.map((r) => ({
|
|
2270
|
+
...r,
|
|
2271
|
+
configs: r.configs.map((c) => {
|
|
2272
|
+
if (c.id === event.id)
|
|
2273
|
+
return next;
|
|
2274
|
+
const i = orphans.get(c.id);
|
|
2275
|
+
if (i == null)
|
|
2276
|
+
return c;
|
|
2277
|
+
const parentIds = [...(c.parentIds ?? [])];
|
|
2278
|
+
parentIds[i] = node.id;
|
|
2279
|
+
return { ...c, parentIds };
|
|
2280
|
+
}),
|
|
2281
|
+
}));
|
|
2282
|
+
},
|
|
2283
|
+
}),
|
|
2134
2284
|
setStudyOutputs: assign({
|
|
2135
2285
|
rows: ({ context, event }) => {
|
|
2136
2286
|
if (event.type !== 'series.setStudyOutputs')
|
|
@@ -2413,7 +2563,7 @@ export const terminalMachine = setup({
|
|
|
2413
2563
|
// may not rewrite which config a study is on (an untyped host
|
|
2414
2564
|
// could still send one).
|
|
2415
2565
|
c.id === event.id
|
|
2416
|
-
?
|
|
2566
|
+
? coherentPatch(c, event.patch)
|
|
2417
2567
|
: follow.has(c.id)
|
|
2418
2568
|
? { ...c, color: color }
|
|
2419
2569
|
: c),
|
|
@@ -2829,6 +2979,7 @@ export const terminalMachine = setup({
|
|
|
2829
2979
|
'series.setStudyParam': { guard: 'canSetStudyParam', actions: 'setStudyParam' },
|
|
2830
2980
|
'series.setStudyOutput': { guard: 'canSetStudyOutput', actions: 'setStudyOutput' },
|
|
2831
2981
|
'series.setStudyInput': { guard: 'canSetStudyInput', actions: 'setStudyInput' },
|
|
2982
|
+
'series.setDataColumns': { guard: 'canSetDataColumns', actions: 'setDataColumns' },
|
|
2832
2983
|
'series.setStudyOutputs': { guard: 'canSetStudyOutputs', actions: 'setStudyOutputs' },
|
|
2833
2984
|
'series.order': { actions: 'orderSeries' },
|
|
2834
2985
|
'series.reindex': { actions: 'orderSeries' },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tidal-ts/terminal",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The terminal machine — an XState v5 statechart that owns a chart's configuration (rows, series, studies, pairs, axes, presets) and never its data.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
"xstate": "^5.28.0"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@tidal-ts/chart": "0.
|
|
40
|
-
"@tidal-ts/core": "0.
|
|
39
|
+
"@tidal-ts/chart": "0.14.0",
|
|
40
|
+
"@tidal-ts/core": "0.14.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@pond-ts/charts": "^0.73.0",
|