@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.
Files changed (198) hide show
  1. package/README.md +72 -0
  2. package/dist/constants/governed-exchanges.constants.d.ts +11 -0
  3. package/dist/constants/governed-exchanges.constants.js +11 -0
  4. package/dist/constants/indicator-sets.constants.d.ts +8 -0
  5. package/dist/constants/indicator-sets.constants.js +8 -0
  6. package/dist/constants/interval.constants.d.ts +34 -0
  7. package/dist/constants/interval.constants.js +121 -0
  8. package/dist/constants/scriptEditor/technicalIndicatorScriptKeys.constants.d.ts +28 -0
  9. package/dist/constants/scriptEditor/technicalIndicatorScriptKeys.constants.js +65 -0
  10. package/dist/constants/tpo-color-schemes.constants.d.ts +30 -0
  11. package/dist/constants/tpo-color-schemes.constants.js +32 -0
  12. package/dist/host-env.d.ts +102 -0
  13. package/dist/host-env.js +26 -0
  14. package/dist/index.d.ts +93 -0
  15. package/dist/index.js +96 -0
  16. package/dist/indicators/controls/tpo-letter.util.d.ts +2 -0
  17. package/dist/indicators/controls/tpo-letter.util.js +13 -0
  18. package/dist/indicators/controls/tpo-session.util.d.ts +99 -0
  19. package/dist/indicators/controls/tpo-session.util.js +389 -0
  20. package/dist/interfaces/kscript-diagnostics.interface.d.ts +64 -0
  21. package/dist/interfaces/kscript-diagnostics.interface.js +1 -0
  22. package/dist/interfaces/om-panel-data.interface.d.ts +103 -0
  23. package/dist/interfaces/om-panel-data.interface.js +7 -0
  24. package/dist/interfaces/wrun-runtime.interface.d.ts +2659 -0
  25. package/dist/interfaces/wrun-runtime.interface.js +55 -0
  26. package/dist/utility/chart/calendar-interval.util.d.ts +24 -0
  27. package/dist/utility/chart/calendar-interval.util.js +81 -0
  28. package/dist/utility/chart/candle-bar-end.util.d.ts +15 -0
  29. package/dist/utility/chart/candle-bar-end.util.js +23 -0
  30. package/dist/utility/chart/cme-realtime.util.d.ts +24 -0
  31. package/dist/utility/chart/cme-realtime.util.js +53 -0
  32. package/dist/utility/chart/interval-ladder.util.d.ts +27 -0
  33. package/dist/utility/chart/interval-ladder.util.js +92 -0
  34. package/dist/utility/chart/kscript-drawing-prep.util.d.ts +40 -0
  35. package/dist/utility/chart/kscript-drawing-prep.util.js +184 -0
  36. package/dist/utility/chart/kscript-drawing-safe-area.util.d.ts +95 -0
  37. package/dist/utility/chart/kscript-drawing-safe-area.util.js +805 -0
  38. package/dist/utility/chart/kscript-legend-entries.util.d.ts +166 -0
  39. package/dist/utility/chart/kscript-legend-entries.util.js +538 -0
  40. package/dist/utility/chart/kscript-output-role.util.d.ts +32 -0
  41. package/dist/utility/chart/kscript-output-role.util.js +215 -0
  42. package/dist/utility/chart/kscript-provenance-keys.util.d.ts +22 -0
  43. package/dist/utility/chart/kscript-provenance-keys.util.js +56 -0
  44. package/dist/utility/chart/kscript-run-result-normalize.util.d.ts +53 -0
  45. package/dist/utility/chart/kscript-run-result-normalize.util.js +476 -0
  46. package/dist/utility/chart/kscript-run-result-shape.util.d.ts +14 -0
  47. package/dist/utility/chart/kscript-run-result-shape.util.js +66 -0
  48. package/dist/utility/chart/kscript-titancharts-container.util.d.ts +29 -0
  49. package/dist/utility/chart/kscript-titancharts-container.util.js +151 -0
  50. package/dist/utility/chart/kscript-viewport-overlays.util.d.ts +83 -0
  51. package/dist/utility/chart/kscript-viewport-overlays.util.js +443 -0
  52. package/dist/utility/chart/om-panel-push-style.util.d.ts +78 -0
  53. package/dist/utility/chart/om-panel-push-style.util.js +301 -0
  54. package/dist/utility/chart/om-panel.util.d.ts +166 -0
  55. package/dist/utility/chart/om-panel.util.js +815 -0
  56. package/dist/utility/chart/om-series.util.d.ts +42 -0
  57. package/dist/utility/chart/om-series.util.js +330 -0
  58. package/dist/utility/chart/om-target.util.d.ts +11 -0
  59. package/dist/utility/chart/om-target.util.js +24 -0
  60. package/dist/utility/chart/om-widget.util.d.ts +148 -0
  61. package/dist/utility/chart/om-widget.util.js +413 -0
  62. package/dist/utility/chart/overlay-output-budget.util.d.ts +16 -0
  63. package/dist/utility/chart/overlay-output-budget.util.js +109 -0
  64. package/dist/utility/chart/overlay-paint-flags.util.d.ts +24 -0
  65. package/dist/utility/chart/overlay-paint-flags.util.js +55 -0
  66. package/dist/utility/chart/profile-row-height.util.d.ts +21 -0
  67. package/dist/utility/chart/profile-row-height.util.js +110 -0
  68. package/dist/utility/chart/session-interval.util.d.ts +1 -0
  69. package/dist/utility/chart/session-interval.util.js +35 -0
  70. package/dist/utility/chart/technical-script-legend-value.util.d.ts +18 -0
  71. package/dist/utility/chart/technical-script-legend-value.util.js +53 -0
  72. package/dist/utility/chart/trading-day.util.d.ts +70 -0
  73. package/dist/utility/chart/trading-day.util.js +238 -0
  74. package/dist/utility/chart/wrun-legend-name.util.d.ts +25 -0
  75. package/dist/utility/chart/wrun-legend-name.util.js +87 -0
  76. package/dist/utility/chart/wrun-run-result.util.d.ts +977 -0
  77. package/dist/utility/chart/wrun-run-result.util.js +5179 -0
  78. package/dist/utility/chart/wrun-visibility-chart.util.d.ts +25 -0
  79. package/dist/utility/chart/wrun-visibility-chart.util.js +22 -0
  80. package/dist/utility/indicators/heatmap-sensitivity.util.d.ts +62 -0
  81. package/dist/utility/indicators/heatmap-sensitivity.util.js +82 -0
  82. package/dist/utility/number-format.util.d.ts +68 -0
  83. package/dist/utility/number-format.util.js +188 -0
  84. package/dist/utility/v2/opra-governed.util.d.ts +1 -0
  85. package/dist/utility/v2/opra-governed.util.js +13 -0
  86. package/dist/utility/wrun/wrun-auto-row.util.d.ts +54 -0
  87. package/dist/utility/wrun/wrun-auto-row.util.js +96 -0
  88. package/dist/utility/wrun/wrun-batched-marks.util.d.ts +341 -0
  89. package/dist/utility/wrun/wrun-batched-marks.util.js +938 -0
  90. package/dist/utility/wrun/wrun-batched-readout.util.d.ts +75 -0
  91. package/dist/utility/wrun/wrun-batched-readout.util.js +171 -0
  92. package/dist/utility/wrun/wrun-box-segment.util.d.ts +185 -0
  93. package/dist/utility/wrun/wrun-box-segment.util.js +570 -0
  94. package/dist/utility/wrun/wrun-build-memo.util.d.ts +133 -0
  95. package/dist/utility/wrun/wrun-build-memo.util.js +301 -0
  96. package/dist/utility/wrun/wrun-builtin-twin-ports.util.d.ts +25 -0
  97. package/dist/utility/wrun/wrun-builtin-twin-ports.util.js +75 -0
  98. package/dist/utility/wrun/wrun-builtin-twin.util.d.ts +9 -0
  99. package/dist/utility/wrun/wrun-builtin-twin.util.js +40 -0
  100. package/dist/utility/wrun/wrun-canvas-cache.util.d.ts +28 -0
  101. package/dist/utility/wrun/wrun-canvas-cache.util.js +56 -0
  102. package/dist/utility/wrun/wrun-canvas-readout.util.d.ts +69 -0
  103. package/dist/utility/wrun/wrun-canvas-readout.util.js +53 -0
  104. package/dist/utility/wrun/wrun-canvases.util.d.ts +295 -0
  105. package/dist/utility/wrun/wrun-canvases.util.js +1432 -0
  106. package/dist/utility/wrun/wrun-cap-notice.util.d.ts +77 -0
  107. package/dist/utility/wrun/wrun-cap-notice.util.js +296 -0
  108. package/dist/utility/wrun/wrun-card-style.util.d.ts +154 -0
  109. package/dist/utility/wrun/wrun-card-style.util.js +539 -0
  110. package/dist/utility/wrun/wrun-chart-context.util.d.ts +89 -0
  111. package/dist/utility/wrun/wrun-chart-context.util.js +213 -0
  112. package/dist/utility/wrun/wrun-chart-names.util.d.ts +23 -0
  113. package/dist/utility/wrun/wrun-chart-names.util.js +33 -0
  114. package/dist/utility/wrun/wrun-chart-time.util.d.ts +12 -0
  115. package/dist/utility/wrun/wrun-chart-time.util.js +23 -0
  116. package/dist/utility/wrun/wrun-child-overlay-id.util.d.ts +13 -0
  117. package/dist/utility/wrun/wrun-child-overlay-id.util.js +44 -0
  118. package/dist/utility/wrun/wrun-color-facts.util.d.ts +40 -0
  119. package/dist/utility/wrun/wrun-color-facts.util.js +88 -0
  120. package/dist/utility/wrun/wrun-color-settings.lazy.d.ts +26 -0
  121. package/dist/utility/wrun/wrun-color-settings.lazy.js +9 -0
  122. package/dist/utility/wrun/wrun-color-settings.util.d.ts +351 -0
  123. package/dist/utility/wrun/wrun-color-settings.util.js +1363 -0
  124. package/dist/utility/wrun/wrun-footprint-modes.util.d.ts +23 -0
  125. package/dist/utility/wrun/wrun-footprint-modes.util.js +24 -0
  126. package/dist/utility/wrun/wrun-frames.d.ts +217 -0
  127. package/dist/utility/wrun/wrun-frames.js +1021 -0
  128. package/dist/utility/wrun/wrun-handles.util.d.ts +792 -0
  129. package/dist/utility/wrun/wrun-handles.util.js +2050 -0
  130. package/dist/utility/wrun/wrun-heatmap-cell-budget.util.d.ts +156 -0
  131. package/dist/utility/wrun/wrun-heatmap-cell-budget.util.js +342 -0
  132. package/dist/utility/wrun/wrun-hosted-wire-caps.d.ts +218 -0
  133. package/dist/utility/wrun/wrun-hosted-wire-caps.js +667 -0
  134. package/dist/utility/wrun/wrun-hosted-wire.util.d.ts +40 -0
  135. package/dist/utility/wrun/wrun-hosted-wire.util.js +27 -0
  136. package/dist/utility/wrun/wrun-hover.util.d.ts +182 -0
  137. package/dist/utility/wrun/wrun-hover.util.js +534 -0
  138. package/dist/utility/wrun/wrun-hud-looks.util.d.ts +246 -0
  139. package/dist/utility/wrun/wrun-hud-looks.util.js +587 -0
  140. package/dist/utility/wrun/wrun-integration-budget.util.d.ts +47 -0
  141. package/dist/utility/wrun/wrun-integration-budget.util.js +122 -0
  142. package/dist/utility/wrun/wrun-latest-snapshot.d.ts +19 -0
  143. package/dist/utility/wrun/wrun-latest-snapshot.js +7 -0
  144. package/dist/utility/wrun/wrun-levels-child.util.d.ts +131 -0
  145. package/dist/utility/wrun/wrun-levels-child.util.js +514 -0
  146. package/dist/utility/wrun/wrun-lifecycle.contract.d.ts +75 -0
  147. package/dist/utility/wrun/wrun-lifecycle.contract.js +9 -0
  148. package/dist/utility/wrun/wrun-market-facts.util.d.ts +116 -0
  149. package/dist/utility/wrun/wrun-market-facts.util.js +238 -0
  150. package/dist/utility/wrun/wrun-output-style.util.d.ts +344 -0
  151. package/dist/utility/wrun/wrun-output-style.util.js +1239 -0
  152. package/dist/utility/wrun/wrun-overlay-identity.util.d.ts +84 -0
  153. package/dist/utility/wrun/wrun-overlay-identity.util.js +142 -0
  154. package/dist/utility/wrun/wrun-overlay-result.util.d.ts +120 -0
  155. package/dist/utility/wrun/wrun-overlay-result.util.js +219 -0
  156. package/dist/utility/wrun/wrun-pack.util.d.ts +70 -0
  157. package/dist/utility/wrun/wrun-pack.util.js +301 -0
  158. package/dist/utility/wrun/wrun-pane-format.util.d.ts +180 -0
  159. package/dist/utility/wrun/wrun-pane-format.util.js +299 -0
  160. package/dist/utility/wrun/wrun-panel-style.lazy.d.ts +25 -0
  161. package/dist/utility/wrun/wrun-panel-style.lazy.js +15 -0
  162. package/dist/utility/wrun/wrun-panel-style.util.d.ts +174 -0
  163. package/dist/utility/wrun/wrun-panel-style.util.js +726 -0
  164. package/dist/utility/wrun/wrun-param-values.util.d.ts +69 -0
  165. package/dist/utility/wrun/wrun-param-values.util.js +230 -0
  166. package/dist/utility/wrun/wrun-refusal.util.d.ts +263 -0
  167. package/dist/utility/wrun/wrun-refusal.util.js +1259 -0
  168. package/dist/utility/wrun/wrun-registry-errors.util.d.ts +199 -0
  169. package/dist/utility/wrun/wrun-registry-errors.util.js +257 -0
  170. package/dist/utility/wrun/wrun-render-select.util.d.ts +336 -0
  171. package/dist/utility/wrun/wrun-render-select.util.js +1157 -0
  172. package/dist/utility/wrun/wrun-script-inputs.util.d.ts +434 -0
  173. package/dist/utility/wrun/wrun-script-inputs.util.js +1971 -0
  174. package/dist/utility/wrun/wrun-setting-words.lazy.d.ts +20 -0
  175. package/dist/utility/wrun/wrun-setting-words.lazy.js +9 -0
  176. package/dist/utility/wrun/wrun-setting-words.util.d.ts +79 -0
  177. package/dist/utility/wrun/wrun-setting-words.util.js +176 -0
  178. package/dist/utility/wrun/wrun-socket-row-store.d.ts +98 -0
  179. package/dist/utility/wrun/wrun-socket-row-store.js +417 -0
  180. package/dist/utility/wrun/wrun-style-flags.util.d.ts +18 -0
  181. package/dist/utility/wrun/wrun-style-flags.util.js +21 -0
  182. package/dist/utility/wrun/wrun-style-words.util.d.ts +148 -0
  183. package/dist/utility/wrun/wrun-style-words.util.js +439 -0
  184. package/dist/utility/wrun/wrun-table-look.util.d.ts +125 -0
  185. package/dist/utility/wrun/wrun-table-look.util.js +225 -0
  186. package/dist/utility/wrun/wrun-text-look.util.d.ts +51 -0
  187. package/dist/utility/wrun/wrun-text-look.util.js +227 -0
  188. package/dist/utility/wrun/wrun-text-params.util.d.ts +106 -0
  189. package/dist/utility/wrun/wrun-text-params.util.js +171 -0
  190. package/dist/utility/wrun/wrun-tpo-rows.util.d.ts +71 -0
  191. package/dist/utility/wrun/wrun-tpo-rows.util.js +438 -0
  192. package/dist/utility/wrun/wrun-twin-compute-inputs.util.d.ts +14 -0
  193. package/dist/utility/wrun/wrun-twin-compute-inputs.util.js +58 -0
  194. package/dist/utility/wrun/wrun-visibility-table.d.ts +437 -0
  195. package/dist/utility/wrun/wrun-visibility-table.js +237 -0
  196. package/dist/utility/wrun/wrun-volume-profile.util.d.ts +37 -0
  197. package/dist/utility/wrun/wrun-volume-profile.util.js +278 -0
  198. package/package.json +38 -0
@@ -0,0 +1,726 @@
1
+ /**
2
+ * WRUN-STYLE g1 (SC02 SC03 SC04 SC06 SC07 SC08 SC16 SC18 SC19 SC20 SC21 SC22
3
+ * SC23 SC24 SC25 SC26 SC28 SC29 SC30 SC32 SC33 SC34 SC39): the style words of
4
+ * a wrun panel (`panels[i]`, `panels[i].series[j]` and the per-run frame
5
+ * chrome beside `rows`) mapped onto the engine's pane settings. One mapper per
6
+ * pane kind plus the words every kind shares; each returns a PATCH that
7
+ * `translatePanelToEngine` (om-panel.util, F-PANELS) merges shallowly into the
8
+ * settings it built from the structural words, a `series` array patch merging
9
+ * per index. A frame field overrides the declared word of the same name for
10
+ * that run; `markers` replaces the declared list. Absent words add no key, so
11
+ * today's drawing stays the default (conventions 10).
12
+ *
13
+ * Pure and worker safe (om-panel.util rides the frame worker): it imports the
14
+ * style foundation only. Colour words resolve here against `ctx.theme`
15
+ * (`wrunPaneColor`: a theme token becomes the chart's palette colour and an
16
+ * `#rrggbbaa` word the `rgba(r, g, b, a)` text the domain panes can read,
17
+ * SC16); the push lane passes no theme and its `#rrggbb` colours pass through
18
+ * unchanged. Font words resolve to CSS stacks (X14). Ranges are checked before
19
+ * a frame gets here (a wrun sheet by the kit, a push frame by the panel parse,
20
+ * om-panel-push-style.util), so nothing here refuses.
21
+ */
22
+ import { formatWrunNumber, resolveWrunColorWord, wrunFontFamilyCss, wrunFontWeightCss, wrunHex8ToRgba, } from './wrun-style-words.util.js';
23
+ import { bindWrunPanelStyle } from './wrun-panel-style.lazy.js';
24
+ // The word lists (g1 section 2), pinned to the F-TYPES sheet types: a key the
25
+ // interface gains and this table lacks (or the reverse) fails to compile.
26
+ const WRUN_PANEL_STYLE_WORDS = {
27
+ height_frac: true,
28
+ maximize: true,
29
+ stats_row: true,
30
+ font_family: true,
31
+ hover_card: true,
32
+ chrome: true,
33
+ format: true,
34
+ decimals: true,
35
+ signed: true,
36
+ unit: true,
37
+ x_format: true,
38
+ x_decimals: true,
39
+ x_unit: true,
40
+ x_title: true,
41
+ y_title: true,
42
+ x_min: true,
43
+ x_max: true,
44
+ y_min: true,
45
+ y_max: true,
46
+ y_zero: true,
47
+ legend_style: true,
48
+ legend_latest: true,
49
+ positive_color: true,
50
+ negative_color: true,
51
+ smooth: true,
52
+ points: true,
53
+ glow: true,
54
+ animate: true,
55
+ fill_mode: true,
56
+ fill_positive_color: true,
57
+ fill_negative_color: true,
58
+ fill_fade: true,
59
+ stroke_fade: true,
60
+ markers: true,
61
+ badge: true,
62
+ bar_width: true,
63
+ bar_radius: true,
64
+ color_mode: true,
65
+ color: true,
66
+ guides: true,
67
+ quadrants: true,
68
+ trails: true,
69
+ trail_width: true,
70
+ trail_fade: true,
71
+ label_overlap: true,
72
+ hole_total: true,
73
+ hole_caption: true,
74
+ slice_gap: true,
75
+ border_color: true,
76
+ border_width: true,
77
+ scale: true,
78
+ palette: true,
79
+ min: true,
80
+ max: true,
81
+ highlight: true,
82
+ row_title: true,
83
+ col_title: true,
84
+ columns: true,
85
+ accent: true,
86
+ position: true,
87
+ offset: true,
88
+ width: true,
89
+ column_widths: true,
90
+ cell_padding: true,
91
+ font_size: true,
92
+ font_weight: true,
93
+ align: true,
94
+ valign: true,
95
+ text_color: true,
96
+ header_text_color: true,
97
+ background_color: true,
98
+ background_opacity: true,
99
+ background_gradient: true,
100
+ gradient_direction: true,
101
+ header_background_color: true,
102
+ border_style: true,
103
+ grid_color: true,
104
+ grid_width: true,
105
+ grid_style: true,
106
+ grid_lines: true,
107
+ header_column: true,
108
+ width_px: true,
109
+ height_px: true,
110
+ };
111
+ const WRUN_PANEL_SERIES_STYLE_WORDS = {
112
+ fill: true,
113
+ fill_color: true,
114
+ style: true,
115
+ smooth: true,
116
+ points: true,
117
+ labels: true,
118
+ width: true,
119
+ line_style: true,
120
+ legend: true,
121
+ align: true,
122
+ format: true,
123
+ decimals: true,
124
+ signed: true,
125
+ unit: true,
126
+ };
127
+ /** Every `panels[i]` style word a wrun declaration may carry (g1 section 2
128
+ * plus the g6 side-strip sizes), in the contract's order. */
129
+ export const WRUN_PANEL_STYLE_KEYS = Object.keys(WRUN_PANEL_STYLE_WORDS);
130
+ /** Every `panels[i].series[j]` style word. */
131
+ export const WRUN_PANEL_SERIES_STYLE_KEYS = Object.keys(WRUN_PANEL_SERIES_STYLE_WORDS);
132
+ /** Today's heatmap palette (the engine's three-stop default), used under
133
+ * scale "palette" when the panel declares none (SC06). */
134
+ export const WRUN_PANEL_HEATMAP_PALETTE = ['#e06c75', '#7a7f93', '#98c379'];
135
+ /** The default `stroke_fade.edge_opacity` (SC03; the engine's own default). */
136
+ export const WRUN_PANEL_STROKE_FADE_EDGE_OPACITY = 0.35;
137
+ /** The badge chip's defaults (C2): the fill when `color` is absent, and the
138
+ * two inks `text_color` falls back to, picked by the fill's luminance. */
139
+ export const WRUN_PANEL_BADGE_DEFAULT_COLOR = 'theme.accent';
140
+ export const WRUN_PANEL_BADGE_LIGHT_INK = '#f4f4f4';
141
+ export const WRUN_PANEL_BADGE_DARK_INK = '#0b0d12';
142
+ /** The luminance above which the dark ink reads better: the app's
143
+ * ink-on-fill cut (hl-theme-tokens.util), which keeps light ink on the
144
+ * saturated mid tones an accent usually is. */
145
+ const WRUN_PANEL_BADGE_INK_CUT = 0.4;
146
+ /** A table anchored at a top_* position starts under the pane's legend pill
147
+ * row (SC22): the same 24 px om-panel.util's `PANEL_TABLE_TOP_OFFSET_PX`
148
+ * gives the default anchor (pinned equal by the spec; restated here so this
149
+ * module never imports its own caller). */
150
+ export const WRUN_PANEL_TABLE_TOP_OFFSET_PX = 24;
151
+ /** What the formatter answers for a number whose words are not declared:
152
+ * the engine prints its own text for a non-string result (titan
153
+ * curveLayout `safeDomainFormat`, panelLayout `safeFormat`, tilesLayout
154
+ * `hostFormatted`), which is how "absent words keep today's engine
155
+ * formatting" reaches a role, tile or column with no words of its own
156
+ * (SC08). The frozen hook type is `string`, so the hole is typed once,
157
+ * here. */
158
+ const WRUN_ENGINE_FORMATTING = undefined;
159
+ /** Resolves a panel colour word for the domain panes (SC16): a theme token
160
+ * becomes the palette colour (alpha = palette alpha x token alpha), then an
161
+ * `#rrggbbaa` word becomes `rgba(r, g, b, a)` because the panes parse
162
+ * rgba() but not 8-digit hex. Without a theme (the push lane) a token and a
163
+ * 6-digit hex pass through unchanged. */
164
+ export function wrunPaneColor(word, theme) {
165
+ return wrunHex8ToRgba(theme === undefined ? word : resolveWrunColorWord(word, theme));
166
+ }
167
+ /** A panel's effective chrome (SC02): the declared word, else "grid" for an
168
+ * unstacked line with x "index" or "number" (today's rich curve), else
169
+ * "box" (today's panel look). */
170
+ export function wrunPanelChrome(panel) {
171
+ if (panel.chrome !== undefined)
172
+ return panel.chrome;
173
+ const numeric = panel.x === 'index' || panel.x === 'number';
174
+ return panel.kind === 'line' && numeric && panel.stacked !== true ? 'grid' : 'box';
175
+ }
176
+ // Helpers
177
+ /** Writes `key` only when the word is declared. */
178
+ function put(patch, key, value) {
179
+ if (value !== undefined)
180
+ patch[key] = value;
181
+ }
182
+ /** A frame field ahead of the declared word of the same name (SC17). */
183
+ function frameFirst(panel, chrome, key) {
184
+ const fromFrame = chrome?.[key];
185
+ return fromFrame !== undefined ? fromFrame : panel[key];
186
+ }
187
+ /** The r, g, b bytes of a colour as the panes read it (`#rgb`, `#rrggbb`,
188
+ * `#rrggbbaa`, `rgb()` or `rgba()`, the forms wrunPaneColor answers);
189
+ * undefined for anything else. */
190
+ function paneColorChannels(color) {
191
+ const text = color.trim();
192
+ const hex = /^#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.exec(text);
193
+ if (hex !== null) {
194
+ const digits = hex[1].length === 3 ? [...hex[1]].map((digit) => digit + digit).join('') : hex[1];
195
+ return [0, 2, 4].map((at) => parseInt(digits.slice(at, at + 2), 16));
196
+ }
197
+ const rgb = /^rgba?\(\s*(\d+(?:\.\d+)?)\s*,\s*(\d+(?:\.\d+)?)\s*,\s*(\d+(?:\.\d+)?)/i.exec(text);
198
+ return rgb !== null ? [Number(rgb[1]), Number(rgb[2]), Number(rgb[3])] : undefined;
199
+ }
200
+ /** The ink a badge chip prints in when `text_color` is absent (C2): the
201
+ * WCAG relative luminance of the resolved fill, the dark ink above the cut,
202
+ * the light ink below it or on a fill the panes could not read. */
203
+ export function wrunPanelBadgeInk(fill) {
204
+ const channels = paneColorChannels(fill);
205
+ if (channels === undefined)
206
+ return WRUN_PANEL_BADGE_LIGHT_INK;
207
+ const [r, g, b] = channels.map((byte) => {
208
+ const channel = byte / 255;
209
+ return channel <= 0.03928 ? channel / 12.92 : ((channel + 0.055) / 1.055) ** 2.4;
210
+ });
211
+ const luminance = 0.2126 * r + 0.7152 * g + 0.0722 * b;
212
+ return luminance > WRUN_PANEL_BADGE_INK_CUT ? WRUN_PANEL_BADGE_DARK_INK : WRUN_PANEL_BADGE_LIGHT_INK;
213
+ }
214
+ /** The badge chip (C2), frame first: the text as declared, the fill
215
+ * (default theme.accent) and the ink (the declared `text_color`, else
216
+ * picked by the fill) through wrunPaneColor. The engine's `settings.badge
217
+ * { text, color, textColor }`. */
218
+ function panelBadge(panel, chrome, ctx) {
219
+ const badge = frameFirst(panel, chrome, 'badge');
220
+ if (badge === undefined)
221
+ return undefined;
222
+ const color = wrunPaneColor(badge.color ?? WRUN_PANEL_BADGE_DEFAULT_COLOR, ctx.theme);
223
+ const textColor = badge.text_color !== undefined ? wrunPaneColor(badge.text_color, ctx.theme) : wrunPanelBadgeInk(color);
224
+ return { text: badge.text, color, textColor };
225
+ }
226
+ /** The declared `chrome` word as the engine key (SC23); the engine's own
227
+ * default stands when none is declared. */
228
+ function chromeStylePatch(panel) {
229
+ return panel.chrome !== undefined ? { chromeStyle: panel.chrome } : {};
230
+ }
231
+ /** A time key in ms (keys under 1e11 are seconds; the SC37 rule). */
232
+ function timeKeyMs(key) {
233
+ return key < 1e11 ? key * 1000 : key;
234
+ }
235
+ /** Each distinct row key (`rows[i][0]`) to the index of its first row: a
236
+ * category line numbers its rows by position (SC04). */
237
+ function firstRowIndexByKey(rows) {
238
+ const indices = new Map();
239
+ rows.forEach((row, index) => {
240
+ const key = String(row[0]);
241
+ if (!indices.has(key))
242
+ indices.set(key, index);
243
+ });
244
+ return indices;
245
+ }
246
+ /** Each distinct row key (`rows[i][0]`, numbers as `String(key)`) to its
247
+ * ordinal in first-seen order: the scatter's group ids, which the engine
248
+ * reads as indices into `legendItems` (SC21 SC33). */
249
+ function keyOrdinals(rows) {
250
+ const ordinals = new Map();
251
+ for (const row of rows) {
252
+ const key = String(row[0]);
253
+ if (!ordinals.has(key))
254
+ ordinals.set(key, ordinals.size);
255
+ }
256
+ return ordinals;
257
+ }
258
+ /** The axis words shared by line, bars, histogram and scatter (SC39, SC20):
259
+ * titles, pinned ranges (frame first) and the zero rule. `y_title` is the
260
+ * rich curve's `yCaption` and every other pane's `yTitle`; `xLabel` (the
261
+ * hover noun) is a curve key, `xMin`/`xMax` a numeric-x key. */
262
+ function axisStyle(panel, chrome, options) {
263
+ const patch = {};
264
+ put(patch, 'xTitle', panel.x_title);
265
+ if (options.curve)
266
+ put(patch, 'xLabel', panel.x_title);
267
+ put(patch, options.rich ? 'yCaption' : 'yTitle', panel.y_title);
268
+ put(patch, 'yMin', frameFirst(panel, chrome, 'y_min'));
269
+ put(patch, 'yMax', frameFirst(panel, chrome, 'y_max'));
270
+ put(patch, 'yIncludeZero', panel.y_zero);
271
+ if (options.xBounds) {
272
+ put(patch, 'xMin', frameFirst(panel, chrome, 'x_min'));
273
+ put(patch, 'xMax', frameFirst(panel, chrome, 'x_max'));
274
+ }
275
+ return patch;
276
+ }
277
+ /** The declared number format of a panel or a series column (SC08, SC40):
278
+ * undefined when none of the four words is declared. */
279
+ function numberSpec(entry) {
280
+ if (entry.format === undefined &&
281
+ entry.decimals === undefined &&
282
+ entry.signed === undefined &&
283
+ entry.unit === undefined) {
284
+ return undefined;
285
+ }
286
+ const spec = {};
287
+ if (entry.format !== undefined)
288
+ spec.format = entry.format;
289
+ if (entry.decimals !== undefined)
290
+ spec.decimals = entry.decimals;
291
+ if (entry.signed !== undefined)
292
+ spec.signed = entry.signed;
293
+ if (entry.unit !== undefined)
294
+ spec.unit = entry.unit;
295
+ return spec;
296
+ }
297
+ /** The same spec without `signed` (axis ticks never carry a +, SC08). */
298
+ function axisSpecOf(spec) {
299
+ const { signed: _signed, ...rest } = spec;
300
+ return rest;
301
+ }
302
+ // The mappers
303
+ /** The words every kind shares (SC07 SC24 SC28): `hover_card: false` turns
304
+ * the hover card off (nothing is sent when true), the tone pair lands as
305
+ * `toneColors`, and on line and bars `legend_style` picks the legend:
306
+ * "none" hides every series (its chip and its value), "pane" the in-canvas
307
+ * legend, "chips" the chips-left style, and "title", the default, lists
308
+ * each series once beside the title (titleLegendStyle). */
309
+ export function wrunPanelCommonStyle(panel, ctx) {
310
+ const patch = {};
311
+ if (panel.hover_card === false)
312
+ patch.tooltipEnabled = false;
313
+ if (panel.positive_color !== undefined || panel.negative_color !== undefined) {
314
+ const tones = {};
315
+ if (panel.positive_color !== undefined)
316
+ tones.positive = wrunPaneColor(panel.positive_color, ctx.theme);
317
+ if (panel.negative_color !== undefined)
318
+ tones.negative = wrunPaneColor(panel.negative_color, ctx.theme);
319
+ patch.toneColors = tones;
320
+ }
321
+ if (panel.kind === 'line' || panel.kind === 'bars') {
322
+ switch (panel.legend_style) {
323
+ case 'none':
324
+ patch.series = (panel.series ?? []).map(() => ({ hideFromLegend: true }));
325
+ patch.hideLegendValues = true;
326
+ break;
327
+ case 'pane':
328
+ patch.seriesLegend = 'canvas';
329
+ break;
330
+ case 'chips':
331
+ patch.legendStyle = 'chips-left';
332
+ break;
333
+ default:
334
+ Object.assign(patch, titleLegendStyle(panel));
335
+ }
336
+ }
337
+ return patch;
338
+ }
339
+ /** The default legend ("title"; TEMPLATE-QA C38 D31 D40 E38) lists each
340
+ * series once. The engine lists a line or bars pane twice by default: a
341
+ * name chip per series beside the title, and a value cell per series (its
342
+ * name, colour and value at the hovered key, else at the last row). A time
343
+ * panel keeps the value cells (its last row is the latest reading) and
344
+ * drops the chips, and so does a panel with its hover card off (the cells
345
+ * are its only hover readout). Any other panel keeps the chips and drops
346
+ * the values: at rest its last row is an arbitrary last category or key
347
+ * that reads like a total, and the hover card prints the hovered one. */
348
+ function titleLegendStyle(panel) {
349
+ if (panel.x !== 'time' && panel.hover_card !== false)
350
+ return { hideLegendValues: true };
351
+ const series = panel.series ?? [];
352
+ return series.length > 0 ? { series: series.map(() => ({ hideFromLegend: true })) } : {};
353
+ }
354
+ /** The markers a line draws this run (SC04): the frame list replaces the
355
+ * declared one. `x` rides as is for "spot" and numeric lines, seconds become
356
+ * ms on a time line (SC37), a category key becomes its row index on a
357
+ * category line (a key absent from the rows drops that marker). A point
358
+ * callout (C3) carries `labelPlacement: 'point'`, its `y` and the NAME of
359
+ * its declared series (`series`; absent = the engine's first series): the
360
+ * engine anchors a callout on the series whose `name` it names (titan
361
+ * `resolveMarkerSeriesIndex`; the translation names every engine series by
362
+ * its declared name), and reads anything else, an index included, as the
363
+ * first series. A new array every run, because the engine's dirty check is
364
+ * by identity. */
365
+ function lineMarkers(panel, chrome, rows, ctx) {
366
+ const declared = chrome?.markers ?? panel.markers;
367
+ if (declared === undefined)
368
+ return undefined;
369
+ const categoryIndex = panel.x === 'category' ? firstRowIndexByKey(rows) : undefined;
370
+ const seriesNames = (panel.series ?? []).map((entry) => entry.name);
371
+ const markers = [];
372
+ for (const marker of declared) {
373
+ let x;
374
+ if (marker.x === 'spot')
375
+ x = 'spot';
376
+ else if (typeof marker.x === 'string')
377
+ x = categoryIndex?.get(marker.x);
378
+ else
379
+ x = panel.x === 'time' ? timeKeyMs(marker.x) : marker.x;
380
+ if (x === undefined)
381
+ continue;
382
+ const entry = { x };
383
+ put(entry, 'label', marker.label);
384
+ if (marker.color !== undefined)
385
+ entry.color = wrunPaneColor(marker.color, ctx.theme);
386
+ put(entry, 'markerBadge', marker.badge);
387
+ put(entry, 'markerWash', marker.wash);
388
+ put(entry, 'labelPlacement', marker.valign);
389
+ put(entry, 'y', marker.y);
390
+ if (marker.series !== undefined && seriesNames.includes(marker.series))
391
+ entry.series = marker.series;
392
+ put(entry, 'labelShowsValue', marker.show_value);
393
+ put(entry, 'lineStyle', marker.line_style);
394
+ put(entry, 'lineWidth', marker.width);
395
+ markers.push(entry);
396
+ }
397
+ return markers;
398
+ }
399
+ /** The line words (SC03 SC04 SC24 SC25 SC29 SC30 SC39): smoothing, the
400
+ * signed two-tone fill, fill fade, stroke fade, markers, dots, end labels,
401
+ * glow, motion, latest-value chips and the axis words on the pane; fill,
402
+ * fill ink, style, width, dash, dots, end label and legend membership per
403
+ * series. `y_title` is the rich curve's caption and a box line's axis title
404
+ * (the effective chrome decides, SC02). */
405
+ export function wrunLineStyle(panel, chrome, rows, ctx) {
406
+ const color = (word) => wrunPaneColor(word, ctx.theme);
407
+ const rich = wrunPanelChrome(panel) !== 'box';
408
+ const settings = {
409
+ ...chromeStylePatch(panel),
410
+ ...axisStyle(panel, chrome, { rich, curve: true, xBounds: panel.x === 'index' || panel.x === 'number' }),
411
+ };
412
+ put(settings, 'smooth', panel.smooth);
413
+ put(settings, 'fillMode', panel.fill_mode);
414
+ if (panel.fill_positive_color !== undefined)
415
+ settings.fillPositiveColor = color(panel.fill_positive_color);
416
+ if (panel.fill_negative_color !== undefined)
417
+ settings.fillNegativeColor = color(panel.fill_negative_color);
418
+ put(settings, 'fillGradient', panel.fill_fade);
419
+ if (panel.stroke_fade !== undefined) {
420
+ const fade = panel.stroke_fade;
421
+ const strokeGradient = {
422
+ pivotX: fade.pivot,
423
+ edgeAlpha: fade.edge_opacity ?? WRUN_PANEL_STROKE_FADE_EDGE_OPACITY,
424
+ };
425
+ if (fade.left_color !== undefined)
426
+ strokeGradient.negativeColor = color(fade.left_color);
427
+ if (fade.right_color !== undefined)
428
+ strokeGradient.positiveColor = color(fade.right_color);
429
+ settings.strokeGradient = strokeGradient;
430
+ }
431
+ put(settings, 'markers', lineMarkers(panel, chrome, rows, ctx));
432
+ put(settings, 'badge', panelBadge(panel, chrome, ctx));
433
+ put(settings, 'points', panel.points);
434
+ put(settings, 'endLabels', panel.labels);
435
+ put(settings, 'glow', panel.glow);
436
+ put(settings, 'tween', panel.animate);
437
+ put(settings, 'legendShowsLatest', panel.legend_latest);
438
+ const series = (panel.series ?? []).map((entry) => {
439
+ const patch = {};
440
+ put(patch, 'fill', entry.fill);
441
+ if (entry.fill_color !== undefined)
442
+ patch.fillColor = color(entry.fill_color);
443
+ put(patch, 'style', entry.style);
444
+ put(patch, 'smooth', entry.smooth);
445
+ put(patch, 'points', entry.points);
446
+ put(patch, 'endLabel', entry.labels);
447
+ put(patch, 'lineWidth', entry.width);
448
+ put(patch, 'lineStyle', entry.line_style);
449
+ if (entry.legend === false)
450
+ patch.hideFromLegend = true;
451
+ return patch;
452
+ });
453
+ return { settings, series };
454
+ }
455
+ /** The bar shape words of bars and histogram: the bar's share of its slot
456
+ * (`barWidthFrac`) and the corner radius of its data end (`barRadius`). An
457
+ * engine that predates them ignores the two settings. */
458
+ function barShapeStyle(panel) {
459
+ const patch = {};
460
+ put(patch, 'barWidthFrac', panel.bar_width);
461
+ put(patch, 'barRadius', panel.bar_radius);
462
+ return patch;
463
+ }
464
+ /** The bars words (SC19 SC23 SC24 SC39, C2): sign colouring (the tones
465
+ * come from the common words), the axis words, the bar shape, the badge
466
+ * chip and legend membership per series (`series[j].legend: false` keeps
467
+ * that series out of the legend chips, a `series` patch merged per index);
468
+ * per-bar colours are row data the caller maps. */
469
+ export function wrunBarsStyle(panel, chrome, _rows, ctx) {
470
+ const patch = {
471
+ ...chromeStylePatch(panel),
472
+ ...axisStyle(panel, chrome, { rich: false, curve: false, xBounds: false }),
473
+ ...barShapeStyle(panel),
474
+ };
475
+ if (panel.color_mode === 'sign')
476
+ patch.signedBars = true;
477
+ put(patch, 'badge', panelBadge(panel, chrome, ctx));
478
+ const series = panel.series ?? [];
479
+ if (series.some((entry) => entry.legend === false)) {
480
+ patch.series = series.map((entry) => (entry.legend === false ? { hideFromLegend: true } : {}));
481
+ }
482
+ return patch;
483
+ }
484
+ /** The histogram words beyond its colour, labels and bins (the caller's,
485
+ * SC38): the chrome, the axis words of its curve bars sub-plan (SC23 SC39),
486
+ * the bar shape and the badge chip (C2). */
487
+ export function wrunHistogramStyle(panel, chrome, _rows, ctx) {
488
+ const patch = {
489
+ ...chromeStylePatch(panel),
490
+ ...axisStyle(panel, chrome, { rich: false, curve: true, xBounds: false }),
491
+ ...barShapeStyle(panel),
492
+ };
493
+ put(patch, 'badge', panelBadge(panel, chrome, ctx));
494
+ return patch;
495
+ }
496
+ /** The scatter words (SC20 SC21 SC23 SC32 SC33 SC39): pinned ranges, guides
497
+ * and quadrants (frame first), trails (each row's group is the ordinal of
498
+ * its key in first-seen order, the index of that key's legend chip), label
499
+ * overlap, the axis words and the legend chips (one per distinct key in
500
+ * first-seen order, in the colour of that key's last row, absent when that
501
+ * row has none: the chip then matches the default ink the engine draws
502
+ * the point and its trail in). */
503
+ export function wrunScatterStyle(panel, chrome, rows, ctx) {
504
+ const color = (word) => wrunPaneColor(word, ctx.theme);
505
+ const patch = {
506
+ ...chromeStylePatch(panel),
507
+ ...axisStyle(panel, chrome, { rich: false, curve: false, xBounds: true }),
508
+ };
509
+ put(patch, 'badge', panelBadge(panel, chrome, ctx));
510
+ const guides = frameFirst(panel, chrome, 'guides');
511
+ if (guides !== undefined) {
512
+ patch.guides = guides.map((guide) => {
513
+ const entry = { axis: guide.axis, value: guide.value };
514
+ put(entry, 'label', guide.label);
515
+ if (guide.color !== undefined)
516
+ entry.color = color(guide.color);
517
+ put(entry, 'lineStyle', guide.line_style);
518
+ put(entry, 'lineWidth', guide.width);
519
+ return entry;
520
+ });
521
+ }
522
+ const quadrants = frameFirst(panel, chrome, 'quadrants');
523
+ if (quadrants !== undefined) {
524
+ const entry = { x: quadrants.x, y: quadrants.y, colors: quadrants.colors.map(color) };
525
+ if (quadrants.labels !== undefined)
526
+ entry.labels = [...quadrants.labels];
527
+ patch.quadrants = entry;
528
+ }
529
+ if (panel.trails === true || panel.legend_style === 'title') {
530
+ const ordinals = keyOrdinals(rows);
531
+ if (panel.trails === true)
532
+ patch.trailGroups = rows.map((row) => ordinals.get(String(row[0])));
533
+ if (panel.legend_style === 'title') {
534
+ const lastColor = new Map();
535
+ for (const row of rows)
536
+ lastColor.set(String(row[0]), typeof row[4] === 'string' ? row[4] : undefined);
537
+ patch.legendItems = [...ordinals.keys()].map((name) => {
538
+ const word = lastColor.get(name);
539
+ return word === undefined ? { name } : { name, color: color(word) };
540
+ });
541
+ }
542
+ }
543
+ put(patch, 'trailWidth', panel.trail_width);
544
+ put(patch, 'trailFade', panel.trail_fade);
545
+ put(patch, 'labelOverlap', panel.label_overlap);
546
+ return patch;
547
+ }
548
+ /** The pie words (SC23 SC33 SC34): the chrome, the legend chips (one per
549
+ * slice), the hole text (a frame `hole_text`, else the slice total printed
550
+ * through the panel format, `String(sum)` without one), the hole caption
551
+ * (frame first), slice gaps and the slice border. */
552
+ export function wrunPieStyle(panel, chrome, rows, ctx) {
553
+ const color = (word) => wrunPaneColor(word, ctx.theme);
554
+ const patch = chromeStylePatch(panel);
555
+ if (panel.legend_style === 'title') {
556
+ patch.legendItems = rows.map((row) => typeof row[2] === 'string' ? { name: String(row[0]), color: color(row[2]) } : { name: String(row[0]) });
557
+ }
558
+ let holeText = chrome?.hole_text;
559
+ if (holeText === undefined && panel.hole_total === true) {
560
+ const sum = rows.reduce((total, row) => total + (typeof row[1] === 'number' ? row[1] : 0), 0);
561
+ const printed = wrunPanelFormatter(panel, rows, ctx)?.(sum, 'value', -1);
562
+ holeText = typeof printed === 'string' ? printed : String(sum);
563
+ }
564
+ put(patch, 'holeText', holeText);
565
+ put(patch, 'holeCaption', frameFirst(panel, chrome, 'hole_caption'));
566
+ put(patch, 'sliceGap', panel.slice_gap);
567
+ if (panel.border_color !== undefined)
568
+ patch.borderColor = color(panel.border_color);
569
+ put(patch, 'borderWidth', panel.border_width);
570
+ return patch;
571
+ }
572
+ /** The heatmap words (SC06 SC18): under scale "palette" the stops (the
573
+ * declared ones, else today's three) and the bounds (frame first); under
574
+ * "signed" none of them, so the engine's diverging scale draws through the
575
+ * common tone pair. The highlight resolves its keys to the engine's row and
576
+ * column indices (a key absent from the rows is dropped), the axis nouns
577
+ * pass through, and a frame summary is fitted to the column count. */
578
+ export function wrunHeatmapStyle(panel, chrome, indices, ctx) {
579
+ const patch = {};
580
+ if (panel.scale !== 'signed') {
581
+ patch.palette = (panel.palette ?? WRUN_PANEL_HEATMAP_PALETTE).map((word) => wrunPaneColor(word, ctx.theme));
582
+ put(patch, 'min', frameFirst(panel, chrome, 'min'));
583
+ put(patch, 'max', frameFirst(panel, chrome, 'max'));
584
+ }
585
+ const highlight = frameFirst(panel, chrome, 'highlight');
586
+ if (highlight !== undefined) {
587
+ const resolved = {};
588
+ put(resolved, 'row', highlight.row !== undefined ? indices.y.get(highlight.row) : undefined);
589
+ put(resolved, 'col', highlight.col !== undefined ? indices.x.get(highlight.col) : undefined);
590
+ if (Object.keys(resolved).length > 0)
591
+ patch.highlight = resolved;
592
+ }
593
+ put(patch, 'rowTitle', panel.row_title);
594
+ put(patch, 'colTitle', panel.col_title);
595
+ if (chrome?.summary !== undefined) {
596
+ patch.summary = chrome.summary.map((row) => {
597
+ const values = row.values.slice(0, indices.columns);
598
+ while (values.length < indices.columns)
599
+ values.push(null);
600
+ return { label: row.label, values };
601
+ });
602
+ }
603
+ return patch;
604
+ }
605
+ /** The tiles words: none of their own. `columns`, `accent` and a tile's
606
+ * colour ride the structural translation (the caller's, SC26 SC15), the
607
+ * tone pair and the hover card are common words (SC28 SC07) and the tile
608
+ * formats reach the engine through {@link wrunPanelFormatter} (SC26). The
609
+ * seam stays so a tiles word lands here without touching the caller. */
610
+ export function wrunTilesStyle(_panel, _rows, _ctx) {
611
+ return {};
612
+ }
613
+ /** The table words onto the engine's Table payload (SC22 SC35; the
614
+ * WRUN-CAPS keys verbatim): the anchor and offset (`y` adds the legend
615
+ * clearance under a top_* anchor), widths, padding, type, alignment, inks
616
+ * (resolved), the background fill and gradient, the border and grid lines,
617
+ * and the header column. Only declared words patch the caller's defaults. */
618
+ export function wrunTableStyle(panel, ctx) {
619
+ const color = (word) => wrunPaneColor(word, ctx.theme);
620
+ const patch = {};
621
+ if (panel.position !== undefined || panel.offset !== undefined) {
622
+ const position = panel.position ?? 'top_left';
623
+ const [dx, dy] = panel.offset ?? [0, 0];
624
+ patch.position = position;
625
+ patch.x = dx;
626
+ patch.y = dy + (position.startsWith('top_') ? WRUN_PANEL_TABLE_TOP_OFFSET_PX : 0);
627
+ }
628
+ put(patch, 'width', panel.width);
629
+ if (panel.column_widths !== undefined)
630
+ patch.columnWidths = [...panel.column_widths];
631
+ put(patch, 'cellPadding', panel.cell_padding);
632
+ put(patch, 'fontSize', panel.font_size);
633
+ put(patch, 'fontWeight', wrunFontWeightCss(panel.font_weight));
634
+ put(patch, 'fontFamily', wrunFontFamilyCss(panel.font_family));
635
+ put(patch, 'align', panel.align);
636
+ put(patch, 'valign', panel.valign);
637
+ if (panel.text_color !== undefined)
638
+ patch.textColor = color(panel.text_color);
639
+ if (panel.header_text_color !== undefined)
640
+ patch.headerTextColor = color(panel.header_text_color);
641
+ if (panel.background_color !== undefined)
642
+ patch.backgroundColor = color(panel.background_color);
643
+ if (panel.header_background_color !== undefined)
644
+ patch.headerBackgroundColor = color(panel.header_background_color);
645
+ put(patch, 'backgroundOpacity', panel.background_opacity);
646
+ if (panel.background_gradient !== undefined)
647
+ patch.backgroundGradient = panel.background_gradient.map(color);
648
+ put(patch, 'gradientDirection', panel.gradient_direction);
649
+ if (panel.border_color !== undefined)
650
+ patch.borderColor = color(panel.border_color);
651
+ put(patch, 'borderWidth', panel.border_width);
652
+ put(patch, 'borderStyle', panel.border_style);
653
+ if (panel.grid_color !== undefined)
654
+ patch.gridColor = color(panel.grid_color);
655
+ put(patch, 'gridWidth', panel.grid_width);
656
+ put(patch, 'gridStyle', panel.grid_style);
657
+ put(patch, 'gridLines', panel.grid_lines);
658
+ put(patch, 'headerColumn', panel.header_column);
659
+ return patch;
660
+ }
661
+ /** The engine's number formatter for a panel (SC08 SC26 SC40), built only
662
+ * when a format word is declared somewhere on it: `format`, `decimals`,
663
+ * `signed`, `unit` (role 'value'; role 'axis' prints the same without the
664
+ * sign), `x_format`, `x_decimals`, `x_unit` (role 'x'), a tile row's own
665
+ * format (element 5: it replaces the panel's format and keeps its
666
+ * decimals, sign and unit, by tile index) or a table column's words
667
+ * (`series[j]`, in place of the table's, by column index). Every spec
668
+ * carries the chart's price digits for "price".
669
+ *
670
+ * A number whose words are not declared keeps the engine's own text
671
+ * (FREEZE 2.2: formatWrunNumber runs only where a surface declares a
672
+ * word): the hook answers a non-string, which every engine surface reads as
673
+ * "print your own" (see WRUN_ENGINE_FORMATTING). One exception: role
674
+ * 'axis' on a curve pane (line, histogram) always prints, because the
675
+ * caller also hands it to the pane's price scale as `getYLabel`, which has
676
+ * no fallback (a non-string prints as an empty label); without value words
677
+ * it prints the foundation's undeclared text. */
678
+ export function wrunPanelFormatter(panel, rows, ctx) {
679
+ const tileFormats = panel.kind === 'tiles' ? rows.map((row) => (typeof row[5] === 'string' ? row[5] : undefined)) : [];
680
+ const columnWords = panel.kind === 'table' ? (panel.series ?? []).map((entry) => numberSpec(entry)) : [];
681
+ const valueWords = numberSpec(panel);
682
+ const xWords = numberSpec({ format: panel.x_format, decimals: panel.x_decimals, unit: panel.x_unit });
683
+ const declared = valueWords !== undefined ||
684
+ xWords !== undefined ||
685
+ tileFormats.some((format) => format !== undefined) ||
686
+ columnWords.some((spec) => spec !== undefined);
687
+ if (!declared)
688
+ return undefined;
689
+ const priceDigits = ctx.priceDigits;
690
+ const bind = (spec) => spec === undefined ? undefined : { ...spec, priceDigits };
691
+ const xSpec = bind(xWords);
692
+ const valueSpec = bind(valueWords);
693
+ const axisSpec = valueSpec === undefined ? undefined : axisSpecOf(valueSpec);
694
+ const indexWords = panel.kind === 'tiles'
695
+ ? tileFormats.map((format) => (format === undefined ? undefined : { ...valueWords, format }))
696
+ : columnWords;
697
+ const indexValueSpecs = indexWords.map(bind);
698
+ const indexAxisSpecs = indexValueSpecs.map((spec) => (spec === undefined ? undefined : axisSpecOf(spec)));
699
+ const axisAlwaysPrints = panel.kind === 'line' || panel.kind === 'histogram';
700
+ return (value, role, index) => {
701
+ if (role === 'x')
702
+ return xSpec === undefined ? WRUN_ENGINE_FORMATTING : formatWrunNumber(value, xSpec);
703
+ const axis = role === 'axis';
704
+ const own = index >= 0 ? (axis ? indexAxisSpecs : indexValueSpecs)[index] : undefined;
705
+ const spec = own ?? (axis ? axisSpec : valueSpec);
706
+ if (spec !== undefined)
707
+ return formatWrunNumber(value, spec);
708
+ return axis && axisAlwaysPrints ? formatWrunNumber(value) : WRUN_ENGINE_FORMATTING;
709
+ };
710
+ }
711
+ // The panel translator's door (wrun-panel-style.lazy.ts): bound as this module evaluates, so every
712
+ // lane that loaded it translates in its own turn.
713
+ bindWrunPanelStyle({
714
+ wrunBarsStyle,
715
+ wrunHeatmapStyle,
716
+ wrunHistogramStyle,
717
+ wrunLineStyle,
718
+ wrunPanelChrome,
719
+ wrunPanelCommonStyle,
720
+ wrunPanelFormatter,
721
+ wrunPaneColor,
722
+ wrunPieStyle,
723
+ wrunScatterStyle,
724
+ wrunTableStyle,
725
+ wrunTilesStyle,
726
+ });