@tidal-ts/terminal 0.5.0 → 0.6.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/terminalMachine.js +51 -17
- package/package.json +3 -3
package/dist/terminalMachine.js
CHANGED
|
@@ -31,18 +31,28 @@ function hidesPointer(context, toggledId, pointer) {
|
|
|
31
31
|
: new Set([toggledId]);
|
|
32
32
|
return cascade.has(pointer);
|
|
33
33
|
}
|
|
34
|
-
import { axisRangeIsEmpty, logAllowed, readsFrom, sourcesOf, } from '@tidal-ts/chart';
|
|
34
|
+
import { axisRangeIsEmpty, logAllowed, isStudySeries, readsFrom, sourcesOf, } 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;
|
|
38
38
|
/** Max viewport rows (the control-panel spec: 1–3, capped at 3 for now). */
|
|
39
39
|
export const MAX_ROWS = 3;
|
|
40
40
|
/**
|
|
41
|
-
* Whether a new study of `op` opens on a row of its own
|
|
42
|
-
* in its own units (pond's `unit` rule — only `inherit`
|
|
43
|
-
* scale)
|
|
41
|
+
* Whether a new study of `op` on `target` opens on a row of its own
|
|
42
|
+
* (TDL-OSCROW): it reads in its own units (pond's `unit` rule — only `inherit`
|
|
43
|
+
* shares its source's scale), its target is a metric rather than a link in a
|
|
44
|
+
* study chain or a pair leg, and there is room for another row.
|
|
44
45
|
*/
|
|
45
|
-
const ownsRow = (context, op) => !opSharesSourceAxis(op) &&
|
|
46
|
+
const ownsRow = (context, target, op) => !opSharesSourceAxis(op) &&
|
|
47
|
+
// Only off a METRIC — a raw one, a derived catalog metric (realized vol) or
|
|
48
|
+
// an unsplit pair's spread. A study of a STUDY, or of a pair leg, stays with
|
|
49
|
+
// its chain: a chain is one pipeline the panel reads top-down within a row,
|
|
50
|
+
// and a compare side is one too; split across rows, the panel showed a
|
|
51
|
+
// middle link as the tail and a leg's oscillator fell out of its pair (tidal
|
|
52
|
+
// #212 review). Its own axis still keeps it off its target's scale.
|
|
53
|
+
(!isStudySeries(target) || isCatalogColumn(context)(target.column)) &&
|
|
54
|
+
!target.group &&
|
|
55
|
+
context.rows.length < MAX_ROWS;
|
|
46
56
|
/** Committed height (px) a freshly added row gets — a **fixed** strip, not a flex
|
|
47
57
|
* remainder row (`height: 0`). Exactly one remainder row is kept (the seed's
|
|
48
58
|
* top/vol panel, which absorbs slack); a second would make dragging any seam
|
|
@@ -996,6 +1006,20 @@ function groupDoomed(rows, groupId) {
|
|
|
996
1006
|
doomed.add(id);
|
|
997
1007
|
return doomed;
|
|
998
1008
|
}
|
|
1009
|
+
/** What `row.remove` takes: the row's configs, each with the same cascade a
|
|
1010
|
+
* single `series.remove` runs (`derivedClosure`), wherever the cascade lands.
|
|
1011
|
+
* So removing a row and removing its series one by one agree: a study of a
|
|
1012
|
+
* STUDY on the row goes with it on any row, and a study of a raw metric (an
|
|
1013
|
+
* RSI of the price on its own row) outlives it, because it reads the data,
|
|
1014
|
+
* not the config. */
|
|
1015
|
+
function rowDoomed(rows, rowId) {
|
|
1016
|
+
const all = flatConfigs(rows);
|
|
1017
|
+
const doomed = new Set();
|
|
1018
|
+
for (const c of rows.find((r) => r.id === rowId)?.configs ?? [])
|
|
1019
|
+
for (const id of derivedClosure(all, c.id))
|
|
1020
|
+
doomed.add(id);
|
|
1021
|
+
return doomed;
|
|
1022
|
+
}
|
|
999
1023
|
export const groupMembers = (configs, groupId) => configs
|
|
1000
1024
|
.filter((c) => c.group?.id === groupId)
|
|
1001
1025
|
.sort((a, b) => (a.group.side === b.group.side ? 0 : a.group.side === 'A' ? -1 : 1));
|
|
@@ -1629,7 +1653,7 @@ export const terminalMachine = setup({
|
|
|
1629
1653
|
// row it drew over the price on a second scale, which is what the
|
|
1630
1654
|
// drawing plan measured for 63 of the addable studies. With the row cap
|
|
1631
1655
|
// reached it overlays as before, on its own axis, and can be moved later.
|
|
1632
|
-
if (ownsRow(context, event.op)) {
|
|
1656
|
+
if (ownsRow(context, target, event.op)) {
|
|
1633
1657
|
// Under the target's row — and under any own-row study of the same
|
|
1634
1658
|
// target already there, so oscillators stack in the order added.
|
|
1635
1659
|
const built = studiesOn(flatConfigs(context.rows), target.id, isCatalogColumn(context));
|
|
@@ -1657,8 +1681,8 @@ export const terminalMachine = setup({
|
|
|
1657
1681
|
rowSeq: ({ context, event }) => {
|
|
1658
1682
|
if (event.type !== 'series.addStudy')
|
|
1659
1683
|
return context.rowSeq;
|
|
1660
|
-
const
|
|
1661
|
-
return
|
|
1684
|
+
const target = flatConfigs(context.rows).find((c) => c.id === event.targetId);
|
|
1685
|
+
return target && ownsRow(context, target, event.op) ? context.rowSeq + 1 : context.rowSeq;
|
|
1662
1686
|
},
|
|
1663
1687
|
// Expand the new study so its controls (period, colour) open for tuning.
|
|
1664
1688
|
expanded: ({ context, event }) => {
|
|
@@ -2330,24 +2354,34 @@ export const terminalMachine = setup({
|
|
|
2330
2354
|
},
|
|
2331
2355
|
}),
|
|
2332
2356
|
removeRow: assign({
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2357
|
+
// Removing a row is removing each of its series (`rowDoomed`), so a
|
|
2358
|
+
// study of one of its STUDIES goes too, on whatever row it sits.
|
|
2359
|
+
rows: ({ context, event }) => {
|
|
2360
|
+
if (event.type !== 'row.remove' || context.rows.length <= 1)
|
|
2361
|
+
return context.rows;
|
|
2362
|
+
const doomed = rowDoomed(context.rows, event.id);
|
|
2363
|
+
const after = context.rows
|
|
2364
|
+
.filter((r) => r.id !== event.id)
|
|
2365
|
+
.map((r) => ({ ...r, configs: r.configs.filter((c) => !doomed.has(c.id)) }));
|
|
2366
|
+
// Removing the remainder row would leave the stack with none, so the
|
|
2367
|
+
// first survivor takes over as the one that absorbs slack.
|
|
2368
|
+
return pruneEmptied(context.rows, after);
|
|
2369
|
+
},
|
|
2338
2370
|
// Removing a row drops its series for good, so a pointer into it can't return
|
|
2339
2371
|
// (unlike a ticker switch) — clear both (mirrors removeSeries).
|
|
2340
2372
|
selected: ({ context, event }) => {
|
|
2341
2373
|
if (event.type !== 'row.remove' || context.rows.length <= 1)
|
|
2342
2374
|
return context.selected;
|
|
2343
|
-
|
|
2344
|
-
|
|
2375
|
+
return context.selected != null && rowDoomed(context.rows, event.id).has(context.selected)
|
|
2376
|
+
? null
|
|
2377
|
+
: context.selected;
|
|
2345
2378
|
},
|
|
2346
2379
|
expanded: ({ context, event }) => {
|
|
2347
2380
|
if (event.type !== 'row.remove' || context.rows.length <= 1)
|
|
2348
2381
|
return context.expanded;
|
|
2349
|
-
|
|
2350
|
-
|
|
2382
|
+
return context.expanded != null && rowDoomed(context.rows, event.id).has(context.expanded)
|
|
2383
|
+
? null
|
|
2384
|
+
: context.expanded;
|
|
2351
2385
|
},
|
|
2352
2386
|
}),
|
|
2353
2387
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tidal-ts/terminal",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.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/
|
|
40
|
-
"@tidal-ts/
|
|
39
|
+
"@tidal-ts/core": "0.6.0",
|
|
40
|
+
"@tidal-ts/chart": "0.6.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@pond-ts/charts": "^0.70.0",
|