sveltekit-ui 1.1.16 → 1.1.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. package/package.json +1 -1
  2. package/dist/Components/ArrowToggle/index.svelte +0 -62
  3. package/dist/Components/Attachment/index.svelte +0 -77
  4. package/dist/Components/Attachment/index.svelte.js +0 -119
  5. package/dist/Components/AudioEditor/index.svelte +0 -252
  6. package/dist/Components/AudioEditor/index.svelte.js +0 -977
  7. package/dist/Components/AudioEditor/samples/alloy-voice-sample.mp3 +0 -0
  8. package/dist/Components/AudioEditor/samples/echo-voice-sample.mp3 +0 -0
  9. package/dist/Components/AudioEditor/samples/fable-voice-sample.mp3 +0 -0
  10. package/dist/Components/AudioEditor/samples/nova-voice-sample.mp3 +0 -0
  11. package/dist/Components/AudioEditor/samples/onyx-voice-sample.mp3 +0 -0
  12. package/dist/Components/AudioEditor/samples/shimmer-voice-sample.mp3 +0 -0
  13. package/dist/Components/Breadcrumbs/index.svelte +0 -27
  14. package/dist/Components/Breadcrumbs/index.svelte.js +0 -88
  15. package/dist/Components/Chart/Klines/index.svelte +0 -87
  16. package/dist/Components/Chart/index.svelte +0 -226
  17. package/dist/Components/Chart/index.svelte.js +0 -1090
  18. package/dist/Components/ChartInput/DisplayNav/Klines/index.svelte +0 -150
  19. package/dist/Components/ChartInput/DisplayNav/Lines/index.svelte +0 -45
  20. package/dist/Components/ChartInput/DisplayNav/index.svelte +0 -297
  21. package/dist/Components/ChartInput/EditPanel/index.svelte +0 -155
  22. package/dist/Components/ChartInput/index.svelte +0 -21
  23. package/dist/Components/ChartInput/index.svelte.js +0 -671
  24. package/dist/Components/Color/index.svelte +0 -51
  25. package/dist/Components/Color/index.svelte.js +0 -31
  26. package/dist/Components/ColorInput/ChromaPicker/index.svelte +0 -50
  27. package/dist/Components/ColorInput/ColorPalette/index.svelte +0 -62
  28. package/dist/Components/ColorInput/OpacityPicker/index.svelte +0 -68
  29. package/dist/Components/ColorInput/ShowcasePicker/index.svelte +0 -136
  30. package/dist/Components/ColorInput/index.svelte +0 -70
  31. package/dist/Components/ColorInput/index.svelte.js +0 -386
  32. package/dist/Components/ConditionsInput/index.svelte +0 -46
  33. package/dist/Components/ConditionsInput/index.svelte.js +0 -201
  34. package/dist/Components/Confetti/index.svelte +0 -98
  35. package/dist/Components/Confetti/index.svelte.js +0 -94
  36. package/dist/Components/Content/index.svelte +0 -500
  37. package/dist/Components/Content/index.svelte.js +0 -910
  38. package/dist/Components/ContentInput/AttributesInput/CustomConfig/Audio/index.svelte +0 -31
  39. package/dist/Components/ContentInput/AttributesInput/CustomConfig/Audio/index.svelte.js +0 -258
  40. package/dist/Components/ContentInput/AttributesInput/CustomConfig/AudioAdvanced/index.svelte +0 -31
  41. package/dist/Components/ContentInput/AttributesInput/CustomConfig/AudioAdvanced/index.svelte.js +0 -258
  42. package/dist/Components/ContentInput/AttributesInput/CustomConfig/Dropdown/index.svelte +0 -58
  43. package/dist/Components/ContentInput/AttributesInput/CustomConfig/Dropdown/index.svelte.js +0 -206
  44. package/dist/Components/ContentInput/AttributesInput/CustomConfig/Image/index.svelte +0 -28
  45. package/dist/Components/ContentInput/AttributesInput/CustomConfig/Image/index.svelte.js +0 -224
  46. package/dist/Components/ContentInput/AttributesInput/CustomConfig/Number/index.svelte +0 -44
  47. package/dist/Components/ContentInput/AttributesInput/CustomConfig/Number/index.svelte.js +0 -272
  48. package/dist/Components/ContentInput/AttributesInput/CustomConfig/Qr/index.svelte +0 -41
  49. package/dist/Components/ContentInput/AttributesInput/CustomConfig/Qr/index.svelte.js +0 -202
  50. package/dist/Components/ContentInput/AttributesInput/CustomConfig/Slider/index.svelte +0 -19
  51. package/dist/Components/ContentInput/AttributesInput/CustomConfig/Slider/index.svelte.js +0 -117
  52. package/dist/Components/ContentInput/AttributesInput/CustomConfig/TableAdvanced/index.svelte +0 -60
  53. package/dist/Components/ContentInput/AttributesInput/CustomConfig/TableAdvanced/index.svelte.js +0 -542
  54. package/dist/Components/ContentInput/AttributesInput/CustomConfig/Tag/index.svelte +0 -47
  55. package/dist/Components/ContentInput/AttributesInput/CustomConfig/Tag/index.svelte.js +0 -185
  56. package/dist/Components/ContentInput/AttributesInput/CustomConfig/TextInput/index.svelte +0 -35
  57. package/dist/Components/ContentInput/AttributesInput/CustomConfig/TextInput/index.svelte.js +0 -222
  58. package/dist/Components/ContentInput/AttributesInput/CustomConfig/TimeInput/index.svelte +0 -20
  59. package/dist/Components/ContentInput/AttributesInput/CustomConfig/TimeInput/index.svelte.js +0 -84
  60. package/dist/Components/ContentInput/AttributesInput/DefinedTypeInput/index.svelte +0 -25
  61. package/dist/Components/ContentInput/AttributesInput/DefinedTypeInput/index.svelte.js +0 -91
  62. package/dist/Components/ContentInput/AttributesInput/index.svelte +0 -352
  63. package/dist/Components/ContentInput/AttributesInput/index.svelte.js +0 -1436
  64. package/dist/Components/ContentInput/ContentPanelBuilder/AddElement/index.svelte +0 -64
  65. package/dist/Components/ContentInput/ContentPanelBuilder/AddElement/index.svelte.js +0 -97
  66. package/dist/Components/ContentInput/ContentPanelBuilder/ElementList/index.svelte +0 -184
  67. package/dist/Components/ContentInput/ContentPanelBuilder/index.svelte +0 -41
  68. package/dist/Components/ContentInput/index.svelte +0 -78
  69. package/dist/Components/ContentInput/index.svelte.js +0 -1197
  70. package/dist/Components/CronInput/index.svelte +0 -78
  71. package/dist/Components/CronInput/index.svelte.js +0 -198
  72. package/dist/Components/DataTypeInput/index.svelte +0 -174
  73. package/dist/Components/DataTypeInput/index.svelte.js +0 -565
  74. package/dist/Components/Dropdown/index.svelte +0 -116
  75. package/dist/Components/Dropdown/index.svelte.js +0 -403
  76. package/dist/Components/ErrorX/index.svelte +0 -58
  77. package/dist/Components/FileInput/index.svelte +0 -146
  78. package/dist/Components/FileInput/index.svelte.js +0 -225
  79. package/dist/Components/Hamburger/index.svelte +0 -99
  80. package/dist/Components/HorizScrollBox/index.svelte +0 -145
  81. package/dist/Components/IconInput/index.svelte +0 -77
  82. package/dist/Components/IconInput/index.svelte.js +0 -259
  83. package/dist/Components/Image/index.svelte +0 -126
  84. package/dist/Components/Image/index.svelte.js +0 -116
  85. package/dist/Components/ImageEditor/Image/CropBox/index.svelte +0 -165
  86. package/dist/Components/ImageEditor/Image/index.svelte +0 -104
  87. package/dist/Components/ImageEditor/Panels/AI/index.svelte +0 -44
  88. package/dist/Components/ImageEditor/Panels/Crop/index.svelte +0 -96
  89. package/dist/Components/ImageEditor/Panels/File/QualityPicker/index.svelte +0 -124
  90. package/dist/Components/ImageEditor/Panels/File/index.svelte +0 -74
  91. package/dist/Components/ImageEditor/Panels/Filters/index.svelte +0 -46
  92. package/dist/Components/ImageEditor/Panels/Resize/index.svelte +0 -58
  93. package/dist/Components/ImageEditor/index.svelte +0 -93
  94. package/dist/Components/ImageEditor/index.svelte.js +0 -1961
  95. package/dist/Components/ImageSlider/index.svelte +0 -124
  96. package/dist/Components/ImageSlider/index.svelte.js +0 -99
  97. package/dist/Components/Json/Nested/index.svelte +0 -157
  98. package/dist/Components/LabeledItem/index.svelte +0 -102
  99. package/dist/Components/Layout/NavBar/FullNav/index.svelte +0 -52
  100. package/dist/Components/Layout/NavBar/NavGuts/index.svelte +0 -87
  101. package/dist/Components/Layout/NavBar/index.svelte +0 -72
  102. package/dist/Components/Layout/index.svelte +0 -149
  103. package/dist/Components/Layout/index.svelte.js +0 -360
  104. package/dist/Components/LoadingWheel/index.svelte +0 -38
  105. package/dist/Components/LocationInput/index.svelte +0 -197
  106. package/dist/Components/LocationInput/index.svelte.js +0 -965
  107. package/dist/Components/Number/index.svelte +0 -47
  108. package/dist/Components/Number/index.svelte.js +0 -151
  109. package/dist/Components/PhoneCountryCode/index.svelte +0 -7
  110. package/dist/Components/PhoneCountryCode/index.svelte.js +0 -260
  111. package/dist/Components/Popover/index.svelte +0 -396
  112. package/dist/Components/Popover/index.svelte.js +0 -319
  113. package/dist/Components/Spacer/index.svelte +0 -41
  114. package/dist/Components/StoragePicker/DisplayFile/index.svelte +0 -15
  115. package/dist/Components/StoragePicker/index.svelte +0 -187
  116. package/dist/Components/StoragePicker/index.svelte.js +0 -592
  117. package/dist/Components/TableAdvanced/ColumnInput/index.svelte +0 -117
  118. package/dist/Components/TableAdvanced/ColumnInput/index.svelte.js +0 -456
  119. package/dist/Components/TableAdvanced/FilterInput/index.svelte +0 -54
  120. package/dist/Components/TableAdvanced/FilterInput/index.svelte.js +0 -247
  121. package/dist/Components/TableAdvanced/Pagination/index.svelte +0 -43
  122. package/dist/Components/TableAdvanced/Pagination/index.svelte.js +0 -97
  123. package/dist/Components/TableAdvanced/SortByInput/index.svelte +0 -72
  124. package/dist/Components/TableAdvanced/SortByInput/index.svelte.js +0 -176
  125. package/dist/Components/Tag/index.svelte +0 -45
  126. package/dist/Components/Tag/index.svelte.js +0 -76
  127. package/dist/Components/TextArrayInput/index.svelte +0 -108
  128. package/dist/Components/TextArrayInput/index.svelte.js +0 -239
  129. package/dist/Components/TextInput/PasswordTooltip/index.svelte +0 -89
  130. package/dist/Components/TimeInput/NumberToggler/index.svelte +0 -34
  131. package/dist/Components/TimeInput/NumberToggler/index.svelte.js +0 -79
  132. package/dist/Components/TimeInput/index.js +0 -702
  133. package/dist/Components/TimeInput/index.svelte +0 -211
  134. package/dist/Components/TimeInput/index.svelte.js +0 -638
  135. package/dist/Components/Tooltip/index.svelte +0 -143
  136. package/dist/Components/TransparentBackground/index.svelte +0 -153
  137. package/dist/Components/TypingDots/index.svelte +0 -84
  138. package/dist/Components/VariablePathInput/index.svelte +0 -63
  139. package/dist/Components/VariablePathInput/index.svelte.js +0 -273
  140. package/dist/Components/XFollow/index.svelte +0 -42
  141. package/dist/Components/YoutubeChannelButton/index.svelte +0 -82
  142. package/dist/Components/YoutubeVideo/index.svelte +0 -73
  143. package/dist/Components/YoutubeVideo/index.svelte.js +0 -54
  144. package/dist/actions/draggable.js +0 -49
  145. package/dist/actions/index.js +0 -24
  146. package/dist/actions/no_spaces.js +0 -33
  147. package/dist/actions/numbers_only.js +0 -26
  148. package/dist/actions/scroll_y.js +0 -28
  149. package/dist/actions/stop_scroll_propagation_y.js +0 -42
  150. package/dist/actions/swipe_handler.js +0 -295
  151. package/dist/client/astc_formatting/index.js +0 -1128
  152. package/dist/client/docs/index.js +0 -7622
  153. package/dist/client/index.js +0 -735
  154. package/dist/client/types/index.js +0 -2812
  155. package/dist/index.js +0 -180
  156. package/dist/style.css +0 -682
@@ -1,1090 +0,0 @@
1
- import { color_var } from "../../client/index.js"
2
-
3
- export function create_chart_manager(config) {
4
- const y_axis_width = 70
5
- const x_axis_height = 30
6
-
7
- let datasets = $state(null)
8
- let chart_prepped = $state(null)
9
- let grid_width = $state(null)
10
- let frame_width = $derived(grid_width ? grid_width - y_axis_width : 0)
11
-
12
- function set_grid_width(input) {
13
- grid_width = input
14
- if (!chart_prepped) {
15
- chart_prepped = prep_chart({ ...config?.chart, shown_start_x: null, shown_end_x: null })
16
- }
17
- }
18
-
19
- function gen_color(l, c, h, o = 16, is_theme_based = true, dark_l_offset = 0, isDarkTheme = true, is_safari = false) {
20
- const l_try = l + dark_l_offset
21
- const l_limited = l_try > 16 ? 16 : l_try < 1 ? 1 : l_try
22
- const l_corrected = isDarkTheme ? l_limited : l
23
- return color_var(l_corrected, c, h, o, is_theme_based, is_safari)
24
- }
25
-
26
- function normalize(x, min, max) {
27
- const numerator = x - min
28
- const denominator = max - min
29
- return numerator != 0 && denominator != 0 ? numerator / denominator : 0
30
- }
31
-
32
- function denormalize(x, min, max) {
33
- const range = max - min
34
- return x != 0 && range != 0 ? x * range + min : min
35
- }
36
-
37
- const period_to_sec = {
38
- "5m": 300, //5m
39
- "10m": 600, //10m
40
- "15m": 900, //15m
41
- "20m": 1200, //20m
42
- "30m": 1800, //30m
43
- "45m": 2700, //45m
44
- "1h": 3600, //1h
45
- "2h": 7200, //2h
46
- "3h": 10800, //3h
47
- "4h": 14400, //4h
48
- "6h": 21600, //6h
49
- "8h": 28800, //8h
50
- "12h": 43200, //12h
51
- "1d": 86400, //1d
52
- "2d": 172800, //2d
53
- "3d": 259200, //3d
54
- "4d": 345600, //4d
55
- "1w": 604800, //1w
56
- "2w": 1209600, //2w
57
- }
58
-
59
- function generate_id(prefix) {
60
- return prefix + "-" + Math.floor(Math.random() * 1000000000000)
61
- }
62
-
63
- function add_val_to_obj_with_path(obj, pathList) {
64
- let current = obj
65
- for (let key of pathList) {
66
- if (!(key in current)) {
67
- current[key] = {}
68
- }
69
- current = current[key]
70
- }
71
- return obj
72
- }
73
- function add_val_to_obj_with_path_2(obj, pathList, val) {
74
- let current = obj
75
- for (let [index, key] of pathList.entries()) {
76
- if (!(key in current)) {
77
- current[key] = {}
78
- }
79
- if (index === pathList.length - 1) {
80
- current[key] = val ? val : {}
81
- }
82
- current = current[key]
83
- }
84
- return obj
85
- }
86
-
87
- function does_path_exist_on_obj(obj, pathList) {
88
- let current = obj
89
- for (let [index, key] of pathList.entries()) {
90
- if (index < pathList.length && !(key in current)) {
91
- return false
92
- }
93
- current = current[key]
94
- }
95
- return true
96
- }
97
- function remove_val_to_obj_with_path(obj, pathList) {
98
- let current = obj
99
- for (let [index, key] of pathList.entries()) {
100
- if (index === pathList.length - 1) {
101
- delete current[key]
102
- }
103
- current = current[key]
104
- }
105
- return obj
106
- }
107
-
108
- function get_obj_from_path(obj, path) {
109
- let current = obj
110
- for (let i = 0; i < path.length; i++) {
111
- if (!(path[i] in current)) return false
112
- current = current[path[i]]
113
- }
114
- return current
115
- }
116
-
117
- function scroll_frame(e, shown_start_x, shown_end_x, min_x_scrollable, max_x_scrollable, frame_width) {
118
- const period_sec = 90 // needs work
119
- const shown_x_range = shown_end_x - shown_start_x
120
- const change_sec = (Math.round((shown_x_range * 0.01) / 60) + 1) * 60
121
- let shown_end_x_loc = shown_end_x
122
- let shown_start_x_loc = shown_start_x
123
- if (e.deltaX < -1 && shown_end_x > min_x_scrollable) {
124
- shown_start_x_loc -= change_sec
125
- shown_end_x_loc -= change_sec
126
- } else if (e.deltaX > 1 && shown_start_x < max_x_scrollable) {
127
- shown_start_x_loc += change_sec
128
- shown_end_x_loc += change_sec
129
- }
130
- let x_pd = e.offsetX / frame_width
131
- if (e.deltaY < -1 && shown_x_range > 90 * period_sec) {
132
- shown_start_x_loc += shown_start_x_loc < max_x_scrollable ? Math.round((change_sec * x_pd) / 10) * 10 : 0
133
- shown_end_x_loc -= shown_end_x_loc > min_x_scrollable ? Math.round((change_sec * (1 - x_pd)) / 10) * 10 : 0
134
- } else if (e.deltaY > 1 && shown_x_range < period_sec * 10000) {
135
- shown_start_x_loc -= shown_start_x_loc > min_x_scrollable ? Math.round((change_sec * x_pd) / 10) * 10 : 0
136
- shown_end_x_loc += shown_end_x_loc < max_x_scrollable ? Math.round((change_sec * (1 - x_pd)) / 10) * 10 : 0
137
- }
138
- return {
139
- shown_start_x: shown_start_x_loc,
140
- shown_end_x: shown_end_x_loc,
141
- }
142
- }
143
-
144
- function get_kline_details(o, l, h, c) {
145
- let res = {}
146
- const is_closed_higher = c > o ? 1 : 0
147
- const kline_height = h - l
148
- const kline_box_height = Math.abs(c - o)
149
- let kline_top_wick_height = h - o
150
- let kline_bottom_wick_height = c - l
151
- if (is_closed_higher) {
152
- kline_top_wick_height = h - c
153
- kline_bottom_wick_height = o - l
154
- }
155
- const kline_box_height_pd = kline_box_height / kline_height
156
- const kline_top_wick_height_pd = kline_top_wick_height / kline_height
157
- const kline_bottom_wick_height_pd = kline_bottom_wick_height / kline_height
158
- const kline_close_height_pd = (c - l) / kline_height
159
- res["is_closed_higher"] = is_closed_higher
160
- res["kline_height"] = kline_height
161
- res["kline_box_height"] = kline_box_height
162
- res["kline_top_wick_height"] = kline_top_wick_height
163
- res["kline_bottom_wick_height"] = kline_bottom_wick_height
164
- res["kline_box_height_pd"] = kline_box_height_pd
165
- res["kline_top_wick_height_pd"] = kline_top_wick_height_pd
166
- res["kline_bottom_wick_height_pd"] = kline_bottom_wick_height_pd
167
- res["kline_close_height_pd"] = kline_close_height_pd
168
- return res
169
- }
170
-
171
- function time_tic_size(seconds) {
172
- const tic_options = [
173
- 300, //5m
174
- 600, //10m
175
- 900, //15m
176
- 1200, //20m
177
- 1800, //30m
178
- 2700, //45m
179
- 3600, //1h
180
- 7200, //2h
181
- 10800, //3h
182
- 14400, //4h
183
- 21600, //6h
184
- 28800, //8h
185
- 43200, //12h
186
- 86400, //1d
187
- 172800, //2d
188
- 259200, //3d
189
- 345600, //4d
190
- 604800, //1w
191
- 1209600, //2w
192
- 2635200, //1m (30.5d)
193
- 7905600, //3m (91.5d)
194
- 15768000, //6m
195
- 31536000, //1y
196
- ]
197
- for (let i = 0; i < tic_options.length - 1; i++) {
198
- if (tic_options[i] < seconds && tic_options[i + 1] > seconds) {
199
- return tic_options[i + 1]
200
- }
201
- }
202
- return "-"
203
- }
204
-
205
- function base_time(high, cleanTicTimeChange) {
206
- const dHigh = new Date(high * 1000)
207
- const year = dHigh.getFullYear()
208
- const month = dHigh.getMonth()
209
- const day = dHigh.getDate()
210
- const hour = dHigh.getHours()
211
- const minute = dHigh.getMinutes()
212
- const ticBases = {
213
- 31536000: { focus: "y", values: [] }, //1y
214
- 15768000: { focus: "M", values: [11, 5, 0] }, //6m
215
- 7905600: { focus: "M", values: [11, 8, 5, 2, 0] }, //3m (91.5d)
216
- 2635200: { focus: "M", values: [11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0] }, //1m (30.5d)
217
- 1209600: { focus: "d", values: [28, 14, 0] }, //2w
218
- 604800: { focus: "d", values: [28, 21, 14, 7, 0] }, //1w
219
- 345600: { focus: "d", values: [28, 24, 20, 16, 12, 8, 4, 0] }, //4d
220
- 259200: { focus: "d", values: [30, 27, 24, 21, 18, 15, 12, 9, 6, 3, 0] }, //3d
221
- 172800: { focus: "d", values: [30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0] }, //2d
222
- 86400: {
223
- focus: "d",
224
- values: [
225
- 31, 30, 19, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3,
226
- 2, 1, 0,
227
- ],
228
- }, //1d
229
- 43200: { focus: "h", values: [12, 0] }, //12h
230
- 28800: { focus: "h", values: [16, 8, 0] }, //8h
231
- 21600: { focus: "h", values: [18, 12, 6, 0] }, //6h
232
- 14400: { focus: "h", values: [20, 16, 12, 8, 4, 0] }, //4h
233
- 10800: { focus: "h", values: [21, 18, 15, 12, 9, 6, 3, 0] }, //3h
234
- 7200: { focus: "h", values: [22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0] }, //2h
235
- 3600: {
236
- focus: "h",
237
- values: [23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0],
238
- }, //1h
239
- 2700: { focus: "m", values: [45, 0] }, //45m
240
- 1800: { focus: "m", values: [30, 0] }, //30m
241
- 1200: { focus: "m", values: [40, 20, 0] }, //20m
242
- 900: { focus: "m", values: [45, 30, 15, 0] }, //15m
243
- 600: { focus: "m", values: [50, 40, 30, 20, 10, 0] }, //10m
244
- 300: { focus: "m", values: [55, 50, 45, 40, 35, 30, 25, 20, 25, 20, 5, 0] }, //5m
245
- }
246
- var d = new Date()
247
- d.setFullYear(year)
248
- d.setMonth(0)
249
- d.setDate(1)
250
- d.setHours(0)
251
- d.setMinutes(0)
252
- d.setMilliseconds(0)
253
- switch (ticBases[cleanTicTimeChange]?.focus) {
254
- case "y": {
255
- break
256
- }
257
- case "M": {
258
- d.setFullYear(year)
259
- for (let item of ticBases[cleanTicTimeChange].values) {
260
- if (item < month) {
261
- d.setMonth(item)
262
- break
263
- }
264
- }
265
- break
266
- }
267
- case "d": {
268
- d.setFullYear(year)
269
- d.setMonth(month)
270
- for (let item of ticBases[cleanTicTimeChange].values) {
271
- if (item < day) {
272
- d.setDate(item)
273
- break
274
- }
275
- }
276
- break
277
- }
278
- case "h": {
279
- d.setFullYear(year)
280
- d.setMonth(month)
281
- d.setDate(day)
282
- for (let item of ticBases[cleanTicTimeChange].values) {
283
- if (item < hour) {
284
- d.setHours(item)
285
- break
286
- }
287
- }
288
- break
289
- }
290
- case "m": {
291
- d.setFullYear(year)
292
- d.setMonth(month)
293
- d.setDate(day)
294
- d.setHours(hour)
295
- for (let item of ticBases[cleanTicTimeChange].values) {
296
- if (item < minute) {
297
- d.setMinutes(item)
298
- break
299
- }
300
- }
301
- break
302
- }
303
- default: {
304
- d.setMonth(month)
305
- d.setDate(day)
306
- d.setHours(hour)
307
- const remainer5min = minute % 300000
308
- const floor5min = minute - remainer5min
309
- d.setMinutes(floor5min)
310
- break
311
- }
312
- }
313
- return Math.floor(d.getTime() / 1000)
314
- }
315
-
316
- function readable_time(seconds) {
317
- const months = ["JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"]
318
- const dateObject = new Date(seconds * 1000)
319
- const year = dateObject.getFullYear()
320
- const month = dateObject.getMonth()
321
- const day = dateObject.getDate()
322
- const hour = dateObject.getHours()
323
- const minute = dateObject.getMinutes()
324
- const year_st = JSON.stringify(year)
325
- const month_st = months[month]
326
- let day_st = JSON.stringify(day)
327
- // if(day_st.length < 2){ day_st = '0' + day_st }
328
- let hour_st = JSON.stringify(hour)
329
- // if(hour_st.length < 2){ hour_st = '0' + hour_st }
330
- let minute_st = JSON.stringify(minute)
331
- if (minute_st.length < 2) {
332
- minute_st = "0" + minute_st
333
- }
334
- const hour_minute_st = hour_st + ":" + minute_st
335
- if (minute > 0 || hour > 0) {
336
- return hour_minute_st
337
- } else if (day > 1) {
338
- return day_st
339
- } else if (month > 0) {
340
- return month_st
341
- }
342
- return year_st
343
- }
344
-
345
- function prep_x_axis(
346
- start_x,
347
- end_x,
348
- frame_width = 500,
349
- min_tic_spacing_x_axis = 20,
350
- min_tic_text_spacing_x_axis = 50
351
- ) {
352
- const amount_of_tics = Math.floor(frame_width / min_tic_spacing_x_axis)
353
- const x_range = end_x - start_x
354
- const tic_x_change = x_range / amount_of_tics
355
- const clean_x_change = time_tic_size(tic_x_change)
356
- const clean_x = base_time(end_x, clean_x_change)
357
- const clean_x_text = readable_time(clean_x)
358
- const clean_x_norm = (clean_x - start_x) / x_range
359
- // const is_remaining_room_for_text = (1 - clean_x_norm) * frame_width >= (min_tic_text_spacing_x_axis / 2)
360
- let tics = [
361
- {
362
- x: clean_x,
363
- norm: clean_x_norm,
364
- text: clean_x_text,
365
- },
366
- ]
367
- let last_tic_with_text_x_norm = clean_x_norm
368
- for (let i = 1; i < amount_of_tics; i++) {
369
- const iter_x = clean_x + clean_x_change * i
370
- const iter_x_norm = (iter_x - start_x) / x_range
371
- // const is_remaining_room = ((end_x - iter_x) / x_range) * frame_width >= (min_tic_text_spacing_x_axis / 2)
372
- const is_far_enough_from_prev_text =
373
- !last_tic_with_text_x_norm ||
374
- (iter_x_norm - last_tic_with_text_x_norm) * frame_width >= min_tic_text_spacing_x_axis
375
- if (iter_x <= end_x) {
376
- if (is_far_enough_from_prev_text) {
377
- tics = [
378
- ...tics,
379
- {
380
- x: iter_x,
381
- norm: iter_x_norm,
382
- text: readable_time(iter_x),
383
- },
384
- ]
385
- last_tic_with_text_x_norm = iter_x_norm
386
- } else {
387
- tics = [
388
- ...tics,
389
- {
390
- x: iter_x,
391
- norm: iter_x_norm,
392
- text: null,
393
- },
394
- ]
395
- }
396
- } else {
397
- break
398
- }
399
- }
400
- last_tic_with_text_x_norm = clean_x_norm
401
- for (let i = 1; i < amount_of_tics; i++) {
402
- const iter_x = clean_x - clean_x_change * i
403
- const iter_x_norm = (iter_x - start_x) / x_range
404
- // const is_remaining_room = iter_x_norm * frame_width >= (min_tic_text_spacing_x_axis / 2)
405
- const is_far_enough_from_prev_text =
406
- !last_tic_with_text_x_norm ||
407
- (last_tic_with_text_x_norm - iter_x_norm) * frame_width >= min_tic_text_spacing_x_axis
408
- if (iter_x >= start_x) {
409
- if (is_far_enough_from_prev_text) {
410
- tics = [
411
- {
412
- x: iter_x,
413
- norm: iter_x_norm,
414
- text: readable_time(iter_x),
415
- },
416
- ...tics,
417
- ]
418
- last_tic_with_text_x_norm = iter_x_norm
419
- } else {
420
- tics = [
421
- {
422
- x: iter_x,
423
- norm: iter_x_norm,
424
- text: null,
425
- },
426
- ...tics,
427
- ]
428
- }
429
- } else {
430
- break
431
- }
432
- }
433
- return tics
434
- }
435
-
436
- function notable_num(low, high) {
437
- let absClosestToZero = low
438
- let absFartherToZero = high
439
- let isPositive = true
440
- if (high < 0) {
441
- absClosestToZero = Math.abs(high)
442
- absFartherToZero = Math.abs(low)
443
- isPositive = false
444
- }
445
- let accumulatedNum = 0
446
- while (accumulatedNum < absFartherToZero) {
447
- const ceiling = absFartherToZero - accumulatedNum
448
- const res = next_big_num_under_target(ceiling)
449
- accumulatedNum += res
450
- if (accumulatedNum > absClosestToZero) {
451
- if (isPositive) {
452
- return accumulatedNum
453
- } else {
454
- return -1 * accumulatedNum
455
- }
456
- }
457
- }
458
- return "-"
459
- }
460
-
461
- function next_big_num_under_target(target) {
462
- const num_bases = [
463
- 100000000000000, 10000000000000, 1000000000000, 100000000000, 10000000000, 1000000000, 100000000, 50000000,
464
- 20000000, 10000000, 5000000, 2000000, 1000000, 750000, 500000, 400000, 250000, 200000, 150000, 100000, 75000,
465
- 50000, 40000, 25000, 20000, 15000, 10000, 7500, 5000, 4000, 3000, 2500, 2000, 1500, 1250, 1000, 750, 500, 400,
466
- 300, 200, 150, 100, 75, 50, 40, 25, 20, 15, 12, 10, 8, 5, 4, 3, 2.5, 2, 1, 0.8, 0.5, 0.4, 0.3, 0.2, 0.1, 0.08,
467
- 0.05, 0.04, 0.03, 0.02, 0.01, 0.008, 0.005, 0.004, 0.003, 0.002, 0.001, 0.0008, 0.0005, 0.0004, 0.0003, 0.0002,
468
- 0.0001, 0.00008, 0.00005, 0.00004, 0.00003, 0.00002, 0.00001, 0.000008, 0.000005, 0.000004, 0.000003, 0.000002,
469
- 0.000001, 0.0000008, 0.0000005, 0.0000004, 0.0000003, 0.0000002, 0.0000001,
470
- ]
471
- for (let num of num_bases) {
472
- if (num < target) {
473
- return num
474
- }
475
- }
476
- return 1
477
- }
478
-
479
- function tic_size(num) {
480
- const tic_options = [
481
- 0.0000001, 0.0000002, 0.0000003, 0.0000004, 0.0000005, 0.0000008, 0.000001, 0.000002, 0.000003, 0.000004,
482
- 0.000005, 0.000008, 0.00001, 0.00002, 0.00003, 0.00004, 0.00005, 0.00008, 0.0001, 0.0002, 0.0003, 0.0004, 0.0005,
483
- 0.0008, 0.001, 0.002, 0.003, 0.004, 0.005, 0.008, 0.01, 0.02, 0.03, 0.04, 0.05, 0.08, 0.1, 0.2, 0.3, 0.4, 0.5,
484
- 0.8, 1, 2, 2.5, 3, 4, 5, 8, 10, 12, 15, 20, 25, 40, 50, 75, 100, 150, 200, 300, 400, 500, 750, 1000, 1250, 1500,
485
- 2000, 2500, 3000, 4000, 5000, 7500, 10000, 15000, 20000, 25000, 40000, 50000, 75000, 100000, 150000, 200000,
486
- 250000, 400000, 500000, 750000, 1000000, 2000000, 5000000, 10000000, 20000000, 50000000, 100000000, 1000000000,
487
- 10000000000, 100000000000, 1000000000000, 10000000000000, 100000000000000,
488
- ]
489
- for (let i = 0; i < tic_options.length - 1; i++) {
490
- if (tic_options[i] < num && tic_options[i + 1] > num) {
491
- return tic_options[i + 1]
492
- }
493
- }
494
- return "-"
495
- }
496
-
497
- function prep_y_axis(
498
- shown_low_y,
499
- shown_high_y,
500
- frame_height = 300,
501
- min_tic_spacing_y_axis = 10,
502
- min_tic_text_spacing_y_axis = 30
503
- ) {
504
- const amount_of_tics = Math.floor(frame_height / min_tic_spacing_y_axis)
505
- const y_range = shown_high_y - shown_low_y
506
- const tic_y_change = y_range / amount_of_tics
507
- const clean_y_change = tic_size(tic_y_change)
508
- const clean_y = notable_num(shown_low_y, shown_high_y)
509
- const clean_y_norm = (clean_y - shown_low_y) / y_range
510
- const clean_y_text = short_lab(clean_y)
511
- const is_remaining_room_for_text = (1 - clean_y_norm) * frame_height >= min_tic_text_spacing_y_axis / 2
512
- let tics = [
513
- {
514
- y: clean_y,
515
- norm: clean_y_norm,
516
- text: is_remaining_room_for_text ? clean_y_text : null,
517
- ppp: (1 - clean_y_norm) * frame_height,
518
- },
519
- ]
520
- let last_tic_with_text_y_norm = is_remaining_room_for_text ? clean_y_norm : null
521
- for (let i = 1; i < amount_of_tics; i++) {
522
- const iter_y = clean_y + clean_y_change * i
523
- const iter_y_norm = (iter_y - shown_low_y) / y_range
524
- const is_remaining_room = ((shown_high_y - iter_y) / y_range) * frame_height >= min_tic_text_spacing_y_axis / 2
525
- const is_far_enough_from_prev_text =
526
- !last_tic_with_text_y_norm ||
527
- (iter_y_norm - last_tic_with_text_y_norm) * frame_height >= min_tic_text_spacing_y_axis
528
- if (iter_y <= shown_high_y) {
529
- if (is_far_enough_from_prev_text && is_remaining_room) {
530
- tics = [
531
- ...tics,
532
- {
533
- y: iter_y,
534
- norm: iter_y_norm,
535
- text: short_lab(iter_y),
536
- },
537
- ]
538
- last_tic_with_text_y_norm = iter_y_norm
539
- } else {
540
- tics = [
541
- ...tics,
542
- {
543
- y: iter_y,
544
- norm: iter_y_norm,
545
- text: null,
546
- },
547
- ]
548
- }
549
- } else {
550
- break
551
- }
552
- }
553
- last_tic_with_text_y_norm = clean_y_norm
554
- for (let i = 1; i < amount_of_tics; i++) {
555
- const iter_y = clean_y - clean_y_change * i
556
- const iter_y_norm = (iter_y - shown_low_y) / y_range
557
- const is_remaining_room = iter_y_norm * frame_height >= min_tic_text_spacing_y_axis / 2
558
- const is_far_enough_from_prev_text =
559
- !last_tic_with_text_y_norm ||
560
- (last_tic_with_text_y_norm - iter_y_norm) * frame_height >= min_tic_text_spacing_y_axis
561
- if (iter_y >= shown_low_y) {
562
- if (is_far_enough_from_prev_text && is_remaining_room) {
563
- tics = [
564
- {
565
- y: iter_y,
566
- norm: iter_y_norm,
567
- text: short_lab(iter_y),
568
- },
569
- ...tics,
570
- ]
571
- last_tic_with_text_y_norm = iter_y_norm
572
- } else {
573
- tics = [
574
- {
575
- x: iter_y,
576
- norm: iter_y_norm,
577
- text: null,
578
- },
579
- ...tics,
580
- ]
581
- }
582
- } else {
583
- break
584
- }
585
- }
586
- return tics
587
- }
588
-
589
- function short_lab(num) {
590
- var if_neg = 1
591
- if ((typeof num === typeof null) | (typeof num === typeof undefined)) {
592
- return "-"
593
- }
594
- if (num < 0) {
595
- if_neg = -1
596
- }
597
- var amount
598
- amount = Math.abs(num)
599
- if (amount === 0) {
600
- return 0
601
- } else if (amount >= 0 && amount < 0.0001) {
602
- return Math.round((if_neg * amount).toFixed(8) * 10000000 + Number.EPSILON) / 10000000
603
- } else if (amount >= 0.0001 && amount < 0.001) {
604
- return Math.round((if_neg * amount).toFixed(7) * 1000000 + Number.EPSILON) / 1000000
605
- } else if (amount >= 0.001 && amount < 0.01) {
606
- return Math.round((if_neg * amount).toFixed(6) * 100000 + Number.EPSILON) / 100000
607
- } else if (amount >= 0.01 && amount < 0.1) {
608
- return Math.round((if_neg * amount).toFixed(5) * 10000 + Number.EPSILON) / 10000
609
- } else if (amount >= 0.1 && amount < 10) {
610
- return Math.round((if_neg * amount).toFixed(4) * 1000 + Number.EPSILON) / 1000
611
- } else if (amount >= 10 && amount < 1000) {
612
- return (if_neg * amount).toFixed(2)
613
- } else if (amount >= 1000 && amount < 1000000) {
614
- return (if_neg * amount).toFixed().replace(/\B(?=(\d{3})+(?!\d))/g, ",")
615
- } else if (amount >= 1000000 && amount < 10000000) {
616
- return (if_neg * (amount / 1000000)).toFixed(2) + " M"
617
- } else if (amount >= 10000000 && amount < 100000000) {
618
- return (if_neg * (amount / 1000000)).toFixed(1) + " M"
619
- } else if (amount >= 100000000 && amount < 1000000000) {
620
- return (if_neg * (amount / 1000000)).toFixed() + " M"
621
- } else if (amount >= 1000000000 && amount < 10000000000) {
622
- return (if_neg * (amount / 1000000000)).toFixed(2) + " B"
623
- } else if (amount >= 10000000000 && amount < 100000000000) {
624
- return (if_neg * (amount / 1000000000)).toFixed(1) + " B"
625
- } else if (amount >= 100000000000 && amount < 1000000000000) {
626
- return (if_neg * (amount / 1000000000)).toFixed() + " B"
627
- } else if (amount >= 1000000000000 && amount < 10000000000000) {
628
- return (if_neg * (amount / 1000000000000)).toFixed(2) + " T"
629
- } else if (amount >= 10000000000000 && amount < 100000000000000) {
630
- return (if_neg * (amount / 1000000000000)).toFixed(1) + " T"
631
- } else if (amount >= 100000000000000 && amount < 1000000000000000) {
632
- return (if_neg * (amount / 1000000000000)).toFixed() + " T"
633
- } else if (amount >= 1000000000000000 && amount < 10000000000000000n) {
634
- return (if_neg * (amount / 1000000000000000)).toFixed(2) + " Q"
635
- } else if (amount >= 10000000000000000n && amount < 100000000000000000n) {
636
- return (if_neg * (amount / 1000000000000000)).toFixed(1) + " Q"
637
- } else if (amount >= 100000000000000000n && amount < 1000000000000000000n) {
638
- return (if_neg * (amount / 1000000000000000)).toFixed() + " Q"
639
- } else if (amount >= 1000000000000000000n && amount < 10000000000000000000n) {
640
- return (if_neg * (amount / 1000000000000000000n)).toFixed(2) + " QN"
641
- } else if (amount >= 10000000000000000000n && amount < 100000000000000000000n) {
642
- return (if_neg * (amount / 1000000000000000000n)).toFixed(1) + " QN"
643
- } else if (amount >= 100000000000000000000n && amount < 1000000000000000000000n) {
644
- return (if_neg * (amount / 1000000000000000000n)).toFixed() + " QN"
645
- } else {
646
- return "Big"
647
- }
648
- }
649
-
650
- function handle_scroll_frame(e) {
651
- e.preventDefault()
652
- const res = scroll_frame(
653
- e,
654
- chart_prepped.shown_start_x,
655
- chart_prepped.shown_end_x,
656
- chart_prepped?.min_x_scrollable,
657
- chart_prepped?.max_x_scrollable,
658
- frame_width
659
- )
660
- chart_prepped.set_shown_start_x(res.shown_start_x)
661
- chart_prepped.set_shown_end_x(res.shown_end_x)
662
- chart_prepped = prep_chart(chart_prepped)
663
- }
664
-
665
- function handle_chart_hover(e, frame_index) {
666
- setTimeout(() => {
667
- const hover_x_pd = e.offsetX / frame_width
668
- chart_prepped.set_x_hovered_percent_decimal(hover_x_pd.toPrecision(3))
669
- // const hover_x = Math.floor(hover_x_pd * (chart_prepped.shown_end_x - chart_prepped.shown_start_x) + chart_prepped.shown_start_x)
670
- // chart_prepped.x_axis_highlight_tic = null
671
- const hover_y_pd = (
672
- (chart_prepped.frames[frame_index].frame_height - e.offsetY) /
673
- chart_prepped.frames[frame_index].frame_height
674
- ).toPrecision(3)
675
- chart_prepped.frames[frame_index].y_hovered_percent_decimal = hover_y_pd
676
- // for(let i = 0; i < chart_prepped.frames[frame_index].shared_y_axiss.length; i++){
677
- // chart_prepped.frames[frame_index].shared_y_axiss[i].y_axis_highlight_tic = hover_y_pd * (chart_prepped.frames[frame_index].shared_y_axiss[i].shown_high_y - chart_prepped.frames[frame_index].shared_y_axiss[i].shown_low_y) + chart_prepped.frames[frame_index].shared_y_axiss[i].shown_low_y
678
- // }
679
- }, 100)
680
- }
681
-
682
- function handle_chart_hover_leave(frame_index) {
683
- setTimeout(() => {
684
- chart_prepped.x_hovered_percent_decimal = null
685
- // chart_prepped.x_axis_highlight_tic = null
686
- chart_prepped.frames[frame_index].y_hovered_percent_decimal = null
687
- // for(let i = 0; i < chart_prepped.frames[frame_index].shared_y_axiss.length; i++){
688
- // chart_prepped.frames[frame_index].shared_y_axiss[i].y_axis_highlight_tic = null
689
- // }
690
- }, 100)
691
- }
692
-
693
- function prep_chart(input) {
694
- if (!input || !datasets || !grid_width) {
695
- chart_prepped = null
696
- return
697
- }
698
- let id = $state(input?.id)
699
- let x_axis_type = $state(input?.x_axis_type)
700
- let x_axis_title = $state(input?.x_axis_title)
701
- let shown_start_x = $state(input?.shown_start_x)
702
- let shown_end_x = $state(input?.shown_end_x)
703
- let frames = $state(input?.frames)
704
- let min_x_scrollable = $state(input?.min_x_scrollable)
705
- let max_x_scrollable = $state(input?.max_x_scrollable)
706
- let x_axis_highlight_tic = $state(input?.x_axis_highlight_tic)
707
- let x_hovered_percent_decimal = $state(input?.x_hovered_percent_decimal)
708
- let all_data_start_x_loc = $state(null)
709
- let all_data_end_x_loc = $state(null)
710
- let most_datapoints_for_x_dataset = 0
711
- if (Array.isArray(frames)) {
712
- for (let frame of frames) {
713
- if (Array.isArray(frame?.shared_y_axiss)) {
714
- for (let shared_y_axis of frame.shared_y_axiss) {
715
- if (Array.isArray(shared_y_axis?.datasets)) {
716
- for (let dataset of shared_y_axis.datasets) {
717
- let most_datapoints_for_x_dataset_loc = 0
718
- if (
719
- ["klines", "path", "points"].some((h) => h == dataset.type) &&
720
- Array.isArray(datasets[dataset?.dataset_id]?.data) &&
721
- datasets[dataset?.dataset_id]?.data.length > 0
722
- ) {
723
- for (let datapoint of datasets[dataset.dataset_id].data) {
724
- most_datapoints_for_x_dataset_loc++
725
- if (
726
- all_data_start_x_loc == undefined ||
727
- all_data_start_x_loc == null ||
728
- isNaN(all_data_start_x_loc) ||
729
- datapoint?.[dataset?.keys?.[0]] < all_data_start_x_loc
730
- ) {
731
- all_data_start_x_loc = datapoint?.[dataset?.keys?.[0]]
732
- }
733
- if (
734
- all_data_end_x_loc == undefined ||
735
- all_data_end_x_loc == null ||
736
- isNaN(all_data_end_x_loc) ||
737
- datapoint?.[dataset?.keys?.[0]] > all_data_end_x_loc
738
- ) {
739
- all_data_end_x_loc = datapoint?.[dataset?.keys?.[0]]
740
- }
741
- }
742
- }
743
- if (most_datapoints_for_x_dataset_loc > most_datapoints_for_x_dataset) {
744
- most_datapoints_for_x_dataset = most_datapoints_for_x_dataset_loc
745
- }
746
- }
747
- }
748
- }
749
- }
750
- }
751
- }
752
- const x_range = all_data_end_x_loc - all_data_start_x_loc
753
- let range_to_show = x_range
754
- let shown_start_x_loc = all_data_start_x_loc
755
- if (most_datapoints_for_x_dataset > 20) {
756
- range_to_show = (x_range * 20) / most_datapoints_for_x_dataset
757
- shown_start_x_loc = all_data_end_x_loc - parseFloat(range_to_show.toPrecision(8))
758
- }
759
- min_x_scrollable = all_data_start_x_loc + Math.floor(range_to_show * 0.1)
760
- max_x_scrollable = all_data_end_x_loc - Math.floor(range_to_show * 0.1)
761
- if (shown_start_x == null || isNaN(shown_start_x)) {
762
- shown_start_x = shown_start_x_loc
763
- } else if (shown_start_x >= max_x_scrollable) {
764
- shown_start_x = min_x_scrollable
765
- }
766
- if (shown_end_x == null || isNaN(shown_end_x)) {
767
- shown_end_x = all_data_end_x_loc
768
- } else if (shown_end_x <= min_x_scrollable) {
769
- shown_end_x = max_x_scrollable
770
- }
771
- let prepped_frames = []
772
- for (let frame of frames) {
773
- const frame_height = frame_width / frame.aspect_ratio
774
- let shown_y_axis_index = $state(0)
775
- let prepped_shared_y_axiss = []
776
- for (let shared_y_axis of frame.shared_y_axiss) {
777
- let y_points = []
778
- let shown_datasets_in_shared_y_low_y
779
- let shown_datasets_in_shared_y_high_y
780
- let pre_prepped_datasets = []
781
- for (let dataset of shared_y_axis.datasets) {
782
- let shown_data = []
783
- let d_loc = null
784
- if (dataset.type === "klines" && dataset?.keys?.length == 5 && datasets[dataset?.dataset_id]?.data) {
785
- for (let kline of datasets[dataset?.dataset_id]?.data) {
786
- if (
787
- !isNaN(kline[dataset?.keys[0]]) &&
788
- !isNaN(kline[dataset?.keys[1]]) &&
789
- !isNaN(kline[dataset?.keys[2]]) &&
790
- !isNaN(kline[dataset?.keys[3]]) &&
791
- !isNaN(kline[dataset?.keys[4]]) &&
792
- shown_start_x <= kline[dataset?.keys[0]] &&
793
- kline[dataset?.keys[0]] < shown_end_x
794
- ) {
795
- const item_to_add = {
796
- x: kline[dataset?.keys[0]],
797
- o: kline[dataset?.keys[1]],
798
- l: kline[dataset?.keys[2]],
799
- h: kline[dataset?.keys[3]],
800
- c: kline[dataset?.keys[4]],
801
- }
802
- shown_data.push(item_to_add)
803
- y_points.push((item_to_add.o + item_to_add.l + item_to_add.h + item_to_add.c) / 4)
804
- }
805
- }
806
- } else if (
807
- ["points", "path"].some((h) => h == dataset.type) &&
808
- dataset?.keys?.length == 2 &&
809
- datasets[dataset?.dataset_id]?.data
810
- ) {
811
- for (let datapoint of datasets[dataset?.dataset_id]?.data) {
812
- if (
813
- !isNaN(datapoint[dataset?.keys[0]]) &&
814
- !isNaN(datapoint[dataset?.keys[1]]) &&
815
- shown_start_x <= datapoint[dataset?.keys[0]] &&
816
- datapoint[dataset?.keys[0]] < shown_end_x
817
- ) {
818
- const item_to_add = {
819
- x: datapoint[dataset?.keys[0]],
820
- y: datapoint[dataset?.keys[1]],
821
- }
822
- shown_data.push(item_to_add)
823
- y_points.push(item_to_add.y)
824
- }
825
- }
826
- if (dataset?.type == "path") {
827
- if (Array.isArray(dataset?.data) && dataset?.data.length > 0) {
828
- d_loc = `M${(dataset?.data[0]?.x * 100).toPrecision(4)} ${(100 - dataset?.data[0]?.y * 100).toPrecision(
829
- 4
830
- )}`
831
- for (let i = 1; i < dataset?.data.length; i++) {
832
- d_loc =
833
- d_loc +
834
- ` L${(dataset?.data[i].x * 100).toPrecision(4)} ${(100 - dataset?.data[i].y * 100).toPrecision(4)}`
835
- }
836
- }
837
- }
838
- } else if (dataset.type == "lines" && dataset?.keys?.length > 1 && datasets[dataset?.dataset_id]?.data) {
839
- for (let datapoint of datasets[dataset?.dataset_id]?.data) {
840
- if (!isNaN(datapoint[dataset?.keys[0]]) && !isNaN(datapoint[dataset?.keys[1]])) {
841
- const item_to_add = {
842
- m: datapoint[dataset?.keys[0]],
843
- b: datapoint[dataset?.keys[1]],
844
- s: dataset?.keys?.length > 2 ? datapoint[dataset?.keys[2]] : null,
845
- }
846
- shown_data.push(item_to_add)
847
- if (!isNaN(datasets[dataset?.dataset_id]?.y_min) && !isNaN(datasets[dataset?.dataset_id]?.y_max)) {
848
- y_points.push((datasets[dataset?.dataset_id]?.y_min + datasets[dataset?.dataset_id]?.y_max) / 2)
849
- }
850
- }
851
- }
852
- }
853
- let color_one =
854
- dataset?.colors.length > 0
855
- ? gen_color(
856
- dataset?.colors[0].l,
857
- dataset?.colors[0].c,
858
- dataset?.colors[0].h,
859
- dataset?.colors[0].o,
860
- dataset?.colors[0].is_theme_based
861
- )
862
- : "#44ff4450"
863
- let color_two =
864
- dataset?.colors.length > 1
865
- ? gen_color(
866
- dataset?.colors[1].l,
867
- dataset?.colors[1].c,
868
- dataset?.colors[1].h,
869
- dataset?.colors[1].o,
870
- dataset?.colors[1].is_theme_based
871
- )
872
- : color_one
873
- ? color_one
874
- : "#ff444450"
875
- pre_prepped_datasets.push({
876
- type: dataset.type,
877
- data: shown_data,
878
- dataset_id: dataset.dataset_id,
879
- name: dataset.name,
880
- period_x: dataset.period_x,
881
- colors: dataset.colors,
882
- color_one: color_one,
883
- color_two: color_two,
884
- d: d_loc,
885
- keys: dataset.keys,
886
- })
887
- }
888
- y_points.sort((a, b) => a - b)
889
- const midpoint = Math.floor(y_points.length / 2)
890
- const lowhalf = y_points.slice(0, midpoint)
891
- const highhalf = y_points.slice(midpoint)
892
- const lowhalfmean = lowhalf.reduce((partial_sum, a) => partial_sum + a, 0) / lowhalf.length
893
- const highhalfmean = highhalf.reduce((partial_sum, a) => partial_sum + a, 0) / highhalf.length
894
- shown_datasets_in_shared_y_low_y = parseFloat((lowhalfmean * 0.9).toPrecision(6))
895
- shown_datasets_in_shared_y_high_y = parseFloat((highhalfmean * 1.1).toPrecision(6))
896
- const shown_y_range =
897
- (shown_datasets_in_shared_y_high_y - shown_datasets_in_shared_y_low_y) /
898
- (1 - shared_y_axis.top_padding_pd - shared_y_axis.bottom_padding_pd)
899
- let shown_low_y = shown_datasets_in_shared_y_low_y - shared_y_axis.bottom_padding_pd * shown_y_range
900
- let shown_high_y = shown_datasets_in_shared_y_high_y + shared_y_axis.top_padding_pd * shown_y_range
901
- const shown_x_range = shown_end_x - shown_start_x
902
- let prepped_datasets = []
903
- for (let pre_prepped_dataset of pre_prepped_datasets) {
904
- const kline_width_pd = (pre_prepped_dataset.period_x * 1) / shown_x_range
905
- let normalized_datapoints_in_range_loc = []
906
- for (let datapoint of pre_prepped_dataset.data) {
907
- if (pre_prepped_dataset.type === "klines") {
908
- const norm_x = (datapoint.x - shown_start_x) / shown_x_range
909
- const norm_o = (datapoint.o - shown_low_y) / shown_y_range
910
- const norm_l = (datapoint.l - shown_low_y) / shown_y_range
911
- const norm_h = (datapoint.h - shown_low_y) / shown_y_range
912
- const norm_c = (datapoint.c - shown_low_y) / shown_y_range
913
- const norm_details = get_kline_details(norm_o, norm_l, norm_h, norm_c)
914
- normalized_datapoints_in_range_loc.push({
915
- x: parseFloat(norm_x.toPrecision(6)),
916
- o: parseFloat(norm_o.toPrecision(6)),
917
- l: parseFloat(norm_l.toPrecision(6)),
918
- h: parseFloat(norm_h.toPrecision(6)),
919
- c: parseFloat(norm_c.toPrecision(6)),
920
- ...norm_details,
921
- })
922
- } else if (pre_prepped_dataset.type === "lines") {
923
- let x1 = shown_start_x
924
- let y1 = datapoint.m * x1 + datapoint.b
925
- if (y1 < shown_low_y) {
926
- x1 = (shown_low_y - datapoint.b) / datapoint.m
927
- y1 = shown_low_y
928
- } else if (y1 > shown_high_y) {
929
- x1 = (shown_high_y - datapoint.b) / datapoint.m
930
- y1 = shown_high_y
931
- }
932
- let x2 = shown_end_x
933
- let y2 = datapoint.m * x2 + datapoint.b
934
- if (y2 < shown_low_y) {
935
- x2 = (shown_low_y - datapoint.b) / datapoint.m
936
- y2 = shown_low_y
937
- } else if (y2 > shown_high_y) {
938
- x2 = (shown_high_y - datapoint.b) / datapoint.m
939
- y2 = shown_high_y
940
- }
941
- const norm_y1 = (y1 - shown_low_y) / shown_y_range
942
- const norm_y2 = (y2 - shown_low_y) / shown_y_range
943
- const norm_x1 = (x1 - shown_start_x) / shown_x_range
944
- const norm_x2 = (x2 - shown_start_x) / shown_x_range
945
- normalized_datapoints_in_range_loc.push({
946
- x1: parseFloat(norm_x1.toPrecision(6)),
947
- y1: parseFloat(norm_y1.toPrecision(6)),
948
- x2: parseFloat(norm_x2.toPrecision(6)),
949
- y2: parseFloat(norm_y2.toPrecision(6)),
950
- s: datapoint?.s,
951
- })
952
- } else {
953
- const norm_x = (datapoint.x - shown_start_x) / shown_x_range
954
- const norm_y = (datapoint.y - shown_low_y) / shown_y_range
955
- normalized_datapoints_in_range_loc.push({
956
- x: parseFloat(norm_x.toPrecision(6)),
957
- y: parseFloat(norm_y.toPrecision(6)),
958
- })
959
- }
960
- }
961
- pre_prepped_dataset.data = normalized_datapoints_in_range_loc
962
- prepped_datasets.push({
963
- ...pre_prepped_dataset,
964
- kline_width_pd: parseFloat(kline_width_pd.toPrecision(8)),
965
- })
966
- }
967
- const y_tics = prep_y_axis(shown_low_y, shown_high_y, frame_height)
968
- prepped_shared_y_axiss.push({
969
- bottom_padding_pd: shared_y_axis.bottom_padding_pd,
970
- top_padding_pd: shared_y_axis.top_padding_pd,
971
- y_axis_title: shared_y_axis.y_axis_title,
972
- y_axis_type: shared_y_axis.y_axis_type,
973
- shown_low_y: parseFloat(shown_low_y.toPrecision(8)),
974
- shown_high_y: parseFloat(shown_high_y.toPrecision(8)),
975
- y_axis_tics: y_tics,
976
- y_axis_highlight_tic: null,
977
- datasets: prepped_datasets,
978
- })
979
- }
980
- function change_shown_y_axis() {
981
- shown_y_axis_index = shown_y_axis_index < frame?.shared_y_axiss.length - 1 ? shown_y_axis_index + 1 : 0
982
- }
983
- prepped_frames.push({
984
- get aspect_ratio() {
985
- return frame.aspect_ratio
986
- },
987
- get frame_height() {
988
- return frame_height
989
- },
990
- get shared_y_axiss() {
991
- return prepped_shared_y_axiss
992
- },
993
- get shown_y_axis_index() {
994
- return shown_y_axis_index
995
- },
996
- y_hovered_percent_decimal: null,
997
- change_shown_y_axis,
998
- })
999
- }
1000
- frames = prepped_frames
1001
- let x_axis_tics = prep_x_axis(shown_start_x, shown_end_x, frame_width)
1002
- function set_shown_start_x(input) {
1003
- shown_start_x = input
1004
- }
1005
- function set_shown_end_x(input) {
1006
- shown_end_x = input
1007
- }
1008
- function set_x_hovered_percent_decimal(input) {
1009
- x_hovered_percent_decimal = input
1010
- }
1011
- return {
1012
- get id() {
1013
- return id
1014
- },
1015
- get x_axis_type() {
1016
- return x_axis_type
1017
- },
1018
- get x_axis_title() {
1019
- return x_axis_title
1020
- },
1021
- get shown_start_x() {
1022
- return shown_start_x
1023
- },
1024
- get shown_end_x() {
1025
- return shown_end_x
1026
- },
1027
- get frames() {
1028
- return frames
1029
- },
1030
- get min_x_scrollable() {
1031
- return min_x_scrollable
1032
- },
1033
- get max_x_scrollable() {
1034
- return max_x_scrollable
1035
- },
1036
- get x_axis_tics() {
1037
- return x_axis_tics
1038
- },
1039
- get x_axis_highlight_tic() {
1040
- return x_axis_highlight_tic
1041
- },
1042
- get x_hovered_percent_decimal() {
1043
- return x_hovered_percent_decimal
1044
- },
1045
- set_shown_start_x,
1046
- set_shown_end_x,
1047
- set_x_hovered_percent_decimal,
1048
- }
1049
- }
1050
-
1051
- function set_datasets(input) {
1052
- datasets = input
1053
- }
1054
-
1055
- function init(config) {
1056
- console.log("init_chart", config)
1057
- datasets = config?.datasets
1058
- chart_prepped = prep_chart({ ...config?.chart, shown_start_x: null, shown_end_x: null })
1059
- }
1060
-
1061
- init(config)
1062
-
1063
- return {
1064
- get datasets() {
1065
- return datasets
1066
- },
1067
- get chart_prepped() {
1068
- return chart_prepped
1069
- },
1070
- get y_axis_width() {
1071
- return y_axis_width
1072
- },
1073
- get x_axis_height() {
1074
- return x_axis_height
1075
- },
1076
- get grid_width() {
1077
- return grid_width
1078
- },
1079
- get frame_width() {
1080
- return frame_width
1081
- },
1082
- period_to_sec,
1083
- handle_scroll_frame,
1084
- handle_chart_hover,
1085
- handle_chart_hover_leave,
1086
- set_grid_width,
1087
- gen_color,
1088
- set_datasets,
1089
- }
1090
- }