@orangecharts/wrun-chart-host 0.1.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/README.md +72 -0
- package/dist/constants/governed-exchanges.constants.d.ts +11 -0
- package/dist/constants/governed-exchanges.constants.js +11 -0
- package/dist/constants/indicator-sets.constants.d.ts +8 -0
- package/dist/constants/indicator-sets.constants.js +8 -0
- package/dist/constants/interval.constants.d.ts +34 -0
- package/dist/constants/interval.constants.js +121 -0
- package/dist/constants/scriptEditor/technicalIndicatorScriptKeys.constants.d.ts +28 -0
- package/dist/constants/scriptEditor/technicalIndicatorScriptKeys.constants.js +65 -0
- package/dist/constants/tpo-color-schemes.constants.d.ts +30 -0
- package/dist/constants/tpo-color-schemes.constants.js +32 -0
- package/dist/host-env.d.ts +102 -0
- package/dist/host-env.js +26 -0
- package/dist/index.d.ts +93 -0
- package/dist/index.js +96 -0
- package/dist/indicators/controls/tpo-letter.util.d.ts +2 -0
- package/dist/indicators/controls/tpo-letter.util.js +13 -0
- package/dist/indicators/controls/tpo-session.util.d.ts +99 -0
- package/dist/indicators/controls/tpo-session.util.js +389 -0
- package/dist/interfaces/kscript-diagnostics.interface.d.ts +64 -0
- package/dist/interfaces/kscript-diagnostics.interface.js +1 -0
- package/dist/interfaces/om-panel-data.interface.d.ts +103 -0
- package/dist/interfaces/om-panel-data.interface.js +7 -0
- package/dist/interfaces/wrun-runtime.interface.d.ts +2659 -0
- package/dist/interfaces/wrun-runtime.interface.js +55 -0
- package/dist/utility/chart/calendar-interval.util.d.ts +24 -0
- package/dist/utility/chart/calendar-interval.util.js +81 -0
- package/dist/utility/chart/candle-bar-end.util.d.ts +15 -0
- package/dist/utility/chart/candle-bar-end.util.js +23 -0
- package/dist/utility/chart/cme-realtime.util.d.ts +24 -0
- package/dist/utility/chart/cme-realtime.util.js +53 -0
- package/dist/utility/chart/interval-ladder.util.d.ts +27 -0
- package/dist/utility/chart/interval-ladder.util.js +92 -0
- package/dist/utility/chart/kscript-drawing-prep.util.d.ts +40 -0
- package/dist/utility/chart/kscript-drawing-prep.util.js +184 -0
- package/dist/utility/chart/kscript-drawing-safe-area.util.d.ts +95 -0
- package/dist/utility/chart/kscript-drawing-safe-area.util.js +805 -0
- package/dist/utility/chart/kscript-legend-entries.util.d.ts +166 -0
- package/dist/utility/chart/kscript-legend-entries.util.js +538 -0
- package/dist/utility/chart/kscript-output-role.util.d.ts +32 -0
- package/dist/utility/chart/kscript-output-role.util.js +215 -0
- package/dist/utility/chart/kscript-provenance-keys.util.d.ts +22 -0
- package/dist/utility/chart/kscript-provenance-keys.util.js +56 -0
- package/dist/utility/chart/kscript-run-result-normalize.util.d.ts +53 -0
- package/dist/utility/chart/kscript-run-result-normalize.util.js +476 -0
- package/dist/utility/chart/kscript-run-result-shape.util.d.ts +14 -0
- package/dist/utility/chart/kscript-run-result-shape.util.js +66 -0
- package/dist/utility/chart/kscript-titancharts-container.util.d.ts +29 -0
- package/dist/utility/chart/kscript-titancharts-container.util.js +151 -0
- package/dist/utility/chart/kscript-viewport-overlays.util.d.ts +83 -0
- package/dist/utility/chart/kscript-viewport-overlays.util.js +443 -0
- package/dist/utility/chart/om-panel-push-style.util.d.ts +78 -0
- package/dist/utility/chart/om-panel-push-style.util.js +301 -0
- package/dist/utility/chart/om-panel.util.d.ts +166 -0
- package/dist/utility/chart/om-panel.util.js +815 -0
- package/dist/utility/chart/om-series.util.d.ts +42 -0
- package/dist/utility/chart/om-series.util.js +330 -0
- package/dist/utility/chart/om-target.util.d.ts +11 -0
- package/dist/utility/chart/om-target.util.js +24 -0
- package/dist/utility/chart/om-widget.util.d.ts +148 -0
- package/dist/utility/chart/om-widget.util.js +413 -0
- package/dist/utility/chart/overlay-output-budget.util.d.ts +16 -0
- package/dist/utility/chart/overlay-output-budget.util.js +109 -0
- package/dist/utility/chart/overlay-paint-flags.util.d.ts +24 -0
- package/dist/utility/chart/overlay-paint-flags.util.js +55 -0
- package/dist/utility/chart/profile-row-height.util.d.ts +21 -0
- package/dist/utility/chart/profile-row-height.util.js +110 -0
- package/dist/utility/chart/session-interval.util.d.ts +1 -0
- package/dist/utility/chart/session-interval.util.js +35 -0
- package/dist/utility/chart/technical-script-legend-value.util.d.ts +18 -0
- package/dist/utility/chart/technical-script-legend-value.util.js +53 -0
- package/dist/utility/chart/trading-day.util.d.ts +70 -0
- package/dist/utility/chart/trading-day.util.js +238 -0
- package/dist/utility/chart/wrun-legend-name.util.d.ts +25 -0
- package/dist/utility/chart/wrun-legend-name.util.js +87 -0
- package/dist/utility/chart/wrun-run-result.util.d.ts +977 -0
- package/dist/utility/chart/wrun-run-result.util.js +5179 -0
- package/dist/utility/chart/wrun-visibility-chart.util.d.ts +25 -0
- package/dist/utility/chart/wrun-visibility-chart.util.js +22 -0
- package/dist/utility/indicators/heatmap-sensitivity.util.d.ts +62 -0
- package/dist/utility/indicators/heatmap-sensitivity.util.js +82 -0
- package/dist/utility/number-format.util.d.ts +68 -0
- package/dist/utility/number-format.util.js +188 -0
- package/dist/utility/v2/opra-governed.util.d.ts +1 -0
- package/dist/utility/v2/opra-governed.util.js +13 -0
- package/dist/utility/wrun/wrun-auto-row.util.d.ts +54 -0
- package/dist/utility/wrun/wrun-auto-row.util.js +96 -0
- package/dist/utility/wrun/wrun-batched-marks.util.d.ts +341 -0
- package/dist/utility/wrun/wrun-batched-marks.util.js +938 -0
- package/dist/utility/wrun/wrun-batched-readout.util.d.ts +75 -0
- package/dist/utility/wrun/wrun-batched-readout.util.js +171 -0
- package/dist/utility/wrun/wrun-box-segment.util.d.ts +185 -0
- package/dist/utility/wrun/wrun-box-segment.util.js +570 -0
- package/dist/utility/wrun/wrun-build-memo.util.d.ts +133 -0
- package/dist/utility/wrun/wrun-build-memo.util.js +301 -0
- package/dist/utility/wrun/wrun-builtin-twin-ports.util.d.ts +25 -0
- package/dist/utility/wrun/wrun-builtin-twin-ports.util.js +75 -0
- package/dist/utility/wrun/wrun-builtin-twin.util.d.ts +9 -0
- package/dist/utility/wrun/wrun-builtin-twin.util.js +40 -0
- package/dist/utility/wrun/wrun-canvas-cache.util.d.ts +28 -0
- package/dist/utility/wrun/wrun-canvas-cache.util.js +56 -0
- package/dist/utility/wrun/wrun-canvas-readout.util.d.ts +69 -0
- package/dist/utility/wrun/wrun-canvas-readout.util.js +53 -0
- package/dist/utility/wrun/wrun-canvases.util.d.ts +295 -0
- package/dist/utility/wrun/wrun-canvases.util.js +1432 -0
- package/dist/utility/wrun/wrun-cap-notice.util.d.ts +77 -0
- package/dist/utility/wrun/wrun-cap-notice.util.js +296 -0
- package/dist/utility/wrun/wrun-card-style.util.d.ts +154 -0
- package/dist/utility/wrun/wrun-card-style.util.js +539 -0
- package/dist/utility/wrun/wrun-chart-context.util.d.ts +89 -0
- package/dist/utility/wrun/wrun-chart-context.util.js +213 -0
- package/dist/utility/wrun/wrun-chart-names.util.d.ts +23 -0
- package/dist/utility/wrun/wrun-chart-names.util.js +33 -0
- package/dist/utility/wrun/wrun-chart-time.util.d.ts +12 -0
- package/dist/utility/wrun/wrun-chart-time.util.js +23 -0
- package/dist/utility/wrun/wrun-child-overlay-id.util.d.ts +13 -0
- package/dist/utility/wrun/wrun-child-overlay-id.util.js +44 -0
- package/dist/utility/wrun/wrun-color-facts.util.d.ts +40 -0
- package/dist/utility/wrun/wrun-color-facts.util.js +88 -0
- package/dist/utility/wrun/wrun-color-settings.lazy.d.ts +26 -0
- package/dist/utility/wrun/wrun-color-settings.lazy.js +9 -0
- package/dist/utility/wrun/wrun-color-settings.util.d.ts +351 -0
- package/dist/utility/wrun/wrun-color-settings.util.js +1363 -0
- package/dist/utility/wrun/wrun-footprint-modes.util.d.ts +23 -0
- package/dist/utility/wrun/wrun-footprint-modes.util.js +24 -0
- package/dist/utility/wrun/wrun-frames.d.ts +217 -0
- package/dist/utility/wrun/wrun-frames.js +1021 -0
- package/dist/utility/wrun/wrun-handles.util.d.ts +792 -0
- package/dist/utility/wrun/wrun-handles.util.js +2050 -0
- package/dist/utility/wrun/wrun-heatmap-cell-budget.util.d.ts +156 -0
- package/dist/utility/wrun/wrun-heatmap-cell-budget.util.js +342 -0
- package/dist/utility/wrun/wrun-hosted-wire-caps.d.ts +218 -0
- package/dist/utility/wrun/wrun-hosted-wire-caps.js +667 -0
- package/dist/utility/wrun/wrun-hosted-wire.util.d.ts +40 -0
- package/dist/utility/wrun/wrun-hosted-wire.util.js +27 -0
- package/dist/utility/wrun/wrun-hover.util.d.ts +182 -0
- package/dist/utility/wrun/wrun-hover.util.js +534 -0
- package/dist/utility/wrun/wrun-hud-looks.util.d.ts +246 -0
- package/dist/utility/wrun/wrun-hud-looks.util.js +587 -0
- package/dist/utility/wrun/wrun-integration-budget.util.d.ts +47 -0
- package/dist/utility/wrun/wrun-integration-budget.util.js +122 -0
- package/dist/utility/wrun/wrun-latest-snapshot.d.ts +19 -0
- package/dist/utility/wrun/wrun-latest-snapshot.js +7 -0
- package/dist/utility/wrun/wrun-levels-child.util.d.ts +131 -0
- package/dist/utility/wrun/wrun-levels-child.util.js +514 -0
- package/dist/utility/wrun/wrun-lifecycle.contract.d.ts +75 -0
- package/dist/utility/wrun/wrun-lifecycle.contract.js +9 -0
- package/dist/utility/wrun/wrun-market-facts.util.d.ts +116 -0
- package/dist/utility/wrun/wrun-market-facts.util.js +238 -0
- package/dist/utility/wrun/wrun-output-style.util.d.ts +344 -0
- package/dist/utility/wrun/wrun-output-style.util.js +1239 -0
- package/dist/utility/wrun/wrun-overlay-identity.util.d.ts +84 -0
- package/dist/utility/wrun/wrun-overlay-identity.util.js +142 -0
- package/dist/utility/wrun/wrun-overlay-result.util.d.ts +120 -0
- package/dist/utility/wrun/wrun-overlay-result.util.js +219 -0
- package/dist/utility/wrun/wrun-pack.util.d.ts +70 -0
- package/dist/utility/wrun/wrun-pack.util.js +301 -0
- package/dist/utility/wrun/wrun-pane-format.util.d.ts +180 -0
- package/dist/utility/wrun/wrun-pane-format.util.js +299 -0
- package/dist/utility/wrun/wrun-panel-style.lazy.d.ts +25 -0
- package/dist/utility/wrun/wrun-panel-style.lazy.js +15 -0
- package/dist/utility/wrun/wrun-panel-style.util.d.ts +174 -0
- package/dist/utility/wrun/wrun-panel-style.util.js +726 -0
- package/dist/utility/wrun/wrun-param-values.util.d.ts +69 -0
- package/dist/utility/wrun/wrun-param-values.util.js +230 -0
- package/dist/utility/wrun/wrun-refusal.util.d.ts +263 -0
- package/dist/utility/wrun/wrun-refusal.util.js +1259 -0
- package/dist/utility/wrun/wrun-registry-errors.util.d.ts +199 -0
- package/dist/utility/wrun/wrun-registry-errors.util.js +257 -0
- package/dist/utility/wrun/wrun-render-select.util.d.ts +336 -0
- package/dist/utility/wrun/wrun-render-select.util.js +1157 -0
- package/dist/utility/wrun/wrun-script-inputs.util.d.ts +434 -0
- package/dist/utility/wrun/wrun-script-inputs.util.js +1971 -0
- package/dist/utility/wrun/wrun-setting-words.lazy.d.ts +20 -0
- package/dist/utility/wrun/wrun-setting-words.lazy.js +9 -0
- package/dist/utility/wrun/wrun-setting-words.util.d.ts +79 -0
- package/dist/utility/wrun/wrun-setting-words.util.js +176 -0
- package/dist/utility/wrun/wrun-socket-row-store.d.ts +98 -0
- package/dist/utility/wrun/wrun-socket-row-store.js +417 -0
- package/dist/utility/wrun/wrun-style-flags.util.d.ts +18 -0
- package/dist/utility/wrun/wrun-style-flags.util.js +21 -0
- package/dist/utility/wrun/wrun-style-words.util.d.ts +148 -0
- package/dist/utility/wrun/wrun-style-words.util.js +439 -0
- package/dist/utility/wrun/wrun-table-look.util.d.ts +125 -0
- package/dist/utility/wrun/wrun-table-look.util.js +225 -0
- package/dist/utility/wrun/wrun-text-look.util.d.ts +51 -0
- package/dist/utility/wrun/wrun-text-look.util.js +227 -0
- package/dist/utility/wrun/wrun-text-params.util.d.ts +106 -0
- package/dist/utility/wrun/wrun-text-params.util.js +171 -0
- package/dist/utility/wrun/wrun-tpo-rows.util.d.ts +71 -0
- package/dist/utility/wrun/wrun-tpo-rows.util.js +438 -0
- package/dist/utility/wrun/wrun-twin-compute-inputs.util.d.ts +14 -0
- package/dist/utility/wrun/wrun-twin-compute-inputs.util.js +58 -0
- package/dist/utility/wrun/wrun-visibility-table.d.ts +437 -0
- package/dist/utility/wrun/wrun-visibility-table.js +237 -0
- package/dist/utility/wrun/wrun-volume-profile.util.d.ts +37 -0
- package/dist/utility/wrun/wrun-volume-profile.util.js +278 -0
- package/package.json +38 -0
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { type WrunCellsCapSummary } from './wrun-cap-notice.util.js';
|
|
2
|
+
/** A heatmap child's cell layout (`settings.cellLayout`, wrun-canvases.util). */
|
|
3
|
+
export type WrunHeatmapCellLayout = 'book' | 'profile' | 'grid';
|
|
4
|
+
/** The chart the budget reads its mounted children from (any engine instance). */
|
|
5
|
+
export interface WrunHeatmapBudgetChart {
|
|
6
|
+
metadata: ReadonlyArray<{
|
|
7
|
+
id: string;
|
|
8
|
+
}>;
|
|
9
|
+
}
|
|
10
|
+
/** The layout a heatmap config names, `book` for anything it does not. */
|
|
11
|
+
export declare function wrunHeatmapCellLayoutOf(settings: Record<string, unknown> | undefined): WrunHeatmapCellLayout;
|
|
12
|
+
/**
|
|
13
|
+
* The cells one heatmap row holds, as the engine reads it: a book row `[ts, price, size, ...]` its
|
|
14
|
+
* pairs, a grid row `[ts, low, step, v0 .. vN]` its values, a volume-profile row its buckets (nested
|
|
15
|
+
* `[ts, [low, high, buy, sell], ...]` or flat quads). Rows are variable width, so each is measured.
|
|
16
|
+
*/
|
|
17
|
+
export declare function wrunHeatmapRowCells(row: unknown, layout: WrunHeatmapCellLayout): number;
|
|
18
|
+
/** The cells a heatmap's rows hold (one row per bar). */
|
|
19
|
+
export declare function countWrunHeatmapCells(rows: ReadonlyArray<unknown>, layout: WrunHeatmapCellLayout): number;
|
|
20
|
+
export interface WrunHeatmapTrim {
|
|
21
|
+
/** The rows kept: the newest bars whole (the input array itself when nothing was dropped). */
|
|
22
|
+
rows: ReadonlyArray<unknown>;
|
|
23
|
+
/** Cells the input rows held. */
|
|
24
|
+
total: number;
|
|
25
|
+
/** Cells the kept rows hold (at most the cap). */
|
|
26
|
+
drawn: number;
|
|
27
|
+
/** Bars (rows) the input held. */
|
|
28
|
+
bars: number;
|
|
29
|
+
/** Bars (rows) kept. */
|
|
30
|
+
drawnBars: number;
|
|
31
|
+
}
|
|
32
|
+
/** The rows under `cap` cells: walking from the newest bar back, every bar that still fits whole is
|
|
33
|
+
* kept and the OLDEST bars are dropped (never a partial row). Rows over `cap` are cut to `target`
|
|
34
|
+
* cells (the cap itself unless the caller trims to a watermark below it). */
|
|
35
|
+
export declare function trimWrunHeatmapRowsToBudget(rows: ReadonlyArray<unknown>, layout: WrunHeatmapCellLayout, cap: number, target?: number): WrunHeatmapTrim;
|
|
36
|
+
/** The share of its allowance a retained heatmap is cut back to once it passes it. */
|
|
37
|
+
export declare const WRUN_HEATMAP_TRIM_WATERMARK = 0.95;
|
|
38
|
+
/**
|
|
39
|
+
* The cells a retained heatmap keeps when it passes `allowance`: the watermark, or the newest row
|
|
40
|
+
* whole when that row alone holds more (one that fits the allowance never empties the child). A
|
|
41
|
+
* newest row past the allowance fits nowhere: the target stays the allowance and the child keeps no
|
|
42
|
+
* row, as before.
|
|
43
|
+
*/
|
|
44
|
+
export declare function wrunHeatmapTrimTarget(allowance: number, newestRowCells: number): number;
|
|
45
|
+
/**
|
|
46
|
+
* Each demand's water-filled share of `cap`: every demand under the even share keeps all of it and
|
|
47
|
+
* the rest of the cap is shared out among the larger ones, so the shares never exceed the cap and no
|
|
48
|
+
* demand is starved by another. Shares are whole cells.
|
|
49
|
+
*/
|
|
50
|
+
export declare function wrunHeatmapCellShares(demands: ReadonlyArray<number>, cap: number): number[];
|
|
51
|
+
/** What one mounted heatmap child holds and last asked for. */
|
|
52
|
+
export interface WrunHeatmapChildCells {
|
|
53
|
+
/** Cells the child's rows asked for (the run's rows plus every live append since). */
|
|
54
|
+
demand: number;
|
|
55
|
+
/** Bars the child's rows asked for. */
|
|
56
|
+
demandBars: number;
|
|
57
|
+
/** Cells and bars the engine holds for it now. */
|
|
58
|
+
mounted: number;
|
|
59
|
+
mountedBars: number;
|
|
60
|
+
}
|
|
61
|
+
/** Which children the Indicator holds: the mount's own records when the seam knows them (a child
|
|
62
|
+
* about to be installed is one), else the chart's overlays. */
|
|
63
|
+
export type WrunHeatmapMountedReader = (childId: string) => boolean;
|
|
64
|
+
/**
|
|
65
|
+
* The rows a seam hands a heatmap child in full (the first install, the full run's replace, the
|
|
66
|
+
* retranslation): the child's allowance applied, the oldest bars dropped when the rows ask for more,
|
|
67
|
+
* the Indicator's cells notice and its mounted count scheduled. Returns the rows to hand the engine
|
|
68
|
+
* (`rows` itself when they fit).
|
|
69
|
+
*/
|
|
70
|
+
export declare function budgetWrunHeatmapRows(tc: WrunHeatmapBudgetChart, overlayId: string, childId: string, layout: WrunHeatmapCellLayout, rows: ReadonlyArray<unknown>, isMounted?: WrunHeatmapMountedReader): ReadonlyArray<unknown>;
|
|
71
|
+
/**
|
|
72
|
+
* After a live merge into a mounted heatmap (the forming row replaced, a newer one appended), or a
|
|
73
|
+
* retranslation rebuilding it from the rows it held: the rows the engine retains are counted again,
|
|
74
|
+
* the merge's growth joins the child's demand (a rebuild has none: the demand the child last asked
|
|
75
|
+
* for stays, so its "Cells capped" numbers survive), and when the retained rows now hold more than
|
|
76
|
+
* the child's allowance (its share after the siblings') the oldest bars are dropped down to the
|
|
77
|
+
* watermark (`wrunHeatmapTrimTarget`). Returns the shorter rows for the seam to hand the engine (and
|
|
78
|
+
* keep as the child's record), or null when the retained rows fit.
|
|
79
|
+
*/
|
|
80
|
+
export declare function budgetWrunHeatmapRetained(tc: WrunHeatmapBudgetChart, overlayId: string, childId: string, layout: WrunHeatmapCellLayout, retained: ReadonlyArray<unknown>, isMounted?: WrunHeatmapMountedReader): ReadonlyArray<unknown> | null;
|
|
81
|
+
/**
|
|
82
|
+
* A history-window merge's budget (a partial run's page, or a prefix run's, landed inside its window,
|
|
83
|
+
* wrun-panel-mount.util), planned apart from its ledger write: a prepared landing plans while its run is
|
|
84
|
+
* still settling and writes only when it commits (`commitWrunHeatmapPlan`). The plan holds the merged rows
|
|
85
|
+
* it was cut from, the rows to hand the engine, the ledger entry the commit writes, and the ledger entries it
|
|
86
|
+
* read, by identity: a sibling landing that committed first moves the ledger, and the commit then plans
|
|
87
|
+
* again from the same merged rows (`currentWrunHeatmapPlan`).
|
|
88
|
+
*/
|
|
89
|
+
export interface WrunHeatmapMergePlan {
|
|
90
|
+
readonly overlayId: string;
|
|
91
|
+
readonly childId: string;
|
|
92
|
+
readonly layout: WrunHeatmapCellLayout;
|
|
93
|
+
/** The merged rows the plan cut. */
|
|
94
|
+
readonly merged: ReadonlyArray<unknown>;
|
|
95
|
+
/** The rows to hand the engine: the newest bars whole (`merged` itself when they fit). */
|
|
96
|
+
readonly rows: ReadonlyArray<unknown>;
|
|
97
|
+
/** The ledger entry the commit writes for the child. */
|
|
98
|
+
readonly cells: Readonly<WrunHeatmapChildCells>;
|
|
99
|
+
/** The ledger entries the plan read: the child's own and every held sibling's. */
|
|
100
|
+
readonly basis: ReadonlyMap<string, WrunHeatmapChildCells>;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* The budget of a history-window merge, planned without writing the ledger or owing the cells notice. The
|
|
104
|
+
* merged rows start from the rows the child holds, which its allowance already cut, so the demand carries
|
|
105
|
+
* forward what the earlier rows asked for and the allowance dropped, with the merge's growth joining it as a
|
|
106
|
+
* live append's does; the rows are cut to the hard allowance, like a run's (`rows` is `merged` itself when
|
|
107
|
+
* they fit).
|
|
108
|
+
*/
|
|
109
|
+
export declare function planWrunHeatmapMerged(tc: WrunHeatmapBudgetChart, overlayId: string, childId: string, layout: WrunHeatmapCellLayout, rows: ReadonlyArray<unknown>, isMounted?: WrunHeatmapMountedReader): WrunHeatmapMergePlan;
|
|
110
|
+
/** The plan as the ledger stands now: `plan` itself while it is current, else the same merged rows planned
|
|
111
|
+
* again (a count and a cut, no copy of a row). */
|
|
112
|
+
export declare function currentWrunHeatmapPlan(tc: WrunHeatmapBudgetChart, plan: WrunHeatmapMergePlan, isMounted?: WrunHeatmapMountedReader): WrunHeatmapMergePlan;
|
|
113
|
+
/** An Indicator's ledger as it stood, its entries by identity (a write replaces an entry, never edits it): what
|
|
114
|
+
* a landing transaction puts back when it rolls back (wrun-panel-mount.util). Null when it held none. */
|
|
115
|
+
export type WrunHeatmapLedgerSnapshot = ReadonlyMap<string, WrunHeatmapChildCells> | null;
|
|
116
|
+
export declare function snapshotWrunHeatmapLedger(tc: WrunHeatmapBudgetChart, overlayId: string): WrunHeatmapLedgerSnapshot;
|
|
117
|
+
/** Put an Indicator's ledger back as `snapshot` held it, and owe its cells notice again. */
|
|
118
|
+
export declare function restoreWrunHeatmapLedger(tc: WrunHeatmapBudgetChart, overlayId: string, snapshot: WrunHeatmapLedgerSnapshot): void;
|
|
119
|
+
/** The ledger write of a plan whose rows the engine was just handed, and the Indicator's cells notice owed. */
|
|
120
|
+
export declare function commitWrunHeatmapPlan(tc: WrunHeatmapBudgetChart, plan: WrunHeatmapMergePlan, isMounted?: WrunHeatmapMountedReader): void;
|
|
121
|
+
/** The Indicator's other heatmap children that now hold more than their share of the cap (a sibling
|
|
122
|
+
* just mounted, or asked for more): the seam trims each through `budgetWrunHeatmapRetained`, so the
|
|
123
|
+
* Indicator's mounted total never stays over the cap. */
|
|
124
|
+
export declare function wrunHeatmapChildrenOverShare(tc: WrunHeatmapBudgetChart, overlayId: string, except: string, isMounted?: WrunHeatmapMountedReader): string[];
|
|
125
|
+
/**
|
|
126
|
+
* After a live append grew one child: its larger demand shrinks its siblings' shares, so while the
|
|
127
|
+
* Indicator's mounted cells pass the cap, the siblings now over their share (whichever order the
|
|
128
|
+
* tick merged them in), for the seam to trim through `budgetWrunHeatmapRetained`. Under the cap the
|
|
129
|
+
* shares are not recomputed (one sum per tick) and nothing is named.
|
|
130
|
+
*/
|
|
131
|
+
export declare function wrunHeatmapSiblingsToRebalance(tc: WrunHeatmapBudgetChart, overlayId: string, grown: string, isMounted?: WrunHeatmapMountedReader): string[];
|
|
132
|
+
/** The Indicator's heatmap cells as one notice: the mounted total, and the capped summary when any
|
|
133
|
+
* child holds fewer cells than it asked for. */
|
|
134
|
+
export declare function wrunHeatmapCellSummary(tc: WrunHeatmapBudgetChart, overlayId: string): WrunCellsCapSummary;
|
|
135
|
+
/** One heatmap child a host is about to mount: its id, its cell layout and the rows its run asked for. */
|
|
136
|
+
export interface WrunHeatmapBudgetChild {
|
|
137
|
+
id: string;
|
|
138
|
+
layout: WrunHeatmapCellLayout;
|
|
139
|
+
rows: ReadonlyArray<unknown>;
|
|
140
|
+
}
|
|
141
|
+
/** The whole mount's budget: each child's rows to hand the engine, and the Indicator's cells notice. */
|
|
142
|
+
export interface WrunHeatmapChildrenBudget {
|
|
143
|
+
/** Each child with the rows to mount, in the input's order (a child's own rows array when they fit). */
|
|
144
|
+
children: WrunHeatmapBudgetChild[];
|
|
145
|
+
/** The Indicator's "Cells capped" notice over these children (`capped` null when every child fits): the summary a
|
|
146
|
+
* host's notice publishes (wrun-cap-notice.util). */
|
|
147
|
+
notices: WrunCellsCapSummary;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* The cell budget of a whole mount's heatmap children, pure: what web's mount does for children installed one after
|
|
151
|
+
* another on a chart that held none of the Indicator's heatmaps (each child's full hand-off under its hard
|
|
152
|
+
* allowance beside the children before it, then every earlier child the new demand pushed over its share cut back
|
|
153
|
+
* to the watermark), through the same steps the ledger seams run. A host with no per-chart ledger (the mobile
|
|
154
|
+
* chart) applies it before its heatmap painter on every full mount and replace; ids are unique.
|
|
155
|
+
*/
|
|
156
|
+
export declare function budgetWrunHeatmapChildren(children: ReadonlyArray<WrunHeatmapBudgetChild>, budget?: number): WrunHeatmapChildrenBudget;
|
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The cell budget of a wrun Indicator's heatmap children (WRUN-COST-GUARD U4, "caps trim and say").
|
|
3
|
+
*
|
|
4
|
+
* A heatmap child hands the engine one row per bar, and every row is as wide as its source made it:
|
|
5
|
+
* a book row carries one (price, size) pair per resting level, a grid row one value per declared
|
|
6
|
+
* grid row, a volume-profile row one bucket per price band. The engine draws every cell it holds,
|
|
7
|
+
* so the budget counts what is MOUNTED (the retained history plus every live append), one cell per
|
|
8
|
+
* pair, value or bucket, row by row. Past `OVERLAY_HISTORICAL_HEATMAP_CELL_BUDGET` the OLDEST bars
|
|
9
|
+
* are dropped before the rows reach the engine (titan's `updateData` takes the shorter array as its
|
|
10
|
+
* retained rows), the newest bars always whole, and the Indicator's legend says so through ONE
|
|
11
|
+
* "Cells capped" row for all its heatmaps (wrun-cap-notice.util).
|
|
12
|
+
*
|
|
13
|
+
* Retained rows trim with hysteresis: a live merge (or a sibling's rebalance, or a rebuild) that
|
|
14
|
+
* takes a child past its allowance drops the oldest bars down to 95% of it
|
|
15
|
+
* (`WRUN_HEATMAP_TRIM_WATERMARK`), so the bars that follow land in place until the allowance is
|
|
16
|
+
* used up again, instead of one whole-array swap per new bar at the cap. The newest row is never
|
|
17
|
+
* trimmed away while it fits the allowance (`wrunHeatmapTrimTarget`). A full hand-off (an install,
|
|
18
|
+
* a run's replace) keeps the hard allowance: the run's rows fill it.
|
|
19
|
+
*
|
|
20
|
+
* The cap is the Indicator's, shared by its heatmaps: each child's allowance is its water-filled
|
|
21
|
+
* share of the cap over the demands every mounted heatmap child of the Indicator last asked for (a
|
|
22
|
+
* small heatmap keeps all its rows, the rest of the cap goes to the larger ones), so no child starves
|
|
23
|
+
* and the cap is never exceeded in total. Each seam that changes a child's mounted rows asks here
|
|
24
|
+
* (wrun-panel-mount.util): the first install, the full-run replace, the live append (which also
|
|
25
|
+
* trims the siblings its growth pushed over their share), a history-window merge (planned without a
|
|
26
|
+
* write, written when it lands, so a prefix run can prepare it ahead of its commit) and the
|
|
27
|
+
* retranslation (both keep the demand the child last asked for: they start from the rows the allowance
|
|
28
|
+
* left). Matrices and profiles are not counted (matrices are price rows rebuilt from the frame;
|
|
29
|
+
* profiles have the engine's own visible-cell cap).
|
|
30
|
+
*
|
|
31
|
+
* Import graph: the guard's constants, the cap notice (its store side loads lazily). No store, no
|
|
32
|
+
* chart instance at import.
|
|
33
|
+
*/
|
|
34
|
+
import { OVERLAY_HISTORICAL_HEATMAP_CELL_BUDGET } from '../chart/overlay-output-budget.util.js';
|
|
35
|
+
import { scheduleWrunCellsCapNotice } from './wrun-cap-notice.util.js';
|
|
36
|
+
function isRowLike(row) {
|
|
37
|
+
return Array.isArray(row) || (ArrayBuffer.isView(row) && !(row instanceof DataView));
|
|
38
|
+
}
|
|
39
|
+
/** The layout a heatmap config names, `book` for anything it does not. */
|
|
40
|
+
export function wrunHeatmapCellLayoutOf(settings) {
|
|
41
|
+
const layout = settings?.cellLayout;
|
|
42
|
+
return layout === 'grid' || layout === 'profile' ? layout : 'book';
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The cells one heatmap row holds, as the engine reads it: a book row `[ts, price, size, ...]` its
|
|
46
|
+
* pairs, a grid row `[ts, low, step, v0 .. vN]` its values, a volume-profile row its buckets (nested
|
|
47
|
+
* `[ts, [low, high, buy, sell], ...]` or flat quads). Rows are variable width, so each is measured.
|
|
48
|
+
*/
|
|
49
|
+
export function wrunHeatmapRowCells(row, layout) {
|
|
50
|
+
if (!isRowLike(row) || row.length <= 1)
|
|
51
|
+
return 0;
|
|
52
|
+
switch (layout) {
|
|
53
|
+
case 'grid':
|
|
54
|
+
return Math.max(0, row.length - 3);
|
|
55
|
+
case 'profile':
|
|
56
|
+
return Array.isArray(row[1]) ? row.length - 1 : (row.length - 1) >> 2;
|
|
57
|
+
default:
|
|
58
|
+
return (row.length - 1) >> 1;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/** The cells a heatmap's rows hold (one row per bar). */
|
|
62
|
+
export function countWrunHeatmapCells(rows, layout) {
|
|
63
|
+
let cells = 0;
|
|
64
|
+
for (const row of rows)
|
|
65
|
+
cells += wrunHeatmapRowCells(row, layout);
|
|
66
|
+
return cells;
|
|
67
|
+
}
|
|
68
|
+
/** The rows under `cap` cells: walking from the newest bar back, every bar that still fits whole is
|
|
69
|
+
* kept and the OLDEST bars are dropped (never a partial row). Rows over `cap` are cut to `target`
|
|
70
|
+
* cells (the cap itself unless the caller trims to a watermark below it). */
|
|
71
|
+
export function trimWrunHeatmapRowsToBudget(rows, layout, cap, target = cap) {
|
|
72
|
+
const total = countWrunHeatmapCells(rows, layout);
|
|
73
|
+
if (total <= cap)
|
|
74
|
+
return { rows, total, drawn: total, bars: rows.length, drawnBars: rows.length };
|
|
75
|
+
let drawn = 0;
|
|
76
|
+
let from = rows.length;
|
|
77
|
+
while (from > 0) {
|
|
78
|
+
const cells = wrunHeatmapRowCells(rows[from - 1], layout);
|
|
79
|
+
if (drawn + cells > target)
|
|
80
|
+
break;
|
|
81
|
+
drawn += cells;
|
|
82
|
+
from -= 1;
|
|
83
|
+
}
|
|
84
|
+
return { rows: rows.slice(from), total, drawn, bars: rows.length, drawnBars: rows.length - from };
|
|
85
|
+
}
|
|
86
|
+
/** The share of its allowance a retained heatmap is cut back to once it passes it. */
|
|
87
|
+
export const WRUN_HEATMAP_TRIM_WATERMARK = 0.95;
|
|
88
|
+
/**
|
|
89
|
+
* The cells a retained heatmap keeps when it passes `allowance`: the watermark, or the newest row
|
|
90
|
+
* whole when that row alone holds more (one that fits the allowance never empties the child). A
|
|
91
|
+
* newest row past the allowance fits nowhere: the target stays the allowance and the child keeps no
|
|
92
|
+
* row, as before.
|
|
93
|
+
*/
|
|
94
|
+
export function wrunHeatmapTrimTarget(allowance, newestRowCells) {
|
|
95
|
+
if (newestRowCells > allowance)
|
|
96
|
+
return allowance;
|
|
97
|
+
return Math.max(Math.floor(allowance * WRUN_HEATMAP_TRIM_WATERMARK), newestRowCells);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Each demand's water-filled share of `cap`: every demand under the even share keeps all of it and
|
|
101
|
+
* the rest of the cap is shared out among the larger ones, so the shares never exceed the cap and no
|
|
102
|
+
* demand is starved by another. Shares are whole cells.
|
|
103
|
+
*/
|
|
104
|
+
export function wrunHeatmapCellShares(demands, cap) {
|
|
105
|
+
const shares = demands.map(() => 0);
|
|
106
|
+
const order = demands.map((_, at) => at).sort((a, b) => demands[a] - demands[b]);
|
|
107
|
+
let remaining = Math.max(0, Math.floor(cap));
|
|
108
|
+
order.forEach((at, step) => {
|
|
109
|
+
const even = Math.floor(remaining / (order.length - step));
|
|
110
|
+
shares[at] = Math.max(0, Math.min(demands[at], even));
|
|
111
|
+
remaining -= shares[at];
|
|
112
|
+
});
|
|
113
|
+
return shares;
|
|
114
|
+
}
|
|
115
|
+
/** Per chart, per Indicator, per heatmap child id. */
|
|
116
|
+
const ledgers = new WeakMap();
|
|
117
|
+
/** The Indicator's children ledger, without the children it no longer holds (a child the run
|
|
118
|
+
* dropped or retired: the seam that mounts `keep` counts it). */
|
|
119
|
+
function ledgerOf(tc, overlayId, keep, isMounted = (id) => tc.metadata.some((meta) => meta.id === id)) {
|
|
120
|
+
let overlays = ledgers.get(tc);
|
|
121
|
+
if (!overlays) {
|
|
122
|
+
overlays = new Map();
|
|
123
|
+
ledgers.set(tc, overlays);
|
|
124
|
+
}
|
|
125
|
+
let ledger = overlays.get(overlayId);
|
|
126
|
+
if (!ledger) {
|
|
127
|
+
ledger = new Map();
|
|
128
|
+
overlays.set(overlayId, ledger);
|
|
129
|
+
}
|
|
130
|
+
for (const id of [...ledger.keys()]) {
|
|
131
|
+
if (id !== keep && !isMounted(id))
|
|
132
|
+
ledger.delete(id);
|
|
133
|
+
}
|
|
134
|
+
return ledger;
|
|
135
|
+
}
|
|
136
|
+
/** The Indicator's children ledger as a plan reads it, writing nothing: the entry of `keep` and those of the
|
|
137
|
+
* children the Indicator still holds (the ones `ledgerOf` drops are left out here, never deleted). */
|
|
138
|
+
function heldLedgerOf(tc, overlayId, keep, isMounted = (id) => tc.metadata.some((meta) => meta.id === id)) {
|
|
139
|
+
const held = new Map();
|
|
140
|
+
for (const [id, cells] of ledgers.get(tc)?.get(overlayId) ?? []) {
|
|
141
|
+
if (id === keep || isMounted(id))
|
|
142
|
+
held.set(id, cells);
|
|
143
|
+
}
|
|
144
|
+
return held;
|
|
145
|
+
}
|
|
146
|
+
/** The child's share of the cap for `demand`, beside the other children's last demands. */
|
|
147
|
+
function allowanceOf(ledger, childId, demand, cap = OVERLAY_HISTORICAL_HEATMAP_CELL_BUDGET) {
|
|
148
|
+
const others = [...ledger].filter(([id]) => id !== childId).map(([, cells]) => cells.demand);
|
|
149
|
+
const shares = wrunHeatmapCellShares([demand, ...others], cap);
|
|
150
|
+
return shares[0];
|
|
151
|
+
}
|
|
152
|
+
/** The full hand-off's step over a ledger: the child's hard allowance applied to its rows, its entry written.
|
|
153
|
+
* Returns the rows to hand the engine (`rows` itself when they fit). */
|
|
154
|
+
function budgetRowsStep(ledger, childId, layout, rows, cap = OVERLAY_HISTORICAL_HEATMAP_CELL_BUDGET) {
|
|
155
|
+
const demand = countWrunHeatmapCells(rows, layout);
|
|
156
|
+
const trim = trimWrunHeatmapRowsToBudget(rows, layout, allowanceOf(ledger, childId, demand, cap));
|
|
157
|
+
ledger.set(childId, { demand, demandBars: rows.length, mounted: trim.drawn, mountedBars: trim.drawnBars });
|
|
158
|
+
return trim.rows;
|
|
159
|
+
}
|
|
160
|
+
/** The retained rows' step over a ledger: the growth joins the child's demand, and past its allowance the oldest
|
|
161
|
+
* bars drop to the watermark; its entry written. Returns the rows (`retained` itself when they fit). */
|
|
162
|
+
function budgetRetainedStep(ledger, childId, layout, retained, cap = OVERLAY_HISTORICAL_HEATMAP_CELL_BUDGET) {
|
|
163
|
+
const { demand, demandBars } = carriedDemand(ledger.get(childId), countWrunHeatmapCells(retained, layout), retained);
|
|
164
|
+
const allowance = allowanceOf(ledger, childId, demand, cap);
|
|
165
|
+
const newest = retained.length > 0 ? wrunHeatmapRowCells(retained[retained.length - 1], layout) : 0;
|
|
166
|
+
const trim = trimWrunHeatmapRowsToBudget(retained, layout, allowance, wrunHeatmapTrimTarget(allowance, newest));
|
|
167
|
+
ledger.set(childId, { demand, demandBars, mounted: trim.drawn, mountedBars: trim.drawnBars });
|
|
168
|
+
return trim.rows;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* The rows a seam hands a heatmap child in full (the first install, the full run's replace, the
|
|
172
|
+
* retranslation): the child's allowance applied, the oldest bars dropped when the rows ask for more,
|
|
173
|
+
* the Indicator's cells notice and its mounted count scheduled. Returns the rows to hand the engine
|
|
174
|
+
* (`rows` itself when they fit).
|
|
175
|
+
*/
|
|
176
|
+
export function budgetWrunHeatmapRows(tc, overlayId, childId, layout, rows, isMounted) {
|
|
177
|
+
const kept = budgetRowsStep(ledgerOf(tc, overlayId, childId, isMounted), childId, layout, rows);
|
|
178
|
+
noteWrunHeatmapCells(tc, overlayId);
|
|
179
|
+
return kept;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* After a live merge into a mounted heatmap (the forming row replaced, a newer one appended), or a
|
|
183
|
+
* retranslation rebuilding it from the rows it held: the rows the engine retains are counted again,
|
|
184
|
+
* the merge's growth joins the child's demand (a rebuild has none: the demand the child last asked
|
|
185
|
+
* for stays, so its "Cells capped" numbers survive), and when the retained rows now hold more than
|
|
186
|
+
* the child's allowance (its share after the siblings') the oldest bars are dropped down to the
|
|
187
|
+
* watermark (`wrunHeatmapTrimTarget`). Returns the shorter rows for the seam to hand the engine (and
|
|
188
|
+
* keep as the child's record), or null when the retained rows fit.
|
|
189
|
+
*/
|
|
190
|
+
export function budgetWrunHeatmapRetained(tc, overlayId, childId, layout, retained, isMounted) {
|
|
191
|
+
const kept = budgetRetainedStep(ledgerOf(tc, overlayId, childId, isMounted), childId, layout, retained);
|
|
192
|
+
noteWrunHeatmapCells(tc, overlayId);
|
|
193
|
+
return kept === retained ? null : kept;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* The budget of a history-window merge, planned without writing the ledger or owing the cells notice. The
|
|
197
|
+
* merged rows start from the rows the child holds, which its allowance already cut, so the demand carries
|
|
198
|
+
* forward what the earlier rows asked for and the allowance dropped, with the merge's growth joining it as a
|
|
199
|
+
* live append's does; the rows are cut to the hard allowance, like a run's (`rows` is `merged` itself when
|
|
200
|
+
* they fit).
|
|
201
|
+
*/
|
|
202
|
+
export function planWrunHeatmapMerged(tc, overlayId, childId, layout, rows, isMounted) {
|
|
203
|
+
const basis = heldLedgerOf(tc, overlayId, childId, isMounted);
|
|
204
|
+
const { demand, demandBars } = carriedDemand(basis.get(childId), countWrunHeatmapCells(rows, layout), rows);
|
|
205
|
+
const trim = trimWrunHeatmapRowsToBudget(rows, layout, allowanceOf(basis, childId, demand));
|
|
206
|
+
return {
|
|
207
|
+
overlayId,
|
|
208
|
+
childId,
|
|
209
|
+
layout,
|
|
210
|
+
merged: rows,
|
|
211
|
+
rows: trim.rows,
|
|
212
|
+
cells: { demand, demandBars, mounted: trim.drawn, mountedBars: trim.drawnBars },
|
|
213
|
+
basis,
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
/** True while the Indicator's ledger holds exactly the entries `plan` read: no seam wrote one since and no
|
|
217
|
+
* child it counted was retired. */
|
|
218
|
+
function isWrunHeatmapPlanCurrent(tc, plan, isMounted) {
|
|
219
|
+
const now = heldLedgerOf(tc, plan.overlayId, plan.childId, isMounted);
|
|
220
|
+
if (now.size !== plan.basis.size)
|
|
221
|
+
return false;
|
|
222
|
+
for (const [id, cells] of plan.basis) {
|
|
223
|
+
if (now.get(id) !== cells)
|
|
224
|
+
return false;
|
|
225
|
+
}
|
|
226
|
+
return true;
|
|
227
|
+
}
|
|
228
|
+
/** The plan as the ledger stands now: `plan` itself while it is current, else the same merged rows planned
|
|
229
|
+
* again (a count and a cut, no copy of a row). */
|
|
230
|
+
export function currentWrunHeatmapPlan(tc, plan, isMounted) {
|
|
231
|
+
return isWrunHeatmapPlanCurrent(tc, plan, isMounted)
|
|
232
|
+
? plan
|
|
233
|
+
: planWrunHeatmapMerged(tc, plan.overlayId, plan.childId, plan.layout, plan.merged, isMounted);
|
|
234
|
+
}
|
|
235
|
+
export function snapshotWrunHeatmapLedger(tc, overlayId) {
|
|
236
|
+
const ledger = ledgers.get(tc)?.get(overlayId);
|
|
237
|
+
return ledger === undefined ? null : new Map(ledger);
|
|
238
|
+
}
|
|
239
|
+
/** Put an Indicator's ledger back as `snapshot` held it, and owe its cells notice again. */
|
|
240
|
+
export function restoreWrunHeatmapLedger(tc, overlayId, snapshot) {
|
|
241
|
+
let overlays = ledgers.get(tc);
|
|
242
|
+
if (snapshot === null)
|
|
243
|
+
overlays?.delete(overlayId);
|
|
244
|
+
else {
|
|
245
|
+
if (!overlays) {
|
|
246
|
+
overlays = new Map();
|
|
247
|
+
ledgers.set(tc, overlays);
|
|
248
|
+
}
|
|
249
|
+
overlays.set(overlayId, new Map(snapshot));
|
|
250
|
+
}
|
|
251
|
+
noteWrunHeatmapCells(tc, overlayId);
|
|
252
|
+
}
|
|
253
|
+
/** The ledger write of a plan whose rows the engine was just handed, and the Indicator's cells notice owed. */
|
|
254
|
+
export function commitWrunHeatmapPlan(tc, plan, isMounted) {
|
|
255
|
+
ledgerOf(tc, plan.overlayId, plan.childId, isMounted).set(plan.childId, { ...plan.cells });
|
|
256
|
+
noteWrunHeatmapCells(tc, plan.overlayId);
|
|
257
|
+
}
|
|
258
|
+
/** The demand a child's rows ask for when they grew from what it held: the cells and bars it last
|
|
259
|
+
* asked for, plus the growth over what it then held (never under the rows themselves). */
|
|
260
|
+
function carriedDemand(before, cells, rows) {
|
|
261
|
+
return {
|
|
262
|
+
demand: Math.max(cells, (before?.demand ?? cells) + cells - (before?.mounted ?? cells)),
|
|
263
|
+
demandBars: Math.max(rows.length, (before?.demandBars ?? rows.length) + rows.length - (before?.mountedBars ?? rows.length)),
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
/** The ledger's children other than `except` holding more than their water-filled share of the cap. */
|
|
267
|
+
function childrenOverShare(ledger, except, cap = OVERLAY_HISTORICAL_HEATMAP_CELL_BUDGET) {
|
|
268
|
+
const children = [...ledger];
|
|
269
|
+
const shares = wrunHeatmapCellShares(children.map(([, cells]) => cells.demand), cap);
|
|
270
|
+
return children.flatMap(([id, cells], at) => (id !== except && cells.mounted > shares[at] ? [id] : []));
|
|
271
|
+
}
|
|
272
|
+
/** The Indicator's other heatmap children that now hold more than their share of the cap (a sibling
|
|
273
|
+
* just mounted, or asked for more): the seam trims each through `budgetWrunHeatmapRetained`, so the
|
|
274
|
+
* Indicator's mounted total never stays over the cap. */
|
|
275
|
+
export function wrunHeatmapChildrenOverShare(tc, overlayId, except, isMounted) {
|
|
276
|
+
return childrenOverShare(ledgerOf(tc, overlayId, except, isMounted), except);
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* After a live append grew one child: its larger demand shrinks its siblings' shares, so while the
|
|
280
|
+
* Indicator's mounted cells pass the cap, the siblings now over their share (whichever order the
|
|
281
|
+
* tick merged them in), for the seam to trim through `budgetWrunHeatmapRetained`. Under the cap the
|
|
282
|
+
* shares are not recomputed (one sum per tick) and nothing is named.
|
|
283
|
+
*/
|
|
284
|
+
export function wrunHeatmapSiblingsToRebalance(tc, overlayId, grown, isMounted) {
|
|
285
|
+
const ledger = ledgerOf(tc, overlayId, grown, isMounted);
|
|
286
|
+
let mounted = 0;
|
|
287
|
+
for (const cells of ledger.values())
|
|
288
|
+
mounted += cells.mounted;
|
|
289
|
+
return mounted > OVERLAY_HISTORICAL_HEATMAP_CELL_BUDGET ? childrenOverShare(ledger, grown) : [];
|
|
290
|
+
}
|
|
291
|
+
/** The Indicator's heatmap cells as one notice: the mounted total, and the capped summary when any
|
|
292
|
+
* child holds fewer cells than it asked for. */
|
|
293
|
+
export function wrunHeatmapCellSummary(tc, overlayId) {
|
|
294
|
+
const children = [...(ledgers.get(tc)?.get(overlayId)?.entries() ?? [])]
|
|
295
|
+
.filter(([id]) => tc.metadata.some((meta) => meta.id === id))
|
|
296
|
+
.map(([, cells]) => cells);
|
|
297
|
+
return cellsSummaryOf(children);
|
|
298
|
+
}
|
|
299
|
+
/** The cells notice over a set of children's ledger entries: the mounted total, and the capped summary when any
|
|
300
|
+
* child holds fewer cells than it asked for. */
|
|
301
|
+
function cellsSummaryOf(children, cap = OVERLAY_HISTORICAL_HEATMAP_CELL_BUDGET) {
|
|
302
|
+
const mounted = children.reduce((sum, cells) => sum + cells.mounted, 0);
|
|
303
|
+
const trimmed = children.filter((cells) => cells.mounted < cells.demand);
|
|
304
|
+
if (trimmed.length === 0)
|
|
305
|
+
return { mounted, capped: null };
|
|
306
|
+
return {
|
|
307
|
+
mounted,
|
|
308
|
+
capped: {
|
|
309
|
+
total: children.reduce((sum, cells) => sum + cells.demand, 0),
|
|
310
|
+
drawn: mounted,
|
|
311
|
+
cap,
|
|
312
|
+
bars: Math.max(...children.map((cells) => cells.demandBars)),
|
|
313
|
+
drawnBars: Math.min(...trimmed.map((cells) => cells.mountedBars)),
|
|
314
|
+
},
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
function noteWrunHeatmapCells(tc, overlayId) {
|
|
318
|
+
scheduleWrunCellsCapNotice(tc, overlayId, () => wrunHeatmapCellSummary(tc, overlayId));
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* The cell budget of a whole mount's heatmap children, pure: what web's mount does for children installed one after
|
|
322
|
+
* another on a chart that held none of the Indicator's heatmaps (each child's full hand-off under its hard
|
|
323
|
+
* allowance beside the children before it, then every earlier child the new demand pushed over its share cut back
|
|
324
|
+
* to the watermark), through the same steps the ledger seams run. A host with no per-chart ledger (the mobile
|
|
325
|
+
* chart) applies it before its heatmap painter on every full mount and replace; ids are unique.
|
|
326
|
+
*/
|
|
327
|
+
export function budgetWrunHeatmapChildren(children, budget = OVERLAY_HISTORICAL_HEATMAP_CELL_BUDGET) {
|
|
328
|
+
const ledger = new Map();
|
|
329
|
+
const rowsById = new Map();
|
|
330
|
+
const layoutById = new Map(children.map((child) => [child.id, child.layout]));
|
|
331
|
+
for (const child of children) {
|
|
332
|
+
rowsById.set(child.id, budgetRowsStep(ledger, child.id, child.layout, child.rows, budget));
|
|
333
|
+
for (const sibling of childrenOverShare(ledger, child.id, budget)) {
|
|
334
|
+
const retained = rowsById.get(sibling) ?? [];
|
|
335
|
+
rowsById.set(sibling, budgetRetainedStep(ledger, sibling, layoutById.get(sibling) ?? 'book', retained, budget));
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
return {
|
|
339
|
+
children: children.map((child) => ({ id: child.id, layout: child.layout, rows: rowsById.get(child.id) ?? [] })),
|
|
340
|
+
notices: cellsSummaryOf([...ledger.values()], budget),
|
|
341
|
+
};
|
|
342
|
+
}
|