sveltekit-ui 1.1.17 → 1.1.19

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