@tidal-ts/terminal 0.2.2 → 0.4.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/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/terminalMachine.d.ts +30 -0
- package/dist/terminalMachine.js +124 -27
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -6,5 +6,5 @@
|
|
|
6
6
|
* private to the module.
|
|
7
7
|
*/
|
|
8
8
|
export { TerminalProvider, useRows, useSelectedSeries, useExpandedSeries, useControlsOpen, usePresetSaved, useActiveSlot, useAddSeries, useAddPair, useCompareAll, useAddStudy, useSetStudyParam, 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, studyChainTail, studyOfferable, SOURCE_COLUMNS, swapAllowed, type EditScope, type RowState, type TerminalPreset, type MetricEntry, type PairLegInput, type PresetStorage, type TerminalEvent, type TerminalInput, } from './terminalMachine.js';
|
|
9
|
+
export { PRESET_SLOTS, MAX_ROWS, activeSlot, canonRows, columnLabel, columnUnits, entryColumn, groupMembers, mintId, axisMoveAllowed, linkToggleAllowed, respecAllowed, outputAllowed, 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
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* private to the module.
|
|
7
7
|
*/
|
|
8
8
|
export { TerminalProvider, useRows, useSelectedSeries, useExpandedSeries, useControlsOpen, usePresetSaved, useActiveSlot, useAddSeries, useAddPair, useCompareAll, useAddStudy, useSetStudyParam, 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, studyChainTail, studyOfferable, SOURCE_COLUMNS, swapAllowed, } from './terminalMachine.js';
|
|
9
|
+
export { PRESET_SLOTS, MAX_ROWS, activeSlot, canonRows, columnLabel, columnUnits, entryColumn, groupMembers, mintId, axisMoveAllowed, linkToggleAllowed, respecAllowed, outputAllowed, 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).
|
|
@@ -151,6 +151,13 @@ export type TerminalEvent = {
|
|
|
151
151
|
name: string;
|
|
152
152
|
value: number;
|
|
153
153
|
}
|
|
154
|
+
/** Which output of a multi-output source a study reads (`Middle`, `Hist`) —
|
|
155
|
+
* the output picker. `output` is one of the source op's declared suffixes. */
|
|
156
|
+
| {
|
|
157
|
+
type: 'series.setStudyOutput';
|
|
158
|
+
id: string;
|
|
159
|
+
output: string;
|
|
160
|
+
}
|
|
154
161
|
/** Draw-order (z) within the series' own row. The row's config list is
|
|
155
162
|
* **front→back** — index 0 paints on top (the render reverses for
|
|
156
163
|
* `<Layers>`), so `up` moves toward the front. */
|
|
@@ -418,6 +425,19 @@ export declare function columnLabel(scope: EditScope, column: string): string;
|
|
|
418
425
|
* (PR #140 review, MEDIUM).
|
|
419
426
|
*/
|
|
420
427
|
export declare function respecAllowed(scope: EditScope, id: string, name: string, value: number): boolean;
|
|
428
|
+
/**
|
|
429
|
+
* Whether a study can switch to reading `output` of its multi-output source —
|
|
430
|
+
* shared by the guard and the host, so a refused choice renders disabled (the
|
|
431
|
+
* {@link respecAllowed} contract). Refused when the study reads no such source
|
|
432
|
+
* (a pair's legs included: see `studyPick`), the source does not declare
|
|
433
|
+
* `output`, it is already the one read, or the rewrite would be incoherent: a
|
|
434
|
+
* spec the registry rejects, a shared axis left holding two units, or a study
|
|
435
|
+
* on its SOURCE's axis changing unit — an SMA of a regression's `R2` is
|
|
436
|
+
* unitless and would be drawn on the regression's `$` scale.
|
|
437
|
+
*
|
|
438
|
+
* Total: it runs in a guard, where a throw kills the actor.
|
|
439
|
+
*/
|
|
440
|
+
export declare function outputAllowed(scope: EditScope, id: string, output: string): boolean;
|
|
421
441
|
export declare const groupMembers: (configs: readonly SeriesConfig[], groupId: string) => SeriesConfig[];
|
|
422
442
|
/**
|
|
423
443
|
* Whether `id` can move onto the axis keyed by `axisGroup` (undefined = the
|
|
@@ -487,6 +507,10 @@ export declare const terminalMachine: import("xstate").StateMachine<TerminalCont
|
|
|
487
507
|
id: string;
|
|
488
508
|
name: string;
|
|
489
509
|
value: number;
|
|
510
|
+
} | {
|
|
511
|
+
type: "series.setStudyOutput";
|
|
512
|
+
id: string;
|
|
513
|
+
output: string;
|
|
490
514
|
} | {
|
|
491
515
|
type: "series.order";
|
|
492
516
|
id: string;
|
|
@@ -582,6 +606,9 @@ export declare const terminalMachine: import("xstate").StateMachine<TerminalCont
|
|
|
582
606
|
} | {
|
|
583
607
|
type: "addPair";
|
|
584
608
|
params: import("xstate").NonReducibleUnknown;
|
|
609
|
+
} | {
|
|
610
|
+
type: "setStudyOutput";
|
|
611
|
+
params: import("xstate").NonReducibleUnknown;
|
|
585
612
|
} | {
|
|
586
613
|
type: "setStudyParam";
|
|
587
614
|
params: import("xstate").NonReducibleUnknown;
|
|
@@ -672,6 +699,9 @@ export declare const terminalMachine: import("xstate").StateMachine<TerminalCont
|
|
|
672
699
|
} | {
|
|
673
700
|
type: "canAddPair";
|
|
674
701
|
params: unknown;
|
|
702
|
+
} | {
|
|
703
|
+
type: "canSetStudyOutput";
|
|
704
|
+
params: unknown;
|
|
675
705
|
} | {
|
|
676
706
|
type: "canSetStudyParam";
|
|
677
707
|
params: unknown;
|
package/dist/terminalMachine.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { assign, enqueueActions, setup } from 'xstate';
|
|
2
|
-
import { COMPARE_PREFIX, hasPairOp, usesCompare, deriveId, opParams, opInputs, opNeedsColumns, opIsBand, opIsMulti, TARGET_ROLES, opSharesSourceAxis, studyTag, inputNames, isPairOp, isValidSpec, partStudyLabel, readPairParts, specUnit, substituteInput, } from '@tidal-ts/core';
|
|
2
|
+
import { COMPARE_PREFIX, hasPairOp, usesCompare, deriveId, opParams, opInputs, opNeedsColumns, opIsBand, opIsMulti, opOutputs, TARGET_ROLES, opSharesSourceAxis, studyTag, inputNames, isPickedInput, isPairOp, isValidSpec, partStudyLabel, readPairParts, specUnit, studyInputOf, studyPick, substituteInput, withStudyOutput, } from '@tidal-ts/core';
|
|
3
3
|
/**
|
|
4
4
|
* The bar columns each data SOURCE carries — the one fact that decides whether a
|
|
5
5
|
* multi-column study is offerable on a series. Only the price series has bars;
|
|
@@ -392,7 +392,10 @@ function toConfig(e, id, axis = e.axis) {
|
|
|
392
392
|
/** The spec a study of `target` at `(op, period)` induces — reads the target's
|
|
393
393
|
* DATA column, or **nests** the target's own spec when the target is derived
|
|
394
394
|
* (the engine reads a string input as a raw column, so composition nests;
|
|
395
|
-
* content-addressing makes the seated copy and the nested copy one node).
|
|
395
|
+
* content-addressing makes the seated copy and the nested copy one node). A
|
|
396
|
+
* MULTI-OUTPUT target is nested as one PICKED output, its primary
|
|
397
|
+
* (`studyInputOf`) — never bare, which would read whichever output it happens
|
|
398
|
+
* to declare first (TDL-STUDYCHAIN). */
|
|
396
399
|
const studySpec = (target, op, period) => {
|
|
397
400
|
// Params come from the REGISTRY, not from a list here: an op is tuned by
|
|
398
401
|
// exactly what it declares, so a two-param study (a band's `period` +
|
|
@@ -420,7 +423,7 @@ const studySpec = (target, op, period) => {
|
|
|
420
423
|
// and `deriveId` dedupes them. That is correct — ATR(14) of the bars is one
|
|
421
424
|
// series — and it is why the picker has to refuse the op where its columns
|
|
422
425
|
// are absent (`opNeedsColumns`) rather than let the fold skip it silently.
|
|
423
|
-
const self = target.derive ?? target.column;
|
|
426
|
+
const self = studyInputOf(target.derive ?? target.column);
|
|
424
427
|
const inputs = opInputs(op).map((r) =>
|
|
425
428
|
// A target role takes the target; a bar role takes its own column. No
|
|
426
429
|
// default and not a target role should be unreachable (a benchmark role is
|
|
@@ -430,7 +433,7 @@ const studySpec = (target, op, period) => {
|
|
|
430
433
|
return {
|
|
431
434
|
op,
|
|
432
435
|
...(declared.length > 0 ? { params } : {}),
|
|
433
|
-
inputs: inputs.length > 0 ? inputs : [
|
|
436
|
+
inputs: inputs.length > 0 ? inputs : [self],
|
|
434
437
|
};
|
|
435
438
|
};
|
|
436
439
|
/** A study `SeriesConfig` layered on a target — same source, and the same axis
|
|
@@ -440,7 +443,7 @@ const studySpec = (target, op, period) => {
|
|
|
440
443
|
* source's params) with the op·period appended — e.g. `Price · SMA · 20`,
|
|
441
444
|
* `ATM Vol · 21D · SMA · 20` — so the lineage is legible. Warm default colour so
|
|
442
445
|
* it reads over its source; the user recolours. */
|
|
443
|
-
function studyConfig(target, op, period, id) {
|
|
446
|
+
function studyConfig(target, op, period, id, unitOf) {
|
|
444
447
|
const derive = studySpec(target, op, period);
|
|
445
448
|
// Only an `inherit` op may share its source's scale (pond's rule, shipped
|
|
446
449
|
// with the catalog's `unit`). An RSI is bounded 0..100 and a vol reading is
|
|
@@ -449,11 +452,21 @@ function studyConfig(target, op, period, id) {
|
|
|
449
452
|
// render before this. A study that reads in its own units gets its own axis
|
|
450
453
|
// group, keyed by its own id, and its own unit for the labels.
|
|
451
454
|
const shares = opSharesSourceAxis(op);
|
|
452
|
-
|
|
455
|
+
// The target's own unit for its column, and the scope's for everything else
|
|
456
|
+
// (a bar's high/low read as its close) — the SAME resolution a re-spec uses,
|
|
457
|
+
// so adding a study and retuning it can never disagree about its unit.
|
|
458
|
+
const own = specUnit(derive, (col) => col === target.column ? (target.unit ?? '') : unitOf(col));
|
|
459
|
+
// Which output of a multi-output target this study reads, named in the label
|
|
460
|
+
// (`Price · DONCHIAN(20) · Middle · SMA(10)`) so the choice is never silent.
|
|
461
|
+
const picked = derive.inputs.find(isPickedInput);
|
|
453
462
|
return {
|
|
454
463
|
id,
|
|
455
|
-
|
|
456
|
-
|
|
464
|
+
// Sharing means sharing the SOURCE's scale — which is the source's own axis
|
|
465
|
+
// group when it has one. An SMA of a MACD (or of an RSI) left out of that
|
|
466
|
+
// group landed on the row's shared axis instead, a line near zero drawn on
|
|
467
|
+
// the price's scale.
|
|
468
|
+
...(shares ? (target.axisGroup ? { axisGroup: target.axisGroup } : {}) : { axisGroup: id }),
|
|
469
|
+
label: `${target.label}${picked ? ` · ${picked.output}` : ''} · ${studyTag(derive)}`, // legend chip
|
|
457
470
|
family: target.family ?? target.label, // main line = the source's name
|
|
458
471
|
tenor: target.tenor, // carry the source's tenor into the params sub-line
|
|
459
472
|
// A study is the same reading, smoothed — so it takes its metric's COLOUR
|
|
@@ -550,7 +563,9 @@ const underCompare = (input) => typeof input === 'string'
|
|
|
550
563
|
input.startsWith(COMPARE_PREFIX)
|
|
551
564
|
? input
|
|
552
565
|
: `${COMPARE_PREFIX}${input}`
|
|
553
|
-
:
|
|
566
|
+
: isPickedInput(input)
|
|
567
|
+
? { from: underCompare(input.from), output: input.output }
|
|
568
|
+
: { ...input, inputs: input.inputs.map(underCompare) };
|
|
554
569
|
/** "Is this column a catalog metric's?" — {@link layeredOn}'s test for the
|
|
555
570
|
* derived metrics that stand alone instead of travelling with a source. A
|
|
556
571
|
* seated config's id no longer says where it came from, so catalog-ness is
|
|
@@ -574,18 +589,31 @@ export const columnUnits = (catalog, configs = []) => {
|
|
|
574
589
|
units.set(c.column, c.unit ?? '');
|
|
575
590
|
for (const e of catalog)
|
|
576
591
|
units.set(entryColumn(e), e.unit);
|
|
592
|
+
// A bar's open/high/low are prices like its close, but no catalog entry
|
|
593
|
+
// names them — they are inputs, never series. Unknown, they read unitless,
|
|
594
|
+
// so every study reading high/low (a Donchian, an ATR band) computed its unit
|
|
595
|
+
// as '' on a RE-spec while it was seated as '$': the unit gate then refused
|
|
596
|
+
// every retune of it, silently (found building the output picker).
|
|
597
|
+
for (const part of BAR_PRICE_PARTS)
|
|
598
|
+
if (!units.has(part))
|
|
599
|
+
units.set(part, units.get('close') ?? '');
|
|
577
600
|
return (column) => units.get(column) ??
|
|
578
601
|
(column.startsWith(COMPARE_PREFIX)
|
|
579
602
|
? (units.get(column.slice(COMPARE_PREFIX.length)) ?? '')
|
|
580
603
|
: '');
|
|
581
604
|
};
|
|
605
|
+
/** The bar columns that read in the same unit as the bar's `close`. */
|
|
606
|
+
const BAR_PRICE_PARTS = ['open', 'high', 'low'];
|
|
582
607
|
const unitOfColumn = (scope) => columnUnits(scope.catalog, flatConfigs(scope.rows));
|
|
583
608
|
/** A resolved+bound leg: the graph input the pair spec takes, and the
|
|
584
609
|
* decorated label the spread reads by. Order matters: the study wraps the
|
|
585
610
|
* metric, then the compare rebind rewrites the LEAVES — so a compare-bound
|
|
586
611
|
* studied leg computes the study over the compare columns. */
|
|
587
612
|
const boundLeg = (leg, input) => {
|
|
588
|
-
|
|
613
|
+
// A multi-output leg (a band) reads its PRIMARY output, picked, exactly as a
|
|
614
|
+
// study of it does — nested bare it read whichever output was declared first,
|
|
615
|
+
// so `Donchian − Price` was silently the TOP edge minus the price.
|
|
616
|
+
let graph = studyInputOf(leg.spec ?? leg.column);
|
|
589
617
|
let label = leg.label;
|
|
590
618
|
if (input.study) {
|
|
591
619
|
graph = { op: input.study.op, params: { period: input.study.period }, inputs: [graph] };
|
|
@@ -787,14 +815,55 @@ export function respecAllowed(scope, id, name, value) {
|
|
|
787
815
|
// could disagree about the very thing they now both write (PR #141 review).
|
|
788
816
|
return next !== null && unitsStayCoherent(scope.rows, next);
|
|
789
817
|
}
|
|
818
|
+
/**
|
|
819
|
+
* Whether a study can switch to reading `output` of its multi-output source —
|
|
820
|
+
* shared by the guard and the host, so a refused choice renders disabled (the
|
|
821
|
+
* {@link respecAllowed} contract). Refused when the study reads no such source
|
|
822
|
+
* (a pair's legs included: see `studyPick`), the source does not declare
|
|
823
|
+
* `output`, it is already the one read, or the rewrite would be incoherent: a
|
|
824
|
+
* spec the registry rejects, a shared axis left holding two units, or a study
|
|
825
|
+
* on its SOURCE's axis changing unit — an SMA of a regression's `R2` is
|
|
826
|
+
* unitless and would be drawn on the regression's `$` scale.
|
|
827
|
+
*
|
|
828
|
+
* Total: it runs in a guard, where a throw kills the actor.
|
|
829
|
+
*/
|
|
830
|
+
export function outputAllowed(scope, id, output) {
|
|
831
|
+
try {
|
|
832
|
+
const configs = flatConfigs(scope.rows);
|
|
833
|
+
const target = configs.find((c) => c.id === id);
|
|
834
|
+
if (!target?.derive)
|
|
835
|
+
return false;
|
|
836
|
+
const pick = studyPick(target.derive);
|
|
837
|
+
if (!pick || !opOutputs(pick.from.op).includes(output))
|
|
838
|
+
return false;
|
|
839
|
+
if (pick.explicit && pick.output === output)
|
|
840
|
+
return false;
|
|
841
|
+
if (!isValidSpec(withStudyOutput(target.derive, output)))
|
|
842
|
+
return false;
|
|
843
|
+
const next = propagateRespec(configs, id, respecOutput(target, output), unitOfColumn(scope));
|
|
844
|
+
if (next === null || !unitsStayCoherent(scope.rows, next))
|
|
845
|
+
return false;
|
|
846
|
+
const borrowed = target.axisGroup != null && target.axisGroup !== target.id;
|
|
847
|
+
return !(borrowed && next.get(id).unit !== (target.unit ?? ''));
|
|
848
|
+
}
|
|
849
|
+
catch {
|
|
850
|
+
return false;
|
|
851
|
+
}
|
|
852
|
+
}
|
|
790
853
|
// --- fn() = None: the LEG GROUP ----------------------------------------------
|
|
791
854
|
// With no transform a pair has no single line and therefore no single ink, so
|
|
792
855
|
// it stops being one config and becomes TWO — each an ordinary series with its
|
|
793
856
|
// own colour, axis, eye and study pipeline, tied together by `SeriesGroup`.
|
|
794
857
|
// Splitting and re-joining are one edit read in two directions.
|
|
795
858
|
/** A leg's graph input as a seated config would carry it: a raw column has no
|
|
796
|
-
* spec, a derived leg carries its own
|
|
797
|
-
|
|
859
|
+
* spec, a derived leg carries its own, and a PICKED leg is its source study —
|
|
860
|
+
* the config that publishes the output (a band leg splits out as the band). */
|
|
861
|
+
const legParts = (leg) => {
|
|
862
|
+
if (typeof leg === 'string')
|
|
863
|
+
return { column: leg };
|
|
864
|
+
const spec = isPickedInput(leg) ? leg.from : leg;
|
|
865
|
+
return { column: deriveId(spec), derive: spec };
|
|
866
|
+
};
|
|
798
867
|
/** The colour leg B takes when a pair splits — the first palette key neither
|
|
799
868
|
* leg A nor anything else in the row is already using, so two fresh lines are
|
|
800
869
|
* never the same colour. Falls back to leg A's if the palette is exhausted. */
|
|
@@ -860,7 +929,7 @@ adding = false) {
|
|
|
860
929
|
const id = pairIdFree ? ((pairIdFree = false), pair.id) : mintId(seq++);
|
|
861
930
|
if (id !== pair.id)
|
|
862
931
|
plan.mints += 1;
|
|
863
|
-
const unit =
|
|
932
|
+
const unit = derive ? specUnit(derive, unitOf) : unitOf(column);
|
|
864
933
|
// A spread arrives UNLINKED because it oscillates; its LEGS do not — they
|
|
865
934
|
// are the raw metrics, and the whole point of drawing both is comparing
|
|
866
935
|
// them, which needs ONE scale. So a created leg is placed like any new
|
|
@@ -969,6 +1038,25 @@ function respecParam(study, name, value) {
|
|
|
969
1038
|
label: `${base} · ${studyTag(derive)}`,
|
|
970
1039
|
};
|
|
971
1040
|
}
|
|
1041
|
+
/** Re-spec a study to read another output of its source, **in place** — the
|
|
1042
|
+
* identity stands, like {@link respecParam}. The label's output segment is
|
|
1043
|
+
* swapped (`… · Line · SMA(10)` → `… · Hist · SMA(10)`); a study saved before
|
|
1044
|
+
* its label named one gains it. */
|
|
1045
|
+
function respecOutput(study, output) {
|
|
1046
|
+
const prev = study.derive;
|
|
1047
|
+
const pick = studyPick(prev);
|
|
1048
|
+
const derive = withStudyOutput(prev, output);
|
|
1049
|
+
const tag = ` · ${studyTag(prev)}`;
|
|
1050
|
+
const named = ` · ${pick.output}${tag}`;
|
|
1051
|
+
// `label` is untyped persisted state; a missing one must not throw here.
|
|
1052
|
+
const label = typeof study.label === 'string' ? study.label : '';
|
|
1053
|
+
const base = label.endsWith(named)
|
|
1054
|
+
? label.slice(0, -named.length)
|
|
1055
|
+
: label.endsWith(tag)
|
|
1056
|
+
? label.slice(0, -tag.length)
|
|
1057
|
+
: (study.family ?? label);
|
|
1058
|
+
return { ...study, column: deriveId(derive), derive, label: `${base} · ${output}${tag}` };
|
|
1059
|
+
}
|
|
972
1060
|
function propagateRespec(configs, rootId, root, unitOf) {
|
|
973
1061
|
const rootCfg = configs.find((c) => c.id === rootId);
|
|
974
1062
|
if (!rootCfg?.derive || !root.derive)
|
|
@@ -1365,18 +1453,11 @@ export const terminalMachine = setup({
|
|
|
1365
1453
|
// live — the same move `b544480` made for multi-output targets.
|
|
1366
1454
|
if (!studyOfferable(target.source, event.op))
|
|
1367
1455
|
return false;
|
|
1368
|
-
// A MULTI-OUTPUT
|
|
1369
|
-
//
|
|
1370
|
-
//
|
|
1371
|
-
//
|
|
1372
|
-
//
|
|
1373
|
-
// shape. Which output such a study should read is a real question the
|
|
1374
|
-
// engine has no way to answer (a MACD's line? its histogram?), so refuse
|
|
1375
|
-
// rather than guess. The `Add ▸ Study` menu hides on these too; this is
|
|
1376
|
-
// the guard that covers the picker, which stays open across picks and
|
|
1377
|
-
// appends to the chain TAIL.
|
|
1378
|
-
if (target.derive && opIsMulti(target.derive.op))
|
|
1379
|
-
return false;
|
|
1456
|
+
// A MULTI-OUTPUT target is fine: `studySpec` reads ONE of its outputs,
|
|
1457
|
+
// picked by name (its primary), so the study has a column to read and the
|
|
1458
|
+
// label says which. This used to refuse a MACD, because a bare nested
|
|
1459
|
+
// multi-output spec read "output 0" — and let a band through, where the
|
|
1460
|
+
// same rule silently smoothed a Donchian's top edge (TDL-STUDYCHAIN).
|
|
1380
1461
|
// A study takes at most ONE study of its own: a metric may carry several
|
|
1381
1462
|
// study CHAINS, but a chain never branches (Peter, 2026-09-12). The panel
|
|
1382
1463
|
// reads a chain top-down as a pipeline, and a branch has no reading in
|
|
@@ -1432,7 +1513,11 @@ export const terminalMachine = setup({
|
|
|
1432
1513
|
// whatever the bindings, and two legs drawing one line if unjoined. The
|
|
1433
1514
|
// same metric ACROSS roles (or under different studies) differs after
|
|
1434
1515
|
// binding, so George's canonical case passes.
|
|
1435
|
-
const name = (i) =>
|
|
1516
|
+
const name = (i) => typeof i === 'string'
|
|
1517
|
+
? i
|
|
1518
|
+
: isPickedInput(i)
|
|
1519
|
+
? `${deriveId(i.from)}#${i.output}`
|
|
1520
|
+
: deriveId(i);
|
|
1436
1521
|
if (name(spec.inputs[0]) === name(spec.inputs[1]))
|
|
1437
1522
|
return false;
|
|
1438
1523
|
// UNJOINED: no spread is ever seated, so the test is whether the two legs
|
|
@@ -1458,6 +1543,7 @@ export const terminalMachine = setup({
|
|
|
1458
1543
|
// rewritten spec and returns false rather than throwing — which also covers
|
|
1459
1544
|
// the actor-killing hazard `canAddStudy` guards (a throwing guard kills the
|
|
1460
1545
|
// actor, and the `>= 2` pre-check does not cover the registry's max).
|
|
1546
|
+
canSetStudyOutput: ({ context, event }) => event.type === 'series.setStudyOutput' && outputAllowed(context, event.id, event.output),
|
|
1461
1547
|
canSetStudyParam: ({ context, event }) => event.type === 'series.setStudyParam' &&
|
|
1462
1548
|
respecAllowed(context, event.id, event.name, event.value),
|
|
1463
1549
|
// The chain toggle — delegated to the shared pure helper so the panel's
|
|
@@ -1514,7 +1600,7 @@ export const terminalMachine = setup({
|
|
|
1514
1600
|
// Every assigner in this `assign` sees the SAME pre-update context, so
|
|
1515
1601
|
// the id minted here and the one `expanded`/`cfgSeq` compute below all
|
|
1516
1602
|
// agree without threading a value between them.
|
|
1517
|
-
const cfg = studyConfig(target, event.op, event.period, mintId(context.cfgSeq));
|
|
1603
|
+
const cfg = studyConfig(target, event.op, event.period, mintId(context.cfgSeq), unitOfColumn(context));
|
|
1518
1604
|
// Overlay on the target's row (own-row oscillators are a later step),
|
|
1519
1605
|
// inserted directly IN FRONT of its target — the list is front→back, so
|
|
1520
1606
|
// that's the target's own index. A study must read over its source (see
|
|
@@ -1623,6 +1709,16 @@ export const terminalMachine = setup({
|
|
|
1623
1709
|
// no pointer moves: every config keeps its identity, so selection,
|
|
1624
1710
|
// expansion, ink, axis membership and range pins all survive (they used to
|
|
1625
1711
|
// be destroyed, and the dependents deleted outright).
|
|
1712
|
+
setStudyOutput: assign({
|
|
1713
|
+
rows: ({ context, event }) => {
|
|
1714
|
+
if (event.type !== 'series.setStudyOutput')
|
|
1715
|
+
return context.rows;
|
|
1716
|
+
const target = flatConfigs(context.rows).find((c) => c.id === event.id);
|
|
1717
|
+
if (!target?.derive)
|
|
1718
|
+
return context.rows;
|
|
1719
|
+
return applyRespec(context, event.id, respecOutput(target, event.output));
|
|
1720
|
+
},
|
|
1721
|
+
}),
|
|
1626
1722
|
setStudyParam: assign({
|
|
1627
1723
|
rows: ({ context, event }) => {
|
|
1628
1724
|
if (event.type !== 'series.setStudyParam')
|
|
@@ -2258,6 +2354,7 @@ export const terminalMachine = setup({
|
|
|
2258
2354
|
}),
|
|
2259
2355
|
},
|
|
2260
2356
|
'series.setStudyParam': { guard: 'canSetStudyParam', actions: 'setStudyParam' },
|
|
2357
|
+
'series.setStudyOutput': { guard: 'canSetStudyOutput', actions: 'setStudyOutput' },
|
|
2261
2358
|
'series.order': { actions: 'orderSeries' },
|
|
2262
2359
|
'series.reindex': { actions: 'orderSeries' },
|
|
2263
2360
|
'series.moveToRow': { guard: 'canMoveToRow', actions: 'moveSeriesToRow' },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tidal-ts/terminal",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.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.4.0",
|
|
40
|
+
"@tidal-ts/core": "0.4.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@pond-ts/charts": "^0.70.0",
|