sveltekit-ui 1.1.71 → 1.1.73
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/.vercel/output/config.json +64 -0
- package/.vercel/output/functions/![-]/catchall.func/.svelte-kit/output/server/chunks/Checkbox.js +285 -0
- package/.vercel/output/functions/![-]/catchall.func/.svelte-kit/output/server/chunks/client.js +1609 -0
- package/.vercel/output/functions/![-]/catchall.func/.svelte-kit/output/server/chunks/client2.js +5320 -0
- package/.vercel/output/functions/![-]/catchall.func/.svelte-kit/output/server/chunks/docs.js +26418 -0
- package/.vercel/output/functions/![-]/catchall.func/.svelte-kit/output/server/chunks/env.js +8 -0
- package/.vercel/output/functions/![-]/catchall.func/.svelte-kit/output/server/chunks/exports.js +371 -0
- package/.vercel/output/functions/![-]/catchall.func/.svelte-kit/output/server/chunks/index.svelte.js +869 -0
- package/.vercel/output/functions/![-]/catchall.func/.svelte-kit/output/server/chunks/index2.svelte.js +220 -0
- package/.vercel/output/functions/![-]/catchall.func/.svelte-kit/output/server/chunks/index3.svelte.js +914 -0
- package/.vercel/output/functions/![-]/catchall.func/.svelte-kit/output/server/chunks/index4.svelte.js +2035 -0
- package/.vercel/output/functions/![-]/catchall.func/.svelte-kit/output/server/chunks/internal.js +823 -0
- package/.vercel/output/functions/![-]/catchall.func/.svelte-kit/output/server/chunks/internal2.js +34 -0
- package/.vercel/output/functions/![-]/catchall.func/.svelte-kit/output/server/chunks/server.js +4203 -0
- package/.vercel/output/functions/![-]/catchall.func/.svelte-kit/output/server/chunks/shared.js +298 -0
- package/.vercel/output/functions/![-]/catchall.func/.svelte-kit/output/server/chunks/state.js +76 -0
- package/.vercel/output/functions/![-]/catchall.func/.svelte-kit/output/server/chunks/utils.js +903 -0
- package/.vercel/output/functions/![-]/catchall.func/.svelte-kit/output/server/entries/endpoints/sitemap.xml/_server.js +223 -0
- package/.vercel/output/functions/![-]/catchall.func/.svelte-kit/output/server/entries/fallbacks/error.svelte.js +10 -0
- package/.vercel/output/functions/![-]/catchall.func/.svelte-kit/output/server/entries/hooks.server.js +7 -0
- package/.vercel/output/functions/![-]/catchall.func/.svelte-kit/output/server/entries/pages/_layout.js +8 -0
- package/.vercel/output/functions/![-]/catchall.func/.svelte-kit/output/server/entries/pages/_layout.svelte.js +826 -0
- package/.vercel/output/functions/![-]/catchall.func/.svelte-kit/output/server/entries/pages/_page.svelte.js +345 -0
- package/.vercel/output/functions/![-]/catchall.func/.svelte-kit/output/server/entries/pages/components/_component_/_page.svelte.js +9431 -0
- package/.vercel/output/functions/![-]/catchall.func/.svelte-kit/output/server/entries/pages/test/_page.svelte.js +50 -0
- package/.vercel/output/functions/![-]/catchall.func/.svelte-kit/output/server/entries/pages/test2/_page.svelte.js +10909 -0
- package/.vercel/output/functions/![-]/catchall.func/.svelte-kit/output/server/entries/pages/test3/_page.server.js +9466 -0
- package/.vercel/output/functions/![-]/catchall.func/.svelte-kit/output/server/entries/pages/test3/_page.svelte.js +99 -0
- package/.vercel/output/functions/![-]/catchall.func/.svelte-kit/output/server/index.js +3515 -0
- package/.vercel/output/functions/![-]/catchall.func/.svelte-kit/output/server/nodes/0.js +10 -0
- package/.vercel/output/functions/![-]/catchall.func/.svelte-kit/output/server/nodes/1.js +8 -0
- package/.vercel/output/functions/![-]/catchall.func/.svelte-kit/output/server/nodes/2.js +8 -0
- package/.vercel/output/functions/![-]/catchall.func/.svelte-kit/output/server/nodes/3.js +8 -0
- package/.vercel/output/functions/![-]/catchall.func/.svelte-kit/output/server/nodes/4.js +8 -0
- package/.vercel/output/functions/![-]/catchall.func/.svelte-kit/output/server/nodes/5.js +8 -0
- package/.vercel/output/functions/![-]/catchall.func/.svelte-kit/output/server/nodes/6.js +10 -0
- package/.vercel/output/functions/![-]/catchall.func/.svelte-kit/vercel-tmp/index.js +42 -0
- package/.vercel/output/functions/![-]/catchall.func/.svelte-kit/vercel-tmp/manifest.js +78 -0
- package/.vercel/output/functions/![-]/catchall.func/.vc-config.json +11 -0
- package/.vercel/output/functions/![-]/catchall.func/package.json +1 -0
- package/.vercel/output/static/_app/immutable/assets/0.D1AvWWSC.css +1 -0
- package/.vercel/output/static/_app/immutable/assets/2.D3o4PLbP.css +1 -0
- package/.vercel/output/static/_app/immutable/assets/3.DK3uvf0v.css +1 -0
- package/.vercel/output/static/_app/immutable/assets/6.BnjxUmH7.css +1 -0
- package/.vercel/output/static/_app/immutable/assets/Checkbox.CJEZNdbe.css +1 -0
- package/.vercel/output/static/_app/immutable/assets/alloy-voice-sample.PT8wH6s9.mp3 +0 -0
- package/.vercel/output/static/_app/immutable/assets/docs.CDTCxDP7.css +1 -0
- package/.vercel/output/static/_app/immutable/assets/echo-voice-sample.pUPbplSr.mp3 +0 -0
- package/.vercel/output/static/_app/immutable/assets/fable-voice-sample.DLFL6517.mp3 +0 -0
- package/.vercel/output/static/_app/immutable/assets/index.CCk09GbO.css +1 -0
- package/.vercel/output/static/_app/immutable/assets/index.CYJKF3O7.css +1 -0
- package/.vercel/output/static/_app/immutable/assets/index.DCBl_q1O.css +1 -0
- package/.vercel/output/static/_app/immutable/assets/index.DatXVBdh.css +1 -0
- package/.vercel/output/static/_app/immutable/assets/nova-voice-sample.DWaD-VGb.mp3 +0 -0
- package/.vercel/output/static/_app/immutable/assets/onyx-voice-sample.DMRXZHJF.mp3 +0 -0
- package/.vercel/output/static/_app/immutable/assets/shimmer-voice-sample.Cho2QgFr.mp3 +0 -0
- package/.vercel/output/static/_app/immutable/chunks/BLfjN0VF.js +1 -0
- package/.vercel/output/static/_app/immutable/chunks/BddFMzPD.js +1 -0
- package/.vercel/output/static/_app/immutable/chunks/Bjy-W4x2.js +81 -0
- package/.vercel/output/static/_app/immutable/chunks/BqBxxYmA.js +14 -0
- package/.vercel/output/static/_app/immutable/chunks/CJM4yLow.js +25 -0
- package/.vercel/output/static/_app/immutable/chunks/CRYWmS0s.js +19 -0
- package/.vercel/output/static/_app/immutable/chunks/CZIC9Qgj.js +11 -0
- package/.vercel/output/static/_app/immutable/chunks/CvmT24cS.js +3 -0
- package/.vercel/output/static/_app/immutable/chunks/D566uQC1.js +2 -0
- package/.vercel/output/static/_app/immutable/chunks/SvbogVTv.js +119 -0
- package/.vercel/output/static/_app/immutable/chunks/_g5tLpFU.js +3 -0
- package/.vercel/output/static/_app/immutable/chunks/u3U-vofW.js +15 -0
- package/.vercel/output/static/_app/immutable/chunks/xihTtKlq.js +1 -0
- package/.vercel/output/static/_app/immutable/entry/app.td6ThZ7k.js +2 -0
- package/.vercel/output/static/_app/immutable/entry/start.2Q3_BAwG.js +1 -0
- package/.vercel/output/static/_app/immutable/nodes/0.C2Ckbl4e.js +8 -0
- package/.vercel/output/static/_app/immutable/nodes/1.DLziSd8k.js +1 -0
- package/.vercel/output/static/_app/immutable/nodes/2.BX7tnCWG.js +58 -0
- package/.vercel/output/static/_app/immutable/nodes/3.CEpCPaPY.js +22 -0
- package/.vercel/output/static/_app/immutable/nodes/4.Ux2eRH04.js +1 -0
- package/.vercel/output/static/_app/immutable/nodes/5.Cv9G2Xkm.js +1 -0
- package/.vercel/output/static/_app/immutable/nodes/6.DcYd4Shl.js +1 -0
- package/.vercel/output/static/_app/version.json +1 -0
- package/.vercel/output/static/android-chrome-192x192.png +0 -0
- package/.vercel/output/static/android-chrome-512x512.png +0 -0
- package/.vercel/output/static/apple-touch-icon.png +0 -0
- package/.vercel/output/static/favicon-inactive.svg +4 -0
- package/.vercel/output/static/favicon-themed.svg +11 -0
- package/.vercel/output/static/favicon-transparent-bg.webp +0 -0
- package/.vercel/output/static/favicon-transparent.webp +0 -0
- package/.vercel/output/static/favicon.png +0 -0
- package/.vercel/output/static/favicon.svg +3 -0
- package/.vercel/output/static/favicon.webp +0 -0
- package/.vercel/output/static/fonts/ProximaVara.woff2 +0 -0
- package/.vercel/output/static/fonts/Quicksand-VariableFont.woff2 +0 -0
- package/.vercel/output/static/fonts/RobotoSerif-VariableFont.woff2 +0 -0
- package/.vercel/output/static/full_logo.webp +0 -0
- package/.vercel/output/static/icon.png +0 -0
- package/.vercel/output/static/site.webmanifest +21 -0
- package/.vercel/output/static/thumbnail.png +0 -0
- package/.vercel/output/static/thumbnail.webp +0 -0
- package/package.json +4 -4
|
@@ -0,0 +1,2035 @@
|
|
|
1
|
+
import { C as escape_html, S as attr, i as derived, l as stringify, n as attr_style, o as ensure_array_like, t as attr_class } from "./server.js";
|
|
2
|
+
import { i as color_var, l as deep_copy } from "./client2.js";
|
|
3
|
+
//#region src/lib/Components/Chart/Klines/index.svelte
|
|
4
|
+
function Klines($$renderer, $$props) {
|
|
5
|
+
$$renderer.component(($$renderer) => {
|
|
6
|
+
let { dataset } = $$props;
|
|
7
|
+
let is_boxed = derived(() => dataset?.colors.length < 2);
|
|
8
|
+
$$renderer.push(`<!--[-->`);
|
|
9
|
+
const each_array = ensure_array_like(dataset.data);
|
|
10
|
+
for (let $$index = 0, $$length = each_array.length; $$index < $$length; $$index++) {
|
|
11
|
+
let kline = each_array[$$index];
|
|
12
|
+
$$renderer.push(`<div class="kline_container svelte-1ss81hy"${attr_style(` width: ${stringify(dataset.kline_width_pd * 100)}%; height: ${stringify(kline.kline_height * 100)}%; left: ${stringify(kline.x * 100)}%; bottom: ${stringify(kline.l * 100)}%; --color_one: ${stringify(dataset?.color_one)}; --color_two: ${stringify(dataset?.color_two)}; `)}><div class="kline svelte-1ss81hy"><div${attr_class("wick top_wick svelte-1ss81hy", void 0, {
|
|
13
|
+
"inc": kline.is_closed_higher || is_boxed(),
|
|
14
|
+
"dec": !kline.is_closed_higher && !is_boxed()
|
|
15
|
+
})}${attr_style(` height: ${stringify(kline.kline_top_wick_height_pd * 100)}%; top: 0; `)}></div> <div${attr_class("box svelte-1ss81hy", void 0, {
|
|
16
|
+
"inc": kline.is_closed_higher,
|
|
17
|
+
"dec": !kline.is_closed_higher && !is_boxed(),
|
|
18
|
+
"dec_box": !kline.is_closed_higher && is_boxed()
|
|
19
|
+
})}${attr_style(`min-height: 2px; top: ${stringify(kline.kline_top_wick_height_pd * 100)}%; bottom: ${stringify(kline.kline_bottom_wick_height_pd * 100)}%;`)}></div> <div${attr_class("wick bottom_wick svelte-1ss81hy", void 0, {
|
|
20
|
+
"inc": kline.is_closed_higher || is_boxed(),
|
|
21
|
+
"dec": !kline.is_closed_higher && !is_boxed()
|
|
22
|
+
})}${attr_style(`height: ${stringify(kline.kline_bottom_wick_height_pd * 100)}%; bottom: 0;`)}></div></div></div>`);
|
|
23
|
+
}
|
|
24
|
+
$$renderer.push(`<!--]-->`);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
//#region src/lib/Components/Chart/index.svelte
|
|
29
|
+
function Chart($$renderer, $$props) {
|
|
30
|
+
$$renderer.component(($$renderer) => {
|
|
31
|
+
let { manager } = $$props;
|
|
32
|
+
$$renderer.push(`<div class="grid svelte-svnvq7"${attr_style(`--y_axis_width: ${stringify(manager?.y_axis_width)}rem; --x_axis_height: ${stringify(manager?.x_axis_height)}rem;`)}>`);
|
|
33
|
+
if (manager?.chart_prepped) {
|
|
34
|
+
$$renderer.push("<!--[0-->");
|
|
35
|
+
$$renderer.push(`<!--[-->`);
|
|
36
|
+
const each_array = ensure_array_like(manager?.chart_prepped.frames);
|
|
37
|
+
for (let i = 0, $$length = each_array.length; i < $$length; i++) {
|
|
38
|
+
let frame = each_array[i];
|
|
39
|
+
$$renderer.push(`<div class="frame svelte-svnvq7"${attr_style(`grid-area: ${stringify(1 + i)} / 1 / ${stringify(2 + i)} / 2; aspect-ratio: ${stringify(frame.aspect_ratio)}; --frame_wid: ${stringify(manager?.grid_width - manager?.y_axis_width)}px`)}>`);
|
|
40
|
+
if (Array.isArray(manager?.chart_prepped?.x_axis_tics)) {
|
|
41
|
+
$$renderer.push("<!--[0-->");
|
|
42
|
+
$$renderer.push(`<!--[-->`);
|
|
43
|
+
const each_array_1 = ensure_array_like(manager?.chart_prepped?.x_axis_tics);
|
|
44
|
+
for (let $$index = 0, $$length = each_array_1.length; $$index < $$length; $$index++) {
|
|
45
|
+
let xtic = each_array_1[$$index];
|
|
46
|
+
$$renderer.push(`<div class="x_line svelte-svnvq7"${attr_style(`--left: ${stringify(xtic?.norm * 100)}%;`)}></div>`);
|
|
47
|
+
}
|
|
48
|
+
$$renderer.push(`<!--]-->`);
|
|
49
|
+
} else $$renderer.push("<!--[-1-->");
|
|
50
|
+
$$renderer.push(`<!--]--> `);
|
|
51
|
+
if (Array.isArray(frame?.shared_y_axiss[frame?.shown_y_axis_index]?.y_axis_tics)) {
|
|
52
|
+
$$renderer.push("<!--[0-->");
|
|
53
|
+
$$renderer.push(`<!--[-->`);
|
|
54
|
+
const each_array_2 = ensure_array_like(frame?.shared_y_axiss[frame?.shown_y_axis_index]?.y_axis_tics);
|
|
55
|
+
for (let $$index_1 = 0, $$length = each_array_2.length; $$index_1 < $$length; $$index_1++) {
|
|
56
|
+
let ytic = each_array_2[$$index_1];
|
|
57
|
+
$$renderer.push(`<div class="y_line svelte-svnvq7"${attr_style(`--bottom: ${stringify(ytic?.norm * 100)}%;`)}></div>`);
|
|
58
|
+
}
|
|
59
|
+
$$renderer.push(`<!--]-->`);
|
|
60
|
+
} else $$renderer.push("<!--[-1-->");
|
|
61
|
+
$$renderer.push(`<!--]--> <!--[-->`);
|
|
62
|
+
const each_array_3 = ensure_array_like(frame.shared_y_axiss);
|
|
63
|
+
for (let $$index_6 = 0, $$length = each_array_3.length; $$index_6 < $$length; $$index_6++) {
|
|
64
|
+
let shared_y_axis = each_array_3[$$index_6];
|
|
65
|
+
$$renderer.push(`<!--[-->`);
|
|
66
|
+
const each_array_4 = ensure_array_like(shared_y_axis.datasets);
|
|
67
|
+
for (let i = 0, $$length = each_array_4.length; i < $$length; i++) {
|
|
68
|
+
let dataset = each_array_4[i];
|
|
69
|
+
$$renderer.push(`<div${attr_style(`position: absolute; height: 100%; width: 100%; z-index=${stringify(i + 1)}`)}>`);
|
|
70
|
+
if (!manager?.datasets || !manager?.datasets?.[dataset?.dataset_id]?.data) $$renderer.push("<!--[0-->");
|
|
71
|
+
else if (dataset.type === "klines") {
|
|
72
|
+
$$renderer.push("<!--[1-->");
|
|
73
|
+
Klines($$renderer, { dataset });
|
|
74
|
+
} else if (dataset.type === "points") {
|
|
75
|
+
$$renderer.push("<!--[2-->");
|
|
76
|
+
$$renderer.push(`<!--[-->`);
|
|
77
|
+
const each_array_5 = ensure_array_like(dataset.data);
|
|
78
|
+
for (let $$index_2 = 0, $$length = each_array_5.length; $$index_2 < $$length; $$index_2++) {
|
|
79
|
+
let point = each_array_5[$$index_2];
|
|
80
|
+
$$renderer.push(`<div${attr_style(`left: ${stringify(point.x * 100)}%; bottom: ${stringify(point.y * 100)}%; position: absolute; box-sizing: border-box; padding-left: 1px; padding-right: 1px; width: 4px; height: 4px; border-radius: 50%; transform: translate(-50%, 50%); border: 1px solid ${stringify(dataset?.color_one)}; background-color: ${stringify(dataset?.color_two)};`)}></div>`);
|
|
81
|
+
}
|
|
82
|
+
$$renderer.push(`<!--]-->`);
|
|
83
|
+
} else if (dataset.type === "path") {
|
|
84
|
+
$$renderer.push("<!--[3-->");
|
|
85
|
+
$$renderer.push(`<svg width="100%" height="100%" viewBox="0 0 100 100" preserveAspectRatio="none"><path${attr("d", dataset?.d)}${attr_style(`fill:none;stroke-width:.2;stroke:${stringify(dataset?.color_one)}`)}></path><!--[-->`);
|
|
86
|
+
const each_array_6 = ensure_array_like(dataset?.data);
|
|
87
|
+
for (let $$index_3 = 0, $$length = each_array_6.length; $$index_3 < $$length; $$index_3++) {
|
|
88
|
+
let datapoint = each_array_6[$$index_3];
|
|
89
|
+
$$renderer.push(`<circle${attr("cx", 100 * datapoint.x)}${attr("cy", 100 - datapoint.y * 100)}${attr("r", .3)}${attr_style(`fill:${stringify(dataset?.color_two)};`)}></circle>`);
|
|
90
|
+
}
|
|
91
|
+
$$renderer.push(`<!--]--></svg>`);
|
|
92
|
+
} else if (dataset.type === "lines") {
|
|
93
|
+
$$renderer.push("<!--[4-->");
|
|
94
|
+
$$renderer.push(`<svg width="100%" height="100%" viewBox="0 0 100 100" preserveAspectRatio="none"><!--[-->`);
|
|
95
|
+
const each_array_7 = ensure_array_like(dataset?.data);
|
|
96
|
+
for (let $$index_4 = 0, $$length = each_array_7.length; $$index_4 < $$length; $$index_4++) {
|
|
97
|
+
let dataline = each_array_7[$$index_4];
|
|
98
|
+
$$renderer.push(`<path${attr("d", `M${stringify(dataline.x1 * 100)} ${stringify(100 - dataline.y1 * 100)} L${stringify(dataline.x2 * 100)} ${stringify(100 - dataline.y2 * 100)}`)}${attr_style(`fill:none;stroke-width:.2;stroke:${stringify(dataset?.color_one)};`)}></path>`);
|
|
99
|
+
}
|
|
100
|
+
$$renderer.push(`<!--]--></svg>`);
|
|
101
|
+
} else {
|
|
102
|
+
$$renderer.push("<!--[-1-->");
|
|
103
|
+
$$renderer.push(`Other`);
|
|
104
|
+
}
|
|
105
|
+
$$renderer.push(`<!--]--></div>`);
|
|
106
|
+
}
|
|
107
|
+
$$renderer.push(`<!--]-->`);
|
|
108
|
+
}
|
|
109
|
+
$$renderer.push(`<!--]--></div> <div class="floater svelte-svnvq7"${attr_style(`grid-area: ${stringify(1 + i)} / 1 / ${stringify(2 + i)} / 2;`)} role="main">`);
|
|
110
|
+
if (manager?.chart_prepped?.x_hovered_percent_decimal != null && !isNaN(manager?.chart_prepped?.x_hovered_percent_decimal)) {
|
|
111
|
+
$$renderer.push("<!--[0-->");
|
|
112
|
+
$$renderer.push(`<div class="x_floater_line svelte-svnvq7"${attr_style(`--left: ${stringify(manager?.chart_prepped?.x_hovered_percent_decimal * 100)}%;`)}></div>`);
|
|
113
|
+
} else $$renderer.push("<!--[-1-->");
|
|
114
|
+
$$renderer.push(`<!--]--> `);
|
|
115
|
+
if (frame.y_hovered_percent_decimal != null && !isNaN(frame.y_hovered_percent_decimal)) {
|
|
116
|
+
$$renderer.push("<!--[0-->");
|
|
117
|
+
$$renderer.push(`<div class="y_floater_line svelte-svnvq7"${attr_style(`--bottom: ${stringify(frame.y_hovered_percent_decimal * 100)}%;`)}></div>`);
|
|
118
|
+
} else $$renderer.push("<!--[-1-->");
|
|
119
|
+
$$renderer.push(`<!--]--> `);
|
|
120
|
+
if (manager?.chart_prepped?.x_hovered_percent_decimal != null && frame?.y_hovered_percent_decimal != null) {
|
|
121
|
+
$$renderer.push("<!--[0-->");
|
|
122
|
+
$$renderer.push(`<div class="x_hover_label svelte-svnvq7"${attr_style(`--left: ${stringify(manager?.chart_prepped?.x_hovered_percent_decimal * 100)}%;`)}>${escape_html(manager?.chart_prepped?.x_axis_highlight_tic)}</div>`);
|
|
123
|
+
} else $$renderer.push("<!--[-1-->");
|
|
124
|
+
$$renderer.push(`<!--]--></div> <div role="button" tabindex="0" class="y_axis svelte-svnvq7"${attr_style(`grid-area: ${stringify(1 + i)} / 2 / ${stringify(2 + i)} / 3;`)}>`);
|
|
125
|
+
if (frame?.shared_y_axiss[frame?.shown_y_axis_index]?.y_axis_tics) {
|
|
126
|
+
$$renderer.push("<!--[0-->");
|
|
127
|
+
$$renderer.push(`<!--[-->`);
|
|
128
|
+
const each_array_8 = ensure_array_like(frame?.shared_y_axiss[frame?.shown_y_axis_index]?.y_axis_tics);
|
|
129
|
+
for (let $$index_7 = 0, $$length = each_array_8.length; $$index_7 < $$length; $$index_7++) {
|
|
130
|
+
let tic = each_array_8[$$index_7];
|
|
131
|
+
$$renderer.push(`<div class="y_axis_tic_container svelte-svnvq7"${attr_style(`--bottom: ${stringify(tic?.norm * 100)}%;`)}><div class="y_axis_tic_mark svelte-svnvq7"></div> `);
|
|
132
|
+
if (tic?.text) {
|
|
133
|
+
$$renderer.push("<!--[0-->");
|
|
134
|
+
$$renderer.push(`<p class="y_axis_tic_text svelte-svnvq7">${escape_html(tic?.text)}</p>`);
|
|
135
|
+
} else $$renderer.push("<!--[-1-->");
|
|
136
|
+
$$renderer.push(`<!--]--></div>`);
|
|
137
|
+
}
|
|
138
|
+
$$renderer.push(`<!--]-->`);
|
|
139
|
+
} else $$renderer.push("<!--[-1-->");
|
|
140
|
+
$$renderer.push(`<!--]--> `);
|
|
141
|
+
if (frame.y_hovered_percent_decimal != null && !isNaN(frame.y_hovered_percent_decimal)) {
|
|
142
|
+
$$renderer.push("<!--[0-->");
|
|
143
|
+
$$renderer.push(`<div class="y_axis_tic_container y_hover_label svelte-svnvq7"${attr_style(`--bottom: ${stringify(frame.y_hovered_percent_decimal * 100)}%;`)}><p class="y_axis_tic_text svelte-svnvq7">${escape_html(frame?.shared_y_axiss[frame?.shown_y_axis_index]?.y_axis_highlight_tic)}</p></div>`);
|
|
144
|
+
} else $$renderer.push("<!--[-1-->");
|
|
145
|
+
$$renderer.push(`<!--]--></div>`);
|
|
146
|
+
}
|
|
147
|
+
$$renderer.push(`<!--]--> <div class="x_axis svelte-svnvq7"${attr_style(`grid-area: ${stringify(1 + manager?.chart_prepped?.frames.length)} / 1 / ${stringify(2 + manager?.chart_prepped?.frames.length)} / 2;`)}>`);
|
|
148
|
+
if (Array.isArray(manager?.chart_prepped?.x_axis_tics)) {
|
|
149
|
+
$$renderer.push("<!--[0-->");
|
|
150
|
+
$$renderer.push(`<!--[-->`);
|
|
151
|
+
const each_array_9 = ensure_array_like(manager?.chart_prepped?.x_axis_tics);
|
|
152
|
+
for (let $$index_9 = 0, $$length = each_array_9.length; $$index_9 < $$length; $$index_9++) {
|
|
153
|
+
let tic = each_array_9[$$index_9];
|
|
154
|
+
$$renderer.push(`<div class="x_axis_tic_container svelte-svnvq7"${attr_style(`--left: ${stringify(tic?.norm * 100)}%;`)}><div class="x_axis_tic_mark svelte-svnvq7"></div> `);
|
|
155
|
+
if (tic?.text) {
|
|
156
|
+
$$renderer.push("<!--[0-->");
|
|
157
|
+
$$renderer.push(`<p class="x_axis_tic_text svelte-svnvq7">${escape_html(tic?.text)}</p>`);
|
|
158
|
+
} else $$renderer.push("<!--[-1-->");
|
|
159
|
+
$$renderer.push(`<!--]--></div>`);
|
|
160
|
+
}
|
|
161
|
+
$$renderer.push(`<!--]-->`);
|
|
162
|
+
} else $$renderer.push("<!--[-1-->");
|
|
163
|
+
$$renderer.push(`<!--]--></div>`);
|
|
164
|
+
} else $$renderer.push("<!--[-1-->");
|
|
165
|
+
$$renderer.push(`<!--]--></div>`);
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
//#endregion
|
|
169
|
+
//#region src/lib/Components/Chart/index.svelte.js
|
|
170
|
+
function create_chart_manager(config) {
|
|
171
|
+
const y_axis_width = 70;
|
|
172
|
+
const x_axis_height = 30;
|
|
173
|
+
let range_to_show_default = 500;
|
|
174
|
+
let min_visible_bars = 20;
|
|
175
|
+
let x_edge_padding_ratio = .5;
|
|
176
|
+
const min_y_axis_pinch_dist_px = 8;
|
|
177
|
+
let datasets = null;
|
|
178
|
+
let chart_prepped = null;
|
|
179
|
+
let grid_width = null;
|
|
180
|
+
let frame_width = derived(() => grid_width ? grid_width - y_axis_width : 0);
|
|
181
|
+
function set_grid_width(input) {
|
|
182
|
+
grid_width = input;
|
|
183
|
+
if (!chart_prepped) chart_prepped = prep_chart({ ...config?.chart });
|
|
184
|
+
}
|
|
185
|
+
function gen_color(l, c, h, o = 16, is_theme_based = true, dark_l_offset = 0, is_dark_theme = true, is_safari = false) {
|
|
186
|
+
const l_try = l + dark_l_offset;
|
|
187
|
+
return color_var(is_dark_theme ? l_try > 16 ? 16 : l_try < 1 ? 1 : l_try : l, c, h, o, is_theme_based, is_safari);
|
|
188
|
+
}
|
|
189
|
+
function is_finite_num(input) {
|
|
190
|
+
return input !== null && input !== void 0 && Number.isFinite(Number(input));
|
|
191
|
+
}
|
|
192
|
+
function get_min_period_sec_from_chart(chart_like = chart_prepped) {
|
|
193
|
+
let min_period_sec = null;
|
|
194
|
+
if (!Array.isArray(chart_like?.frames)) return min_period_sec;
|
|
195
|
+
for (let frame of chart_like.frames) {
|
|
196
|
+
if (!Array.isArray(frame?.shared_y_axiss)) continue;
|
|
197
|
+
for (let shared_y_axis of frame.shared_y_axiss) {
|
|
198
|
+
if (!Array.isArray(shared_y_axis?.datasets)) continue;
|
|
199
|
+
for (let dataset of shared_y_axis.datasets) {
|
|
200
|
+
const period_x = Number(dataset?.period_x);
|
|
201
|
+
if (Number.isFinite(period_x) && period_x > 0) min_period_sec = min_period_sec == null ? period_x : Math.min(min_period_sec, period_x);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return min_period_sec;
|
|
206
|
+
}
|
|
207
|
+
function get_safe_y_range(low_y, high_y) {
|
|
208
|
+
const range_y = Number(high_y) - Number(low_y);
|
|
209
|
+
if (Number.isFinite(range_y) && range_y > 0) return range_y;
|
|
210
|
+
const center_y = is_finite_num(low_y) && is_finite_num(high_y) ? (Number(low_y) + Number(high_y)) / 2 : is_finite_num(low_y) ? Number(low_y) : is_finite_num(high_y) ? Number(high_y) : 0;
|
|
211
|
+
return Math.max(Math.abs(center_y) * .01, 1e-8);
|
|
212
|
+
}
|
|
213
|
+
function get_padded_y_bounds(low_y, high_y, top_padding_pd = .2, bottom_padding_pd = .2) {
|
|
214
|
+
const safe_top_padding_pd = clamp(top_padding_pd, 0, .45);
|
|
215
|
+
const safe_bottom_padding_pd = clamp(bottom_padding_pd, 0, .45);
|
|
216
|
+
const shown_y_range = get_safe_y_range(low_y, high_y) / clamp(1 - safe_top_padding_pd - safe_bottom_padding_pd, .1, 1);
|
|
217
|
+
return {
|
|
218
|
+
shown_low_y: Number(low_y) - safe_bottom_padding_pd * shown_y_range,
|
|
219
|
+
shown_high_y: Number(high_y) + safe_top_padding_pd * shown_y_range,
|
|
220
|
+
shown_y_range
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
function get_data_range_sec(chart_like = chart_prepped) {
|
|
224
|
+
const data_start_x = chart_like?.all_data_start_x;
|
|
225
|
+
const data_range_sec = chart_like?.all_data_end_x - data_start_x;
|
|
226
|
+
return Number.isFinite(data_range_sec) && data_range_sec > 0 ? data_range_sec : null;
|
|
227
|
+
}
|
|
228
|
+
function get_max_range_sec_from_chart(chart_like = chart_prepped) {
|
|
229
|
+
const data_range_sec = get_data_range_sec(chart_like);
|
|
230
|
+
if (!Number.isFinite(data_range_sec) || data_range_sec <= 0) return data_range_sec;
|
|
231
|
+
return data_range_sec * (1 + x_edge_padding_ratio * 2);
|
|
232
|
+
}
|
|
233
|
+
function get_x_edge_padding_sec(range_sec) {
|
|
234
|
+
return Math.max((Number(range_sec) || 0) * x_edge_padding_ratio, 0);
|
|
235
|
+
}
|
|
236
|
+
const period_to_sec = {
|
|
237
|
+
"5m": 300,
|
|
238
|
+
"10m": 600,
|
|
239
|
+
"15m": 900,
|
|
240
|
+
"20m": 1200,
|
|
241
|
+
"30m": 1800,
|
|
242
|
+
"45m": 2700,
|
|
243
|
+
"1h": 3600,
|
|
244
|
+
"2h": 7200,
|
|
245
|
+
"3h": 10800,
|
|
246
|
+
"4h": 14400,
|
|
247
|
+
"6h": 21600,
|
|
248
|
+
"8h": 28800,
|
|
249
|
+
"12h": 43200,
|
|
250
|
+
"1d": 86400,
|
|
251
|
+
"2d": 172800,
|
|
252
|
+
"3d": 259200,
|
|
253
|
+
"4d": 345600,
|
|
254
|
+
"1w": 604800,
|
|
255
|
+
"2w": 1209600
|
|
256
|
+
};
|
|
257
|
+
function scroll_frame(e, shown_start_x, shown_end_x, min_x_scrollable, max_x_scrollable, frame_width, min_period_sec = 60, max_range_sec = null) {
|
|
258
|
+
const shown_x_range = shown_end_x - shown_start_x;
|
|
259
|
+
const change_sec = (Math.round(shown_x_range * .01 / 60) + 1) * 60;
|
|
260
|
+
const min_range_sec = Math.max(Number(min_visible_bars) || 0, 1) * min_period_sec;
|
|
261
|
+
const max_allowed_range_sec = Number.isFinite(max_range_sec) && max_range_sec > 0 ? max_range_sec : min_period_sec * 1e4;
|
|
262
|
+
let shown_end_x_loc = shown_end_x;
|
|
263
|
+
let shown_start_x_loc = shown_start_x;
|
|
264
|
+
if (e.deltaX < -1) {
|
|
265
|
+
shown_start_x_loc -= change_sec;
|
|
266
|
+
shown_end_x_loc -= change_sec;
|
|
267
|
+
} else if (e.deltaX > 1) {
|
|
268
|
+
shown_start_x_loc += change_sec;
|
|
269
|
+
shown_end_x_loc += change_sec;
|
|
270
|
+
}
|
|
271
|
+
let x_pd = e.offsetX / frame_width;
|
|
272
|
+
if (e.deltaY < -1 && shown_x_range > min_range_sec) {
|
|
273
|
+
shown_start_x_loc += Math.round(change_sec * x_pd / 10) * 10;
|
|
274
|
+
shown_end_x_loc -= Math.round(change_sec * (1 - x_pd) / 10) * 10;
|
|
275
|
+
} else if (e.deltaY > 1 && shown_x_range < max_allowed_range_sec) {
|
|
276
|
+
shown_start_x_loc -= Math.round(change_sec * x_pd / 10) * 10;
|
|
277
|
+
shown_end_x_loc += Math.round(change_sec * (1 - x_pd) / 10) * 10;
|
|
278
|
+
}
|
|
279
|
+
return {
|
|
280
|
+
shown_start_x: shown_start_x_loc,
|
|
281
|
+
shown_end_x: shown_end_x_loc
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
function get_kline_details(o, l, h, c) {
|
|
285
|
+
let res = {};
|
|
286
|
+
const is_closed_higher = c > o ? 1 : 0;
|
|
287
|
+
const kline_height = Math.max(h - l, 1e-8);
|
|
288
|
+
const kline_box_height = Math.abs(c - o);
|
|
289
|
+
let kline_top_wick_height = h - o;
|
|
290
|
+
let kline_bottom_wick_height = c - l;
|
|
291
|
+
if (is_closed_higher) {
|
|
292
|
+
kline_top_wick_height = h - c;
|
|
293
|
+
kline_bottom_wick_height = o - l;
|
|
294
|
+
}
|
|
295
|
+
const kline_box_height_pd = kline_box_height / kline_height;
|
|
296
|
+
const kline_top_wick_height_pd = kline_top_wick_height / kline_height;
|
|
297
|
+
const kline_bottom_wick_height_pd = kline_bottom_wick_height / kline_height;
|
|
298
|
+
const kline_close_height_pd = (c - l) / kline_height;
|
|
299
|
+
res["is_closed_higher"] = is_closed_higher;
|
|
300
|
+
res["kline_height"] = kline_height;
|
|
301
|
+
res["kline_box_height"] = kline_box_height;
|
|
302
|
+
res["kline_top_wick_height"] = kline_top_wick_height;
|
|
303
|
+
res["kline_bottom_wick_height"] = kline_bottom_wick_height;
|
|
304
|
+
res["kline_box_height_pd"] = kline_box_height_pd;
|
|
305
|
+
res["kline_top_wick_height_pd"] = kline_top_wick_height_pd;
|
|
306
|
+
res["kline_bottom_wick_height_pd"] = kline_bottom_wick_height_pd;
|
|
307
|
+
res["kline_close_height_pd"] = kline_close_height_pd;
|
|
308
|
+
return res;
|
|
309
|
+
}
|
|
310
|
+
function time_tic_size(seconds) {
|
|
311
|
+
const tic_options = [
|
|
312
|
+
300,
|
|
313
|
+
600,
|
|
314
|
+
900,
|
|
315
|
+
1200,
|
|
316
|
+
1800,
|
|
317
|
+
2700,
|
|
318
|
+
3600,
|
|
319
|
+
7200,
|
|
320
|
+
10800,
|
|
321
|
+
14400,
|
|
322
|
+
21600,
|
|
323
|
+
28800,
|
|
324
|
+
43200,
|
|
325
|
+
86400,
|
|
326
|
+
172800,
|
|
327
|
+
259200,
|
|
328
|
+
345600,
|
|
329
|
+
604800,
|
|
330
|
+
1209600,
|
|
331
|
+
2635200,
|
|
332
|
+
7905600,
|
|
333
|
+
15768e3,
|
|
334
|
+
31536e3
|
|
335
|
+
];
|
|
336
|
+
for (let i = 0; i < tic_options.length - 1; i++) if (tic_options[i] < seconds && tic_options[i + 1] > seconds) return tic_options[i + 1];
|
|
337
|
+
return "-";
|
|
338
|
+
}
|
|
339
|
+
function base_time(high, clean_tic_time_change) {
|
|
340
|
+
const d_high = /* @__PURE__ */ new Date(high * 1e3);
|
|
341
|
+
const year = d_high.getFullYear();
|
|
342
|
+
const month = d_high.getMonth();
|
|
343
|
+
const day = d_high.getDate();
|
|
344
|
+
const hour = d_high.getHours();
|
|
345
|
+
const minute = d_high.getMinutes();
|
|
346
|
+
const ticBases = {
|
|
347
|
+
31536e3: {
|
|
348
|
+
focus: "y",
|
|
349
|
+
values: []
|
|
350
|
+
},
|
|
351
|
+
15768e3: {
|
|
352
|
+
focus: "M",
|
|
353
|
+
values: [
|
|
354
|
+
11,
|
|
355
|
+
5,
|
|
356
|
+
0
|
|
357
|
+
]
|
|
358
|
+
},
|
|
359
|
+
7905600: {
|
|
360
|
+
focus: "M",
|
|
361
|
+
values: [
|
|
362
|
+
11,
|
|
363
|
+
8,
|
|
364
|
+
5,
|
|
365
|
+
2,
|
|
366
|
+
0
|
|
367
|
+
]
|
|
368
|
+
},
|
|
369
|
+
2635200: {
|
|
370
|
+
focus: "M",
|
|
371
|
+
values: [
|
|
372
|
+
11,
|
|
373
|
+
10,
|
|
374
|
+
9,
|
|
375
|
+
8,
|
|
376
|
+
7,
|
|
377
|
+
6,
|
|
378
|
+
5,
|
|
379
|
+
4,
|
|
380
|
+
3,
|
|
381
|
+
2,
|
|
382
|
+
1,
|
|
383
|
+
0
|
|
384
|
+
]
|
|
385
|
+
},
|
|
386
|
+
1209600: {
|
|
387
|
+
focus: "d",
|
|
388
|
+
values: [
|
|
389
|
+
28,
|
|
390
|
+
14,
|
|
391
|
+
0
|
|
392
|
+
]
|
|
393
|
+
},
|
|
394
|
+
604800: {
|
|
395
|
+
focus: "d",
|
|
396
|
+
values: [
|
|
397
|
+
28,
|
|
398
|
+
21,
|
|
399
|
+
14,
|
|
400
|
+
7,
|
|
401
|
+
0
|
|
402
|
+
]
|
|
403
|
+
},
|
|
404
|
+
345600: {
|
|
405
|
+
focus: "d",
|
|
406
|
+
values: [
|
|
407
|
+
28,
|
|
408
|
+
24,
|
|
409
|
+
20,
|
|
410
|
+
16,
|
|
411
|
+
12,
|
|
412
|
+
8,
|
|
413
|
+
4,
|
|
414
|
+
0
|
|
415
|
+
]
|
|
416
|
+
},
|
|
417
|
+
259200: {
|
|
418
|
+
focus: "d",
|
|
419
|
+
values: [
|
|
420
|
+
30,
|
|
421
|
+
27,
|
|
422
|
+
24,
|
|
423
|
+
21,
|
|
424
|
+
18,
|
|
425
|
+
15,
|
|
426
|
+
12,
|
|
427
|
+
9,
|
|
428
|
+
6,
|
|
429
|
+
3,
|
|
430
|
+
0
|
|
431
|
+
]
|
|
432
|
+
},
|
|
433
|
+
172800: {
|
|
434
|
+
focus: "d",
|
|
435
|
+
values: [
|
|
436
|
+
30,
|
|
437
|
+
28,
|
|
438
|
+
26,
|
|
439
|
+
24,
|
|
440
|
+
22,
|
|
441
|
+
20,
|
|
442
|
+
18,
|
|
443
|
+
16,
|
|
444
|
+
14,
|
|
445
|
+
12,
|
|
446
|
+
10,
|
|
447
|
+
8,
|
|
448
|
+
6,
|
|
449
|
+
4,
|
|
450
|
+
2,
|
|
451
|
+
0
|
|
452
|
+
]
|
|
453
|
+
},
|
|
454
|
+
86400: {
|
|
455
|
+
focus: "d",
|
|
456
|
+
values: [
|
|
457
|
+
31,
|
|
458
|
+
30,
|
|
459
|
+
19,
|
|
460
|
+
28,
|
|
461
|
+
27,
|
|
462
|
+
26,
|
|
463
|
+
25,
|
|
464
|
+
24,
|
|
465
|
+
23,
|
|
466
|
+
22,
|
|
467
|
+
21,
|
|
468
|
+
20,
|
|
469
|
+
19,
|
|
470
|
+
18,
|
|
471
|
+
17,
|
|
472
|
+
16,
|
|
473
|
+
15,
|
|
474
|
+
14,
|
|
475
|
+
13,
|
|
476
|
+
12,
|
|
477
|
+
11,
|
|
478
|
+
10,
|
|
479
|
+
9,
|
|
480
|
+
8,
|
|
481
|
+
7,
|
|
482
|
+
6,
|
|
483
|
+
5,
|
|
484
|
+
4,
|
|
485
|
+
3,
|
|
486
|
+
2,
|
|
487
|
+
1,
|
|
488
|
+
0
|
|
489
|
+
]
|
|
490
|
+
},
|
|
491
|
+
43200: {
|
|
492
|
+
focus: "h",
|
|
493
|
+
values: [12, 0]
|
|
494
|
+
},
|
|
495
|
+
28800: {
|
|
496
|
+
focus: "h",
|
|
497
|
+
values: [
|
|
498
|
+
16,
|
|
499
|
+
8,
|
|
500
|
+
0
|
|
501
|
+
]
|
|
502
|
+
},
|
|
503
|
+
21600: {
|
|
504
|
+
focus: "h",
|
|
505
|
+
values: [
|
|
506
|
+
18,
|
|
507
|
+
12,
|
|
508
|
+
6,
|
|
509
|
+
0
|
|
510
|
+
]
|
|
511
|
+
},
|
|
512
|
+
14400: {
|
|
513
|
+
focus: "h",
|
|
514
|
+
values: [
|
|
515
|
+
20,
|
|
516
|
+
16,
|
|
517
|
+
12,
|
|
518
|
+
8,
|
|
519
|
+
4,
|
|
520
|
+
0
|
|
521
|
+
]
|
|
522
|
+
},
|
|
523
|
+
10800: {
|
|
524
|
+
focus: "h",
|
|
525
|
+
values: [
|
|
526
|
+
21,
|
|
527
|
+
18,
|
|
528
|
+
15,
|
|
529
|
+
12,
|
|
530
|
+
9,
|
|
531
|
+
6,
|
|
532
|
+
3,
|
|
533
|
+
0
|
|
534
|
+
]
|
|
535
|
+
},
|
|
536
|
+
7200: {
|
|
537
|
+
focus: "h",
|
|
538
|
+
values: [
|
|
539
|
+
22,
|
|
540
|
+
20,
|
|
541
|
+
18,
|
|
542
|
+
16,
|
|
543
|
+
14,
|
|
544
|
+
12,
|
|
545
|
+
10,
|
|
546
|
+
8,
|
|
547
|
+
6,
|
|
548
|
+
4,
|
|
549
|
+
2,
|
|
550
|
+
0
|
|
551
|
+
]
|
|
552
|
+
},
|
|
553
|
+
3600: {
|
|
554
|
+
focus: "h",
|
|
555
|
+
values: [
|
|
556
|
+
23,
|
|
557
|
+
22,
|
|
558
|
+
21,
|
|
559
|
+
20,
|
|
560
|
+
19,
|
|
561
|
+
18,
|
|
562
|
+
17,
|
|
563
|
+
16,
|
|
564
|
+
15,
|
|
565
|
+
14,
|
|
566
|
+
13,
|
|
567
|
+
12,
|
|
568
|
+
11,
|
|
569
|
+
10,
|
|
570
|
+
9,
|
|
571
|
+
8,
|
|
572
|
+
7,
|
|
573
|
+
6,
|
|
574
|
+
5,
|
|
575
|
+
4,
|
|
576
|
+
3,
|
|
577
|
+
2,
|
|
578
|
+
1,
|
|
579
|
+
0
|
|
580
|
+
]
|
|
581
|
+
},
|
|
582
|
+
2700: {
|
|
583
|
+
focus: "m",
|
|
584
|
+
values: [45, 0]
|
|
585
|
+
},
|
|
586
|
+
1800: {
|
|
587
|
+
focus: "m",
|
|
588
|
+
values: [30, 0]
|
|
589
|
+
},
|
|
590
|
+
1200: {
|
|
591
|
+
focus: "m",
|
|
592
|
+
values: [
|
|
593
|
+
40,
|
|
594
|
+
20,
|
|
595
|
+
0
|
|
596
|
+
]
|
|
597
|
+
},
|
|
598
|
+
900: {
|
|
599
|
+
focus: "m",
|
|
600
|
+
values: [
|
|
601
|
+
45,
|
|
602
|
+
30,
|
|
603
|
+
15,
|
|
604
|
+
0
|
|
605
|
+
]
|
|
606
|
+
},
|
|
607
|
+
600: {
|
|
608
|
+
focus: "m",
|
|
609
|
+
values: [
|
|
610
|
+
50,
|
|
611
|
+
40,
|
|
612
|
+
30,
|
|
613
|
+
20,
|
|
614
|
+
10,
|
|
615
|
+
0
|
|
616
|
+
]
|
|
617
|
+
},
|
|
618
|
+
300: {
|
|
619
|
+
focus: "m",
|
|
620
|
+
values: [
|
|
621
|
+
55,
|
|
622
|
+
50,
|
|
623
|
+
45,
|
|
624
|
+
40,
|
|
625
|
+
35,
|
|
626
|
+
30,
|
|
627
|
+
25,
|
|
628
|
+
20,
|
|
629
|
+
25,
|
|
630
|
+
20,
|
|
631
|
+
5,
|
|
632
|
+
0
|
|
633
|
+
]
|
|
634
|
+
}
|
|
635
|
+
};
|
|
636
|
+
var d = /* @__PURE__ */ new Date();
|
|
637
|
+
d.setFullYear(year);
|
|
638
|
+
d.setMonth(0);
|
|
639
|
+
d.setDate(1);
|
|
640
|
+
d.setHours(0);
|
|
641
|
+
d.setMinutes(0);
|
|
642
|
+
d.setMilliseconds(0);
|
|
643
|
+
switch (ticBases[clean_tic_time_change]?.focus) {
|
|
644
|
+
case "y": break;
|
|
645
|
+
case "M":
|
|
646
|
+
d.setFullYear(year);
|
|
647
|
+
for (let item of ticBases[clean_tic_time_change].values) if (item < month) {
|
|
648
|
+
d.setMonth(item);
|
|
649
|
+
break;
|
|
650
|
+
}
|
|
651
|
+
break;
|
|
652
|
+
case "d":
|
|
653
|
+
d.setFullYear(year);
|
|
654
|
+
d.setMonth(month);
|
|
655
|
+
for (let item of ticBases[clean_tic_time_change].values) if (item < day) {
|
|
656
|
+
d.setDate(item);
|
|
657
|
+
break;
|
|
658
|
+
}
|
|
659
|
+
break;
|
|
660
|
+
case "h":
|
|
661
|
+
d.setFullYear(year);
|
|
662
|
+
d.setMonth(month);
|
|
663
|
+
d.setDate(day);
|
|
664
|
+
for (let item of ticBases[clean_tic_time_change].values) if (item < hour) {
|
|
665
|
+
d.setHours(item);
|
|
666
|
+
break;
|
|
667
|
+
}
|
|
668
|
+
break;
|
|
669
|
+
case "m":
|
|
670
|
+
d.setFullYear(year);
|
|
671
|
+
d.setMonth(month);
|
|
672
|
+
d.setDate(day);
|
|
673
|
+
d.setHours(hour);
|
|
674
|
+
for (let item of ticBases[clean_tic_time_change].values) if (item < minute) {
|
|
675
|
+
d.setMinutes(item);
|
|
676
|
+
break;
|
|
677
|
+
}
|
|
678
|
+
break;
|
|
679
|
+
default: {
|
|
680
|
+
d.setMonth(month);
|
|
681
|
+
d.setDate(day);
|
|
682
|
+
d.setHours(hour);
|
|
683
|
+
const floor5min = minute - minute % 3e5;
|
|
684
|
+
d.setMinutes(floor5min);
|
|
685
|
+
break;
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
return Math.floor(d.getTime() / 1e3);
|
|
689
|
+
}
|
|
690
|
+
function readable_time(seconds) {
|
|
691
|
+
const months = [
|
|
692
|
+
"JAN",
|
|
693
|
+
"FEB",
|
|
694
|
+
"MAR",
|
|
695
|
+
"APR",
|
|
696
|
+
"MAY",
|
|
697
|
+
"JUN",
|
|
698
|
+
"JUL",
|
|
699
|
+
"AUG",
|
|
700
|
+
"SEP",
|
|
701
|
+
"OCT",
|
|
702
|
+
"NOV",
|
|
703
|
+
"DEC"
|
|
704
|
+
];
|
|
705
|
+
const date_object = /* @__PURE__ */ new Date(seconds * 1e3);
|
|
706
|
+
const year = date_object.getFullYear();
|
|
707
|
+
const month = date_object.getMonth();
|
|
708
|
+
const day = date_object.getDate();
|
|
709
|
+
const hour = date_object.getHours();
|
|
710
|
+
const minute = date_object.getMinutes();
|
|
711
|
+
const year_st = JSON.stringify(year);
|
|
712
|
+
const month_st = months[month];
|
|
713
|
+
let day_st = JSON.stringify(day);
|
|
714
|
+
let hour_st = JSON.stringify(hour);
|
|
715
|
+
let minute_st = JSON.stringify(minute);
|
|
716
|
+
if (minute_st.length < 2) minute_st = "0" + minute_st;
|
|
717
|
+
const hour_minute_st = hour_st + ":" + minute_st;
|
|
718
|
+
if (minute > 0 || hour > 0) return hour_minute_st;
|
|
719
|
+
else if (day > 1) return day_st;
|
|
720
|
+
else if (month > 0) return month_st;
|
|
721
|
+
return year_st;
|
|
722
|
+
}
|
|
723
|
+
function prep_x_axis(start_x, end_x, frame_width = 500, min_tic_spacing_x_axis = 20, min_tic_text_spacing_x_axis = 50) {
|
|
724
|
+
const amount_of_tics = Math.floor(frame_width / min_tic_spacing_x_axis);
|
|
725
|
+
const x_range = end_x - start_x;
|
|
726
|
+
const clean_x_change = time_tic_size(x_range / amount_of_tics);
|
|
727
|
+
const clean_x = base_time(end_x, clean_x_change);
|
|
728
|
+
const clean_x_text = readable_time(clean_x);
|
|
729
|
+
const clean_x_norm = (clean_x - start_x) / x_range;
|
|
730
|
+
let tics = [{
|
|
731
|
+
x: clean_x,
|
|
732
|
+
norm: clean_x_norm,
|
|
733
|
+
text: clean_x_text
|
|
734
|
+
}];
|
|
735
|
+
let last_tic_with_text_x_norm = clean_x_norm;
|
|
736
|
+
for (let i = 1; i < amount_of_tics; i++) {
|
|
737
|
+
const iter_x = clean_x + clean_x_change * i;
|
|
738
|
+
const iter_x_norm = (iter_x - start_x) / x_range;
|
|
739
|
+
const is_far_enough_from_prev_text = !last_tic_with_text_x_norm || (iter_x_norm - last_tic_with_text_x_norm) * frame_width >= min_tic_text_spacing_x_axis;
|
|
740
|
+
if (iter_x <= end_x) if (is_far_enough_from_prev_text) {
|
|
741
|
+
tics = [...tics, {
|
|
742
|
+
x: iter_x,
|
|
743
|
+
norm: iter_x_norm,
|
|
744
|
+
text: readable_time(iter_x)
|
|
745
|
+
}];
|
|
746
|
+
last_tic_with_text_x_norm = iter_x_norm;
|
|
747
|
+
} else tics = [...tics, {
|
|
748
|
+
x: iter_x,
|
|
749
|
+
norm: iter_x_norm,
|
|
750
|
+
text: null
|
|
751
|
+
}];
|
|
752
|
+
else break;
|
|
753
|
+
}
|
|
754
|
+
last_tic_with_text_x_norm = clean_x_norm;
|
|
755
|
+
for (let i = 1; i < amount_of_tics; i++) {
|
|
756
|
+
const iter_x = clean_x - clean_x_change * i;
|
|
757
|
+
const iter_x_norm = (iter_x - start_x) / x_range;
|
|
758
|
+
const is_far_enough_from_prev_text = !last_tic_with_text_x_norm || (last_tic_with_text_x_norm - iter_x_norm) * frame_width >= min_tic_text_spacing_x_axis;
|
|
759
|
+
if (iter_x >= start_x) if (is_far_enough_from_prev_text) {
|
|
760
|
+
tics = [{
|
|
761
|
+
x: iter_x,
|
|
762
|
+
norm: iter_x_norm,
|
|
763
|
+
text: readable_time(iter_x)
|
|
764
|
+
}, ...tics];
|
|
765
|
+
last_tic_with_text_x_norm = iter_x_norm;
|
|
766
|
+
} else tics = [{
|
|
767
|
+
x: iter_x,
|
|
768
|
+
norm: iter_x_norm,
|
|
769
|
+
text: null
|
|
770
|
+
}, ...tics];
|
|
771
|
+
else break;
|
|
772
|
+
}
|
|
773
|
+
return tics;
|
|
774
|
+
}
|
|
775
|
+
function notable_num(low, high) {
|
|
776
|
+
let abs_closest_to_zero = low;
|
|
777
|
+
let abs_farther_to_zero = high;
|
|
778
|
+
let is_positive = true;
|
|
779
|
+
if (high < 0) {
|
|
780
|
+
abs_closest_to_zero = Math.abs(high);
|
|
781
|
+
abs_farther_to_zero = Math.abs(low);
|
|
782
|
+
is_positive = false;
|
|
783
|
+
}
|
|
784
|
+
let accumulated_num = 0;
|
|
785
|
+
while (accumulated_num < abs_farther_to_zero) {
|
|
786
|
+
const res = next_big_num_under_target(abs_farther_to_zero - accumulated_num);
|
|
787
|
+
accumulated_num += res;
|
|
788
|
+
if (accumulated_num > abs_closest_to_zero) if (is_positive) return accumulated_num;
|
|
789
|
+
else return -1 * accumulated_num;
|
|
790
|
+
}
|
|
791
|
+
return "-";
|
|
792
|
+
}
|
|
793
|
+
function next_big_num_under_target(target) {
|
|
794
|
+
for (let num of [
|
|
795
|
+
0x5af3107a4000,
|
|
796
|
+
0x9184e72a000,
|
|
797
|
+
0xe8d4a51000,
|
|
798
|
+
1e11,
|
|
799
|
+
1e10,
|
|
800
|
+
1e9,
|
|
801
|
+
1e8,
|
|
802
|
+
5e7,
|
|
803
|
+
2e7,
|
|
804
|
+
1e7,
|
|
805
|
+
5e6,
|
|
806
|
+
2e6,
|
|
807
|
+
1e6,
|
|
808
|
+
75e4,
|
|
809
|
+
5e5,
|
|
810
|
+
4e5,
|
|
811
|
+
25e4,
|
|
812
|
+
2e5,
|
|
813
|
+
15e4,
|
|
814
|
+
1e5,
|
|
815
|
+
75e3,
|
|
816
|
+
5e4,
|
|
817
|
+
4e4,
|
|
818
|
+
25e3,
|
|
819
|
+
2e4,
|
|
820
|
+
15e3,
|
|
821
|
+
1e4,
|
|
822
|
+
7500,
|
|
823
|
+
5e3,
|
|
824
|
+
4e3,
|
|
825
|
+
3e3,
|
|
826
|
+
2500,
|
|
827
|
+
2e3,
|
|
828
|
+
1500,
|
|
829
|
+
1250,
|
|
830
|
+
1e3,
|
|
831
|
+
750,
|
|
832
|
+
500,
|
|
833
|
+
400,
|
|
834
|
+
300,
|
|
835
|
+
200,
|
|
836
|
+
150,
|
|
837
|
+
100,
|
|
838
|
+
75,
|
|
839
|
+
50,
|
|
840
|
+
40,
|
|
841
|
+
25,
|
|
842
|
+
20,
|
|
843
|
+
15,
|
|
844
|
+
12,
|
|
845
|
+
10,
|
|
846
|
+
8,
|
|
847
|
+
5,
|
|
848
|
+
4,
|
|
849
|
+
3,
|
|
850
|
+
2.5,
|
|
851
|
+
2,
|
|
852
|
+
1,
|
|
853
|
+
.8,
|
|
854
|
+
.5,
|
|
855
|
+
.4,
|
|
856
|
+
.3,
|
|
857
|
+
.2,
|
|
858
|
+
.1,
|
|
859
|
+
.08,
|
|
860
|
+
.05,
|
|
861
|
+
.04,
|
|
862
|
+
.03,
|
|
863
|
+
.02,
|
|
864
|
+
.01,
|
|
865
|
+
.008,
|
|
866
|
+
.005,
|
|
867
|
+
.004,
|
|
868
|
+
.003,
|
|
869
|
+
.002,
|
|
870
|
+
.001,
|
|
871
|
+
8e-4,
|
|
872
|
+
5e-4,
|
|
873
|
+
4e-4,
|
|
874
|
+
3e-4,
|
|
875
|
+
2e-4,
|
|
876
|
+
1e-4,
|
|
877
|
+
8e-5,
|
|
878
|
+
5e-5,
|
|
879
|
+
4e-5,
|
|
880
|
+
3e-5,
|
|
881
|
+
2e-5,
|
|
882
|
+
1e-5,
|
|
883
|
+
8e-6,
|
|
884
|
+
5e-6,
|
|
885
|
+
4e-6,
|
|
886
|
+
3e-6,
|
|
887
|
+
2e-6,
|
|
888
|
+
1e-6,
|
|
889
|
+
8e-7,
|
|
890
|
+
5e-7,
|
|
891
|
+
4e-7,
|
|
892
|
+
3e-7,
|
|
893
|
+
2e-7,
|
|
894
|
+
1e-7
|
|
895
|
+
]) if (num < target) return num;
|
|
896
|
+
return 1;
|
|
897
|
+
}
|
|
898
|
+
function tic_size(num) {
|
|
899
|
+
const tic_options = [
|
|
900
|
+
1e-7,
|
|
901
|
+
2e-7,
|
|
902
|
+
3e-7,
|
|
903
|
+
4e-7,
|
|
904
|
+
5e-7,
|
|
905
|
+
8e-7,
|
|
906
|
+
1e-6,
|
|
907
|
+
2e-6,
|
|
908
|
+
3e-6,
|
|
909
|
+
4e-6,
|
|
910
|
+
5e-6,
|
|
911
|
+
8e-6,
|
|
912
|
+
1e-5,
|
|
913
|
+
2e-5,
|
|
914
|
+
3e-5,
|
|
915
|
+
4e-5,
|
|
916
|
+
5e-5,
|
|
917
|
+
8e-5,
|
|
918
|
+
1e-4,
|
|
919
|
+
2e-4,
|
|
920
|
+
3e-4,
|
|
921
|
+
4e-4,
|
|
922
|
+
5e-4,
|
|
923
|
+
8e-4,
|
|
924
|
+
.001,
|
|
925
|
+
.002,
|
|
926
|
+
.003,
|
|
927
|
+
.004,
|
|
928
|
+
.005,
|
|
929
|
+
.008,
|
|
930
|
+
.01,
|
|
931
|
+
.02,
|
|
932
|
+
.03,
|
|
933
|
+
.04,
|
|
934
|
+
.05,
|
|
935
|
+
.08,
|
|
936
|
+
.1,
|
|
937
|
+
.2,
|
|
938
|
+
.3,
|
|
939
|
+
.4,
|
|
940
|
+
.5,
|
|
941
|
+
.8,
|
|
942
|
+
1,
|
|
943
|
+
2,
|
|
944
|
+
2.5,
|
|
945
|
+
3,
|
|
946
|
+
4,
|
|
947
|
+
5,
|
|
948
|
+
8,
|
|
949
|
+
10,
|
|
950
|
+
12,
|
|
951
|
+
15,
|
|
952
|
+
20,
|
|
953
|
+
25,
|
|
954
|
+
40,
|
|
955
|
+
50,
|
|
956
|
+
75,
|
|
957
|
+
100,
|
|
958
|
+
150,
|
|
959
|
+
200,
|
|
960
|
+
300,
|
|
961
|
+
400,
|
|
962
|
+
500,
|
|
963
|
+
750,
|
|
964
|
+
1e3,
|
|
965
|
+
1250,
|
|
966
|
+
1500,
|
|
967
|
+
2e3,
|
|
968
|
+
2500,
|
|
969
|
+
3e3,
|
|
970
|
+
4e3,
|
|
971
|
+
5e3,
|
|
972
|
+
7500,
|
|
973
|
+
1e4,
|
|
974
|
+
15e3,
|
|
975
|
+
2e4,
|
|
976
|
+
25e3,
|
|
977
|
+
4e4,
|
|
978
|
+
5e4,
|
|
979
|
+
75e3,
|
|
980
|
+
1e5,
|
|
981
|
+
15e4,
|
|
982
|
+
2e5,
|
|
983
|
+
25e4,
|
|
984
|
+
4e5,
|
|
985
|
+
5e5,
|
|
986
|
+
75e4,
|
|
987
|
+
1e6,
|
|
988
|
+
2e6,
|
|
989
|
+
5e6,
|
|
990
|
+
1e7,
|
|
991
|
+
2e7,
|
|
992
|
+
5e7,
|
|
993
|
+
1e8,
|
|
994
|
+
1e9,
|
|
995
|
+
1e10,
|
|
996
|
+
1e11,
|
|
997
|
+
0xe8d4a51000,
|
|
998
|
+
0x9184e72a000,
|
|
999
|
+
0x5af3107a4000
|
|
1000
|
+
];
|
|
1001
|
+
for (let i = 0; i < tic_options.length - 1; i++) if (tic_options[i] < num && tic_options[i + 1] > num) return tic_options[i + 1];
|
|
1002
|
+
return "-";
|
|
1003
|
+
}
|
|
1004
|
+
function prep_y_axis(shown_low_y, shown_high_y, frame_height = 300, min_tic_spacing_y_axis = 10, min_tic_text_spacing_y_axis = 30) {
|
|
1005
|
+
const amount_of_tics = Math.floor(frame_height / min_tic_spacing_y_axis);
|
|
1006
|
+
const y_range = shown_high_y - shown_low_y;
|
|
1007
|
+
const clean_y_change = tic_size(y_range / amount_of_tics);
|
|
1008
|
+
const clean_y = notable_num(shown_low_y, shown_high_y);
|
|
1009
|
+
const clean_y_norm = (clean_y - shown_low_y) / y_range;
|
|
1010
|
+
const clean_y_text = short_lab(clean_y);
|
|
1011
|
+
const is_remaining_room_for_text = (1 - clean_y_norm) * frame_height >= min_tic_text_spacing_y_axis / 2;
|
|
1012
|
+
let tics = [{
|
|
1013
|
+
y: clean_y,
|
|
1014
|
+
norm: clean_y_norm,
|
|
1015
|
+
text: is_remaining_room_for_text ? clean_y_text : null,
|
|
1016
|
+
ppp: (1 - clean_y_norm) * frame_height
|
|
1017
|
+
}];
|
|
1018
|
+
let last_tic_with_text_y_norm = is_remaining_room_for_text ? clean_y_norm : null;
|
|
1019
|
+
for (let i = 1; i < amount_of_tics; i++) {
|
|
1020
|
+
const iter_y = clean_y + clean_y_change * i;
|
|
1021
|
+
const iter_y_norm = (iter_y - shown_low_y) / y_range;
|
|
1022
|
+
const is_remaining_room = (shown_high_y - iter_y) / y_range * frame_height >= min_tic_text_spacing_y_axis / 2;
|
|
1023
|
+
const is_far_enough_from_prev_text = !last_tic_with_text_y_norm || (iter_y_norm - last_tic_with_text_y_norm) * frame_height >= min_tic_text_spacing_y_axis;
|
|
1024
|
+
if (iter_y <= shown_high_y) if (is_far_enough_from_prev_text && is_remaining_room) {
|
|
1025
|
+
tics = [...tics, {
|
|
1026
|
+
y: iter_y,
|
|
1027
|
+
norm: iter_y_norm,
|
|
1028
|
+
text: short_lab(iter_y)
|
|
1029
|
+
}];
|
|
1030
|
+
last_tic_with_text_y_norm = iter_y_norm;
|
|
1031
|
+
} else tics = [...tics, {
|
|
1032
|
+
y: iter_y,
|
|
1033
|
+
norm: iter_y_norm,
|
|
1034
|
+
text: null
|
|
1035
|
+
}];
|
|
1036
|
+
else break;
|
|
1037
|
+
}
|
|
1038
|
+
last_tic_with_text_y_norm = clean_y_norm;
|
|
1039
|
+
for (let i = 1; i < amount_of_tics; i++) {
|
|
1040
|
+
const iter_y = clean_y - clean_y_change * i;
|
|
1041
|
+
const iter_y_norm = (iter_y - shown_low_y) / y_range;
|
|
1042
|
+
const is_remaining_room = iter_y_norm * frame_height >= min_tic_text_spacing_y_axis / 2;
|
|
1043
|
+
const is_far_enough_from_prev_text = !last_tic_with_text_y_norm || (last_tic_with_text_y_norm - iter_y_norm) * frame_height >= min_tic_text_spacing_y_axis;
|
|
1044
|
+
if (iter_y >= shown_low_y) if (is_far_enough_from_prev_text && is_remaining_room) {
|
|
1045
|
+
tics = [{
|
|
1046
|
+
y: iter_y,
|
|
1047
|
+
norm: iter_y_norm,
|
|
1048
|
+
text: short_lab(iter_y)
|
|
1049
|
+
}, ...tics];
|
|
1050
|
+
last_tic_with_text_y_norm = iter_y_norm;
|
|
1051
|
+
} else tics = [{
|
|
1052
|
+
x: iter_y,
|
|
1053
|
+
norm: iter_y_norm,
|
|
1054
|
+
text: null
|
|
1055
|
+
}, ...tics];
|
|
1056
|
+
else break;
|
|
1057
|
+
}
|
|
1058
|
+
return tics;
|
|
1059
|
+
}
|
|
1060
|
+
function short_lab(num) {
|
|
1061
|
+
var if_neg = 1;
|
|
1062
|
+
if (typeof num === "object" | typeof num === "undefined") return "-";
|
|
1063
|
+
if (num < 0) if_neg = -1;
|
|
1064
|
+
var amount = Math.abs(num);
|
|
1065
|
+
if (amount === 0) return 0;
|
|
1066
|
+
else if (amount >= 0 && amount < 1e-4) return Math.round((if_neg * amount).toFixed(8) * 1e7 + Number.EPSILON) / 1e7;
|
|
1067
|
+
else if (amount >= 1e-4 && amount < .001) return Math.round((if_neg * amount).toFixed(7) * 1e6 + Number.EPSILON) / 1e6;
|
|
1068
|
+
else if (amount >= .001 && amount < .01) return Math.round((if_neg * amount).toFixed(6) * 1e5 + Number.EPSILON) / 1e5;
|
|
1069
|
+
else if (amount >= .01 && amount < .1) return Math.round((if_neg * amount).toFixed(5) * 1e4 + Number.EPSILON) / 1e4;
|
|
1070
|
+
else if (amount >= .1 && amount < 10) return Math.round((if_neg * amount).toFixed(4) * 1e3 + Number.EPSILON) / 1e3;
|
|
1071
|
+
else if (amount >= 10 && amount < 1e3) return (if_neg * amount).toFixed(2);
|
|
1072
|
+
else if (amount >= 1e3 && amount < 1e6) return (if_neg * amount).toFixed().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
1073
|
+
else if (amount >= 1e6 && amount < 1e7) return (if_neg * (amount / 1e6)).toFixed(2) + " M";
|
|
1074
|
+
else if (amount >= 1e7 && amount < 1e8) return (if_neg * (amount / 1e6)).toFixed(1) + " M";
|
|
1075
|
+
else if (amount >= 1e8 && amount < 1e9) return (if_neg * (amount / 1e6)).toFixed() + " M";
|
|
1076
|
+
else if (amount >= 1e9 && amount < 1e10) return (if_neg * (amount / 1e9)).toFixed(2) + " B";
|
|
1077
|
+
else if (amount >= 1e10 && amount < 1e11) return (if_neg * (amount / 1e9)).toFixed(1) + " B";
|
|
1078
|
+
else if (amount >= 1e11 && amount < 0xe8d4a51000) return (if_neg * (amount / 1e9)).toFixed() + " B";
|
|
1079
|
+
else if (amount >= 0xe8d4a51000 && amount < 0x9184e72a000) return (if_neg * (amount / 0xe8d4a51000)).toFixed(2) + " T";
|
|
1080
|
+
else if (amount >= 0x9184e72a000 && amount < 0x5af3107a4000) return (if_neg * (amount / 0xe8d4a51000)).toFixed(1) + " T";
|
|
1081
|
+
else if (amount >= 0x5af3107a4000 && amount < 0x38d7ea4c68000) return (if_neg * (amount / 0xe8d4a51000)).toFixed() + " T";
|
|
1082
|
+
else if (amount >= 0x38d7ea4c68000 && amount < 10000000000000000n) return (if_neg * (amount / 0x38d7ea4c68000)).toFixed(2) + " Q";
|
|
1083
|
+
else if (amount >= 10000000000000000n && amount < 100000000000000000n) return (if_neg * (amount / 0x38d7ea4c68000)).toFixed(1) + " Q";
|
|
1084
|
+
else if (amount >= 100000000000000000n && amount < 1000000000000000000n) return (if_neg * (amount / 0x38d7ea4c68000)).toFixed() + " Q";
|
|
1085
|
+
else if (amount >= 1000000000000000000n && amount < 10000000000000000000n) return (if_neg * (amount / 1000000000000000000n)).toFixed(2) + " QN";
|
|
1086
|
+
else if (amount >= 10000000000000000000n && amount < 100000000000000000000n) return (if_neg * (amount / 1000000000000000000n)).toFixed(1) + " QN";
|
|
1087
|
+
else if (amount >= 100000000000000000000n && amount < 1000000000000000000000n) return (if_neg * (amount / 1000000000000000000n)).toFixed() + " QN";
|
|
1088
|
+
else return "Big";
|
|
1089
|
+
}
|
|
1090
|
+
function handle_scroll_frame(e) {
|
|
1091
|
+
e.preventDefault();
|
|
1092
|
+
const min_period_sec = get_min_period_sec_from_chart() ?? 60;
|
|
1093
|
+
const max_range_sec = get_max_range_sec_from_chart();
|
|
1094
|
+
const res = scroll_frame(e, chart_prepped.shown_start_x, chart_prepped.shown_end_x, chart_prepped?.min_x_scrollable, chart_prepped?.max_x_scrollable, frame_width(), min_period_sec, max_range_sec);
|
|
1095
|
+
apply_view(res.shown_start_x, res.shown_end_x);
|
|
1096
|
+
}
|
|
1097
|
+
function get_y_axis_zoom_factor_from_wheel(delta_y) {
|
|
1098
|
+
const clamped_delta = clamp(Number(delta_y) || 0, -120, 120);
|
|
1099
|
+
return Math.exp(clamped_delta * 45e-5);
|
|
1100
|
+
}
|
|
1101
|
+
function get_y_axis_state(frame_index) {
|
|
1102
|
+
const frame = chart_prepped?.frames?.[frame_index];
|
|
1103
|
+
const axis_index = frame?.shown_y_axis_index ?? 0;
|
|
1104
|
+
return {
|
|
1105
|
+
frame,
|
|
1106
|
+
axis_index,
|
|
1107
|
+
axis: frame?.shared_y_axiss?.[axis_index]
|
|
1108
|
+
};
|
|
1109
|
+
}
|
|
1110
|
+
function get_current_y_bounds(axis) {
|
|
1111
|
+
return {
|
|
1112
|
+
low_y: is_finite_num(axis?.manual_low_y) ? Number(axis.manual_low_y) : Number(axis?.shown_low_y),
|
|
1113
|
+
high_y: is_finite_num(axis?.manual_high_y) ? Number(axis.manual_high_y) : Number(axis?.shown_high_y)
|
|
1114
|
+
};
|
|
1115
|
+
}
|
|
1116
|
+
function set_manual_y_bounds(axis, low_y, high_y) {
|
|
1117
|
+
axis.manual_low_y = parseFloat(low_y.toPrecision(10));
|
|
1118
|
+
axis.manual_high_y = parseFloat(high_y.toPrecision(10));
|
|
1119
|
+
chart_prepped = prep_chart(deep_copy(chart_prepped));
|
|
1120
|
+
}
|
|
1121
|
+
let pointer_cache = /* @__PURE__ */ new Map();
|
|
1122
|
+
let touch_hover_memory = {
|
|
1123
|
+
frame_index: null,
|
|
1124
|
+
x_hovered_percent_decimal: null,
|
|
1125
|
+
y_hovered_percent_decimal: null
|
|
1126
|
+
};
|
|
1127
|
+
let gesture_state = {
|
|
1128
|
+
mode: null,
|
|
1129
|
+
start_shown_start_x: null,
|
|
1130
|
+
start_shown_end_x: null,
|
|
1131
|
+
start_range_sec: null,
|
|
1132
|
+
start_primary_x: null,
|
|
1133
|
+
start_primary_y: null,
|
|
1134
|
+
start_dist_px: null,
|
|
1135
|
+
start_center_pd: null,
|
|
1136
|
+
touch_hover_offset_x: null,
|
|
1137
|
+
touch_hover_offset_y: null,
|
|
1138
|
+
touch_hover_frame_index: null
|
|
1139
|
+
};
|
|
1140
|
+
let y_axis_gesture_state = {
|
|
1141
|
+
mode: null,
|
|
1142
|
+
frame_index: null,
|
|
1143
|
+
start_y: null,
|
|
1144
|
+
start_dist_px: null,
|
|
1145
|
+
start_range_y: null,
|
|
1146
|
+
start_low_y: null,
|
|
1147
|
+
start_high_y: null,
|
|
1148
|
+
anchor_pd: null,
|
|
1149
|
+
anchor_y: null,
|
|
1150
|
+
did_drag: false,
|
|
1151
|
+
suppress_click: false
|
|
1152
|
+
};
|
|
1153
|
+
let y_axis_pointer_cache = /* @__PURE__ */ new Map();
|
|
1154
|
+
function clamp(n, min, max) {
|
|
1155
|
+
return n < min ? min : n > max ? max : n;
|
|
1156
|
+
}
|
|
1157
|
+
function clamp_range_to_limits(range_sec) {
|
|
1158
|
+
const min_period_sec = get_min_period_sec_from_chart() ?? 60;
|
|
1159
|
+
return clamp(range_sec, Math.max(Number(min_visible_bars) || 0, 1) * min_period_sec, get_max_range_sec_from_chart() ?? range_sec);
|
|
1160
|
+
}
|
|
1161
|
+
function clamp_y_range_to_limits(range_y, axis) {
|
|
1162
|
+
const data_low_y = axis?.data_low_y;
|
|
1163
|
+
const data_high_y = axis?.data_high_y;
|
|
1164
|
+
const data_range_y = get_safe_y_range(data_low_y, data_high_y);
|
|
1165
|
+
const center_y = is_finite_num(data_low_y) && is_finite_num(data_high_y) ? (Number(data_low_y) + Number(data_high_y)) / 2 : is_finite_num(data_low_y) ? Number(data_low_y) : is_finite_num(data_high_y) ? Number(data_high_y) : 0;
|
|
1166
|
+
const min_range_y = Math.max(data_range_y * .02, Math.abs(center_y) * 1e-6, 1e-8);
|
|
1167
|
+
return clamp(range_y, min_range_y, Math.max(data_range_y * 1e3, min_range_y * 10));
|
|
1168
|
+
}
|
|
1169
|
+
function clamp_view_to_data(shown_start_x, shown_end_x) {
|
|
1170
|
+
if (!chart_prepped) return {
|
|
1171
|
+
shown_start_x,
|
|
1172
|
+
shown_end_x
|
|
1173
|
+
};
|
|
1174
|
+
const range = shown_end_x - shown_start_x;
|
|
1175
|
+
if (!isFinite(range) || range <= 0) return {
|
|
1176
|
+
shown_start_x,
|
|
1177
|
+
shown_end_x
|
|
1178
|
+
};
|
|
1179
|
+
const edge_padding_sec = get_x_edge_padding_sec(range);
|
|
1180
|
+
const min_x = chart_prepped.all_data_start_x - edge_padding_sec;
|
|
1181
|
+
const max_x = chart_prepped.all_data_end_x + edge_padding_sec;
|
|
1182
|
+
let start = shown_start_x;
|
|
1183
|
+
let end = shown_end_x;
|
|
1184
|
+
if (end > max_x) {
|
|
1185
|
+
const diff = end - max_x;
|
|
1186
|
+
start -= diff;
|
|
1187
|
+
end -= diff;
|
|
1188
|
+
}
|
|
1189
|
+
if (start < min_x) {
|
|
1190
|
+
const diff = min_x - start;
|
|
1191
|
+
start += diff;
|
|
1192
|
+
end += diff;
|
|
1193
|
+
}
|
|
1194
|
+
if (start < min_x) start = min_x;
|
|
1195
|
+
if (end > max_x) end = max_x;
|
|
1196
|
+
if (end - start < 1) end = start + 1;
|
|
1197
|
+
return {
|
|
1198
|
+
shown_start_x: start,
|
|
1199
|
+
shown_end_x: end
|
|
1200
|
+
};
|
|
1201
|
+
}
|
|
1202
|
+
function reset_gesture_state() {
|
|
1203
|
+
gesture_state.mode = null;
|
|
1204
|
+
gesture_state.start_shown_start_x = null;
|
|
1205
|
+
gesture_state.start_shown_end_x = null;
|
|
1206
|
+
gesture_state.start_range_sec = null;
|
|
1207
|
+
gesture_state.start_primary_x = null;
|
|
1208
|
+
gesture_state.start_primary_y = null;
|
|
1209
|
+
gesture_state.start_dist_px = null;
|
|
1210
|
+
gesture_state.start_center_pd = null;
|
|
1211
|
+
gesture_state.touch_hover_offset_x = null;
|
|
1212
|
+
gesture_state.touch_hover_offset_y = null;
|
|
1213
|
+
gesture_state.touch_hover_frame_index = null;
|
|
1214
|
+
}
|
|
1215
|
+
function get_two_pointer_info() {
|
|
1216
|
+
const pts = [...pointer_cache.values()];
|
|
1217
|
+
if (pts.length < 2) return null;
|
|
1218
|
+
const a = pts[0];
|
|
1219
|
+
const b = pts[1];
|
|
1220
|
+
const dx = b.x - a.x;
|
|
1221
|
+
const dy = b.y - a.y;
|
|
1222
|
+
return {
|
|
1223
|
+
dist: Math.sqrt(dx * dx + dy * dy),
|
|
1224
|
+
center_x: (a.x + b.x) / 2,
|
|
1225
|
+
center_y: (a.y + b.y) / 2
|
|
1226
|
+
};
|
|
1227
|
+
}
|
|
1228
|
+
function apply_view(shown_start_x, shown_end_x) {
|
|
1229
|
+
const clamped = clamp_view_to_data(shown_start_x, shown_end_x);
|
|
1230
|
+
chart_prepped.set_shown_start_x(clamped.shown_start_x);
|
|
1231
|
+
chart_prepped.set_shown_end_x(clamped.shown_end_x);
|
|
1232
|
+
chart_prepped = prep_chart(deep_copy(chart_prepped));
|
|
1233
|
+
}
|
|
1234
|
+
function get_chart_point_from_event(e, frame_index) {
|
|
1235
|
+
const rect = e.currentTarget?.getBoundingClientRect?.();
|
|
1236
|
+
const frame_height = chart_prepped?.frames?.[frame_index]?.frame_height;
|
|
1237
|
+
const width = rect?.width || frame_width() || 1;
|
|
1238
|
+
const height = rect?.height || frame_height || 1;
|
|
1239
|
+
return {
|
|
1240
|
+
x: clamp((rect ? e.clientX - rect.left : e.offsetX) ?? 0, 0, width),
|
|
1241
|
+
y: clamp((rect ? e.clientY - rect.top : e.offsetY) ?? 0, 0, height),
|
|
1242
|
+
width,
|
|
1243
|
+
height
|
|
1244
|
+
};
|
|
1245
|
+
}
|
|
1246
|
+
function clear_chart_hover(frame_index, { clear_x = true } = {}) {
|
|
1247
|
+
if (!chart_prepped) return;
|
|
1248
|
+
if (clear_x) {
|
|
1249
|
+
chart_prepped.x_hovered_percent_decimal = null;
|
|
1250
|
+
chart_prepped.x_axis_highlight_tic = null;
|
|
1251
|
+
}
|
|
1252
|
+
const frame = chart_prepped?.frames?.[frame_index];
|
|
1253
|
+
if (!frame) return;
|
|
1254
|
+
frame.y_hovered_percent_decimal = null;
|
|
1255
|
+
for (let i = 0; i < frame.shared_y_axiss.length; i++) frame.shared_y_axiss[i].y_axis_highlight_tic = null;
|
|
1256
|
+
}
|
|
1257
|
+
function clear_all_chart_hover() {
|
|
1258
|
+
if (!chart_prepped) return;
|
|
1259
|
+
chart_prepped.x_hovered_percent_decimal = null;
|
|
1260
|
+
chart_prepped.x_axis_highlight_tic = null;
|
|
1261
|
+
for (let frame of chart_prepped?.frames ?? []) {
|
|
1262
|
+
frame.y_hovered_percent_decimal = null;
|
|
1263
|
+
for (let shared_y_axis of frame?.shared_y_axiss ?? []) shared_y_axis.y_axis_highlight_tic = null;
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
function set_chart_hover(frame_index, x, y, width = frame_width(), height = null) {
|
|
1267
|
+
if (!chart_prepped) return;
|
|
1268
|
+
const frame = chart_prepped?.frames?.[frame_index];
|
|
1269
|
+
if (!frame) return;
|
|
1270
|
+
const safe_width = Number(width) > 0 ? Number(width) : frame_width() || 1;
|
|
1271
|
+
const safe_height = Number(height) > 0 ? Number(height) : frame?.frame_height || 1;
|
|
1272
|
+
const hover_x_pd = clamp(x / safe_width, 0, 1);
|
|
1273
|
+
const hover_y_pd = clamp((safe_height - y) / safe_height, 0, 1);
|
|
1274
|
+
chart_prepped.set_x_hovered_percent_decimal(parseFloat(hover_x_pd.toPrecision(4)));
|
|
1275
|
+
for (let i = 0; i < (chart_prepped?.frames?.length ?? 0); i++) {
|
|
1276
|
+
if (i === frame_index) continue;
|
|
1277
|
+
const inactive_frame = chart_prepped.frames[i];
|
|
1278
|
+
inactive_frame.y_hovered_percent_decimal = null;
|
|
1279
|
+
for (let shared_y_axis of inactive_frame?.shared_y_axiss ?? []) shared_y_axis.y_axis_highlight_tic = null;
|
|
1280
|
+
}
|
|
1281
|
+
frame.y_hovered_percent_decimal = parseFloat(hover_y_pd.toPrecision(4));
|
|
1282
|
+
for (let i = 0; i < frame.shared_y_axiss.length; i++) frame.shared_y_axiss[i].y_axis_highlight_tic = hover_y_pd * (frame.shared_y_axiss[i].shown_high_y - frame.shared_y_axiss[i].shown_low_y) + frame.shared_y_axiss[i].shown_low_y;
|
|
1283
|
+
}
|
|
1284
|
+
function get_current_hover_point(frame_index, width = frame_width(), height = null) {
|
|
1285
|
+
if (!chart_prepped) return null;
|
|
1286
|
+
const frame = chart_prepped?.frames?.[frame_index];
|
|
1287
|
+
let hover_x_pd = Number(chart_prepped?.x_hovered_percent_decimal);
|
|
1288
|
+
let hover_y_pd = Number(frame?.y_hovered_percent_decimal);
|
|
1289
|
+
if ((!Number.isFinite(hover_x_pd) || !Number.isFinite(hover_y_pd)) && touch_hover_memory.frame_index === frame_index) {
|
|
1290
|
+
hover_x_pd = Number(touch_hover_memory.x_hovered_percent_decimal);
|
|
1291
|
+
hover_y_pd = Number(touch_hover_memory.y_hovered_percent_decimal);
|
|
1292
|
+
}
|
|
1293
|
+
if (!frame || !Number.isFinite(hover_x_pd) || !Number.isFinite(hover_y_pd)) return null;
|
|
1294
|
+
const safe_width = Number(width) > 0 ? Number(width) : frame_width() || 1;
|
|
1295
|
+
const safe_height = Number(height) > 0 ? Number(height) : frame?.frame_height || 1;
|
|
1296
|
+
return {
|
|
1297
|
+
x: clamp(hover_x_pd * safe_width, 0, safe_width),
|
|
1298
|
+
y: clamp(safe_height - hover_y_pd * safe_height, 0, safe_height),
|
|
1299
|
+
width: safe_width,
|
|
1300
|
+
height: safe_height
|
|
1301
|
+
};
|
|
1302
|
+
}
|
|
1303
|
+
function remember_touch_hover(frame_index) {
|
|
1304
|
+
touch_hover_memory.frame_index = frame_index;
|
|
1305
|
+
touch_hover_memory.x_hovered_percent_decimal = chart_prepped?.x_hovered_percent_decimal ?? null;
|
|
1306
|
+
touch_hover_memory.y_hovered_percent_decimal = chart_prepped?.frames?.[frame_index]?.y_hovered_percent_decimal ?? null;
|
|
1307
|
+
}
|
|
1308
|
+
function restore_touch_hover_from_memory(frame_index = touch_hover_memory.frame_index) {
|
|
1309
|
+
if (!chart_prepped || !Number.isInteger(frame_index)) return false;
|
|
1310
|
+
const hover_x_pd = Number(touch_hover_memory.x_hovered_percent_decimal);
|
|
1311
|
+
const hover_y_pd = Number(touch_hover_memory.y_hovered_percent_decimal);
|
|
1312
|
+
const frame_height = chart_prepped?.frames?.[frame_index]?.frame_height;
|
|
1313
|
+
if (!Number.isFinite(hover_x_pd) || !Number.isFinite(hover_y_pd) || !Number.isFinite(frame_height)) return false;
|
|
1314
|
+
set_chart_hover(frame_index, hover_x_pd * (frame_width() || 1), frame_height - hover_y_pd * frame_height, frame_width(), frame_height);
|
|
1315
|
+
return true;
|
|
1316
|
+
}
|
|
1317
|
+
function begin_touch_hover(frame_index, pointer_x, pointer_y, width = frame_width(), height = null) {
|
|
1318
|
+
const current_hover = get_current_hover_point(frame_index, width, height);
|
|
1319
|
+
const hover_x = current_hover?.x ?? pointer_x;
|
|
1320
|
+
const hover_y = current_hover?.y ?? pointer_y;
|
|
1321
|
+
gesture_state.touch_hover_offset_x = hover_x - pointer_x;
|
|
1322
|
+
gesture_state.touch_hover_offset_y = hover_y - pointer_y;
|
|
1323
|
+
gesture_state.touch_hover_frame_index = frame_index;
|
|
1324
|
+
set_chart_hover(frame_index, hover_x, hover_y, width, height);
|
|
1325
|
+
remember_touch_hover(frame_index);
|
|
1326
|
+
}
|
|
1327
|
+
function update_touch_hover(frame_index, pointer_x, pointer_y, width = frame_width(), height = null) {
|
|
1328
|
+
const hover_frame_index = Number.isInteger(gesture_state.touch_hover_frame_index) ? gesture_state.touch_hover_frame_index : frame_index;
|
|
1329
|
+
const hover_frame_height = chart_prepped?.frames?.[hover_frame_index]?.frame_height;
|
|
1330
|
+
const safe_height = Number(height) > 0 ? Number(height) : hover_frame_height;
|
|
1331
|
+
set_chart_hover(hover_frame_index, pointer_x + (gesture_state.touch_hover_offset_x ?? 0), pointer_y + (gesture_state.touch_hover_offset_y ?? 0), width, safe_height);
|
|
1332
|
+
remember_touch_hover(hover_frame_index);
|
|
1333
|
+
}
|
|
1334
|
+
function handle_pointer_down(e, frame_index) {
|
|
1335
|
+
if (!chart_prepped) return;
|
|
1336
|
+
e.preventDefault();
|
|
1337
|
+
e.currentTarget?.setPointerCapture?.(e.pointerId);
|
|
1338
|
+
const { x, y, width, height } = get_chart_point_from_event(e, frame_index);
|
|
1339
|
+
pointer_cache.set(e.pointerId, {
|
|
1340
|
+
x,
|
|
1341
|
+
y,
|
|
1342
|
+
frame_index,
|
|
1343
|
+
pointer_type: e.pointerType
|
|
1344
|
+
});
|
|
1345
|
+
if (e.pointerType !== "mouse") begin_touch_hover(frame_index, x, y, width, height);
|
|
1346
|
+
if (pointer_cache.size === 1) {
|
|
1347
|
+
gesture_state.mode = "pan";
|
|
1348
|
+
gesture_state.start_shown_start_x = chart_prepped.shown_start_x;
|
|
1349
|
+
gesture_state.start_shown_end_x = chart_prepped.shown_end_x;
|
|
1350
|
+
gesture_state.start_range_sec = chart_prepped.shown_end_x - chart_prepped.shown_start_x;
|
|
1351
|
+
gesture_state.start_primary_x = x;
|
|
1352
|
+
gesture_state.start_primary_y = y;
|
|
1353
|
+
}
|
|
1354
|
+
if (pointer_cache.size === 2) {
|
|
1355
|
+
clear_all_chart_hover();
|
|
1356
|
+
gesture_state.touch_hover_offset_x = null;
|
|
1357
|
+
gesture_state.touch_hover_offset_y = null;
|
|
1358
|
+
gesture_state.touch_hover_frame_index = null;
|
|
1359
|
+
const info = get_two_pointer_info();
|
|
1360
|
+
if (!info) return;
|
|
1361
|
+
gesture_state.mode = "pinch";
|
|
1362
|
+
gesture_state.start_shown_start_x = chart_prepped.shown_start_x;
|
|
1363
|
+
gesture_state.start_shown_end_x = chart_prepped.shown_end_x;
|
|
1364
|
+
gesture_state.start_range_sec = chart_prepped.shown_end_x - chart_prepped.shown_start_x;
|
|
1365
|
+
gesture_state.start_dist_px = info.dist;
|
|
1366
|
+
gesture_state.start_center_pd = frame_width() ? clamp(info.center_x / frame_width(), 0, 1) : .5;
|
|
1367
|
+
}
|
|
1368
|
+
}
|
|
1369
|
+
function handle_pointer_move(e, frame_index) {
|
|
1370
|
+
if (!chart_prepped) return;
|
|
1371
|
+
if (!pointer_cache.has(e.pointerId)) return;
|
|
1372
|
+
e.preventDefault();
|
|
1373
|
+
const { x, y, width, height } = get_chart_point_from_event(e, frame_index);
|
|
1374
|
+
const cached_pointer = pointer_cache.get(e.pointerId);
|
|
1375
|
+
pointer_cache.set(e.pointerId, {
|
|
1376
|
+
...cached_pointer,
|
|
1377
|
+
x,
|
|
1378
|
+
y,
|
|
1379
|
+
frame_index,
|
|
1380
|
+
pointer_type: e.pointerType
|
|
1381
|
+
});
|
|
1382
|
+
if (pointer_cache.size === 1 && gesture_state.mode === "pan") {
|
|
1383
|
+
if (e.pointerType !== "mouse") {
|
|
1384
|
+
update_touch_hover(frame_index, x, y, width, height);
|
|
1385
|
+
return;
|
|
1386
|
+
}
|
|
1387
|
+
const dx_px = x - gesture_state.start_primary_x;
|
|
1388
|
+
const start_range = gesture_state.start_range_sec;
|
|
1389
|
+
if (!frame_width() || !start_range) return;
|
|
1390
|
+
const delta_sec = -dx_px / frame_width() * start_range;
|
|
1391
|
+
apply_view(gesture_state.start_shown_start_x + delta_sec, gesture_state.start_shown_end_x + delta_sec);
|
|
1392
|
+
return;
|
|
1393
|
+
}
|
|
1394
|
+
if (pointer_cache.size >= 2) {
|
|
1395
|
+
clear_all_chart_hover();
|
|
1396
|
+
if (gesture_state.mode !== "pinch") {
|
|
1397
|
+
const info0 = get_two_pointer_info();
|
|
1398
|
+
if (!info0) return;
|
|
1399
|
+
gesture_state.mode = "pinch";
|
|
1400
|
+
gesture_state.start_shown_start_x = chart_prepped.shown_start_x;
|
|
1401
|
+
gesture_state.start_shown_end_x = chart_prepped.shown_end_x;
|
|
1402
|
+
gesture_state.start_range_sec = chart_prepped.shown_end_x - chart_prepped.shown_start_x;
|
|
1403
|
+
gesture_state.start_dist_px = info0.dist;
|
|
1404
|
+
gesture_state.start_center_pd = frame_width() ? clamp(info0.center_x / frame_width(), 0, 1) : .5;
|
|
1405
|
+
}
|
|
1406
|
+
const info = get_two_pointer_info();
|
|
1407
|
+
if (!info || !gesture_state.start_dist_px) return;
|
|
1408
|
+
const dist_ratio = info.dist / gesture_state.start_dist_px;
|
|
1409
|
+
if (!dist_ratio || dist_ratio <= 0) return;
|
|
1410
|
+
const start_range = gesture_state.start_range_sec;
|
|
1411
|
+
const center_pd = gesture_state.start_center_pd ?? .5;
|
|
1412
|
+
const center_time = gesture_state.start_shown_start_x + center_pd * start_range;
|
|
1413
|
+
let next_range = start_range / dist_ratio;
|
|
1414
|
+
next_range = clamp_range_to_limits(next_range);
|
|
1415
|
+
let next_start = center_time - center_pd * next_range;
|
|
1416
|
+
apply_view(next_start, next_start + next_range);
|
|
1417
|
+
}
|
|
1418
|
+
}
|
|
1419
|
+
function handle_pointer_up(e, frame_index) {
|
|
1420
|
+
const pointer_details = pointer_cache.get(e.pointerId);
|
|
1421
|
+
pointer_cache.delete(e.pointerId);
|
|
1422
|
+
if (pointer_cache.size === 0) {
|
|
1423
|
+
if ((pointer_details?.pointer_type ?? e.pointerType) !== "mouse") restore_touch_hover_from_memory(pointer_details?.frame_index ?? frame_index);
|
|
1424
|
+
reset_gesture_state();
|
|
1425
|
+
return;
|
|
1426
|
+
}
|
|
1427
|
+
if (pointer_cache.size === 1) {
|
|
1428
|
+
const remaining = [...pointer_cache.values()][0];
|
|
1429
|
+
gesture_state.mode = "pan";
|
|
1430
|
+
gesture_state.start_shown_start_x = chart_prepped?.shown_start_x;
|
|
1431
|
+
gesture_state.start_shown_end_x = chart_prepped?.shown_end_x;
|
|
1432
|
+
gesture_state.start_range_sec = chart_prepped?.shown_end_x - chart_prepped?.shown_start_x;
|
|
1433
|
+
gesture_state.start_primary_x = remaining?.x;
|
|
1434
|
+
gesture_state.start_primary_y = remaining?.y;
|
|
1435
|
+
gesture_state.start_dist_px = null;
|
|
1436
|
+
gesture_state.start_center_pd = null;
|
|
1437
|
+
if (remaining?.pointer_type !== "mouse" && Number.isInteger(remaining?.frame_index)) begin_touch_hover(remaining.frame_index, remaining.x, remaining.y, frame_width(), chart_prepped?.frames?.[remaining.frame_index]?.frame_height);
|
|
1438
|
+
}
|
|
1439
|
+
}
|
|
1440
|
+
function handle_pointer_cancel(e, frame_index) {
|
|
1441
|
+
const pointer_details = pointer_cache.get(e.pointerId);
|
|
1442
|
+
pointer_cache.delete(e.pointerId);
|
|
1443
|
+
if (pointer_cache.size === 0) {
|
|
1444
|
+
if ((pointer_details?.pointer_type ?? e.pointerType) !== "mouse") restore_touch_hover_from_memory(pointer_details?.frame_index ?? frame_index);
|
|
1445
|
+
reset_gesture_state();
|
|
1446
|
+
return;
|
|
1447
|
+
}
|
|
1448
|
+
if (pointer_cache.size === 1) {
|
|
1449
|
+
const remaining = [...pointer_cache.values()][0];
|
|
1450
|
+
gesture_state.mode = "pan";
|
|
1451
|
+
gesture_state.start_shown_start_x = chart_prepped?.shown_start_x;
|
|
1452
|
+
gesture_state.start_shown_end_x = chart_prepped?.shown_end_x;
|
|
1453
|
+
gesture_state.start_range_sec = chart_prepped?.shown_end_x - chart_prepped?.shown_start_x;
|
|
1454
|
+
gesture_state.start_primary_x = remaining?.x;
|
|
1455
|
+
gesture_state.start_primary_y = remaining?.y;
|
|
1456
|
+
gesture_state.start_dist_px = null;
|
|
1457
|
+
gesture_state.start_center_pd = null;
|
|
1458
|
+
if (remaining?.pointer_type !== "mouse" && Number.isInteger(remaining?.frame_index)) begin_touch_hover(remaining.frame_index, remaining.x, remaining.y, frame_width(), chart_prepped?.frames?.[remaining.frame_index]?.frame_height);
|
|
1459
|
+
}
|
|
1460
|
+
}
|
|
1461
|
+
function handle_scroll_y_axis(e, frame_index) {
|
|
1462
|
+
if (!chart_prepped) return;
|
|
1463
|
+
e.preventDefault();
|
|
1464
|
+
e.stopPropagation();
|
|
1465
|
+
const { frame, axis } = get_y_axis_state(frame_index);
|
|
1466
|
+
if (!axis) return;
|
|
1467
|
+
const zoom_factor = get_y_axis_zoom_factor_from_wheel(e.deltaY);
|
|
1468
|
+
if (!Number.isFinite(zoom_factor) || zoom_factor === 1) return;
|
|
1469
|
+
const { low_y: current_low_y, high_y: current_high_y } = get_current_y_bounds(axis);
|
|
1470
|
+
const current_range_y = current_high_y - current_low_y;
|
|
1471
|
+
if (!Number.isFinite(current_range_y) || current_range_y <= 0) return;
|
|
1472
|
+
const rect = e.currentTarget?.getBoundingClientRect?.();
|
|
1473
|
+
const height = rect?.height || frame?.frame_height || 1;
|
|
1474
|
+
const anchor_pd = clamp((height - (rect ? e.clientY - rect.top : e.offsetY)) / height, 0, 1);
|
|
1475
|
+
const anchor_y = current_low_y + anchor_pd * current_range_y;
|
|
1476
|
+
const next_range_y = clamp_y_range_to_limits(current_range_y * zoom_factor, axis);
|
|
1477
|
+
const next_low_y = anchor_y - anchor_pd * next_range_y;
|
|
1478
|
+
set_manual_y_bounds(axis, next_low_y, next_low_y + next_range_y);
|
|
1479
|
+
}
|
|
1480
|
+
function reset_y_axis_gesture_state() {
|
|
1481
|
+
y_axis_pointer_cache.clear();
|
|
1482
|
+
y_axis_gesture_state.mode = null;
|
|
1483
|
+
y_axis_gesture_state.frame_index = null;
|
|
1484
|
+
y_axis_gesture_state.start_y = null;
|
|
1485
|
+
y_axis_gesture_state.start_dist_px = null;
|
|
1486
|
+
y_axis_gesture_state.start_range_y = null;
|
|
1487
|
+
y_axis_gesture_state.start_low_y = null;
|
|
1488
|
+
y_axis_gesture_state.start_high_y = null;
|
|
1489
|
+
y_axis_gesture_state.anchor_pd = null;
|
|
1490
|
+
y_axis_gesture_state.anchor_y = null;
|
|
1491
|
+
y_axis_gesture_state.did_drag = false;
|
|
1492
|
+
}
|
|
1493
|
+
function get_y_axis_point_from_event(e, frame_index) {
|
|
1494
|
+
const { frame } = get_y_axis_state(frame_index);
|
|
1495
|
+
const rect = e.currentTarget?.getBoundingClientRect?.();
|
|
1496
|
+
const height = rect?.height || frame?.frame_height || 1;
|
|
1497
|
+
const y = clamp((rect ? e.clientY - rect.top : e.offsetY) ?? 0, 0, height);
|
|
1498
|
+
return {
|
|
1499
|
+
y,
|
|
1500
|
+
y_pd: clamp((height - y) / height, 0, 1),
|
|
1501
|
+
height
|
|
1502
|
+
};
|
|
1503
|
+
}
|
|
1504
|
+
function get_two_y_axis_pointer_info() {
|
|
1505
|
+
const pts = [...y_axis_pointer_cache.values()];
|
|
1506
|
+
if (pts.length < 2) return null;
|
|
1507
|
+
const a = pts[0];
|
|
1508
|
+
const b = pts[1];
|
|
1509
|
+
const dist = Math.max(Math.abs(b.y - a.y), min_y_axis_pinch_dist_px);
|
|
1510
|
+
const center_y = (a.y + b.y) / 2;
|
|
1511
|
+
const height = a.height || b.height || 1;
|
|
1512
|
+
return {
|
|
1513
|
+
dist,
|
|
1514
|
+
center_y,
|
|
1515
|
+
center_pd: clamp((height - center_y) / height, 0, 1),
|
|
1516
|
+
height
|
|
1517
|
+
};
|
|
1518
|
+
}
|
|
1519
|
+
function set_y_axis_gesture_baseline(frame_index, start_y, anchor_pd, axis, mode = "pan", start_dist_px = null) {
|
|
1520
|
+
const { low_y: start_low_y, high_y: start_high_y } = get_current_y_bounds(axis);
|
|
1521
|
+
const start_range_y = start_high_y - start_low_y;
|
|
1522
|
+
if (!Number.isFinite(start_range_y) || start_range_y <= 0) return false;
|
|
1523
|
+
y_axis_gesture_state.mode = mode;
|
|
1524
|
+
y_axis_gesture_state.frame_index = frame_index;
|
|
1525
|
+
y_axis_gesture_state.start_y = start_y;
|
|
1526
|
+
y_axis_gesture_state.start_dist_px = start_dist_px;
|
|
1527
|
+
y_axis_gesture_state.start_range_y = start_range_y;
|
|
1528
|
+
y_axis_gesture_state.start_low_y = start_low_y;
|
|
1529
|
+
y_axis_gesture_state.start_high_y = start_high_y;
|
|
1530
|
+
y_axis_gesture_state.anchor_pd = anchor_pd;
|
|
1531
|
+
y_axis_gesture_state.anchor_y = start_low_y + anchor_pd * start_range_y;
|
|
1532
|
+
return true;
|
|
1533
|
+
}
|
|
1534
|
+
function handle_y_axis_pointer_down(e, frame_index) {
|
|
1535
|
+
if (!chart_prepped || e.button > 0) return;
|
|
1536
|
+
const { frame, axis } = get_y_axis_state(frame_index);
|
|
1537
|
+
if (!frame || !axis) return;
|
|
1538
|
+
e.preventDefault();
|
|
1539
|
+
e.stopPropagation();
|
|
1540
|
+
e.currentTarget?.setPointerCapture?.(e.pointerId);
|
|
1541
|
+
const point = get_y_axis_point_from_event(e, frame_index);
|
|
1542
|
+
y_axis_pointer_cache.set(e.pointerId, {
|
|
1543
|
+
y: point.y,
|
|
1544
|
+
height: point.height,
|
|
1545
|
+
frame_index
|
|
1546
|
+
});
|
|
1547
|
+
y_axis_gesture_state.did_drag = false;
|
|
1548
|
+
if (y_axis_pointer_cache.size >= 2) {
|
|
1549
|
+
const info = get_two_y_axis_pointer_info();
|
|
1550
|
+
if (!info) return;
|
|
1551
|
+
if (!set_y_axis_gesture_baseline(frame_index, info.center_y, info.center_pd, axis, "pinch", info.dist)) y_axis_pointer_cache.delete(e.pointerId);
|
|
1552
|
+
return;
|
|
1553
|
+
}
|
|
1554
|
+
if (!set_y_axis_gesture_baseline(frame_index, point.y, point.y_pd, axis, "pan")) y_axis_pointer_cache.delete(e.pointerId);
|
|
1555
|
+
}
|
|
1556
|
+
function handle_y_axis_pointer_move(e, frame_index) {
|
|
1557
|
+
if (!chart_prepped) return;
|
|
1558
|
+
if (!y_axis_pointer_cache.has(e.pointerId) || y_axis_gesture_state.frame_index !== frame_index) return;
|
|
1559
|
+
const { frame, axis } = get_y_axis_state(frame_index);
|
|
1560
|
+
if (!frame || !axis) return;
|
|
1561
|
+
e.preventDefault();
|
|
1562
|
+
e.stopPropagation();
|
|
1563
|
+
const point = get_y_axis_point_from_event(e, frame_index);
|
|
1564
|
+
y_axis_pointer_cache.set(e.pointerId, {
|
|
1565
|
+
y: point.y,
|
|
1566
|
+
height: point.height,
|
|
1567
|
+
frame_index
|
|
1568
|
+
});
|
|
1569
|
+
if (y_axis_pointer_cache.size >= 2) {
|
|
1570
|
+
if (y_axis_gesture_state.mode !== "pinch") {
|
|
1571
|
+
const info0 = get_two_y_axis_pointer_info();
|
|
1572
|
+
if (!info0) return;
|
|
1573
|
+
set_y_axis_gesture_baseline(frame_index, info0.center_y, info0.center_pd, axis, "pinch", info0.dist);
|
|
1574
|
+
}
|
|
1575
|
+
const info = get_two_y_axis_pointer_info();
|
|
1576
|
+
if (!info || !y_axis_gesture_state.start_dist_px) return;
|
|
1577
|
+
if (Math.abs(info.dist - y_axis_gesture_state.start_dist_px) > 4) y_axis_gesture_state.did_drag = true;
|
|
1578
|
+
const dist_ratio = info.dist / y_axis_gesture_state.start_dist_px;
|
|
1579
|
+
if (!Number.isFinite(dist_ratio) || dist_ratio <= 0) return;
|
|
1580
|
+
const next_range_y = clamp_y_range_to_limits(y_axis_gesture_state.start_range_y / dist_ratio, axis);
|
|
1581
|
+
const next_low_y = y_axis_gesture_state.anchor_y - y_axis_gesture_state.anchor_pd * next_range_y;
|
|
1582
|
+
set_manual_y_bounds(axis, next_low_y, next_low_y + next_range_y);
|
|
1583
|
+
return;
|
|
1584
|
+
}
|
|
1585
|
+
const height = point.height;
|
|
1586
|
+
const delta_y = point.y - y_axis_gesture_state.start_y;
|
|
1587
|
+
if (Math.abs(delta_y) > 4) y_axis_gesture_state.did_drag = true;
|
|
1588
|
+
if (!Number.isFinite(height) || height <= 0 || !Number.isFinite(y_axis_gesture_state.start_range_y)) return;
|
|
1589
|
+
const price_delta_y = delta_y / height * y_axis_gesture_state.start_range_y;
|
|
1590
|
+
set_manual_y_bounds(axis, y_axis_gesture_state.start_low_y + price_delta_y, y_axis_gesture_state.start_high_y + price_delta_y);
|
|
1591
|
+
}
|
|
1592
|
+
function handle_y_axis_pointer_up(e, frame_index) {
|
|
1593
|
+
if (!y_axis_pointer_cache.has(e.pointerId) || y_axis_gesture_state.frame_index !== frame_index) return;
|
|
1594
|
+
e.preventDefault();
|
|
1595
|
+
e.stopPropagation();
|
|
1596
|
+
y_axis_pointer_cache.delete(e.pointerId);
|
|
1597
|
+
if (y_axis_pointer_cache.size === 0) {
|
|
1598
|
+
y_axis_gesture_state.suppress_click = y_axis_gesture_state.did_drag;
|
|
1599
|
+
reset_y_axis_gesture_state();
|
|
1600
|
+
return;
|
|
1601
|
+
}
|
|
1602
|
+
const remaining = [...y_axis_pointer_cache.values()][0];
|
|
1603
|
+
const { axis } = get_y_axis_state(remaining.frame_index);
|
|
1604
|
+
if (axis) {
|
|
1605
|
+
const anchor_pd = clamp((remaining.height - remaining.y) / remaining.height, 0, 1);
|
|
1606
|
+
set_y_axis_gesture_baseline(remaining.frame_index, remaining.y, anchor_pd, axis, "pan");
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1609
|
+
function handle_y_axis_pointer_cancel(e, frame_index) {
|
|
1610
|
+
if (!y_axis_pointer_cache.has(e.pointerId) || y_axis_gesture_state.frame_index !== frame_index) return;
|
|
1611
|
+
e.preventDefault();
|
|
1612
|
+
e.stopPropagation();
|
|
1613
|
+
y_axis_pointer_cache.delete(e.pointerId);
|
|
1614
|
+
if (y_axis_pointer_cache.size === 0) {
|
|
1615
|
+
y_axis_gesture_state.suppress_click = y_axis_gesture_state.did_drag;
|
|
1616
|
+
reset_y_axis_gesture_state();
|
|
1617
|
+
return;
|
|
1618
|
+
}
|
|
1619
|
+
const remaining = [...y_axis_pointer_cache.values()][0];
|
|
1620
|
+
const { axis } = get_y_axis_state(remaining.frame_index);
|
|
1621
|
+
if (axis) {
|
|
1622
|
+
const anchor_pd = clamp((remaining.height - remaining.y) / remaining.height, 0, 1);
|
|
1623
|
+
set_y_axis_gesture_baseline(remaining.frame_index, remaining.y, anchor_pd, axis, "pan");
|
|
1624
|
+
}
|
|
1625
|
+
}
|
|
1626
|
+
function handle_y_axis_click(frame_index) {
|
|
1627
|
+
if (y_axis_gesture_state.suppress_click) {
|
|
1628
|
+
y_axis_gesture_state.suppress_click = false;
|
|
1629
|
+
return;
|
|
1630
|
+
}
|
|
1631
|
+
chart_prepped?.frames?.[frame_index]?.change_shown_y_axis?.();
|
|
1632
|
+
}
|
|
1633
|
+
function handle_chart_hover(e, frame_index) {
|
|
1634
|
+
const point = get_chart_point_from_event(e, frame_index);
|
|
1635
|
+
set_chart_hover(frame_index, point.x, point.y, point.width, point.height);
|
|
1636
|
+
}
|
|
1637
|
+
function handle_chart_hover_leave(e, frame_index) {
|
|
1638
|
+
if (e?.relatedTarget?.closest?.(".floater")) {
|
|
1639
|
+
clear_chart_hover(frame_index, { clear_x: false });
|
|
1640
|
+
return;
|
|
1641
|
+
}
|
|
1642
|
+
clear_chart_hover(frame_index);
|
|
1643
|
+
}
|
|
1644
|
+
function refresh_chart(opts = {}) {
|
|
1645
|
+
const keep_view = typeof opts.keep_view === "boolean" ? opts.keep_view : true;
|
|
1646
|
+
if (!grid_width || !datasets) return;
|
|
1647
|
+
if (!chart_prepped) {
|
|
1648
|
+
chart_prepped = prep_chart({ ...config?.chart });
|
|
1649
|
+
return;
|
|
1650
|
+
}
|
|
1651
|
+
const next_chart = { ...chart_prepped };
|
|
1652
|
+
if (!keep_view) {
|
|
1653
|
+
next_chart.shown_start_x = null;
|
|
1654
|
+
next_chart.shown_end_x = null;
|
|
1655
|
+
}
|
|
1656
|
+
chart_prepped = prep_chart(next_chart);
|
|
1657
|
+
}
|
|
1658
|
+
function pad2(n) {
|
|
1659
|
+
const s = String(n);
|
|
1660
|
+
return s.length < 2 ? "0" + s : s;
|
|
1661
|
+
}
|
|
1662
|
+
function readable_time_full_to_minute(seconds) {
|
|
1663
|
+
if (seconds == null || isNaN(seconds)) return "-";
|
|
1664
|
+
const d = /* @__PURE__ */ new Date(seconds * 1e3);
|
|
1665
|
+
return `${d.getFullYear()}-${pad2(d.getMonth() + 1)}-${pad2(d.getDate())} ${pad2(d.getHours())}:${pad2(d.getMinutes())}`;
|
|
1666
|
+
}
|
|
1667
|
+
function get_path_d(data) {
|
|
1668
|
+
if (!Array.isArray(data) || data.length === 0) return null;
|
|
1669
|
+
let path_d = null;
|
|
1670
|
+
for (let datapoint of data) {
|
|
1671
|
+
const x = Number(datapoint?.x);
|
|
1672
|
+
const y = Number(datapoint?.y);
|
|
1673
|
+
if (!Number.isFinite(x) || !Number.isFinite(y)) continue;
|
|
1674
|
+
const point = `${(x * 100).toPrecision(4)} ${(100 - y * 100).toPrecision(4)}`;
|
|
1675
|
+
path_d = path_d == null ? `M${point}` : `${path_d} L${point}`;
|
|
1676
|
+
}
|
|
1677
|
+
return path_d;
|
|
1678
|
+
}
|
|
1679
|
+
function prep_chart(input) {
|
|
1680
|
+
if (!input || !datasets || !grid_width) {
|
|
1681
|
+
chart_prepped = null;
|
|
1682
|
+
return;
|
|
1683
|
+
}
|
|
1684
|
+
let id = input?.id;
|
|
1685
|
+
let x_axis_type = input?.x_axis_type;
|
|
1686
|
+
let x_axis_title = input?.x_axis_title;
|
|
1687
|
+
let shown_start_x = input?.shown_start_x;
|
|
1688
|
+
let shown_end_x = input?.shown_end_x;
|
|
1689
|
+
let frames = input?.frames;
|
|
1690
|
+
let min_x_scrollable = input?.min_x_scrollable;
|
|
1691
|
+
let max_x_scrollable = input?.max_x_scrollable;
|
|
1692
|
+
let x_axis_highlight_tic = input?.x_axis_highlight_tic;
|
|
1693
|
+
let x_hovered_percent_decimal = input?.x_hovered_percent_decimal;
|
|
1694
|
+
let all_data_start_x_loc = null;
|
|
1695
|
+
let all_data_end_x_loc = null;
|
|
1696
|
+
let most_datapoints_for_x_dataset = 0;
|
|
1697
|
+
if (Array.isArray(frames)) {
|
|
1698
|
+
for (let frame of frames) if (Array.isArray(frame?.shared_y_axiss)) {
|
|
1699
|
+
for (let shared_y_axis of frame.shared_y_axiss) if (Array.isArray(shared_y_axis?.datasets)) for (let dataset of shared_y_axis.datasets) {
|
|
1700
|
+
let most_datapoints_for_x_dataset_loc = 0;
|
|
1701
|
+
if ([
|
|
1702
|
+
"klines",
|
|
1703
|
+
"path",
|
|
1704
|
+
"points"
|
|
1705
|
+
].some((h) => h == dataset.type) && Array.isArray(datasets[dataset?.dataset_id]?.data) && datasets[dataset?.dataset_id]?.data.length > 0) for (let datapoint of datasets[dataset.dataset_id].data) {
|
|
1706
|
+
most_datapoints_for_x_dataset_loc++;
|
|
1707
|
+
if (all_data_start_x_loc == void 0 || all_data_start_x_loc == null || isNaN(all_data_start_x_loc) || datapoint?.[dataset?.keys?.[0]] < all_data_start_x_loc) all_data_start_x_loc = datapoint?.[dataset?.keys?.[0]];
|
|
1708
|
+
if (all_data_end_x_loc == void 0 || all_data_end_x_loc == null || isNaN(all_data_end_x_loc) || datapoint?.[dataset?.keys?.[0]] > all_data_end_x_loc) all_data_end_x_loc = datapoint?.[dataset?.keys?.[0]];
|
|
1709
|
+
}
|
|
1710
|
+
if (most_datapoints_for_x_dataset_loc > most_datapoints_for_x_dataset) most_datapoints_for_x_dataset = most_datapoints_for_x_dataset_loc;
|
|
1711
|
+
}
|
|
1712
|
+
}
|
|
1713
|
+
}
|
|
1714
|
+
const x_range = all_data_end_x_loc - all_data_start_x_loc;
|
|
1715
|
+
let range_to_show = x_range;
|
|
1716
|
+
let shown_start_x_loc = all_data_start_x_loc;
|
|
1717
|
+
if (most_datapoints_for_x_dataset > 20) {
|
|
1718
|
+
range_to_show = x_range * range_to_show_default / most_datapoints_for_x_dataset;
|
|
1719
|
+
shown_start_x_loc = all_data_end_x_loc - parseFloat(range_to_show.toPrecision(8));
|
|
1720
|
+
}
|
|
1721
|
+
min_x_scrollable = all_data_start_x_loc + Math.floor(range_to_show * .1);
|
|
1722
|
+
max_x_scrollable = all_data_end_x_loc - Math.floor(range_to_show * .1);
|
|
1723
|
+
if (shown_start_x == null || isNaN(shown_start_x)) shown_start_x = shown_start_x_loc;
|
|
1724
|
+
if (shown_end_x == null || isNaN(shown_end_x)) shown_end_x = all_data_end_x_loc;
|
|
1725
|
+
let prepped_frames = [];
|
|
1726
|
+
for (let frame of frames) {
|
|
1727
|
+
const frame_height = frame_width() / frame.aspect_ratio;
|
|
1728
|
+
let shown_y_axis_index = Number.isInteger(frame?.shown_y_axis_index) ? frame.shown_y_axis_index : 0;
|
|
1729
|
+
let prepped_shared_y_axiss = [];
|
|
1730
|
+
for (let shared_y_axis of frame.shared_y_axiss) {
|
|
1731
|
+
let data_low_y = Infinity;
|
|
1732
|
+
let data_high_y = -Infinity;
|
|
1733
|
+
let fallback_low_y = Infinity;
|
|
1734
|
+
let fallback_high_y = -Infinity;
|
|
1735
|
+
let pre_prepped_datasets = [];
|
|
1736
|
+
function register_y_value(value, include_in_primary = true) {
|
|
1737
|
+
if (!is_finite_num(value)) return;
|
|
1738
|
+
const safe_value = Number(value);
|
|
1739
|
+
fallback_low_y = Math.min(fallback_low_y, safe_value);
|
|
1740
|
+
fallback_high_y = Math.max(fallback_high_y, safe_value);
|
|
1741
|
+
if (!include_in_primary) return;
|
|
1742
|
+
data_low_y = Math.min(data_low_y, safe_value);
|
|
1743
|
+
data_high_y = Math.max(data_high_y, safe_value);
|
|
1744
|
+
}
|
|
1745
|
+
for (let dataset of shared_y_axis.datasets) {
|
|
1746
|
+
const affects_y_scale = dataset?.affects_y_scale ?? dataset?.type !== "lines";
|
|
1747
|
+
let shown_data = [];
|
|
1748
|
+
let d_loc = null;
|
|
1749
|
+
if (dataset.type === "klines" && dataset?.keys?.length == 5 && datasets[dataset?.dataset_id]?.data) {
|
|
1750
|
+
for (let kline of datasets[dataset?.dataset_id]?.data) if (!isNaN(kline[dataset?.keys[0]]) && !isNaN(kline[dataset?.keys[1]]) && !isNaN(kline[dataset?.keys[2]]) && !isNaN(kline[dataset?.keys[3]]) && !isNaN(kline[dataset?.keys[4]]) && shown_start_x <= kline[dataset?.keys[0]] && kline[dataset?.keys[0]] < shown_end_x) {
|
|
1751
|
+
const item_to_add = {
|
|
1752
|
+
x: kline[dataset?.keys[0]],
|
|
1753
|
+
o: kline[dataset?.keys[1]],
|
|
1754
|
+
l: kline[dataset?.keys[2]],
|
|
1755
|
+
h: kline[dataset?.keys[3]],
|
|
1756
|
+
c: kline[dataset?.keys[4]]
|
|
1757
|
+
};
|
|
1758
|
+
shown_data.push(item_to_add);
|
|
1759
|
+
register_y_value(item_to_add.l, affects_y_scale);
|
|
1760
|
+
register_y_value(item_to_add.h, affects_y_scale);
|
|
1761
|
+
}
|
|
1762
|
+
} else if (["points", "path"].some((h) => h == dataset.type) && dataset?.keys?.length == 2 && datasets[dataset?.dataset_id]?.data) {
|
|
1763
|
+
for (let datapoint of datasets[dataset?.dataset_id]?.data) if (!isNaN(datapoint[dataset?.keys[0]]) && !isNaN(datapoint[dataset?.keys[1]]) && shown_start_x <= datapoint[dataset?.keys[0]] && datapoint[dataset?.keys[0]] < shown_end_x) {
|
|
1764
|
+
const item_to_add = {
|
|
1765
|
+
x: datapoint[dataset?.keys[0]],
|
|
1766
|
+
y: datapoint[dataset?.keys[1]]
|
|
1767
|
+
};
|
|
1768
|
+
shown_data.push(item_to_add);
|
|
1769
|
+
register_y_value(item_to_add.y, affects_y_scale);
|
|
1770
|
+
}
|
|
1771
|
+
} else if (dataset.type == "lines" && dataset?.keys?.length > 1 && datasets[dataset?.dataset_id]?.data) {
|
|
1772
|
+
for (let datapoint of datasets[dataset?.dataset_id]?.data) if (!isNaN(datapoint[dataset?.keys[0]]) && !isNaN(datapoint[dataset?.keys[1]])) {
|
|
1773
|
+
const item_to_add = {
|
|
1774
|
+
m: datapoint[dataset?.keys[0]],
|
|
1775
|
+
b: datapoint[dataset?.keys[1]],
|
|
1776
|
+
s: dataset?.keys?.length > 2 ? datapoint[dataset?.keys[2]] : null
|
|
1777
|
+
};
|
|
1778
|
+
shown_data.push(item_to_add);
|
|
1779
|
+
register_y_value(item_to_add.m * shown_start_x + item_to_add.b, affects_y_scale);
|
|
1780
|
+
register_y_value(item_to_add.m * shown_end_x + item_to_add.b, affects_y_scale);
|
|
1781
|
+
register_y_value(datasets[dataset?.dataset_id]?.y_min, affects_y_scale);
|
|
1782
|
+
register_y_value(datasets[dataset?.dataset_id]?.y_max, affects_y_scale);
|
|
1783
|
+
}
|
|
1784
|
+
}
|
|
1785
|
+
let color_one = dataset?.colors.length > 0 ? gen_color(dataset?.colors[0].l, dataset?.colors[0].c, dataset?.colors[0].h, dataset?.colors[0].o, dataset?.colors[0].is_theme_based) : "#44ff4450";
|
|
1786
|
+
let color_two = dataset?.colors.length > 1 ? gen_color(dataset?.colors[1].l, dataset?.colors[1].c, dataset?.colors[1].h, dataset?.colors[1].o, dataset?.colors[1].is_theme_based) : color_one ? color_one : "#ff444450";
|
|
1787
|
+
pre_prepped_datasets.push({
|
|
1788
|
+
type: dataset.type,
|
|
1789
|
+
data: shown_data,
|
|
1790
|
+
dataset_id: dataset.dataset_id,
|
|
1791
|
+
name: dataset.name,
|
|
1792
|
+
period_x: dataset.period_x,
|
|
1793
|
+
colors: dataset.colors,
|
|
1794
|
+
color_one,
|
|
1795
|
+
color_two,
|
|
1796
|
+
d: d_loc,
|
|
1797
|
+
keys: dataset.keys,
|
|
1798
|
+
affects_y_scale
|
|
1799
|
+
});
|
|
1800
|
+
}
|
|
1801
|
+
if (!Number.isFinite(data_low_y) || !Number.isFinite(data_high_y)) {
|
|
1802
|
+
data_low_y = fallback_low_y;
|
|
1803
|
+
data_high_y = fallback_high_y;
|
|
1804
|
+
}
|
|
1805
|
+
if (!(Number.isFinite(data_low_y) && Number.isFinite(data_high_y))) {
|
|
1806
|
+
data_low_y = 0;
|
|
1807
|
+
data_high_y = 1;
|
|
1808
|
+
}
|
|
1809
|
+
const has_manual_y_bounds = is_finite_num(shared_y_axis?.manual_low_y) && is_finite_num(shared_y_axis?.manual_high_y) && Number(shared_y_axis.manual_high_y) > Number(shared_y_axis.manual_low_y);
|
|
1810
|
+
let shown_low_y = has_manual_y_bounds ? Number(shared_y_axis.manual_low_y) : null;
|
|
1811
|
+
let shown_high_y = has_manual_y_bounds ? Number(shared_y_axis.manual_high_y) : null;
|
|
1812
|
+
if (!has_manual_y_bounds) {
|
|
1813
|
+
const padded_y_bounds = get_padded_y_bounds(data_low_y, data_high_y, shared_y_axis.top_padding_pd, shared_y_axis.bottom_padding_pd);
|
|
1814
|
+
shown_low_y = padded_y_bounds.shown_low_y;
|
|
1815
|
+
shown_high_y = padded_y_bounds.shown_high_y;
|
|
1816
|
+
}
|
|
1817
|
+
let shown_y_range = shown_high_y - shown_low_y;
|
|
1818
|
+
if (!Number.isFinite(shown_y_range) || shown_y_range <= 0) {
|
|
1819
|
+
shown_y_range = get_safe_y_range(shown_low_y, shown_high_y);
|
|
1820
|
+
shown_low_y = Number(shown_low_y) - shown_y_range / 2;
|
|
1821
|
+
shown_high_y = shown_low_y + shown_y_range;
|
|
1822
|
+
}
|
|
1823
|
+
const shown_x_range = shown_end_x - shown_start_x;
|
|
1824
|
+
let prepped_datasets = [];
|
|
1825
|
+
for (let pre_prepped_dataset of pre_prepped_datasets) {
|
|
1826
|
+
const kline_width_pd = pre_prepped_dataset.period_x * 1 / shown_x_range;
|
|
1827
|
+
let normalized_datapoints_in_range_loc = [];
|
|
1828
|
+
for (let datapoint of pre_prepped_dataset.data) if (pre_prepped_dataset.type === "klines") {
|
|
1829
|
+
const norm_x = (datapoint.x - shown_start_x) / shown_x_range;
|
|
1830
|
+
const norm_o = (datapoint.o - shown_low_y) / shown_y_range;
|
|
1831
|
+
const norm_l = (datapoint.l - shown_low_y) / shown_y_range;
|
|
1832
|
+
const norm_h = (datapoint.h - shown_low_y) / shown_y_range;
|
|
1833
|
+
const norm_c = (datapoint.c - shown_low_y) / shown_y_range;
|
|
1834
|
+
const norm_details = get_kline_details(norm_o, norm_l, norm_h, norm_c);
|
|
1835
|
+
normalized_datapoints_in_range_loc.push({
|
|
1836
|
+
x: parseFloat(norm_x.toPrecision(6)),
|
|
1837
|
+
o: parseFloat(norm_o.toPrecision(6)),
|
|
1838
|
+
l: parseFloat(norm_l.toPrecision(6)),
|
|
1839
|
+
h: parseFloat(norm_h.toPrecision(6)),
|
|
1840
|
+
c: parseFloat(norm_c.toPrecision(6)),
|
|
1841
|
+
...norm_details
|
|
1842
|
+
});
|
|
1843
|
+
} else if (pre_prepped_dataset.type === "lines") {
|
|
1844
|
+
let x1 = shown_start_x;
|
|
1845
|
+
let y1 = datapoint.m * x1 + datapoint.b;
|
|
1846
|
+
if (y1 < shown_low_y) {
|
|
1847
|
+
x1 = (shown_low_y - datapoint.b) / datapoint.m;
|
|
1848
|
+
y1 = shown_low_y;
|
|
1849
|
+
} else if (y1 > shown_high_y) {
|
|
1850
|
+
x1 = (shown_high_y - datapoint.b) / datapoint.m;
|
|
1851
|
+
y1 = shown_high_y;
|
|
1852
|
+
}
|
|
1853
|
+
let x2 = shown_end_x;
|
|
1854
|
+
let y2 = datapoint.m * x2 + datapoint.b;
|
|
1855
|
+
if (y2 < shown_low_y) {
|
|
1856
|
+
x2 = (shown_low_y - datapoint.b) / datapoint.m;
|
|
1857
|
+
y2 = shown_low_y;
|
|
1858
|
+
} else if (y2 > shown_high_y) {
|
|
1859
|
+
x2 = (shown_high_y - datapoint.b) / datapoint.m;
|
|
1860
|
+
y2 = shown_high_y;
|
|
1861
|
+
}
|
|
1862
|
+
const norm_y1 = (y1 - shown_low_y) / shown_y_range;
|
|
1863
|
+
const norm_y2 = (y2 - shown_low_y) / shown_y_range;
|
|
1864
|
+
const norm_x1 = (x1 - shown_start_x) / shown_x_range;
|
|
1865
|
+
const norm_x2 = (x2 - shown_start_x) / shown_x_range;
|
|
1866
|
+
normalized_datapoints_in_range_loc.push({
|
|
1867
|
+
x1: parseFloat(norm_x1.toPrecision(6)),
|
|
1868
|
+
y1: parseFloat(norm_y1.toPrecision(6)),
|
|
1869
|
+
x2: parseFloat(norm_x2.toPrecision(6)),
|
|
1870
|
+
y2: parseFloat(norm_y2.toPrecision(6)),
|
|
1871
|
+
s: datapoint?.s
|
|
1872
|
+
});
|
|
1873
|
+
} else {
|
|
1874
|
+
const norm_x = (datapoint.x - shown_start_x) / shown_x_range;
|
|
1875
|
+
const norm_y = (datapoint.y - shown_low_y) / shown_y_range;
|
|
1876
|
+
normalized_datapoints_in_range_loc.push({
|
|
1877
|
+
x: parseFloat(norm_x.toPrecision(6)),
|
|
1878
|
+
y: parseFloat(norm_y.toPrecision(6))
|
|
1879
|
+
});
|
|
1880
|
+
}
|
|
1881
|
+
const d_loc_normalized = pre_prepped_dataset.type === "path" ? get_path_d(normalized_datapoints_in_range_loc) : pre_prepped_dataset.d;
|
|
1882
|
+
pre_prepped_dataset.data = normalized_datapoints_in_range_loc;
|
|
1883
|
+
pre_prepped_dataset.d = d_loc_normalized;
|
|
1884
|
+
prepped_datasets.push({
|
|
1885
|
+
...pre_prepped_dataset,
|
|
1886
|
+
kline_width_pd: parseFloat(kline_width_pd.toPrecision(8))
|
|
1887
|
+
});
|
|
1888
|
+
}
|
|
1889
|
+
const y_tics = prep_y_axis(shown_low_y, shown_high_y, frame_height);
|
|
1890
|
+
prepped_shared_y_axiss.push({
|
|
1891
|
+
bottom_padding_pd: shared_y_axis.bottom_padding_pd,
|
|
1892
|
+
top_padding_pd: shared_y_axis.top_padding_pd,
|
|
1893
|
+
y_axis_title: shared_y_axis.y_axis_title,
|
|
1894
|
+
y_axis_type: shared_y_axis.y_axis_type,
|
|
1895
|
+
data_low_y: parseFloat(data_low_y.toPrecision(8)),
|
|
1896
|
+
data_high_y: parseFloat(data_high_y.toPrecision(8)),
|
|
1897
|
+
manual_low_y: has_manual_y_bounds ? parseFloat(Number(shared_y_axis.manual_low_y).toPrecision(10)) : null,
|
|
1898
|
+
manual_high_y: has_manual_y_bounds ? parseFloat(Number(shared_y_axis.manual_high_y).toPrecision(10)) : null,
|
|
1899
|
+
shown_low_y: parseFloat(shown_low_y.toPrecision(8)),
|
|
1900
|
+
shown_high_y: parseFloat(shown_high_y.toPrecision(8)),
|
|
1901
|
+
y_axis_tics: y_tics,
|
|
1902
|
+
y_axis_highlight_tic: null,
|
|
1903
|
+
datasets: prepped_datasets
|
|
1904
|
+
});
|
|
1905
|
+
}
|
|
1906
|
+
function change_shown_y_axis() {
|
|
1907
|
+
shown_y_axis_index = shown_y_axis_index < frame?.shared_y_axiss.length - 1 ? shown_y_axis_index + 1 : 0;
|
|
1908
|
+
}
|
|
1909
|
+
prepped_frames.push({
|
|
1910
|
+
get aspect_ratio() {
|
|
1911
|
+
return frame.aspect_ratio;
|
|
1912
|
+
},
|
|
1913
|
+
get frame_height() {
|
|
1914
|
+
return frame_height;
|
|
1915
|
+
},
|
|
1916
|
+
get shared_y_axiss() {
|
|
1917
|
+
return prepped_shared_y_axiss;
|
|
1918
|
+
},
|
|
1919
|
+
get shown_y_axis_index() {
|
|
1920
|
+
return shown_y_axis_index;
|
|
1921
|
+
},
|
|
1922
|
+
y_hovered_percent_decimal: null,
|
|
1923
|
+
change_shown_y_axis
|
|
1924
|
+
});
|
|
1925
|
+
}
|
|
1926
|
+
frames = prepped_frames;
|
|
1927
|
+
let x_axis_tics = prep_x_axis(shown_start_x, shown_end_x, frame_width());
|
|
1928
|
+
function set_shown_start_x(input) {
|
|
1929
|
+
shown_start_x = input;
|
|
1930
|
+
}
|
|
1931
|
+
function set_shown_end_x(input) {
|
|
1932
|
+
shown_end_x = input;
|
|
1933
|
+
}
|
|
1934
|
+
function set_x_hovered_percent_decimal(input) {
|
|
1935
|
+
x_hovered_percent_decimal = input;
|
|
1936
|
+
const hover_x_sec = input * (shown_end_x - shown_start_x) + shown_start_x;
|
|
1937
|
+
x_axis_highlight_tic = readable_time_full_to_minute(Math.round(hover_x_sec / 60) * 60);
|
|
1938
|
+
}
|
|
1939
|
+
return {
|
|
1940
|
+
get id() {
|
|
1941
|
+
return id;
|
|
1942
|
+
},
|
|
1943
|
+
get x_axis_type() {
|
|
1944
|
+
return x_axis_type;
|
|
1945
|
+
},
|
|
1946
|
+
get x_axis_title() {
|
|
1947
|
+
return x_axis_title;
|
|
1948
|
+
},
|
|
1949
|
+
get shown_start_x() {
|
|
1950
|
+
return shown_start_x;
|
|
1951
|
+
},
|
|
1952
|
+
get shown_end_x() {
|
|
1953
|
+
return shown_end_x;
|
|
1954
|
+
},
|
|
1955
|
+
get all_data_start_x() {
|
|
1956
|
+
return all_data_start_x_loc;
|
|
1957
|
+
},
|
|
1958
|
+
get all_data_end_x() {
|
|
1959
|
+
return all_data_end_x_loc;
|
|
1960
|
+
},
|
|
1961
|
+
get frames() {
|
|
1962
|
+
return frames;
|
|
1963
|
+
},
|
|
1964
|
+
get min_x_scrollable() {
|
|
1965
|
+
return min_x_scrollable;
|
|
1966
|
+
},
|
|
1967
|
+
get max_x_scrollable() {
|
|
1968
|
+
return max_x_scrollable;
|
|
1969
|
+
},
|
|
1970
|
+
get x_axis_tics() {
|
|
1971
|
+
return x_axis_tics;
|
|
1972
|
+
},
|
|
1973
|
+
get x_axis_highlight_tic() {
|
|
1974
|
+
return x_axis_highlight_tic;
|
|
1975
|
+
},
|
|
1976
|
+
get x_hovered_percent_decimal() {
|
|
1977
|
+
return x_hovered_percent_decimal;
|
|
1978
|
+
},
|
|
1979
|
+
set_shown_start_x,
|
|
1980
|
+
set_shown_end_x,
|
|
1981
|
+
set_x_hovered_percent_decimal
|
|
1982
|
+
};
|
|
1983
|
+
}
|
|
1984
|
+
function set_datasets(input) {
|
|
1985
|
+
datasets = input;
|
|
1986
|
+
}
|
|
1987
|
+
function init(config) {
|
|
1988
|
+
range_to_show_default = config?.range_to_show_default ?? 500;
|
|
1989
|
+
min_visible_bars = config?.min_visible_bars ?? 20;
|
|
1990
|
+
x_edge_padding_ratio = config?.x_edge_padding_ratio ?? .5;
|
|
1991
|
+
datasets = config?.datasets;
|
|
1992
|
+
chart_prepped = prep_chart({ ...config?.chart });
|
|
1993
|
+
}
|
|
1994
|
+
init(config);
|
|
1995
|
+
return {
|
|
1996
|
+
get datasets() {
|
|
1997
|
+
return datasets;
|
|
1998
|
+
},
|
|
1999
|
+
get chart_prepped() {
|
|
2000
|
+
return chart_prepped;
|
|
2001
|
+
},
|
|
2002
|
+
get y_axis_width() {
|
|
2003
|
+
return y_axis_width;
|
|
2004
|
+
},
|
|
2005
|
+
get x_axis_height() {
|
|
2006
|
+
return x_axis_height;
|
|
2007
|
+
},
|
|
2008
|
+
get grid_width() {
|
|
2009
|
+
return grid_width;
|
|
2010
|
+
},
|
|
2011
|
+
get frame_width() {
|
|
2012
|
+
return frame_width();
|
|
2013
|
+
},
|
|
2014
|
+
period_to_sec,
|
|
2015
|
+
handle_scroll_frame,
|
|
2016
|
+
handle_pointer_down,
|
|
2017
|
+
handle_pointer_move,
|
|
2018
|
+
handle_pointer_up,
|
|
2019
|
+
handle_pointer_cancel,
|
|
2020
|
+
handle_y_axis_pointer_down,
|
|
2021
|
+
handle_y_axis_pointer_move,
|
|
2022
|
+
handle_y_axis_pointer_up,
|
|
2023
|
+
handle_y_axis_pointer_cancel,
|
|
2024
|
+
handle_y_axis_click,
|
|
2025
|
+
handle_scroll_y_axis,
|
|
2026
|
+
handle_chart_hover,
|
|
2027
|
+
handle_chart_hover_leave,
|
|
2028
|
+
set_grid_width,
|
|
2029
|
+
gen_color,
|
|
2030
|
+
set_datasets,
|
|
2031
|
+
refresh_chart
|
|
2032
|
+
};
|
|
2033
|
+
}
|
|
2034
|
+
//#endregion
|
|
2035
|
+
export { Chart as n, create_chart_manager as t };
|