@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,1239 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The over-time plot looks of WRUN-STYLE group 5 (OT01..OT38) and the pane
|
|
3
|
+
* words (OT08 OT18 OT19 OT20 OT24, plus the DW25 widget routing): pure
|
|
4
|
+
* helpers the run-result adapter (wrun-run-result.util) merges into the
|
|
5
|
+
* outputs it mounts, the child-pane plan it splits a result by, the define
|
|
6
|
+
* a declared pane gives its child, and the mount settings the panel mount
|
|
7
|
+
* (wrun-panel-mount.util) gives a series child.
|
|
8
|
+
*
|
|
9
|
+
* Every word is opt-in: a helper answers an empty patch for an output that
|
|
10
|
+
* declares none of its words, so a sheet without them mounts byte-identical.
|
|
11
|
+
* Refusals read `WRUN <sheet>: output '<name>' <key> must ...`, the plain
|
|
12
|
+
* messages of the kit's area module (packages/sdk/src/wrun-style/outputs.ts
|
|
13
|
+
* and panes.ts), so a hand-written sheet fails here the way the kit would.
|
|
14
|
+
*
|
|
15
|
+
* Colours are never resolved here: a theme token (`theme.up`) rides the
|
|
16
|
+
* patch as written and `multiplyWrunOpacity` scales its alpha in the token's
|
|
17
|
+
* own `/aa` form; the mount doors resolve it against the chart's palette
|
|
18
|
+
* (wrun-style-words.util). Font words become CSS stacks here (X14: the
|
|
19
|
+
* engine never sees a font word).
|
|
20
|
+
*
|
|
21
|
+
* Imports no vue, no DOM, no titan and no kit: main-thread and worker safe.
|
|
22
|
+
*/
|
|
23
|
+
import { decodeWrunPackedColor } from './wrun-color-settings.util.js';
|
|
24
|
+
import { WRUN3_MAX_GLOW_PX } from './wrun-handles.util.js';
|
|
25
|
+
import { wrunOutputPlotRule } from './wrun-visibility-table.js';
|
|
26
|
+
import { parseWrunThemeToken, WRUN_FONT_FAMILIES, WRUN_VALUE_FORMATS, wrunFontFamilyCss, wrunThemeTokenOfPacked, wrunThemeTokenScaleAlpha, wrunThemeTokenWord, } from './wrun-style-words.util.js';
|
|
27
|
+
// Words and bounds (the kit's g5 lists, restated: the app never imports the
|
|
28
|
+
// kit bundle outside the compile lane, X22).
|
|
29
|
+
/** The sheet's mark placements (OT07, D5) and the engine words they map to;
|
|
30
|
+
* the engine's own camelCase words stay accepted for hand-written sheets. */
|
|
31
|
+
const WRUN_LOCATION_WORDS = {
|
|
32
|
+
absolute: 'absolute',
|
|
33
|
+
above_bar: 'aboveBar',
|
|
34
|
+
below_bar: 'belowBar',
|
|
35
|
+
top: 'top',
|
|
36
|
+
bottom: 'bottom',
|
|
37
|
+
aboveBar: 'aboveBar',
|
|
38
|
+
belowBar: 'belowBar',
|
|
39
|
+
};
|
|
40
|
+
const WRUN_LOCATION_LIST = "'absolute', 'above_bar', 'below_bar', 'top', 'bottom'";
|
|
41
|
+
/** How a line splits its colour (OT14). */
|
|
42
|
+
export const WRUN_LINE_SPLIT_MODES = ['level', 'slope'];
|
|
43
|
+
/** A candle group's body style (OT17) and the engine plot kind it mounts as. */
|
|
44
|
+
export const WRUN_CANDLE_STYLES = ['candle', 'hollow', 'ohlc', 'high_low'];
|
|
45
|
+
const WRUN_CANDLE_PLOT_TYPES = {
|
|
46
|
+
candle: 'candle',
|
|
47
|
+
hollow: 'hollowCandle',
|
|
48
|
+
ohlc: 'ohlcBar',
|
|
49
|
+
high_low: 'highLow',
|
|
50
|
+
};
|
|
51
|
+
/** Column alpha by magnitude (OT34). */
|
|
52
|
+
export const WRUN_BAR_GRADINGS = ['linear', 'square'];
|
|
53
|
+
/** The on-line label pill of a guide (OT10). */
|
|
54
|
+
export const WRUN_PILL_STYLES = ['filled', 'outlined'];
|
|
55
|
+
const WRUN_GUIDE_ALIGNS = ['left', 'center', 'right'];
|
|
56
|
+
const WRUN_GRADIENT_MODES = ['pane', 'fill', 'line'];
|
|
57
|
+
const WRUN_LINE_STYLE_WORDS = ['solid', 'dashed', 'dotted'];
|
|
58
|
+
/** The pane's value scale (OT18) and the engine value mode it maps to. */
|
|
59
|
+
export const WRUN_PANE_SCALES = ['linear', 'log', 'percent', 'indexed'];
|
|
60
|
+
const WRUN_PANE_VALUE_MODES = {
|
|
61
|
+
linear: 'regular',
|
|
62
|
+
log: 'logarithmic',
|
|
63
|
+
percent: 'percent',
|
|
64
|
+
indexed: 'indexed',
|
|
65
|
+
};
|
|
66
|
+
/** Where a pane sits (OT24). */
|
|
67
|
+
export const WRUN_PANE_PLACES = ['below', 'price'];
|
|
68
|
+
/** The name of the default pane below the chart (OT08): `pane("lower", ...)`
|
|
69
|
+
* styles it, `outputs[].pane: "lower"` names it. */
|
|
70
|
+
export const WRUN_DEFAULT_PANE_NAME = 'lower';
|
|
71
|
+
/** The widget kinds a `panel: "lower"` routes into the lower pane (DW25). */
|
|
72
|
+
const WRUN_LOWER_PANE_WIDGET_KINDS = new Set(['card', 'feed', 'meter', 'ladder']);
|
|
73
|
+
export const WRUN_MIN_Z = -10;
|
|
74
|
+
export const WRUN_MAX_Z = 10;
|
|
75
|
+
const WRUN_MIN_GRADIENT_STOPS = 2;
|
|
76
|
+
const WRUN_MAX_GRADIENT_STOPS = 8;
|
|
77
|
+
const WRUN_MIN_FONT_SIZE_PX = 6;
|
|
78
|
+
const WRUN_MAX_FONT_SIZE_PX = 64;
|
|
79
|
+
const WRUN_MAX_BORDER_WIDTH = 10;
|
|
80
|
+
const WRUN_MIN_BGCOLOR_LINE_WIDTH_PX = 0.5;
|
|
81
|
+
const WRUN_MAX_BGCOLOR_LINE_WIDTH_PX = 10;
|
|
82
|
+
const WRUN_MIN_PANE_HEIGHT = 0.05;
|
|
83
|
+
const WRUN_MAX_PANE_HEIGHT = 0.6;
|
|
84
|
+
const WRUN_MAX_PANE_PADDING = 0.4;
|
|
85
|
+
const WRUN_MAX_VALUE_DECIMALS = 8;
|
|
86
|
+
const WRUN_MAX_VALUE_UNIT_CHARS = 8;
|
|
87
|
+
/** Titan's own flat delta-fill alpha, the interior an area paints under its
|
|
88
|
+
* line when the sheet declares no `fill_opacity` (OT02, OT31). */
|
|
89
|
+
export const WRUN_AREA_FILL_ALPHA = 0.4;
|
|
90
|
+
/** The engine layer every line, bar, band and mark paints in when `z` is
|
|
91
|
+
* absent (OT04); a split area fill sits half a layer under it (OT31). */
|
|
92
|
+
const WRUN_PLOT_LAYER = 2;
|
|
93
|
+
/**
|
|
94
|
+
* The most glow a wrun output or drawing lands with (PLOTS-2): the engine
|
|
95
|
+
* writes glow to `ctx.shadowBlur` with no clamp, its cost grows with the
|
|
96
|
+
* radius, and a glowing mark, column or candle leaves its batch and blurs one
|
|
97
|
+
* primitive per bar on every full frame. It IS the handles' validation range
|
|
98
|
+
* (`WRUN3_MAX_GLOW_PX`, the kit's documented 0 to 32, pinned by the kit
|
|
99
|
+
* mirror), one constant so the two can never drift: no documented-legal
|
|
100
|
+
* script changes, only a value past it (a hand-written sheet the kit never
|
|
101
|
+
* validated) lands at the ceiling, and a negative one as none instead of
|
|
102
|
+
* refusing the run. `true` stays the engine's 12 px.
|
|
103
|
+
*/
|
|
104
|
+
export const WRUN_MAX_GLOW_PX = WRUN3_MAX_GLOW_PX;
|
|
105
|
+
/** The engine's clampGlow ceiling for plotShape(glow=...): a shape's glow
|
|
106
|
+
* lands at most this (under the host's 32), as before the host clamp. */
|
|
107
|
+
const WRUN_ENGINE_SHAPE_GLOW_MAX_PX = 30;
|
|
108
|
+
let wrunGlowClampDisabled = false;
|
|
109
|
+
/** Kill switch for the host glow clamp: off restores today's glow exactly
|
|
110
|
+
* (any px >= 0, a negative refused; render.shape keeps the engine's 30). */
|
|
111
|
+
export function setWrunGlowClampDisabled(disabled) {
|
|
112
|
+
wrunGlowClampDisabled = disabled === true;
|
|
113
|
+
}
|
|
114
|
+
export function isWrunGlowClampDisabled() {
|
|
115
|
+
return wrunGlowClampDisabled;
|
|
116
|
+
}
|
|
117
|
+
/** A finite declared glow in px as it lands: inside 0..32 (a negative is
|
|
118
|
+
* none) while the clamp is on, as declared while it is off. */
|
|
119
|
+
export function landWrunGlowPx(px) {
|
|
120
|
+
return wrunGlowClampDisabled ? px : Math.min(WRUN_MAX_GLOW_PX, Math.max(0, px));
|
|
121
|
+
}
|
|
122
|
+
/** A finite plotShape glow in px as it lands: 0 or less is no glow (false),
|
|
123
|
+
* else at most the engine's clampGlow 30 (under the host's 32). */
|
|
124
|
+
export function landWrunShapeGlowPx(px) {
|
|
125
|
+
return px <= 0 ? false : Math.min(WRUN_ENGINE_SHAPE_GLOW_MAX_PX, WRUN_MAX_GLOW_PX, px);
|
|
126
|
+
}
|
|
127
|
+
if (typeof window !== 'undefined') {
|
|
128
|
+
const win = window;
|
|
129
|
+
win.__disableKiyoWrunGlowClamp = () => {
|
|
130
|
+
setWrunGlowClampDisabled(true);
|
|
131
|
+
return 'Kiyo wrun glow clamp DISABLED (glow lands as declared; reload the Indicator to repaint)';
|
|
132
|
+
};
|
|
133
|
+
win.__enableKiyoWrunGlowClamp = () => {
|
|
134
|
+
setWrunGlowClampDisabled(false);
|
|
135
|
+
return `Kiyo wrun glow clamp ENABLED (glow lands inside 0..${WRUN_MAX_GLOW_PX} px)`;
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
// Small readers
|
|
139
|
+
function wordList(words) {
|
|
140
|
+
return words.map((word) => `'${word}'`).join(', ');
|
|
141
|
+
}
|
|
142
|
+
function isWord(words, value) {
|
|
143
|
+
return typeof value === 'string' && words.includes(value);
|
|
144
|
+
}
|
|
145
|
+
function isFinite(value) {
|
|
146
|
+
return typeof value === 'number' && Number.isFinite(value);
|
|
147
|
+
}
|
|
148
|
+
function isUnitInterval(value) {
|
|
149
|
+
return isFinite(value) && value >= 0 && value <= 1;
|
|
150
|
+
}
|
|
151
|
+
function isColorWord(value) {
|
|
152
|
+
return typeof value === 'string' && value.trim() !== '';
|
|
153
|
+
}
|
|
154
|
+
function refusal(sheetId, subject, message) {
|
|
155
|
+
return new Error(`WRUN ${sheetId === undefined ? '' : `${sheetId}: `}${subject} ${message}`);
|
|
156
|
+
}
|
|
157
|
+
/** The declared opacity when it is a unit-interval number, else undefined
|
|
158
|
+
* (the adapter refuses a malformed one on its own path). */
|
|
159
|
+
function declaredOpacity(value) {
|
|
160
|
+
return isUnitInterval(value) ? value : undefined;
|
|
161
|
+
}
|
|
162
|
+
function parseHexColor(text) {
|
|
163
|
+
const hex = /^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i.exec(text);
|
|
164
|
+
if (!hex)
|
|
165
|
+
return undefined;
|
|
166
|
+
let digits = hex[1];
|
|
167
|
+
if (digits.length <= 4)
|
|
168
|
+
digits = [...digits].map((digit) => digit + digit).join('');
|
|
169
|
+
return {
|
|
170
|
+
r: parseInt(digits.slice(0, 2), 16),
|
|
171
|
+
g: parseInt(digits.slice(2, 4), 16),
|
|
172
|
+
b: parseInt(digits.slice(4, 6), 16),
|
|
173
|
+
a: digits.length === 8 ? Number((parseInt(digits.slice(6, 8), 16) / 255).toFixed(3)) : 1,
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
function parseRgbColor(text) {
|
|
177
|
+
const rgb = /^rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*(?:,\s*([\d.]+)\s*)?\)$/i.exec(text);
|
|
178
|
+
if (!rgb)
|
|
179
|
+
return undefined;
|
|
180
|
+
const r = Number(rgb[1]);
|
|
181
|
+
const g = Number(rgb[2]);
|
|
182
|
+
const b = Number(rgb[3]);
|
|
183
|
+
const a = rgb[4] === undefined ? 1 : Number(rgb[4]);
|
|
184
|
+
if (![r, g, b].every((channel) => Number.isFinite(channel) && channel >= 0 && channel <= 255))
|
|
185
|
+
return undefined;
|
|
186
|
+
if (!Number.isFinite(a) || a < 0 || a > 1)
|
|
187
|
+
return undefined;
|
|
188
|
+
return { r, g, b, a };
|
|
189
|
+
}
|
|
190
|
+
/** The product of a colour's own alpha and a factor, written the way the
|
|
191
|
+
* adapter's `withOpacity` writes a plain factor (byte-identical for a
|
|
192
|
+
* colour without alpha) and at three decimals otherwise. */
|
|
193
|
+
function scaledAlpha(own, factor) {
|
|
194
|
+
return own === 1 ? factor : Number((own * factor).toFixed(3));
|
|
195
|
+
}
|
|
196
|
+
/** MULTIPLIES a colour's own alpha by `opacity` (conventions 3, OT30): a
|
|
197
|
+
* colour without alpha comes back exactly as the adapter's `withOpacity`
|
|
198
|
+
* wrote it (`rgba(r, g, b, opacity)`), one with alpha at the product; a
|
|
199
|
+
* theme token keeps its word with its alpha scaled (`theme.up` at 0.5 is
|
|
200
|
+
* `theme.up/80`); `hsl()` / `hsla()` scale in place. An opacity that is
|
|
201
|
+
* absent, 1, out of 0..1 or not a number, and a colour the parser cannot
|
|
202
|
+
* read (a named colour), come back unchanged. */
|
|
203
|
+
export function multiplyWrunOpacity(color, opacity) {
|
|
204
|
+
if (typeof color !== 'string')
|
|
205
|
+
return color;
|
|
206
|
+
if (opacity === undefined || !isFinite(opacity) || opacity < 0 || opacity >= 1)
|
|
207
|
+
return color;
|
|
208
|
+
if (parseWrunThemeToken(color) !== null)
|
|
209
|
+
return wrunThemeTokenScaleAlpha(color, opacity);
|
|
210
|
+
const text = color.trim();
|
|
211
|
+
const parts = parseHexColor(text) ?? parseRgbColor(text);
|
|
212
|
+
if (parts !== undefined)
|
|
213
|
+
return `rgba(${parts.r}, ${parts.g}, ${parts.b}, ${scaledAlpha(parts.a, opacity)})`;
|
|
214
|
+
const hsl = /^hsla?(\(\s*-?\d+(?:\.\d+)?(?:deg)?\s*,\s*\d+(?:\.\d+)?%\s*,\s*\d+(?:\.\d+)?%)\s*(?:,\s*([\d.]+)\s*)?\)$/i.exec(text);
|
|
215
|
+
if (hsl) {
|
|
216
|
+
const own = hsl[2] === undefined ? 1 : Number(hsl[2]);
|
|
217
|
+
return `hsla${hsl[1]}, ${scaledAlpha(isUnitInterval(own) ? own : 1, opacity)})`;
|
|
218
|
+
}
|
|
219
|
+
return color;
|
|
220
|
+
}
|
|
221
|
+
/** A legacy output `unit` (declared without `format`) that the legend prints
|
|
222
|
+
* after the value (TEMPLATE-QA B15): a suffix that attaches to a number
|
|
223
|
+
* ("%", "x", "M", "°C"), at most 8 characters and with no run of two
|
|
224
|
+
* letters. A unit that names what the value measures ("probability",
|
|
225
|
+
* "score", "USD") keeps its legacy meaning: accepted, unprinted. */
|
|
226
|
+
function isPrintedLegacyUnit(unit) {
|
|
227
|
+
return (typeof unit === 'string' &&
|
|
228
|
+
unit.trim() !== '' &&
|
|
229
|
+
unit.length <= WRUN_MAX_VALUE_UNIT_CHARS &&
|
|
230
|
+
!/\p{L}{2}/u.test(unit));
|
|
231
|
+
}
|
|
232
|
+
/** The declared `decimals` / `signed` / `unit` of an entry, validated the
|
|
233
|
+
* kit's way: `decimals` an integer 0..8, `signed` a boolean, `unit` a
|
|
234
|
+
* string of at most 8 characters beside `format`; `decimals` and `signed`
|
|
235
|
+
* need `format`. With `legacyUnit` a `unit` without `format` keeps its
|
|
236
|
+
* legacy meaning (accepted, unbounded: the outputs' rule) and rides along
|
|
237
|
+
* only as a printed suffix (isPrintedLegacyUnit); without it `unit` needs
|
|
238
|
+
* `format` too. Undefined = nothing declared (an empty `unit` prints
|
|
239
|
+
* nothing and counts as nothing). */
|
|
240
|
+
function readFormatOptions(entry, subject, sheetId, legacyUnit) {
|
|
241
|
+
const hasFormat = entry.format !== undefined;
|
|
242
|
+
const options = {};
|
|
243
|
+
if (entry.decimals !== undefined) {
|
|
244
|
+
if (!Number.isInteger(entry.decimals) ||
|
|
245
|
+
entry.decimals < 0 ||
|
|
246
|
+
entry.decimals > WRUN_MAX_VALUE_DECIMALS) {
|
|
247
|
+
throw refusal(sheetId, subject, `decimals must be an integer from 0 to ${WRUN_MAX_VALUE_DECIMALS}`);
|
|
248
|
+
}
|
|
249
|
+
if (!hasFormat)
|
|
250
|
+
throw refusal(sheetId, subject, 'decimals needs format');
|
|
251
|
+
options.decimals = entry.decimals;
|
|
252
|
+
}
|
|
253
|
+
if (entry.signed !== undefined) {
|
|
254
|
+
if (typeof entry.signed !== 'boolean')
|
|
255
|
+
throw refusal(sheetId, subject, 'signed must be true or false');
|
|
256
|
+
if (!hasFormat)
|
|
257
|
+
throw refusal(sheetId, subject, 'signed needs format');
|
|
258
|
+
options.signed = entry.signed;
|
|
259
|
+
}
|
|
260
|
+
if (entry.unit !== undefined && (hasFormat || !legacyUnit)) {
|
|
261
|
+
if (typeof entry.unit !== 'string')
|
|
262
|
+
throw refusal(sheetId, subject, 'unit must be a string');
|
|
263
|
+
if (!hasFormat)
|
|
264
|
+
throw refusal(sheetId, subject, 'unit needs format');
|
|
265
|
+
if (entry.unit.length > WRUN_MAX_VALUE_UNIT_CHARS) {
|
|
266
|
+
throw refusal(sheetId, subject, `unit takes at most ${WRUN_MAX_VALUE_UNIT_CHARS} characters`);
|
|
267
|
+
}
|
|
268
|
+
if (entry.unit !== '')
|
|
269
|
+
options.unit = entry.unit;
|
|
270
|
+
}
|
|
271
|
+
else if (legacyUnit && !hasFormat && isPrintedLegacyUnit(entry.unit)) {
|
|
272
|
+
options.unit = entry.unit;
|
|
273
|
+
}
|
|
274
|
+
return Object.keys(options).length > 0 ? options : undefined;
|
|
275
|
+
}
|
|
276
|
+
/** The `formatOptions` an output's declaration stamps on the mounted output
|
|
277
|
+
* (OT32), beside its `format`, or a printed legacy unit alone without one
|
|
278
|
+
* (B15): undefined when it declares no companion. */
|
|
279
|
+
export function readWrunOutputFormatOptions(output, sheetId) {
|
|
280
|
+
return readFormatOptions(output, `output '${output.name}'`, sheetId, true);
|
|
281
|
+
}
|
|
282
|
+
/** The sheet's `location` word (OT07, D5) as the engine's word; a camel
|
|
283
|
+
* word passes as written; anything else refuses by name. */
|
|
284
|
+
function markerLocation(value, subject, sheetId) {
|
|
285
|
+
const word = typeof value === 'string' ? WRUN_LOCATION_WORDS[value] : undefined;
|
|
286
|
+
if (word === undefined)
|
|
287
|
+
throw refusal(sheetId, subject, `location must be one of ${WRUN_LOCATION_LIST}`);
|
|
288
|
+
return word;
|
|
289
|
+
}
|
|
290
|
+
/** The colour stops of a `gradient` / `fill_gradient` (2..8 colour words). */
|
|
291
|
+
function colorStops(value, key, subject, sheetId) {
|
|
292
|
+
if (!Array.isArray(value) ||
|
|
293
|
+
value.length < WRUN_MIN_GRADIENT_STOPS ||
|
|
294
|
+
value.length > WRUN_MAX_GRADIENT_STOPS ||
|
|
295
|
+
!value.every(isColorWord)) {
|
|
296
|
+
throw refusal(sheetId, subject, `${key} must list ${WRUN_MIN_GRADIENT_STOPS} to ${WRUN_MAX_GRADIENT_STOPS} colours`);
|
|
297
|
+
}
|
|
298
|
+
return [...value];
|
|
299
|
+
}
|
|
300
|
+
/** `z` (OT04): an integer -10..10 as the engine's `zOrder`. */
|
|
301
|
+
function zOrderPatch(value, subject, sheetId) {
|
|
302
|
+
if (value === undefined)
|
|
303
|
+
return {};
|
|
304
|
+
if (!Number.isInteger(value) || value < WRUN_MIN_Z || value > WRUN_MAX_Z) {
|
|
305
|
+
throw refusal(sheetId, subject, `z must be an integer from ${WRUN_MIN_Z} to ${WRUN_MAX_Z}`);
|
|
306
|
+
}
|
|
307
|
+
return { zOrder: value };
|
|
308
|
+
}
|
|
309
|
+
/** `glow` (OT16): px on every drawn output and on render.shape, landing
|
|
310
|
+
* inside 0..32 (`landWrunGlowPx`, PLOTS-2); a value that is no number
|
|
311
|
+
* refuses by name. */
|
|
312
|
+
function glowPatch(value, subject, sheetId) {
|
|
313
|
+
if (value === undefined)
|
|
314
|
+
return {};
|
|
315
|
+
if (!isFinite(value) || (value < 0 && wrunGlowClampDisabled)) {
|
|
316
|
+
throw refusal(sheetId, subject, 'glow must be a number of px >= 0');
|
|
317
|
+
}
|
|
318
|
+
return { glow: landWrunGlowPx(value) };
|
|
319
|
+
}
|
|
320
|
+
/** The mark look shared by shape outputs and render.shape (OT07 OT16 OT35,
|
|
321
|
+
* D5): placement, glow, the char glyph and its font, the hollow and faded
|
|
322
|
+
* interior. `fill: true` is the adapter's own field (sent as today); only
|
|
323
|
+
* `fill: false` rides the patch. */
|
|
324
|
+
function markLook(entry, subject, sheetId) {
|
|
325
|
+
const patch = {};
|
|
326
|
+
if (entry.location !== undefined)
|
|
327
|
+
patch.location = markerLocation(entry.location, subject, sheetId);
|
|
328
|
+
Object.assign(patch, glowPatch(entry.glow, subject, sheetId));
|
|
329
|
+
const charMark = entry.shape === 'char';
|
|
330
|
+
if (entry.char !== undefined) {
|
|
331
|
+
if (typeof entry.char !== 'string' || Array.from(entry.char).length !== 1) {
|
|
332
|
+
throw refusal(sheetId, subject, 'char must be one character');
|
|
333
|
+
}
|
|
334
|
+
if (!charMark)
|
|
335
|
+
throw refusal(sheetId, subject, "char needs shape 'char'");
|
|
336
|
+
patch.char = entry.char;
|
|
337
|
+
}
|
|
338
|
+
else if (charMark) {
|
|
339
|
+
throw refusal(sheetId, subject, "shape 'char' needs char (one character)");
|
|
340
|
+
}
|
|
341
|
+
if (entry.fill !== undefined) {
|
|
342
|
+
if (typeof entry.fill !== 'boolean')
|
|
343
|
+
throw refusal(sheetId, subject, 'fill must be true or false');
|
|
344
|
+
if (charMark)
|
|
345
|
+
throw refusal(sheetId, subject, 'fill does not apply to a char mark');
|
|
346
|
+
// R25: the engine reads a hollow mark from `hollow: true`; `fill: false`
|
|
347
|
+
// keeps its HEAD meaning there (it hollows circles only, because kScript's
|
|
348
|
+
// plotShape always sends fill false). A wrun sheet's hollow mark sends both.
|
|
349
|
+
if (entry.fill === false) {
|
|
350
|
+
patch.fill = false;
|
|
351
|
+
patch.hollow = true;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
if (entry.fill_opacity !== undefined) {
|
|
355
|
+
if (!isUnitInterval(entry.fill_opacity))
|
|
356
|
+
throw refusal(sheetId, subject, 'fill_opacity must be between 0 and 1');
|
|
357
|
+
if (charMark)
|
|
358
|
+
throw refusal(sheetId, subject, 'fill_opacity does not apply to a char mark');
|
|
359
|
+
if (entry.fill === false) {
|
|
360
|
+
throw refusal(sheetId, subject, 'fill_opacity needs fill (an outline-only mark has no interior to fade)');
|
|
361
|
+
}
|
|
362
|
+
patch.fillOpacity = entry.fill_opacity;
|
|
363
|
+
}
|
|
364
|
+
if (entry.font_family !== undefined) {
|
|
365
|
+
const css = wrunFontFamilyCss(entry.font_family);
|
|
366
|
+
if (css === undefined)
|
|
367
|
+
throw refusal(sheetId, subject, `font_family must be one of ${wordList(WRUN_FONT_FAMILIES)}`);
|
|
368
|
+
if (!charMark)
|
|
369
|
+
throw refusal(sheetId, subject, "font_family applies to a char mark only (shape 'char')");
|
|
370
|
+
patch.fontFamily = css;
|
|
371
|
+
}
|
|
372
|
+
return patch;
|
|
373
|
+
}
|
|
374
|
+
/** The run-output fields an output's g5 look words add (OT01 OT02 OT04 OT07
|
|
375
|
+
* OT09 OT11 OT13 OT14 OT16 OT32 OT34 OT35), merged over the adapter's own
|
|
376
|
+
* fields by every mount branch: an output that declares none of them gets
|
|
377
|
+
* an empty patch. `mount` is how the adapter mounts the output; an area
|
|
378
|
+
* passed as a line is read as an area. */
|
|
379
|
+
export function wrunOutputLookPatch(output, mount, ctx) {
|
|
380
|
+
const subject = `output '${output.name}'`;
|
|
381
|
+
const { sheetId } = ctx;
|
|
382
|
+
const kind = mount === 'line' && output.plot === 'area' ? 'area' : mount;
|
|
383
|
+
const guide = output.role === 'guide';
|
|
384
|
+
const opacity = declaredOpacity(output.opacity);
|
|
385
|
+
const fade = (color) => multiplyWrunOpacity(color, opacity);
|
|
386
|
+
const patch = {};
|
|
387
|
+
// OT01: the axis tag on every sheet (per_output's own flag wins), the
|
|
388
|
+
// name tag; a guide takes `axis_label` as its axis pill (wrunGuideLook).
|
|
389
|
+
if (guide) {
|
|
390
|
+
if (!ctx.perOutputPriceDisplay)
|
|
391
|
+
patch.showPriceDisplay = false;
|
|
392
|
+
}
|
|
393
|
+
else {
|
|
394
|
+
const resolved = ctx.showPriceDisplay ??
|
|
395
|
+
(ctx.perOutputPriceDisplay && typeof output.show_price_display === 'boolean'
|
|
396
|
+
? output.show_price_display
|
|
397
|
+
: undefined);
|
|
398
|
+
if (resolved !== undefined)
|
|
399
|
+
patch.showPriceDisplay = resolved;
|
|
400
|
+
else if (output.axis_label !== undefined) {
|
|
401
|
+
if (typeof output.axis_label !== 'boolean')
|
|
402
|
+
throw refusal(sheetId, subject, 'axis_label must be true or false');
|
|
403
|
+
patch.showPriceDisplay = output.axis_label;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
if (output.axis_name !== undefined) {
|
|
407
|
+
if (typeof output.axis_name !== 'boolean')
|
|
408
|
+
throw refusal(sheetId, subject, 'axis_name must be true or false');
|
|
409
|
+
if (output.axis_name && output.axis_label === false) {
|
|
410
|
+
throw refusal(sheetId, subject, 'axis_name: true needs axis_label, not axis_label: false');
|
|
411
|
+
}
|
|
412
|
+
if (output.axis_name)
|
|
413
|
+
patch.showYAxisNameLabel = true;
|
|
414
|
+
}
|
|
415
|
+
// OT09: the last-value line.
|
|
416
|
+
if (output.price_line !== undefined) {
|
|
417
|
+
if (typeof output.price_line !== 'boolean')
|
|
418
|
+
throw refusal(sheetId, subject, 'price_line must be true or false');
|
|
419
|
+
if (guide)
|
|
420
|
+
throw refusal(sheetId, subject, 'price_line and role "guide" on one output (a guide is already a line at its value)');
|
|
421
|
+
if (output.price_line)
|
|
422
|
+
patch.showLastValueLine = true;
|
|
423
|
+
}
|
|
424
|
+
// OT04, OT16, OT32.
|
|
425
|
+
Object.assign(patch, zOrderPatch(output.z, subject, sheetId));
|
|
426
|
+
Object.assign(patch, glowPatch(output.glow, subject, sheetId));
|
|
427
|
+
// The companions beside `format`, or a unit printed without one (B15: "%").
|
|
428
|
+
const formatOptions = readWrunOutputFormatOptions(output, sheetId);
|
|
429
|
+
if (formatOptions !== undefined)
|
|
430
|
+
patch.formatOptions = formatOptions;
|
|
431
|
+
// OT11 OT13 OT14: the line looks.
|
|
432
|
+
if (kind === 'line') {
|
|
433
|
+
if (output.step !== undefined) {
|
|
434
|
+
if (typeof output.step !== 'boolean')
|
|
435
|
+
throw refusal(sheetId, subject, 'step must be true or false');
|
|
436
|
+
if (output.step && (output.smooth === true || output.smooth === 1)) {
|
|
437
|
+
throw refusal(sheetId, subject, 'step and smooth on one output (take one)');
|
|
438
|
+
}
|
|
439
|
+
if (output.step)
|
|
440
|
+
patch.smooth = 'step';
|
|
441
|
+
}
|
|
442
|
+
if (output.gradient !== undefined) {
|
|
443
|
+
const stops = colorStops(output.gradient, 'gradient', subject, sheetId);
|
|
444
|
+
if (output.color_by !== undefined || output.color_packed_by !== undefined || output.split !== undefined) {
|
|
445
|
+
throw refusal(sheetId, subject, 'gradient and color_by, color_packed_by or split on one output (take one)');
|
|
446
|
+
}
|
|
447
|
+
// The engine lays gradientColors from the bottom of the pane up; the
|
|
448
|
+
// sheet lists stops from the top down. The legend dot reads the top.
|
|
449
|
+
patch.gradientColors = [[...stops].reverse().map(fade)];
|
|
450
|
+
patch.colors = [fade(stops[0])];
|
|
451
|
+
patch.glow = isFinite(output.glow) ? landWrunGlowPx(output.glow) : 0;
|
|
452
|
+
}
|
|
453
|
+
if (output.split !== undefined) {
|
|
454
|
+
if (!isWord(WRUN_LINE_SPLIT_MODES, output.split)) {
|
|
455
|
+
throw refusal(sheetId, subject, `split must be one of ${wordList(WRUN_LINE_SPLIT_MODES)}`);
|
|
456
|
+
}
|
|
457
|
+
if (output.color_by !== undefined || output.color_packed_by !== undefined) {
|
|
458
|
+
throw refusal(sheetId, subject, 'split and color_by or color_packed_by on one output (take one)');
|
|
459
|
+
}
|
|
460
|
+
if (!isColorWord(output.up_color) || !isColorWord(output.down_color)) {
|
|
461
|
+
throw refusal(sheetId, subject, 'split needs up_color and down_color');
|
|
462
|
+
}
|
|
463
|
+
if (output.split_level !== undefined && !isFinite(output.split_level)) {
|
|
464
|
+
throw refusal(sheetId, subject, 'split_level must be a finite number');
|
|
465
|
+
}
|
|
466
|
+
if (output.split_base !== undefined && !isFinite(output.split_base)) {
|
|
467
|
+
throw refusal(sheetId, subject, 'split_base must be a finite number');
|
|
468
|
+
}
|
|
469
|
+
if (output.split === 'slope' && (output.split_level !== undefined || output.split_fill !== undefined)) {
|
|
470
|
+
throw refusal(sheetId, subject, 'split_level and split_fill need split "level"');
|
|
471
|
+
}
|
|
472
|
+
if (output.split_base !== undefined && output.split_fill !== true) {
|
|
473
|
+
throw refusal(sheetId, subject, 'split_base needs split_fill: true');
|
|
474
|
+
}
|
|
475
|
+
const level = output.split_level ?? 0;
|
|
476
|
+
patch.multiColorSettings = {
|
|
477
|
+
topColor: fade(output.up_color),
|
|
478
|
+
bottomColor: fade(output.down_color),
|
|
479
|
+
separatingLevel: level,
|
|
480
|
+
baseValue: output.split_base ?? level,
|
|
481
|
+
fill: output.split_fill === true,
|
|
482
|
+
mode: output.split,
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
else {
|
|
486
|
+
for (const key of ['up_color', 'down_color', 'split_level', 'split_fill', 'split_base']) {
|
|
487
|
+
if (output[key] !== undefined)
|
|
488
|
+
throw refusal(sheetId, subject, `${key} needs split`);
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
else {
|
|
493
|
+
for (const key of ['step', 'gradient', 'split']) {
|
|
494
|
+
if (output[key] !== undefined)
|
|
495
|
+
throw refusal(sheetId, subject, `${key} needs a line output`);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
// OT02: the area fill colour, alpha and gradient.
|
|
499
|
+
if (kind === 'area') {
|
|
500
|
+
if (output.fill_opacity !== undefined && !isUnitInterval(output.fill_opacity)) {
|
|
501
|
+
throw refusal(sheetId, subject, 'fill_opacity must be between 0 and 1');
|
|
502
|
+
}
|
|
503
|
+
if (output.fill_color !== undefined && !isColorWord(output.fill_color)) {
|
|
504
|
+
throw refusal(sheetId, subject, 'fill_color must be a colour');
|
|
505
|
+
}
|
|
506
|
+
if (output.fill_gradient !== undefined) {
|
|
507
|
+
const stops = colorStops(output.fill_gradient, 'fill_gradient', subject, sheetId);
|
|
508
|
+
if (output.fill_color !== undefined) {
|
|
509
|
+
throw refusal(sheetId, subject, 'fill_color and fill_gradient on one output (take one)');
|
|
510
|
+
}
|
|
511
|
+
if (output.gradient_mode !== undefined && !isWord(WRUN_GRADIENT_MODES, output.gradient_mode)) {
|
|
512
|
+
throw refusal(sheetId, subject, `gradient_mode must be one of ${wordList(WRUN_GRADIENT_MODES)}`);
|
|
513
|
+
}
|
|
514
|
+
const alpha = (output.fill_opacity ?? 1) * (opacity ?? 1);
|
|
515
|
+
patch.fillGradient = {
|
|
516
|
+
stops: stops.map((stop, at) => [at / (stops.length - 1), multiplyWrunOpacity(stop, alpha)]),
|
|
517
|
+
...(output.gradient_mode !== undefined ? { mode: output.gradient_mode } : {}),
|
|
518
|
+
};
|
|
519
|
+
}
|
|
520
|
+
else {
|
|
521
|
+
if (output.gradient_mode !== undefined)
|
|
522
|
+
throw refusal(sheetId, subject, 'gradient_mode needs fill_gradient');
|
|
523
|
+
const base = output.fill_color ?? ctx.baseColor;
|
|
524
|
+
if ((output.fill_color !== undefined || output.fill_opacity !== undefined) && base !== undefined) {
|
|
525
|
+
const tint = multiplyWrunOpacity(base, (output.fill_opacity ?? WRUN_AREA_FILL_ALPHA) * (opacity ?? 1));
|
|
526
|
+
patch.fillGradient = {
|
|
527
|
+
stops: [
|
|
528
|
+
[0, tint],
|
|
529
|
+
[1, tint],
|
|
530
|
+
],
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
else {
|
|
536
|
+
for (const key of ['fill_color', 'fill_gradient', 'gradient_mode']) {
|
|
537
|
+
if (output[key] !== undefined)
|
|
538
|
+
throw refusal(sheetId, subject, `${key} needs an area output`);
|
|
539
|
+
}
|
|
540
|
+
if (output.fill_opacity !== undefined && kind !== 'shape') {
|
|
541
|
+
throw refusal(sheetId, subject, 'fill_opacity needs an area or shape output');
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
// OT34: column alpha by magnitude.
|
|
545
|
+
if (output.grading !== undefined) {
|
|
546
|
+
if (kind !== 'bar')
|
|
547
|
+
throw refusal(sheetId, subject, 'grading needs a bar or histogram output');
|
|
548
|
+
if (!isWord(WRUN_BAR_GRADINGS, output.grading)) {
|
|
549
|
+
throw refusal(sheetId, subject, `grading must be one of ${wordList(WRUN_BAR_GRADINGS)}`);
|
|
550
|
+
}
|
|
551
|
+
patch.gradingMode = output.grading;
|
|
552
|
+
}
|
|
553
|
+
// OT07 OT35: the mark look.
|
|
554
|
+
if (kind === 'shape') {
|
|
555
|
+
Object.assign(patch, markLook(output, subject, sheetId));
|
|
556
|
+
}
|
|
557
|
+
else {
|
|
558
|
+
for (const key of ['char', 'font_family']) {
|
|
559
|
+
if (output[key] !== undefined)
|
|
560
|
+
throw refusal(sheetId, subject, `${key} needs a shape output (a char mark)`);
|
|
561
|
+
}
|
|
562
|
+
if (output.location !== undefined && kind !== 'candle') {
|
|
563
|
+
throw refusal(sheetId, subject, 'location needs a shape output');
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
return patch;
|
|
567
|
+
}
|
|
568
|
+
// The guide (OT10)
|
|
569
|
+
/** The hline fields a `role: "guide"` output adds (OT10): the on-line label
|
|
570
|
+
* (`align` places the output's `label`, `pill_style` and `font_size` dress
|
|
571
|
+
* it), the axis pill (`axis_label: true` puts value + label on the axis
|
|
572
|
+
* instead), the constant `value` and the paint order. `lastValue` is the
|
|
573
|
+
* output's last finite value (NaN when the run never gave one). */
|
|
574
|
+
export function wrunGuideLook(output, lastValue, label) {
|
|
575
|
+
const subject = `output '${output.name}'`;
|
|
576
|
+
const patch = { value: lastValue };
|
|
577
|
+
if (output.align !== undefined) {
|
|
578
|
+
if (!isWord(WRUN_GUIDE_ALIGNS, output.align)) {
|
|
579
|
+
throw refusal(undefined, subject, `align must be one of ${wordList(WRUN_GUIDE_ALIGNS)}`);
|
|
580
|
+
}
|
|
581
|
+
if (output.axis_label === true) {
|
|
582
|
+
throw refusal(undefined, subject, 'align and axis_label: true on one guide (take one: the label sits on the line or on the axis)');
|
|
583
|
+
}
|
|
584
|
+
patch.label = label;
|
|
585
|
+
patch.labelAnchor = output.align;
|
|
586
|
+
if (output.pill_style !== undefined) {
|
|
587
|
+
if (!isWord(WRUN_PILL_STYLES, output.pill_style)) {
|
|
588
|
+
throw refusal(undefined, subject, `pill_style must be one of ${wordList(WRUN_PILL_STYLES)}`);
|
|
589
|
+
}
|
|
590
|
+
if (output.pill_style === 'outlined')
|
|
591
|
+
patch.pillStyle = 'outlined';
|
|
592
|
+
}
|
|
593
|
+
if (output.font_size !== undefined) {
|
|
594
|
+
if (!Number.isInteger(output.font_size) ||
|
|
595
|
+
output.font_size < WRUN_MIN_FONT_SIZE_PX ||
|
|
596
|
+
output.font_size > WRUN_MAX_FONT_SIZE_PX) {
|
|
597
|
+
throw refusal(undefined, subject, `font_size must be an integer from ${WRUN_MIN_FONT_SIZE_PX} to ${WRUN_MAX_FONT_SIZE_PX}`);
|
|
598
|
+
}
|
|
599
|
+
patch.fontSize = output.font_size;
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
else {
|
|
603
|
+
if (output.pill_style !== undefined)
|
|
604
|
+
throw refusal(undefined, subject, 'pill_style needs align');
|
|
605
|
+
if (output.font_size !== undefined)
|
|
606
|
+
throw refusal(undefined, subject, 'font_size needs align');
|
|
607
|
+
}
|
|
608
|
+
if (output.axis_label === true) {
|
|
609
|
+
patch.axisLabel = true;
|
|
610
|
+
patch.label = label;
|
|
611
|
+
}
|
|
612
|
+
Object.assign(patch, zOrderPatch(output.z, subject, undefined));
|
|
613
|
+
return patch;
|
|
614
|
+
}
|
|
615
|
+
// The candle group (OT17, OT30)
|
|
616
|
+
/** A candle pair list, [both] or [up, down], as the engine's [up, down] at
|
|
617
|
+
* the group's opacity. */
|
|
618
|
+
function candlePair(value, key, subject, sheetId, opacity) {
|
|
619
|
+
if (!Array.isArray(value) || value.length < 1 || value.length > 2 || !value.every(isColorWord)) {
|
|
620
|
+
throw refusal(sheetId, subject, `${key} must list 1 or 2 colours`);
|
|
621
|
+
}
|
|
622
|
+
const [up, down = up] = value;
|
|
623
|
+
return [multiplyWrunOpacity(up, opacity), multiplyWrunOpacity(down, opacity)];
|
|
624
|
+
}
|
|
625
|
+
/** The candle look a group's first output declares (OT17): the body style
|
|
626
|
+
* as the engine plot kind, the border and wick pairs (faded by the group's
|
|
627
|
+
* opacity, OT30) and the border width. */
|
|
628
|
+
export function wrunCandleLook(first, sheetId) {
|
|
629
|
+
const subject = `output '${first.name}'`;
|
|
630
|
+
const opacity = declaredOpacity(first.opacity);
|
|
631
|
+
const patch = {};
|
|
632
|
+
if (first.candle_style !== undefined) {
|
|
633
|
+
if (!isWord(WRUN_CANDLE_STYLES, first.candle_style)) {
|
|
634
|
+
throw refusal(sheetId, subject, `candle_style must be one of ${wordList(WRUN_CANDLE_STYLES)}`);
|
|
635
|
+
}
|
|
636
|
+
patch.plotType = WRUN_CANDLE_PLOT_TYPES[first.candle_style];
|
|
637
|
+
}
|
|
638
|
+
if (first.border_colors !== undefined) {
|
|
639
|
+
patch.strokeColor = candlePair(first.border_colors, 'border_colors', subject, sheetId, opacity);
|
|
640
|
+
}
|
|
641
|
+
if (first.wick_colors !== undefined) {
|
|
642
|
+
patch.wickColor = candlePair(first.wick_colors, 'wick_colors', subject, sheetId, opacity);
|
|
643
|
+
}
|
|
644
|
+
if (first.border_width !== undefined) {
|
|
645
|
+
if (!isFinite(first.border_width) || first.border_width < 0 || first.border_width > WRUN_MAX_BORDER_WIDTH) {
|
|
646
|
+
throw refusal(sheetId, subject, `border_width must be between 0 and ${WRUN_MAX_BORDER_WIDTH}`);
|
|
647
|
+
}
|
|
648
|
+
patch.strokeWidth = first.border_width;
|
|
649
|
+
}
|
|
650
|
+
return patch;
|
|
651
|
+
}
|
|
652
|
+
/** Refuses the candle look keys on a group's second to fourth output by
|
|
653
|
+
* name (OT17): only the first output carries the group's look. */
|
|
654
|
+
export function assertWrunCandleMemberLook(member, sheetId) {
|
|
655
|
+
for (const key of ['candle_style', 'border_colors', 'wick_colors', 'border_width']) {
|
|
656
|
+
if (member[key] !== undefined) {
|
|
657
|
+
throw refusal(sheetId, `output '${member.name}'`, `${key}: only the first output of a candle group takes it`);
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
/** The plotShape wire of a shape output with a colour ladder (OT05): mark
|
|
662
|
+
* rows `[ts, value, widthSlot, colorSlot]` at styleDataOffset 2
|
|
663
|
+
* (styleProperties ['width', 'color']), the `color` table
|
|
664
|
+
* `[staticColor, ...ladder]` so a non-finite rung indexes slot 0 (the
|
|
665
|
+
* static colour, the output ladder rule), the `widths` table only when
|
|
666
|
+
* one is declared. */
|
|
667
|
+
export function wrunShapeLadderOutput(input) {
|
|
668
|
+
const fade = (color) => multiplyWrunOpacity(color, input.opacity);
|
|
669
|
+
const staticColor = fade(input.staticColor);
|
|
670
|
+
const table = [staticColor, ...input.ladder.map(fade)];
|
|
671
|
+
const data = input.records.map(([ts, value, rowAt]) => {
|
|
672
|
+
const slot = input.slotAt(rowAt);
|
|
673
|
+
const colorSlot = slot === undefined || slot < 0 || slot >= input.ladder.length ? 0 : slot + 1;
|
|
674
|
+
return [ts, value, input.widthSlotAt?.(rowAt) ?? 0, colorSlot];
|
|
675
|
+
});
|
|
676
|
+
return {
|
|
677
|
+
data,
|
|
678
|
+
colors: [staticColor],
|
|
679
|
+
color: table,
|
|
680
|
+
...(input.widths !== undefined ? { widths: [...input.widths] } : {}),
|
|
681
|
+
styleProperties: ['width', 'color'],
|
|
682
|
+
styleDataOffset: 2,
|
|
683
|
+
};
|
|
684
|
+
}
|
|
685
|
+
/** The output key an area's fill band mounts under (OT31): the band's own
|
|
686
|
+
* mount mints it, the pane routing and the visibility apply find it by it. */
|
|
687
|
+
export function wrunAreaFillKey(name) {
|
|
688
|
+
return `${name}__area_fill`;
|
|
689
|
+
}
|
|
690
|
+
/** The second output an area with a fill ladder mounts right after its line
|
|
691
|
+
* (OT31): `<name>__area_fill`, the engine's plotLine(value=[v, 0],
|
|
692
|
+
* fill=true) band with no edge lines (width 0), each bar's interior from
|
|
693
|
+
* the fill ladder at alpha own x (fill_opacity ?? 0.4) x (opacity ?? 1),
|
|
694
|
+
* never a legend line nor a tag, half a layer under the line. */
|
|
695
|
+
export function wrunAreaFillLadderOutput(input) {
|
|
696
|
+
const alpha = (input.fillOpacity ?? WRUN_AREA_FILL_ALPHA) * (input.opacity ?? 1);
|
|
697
|
+
const fade = (color) => multiplyWrunOpacity(color, alpha);
|
|
698
|
+
const table = input.ladder.map(fade);
|
|
699
|
+
const z = input.z ?? WRUN_PLOT_LAYER;
|
|
700
|
+
return {
|
|
701
|
+
key: wrunAreaFillKey(input.name),
|
|
702
|
+
output: {
|
|
703
|
+
plotType: 'spline',
|
|
704
|
+
labels: [input.label],
|
|
705
|
+
legend: false,
|
|
706
|
+
showPriceDisplay: false,
|
|
707
|
+
multiValue: true,
|
|
708
|
+
fill: true,
|
|
709
|
+
areaFill: true,
|
|
710
|
+
smooth: input.smooth === true,
|
|
711
|
+
width: 0,
|
|
712
|
+
...(input.forceOnChart ? { forceOnChart: true } : {}),
|
|
713
|
+
colors: [fade(input.staticColor)],
|
|
714
|
+
color: table,
|
|
715
|
+
widths: [0],
|
|
716
|
+
styleProperties: ['color', 'width'],
|
|
717
|
+
styleDataOffset: 3,
|
|
718
|
+
zOrder: z - 0.5,
|
|
719
|
+
data: input.points.map(([ts, value], rowAt) => {
|
|
720
|
+
const plotted = [ts, value, Number.isFinite(value) ? 0 : Number.NaN];
|
|
721
|
+
const slot = input.slotAt(rowAt);
|
|
722
|
+
return slot === undefined || slot < 0 || slot >= table.length ? plotted : [...plotted, slot, 0];
|
|
723
|
+
}),
|
|
724
|
+
},
|
|
725
|
+
};
|
|
726
|
+
}
|
|
727
|
+
/** The spans of every stacked bar output (OT38), keyed by output name, one
|
|
728
|
+
* entry per run row (undefined where the row is not ready or the member's
|
|
729
|
+
* value is not finite: the member draws nothing that bar). Members sharing
|
|
730
|
+
* a `stack` name stack in declaration order; a `stack` off a bar or
|
|
731
|
+
* histogram output, beside `base`, or whose members sit on different panes
|
|
732
|
+
* refuses by name. */
|
|
733
|
+
export function wrunStackedRows(outputs, rows) {
|
|
734
|
+
const spans = new Map();
|
|
735
|
+
const stacks = new Map();
|
|
736
|
+
for (const output of [...outputs].sort((a, b) => a.index - b.index)) {
|
|
737
|
+
if (output.stack === undefined)
|
|
738
|
+
continue;
|
|
739
|
+
const subject = `output '${output.name}'`;
|
|
740
|
+
if (typeof output.stack !== 'string' || output.stack === '')
|
|
741
|
+
throw refusal(undefined, subject, 'stack must be a name');
|
|
742
|
+
if (output.plot !== 'bar' && output.plot !== 'histogram') {
|
|
743
|
+
throw refusal(undefined, subject, 'stack needs a bar or histogram output');
|
|
744
|
+
}
|
|
745
|
+
if (output.base !== undefined) {
|
|
746
|
+
throw refusal(undefined, subject, 'stack and base on one output (a stack grows from 0)');
|
|
747
|
+
}
|
|
748
|
+
const members = stacks.get(output.stack) ?? [];
|
|
749
|
+
const first = members[0];
|
|
750
|
+
if (first !== undefined && (first.panel !== output.panel || first.pane !== output.pane)) {
|
|
751
|
+
throw refusal(undefined, subject, `stack '${output.stack}' members must share one pane (panel and pane)`);
|
|
752
|
+
}
|
|
753
|
+
members.push(output);
|
|
754
|
+
stacks.set(output.stack, members);
|
|
755
|
+
}
|
|
756
|
+
for (const members of stacks.values()) {
|
|
757
|
+
for (const member of members)
|
|
758
|
+
spans.set(member.name, new Array(rows.length));
|
|
759
|
+
rows.forEach((row, rowAt) => {
|
|
760
|
+
if (row.outputs === null)
|
|
761
|
+
return;
|
|
762
|
+
let above = 0;
|
|
763
|
+
let below = 0;
|
|
764
|
+
for (const member of members) {
|
|
765
|
+
const value = row.outputs[member.index];
|
|
766
|
+
if (!isFinite(value))
|
|
767
|
+
continue;
|
|
768
|
+
const previous = value >= 0 ? above : below;
|
|
769
|
+
const next = previous + value;
|
|
770
|
+
spans.get(member.name)[rowAt] = [next, previous];
|
|
771
|
+
if (value >= 0)
|
|
772
|
+
above = next;
|
|
773
|
+
else
|
|
774
|
+
below = next;
|
|
775
|
+
}
|
|
776
|
+
});
|
|
777
|
+
}
|
|
778
|
+
return spans;
|
|
779
|
+
}
|
|
780
|
+
/** A fill row's opacity, the per-row cell of the engine's fillBetween wire
|
|
781
|
+
* (`[ts, colorSlot, opacity]`): the `opacity_by` output's value on the row
|
|
782
|
+
* when it is finite (clamped to 0..1, as titan paints it), else the fill's
|
|
783
|
+
* static `opacity`, else `fallback` (the host's own default; titan's is
|
|
784
|
+
* 0.25). Titan replaces each colour's alpha with it in every colour mode
|
|
785
|
+
* (static, `color_by`, `color_packed_by`), so every mode takes it. `row`
|
|
786
|
+
* is the run row's outputs (null on a row that was not ready). The kit's
|
|
787
|
+
* `wrunFillRowOpacity` (om scaffold 42, wrun-style/panes.ts), verbatim:
|
|
788
|
+
* wrun-fill-opacity.kit-mirror.spec.ts pins it to the kit's export. */
|
|
789
|
+
export function wrunFillRowOpacity(fill, row, outputIndex, fallback) {
|
|
790
|
+
const base = fill.opacity ?? fallback;
|
|
791
|
+
if (fill.opacity_by === undefined || row === null || row === undefined)
|
|
792
|
+
return base;
|
|
793
|
+
const at = outputIndex.get(fill.opacity_by);
|
|
794
|
+
const value = at === undefined ? Number.NaN : row[at];
|
|
795
|
+
return typeof value === 'number' && Number.isFinite(value) ? Math.min(1, Math.max(0, value)) : base;
|
|
796
|
+
}
|
|
797
|
+
/** The engine's fillBetween colour wire of a sheet fill (OT03): a static
|
|
798
|
+
* colour (`color`, else `staticColor`) for every row; `color_by` + `colors`
|
|
799
|
+
* the ladder table with each row's slot (floor, out of range = slot 0, a
|
|
800
|
+
* non-finite rung = NaN: no fill that bar); `color_packed_by` a palette
|
|
801
|
+
* interned in row order (the static colour where a value does not decode,
|
|
802
|
+
* NaN when there is none); `z` the paint order (OT04). Each row's opacity
|
|
803
|
+
* is wrunFillRowOpacity's in every mode: the `opacity_by` output's value on
|
|
804
|
+
* the row, else the static `opacity`, else `options.opacity` (else 0.25). */
|
|
805
|
+
export function wrunFillLadderRows(fill, rows, outputIndex, options = {}) {
|
|
806
|
+
const [first, second] = fill.between;
|
|
807
|
+
const subject = `fill '${first}'/'${second}'`;
|
|
808
|
+
const { sheetId } = options;
|
|
809
|
+
const fallbackOpacity = options.opacity ?? 0.25;
|
|
810
|
+
const staticColor = fill.color ?? options.staticColor;
|
|
811
|
+
if (fill.color_by !== undefined && fill.color_packed_by !== undefined) {
|
|
812
|
+
throw refusal(sheetId, subject, 'declares color_packed_by beside color_by: a colour reads one ladder');
|
|
813
|
+
}
|
|
814
|
+
if (fill.opacity_by !== undefined && !outputIndex.has(fill.opacity_by)) {
|
|
815
|
+
throw refusal(sheetId, subject, `opacity_by names '${fill.opacity_by}', which is not a declared output`);
|
|
816
|
+
}
|
|
817
|
+
const opacity = (row) => wrunFillRowOpacity(fill, row.outputs, outputIndex, fallbackOpacity);
|
|
818
|
+
const zOrder = zOrderPatch(fill.z, subject, sheetId);
|
|
819
|
+
if (fill.color_packed_by !== undefined) {
|
|
820
|
+
const packedIndex = outputIndex.get(fill.color_packed_by);
|
|
821
|
+
if (packedIndex === undefined) {
|
|
822
|
+
throw refusal(sheetId, subject, `color_packed_by names '${fill.color_packed_by}', which is not a declared output`);
|
|
823
|
+
}
|
|
824
|
+
const colors = [];
|
|
825
|
+
const slots = new Map();
|
|
826
|
+
const slotOf = (color) => {
|
|
827
|
+
let slot = slots.get(color);
|
|
828
|
+
if (slot === undefined) {
|
|
829
|
+
slot = colors.length;
|
|
830
|
+
colors.push(color);
|
|
831
|
+
slots.set(color, slot);
|
|
832
|
+
}
|
|
833
|
+
return slot;
|
|
834
|
+
};
|
|
835
|
+
const data = rows.map((row) => {
|
|
836
|
+
const rung = row.outputs?.[packedIndex];
|
|
837
|
+
const token = typeof rung === 'number' ? wrunThemeTokenOfPacked(rung) : null;
|
|
838
|
+
const color = (token !== null ? wrunThemeTokenWord(token) : decodeWrunPackedColor(rung)) ?? staticColor;
|
|
839
|
+
return [row.ts, color === undefined ? Number.NaN : slotOf(color), opacity(row)];
|
|
840
|
+
});
|
|
841
|
+
return { colors, data, ...zOrder };
|
|
842
|
+
}
|
|
843
|
+
if (fill.color_by !== undefined) {
|
|
844
|
+
if (!Array.isArray(fill.colors) || fill.colors.length < 1) {
|
|
845
|
+
throw refusal(sheetId, subject, 'declares color_by without colors (both or neither)');
|
|
846
|
+
}
|
|
847
|
+
const ladderIndex = outputIndex.get(fill.color_by);
|
|
848
|
+
if (ladderIndex === undefined) {
|
|
849
|
+
throw refusal(sheetId, subject, `color_by names '${fill.color_by}', which is not a declared output`);
|
|
850
|
+
}
|
|
851
|
+
const colors = [...fill.colors];
|
|
852
|
+
const data = rows.map((row) => {
|
|
853
|
+
const rung = row.outputs?.[ladderIndex];
|
|
854
|
+
if (!isFinite(rung))
|
|
855
|
+
return [row.ts, Number.NaN, opacity(row)];
|
|
856
|
+
const slot = Math.floor(rung);
|
|
857
|
+
return [row.ts, slot >= 0 && slot < colors.length ? slot : 0, opacity(row)];
|
|
858
|
+
});
|
|
859
|
+
return { colors, data, ...zOrder };
|
|
860
|
+
}
|
|
861
|
+
if (fill.colors !== undefined)
|
|
862
|
+
throw refusal(sheetId, subject, 'declares colors without color_by (both or neither)');
|
|
863
|
+
return {
|
|
864
|
+
colors: staticColor === undefined ? [] : [staticColor],
|
|
865
|
+
data: rows.map((row) => [row.ts, 0, opacity(row)]),
|
|
866
|
+
...zOrder,
|
|
867
|
+
};
|
|
868
|
+
}
|
|
869
|
+
/** The inset sender settings an inset output's colour words add (OT36):
|
|
870
|
+
* `colors` without `color_by` is the sign pair (`up_color` at or above 0,
|
|
871
|
+
* `down_color` below), `color_by` + `colors` the `palette` each row's
|
|
872
|
+
* ladder slot indexes, `opacity` the strip alpha. `rows` are the run rows
|
|
873
|
+
* (the strip reads every ready row); a `color_by` needs the declared
|
|
874
|
+
* outputs' indexes (`ctx.outputIndexByName`). */
|
|
875
|
+
export function wrunInsetLook(output, rows, ctx = {}) {
|
|
876
|
+
const subject = `output '${output.name}'`;
|
|
877
|
+
const { sheetId } = ctx;
|
|
878
|
+
const settings = {};
|
|
879
|
+
if (output.color_packed_by !== undefined) {
|
|
880
|
+
throw refusal(sheetId, subject, 'an inset output takes no color_packed_by (colors without color_by is its sign pair)');
|
|
881
|
+
}
|
|
882
|
+
if (output.color !== undefined)
|
|
883
|
+
settings.color = output.color;
|
|
884
|
+
if (output.opacity !== undefined) {
|
|
885
|
+
if (!isUnitInterval(output.opacity))
|
|
886
|
+
throw refusal(sheetId, subject, 'opacity must be between 0 and 1');
|
|
887
|
+
settings.opacity = output.opacity;
|
|
888
|
+
}
|
|
889
|
+
if (output.colors !== undefined && (!Array.isArray(output.colors) || !output.colors.every(isColorWord))) {
|
|
890
|
+
throw refusal(sheetId, subject, 'colors must list colours');
|
|
891
|
+
}
|
|
892
|
+
if (output.color_by === undefined) {
|
|
893
|
+
if (output.colors !== undefined && output.colors.length > 0) {
|
|
894
|
+
settings.up_color = output.colors[0];
|
|
895
|
+
settings.down_color = output.colors[1] ?? output.colors[0];
|
|
896
|
+
}
|
|
897
|
+
return { settings };
|
|
898
|
+
}
|
|
899
|
+
if (!Array.isArray(output.colors) || output.colors.length < 1) {
|
|
900
|
+
throw refusal(sheetId, subject, 'color_by needs colors beside it (both or neither)');
|
|
901
|
+
}
|
|
902
|
+
const ladderIndex = ctx.outputIndexByName?.get(output.color_by);
|
|
903
|
+
if (ladderIndex === undefined) {
|
|
904
|
+
throw refusal(sheetId, subject, `color_by '${output.color_by}' does not match a declared output`);
|
|
905
|
+
}
|
|
906
|
+
const palette = [...output.colors];
|
|
907
|
+
settings.palette = palette;
|
|
908
|
+
const data = [];
|
|
909
|
+
for (const row of rows) {
|
|
910
|
+
if (row.outputs === null)
|
|
911
|
+
continue;
|
|
912
|
+
const value = row.outputs[output.index] ?? Number.NaN;
|
|
913
|
+
const rung = row.outputs[ladderIndex];
|
|
914
|
+
if (!isFinite(rung)) {
|
|
915
|
+
data.push([row.ts, value]);
|
|
916
|
+
continue;
|
|
917
|
+
}
|
|
918
|
+
const slot = Math.floor(rung);
|
|
919
|
+
data.push([row.ts, value, slot >= 0 && slot < palette.length ? slot : 0]);
|
|
920
|
+
}
|
|
921
|
+
return { settings, data };
|
|
922
|
+
}
|
|
923
|
+
/** A render.shape `glow` (the frozen sheet contract beside OT16): the
|
|
924
|
+
* plotShape(glow=...) value through the engine's clampGlow, pinned against
|
|
925
|
+
* it: a boolean as declared (`true` is the engine's 12 px), a number of px
|
|
926
|
+
* up to 30 (`landWrunShapeGlowPx`), 0 or a negative no glow (false; a
|
|
927
|
+
* negative refused while the host clamp is off, PLOTS-2); anything else
|
|
928
|
+
* refuses by name. */
|
|
929
|
+
function shapeRendererGlow(glow, subject, sheetId) {
|
|
930
|
+
if (glow === undefined)
|
|
931
|
+
return {};
|
|
932
|
+
if (typeof glow === 'boolean')
|
|
933
|
+
return { glow };
|
|
934
|
+
if (typeof glow !== 'number' || !Number.isFinite(glow)) {
|
|
935
|
+
throw refusal(sheetId, subject, 'glow must be true, false or a number of px');
|
|
936
|
+
}
|
|
937
|
+
if (glow < 0 && wrunGlowClampDisabled)
|
|
938
|
+
throw refusal(sheetId, subject, 'glow must be a number of px >= 0');
|
|
939
|
+
return { glow: landWrunShapeGlowPx(glow) };
|
|
940
|
+
}
|
|
941
|
+
/** The mark look a render.shape declares (D5: OT07 OT16 OT35): placement,
|
|
942
|
+
* glow (through the engine's clamp, `shapeRendererGlow`), the char glyph
|
|
943
|
+
* and its font stack, the hollow (`fill: false`) and faded (`fillOpacity`)
|
|
944
|
+
* interior. `width` is the adapter's own field. */
|
|
945
|
+
export function wrunShapeRendererLook(renderer, sheetId) {
|
|
946
|
+
const subject = `shape renderer '${renderer.name}'`;
|
|
947
|
+
const { glow, ...rest } = renderer;
|
|
948
|
+
return { ...markLook(rest, subject, sheetId), ...shapeRendererGlow(glow, subject, sheetId) };
|
|
949
|
+
}
|
|
950
|
+
/** The vertical-line fields a render.bgcolor declares (OT38): `width` (px,
|
|
951
|
+
* 0.5..10) as `lineWidth`, `line_style` (needs `width`) as `lineStyle`;
|
|
952
|
+
* without them the renderer keeps painting a band. */
|
|
953
|
+
export function wrunBgcolorLineLook(renderer) {
|
|
954
|
+
const subject = `bgcolor renderer '${renderer.name}'`;
|
|
955
|
+
const patch = {};
|
|
956
|
+
if (renderer.width !== undefined) {
|
|
957
|
+
if (!isFinite(renderer.width) ||
|
|
958
|
+
renderer.width < WRUN_MIN_BGCOLOR_LINE_WIDTH_PX ||
|
|
959
|
+
renderer.width > WRUN_MAX_BGCOLOR_LINE_WIDTH_PX) {
|
|
960
|
+
throw refusal(undefined, subject, `width must be between ${WRUN_MIN_BGCOLOR_LINE_WIDTH_PX} and ${WRUN_MAX_BGCOLOR_LINE_WIDTH_PX}`);
|
|
961
|
+
}
|
|
962
|
+
patch.lineWidth = renderer.width;
|
|
963
|
+
}
|
|
964
|
+
if (renderer.line_style !== undefined) {
|
|
965
|
+
if (!isWord(WRUN_LINE_STYLE_WORDS, renderer.line_style)) {
|
|
966
|
+
throw refusal(undefined, subject, `line_style must be one of ${wordList(WRUN_LINE_STYLE_WORDS)}`);
|
|
967
|
+
}
|
|
968
|
+
if (renderer.width === undefined) {
|
|
969
|
+
throw refusal(undefined, subject, 'line_style needs width (the dash applies to the vertical line width draws)');
|
|
970
|
+
}
|
|
971
|
+
patch.lineStyle = renderer.line_style;
|
|
972
|
+
}
|
|
973
|
+
return patch;
|
|
974
|
+
}
|
|
975
|
+
// Panes (OT08 OT18 OT19 OT20 OT24, DW25)
|
|
976
|
+
/** The declared panes of a sheet (`panes[]`), validated: a name, a unique
|
|
977
|
+
* one, a place word, a height share (never on a price-placed pane), the
|
|
978
|
+
* scale words. Absent = none. */
|
|
979
|
+
function readSheetPanes(sheet) {
|
|
980
|
+
const panes = sheet.panes;
|
|
981
|
+
if (panes === undefined)
|
|
982
|
+
return [];
|
|
983
|
+
if (!Array.isArray(panes))
|
|
984
|
+
throw refusal(sheet.id, 'panes', 'must be a list of pane declarations');
|
|
985
|
+
const seen = new Set();
|
|
986
|
+
return panes.map((pane, at) => {
|
|
987
|
+
const name = pane?.name;
|
|
988
|
+
const subject = `pane${typeof name === 'string' ? ` '${name}'` : ` #${at}`}`;
|
|
989
|
+
if (typeof name !== 'string' || name === '')
|
|
990
|
+
throw refusal(sheet.id, subject, 'name must be a name');
|
|
991
|
+
if (seen.has(name))
|
|
992
|
+
throw refusal(sheet.id, subject, `name '${name}' is already declared; pane names are unique`);
|
|
993
|
+
seen.add(name);
|
|
994
|
+
if (pane.place !== undefined && !isWord(WRUN_PANE_PLACES, pane.place)) {
|
|
995
|
+
throw refusal(sheet.id, subject, "place must be 'below' or 'price'");
|
|
996
|
+
}
|
|
997
|
+
if (pane.place === 'price' && name === WRUN_DEFAULT_PANE_NAME) {
|
|
998
|
+
throw refusal(sheet.id, subject, `pane '${WRUN_DEFAULT_PANE_NAME}' is the default pane below the chart; place it below`);
|
|
999
|
+
}
|
|
1000
|
+
if (pane.height_frac !== undefined) {
|
|
1001
|
+
if (!isFinite(pane.height_frac) ||
|
|
1002
|
+
pane.height_frac < WRUN_MIN_PANE_HEIGHT ||
|
|
1003
|
+
pane.height_frac > WRUN_MAX_PANE_HEIGHT) {
|
|
1004
|
+
throw refusal(sheet.id, subject, `height_frac must be between ${WRUN_MIN_PANE_HEIGHT} and ${WRUN_MAX_PANE_HEIGHT}`);
|
|
1005
|
+
}
|
|
1006
|
+
if (pane.place === 'price') {
|
|
1007
|
+
throw refusal(sheet.id, subject, 'height_frac does not apply to a pane placed on price (it draws over the candles)');
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
if (pane.title !== undefined && (typeof pane.title !== 'string' || pane.title === '' || pane.title.length > 40)) {
|
|
1011
|
+
throw refusal(sheet.id, subject, 'title must be 1 to 40 characters');
|
|
1012
|
+
}
|
|
1013
|
+
return pane;
|
|
1014
|
+
});
|
|
1015
|
+
}
|
|
1016
|
+
/** A drawn output: a plot word the visibility table rides on a titan plot family
|
|
1017
|
+
* (wrun-visibility-table.ts wrunOutputPlotRule; a data-only "" and an inset output never mount a
|
|
1018
|
+
* plot of their own), the one reader of the word. */
|
|
1019
|
+
function isDrawnOutput(output) {
|
|
1020
|
+
const rule = wrunOutputPlotRule(output.plot);
|
|
1021
|
+
return rule !== 'not-drawn' && rule.titan !== undefined;
|
|
1022
|
+
}
|
|
1023
|
+
/** The pane an output draws into: its declared `pane`, else the default
|
|
1024
|
+
* lower pane when its panel is `lower`, else undefined (the price pane). */
|
|
1025
|
+
export function wrunPaneOfOutput(output) {
|
|
1026
|
+
if (typeof output.pane === 'string' && output.pane !== '')
|
|
1027
|
+
return output.pane;
|
|
1028
|
+
return output.panel === 'lower' ? WRUN_DEFAULT_PANE_NAME : undefined;
|
|
1029
|
+
}
|
|
1030
|
+
/** The series child's overlay id (`<parent>::series:<pane>`): the default
|
|
1031
|
+
* pane keeps the "lower" child every on-price Indicator always had. */
|
|
1032
|
+
export function wrunPaneChildId(overlayId, pane) {
|
|
1033
|
+
return `${overlayId}::series:${pane}`;
|
|
1034
|
+
}
|
|
1035
|
+
/** The anchor output of a renderer: text / label by `y`, shape and
|
|
1036
|
+
* stats_row by `output`, bgcolor by `where`; a corner label, a table, an
|
|
1037
|
+
* inset and a barcolor anchor on nothing. */
|
|
1038
|
+
function rendererAnchor(renderer) {
|
|
1039
|
+
switch (renderer.kind) {
|
|
1040
|
+
case 'text':
|
|
1041
|
+
case 'label':
|
|
1042
|
+
return renderer.y;
|
|
1043
|
+
case 'shape':
|
|
1044
|
+
case 'stats_row':
|
|
1045
|
+
return renderer.output;
|
|
1046
|
+
case 'bgcolor':
|
|
1047
|
+
return renderer.where;
|
|
1048
|
+
default:
|
|
1049
|
+
return undefined;
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
/** The declared `panel` of a renderer, box or segment (`overlay` pins the
|
|
1053
|
+
* price pane, `lower` the lower pane of its anchor). */
|
|
1054
|
+
function declaredPanel(entry) {
|
|
1055
|
+
const panel = entry?.panel;
|
|
1056
|
+
return typeof panel === 'string' ? panel : undefined;
|
|
1057
|
+
}
|
|
1058
|
+
/** The pane a visual rides, by its declared panel and anchor output (OT08):
|
|
1059
|
+
* `overlay` stays on price; otherwise the anchor's pane (a `lower` panel on
|
|
1060
|
+
* a price anchor takes the default lower pane). Undefined = the parent
|
|
1061
|
+
* (the price pane, or the home pane of an Indicator that homes below). */
|
|
1062
|
+
export function wrunPaneOfVisual(plan, panel, anchor) {
|
|
1063
|
+
if (panel === 'overlay')
|
|
1064
|
+
return undefined;
|
|
1065
|
+
const anchorPane = anchor === undefined ? undefined : plan.outputPane[anchor];
|
|
1066
|
+
const pane = anchorPane ?? (panel === 'lower' ? WRUN_DEFAULT_PANE_NAME : undefined);
|
|
1067
|
+
if (pane === undefined || pane === plan.home)
|
|
1068
|
+
return undefined;
|
|
1069
|
+
return plan.children.some((child) => child.name === pane) ? pane : undefined;
|
|
1070
|
+
}
|
|
1071
|
+
/** The child-pane plan of a sheet (OT08 OT24, DW25): every pane a drawn
|
|
1072
|
+
* output homes in is one series child named by the pane (the default keeps
|
|
1073
|
+
* "lower"), in panes[] order with the undeclared default first; ranges,
|
|
1074
|
+
* fills, boxes, segments and renderers follow their anchor output's pane
|
|
1075
|
+
* and `panel: "lower"` widgets the lower pane (the default pane when drawn
|
|
1076
|
+
* into, else the first pane placed below). `homesBelow` (the result's side
|
|
1077
|
+
* is offchart) keeps the first drawn output's pane on the parent and splits
|
|
1078
|
+
* the others; a sheet that pins `overlay: "onchart"` splits nothing. */
|
|
1079
|
+
export function planWrunPanes(sheet, homesBelow) {
|
|
1080
|
+
const panes = readSheetPanes(sheet);
|
|
1081
|
+
const paneByName = new Map(panes.map((pane) => [pane.name, pane]));
|
|
1082
|
+
const ordered = [...sheet.outputs].sort((a, b) => a.index - b.index);
|
|
1083
|
+
const outputPane = {};
|
|
1084
|
+
const drawnPanes = [];
|
|
1085
|
+
let firstDrawn;
|
|
1086
|
+
for (const output of ordered) {
|
|
1087
|
+
if (!isDrawnOutput(output))
|
|
1088
|
+
continue;
|
|
1089
|
+
firstDrawn ??= output;
|
|
1090
|
+
const pane = wrunPaneOfOutput(output);
|
|
1091
|
+
if (pane === undefined)
|
|
1092
|
+
continue;
|
|
1093
|
+
outputPane[output.name] = pane;
|
|
1094
|
+
if (!drawnPanes.includes(pane))
|
|
1095
|
+
drawnPanes.push(pane);
|
|
1096
|
+
}
|
|
1097
|
+
const home = homesBelow && firstDrawn !== undefined ? wrunPaneOfOutput(firstDrawn) : undefined;
|
|
1098
|
+
const names = [];
|
|
1099
|
+
if (sheet.overlay !== 'onchart') {
|
|
1100
|
+
const candidates = [
|
|
1101
|
+
...(!paneByName.has(WRUN_DEFAULT_PANE_NAME) && drawnPanes.includes(WRUN_DEFAULT_PANE_NAME)
|
|
1102
|
+
? [WRUN_DEFAULT_PANE_NAME]
|
|
1103
|
+
: []),
|
|
1104
|
+
...panes.map((pane) => pane.name).filter((name) => drawnPanes.includes(name)),
|
|
1105
|
+
...drawnPanes,
|
|
1106
|
+
];
|
|
1107
|
+
for (const name of candidates) {
|
|
1108
|
+
if (name !== home && !names.includes(name))
|
|
1109
|
+
names.push(name);
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
const children = names.map((name) => {
|
|
1113
|
+
const declaration = paneByName.get(name);
|
|
1114
|
+
return {
|
|
1115
|
+
name,
|
|
1116
|
+
place: declaration?.place === 'price' ? 'price' : 'below',
|
|
1117
|
+
...(declaration !== undefined ? { declaration } : {}),
|
|
1118
|
+
...(declaration?.title !== undefined ? { title: declaration.title } : {}),
|
|
1119
|
+
...(declaration?.height_frac !== undefined ? { height: declaration.height_frac } : {}),
|
|
1120
|
+
outputs: ordered.filter((output) => isDrawnOutput(output) && outputPane[output.name] === name).map((o) => o.name),
|
|
1121
|
+
ranges: [],
|
|
1122
|
+
fills: [],
|
|
1123
|
+
boxes: [],
|
|
1124
|
+
segments: [],
|
|
1125
|
+
renderers: [],
|
|
1126
|
+
drawings: [],
|
|
1127
|
+
};
|
|
1128
|
+
});
|
|
1129
|
+
const plan = { ...(home !== undefined ? { home } : {}), children, outputPane };
|
|
1130
|
+
const childOf = (panel, anchor) => {
|
|
1131
|
+
const pane = wrunPaneOfVisual(plan, panel, anchor);
|
|
1132
|
+
return pane === undefined ? undefined : children.find((child) => child.name === pane);
|
|
1133
|
+
};
|
|
1134
|
+
(sheet.ranges ?? []).forEach((range, at) => childOf(undefined, range.upper)?.ranges.push(at));
|
|
1135
|
+
(sheet.fills ?? []).forEach((fill, at) => childOf(undefined, fill.between?.[0])?.fills.push(at));
|
|
1136
|
+
// The sheet type leaves boxes and segments untyped on purpose (their reader
|
|
1137
|
+
// refuses a bad field by name): only their names and anchors are read here.
|
|
1138
|
+
const { boxes, segments } = sheet;
|
|
1139
|
+
for (const box of boxes ?? [])
|
|
1140
|
+
childOf(declaredPanel(box), box.top)?.boxes.push(box.name);
|
|
1141
|
+
for (const segment of segments ?? [])
|
|
1142
|
+
childOf(declaredPanel(segment), segment.y_from)?.segments.push(segment.name);
|
|
1143
|
+
for (const renderer of sheet.renderers ?? []) {
|
|
1144
|
+
const anchor = rendererAnchor(renderer);
|
|
1145
|
+
if (anchor === undefined)
|
|
1146
|
+
continue;
|
|
1147
|
+
childOf(declaredPanel(renderer), anchor)?.renderers.push(renderer.name);
|
|
1148
|
+
}
|
|
1149
|
+
// DW25: a widget's "lower" pane is the Indicator's lower pane: the default
|
|
1150
|
+
// pane when it is a child, else the first child placed below the chart.
|
|
1151
|
+
const widgetPane = children.find((child) => child.name === WRUN_DEFAULT_PANE_NAME) ??
|
|
1152
|
+
children.find((child) => child.place === 'below');
|
|
1153
|
+
(sheet.drawings ?? []).forEach((drawing, at) => {
|
|
1154
|
+
const kind = drawing.kind;
|
|
1155
|
+
if (typeof kind !== 'string' || !WRUN_LOWER_PANE_WIDGET_KINDS.has(kind))
|
|
1156
|
+
return;
|
|
1157
|
+
if (declaredPanel(drawing) === 'lower')
|
|
1158
|
+
widgetPane?.drawings.push(at);
|
|
1159
|
+
});
|
|
1160
|
+
return plan;
|
|
1161
|
+
}
|
|
1162
|
+
/** The declared height share (`height_frac`) of the pane holding a sheet's
|
|
1163
|
+
* first drawn output, when that output sits below the chart (OT20): what a
|
|
1164
|
+
* NEW add of an Indicator that homes below mounts as its `gridHeight`.
|
|
1165
|
+
* Undefined when the first drawn output is on price, the pane is not
|
|
1166
|
+
* declared or declares no height. */
|
|
1167
|
+
export function wrunHomePaneHeight(sheet) {
|
|
1168
|
+
const first = [...sheet.outputs].sort((a, b) => a.index - b.index).find(isDrawnOutput);
|
|
1169
|
+
const pane = first === undefined ? undefined : wrunPaneOfOutput(first);
|
|
1170
|
+
if (pane === undefined)
|
|
1171
|
+
return undefined;
|
|
1172
|
+
return readSheetPanes(sheet).find((declared) => declared.name === pane)?.height_frac;
|
|
1173
|
+
}
|
|
1174
|
+
/** A declared pane's define (OT18 OT19): `pane` is the scale look the engine
|
|
1175
|
+
* applies (value mode, inversion, padding, held ends), always present for a
|
|
1176
|
+
* declared pane; `paneAxis` the axis tick format (app-only, read by the
|
|
1177
|
+
* pane formatter) only when the pane declares format words. */
|
|
1178
|
+
export function wrunPaneDefine(pane) {
|
|
1179
|
+
const subject = `pane '${pane.name}'`;
|
|
1180
|
+
if (pane.scale !== undefined && !isWord(WRUN_PANE_SCALES, pane.scale)) {
|
|
1181
|
+
throw refusal(undefined, subject, `scale must be one of ${wordList(WRUN_PANE_SCALES)}`);
|
|
1182
|
+
}
|
|
1183
|
+
if (pane.invert !== undefined && typeof pane.invert !== 'boolean') {
|
|
1184
|
+
throw refusal(undefined, subject, 'invert must be true or false');
|
|
1185
|
+
}
|
|
1186
|
+
if (pane.padding !== undefined) {
|
|
1187
|
+
const padding = pane.padding;
|
|
1188
|
+
if (!Array.isArray(padding) ||
|
|
1189
|
+
padding.length !== 2 ||
|
|
1190
|
+
!padding.every((entry) => isFinite(entry) && entry >= 0 && entry <= WRUN_MAX_PANE_PADDING)) {
|
|
1191
|
+
throw refusal(undefined, subject, `padding must be [top, bottom], each between 0 and ${WRUN_MAX_PANE_PADDING}`);
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1194
|
+
for (const key of ['min', 'max']) {
|
|
1195
|
+
if (pane[key] !== undefined && !isFinite(pane[key]))
|
|
1196
|
+
throw refusal(undefined, subject, `${key} must be a finite number`);
|
|
1197
|
+
}
|
|
1198
|
+
if (pane.min !== undefined && pane.max !== undefined && pane.min >= pane.max) {
|
|
1199
|
+
throw refusal(undefined, subject, 'min must be less than max');
|
|
1200
|
+
}
|
|
1201
|
+
if (pane.scale === 'log' && pane.min !== undefined && pane.min <= 0) {
|
|
1202
|
+
throw refusal(undefined, subject, 'a log scale needs min above 0');
|
|
1203
|
+
}
|
|
1204
|
+
const scale = {
|
|
1205
|
+
valueMode: WRUN_PANE_VALUE_MODES[pane.scale ?? 'linear'],
|
|
1206
|
+
invertScale: pane.invert === true,
|
|
1207
|
+
...(pane.padding !== undefined
|
|
1208
|
+
? { verticalPaddingTop: pane.padding[0], verticalPaddingBottom: pane.padding[1] }
|
|
1209
|
+
: {}),
|
|
1210
|
+
...(pane.min !== undefined ? { fixedLow: pane.min } : {}),
|
|
1211
|
+
...(pane.max !== undefined ? { fixedHigh: pane.max } : {}),
|
|
1212
|
+
};
|
|
1213
|
+
if (pane.format !== undefined && !isWord(WRUN_VALUE_FORMATS, pane.format)) {
|
|
1214
|
+
throw refusal(undefined, subject, `format must be one of ${wordList(WRUN_VALUE_FORMATS)}`);
|
|
1215
|
+
}
|
|
1216
|
+
const options = readFormatOptions(pane, subject, undefined, false);
|
|
1217
|
+
const paneAxis = pane.format === undefined ? undefined : { format: pane.format, ...(options ?? {}) };
|
|
1218
|
+
return { pane: scale, ...(paneAxis !== undefined ? { paneAxis } : {}) };
|
|
1219
|
+
}
|
|
1220
|
+
/** The engine settings a series child takes from its pane (OT20 OT24): a
|
|
1221
|
+
* pane placed on price mounts pinned over the candles on its own hidden
|
|
1222
|
+
* scale (the pinned onchart flags, no main-pane fold); a pane below the
|
|
1223
|
+
* chart carries its declared height share as `gridHeight` (absent = the
|
|
1224
|
+
* mount's default share). Takes the child's pane info or a declaration. */
|
|
1225
|
+
export function wrunPaneChildMountSettings(pane) {
|
|
1226
|
+
if (pane?.place === 'price') {
|
|
1227
|
+
return {
|
|
1228
|
+
isPinnedToChart: true,
|
|
1229
|
+
showIndependentYAxis: true,
|
|
1230
|
+
isIndependentSubsetRange: true,
|
|
1231
|
+
hidePriceScale: true,
|
|
1232
|
+
shouldAdjustMainGridRange: false,
|
|
1233
|
+
};
|
|
1234
|
+
}
|
|
1235
|
+
const height = pane?.height ?? pane?.height_frac;
|
|
1236
|
+
return isFinite(height) && height >= WRUN_MIN_PANE_HEIGHT && height <= WRUN_MAX_PANE_HEIGHT
|
|
1237
|
+
? { gridHeight: height }
|
|
1238
|
+
: {};
|
|
1239
|
+
}
|