@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,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The chart instance of each pane as the wrun run-result adapter and the alert target reach it
|
|
3
|
+
* (chartIndex -> the titan chart, registered by the chart's hover bridge at pane init, forgotten at
|
|
4
|
+
* teardown): the adapter applies output visibility through it (applyWrunOutputVisibility, which
|
|
5
|
+
* never imports the engine registry that node specs mock away), and the alert arm reads the pane's
|
|
6
|
+
* market tick, price scale and theme from it. A thin fact: the registry is a Map, so the alert
|
|
7
|
+
* target reads it without the run-result adapter behind it
|
|
8
|
+
* (docs/features/kscript/wrun/wrun-browser-runtime.md, "Boot doors").
|
|
9
|
+
*/
|
|
10
|
+
/** The slice of a titan chart the visibility apply reaches. */
|
|
11
|
+
export interface WrunVisibilityChart {
|
|
12
|
+
metadata?: ReadonlyArray<{
|
|
13
|
+
id?: unknown;
|
|
14
|
+
nestedMeta?: unknown;
|
|
15
|
+
isHidden?: unknown;
|
|
16
|
+
}>;
|
|
17
|
+
changeVisibilityOverlay?(id: string, isVisible: boolean, options?: {
|
|
18
|
+
targetId?: string;
|
|
19
|
+
}): void;
|
|
20
|
+
}
|
|
21
|
+
export declare function registerWrunVisibilityChart(chartIndex: number, chart: WrunVisibilityChart | null): void;
|
|
22
|
+
/** The registered chart instance of a pane (undefined before the bridge
|
|
23
|
+
* attaches and after it detaches): the alert arm reads the pane's market
|
|
24
|
+
* tick and price scale from it without importing the engine registry. */
|
|
25
|
+
export declare function getWrunVisibilityChart(chartIndex: number): WrunVisibilityChart | undefined;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The chart instance of each pane as the wrun run-result adapter and the alert target reach it
|
|
3
|
+
* (chartIndex -> the titan chart, registered by the chart's hover bridge at pane init, forgotten at
|
|
4
|
+
* teardown): the adapter applies output visibility through it (applyWrunOutputVisibility, which
|
|
5
|
+
* never imports the engine registry that node specs mock away), and the alert arm reads the pane's
|
|
6
|
+
* market tick, price scale and theme from it. A thin fact: the registry is a Map, so the alert
|
|
7
|
+
* target reads it without the run-result adapter behind it
|
|
8
|
+
* (docs/features/kscript/wrun/wrun-browser-runtime.md, "Boot doors").
|
|
9
|
+
*/
|
|
10
|
+
const visibilityCharts = new Map();
|
|
11
|
+
export function registerWrunVisibilityChart(chartIndex, chart) {
|
|
12
|
+
if (chart === null)
|
|
13
|
+
visibilityCharts.delete(chartIndex);
|
|
14
|
+
else
|
|
15
|
+
visibilityCharts.set(chartIndex, chart);
|
|
16
|
+
}
|
|
17
|
+
/** The registered chart instance of a pane (undefined before the bridge
|
|
18
|
+
* attaches and after it detaches): the alert arm reads the pane's market
|
|
19
|
+
* tick and price scale from it without importing the engine registry. */
|
|
20
|
+
export function getWrunVisibilityChart(chartIndex) {
|
|
21
|
+
return visibilityCharts.get(chartIndex);
|
|
22
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The heatmap sensitivity scale (the slider position, its legacy words and the calibration quantile they map to):
|
|
3
|
+
* pure, split out of options-heatmap-encoding.util (which re-exports every name here) so the wrun canvases and
|
|
4
|
+
* colour settings read the scale without the options venue tables. It rides the `@orangecharts/wrun-chart-host`
|
|
5
|
+
* package (docs/features/kscript/wrun/wrun-chart-host.md).
|
|
6
|
+
*/
|
|
7
|
+
/** Legacy tri-state sensitivity strings (pre-slider workspaces). */
|
|
8
|
+
export type OptionsHeatmapLegacySensitivity = 'low' | 'normal' | 'high';
|
|
9
|
+
/**
|
|
10
|
+
* User-facing color sensitivity: which |value| quantile saturates the ramp.
|
|
11
|
+
* Persisted as a CONTINUOUS 0–100 slider position (0 = subtle, 100 = vivid);
|
|
12
|
+
* legacy workspaces may still carry a tri-state string.
|
|
13
|
+
*/
|
|
14
|
+
export type OptionsHeatmapSensitivity = number | OptionsHeatmapLegacySensitivity;
|
|
15
|
+
/**
|
|
16
|
+
* Calibration quantile anchors of the legacy tri-state. LOW pins the ramp to
|
|
17
|
+
* the extreme tail (only monsters saturate, flatter map); HIGH saturates at
|
|
18
|
+
* the 90th percentile so subtle structure pops. NORMAL is the historical
|
|
19
|
+
* 0.98 default. The continuous map below interpolates linearly between the
|
|
20
|
+
* low and high anchors.
|
|
21
|
+
*/
|
|
22
|
+
export declare const HEATMAP_SENSITIVITY_QUANTILES: Record<OptionsHeatmapLegacySensitivity, number>;
|
|
23
|
+
/** Slider-position domain for the sensitivity setting. */
|
|
24
|
+
export declare const HEATMAP_SENSITIVITY_MIN = 0;
|
|
25
|
+
export declare const HEATMAP_SENSITIVITY_MAX = 100;
|
|
26
|
+
/**
|
|
27
|
+
* Exact slider positions of the legacy tri-state strings under the linear
|
|
28
|
+
* quantile map: low sits at 0, high at 100, normal at
|
|
29
|
+
* (0.995 − 0.98) / 0.095 × 100 ≈ 15.789. Computed from the SAME anchor
|
|
30
|
+
* constants the map uses, so `heatmapSensitivityQuantile` returns each
|
|
31
|
+
* legacy quantile byte-exactly at these positions, and every comparison
|
|
32
|
+
* surface (refetch gate, calibration stamps) sees a legacy string and its
|
|
33
|
+
* numeric position as the SAME value.
|
|
34
|
+
*/
|
|
35
|
+
export declare const HEATMAP_SENSITIVITY_LEGACY_POSITIONS: Record<OptionsHeatmapLegacySensitivity, number>;
|
|
36
|
+
/** Default sensitivity = the legacy 'normal' position (the historical 0.98 quantile). */
|
|
37
|
+
export declare const HEATMAP_SENSITIVITY_DEFAULT: number;
|
|
38
|
+
/**
|
|
39
|
+
* ONE normalization for every surface that stores or compares sensitivity:
|
|
40
|
+
* finite numbers clamp into [0, 100]; legacy strings map to their exact
|
|
41
|
+
* positions; anything else (missing setting, garbage) is the default. This
|
|
42
|
+
* keeps a restored legacy 'normal' and its numeric position comparing EQUAL,
|
|
43
|
+
* so old workspaces neither refetch nor recalibrate spuriously.
|
|
44
|
+
*/
|
|
45
|
+
export declare function normalizeHeatmapSensitivity(value: unknown): number;
|
|
46
|
+
/**
|
|
47
|
+
* Calibration quantile for a persisted sensitivity: linear in the normalized
|
|
48
|
+
* slider position t, quantile = 0.995 − (t/100) × (0.995 − 0.90). t = 0
|
|
49
|
+
* reserves full color for the extreme tail, t = 100 saturates at the 90th
|
|
50
|
+
* percentile; legacy strings land on their exact historical quantiles
|
|
51
|
+
* (low 0.995, normal 0.98, high 0.90) via their normalized positions.
|
|
52
|
+
*/
|
|
53
|
+
export declare function heatmapSensitivityQuantile(sensitivity: unknown): number;
|
|
54
|
+
/**
|
|
55
|
+
* The slider position of a calibration quantile: the inverse of
|
|
56
|
+
* `heatmapSensitivityQuantile` over the same anchors, t = (0.995 − q) /
|
|
57
|
+
* (0.995 − 0.90) × 100, clamped into [0, 100] (a quantile outside
|
|
58
|
+
* 0.90..0.995 lands on the nearer end). It is written as the legacy
|
|
59
|
+
* positions are, so 0.98 lands exactly on the Normal position. A
|
|
60
|
+
* quantile that is not a finite number reads as the default.
|
|
61
|
+
*/
|
|
62
|
+
export declare function heatmapSensitivityForQuantile(quantile: number): number;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The heatmap sensitivity scale (the slider position, its legacy words and the calibration quantile they map to):
|
|
3
|
+
* pure, split out of options-heatmap-encoding.util (which re-exports every name here) so the wrun canvases and
|
|
4
|
+
* colour settings read the scale without the options venue tables. It rides the `@orangecharts/wrun-chart-host`
|
|
5
|
+
* package (docs/features/kscript/wrun/wrun-chart-host.md).
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Calibration quantile anchors of the legacy tri-state. LOW pins the ramp to
|
|
9
|
+
* the extreme tail (only monsters saturate, flatter map); HIGH saturates at
|
|
10
|
+
* the 90th percentile so subtle structure pops. NORMAL is the historical
|
|
11
|
+
* 0.98 default. The continuous map below interpolates linearly between the
|
|
12
|
+
* low and high anchors.
|
|
13
|
+
*/
|
|
14
|
+
export const HEATMAP_SENSITIVITY_QUANTILES = {
|
|
15
|
+
low: 0.995,
|
|
16
|
+
normal: 0.98,
|
|
17
|
+
high: 0.9,
|
|
18
|
+
};
|
|
19
|
+
/** Slider-position domain for the sensitivity setting. */
|
|
20
|
+
export const HEATMAP_SENSITIVITY_MIN = 0;
|
|
21
|
+
export const HEATMAP_SENSITIVITY_MAX = 100;
|
|
22
|
+
const HEATMAP_SENSITIVITY_QUANTILE_SPAN = HEATMAP_SENSITIVITY_QUANTILES.low - HEATMAP_SENSITIVITY_QUANTILES.high;
|
|
23
|
+
/**
|
|
24
|
+
* Exact slider positions of the legacy tri-state strings under the linear
|
|
25
|
+
* quantile map: low sits at 0, high at 100, normal at
|
|
26
|
+
* (0.995 − 0.98) / 0.095 × 100 ≈ 15.789. Computed from the SAME anchor
|
|
27
|
+
* constants the map uses, so `heatmapSensitivityQuantile` returns each
|
|
28
|
+
* legacy quantile byte-exactly at these positions, and every comparison
|
|
29
|
+
* surface (refetch gate, calibration stamps) sees a legacy string and its
|
|
30
|
+
* numeric position as the SAME value.
|
|
31
|
+
*/
|
|
32
|
+
export const HEATMAP_SENSITIVITY_LEGACY_POSITIONS = {
|
|
33
|
+
low: HEATMAP_SENSITIVITY_MIN,
|
|
34
|
+
normal: ((HEATMAP_SENSITIVITY_QUANTILES.low - HEATMAP_SENSITIVITY_QUANTILES.normal) / HEATMAP_SENSITIVITY_QUANTILE_SPAN) *
|
|
35
|
+
100,
|
|
36
|
+
high: HEATMAP_SENSITIVITY_MAX,
|
|
37
|
+
};
|
|
38
|
+
/** Default sensitivity = the legacy 'normal' position (the historical 0.98 quantile). */
|
|
39
|
+
export const HEATMAP_SENSITIVITY_DEFAULT = HEATMAP_SENSITIVITY_LEGACY_POSITIONS.normal;
|
|
40
|
+
/**
|
|
41
|
+
* ONE normalization for every surface that stores or compares sensitivity:
|
|
42
|
+
* finite numbers clamp into [0, 100]; legacy strings map to their exact
|
|
43
|
+
* positions; anything else (missing setting, garbage) is the default. This
|
|
44
|
+
* keeps a restored legacy 'normal' and its numeric position comparing EQUAL,
|
|
45
|
+
* so old workspaces neither refetch nor recalibrate spuriously.
|
|
46
|
+
*/
|
|
47
|
+
export function normalizeHeatmapSensitivity(value) {
|
|
48
|
+
if (typeof value === 'number' && Number.isFinite(value)) {
|
|
49
|
+
return Math.min(HEATMAP_SENSITIVITY_MAX, Math.max(HEATMAP_SENSITIVITY_MIN, value));
|
|
50
|
+
}
|
|
51
|
+
if (typeof value === 'string') {
|
|
52
|
+
const position = HEATMAP_SENSITIVITY_LEGACY_POSITIONS[value];
|
|
53
|
+
if (typeof position === 'number')
|
|
54
|
+
return position;
|
|
55
|
+
}
|
|
56
|
+
return HEATMAP_SENSITIVITY_DEFAULT;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Calibration quantile for a persisted sensitivity: linear in the normalized
|
|
60
|
+
* slider position t, quantile = 0.995 − (t/100) × (0.995 − 0.90). t = 0
|
|
61
|
+
* reserves full color for the extreme tail, t = 100 saturates at the 90th
|
|
62
|
+
* percentile; legacy strings land on their exact historical quantiles
|
|
63
|
+
* (low 0.995, normal 0.98, high 0.90) via their normalized positions.
|
|
64
|
+
*/
|
|
65
|
+
export function heatmapSensitivityQuantile(sensitivity) {
|
|
66
|
+
const t = normalizeHeatmapSensitivity(sensitivity);
|
|
67
|
+
return HEATMAP_SENSITIVITY_QUANTILES.low - (t / 100) * HEATMAP_SENSITIVITY_QUANTILE_SPAN;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The slider position of a calibration quantile: the inverse of
|
|
71
|
+
* `heatmapSensitivityQuantile` over the same anchors, t = (0.995 − q) /
|
|
72
|
+
* (0.995 − 0.90) × 100, clamped into [0, 100] (a quantile outside
|
|
73
|
+
* 0.90..0.995 lands on the nearer end). It is written as the legacy
|
|
74
|
+
* positions are, so 0.98 lands exactly on the Normal position. A
|
|
75
|
+
* quantile that is not a finite number reads as the default.
|
|
76
|
+
*/
|
|
77
|
+
export function heatmapSensitivityForQuantile(quantile) {
|
|
78
|
+
if (!Number.isFinite(quantile))
|
|
79
|
+
return HEATMAP_SENSITIVITY_DEFAULT;
|
|
80
|
+
const t = ((HEATMAP_SENSITIVITY_QUANTILES.low - quantile) / HEATMAP_SENSITIVITY_QUANTILE_SPAN) * 100;
|
|
81
|
+
return Math.min(HEATMAP_SENSITIVITY_MAX, Math.max(HEATMAP_SENSITIVITY_MIN, t));
|
|
82
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/** The chart whose tab title a price belongs to: any engine instance, keyed by identity alone. */
|
|
2
|
+
type TitleChart = object;
|
|
3
|
+
/**
|
|
4
|
+
* Round a number to the given number of decimal places
|
|
5
|
+
*
|
|
6
|
+
* @param {number} num - The number to round
|
|
7
|
+
* @param {number} decimalPlaces - The number of decimal places to round to
|
|
8
|
+
* @returns {number} The rounded number
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* roundToDecimalPlaces(1.2345, 2) // 1.23
|
|
12
|
+
* roundToDecimalPlaces(1.2345, 3) // 1.235
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
export declare function roundToDecimalPlaces(num: number, decimalPlaces: number): number;
|
|
16
|
+
export declare function countDecimalPlaces(value: number): number;
|
|
17
|
+
export declare function partiallyFormatNumbers(num: number, decimalPlaces?: number | string, shouldRound?: boolean, isRoundFromThousand?: boolean): string | number;
|
|
18
|
+
/**
|
|
19
|
+
* Formats delta values to always show exactly 1 decimal place
|
|
20
|
+
* @param num - The numeric value to format
|
|
21
|
+
* @returns Formatted string with exactly 1 decimal place
|
|
22
|
+
*/
|
|
23
|
+
export declare function formatDelta(num: number): string;
|
|
24
|
+
/**
|
|
25
|
+
* Compact HEADCOUNT: an exact integer under 1000, then one decimal at most.
|
|
26
|
+
* `840 → "840"`, `5230 → "5.2k"`, `1_250_000 → "1.3M"`.
|
|
27
|
+
*
|
|
28
|
+
* Deliberately not `formatNumbers`, which is a PRICE/VOLUME formatter: it
|
|
29
|
+
* renders 12 as "12.0" and uses an uppercase "K". Neither is right for
|
|
30
|
+
* "12 watching" — a count of people is a whole number, and the design's scale
|
|
31
|
+
* is lowercase k / uppercase M.
|
|
32
|
+
*/
|
|
33
|
+
export declare function formatCompactCount(count: number): string;
|
|
34
|
+
export declare function formatNumbers(num: number, defaultDecimalPlaces?: number, shouldRound?: boolean): string;
|
|
35
|
+
export declare function changeNumberFormat(value: number, precision: number): string;
|
|
36
|
+
/**
|
|
37
|
+
* Compact positive-volume numeral with sub-unit honesty: values >= 1 keep the
|
|
38
|
+
* `changeNumberFormat(value, 1)` convention (K/M/B suffixes, 1 decimal), while
|
|
39
|
+
* values in (0, 1) render with up to 4 significant digits (plain decimal,
|
|
40
|
+
* trailing zeros trimmed) so BTC-sized prints like 0.0432 never collapse to
|
|
41
|
+
* "0.0". Zero and non-finite input render as '' (callers decide their own
|
|
42
|
+
* empty/zero glyph).
|
|
43
|
+
*/
|
|
44
|
+
export declare function formatAdaptiveVolume(value: number): string;
|
|
45
|
+
export declare function safeDivide(a: number, b: number): number;
|
|
46
|
+
/**
|
|
47
|
+
* The price text the ticker surfaces print: the desktop ticker bar, the
|
|
48
|
+
* orderbook ticker, and the mobile header, legend and stats, so one symbol
|
|
49
|
+
* reads the same number on every one of them. The decimals come from the
|
|
50
|
+
* price's own magnitude, because the FE holds no per-symbol tick size and the
|
|
51
|
+
* chart's axis precision moves with every zoom. `reference` is the price a
|
|
52
|
+
* difference belongs to: a 24h change prints at its price's resolution.
|
|
53
|
+
*/
|
|
54
|
+
export declare function formatPriceByMagnitude(value: number, reference?: number): string;
|
|
55
|
+
export declare function titlePriceDirection(curr: unknown, prev: unknown, lastGlyph?: string): string;
|
|
56
|
+
/**
|
|
57
|
+
* The tab title's price: the ticker bar's text (formatPriceByMagnitude) with
|
|
58
|
+
* thousands grouped. Never the price axis step: the engine computes that only
|
|
59
|
+
* when it paints, so a chart mounted in a background tab printed the raw float
|
|
60
|
+
* (0.9992810927390368), and an axis stretched by one stray value cut the same
|
|
61
|
+
* ratio to "1.00". Negative values (spread formulas) keep the magnitude rule.
|
|
62
|
+
*/
|
|
63
|
+
export declare function formatTitlePrice(price: number): string;
|
|
64
|
+
export declare function formatChartTitlePrice(price: number, tc: TitleChart, context: {
|
|
65
|
+
symbolKey: string;
|
|
66
|
+
previousPrice?: number;
|
|
67
|
+
}): string;
|
|
68
|
+
export {};
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
// Number-formatting and tab-title helpers stay free of runtime dependencies so
|
|
2
|
+
// light consumers do not pull the chart engine or stores into the boot graph.
|
|
3
|
+
/**
|
|
4
|
+
* Round a number to the given number of decimal places
|
|
5
|
+
*
|
|
6
|
+
* @param {number} num - The number to round
|
|
7
|
+
* @param {number} decimalPlaces - The number of decimal places to round to
|
|
8
|
+
* @returns {number} The rounded number
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* roundToDecimalPlaces(1.2345, 2) // 1.23
|
|
12
|
+
* roundToDecimalPlaces(1.2345, 3) // 1.235
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
export function roundToDecimalPlaces(num, decimalPlaces) {
|
|
16
|
+
const factor = Math.pow(10, decimalPlaces);
|
|
17
|
+
return Math.round(num * factor) / factor;
|
|
18
|
+
}
|
|
19
|
+
export function countDecimalPlaces(value) {
|
|
20
|
+
if (!Number.isFinite(value) || value === 0)
|
|
21
|
+
return 0;
|
|
22
|
+
// Handle scientific notation (e.g., 0.0000001.toString() => "1e-7")
|
|
23
|
+
const str = value.toString();
|
|
24
|
+
if (str.includes('e-')) {
|
|
25
|
+
const [coeff, exp] = str.split('e-');
|
|
26
|
+
const coeffDecimals = coeff.split('.')[1]?.length || 0;
|
|
27
|
+
return coeffDecimals + Number(exp);
|
|
28
|
+
}
|
|
29
|
+
return str.split('.')[1]?.length || 0;
|
|
30
|
+
}
|
|
31
|
+
export function partiallyFormatNumbers(num, decimalPlaces, shouldRound = false, isRoundFromThousand = false) {
|
|
32
|
+
if (!num || !decimalPlaces)
|
|
33
|
+
return num;
|
|
34
|
+
const limit = isRoundFromThousand ? 1000 : 1000000;
|
|
35
|
+
// if the number is very large(above > 1K)
|
|
36
|
+
if (Math.abs(num) >= limit)
|
|
37
|
+
return formatNumbers(num, Number(decimalPlaces), shouldRound);
|
|
38
|
+
return Number(num || 0).toFixed(Number(decimalPlaces));
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Formats delta values to always show exactly 1 decimal place
|
|
42
|
+
* @param num - The numeric value to format
|
|
43
|
+
* @returns Formatted string with exactly 1 decimal place
|
|
44
|
+
*/
|
|
45
|
+
export function formatDelta(num) {
|
|
46
|
+
if (typeof num !== 'number')
|
|
47
|
+
return String(num);
|
|
48
|
+
return num.toFixed(1);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Compact HEADCOUNT: an exact integer under 1000, then one decimal at most.
|
|
52
|
+
* `840 → "840"`, `5230 → "5.2k"`, `1_250_000 → "1.3M"`.
|
|
53
|
+
*
|
|
54
|
+
* Deliberately not `formatNumbers`, which is a PRICE/VOLUME formatter: it
|
|
55
|
+
* renders 12 as "12.0" and uses an uppercase "K". Neither is right for
|
|
56
|
+
* "12 watching" — a count of people is a whole number, and the design's scale
|
|
57
|
+
* is lowercase k / uppercase M.
|
|
58
|
+
*/
|
|
59
|
+
export function formatCompactCount(count) {
|
|
60
|
+
if (count >= 1_000_000)
|
|
61
|
+
return `${parseFloat((count / 1_000_000).toFixed(1))}M`;
|
|
62
|
+
if (count >= 1000)
|
|
63
|
+
return `${parseFloat((count / 1000).toFixed(1))}k`;
|
|
64
|
+
return String(count);
|
|
65
|
+
}
|
|
66
|
+
export function formatNumbers(num, defaultDecimalPlaces = 1, shouldRound = true) {
|
|
67
|
+
if (typeof num != 'number')
|
|
68
|
+
return num;
|
|
69
|
+
const THOUSAND = 1000.0;
|
|
70
|
+
const MILLION = 1000 * THOUSAND;
|
|
71
|
+
const absNum = Math.abs(num);
|
|
72
|
+
if (absNum >= MILLION) {
|
|
73
|
+
let number = num;
|
|
74
|
+
if (shouldRound)
|
|
75
|
+
number = (Math.round((num * 10) / MILLION) / 10) * MILLION;
|
|
76
|
+
return changeNumberFormat(number, defaultDecimalPlaces);
|
|
77
|
+
}
|
|
78
|
+
else if (absNum >= THOUSAND) {
|
|
79
|
+
let numInKs = num / THOUSAND;
|
|
80
|
+
let digits = 1;
|
|
81
|
+
if (Math.abs(numInKs) >= 100) {
|
|
82
|
+
numInKs = Math.round(numInKs);
|
|
83
|
+
digits = 0;
|
|
84
|
+
}
|
|
85
|
+
return numInKs.toFixed(digits) + 'K';
|
|
86
|
+
}
|
|
87
|
+
return num.toFixed(defaultDecimalPlaces);
|
|
88
|
+
}
|
|
89
|
+
export function changeNumberFormat(value, precision) {
|
|
90
|
+
// Nine Zeroes for Billions
|
|
91
|
+
const absValue = Math.abs(Number(value));
|
|
92
|
+
if (absValue >= 1.0e9) {
|
|
93
|
+
return (Number(value) / 1.0e9).toFixed(precision) + 'B';
|
|
94
|
+
}
|
|
95
|
+
else if (absValue >= 1.0e6) {
|
|
96
|
+
return (Number(value) / 1.0e6).toFixed(precision) + 'M';
|
|
97
|
+
}
|
|
98
|
+
else if (absValue >= 1.0e3) {
|
|
99
|
+
return (Number(value) / 1.0e3).toFixed(precision) + 'K';
|
|
100
|
+
}
|
|
101
|
+
return Number(value).toFixed(precision);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Compact positive-volume numeral with sub-unit honesty: values >= 1 keep the
|
|
105
|
+
* `changeNumberFormat(value, 1)` convention (K/M/B suffixes, 1 decimal), while
|
|
106
|
+
* values in (0, 1) render with up to 4 significant digits (plain decimal,
|
|
107
|
+
* trailing zeros trimmed) so BTC-sized prints like 0.0432 never collapse to
|
|
108
|
+
* "0.0". Zero and non-finite input render as '' (callers decide their own
|
|
109
|
+
* empty/zero glyph).
|
|
110
|
+
*/
|
|
111
|
+
export function formatAdaptiveVolume(value) {
|
|
112
|
+
if (!Number.isFinite(value) || value <= 0)
|
|
113
|
+
return '';
|
|
114
|
+
if (value >= 1)
|
|
115
|
+
return changeNumberFormat(value, 1);
|
|
116
|
+
// 4 significant digits for 0.x values; toFixed keeps the plain-decimal form
|
|
117
|
+
// (no exponent) for arbitrarily small prints. Cap the decimals defensively.
|
|
118
|
+
const decimals = Math.min(20, 3 - Math.floor(Math.log10(value)));
|
|
119
|
+
const fixed = value.toFixed(decimals);
|
|
120
|
+
return fixed.includes('.') ? fixed.replace(/0+$/, '').replace(/\.$/, '') : fixed;
|
|
121
|
+
}
|
|
122
|
+
export function safeDivide(a, b) {
|
|
123
|
+
if (b === 0)
|
|
124
|
+
return 0;
|
|
125
|
+
return a / b;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Significant digits a ticker price keeps however small it is. Five decimals
|
|
129
|
+
* under 10 hold three or more down to 0.001; below that they round a live
|
|
130
|
+
* price toward zero (PEPE at 0.00000487 read "0.00000"), so the decimals grow
|
|
131
|
+
* with the leading zeros instead.
|
|
132
|
+
*/
|
|
133
|
+
const TICKER_MIN_SIGNIFICANT_DIGITS = 3;
|
|
134
|
+
const MAX_TICKER_DECIMALS = 20;
|
|
135
|
+
/**
|
|
136
|
+
* The price text the ticker surfaces print: the desktop ticker bar, the
|
|
137
|
+
* orderbook ticker, and the mobile header, legend and stats, so one symbol
|
|
138
|
+
* reads the same number on every one of them. The decimals come from the
|
|
139
|
+
* price's own magnitude, because the FE holds no per-symbol tick size and the
|
|
140
|
+
* chart's axis precision moves with every zoom. `reference` is the price a
|
|
141
|
+
* difference belongs to: a 24h change prints at its price's resolution.
|
|
142
|
+
*/
|
|
143
|
+
export function formatPriceByMagnitude(value, reference = value) {
|
|
144
|
+
const ladder = value >= 10000 ? 1 : value >= 1000 ? 2 : value >= 100 ? 3 : value >= 10 ? 4 : 5;
|
|
145
|
+
const magnitude = Math.abs(reference);
|
|
146
|
+
const floor = magnitude > 0 && magnitude < 1
|
|
147
|
+
? Math.min(TICKER_MIN_SIGNIFICANT_DIGITS - 1 - Math.floor(Math.log10(magnitude)), MAX_TICKER_DECIMALS)
|
|
148
|
+
: 0;
|
|
149
|
+
const decimals = Math.max(ladder, floor);
|
|
150
|
+
return value >= 10000
|
|
151
|
+
? value.toLocaleString('en-US', { minimumFractionDigits: decimals, maximumFractionDigits: decimals })
|
|
152
|
+
: value.toFixed(decimals);
|
|
153
|
+
}
|
|
154
|
+
export function titlePriceDirection(curr, prev, lastGlyph = '') {
|
|
155
|
+
if (typeof curr !== 'number' || typeof prev !== 'number' || !Number.isFinite(curr) || !Number.isFinite(prev)) {
|
|
156
|
+
return '';
|
|
157
|
+
}
|
|
158
|
+
if (curr > prev)
|
|
159
|
+
return '▲';
|
|
160
|
+
if (curr < prev)
|
|
161
|
+
return '▼';
|
|
162
|
+
return lastGlyph;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* The tab title's price: the ticker bar's text (formatPriceByMagnitude) with
|
|
166
|
+
* thousands grouped. Never the price axis step: the engine computes that only
|
|
167
|
+
* when it paints, so a chart mounted in a background tab printed the raw float
|
|
168
|
+
* (0.9992810927390368), and an axis stretched by one stray value cut the same
|
|
169
|
+
* ratio to "1.00". Negative values (spread formulas) keep the magnitude rule.
|
|
170
|
+
*/
|
|
171
|
+
export function formatTitlePrice(price) {
|
|
172
|
+
if (!Number.isFinite(price))
|
|
173
|
+
return '';
|
|
174
|
+
const [whole, fraction] = formatPriceByMagnitude(Math.abs(price)).replace(/,/g, '').split('.');
|
|
175
|
+
const grouped = whole.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
|
176
|
+
const text = fraction === undefined ? grouped : `${grouped}.${fraction}`;
|
|
177
|
+
return price < 0 ? `-${text}` : text;
|
|
178
|
+
}
|
|
179
|
+
// Keyed by the chart instance so a destroyed chart takes its entry with it (no retainer).
|
|
180
|
+
const titlePricesByChart = new WeakMap();
|
|
181
|
+
export function formatChartTitlePrice(price, tc, context) {
|
|
182
|
+
const stored = titlePricesByChart.get(tc);
|
|
183
|
+
const previous = stored?.symbolKey === context.symbolKey ? stored : undefined;
|
|
184
|
+
const glyph = titlePriceDirection(price, previous ? previous.price : context.previousPrice, previous?.glyph);
|
|
185
|
+
titlePricesByChart.set(tc, { symbolKey: context.symbolKey, price, glyph });
|
|
186
|
+
const formattedPrice = formatTitlePrice(price);
|
|
187
|
+
return glyph ? `${formattedPrice} ${glyph}` : formattedPrice;
|
|
188
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isOpraGoverned(exchange: string | undefined | null): boolean;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether an exchange is OPRA-governed (a pure leaf split out of gate-plane.util, which re-exports it): the trading
|
|
3
|
+
* day and the venue checks read it without the gate plane's socket-slot table. The governed codes are the package's
|
|
4
|
+
* byte copy of the OPRA interface's list (pinned equal to it). It rides the `@orangecharts/wrun-chart-host` package
|
|
5
|
+
* (docs/features/kscript/wrun/wrun-chart-host.md).
|
|
6
|
+
*/
|
|
7
|
+
import { normalizeExchangeCode } from '../chart/cme-realtime.util.js';
|
|
8
|
+
import { OPRA_GOVERNED_EXCHANGES } from '../../constants/governed-exchanges.constants.js';
|
|
9
|
+
const OPRA_GOVERNED_EXCHANGE_SET = new Set(OPRA_GOVERNED_EXCHANGES);
|
|
10
|
+
export function isOpraGoverned(exchange) {
|
|
11
|
+
const code = normalizeExchangeCode(exchange);
|
|
12
|
+
return code !== null && OPRA_GOVERNED_EXCHANGE_SET.has(code);
|
|
13
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The auto price unit of a profile canvas (WRUN guardrails G1): where a
|
|
3
|
+
* `row_height: "auto"` takes its unit when the script names none. The unit
|
|
4
|
+
* comes from what the venue serves, else from the bars themselves, never
|
|
5
|
+
* from the decimals a close prints (a BTC close printing one decimal once
|
|
6
|
+
* made $0.10 TPO rows, 22,946 of them over 16 days):
|
|
7
|
+
*
|
|
8
|
+
* 1. bucket the served bucket width of the child's own cells
|
|
9
|
+
* 2. block the served TPO block for the chart market (the native
|
|
10
|
+
* TPO's catalog mirror), else the instrument tick the engine
|
|
11
|
+
* holds (CME venues): both are venue facts
|
|
12
|
+
* 3. bar-range the median positive candle range / 4, snapped to 1, 2, 5 x 10^k
|
|
13
|
+
* 4. none no bar with a positive range (nothing to size by) reads 1
|
|
14
|
+
*
|
|
15
|
+
* No unit floors at the chart's price step: titan's `priceStep` is the axis
|
|
16
|
+
* label spacing (100 to 500 on BTC, moving with zoom and pane height), not
|
|
17
|
+
* an instrument tick. The caller decides what the unit becomes: the TPO
|
|
18
|
+
* multiplies every unit but the bar range by the native row table and takes
|
|
19
|
+
* a bar-range unit as is (it already scales with the interval).
|
|
20
|
+
*
|
|
21
|
+
* The rows-per-period cap lives here too: a canvas folds its period rows,
|
|
22
|
+
* and while any period holds more than WRUN_MAX_ROWS_PER_PERIOD levels the
|
|
23
|
+
* row height doubles (at most WRUN_ROW_CAP_MAX_DOUBLINGS times) and the
|
|
24
|
+
* author is told (wrun-canvases.util).
|
|
25
|
+
*
|
|
26
|
+
* A leaf: no store, worker, dialog or control import.
|
|
27
|
+
*/
|
|
28
|
+
export type WrunAutoRowKind = 'tpo' | 'footprint' | 'profile';
|
|
29
|
+
export interface WrunAutoRowInput {
|
|
30
|
+
kind: WrunAutoRowKind;
|
|
31
|
+
/** The served bucket width when the child has cells (volume_profile rows); wins when present. */
|
|
32
|
+
bucketWidth?: number;
|
|
33
|
+
/** ctx.tpoBlockSize ?? ctx.priceTick for tpo (the served block, else the CME engine tick);
|
|
34
|
+
* undefined on a mirror miss off CME. */
|
|
35
|
+
blockSize?: number;
|
|
36
|
+
/** Candle rows [ts, o, h, l, c, v]; the bar-range fallback reads their high-low. */
|
|
37
|
+
bars?: ReadonlyArray<ArrayLike<number>>;
|
|
38
|
+
}
|
|
39
|
+
export interface WrunAutoRowUnit {
|
|
40
|
+
unit: number;
|
|
41
|
+
source: 'bucket' | 'block' | 'bar-range' | 'none';
|
|
42
|
+
}
|
|
43
|
+
/** The most price levels one period row may hold before the row height coarsens. */
|
|
44
|
+
export declare const WRUN_MAX_ROWS_PER_PERIOD = 512;
|
|
45
|
+
/** The most times the cap doubles a row height; past it the fold is accepted as is. */
|
|
46
|
+
export declare const WRUN_ROW_CAP_MAX_DOUBLINGS = 6;
|
|
47
|
+
/** 1, 2, 5 x 10^k at or above `value` (value <= 0 or non-finite -> the floor). */
|
|
48
|
+
export declare function snapNiceUnit(value: number, floor: number): number;
|
|
49
|
+
/**
|
|
50
|
+
* The auto unit of a canvas row (the ladder above): the served bucket width,
|
|
51
|
+
* else the served block or the CME engine tick, else the snapped median bar
|
|
52
|
+
* range / 4, else 1. Nothing floors it.
|
|
53
|
+
*/
|
|
54
|
+
export declare function wrunAutoRowUnit(input: WrunAutoRowInput): WrunAutoRowUnit;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The auto price unit of a profile canvas (WRUN guardrails G1): where a
|
|
3
|
+
* `row_height: "auto"` takes its unit when the script names none. The unit
|
|
4
|
+
* comes from what the venue serves, else from the bars themselves, never
|
|
5
|
+
* from the decimals a close prints (a BTC close printing one decimal once
|
|
6
|
+
* made $0.10 TPO rows, 22,946 of them over 16 days):
|
|
7
|
+
*
|
|
8
|
+
* 1. bucket the served bucket width of the child's own cells
|
|
9
|
+
* 2. block the served TPO block for the chart market (the native
|
|
10
|
+
* TPO's catalog mirror), else the instrument tick the engine
|
|
11
|
+
* holds (CME venues): both are venue facts
|
|
12
|
+
* 3. bar-range the median positive candle range / 4, snapped to 1, 2, 5 x 10^k
|
|
13
|
+
* 4. none no bar with a positive range (nothing to size by) reads 1
|
|
14
|
+
*
|
|
15
|
+
* No unit floors at the chart's price step: titan's `priceStep` is the axis
|
|
16
|
+
* label spacing (100 to 500 on BTC, moving with zoom and pane height), not
|
|
17
|
+
* an instrument tick. The caller decides what the unit becomes: the TPO
|
|
18
|
+
* multiplies every unit but the bar range by the native row table and takes
|
|
19
|
+
* a bar-range unit as is (it already scales with the interval).
|
|
20
|
+
*
|
|
21
|
+
* The rows-per-period cap lives here too: a canvas folds its period rows,
|
|
22
|
+
* and while any period holds more than WRUN_MAX_ROWS_PER_PERIOD levels the
|
|
23
|
+
* row height doubles (at most WRUN_ROW_CAP_MAX_DOUBLINGS times) and the
|
|
24
|
+
* author is told (wrun-canvases.util).
|
|
25
|
+
*
|
|
26
|
+
* A leaf: no store, worker, dialog or control import.
|
|
27
|
+
*/
|
|
28
|
+
/** The most price levels one period row may hold before the row height coarsens. */
|
|
29
|
+
export const WRUN_MAX_ROWS_PER_PERIOD = 512;
|
|
30
|
+
/** The most times the cap doubles a row height; past it the fold is accepted as is. */
|
|
31
|
+
export const WRUN_ROW_CAP_MAX_DOUBLINGS = 6;
|
|
32
|
+
/** The bar-range fallback's divisor: a median candle spans four rows. */
|
|
33
|
+
const BAR_RANGE_ROWS = 4;
|
|
34
|
+
/** The nice mantissas, ascending; 10 closes the decade. */
|
|
35
|
+
const NICE_MANTISSAS = [1, 2, 5, 10];
|
|
36
|
+
/** The tolerance a mantissa may sit above a nice step and still snap to it (float noise). */
|
|
37
|
+
const NICE_TOLERANCE = 1e-9;
|
|
38
|
+
function finite(value) {
|
|
39
|
+
return typeof value === 'number' && Number.isFinite(value);
|
|
40
|
+
}
|
|
41
|
+
function positive(value) {
|
|
42
|
+
return finite(value) && value > 0;
|
|
43
|
+
}
|
|
44
|
+
/** A unit trimmed of float noise (the TPO builder's rowPrice rule). */
|
|
45
|
+
function trimmed(value) {
|
|
46
|
+
return Number(value.toPrecision(12));
|
|
47
|
+
}
|
|
48
|
+
/** 1, 2, 5 x 10^k at or above `value` (value <= 0 or non-finite -> the floor). */
|
|
49
|
+
export function snapNiceUnit(value, floor) {
|
|
50
|
+
const lowest = positive(floor) ? floor : 0;
|
|
51
|
+
if (!positive(value))
|
|
52
|
+
return lowest;
|
|
53
|
+
const decade = 10 ** Math.floor(Math.log10(value));
|
|
54
|
+
const mantissa = value / decade;
|
|
55
|
+
const nice = NICE_MANTISSAS.find((step) => mantissa <= step * (1 + NICE_TOLERANCE)) ?? 10;
|
|
56
|
+
return Math.max(trimmed(nice * decade), lowest);
|
|
57
|
+
}
|
|
58
|
+
/** The median high - low of the candle rows with a finite, positive range; undefined without
|
|
59
|
+
* one. A flat bar (high equal to low) says nothing about the price scale and a quiet market
|
|
60
|
+
* prints many (a Polymarket odds chart, an illiquid alt): it never sizes the unit. */
|
|
61
|
+
function medianBarRange(bars) {
|
|
62
|
+
if (bars === undefined || bars.length === 0)
|
|
63
|
+
return undefined;
|
|
64
|
+
const ranges = new Float64Array(bars.length);
|
|
65
|
+
let count = 0;
|
|
66
|
+
for (const bar of bars) {
|
|
67
|
+
if (!bar)
|
|
68
|
+
continue;
|
|
69
|
+
const high = bar[2];
|
|
70
|
+
const low = bar[3];
|
|
71
|
+
if (!finite(high) || !finite(low) || high <= low)
|
|
72
|
+
continue;
|
|
73
|
+
ranges[count] = high - low;
|
|
74
|
+
count += 1;
|
|
75
|
+
}
|
|
76
|
+
if (count === 0)
|
|
77
|
+
return undefined;
|
|
78
|
+
const sorted = ranges.subarray(0, count).sort();
|
|
79
|
+
const middle = count >> 1;
|
|
80
|
+
return count % 2 === 1 ? sorted[middle] : (sorted[middle - 1] + sorted[middle]) / 2;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* The auto unit of a canvas row (the ladder above): the served bucket width,
|
|
84
|
+
* else the served block or the CME engine tick, else the snapped median bar
|
|
85
|
+
* range / 4, else 1. Nothing floors it.
|
|
86
|
+
*/
|
|
87
|
+
export function wrunAutoRowUnit(input) {
|
|
88
|
+
if (positive(input.bucketWidth))
|
|
89
|
+
return { unit: input.bucketWidth, source: 'bucket' };
|
|
90
|
+
if (positive(input.blockSize))
|
|
91
|
+
return { unit: input.blockSize, source: 'block' };
|
|
92
|
+
const range = medianBarRange(input.bars);
|
|
93
|
+
if (positive(range))
|
|
94
|
+
return { unit: snapNiceUnit(range / BAR_RANGE_ROWS, 0), source: 'bar-range' };
|
|
95
|
+
return { unit: 1, source: 'none' };
|
|
96
|
+
}
|