@tradeglotnpm/charts 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/NOTICE +19 -0
- package/README.md +50 -2
- package/assets/glot-charts-attribution.svg +6 -0
- package/dist/attribution.d.ts +3 -0
- package/dist/chart.d.ts +41 -0
- package/dist/csv.d.ts +2 -0
- package/dist/draw.d.ts +18 -0
- package/dist/glot-charts.esm.min.js +6 -0
- package/dist/glot-charts.min.js +6 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +1763 -0
- package/dist/marks.d.ts +15 -0
- package/dist/scale.d.ts +17 -0
- package/dist/series/axes.d.ts +46 -0
- package/dist/series/frame.d.ts +40 -0
- package/dist/series/gestures.d.ts +28 -0
- package/dist/series/logo.d.ts +2 -0
- package/dist/series/paint.d.ts +33 -0
- package/dist/series/series.d.ts +67 -0
- package/dist/series/time-chart.d.ts +76 -0
- package/dist/series/timeline.d.ts +15 -0
- package/dist/series/types.d.ts +128 -0
- package/dist/styles.d.ts +3 -0
- package/dist/theme.d.ts +18 -0
- package/dist/types.d.ts +73 -0
- package/dist/version.d.ts +1 -0
- package/package.json +63 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Glot Charts
|
|
2
|
+
Copyright 2026 TradeGlot
|
|
3
|
+
|
|
4
|
+
This product includes software developed by TradeGlot (https://tradeglot.com).
|
|
5
|
+
|
|
6
|
+
Licensed under the Apache License 2.0; see LICENSE.
|
|
7
|
+
|
|
8
|
+
Attribution notice: When you use Glot Charts in a product that is available to end
|
|
9
|
+
users, you must keep the Glot Charts attribution logo enabled on the chart
|
|
10
|
+
(attributionLogo: true, the default), or display the text "Charts by Glot Charts
|
|
11
|
+
(TradeGlot)" together with a link to https://tradeglot.com on a page of your website
|
|
12
|
+
or application that is publicly available to your users. See docs/attribution.md.
|
|
13
|
+
|
|
14
|
+
Trademarks: "Glot", "TradeGlot" and the TradeGlot logos are trademarks of TradeGlot.
|
|
15
|
+
No license in this repository grants any right to use them; see TRADEMARKS.md.
|
|
16
|
+
|
|
17
|
+
TradingView and Pine Script are trademarks of TradingView, Inc. MetaTrader, MQL4 and
|
|
18
|
+
MQL5 are trademarks of MetaQuotes Ltd. TradeGlot is not affiliated with, endorsed by
|
|
19
|
+
or sponsored by these companies. They are named only to describe compatibility.
|
package/README.md
CHANGED
|
@@ -1,3 +1,51 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @tradeglotnpm/charts
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Open-source financial charts for the web: candles, indicator lines, shape marks, fills and trade marks on Canvas 2D, with crosshair, pan and zoom. No run-time dependencies; about 6 KB gzip. Up is blue and down is orange by default.
|
|
4
|
+
|
|
5
|
+
> 0.1 is a preview: the API may change before 1.0.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @tradeglotnpm/charts
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Or with a script tag (global `GlotCharts`):
|
|
14
|
+
|
|
15
|
+
```html
|
|
16
|
+
<script src="https://cdn.jsdelivr.net/npm/@tradeglotnpm/charts@0.1/dist/glot-charts.min.js"></script>
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Quick start
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { createChart } from "@tradeglotnpm/charts";
|
|
23
|
+
|
|
24
|
+
const chart = createChart(document.getElementById("chart")!, { theme: "dark" }); // give #chart a height
|
|
25
|
+
chart.setData({
|
|
26
|
+
bars: [{ time: Date.UTC(2026, 0, 5), open: 4101.2, high: 4110.8, low: 4098.5, close: 4108.3 }],
|
|
27
|
+
});
|
|
28
|
+
chart.update({
|
|
29
|
+
time: Date.UTC(2026, 0, 5, 1),
|
|
30
|
+
open: 4108.3,
|
|
31
|
+
high: 4116.9,
|
|
32
|
+
low: 4105.0,
|
|
33
|
+
close: 4116.4,
|
|
34
|
+
});
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
`time` is Unix time in milliseconds, UTC.
|
|
38
|
+
|
|
39
|
+
## Documentation
|
|
40
|
+
|
|
41
|
+
- [Live demo](https://tradeglot.github.io/glot-charts/)
|
|
42
|
+
- [Getting started](https://github.com/tradeglot/glot-charts/blob/main/docs/getting-started.md)
|
|
43
|
+
- [API reference](https://github.com/tradeglot/glot-charts/blob/main/docs/api.md)
|
|
44
|
+
- [Examples: plain HTML, React, Vue](https://github.com/tradeglot/glot-charts/tree/main/examples)
|
|
45
|
+
- [Changelog](https://github.com/tradeglot/glot-charts/blob/main/CHANGELOG.md)
|
|
46
|
+
|
|
47
|
+
## License and attribution
|
|
48
|
+
|
|
49
|
+
Apache 2.0 with an attribution notice (see `NOTICE`). The chart shows a small Glot Charts logo by default; you may turn it off if you credit Glot Charts with a link on a public page of your product ([details](https://github.com/tradeglot/glot-charts/blob/main/docs/attribution.md)).
|
|
50
|
+
|
|
51
|
+
Charts show past prices. Trading involves risk of loss.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="96" height="20" viewBox="0 0 96 20" role="img" aria-label="Glot Charts">
|
|
2
|
+
<rect x="2" y="2" width="16" height="16" rx="4" fill="#6D5BFF"/>
|
|
3
|
+
<path d="M7 6.5L4.8 10 7 13.5M13 6.5L15.2 10 13 13.5" fill="none" stroke="#FFFFFF" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"/>
|
|
4
|
+
<rect x="8.6" y="7" width="2.8" height="6" rx="0.8" fill="#FFFFFF"/>
|
|
5
|
+
<text x="23" y="14.5" font-family="Space Grotesk, Arial, sans-serif" font-size="12" font-weight="600" fill="#5A5F7A">Glot Charts</text>
|
|
6
|
+
</svg>
|
package/dist/chart.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type ThemeOption } from "./theme.js";
|
|
2
|
+
import type { Bar, ChartData, ChartOptions } from "./types.js";
|
|
3
|
+
export declare class GlotChart {
|
|
4
|
+
private opts;
|
|
5
|
+
readonly el: HTMLDivElement;
|
|
6
|
+
private canvas;
|
|
7
|
+
private legend;
|
|
8
|
+
private labelEl;
|
|
9
|
+
private data;
|
|
10
|
+
private view;
|
|
11
|
+
private frame;
|
|
12
|
+
private drag;
|
|
13
|
+
private moved;
|
|
14
|
+
private raf;
|
|
15
|
+
private resize;
|
|
16
|
+
constructor(host: HTMLElement, opts?: ChartOptions);
|
|
17
|
+
setData(data: ChartData, keepView?: boolean): void;
|
|
18
|
+
/**
|
|
19
|
+
* Adds or changes the newest bar, for live data. A bar with the same time as the last bar
|
|
20
|
+
* replaces it; a later bar is appended. Indicator values for the new bar can follow through
|
|
21
|
+
* `setData`. Throws on a bar older than the last one.
|
|
22
|
+
*/
|
|
23
|
+
update(bar: Bar): void;
|
|
24
|
+
/** Switches between the built-in themes or your own colors. */
|
|
25
|
+
setTheme(theme: ThemeOption): void;
|
|
26
|
+
/** The data the chart currently draws. */
|
|
27
|
+
getData(): ChartData;
|
|
28
|
+
/** Highlights one bar (debugger cursor) and scrolls it into view. */
|
|
29
|
+
mark(bar: number | null): void;
|
|
30
|
+
/** Re-reads the theme colors (after a theme switch). */
|
|
31
|
+
refresh(): void;
|
|
32
|
+
dispose(): void;
|
|
33
|
+
private ariaLabel;
|
|
34
|
+
private bind;
|
|
35
|
+
private hover;
|
|
36
|
+
private renderLegend;
|
|
37
|
+
private schedule;
|
|
38
|
+
private draw;
|
|
39
|
+
}
|
|
40
|
+
/** Creates a chart inside `host` (it fills the host, so give the host a size). */
|
|
41
|
+
export declare function createChart(host: HTMLElement, options?: ChartOptions): GlotChart;
|
package/dist/csv.d.ts
ADDED
package/dist/draw.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type Viewport } from "./scale.js";
|
|
2
|
+
import type { ChartTheme } from "./theme.js";
|
|
3
|
+
import type { ChartData } from "./types.js";
|
|
4
|
+
export declare const AXIS_W = 72;
|
|
5
|
+
export declare const AXIS_H = 24;
|
|
6
|
+
export interface Frame {
|
|
7
|
+
width: number;
|
|
8
|
+
height: number;
|
|
9
|
+
/** Bar under the pointer, for the crosshair and legend. */
|
|
10
|
+
hover: number | null;
|
|
11
|
+
/** Bar highlighted by the debugger (part 4) or a click. */
|
|
12
|
+
marked: number | null;
|
|
13
|
+
}
|
|
14
|
+
export declare function drawFrame(ctx: CanvasRenderingContext2D, d: ChartData, v: Viewport, th: ChartTheme, f: Frame): void;
|
|
15
|
+
/** Index of the bar with time <= t (bars sorted by time). */
|
|
16
|
+
export declare function bisect(bars: {
|
|
17
|
+
time: number;
|
|
18
|
+
}[], t: number): number;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/*! Glot Charts 0.2.0 | Apache-2.0 with NOTICE | https://github.com/tradeglot/glot-charts */
|
|
2
|
+
var Fe=Object.defineProperty;var Be=(t,e,i)=>e in t?Fe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i;var p=(t,e,i)=>Be(t,typeof e!="symbol"?e+"":e,i);function de(t,e,i){let n=Math.ceil(e/i.barWidth)+1,r=Math.min(t-1,Math.floor(i.end));return[Math.max(0,r-n+1),r]}function Q(t,e,i){return e-(i.end-t+.5)*i.barWidth}function q(t,e,i){return Math.round(i.end+.5-(e-t)/i.barWidth)}function K(t,e=.05){let i=1/0,n=-1/0;for(let o of t)o===null||!Number.isFinite(o)||(o<i&&(i=o),o>n&&(n=o));if(i===1/0)return[0,1];if(i===n)return[i-1,n+1];let r=(n-i)*e;return[i-r,n+r]}function R(t,e){let i=t/Math.max(1,e),n=10**Math.floor(Math.log10(i)),r=i/n;return(r<1.5?1:r<3?2:r<7?5:10)*n}function P(t){return Math.max(0,Math.min(8,-Math.floor(Math.log10(t)+1e-9)))}function y(t,e){let i=Math.abs(t).toFixed(e),[n="0",r]=i.split("."),o=n.replace(/\B(?=(\d{3})+(?!\d))/g,",");return(t<0?"\u2212":"")+o+(r?"."+r:"")}function z(t,e){if(!t)return null;switch(t){case"up":return e.up;case"down":return e.down;case"accent":return e.accent;case"neutral":return e.muted;default:return t}}function ee(t,e,i,n,r,o,s,a){t.lineWidth=1.5;for(let l=Math.max(r,1);l<=o;l++){let h=e.values[l-1],m=e.values[l];h==null||m===null||m===void 0||(t.strokeStyle=z(e.colors?.[l],n)??i,t.beginPath(),t.moveTo(s(l-1),a(h)),t.lineTo(s(l),a(m)),t.stroke())}t.lineWidth=1}function pe(t,e,i,n,r,o,s,a){let l=i.find(m=>m.name===e.a)?.values,h=i.find(m=>m.name===e.b)?.values;if(!(!l||!h))for(let m=Math.max(r,1);m<=o;m++){let u=[l[m-1],l[m],h[m],h[m-1]],c=z(e.colors[m],n);if(!c||u.some(b=>b==null))continue;let[g,v,S,A]=u;t.fillStyle=c,t.beginPath(),t.moveTo(s(m-1),a(g)),t.lineTo(s(m),a(v)),t.lineTo(s(m),a(S)),t.lineTo(s(m-1),a(A)),t.closePath(),t.fill()}}function ce(t,e,i,n,r,o,s,a,l){for(let m=r;m<=o;m++){if(!e.values[m])continue;let u=i[m],c=s(m),g=e.at==="below_bar"?a(u.low)+12+2:e.at==="top"?12:e.at==="bottom"?l-12:a(u.high)-12-2,v=z(e.colors?.[m],n)??n.accent;if(t.fillStyle=t.strokeStyle=v,Ve(t,e.shape,c,g,6),e.text){t.font=`11px ${n.font}`,t.textAlign="center";let S=e.at==="below_bar"||e.at==="bottom";t.fillText(e.text,c,S?g+12+4:g-12-4),t.textAlign="start"}}}function Ve(t,e,i,n,r){switch(t.beginPath(),e){case"triangle_up":case"arrow_up":case"label_up":L(t,[i,n-r,i+r,n+r,i-r,n+r]);break;case"triangle_down":case"arrow_down":case"label_down":L(t,[i,n+r,i+r,n-r,i-r,n-r]);break;case"square":t.rect(i-r*.8,n-r*.8,r*1.6,r*1.6);break;case"diamond":L(t,[i,n-r,i+r,n,i,n+r,i-r,n]);break;case"cross":case"x_cross":{let o=e==="cross"?0:Math.PI/4;t.lineWidth=2;for(let s of[o,o+Math.PI/2])t.moveTo(i-r*Math.cos(s),n-r*Math.sin(s)),t.lineTo(i+r*Math.cos(s),n+r*Math.sin(s));t.stroke(),t.lineWidth=1;return}case"flag":L(t,[i-r*.6,n-r,i+r,n-r*.4,i-r*.6,n+r*.2]);break;default:t.arc(i,n,r*.7,0,Math.PI*2)}t.fill()}function L(t,e){t.moveTo(e[0],e[1]);for(let i=2;i<e.length;i+=2)t.lineTo(e[i],e[i+1]);t.closePath()}var x=72,H=24;function be(t,e,i,n,r){let o=r.width-x,s=e.series??[],a=s.filter(d=>!d.overlay),l=(r.height-H)*(a.length?.72:1),h=l,m=r.height-H-l;if(t.clearRect(0,0,r.width,r.height),t.fillStyle=n.bg,t.fillRect(0,0,r.width,r.height),e.bars.length===0)return;let[u,c]=de(e.bars.length,o,i),g=e.bars.slice(u,c+1),v=s.filter(d=>d.overlay),[S,A]=K([...g.flatMap(d=>[d.low,d.high]),...v.flatMap(d=>d.values.slice(u,c+1))]),b=d=>(A-d)/(A-S)*(l-8)+4,w=d=>Q(d,o,i),$=R(A-S,Math.max(2,Math.floor(l/60))),le=P($);t.font=`12px ${n.mono}`,t.textBaseline="middle";for(let d=Math.ceil(S/$)*$;d<=A;d+=$)D(t,n.grid,0,b(d),o,b(d)),t.fillStyle=n.muted,t.fillText(y(d,le),o+6,b(d));r.marked!==null&&r.marked>=u&&r.marked<=c&&(t.fillStyle=n.grid,t.fillRect(w(r.marked)-i.barWidth/2,0,i.barWidth,r.height-H));let he=Math.max(1,i.barWidth*.7);for(let d=u;d<=c;d++){let f=e.bars[d],T=f.close>=f.open;t.strokeStyle=t.fillStyle=T?n.up:n.down;let C=Math.round(w(d))+.5;D(t,t.strokeStyle,C,b(f.high),C,b(f.low));let M=b(Math.max(f.open,f.close));t.fillRect(C-he/2,M,he,Math.max(1,b(Math.min(f.open,f.close))-M))}for(let d of e.fills??[])pe(t,d,s,n,u,c,w,b);v.forEach((d,f)=>{let T=n.series[f%n.series.length];d.colors?.some(C=>C)?ee(t,d,T,n,u,c,w,b):fe(t,T,d.values,u,c,w,b,f>=n.series.length)});for(let d of e.shapes??[])ce(t,d,e.bars,n,u,c,w,b,l);let me=d=>ge(e.bars,d);for(let d of e.trades??[]){let f=me(d.entryTime),T=me(d.exitTime),C=d.side==="buy"?n.up:n.down;f>=u&&f<=c&&Le(t,C,w(f),b(d.entryPrice),d.side==="buy"),T>=u&&T<=c&&ze(t,C,w(T),b(d.exitPrice))}if(a.length){D(t,n.grid,0,h,r.width,h);let[d,f]=K(a.flatMap(M=>M.values.slice(u,c+1))),T=M=>h+4+(f-M)/(f-d)*(m-8);a.forEach((M,Oe)=>{let ue=n.series[Oe%n.series.length];M.colors?.some(We=>We)?ee(t,M,ue,n,u,c,w,T):fe(t,ue,M.values,u,c,w,T,!1)});let C=P(R(f-d,2));t.fillStyle=n.muted,t.fillText(y(f,C),o+6,h+10),t.fillText(y(d,C),o+6,h+m-10)}Ne(t,e,i,n,r,u,c),$e(t,e,n,r,w,b,l,le)}function Ne(t,e,i,n,r,o,s){let a=r.width-x,l=r.height-H;D(t,n.grid,0,l,r.width,l),t.fillStyle=n.muted,t.font=`12px ${n.font}`;let h=Math.max(1,Math.ceil(110/i.barWidth));for(let m=o-o%h;m<=s;m+=h){if(m<o)continue;let u=new Date(e.bars[m].time).toISOString();t.fillText(`${u.slice(5,10)} ${u.slice(11,16)}`,Q(m,a,i)-30,l+12)}t.fillText("UTC",a+6,l+12)}function $e(t,e,i,n,r,o,s,a){if(n.hover===null||!e.bars[n.hover])return;let l=e.bars[n.hover];t.setLineDash([4,4]),D(t,i.muted,Math.round(r(n.hover))+.5,0,Math.round(r(n.hover))+.5,n.height-H),t.setLineDash([]);let h=o(l.close);h>=0&&h<=s&&(t.fillStyle=i.grid,t.fillRect(n.width-x,h-9,x,18),t.fillStyle=i.text,t.font=`12px ${i.mono}`,t.fillText(y(l.close,a+1),n.width-x+6,h))}function fe(t,e,i,n,r,o,s,a){t.strokeStyle=e,t.lineWidth=1.5,t.setLineDash(a?[6,3]:[]),t.beginPath();let l=!1;for(let h=n;h<=r;h++){let m=i[h];if(m==null||!Number.isFinite(m)){l=!1;continue}l?t.lineTo(o(h),s(m)):t.moveTo(o(h),s(m)),l=!0}t.stroke(),t.setLineDash([]),t.lineWidth=1}function D(t,e,i,n,r,o){t.strokeStyle=e,t.beginPath(),t.moveTo(i,n),t.lineTo(r,o),t.stroke()}function Le(t,e,i,n,r){let s=r?n+10:n-10;t.fillStyle=e,t.beginPath(),t.moveTo(i,r?s-6:s+6),t.lineTo(i-6,r?s+6:s-6),t.lineTo(i+6,r?s+6:s-6),t.fill()}function ze(t,e,i,n){t.strokeStyle=e,t.lineWidth=2,t.beginPath(),t.arc(i,n,4,0,Math.PI*2),t.stroke(),t.lineWidth=1}function ge(t,e){let i=0,n=t.length-1;for(;i<n;){let r=i+n+1>>1;t[r].time<=e?i=r:n=r-1}return i}var E="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI5NiIgaGVpZ2h0PSIyMCIgdmlld0JveD0iMCAwIDk2IDIwIiByb2xlPSJpbWciIGFyaWEtbGFiZWw9Ikdsb3QgQ2hhcnRzIj4KPHJlY3QgeD0iMiIgeT0iMiIgd2lkdGg9IjE2IiBoZWlnaHQ9IjE2IiByeD0iNCIgZmlsbD0iIzZENUJGRiIvPgo8cGF0aCBkPSJNNyA2LjVMNC44IDEwIDcgMTMuNU0xMyA2LjVMMTUuMiAxMCAxMyAxMy41IiBmaWxsPSJub25lIiBzdHJva2U9IiNGRkZGRkYiIHN0cm9rZS13aWR0aD0iMS40IiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiLz4KPHJlY3QgeD0iOC42IiB5PSI3IiB3aWR0aD0iMi44IiBoZWlnaHQ9IjYiIHJ4PSIwLjgiIGZpbGw9IiNGRkZGRkYiLz4KPHRleHQgeD0iMjMiIHk9IjE0LjUiIGZvbnQtZmFtaWx5PSJTcGFjZSBHcm90ZXNrLCBBcmlhbCwgc2Fucy1zZXJpZiIgZm9udC1zaXplPSIxMiIgZm9udC13ZWlnaHQ9IjYwMCIgZmlsbD0iIzVBNUY3QSI+R2xvdCBDaGFydHM8L3RleHQ+Cjwvc3ZnPgo=",O="https://tradeglot.com/";var _e=`
|
|
3
|
+
:where(.glot-chart-legend){position:absolute;left:8px;top:6px;right:80px;font:12px var(--glot-chart-mono);color:var(--glot-chart-text);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;pointer-events:none}
|
|
4
|
+
:where(.glot-chart-label){position:absolute;right:80px;bottom:30px;font:600 12px var(--glot-chart-font);color:var(--glot-chart-muted);border:1px solid var(--glot-chart-grid);border-radius:999px;padding:2px 10px;pointer-events:none}
|
|
5
|
+
`;function _(t){if(t.querySelector("style[data-glot-charts]"))return;let e=t.createElement("style");e.dataset.glotCharts="",e.textContent=_e,t.head.append(e)}function U(t,e){t.style.setProperty("--glot-chart-text",e.text),t.style.setProperty("--glot-chart-muted",e.muted),t.style.setProperty("--glot-chart-grid",e.grid),t.style.setProperty("--glot-chart-font",e.font),t.style.setProperty("--glot-chart-mono",e.mono)}var ve='"Be Vietnam Pro", "Inter", sans-serif',ye='"JetBrains Mono", Menlo, monospace',te={dark:{bg:"#0E0F1A",text:"#ECEEF8",muted:"#A3A8C3",grid:"#2A2E48",up:"#3D8BFF",down:"#FF7A3D",accent:"#A99FFF",font:ve,mono:ye,series:["#A99FFF","#ECEEF8","#A3A8C3"]},light:{bg:"#F6F6FB",text:"#14152B",muted:"#5A5F7A",grid:"#DCDDEA",up:"#2266DE",down:"#BA481A",accent:"#5B4BE0",font:ve,mono:ye,series:["#5B4BE0","#14152B","#5A5F7A"]}};function W(t,e="dark"){let i=typeof e=="string"?te[e]:{...te.dark,...e},n=getComputedStyle(t),r=(h,m)=>n.getPropertyValue(h).trim()||m,o=r("--tg-text-accent",i.accent),s=r("--tg-text",i.text),a=r("--tg-muted",i.muted),l=n.getPropertyValue("--tg-text-accent").trim()!=="";return{bg:r("--tg-bg",i.bg),text:s,muted:a,grid:r("--tg-border",i.grid),up:r("--tg-chart-candle-up",i.up),down:r("--tg-chart-candle-down",i.down),accent:o,font:r("--tg-font-ui",i.font),mono:r("--tg-font-mono",i.mono),series:l?[o,s,a]:i.series}}var Ue=2,Ge=40,G=class{constructor(e,i={}){this.opts=i;p(this,"el");p(this,"canvas");p(this,"legend");p(this,"labelEl");p(this,"data",{bars:[]});p(this,"view",{end:0,barWidth:8});p(this,"frame",{width:0,height:0,hover:null,marked:null});p(this,"drag",null);p(this,"moved",!1);p(this,"raf",0);p(this,"resize");if(this.el=document.createElement("div"),this.el.className="glot-chart",this.el.style.cssText="position:relative;width:100%;height:100%;overflow:hidden;touch-action:none",this.canvas=document.createElement("canvas"),this.canvas.style.cssText="position:absolute;inset:0;width:100%;height:100%;cursor:crosshair",this.canvas.setAttribute("role","img"),this.legend=document.createElement("div"),this.legend.className="glot-chart-legend",this.labelEl=document.createElement("span"),this.labelEl.className="glot-chart-label",this.el.append(this.canvas,this.legend,this.labelEl),i.attributionLogo!==!1){let n=document.createElement("a");n.className="glot-chart-attribution",n.href=i.attributionHref??O,n.target="_blank",n.rel="noopener",n.title="Charts by Glot Charts (TradeGlot)",n.style.cssText="position:absolute;left:8px;bottom:28px;height:18px;opacity:0.7";let r=document.createElement("img");r.src=i.attributionSrc??E,r.alt="Glot Charts",r.height=18,r.style.cssText="height:18px;display:block",n.append(r),this.el.append(n)}_(e.ownerDocument),e.append(this.el),this.bind(),this.resize=new ResizeObserver(()=>this.schedule()),this.resize.observe(this.el)}setData(e,i=!1){let n=this.view.end>=this.data.bars.length-1;this.data=e,(!i||n)&&(this.view.end=Math.max(0,e.bars.length-1)),this.labelEl.textContent=e.label??"",this.labelEl.hidden=!e.label,this.canvas.setAttribute("aria-label",this.ariaLabel()),this.schedule()}update(e){let i=this.data.bars,n=i[i.length-1],r=this.view.end>=i.length-1;if(n&&e.time<n.time)throw new RangeError(`update: bar time ${e.time} is older than the last bar ${n.time}`);n&&e.time===n.time?i[i.length-1]=e:(i.push(e),r&&(this.view.end=i.length-1)),this.canvas.setAttribute("aria-label",this.ariaLabel()),this.schedule()}setTheme(e){this.opts={...this.opts,theme:e},this.schedule()}getData(){return this.data}mark(e){if(this.frame.marked=e,e!==null){let i=(this.frame.width-x)/this.view.barWidth;(e>this.view.end||e<this.view.end-i+1)&&(this.view.end=Math.min(this.data.bars.length-1,e+Math.floor(i/2)))}this.schedule()}refresh(){this.schedule()}dispose(){this.resize.disconnect(),cancelAnimationFrame(this.raf),this.el.remove()}ariaLabel(){let e=this.data.label;return`${this.data.bars.length} bars${e?`, ${e}`:""}`}bind(){let e=this.canvas;e.addEventListener("wheel",i=>{i.preventDefault();let n=i.deltaY>0?.85:1.15;this.view.barWidth=Math.min(Ge,Math.max(Ue,this.view.barWidth*n)),this.schedule()},{passive:!1}),e.addEventListener("pointerdown",i=>{this.drag={x:i.clientX,end:this.view.end},this.moved=!1,e.setPointerCapture(i.pointerId)}),e.addEventListener("pointermove",i=>{let n=e.getBoundingClientRect();if(this.drag){let r=i.clientX-this.drag.x;Math.abs(r)>3&&(this.moved=!0);let o=this.data.bars.length;this.view.end=Math.min(o-1+20,Math.max(0,this.drag.end-r/this.view.barWidth))}this.hover(q(i.clientX-n.left,n.width-x,this.view))}),e.addEventListener("pointerup",i=>{let n=e.getBoundingClientRect();if(this.drag&&!this.moved){let r=q(i.clientX-n.left,n.width-x,this.view);r>=0&&r<this.data.bars.length&&this.opts.onBarClick?.(r)}this.drag=null}),e.addEventListener("pointerleave",()=>this.hover(null))}hover(e){let i=e!==null&&e>=0&&e<this.data.bars.length?e:null;this.frame.hover=i,this.renderLegend(i??this.frame.marked??this.data.bars.length-1),this.schedule()}renderLegend(e){let i=this.data.bars[e];if(!i){this.legend.textContent="";return}let n=o=>y(o,2),r=[`O ${n(i.open)} H ${n(i.high)} L ${n(i.low)} C ${n(i.close)}`];for(let o of this.data.series??[]){let s=o.values[e];r.push(`${o.name} ${s==null?"na":n(s)}`)}this.legend.textContent=r.join(" ")}schedule(){cancelAnimationFrame(this.raf),this.raf=requestAnimationFrame(()=>this.draw())}draw(){let e=window.devicePixelRatio||1,i=this.el.clientWidth,n=this.el.clientHeight;if(i===0||n===0)return;(this.canvas.width!==Math.round(i*e)||this.canvas.height!==Math.round(n*e))&&(this.canvas.width=Math.round(i*e),this.canvas.height=Math.round(n*e));let r=this.canvas.getContext("2d");if(!r)return;r.setTransform(e,0,0,e,0,0),this.frame.width=i,this.frame.height=n,this.frame.hover===null&&this.renderLegend(this.frame.marked??this.data.bars.length-1);let o=W(this.el,this.opts.theme);U(this.el,o),be(r,this.data,this.view,o,this.frame)}};function Ze(t,e={}){return new G(t,e)}var je="0.2.0";function Ye(t){let e=t.split(`
|
|
6
|
+
`).filter(m=>m.trim()),i=(e.shift()??"").split(",").map(m=>m.trim().toLowerCase()),n=m=>i.indexOf(m),[r,o,s,a,l]=["time","open","high","low","close"].map(n);if([r,o,s,a,l].some(m=>m===void 0||m<0))return[];let h=[];for(let m of e){let u=m.split(","),c={time:Number(u[r]),open:Number(u[o]),high:Number(u[s]),low:Number(u[a]),close:Number(u[l])};Object.values(c).every(Number.isFinite)&&h.push(c)}return h}function we(t){let e=document.createElement("a");e.className="glot-chart-attribution",e.href=t.attributionHref??O,e.target="_blank",e.rel="noopener",e.title="Charts by Glot Charts (TradeGlot)";let i=t.timeAxisHeight??24;e.style.cssText=`position:absolute;left:8px;bottom:${i+6}px;height:18px;opacity:0.7;z-index:3`;let n=document.createElement("img");return n.src=t.attributionSrc??E,n.alt="Glot Charts",n.height=18,n.style.cssText="height:18px;display:block",e.append(n),e}function Te(t,e){switch(t){case"dotted":return[e,e];case"dashed":return[2*e,2*e];case"large-dashed":return[6*e,6*e];case"sparse-dotted":return[e,4*e];default:return[]}}function*ie(t,e){for(let i of t){let n=e.at(i.time);n===void 0||n<e.first-1||n>e.last+1||(yield[i,n])}}function Ce(t,e,i){e.visible&&(e.kind==="candles"?Xe(t,e,i):e.kind==="line"?Je(t,e,i):Qe(t,e,i))}function Xe(t,e,i){let n=e.opts,r=n.upColor??i.theme.up,o=n.downColor??i.theme.down,s=Math.max(1,Math.min(i.bw*.7,i.bw-1));t.lineWidth=1,t.setLineDash([]);for(let[a,l]of ie(e.data(),i)){let h=a.close>=a.open,m=Math.round(i.x(l))+.5;t.strokeStyle=h?n.wickUpColor??r:n.wickDownColor??o,t.beginPath(),t.moveTo(m,i.y(a.high)),t.lineTo(m,i.y(a.low)),t.stroke(),t.fillStyle=h?r:o;let u=i.y(Math.max(a.open,a.close)),c=Math.max(1,i.y(Math.min(a.open,a.close))-u);t.fillRect(Math.round(m-s/2),u,Math.max(1,Math.round(s)),c)}}function Je(t,e,i){let n=e.opts.width??1.5;t.strokeStyle=e.opts.color??i.theme.series[0],t.lineWidth=n,t.setLineDash(Te(e.opts.style,n)),t.beginPath();let r=!1,o=-2;for(let[s,a]of ie(e.data(),i)){if(!Number.isFinite(s.value)){r=!1;continue}r&&a>o?t.lineTo(i.x(a),i.y(s.value)):t.moveTo(i.x(a),i.y(s.value)),r=!0,o=a}t.stroke(),t.setLineDash([]),t.lineWidth=1}function Qe(t,e,i){let n=i.y(e.opts.base??0),r=Math.max(1,Math.round(i.bw*.8)),o=e.opts.color??i.theme.series[0];for(let[s,a]of ie(e.data(),i)){if(!Number.isFinite(s.value))continue;let l=i.y(s.value);t.fillStyle=s.color??o,t.fillRect(Math.round(i.x(a)-r/2),Math.min(l,n),r,Math.max(1,Math.abs(n-l)))}}function Me(t,e,i){if(!e.visible)return;t.font=`11px ${i.theme.font}`,t.textBaseline="bottom",t.textAlign="right";for(let r of e.lines){let o=r.opts,s=Math.round(i.y(o.price))+.5;if(s<0||s>i.plotH)continue;let a=o.width??1;t.strokeStyle=o.color??i.theme.muted,t.lineWidth=a,t.setLineDash(Te(o.style,a)),t.beginPath(),t.moveTo(0,s),t.lineTo(i.plotW,s),t.stroke(),o.title&&o.axisLabel===!1&&(t.setLineDash([]),t.fillStyle=o.color??i.theme.muted,t.fillText(o.title,i.plotW-6,s-2))}let n=re(e,i.theme);if(n&&e.opts.lastPriceLine===!0){let r=Math.round(i.y(n.value))+.5;t.strokeStyle=n.color,t.lineWidth=1,t.setLineDash([1,2]),t.beginPath(),t.moveTo(0,r),t.lineTo(i.plotW,r),t.stroke()}t.setLineDash([]),t.lineWidth=1,t.textAlign="left"}function ne(t){let e=0,i=0,n=0,r=/^#([0-9a-f]{3}|[0-9a-f]{6})/i.exec(t),o=/rgba?\(([^)]+)\)/i.exec(t);if(r){let s=r[1].length===3?[...r[1]].map(a=>a+a).join(""):r[1];[e,i,n]=[0,2,4].map(a=>parseInt(s.slice(a,a+2),16))}else if(o)[e,i,n]=o[1].split(",").map(s=>parseFloat(s));else return"#ffffff";return .299*e+.587*i+.114*n>150?"#000000":"#ffffff"}function re(t,e){let i=t.data(),n=i[i.length-1];if(!n)return null;if(t.kind==="candles"){let s=n,a=s.close>=s.open;return{value:s.close,color:(a?t.opts.upColor:t.opts.downColor)??(a?e.up:e.down)}}let r=n,o=r.color??t.opts.color??e.series[0];return{value:r.value,color:o}}function Se(t,e,i){if(!e.visible||e.markers.length===0)return;let n=e.data(),r=new Map(n.map(a=>[a.time,a])),o=new Map,s=Math.max(7,Math.min(12,i.bw*.9));t.font=`11px ${i.theme.font}`,t.textAlign="center";for(let a of e.markers){let l=i.at(a.time),h=r.get(a.time);if(l===void 0||!h||l<i.first||l>i.last)continue;let m="high"in h?[h.high,h.low]:[h.value,h.value],u=`${a.time}:${a.position}`,c=o.get(u)??0,g=s*(a.size??1),v=qe(t,a,i.x(l),m,i,g,c);o.set(u,c+v)}t.textAlign="left"}function qe(t,e,i,[n,r],o,s,a){let l=e.color??o.theme.accent,h=e.position==="above",m=e.position==="inside"?o.y(n):h?o.y(n)-4:o.y(r)+4,u=h?-1:1,c=m+u*a,g=e.position==="inside"?m:c+u*s/2;t.fillStyle=l,s>=3&&Ke(t,e.shape,i,g,s);let v=s+2;if(e.text){t.textBaseline=h?"bottom":"top";let S=e.position==="inside"?g-s:c+u*(s+2);t.fillText(e.text,i,S),v+=13}return v}function Ke(t,e,i,n,r){let o=r/2;if(t.beginPath(),e==="circle")t.arc(i,n,o*.8,0,Math.PI*2);else if(e==="square")t.rect(i-o*.8,n-o*.8,o*1.6,o*1.6);else{let s=e==="arrow_up"?-1:1;t.moveTo(i,n+s*o),t.lineTo(i-o,n),t.lineTo(i-o*.35,n),t.lineTo(i-o*.35,n-s*o),t.lineTo(i+o*.35,n-s*o),t.lineTo(i+o*.35,n),t.lineTo(i+o,n),t.closePath()}t.fill()}var xe="Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec".split(" "),Z=864e5;function ke(t,e,i,n){let r=R(e-t,Math.max(2,Math.floor(i/50))),o=[];for(let s=Math.ceil(t/r)*r;s<=e;s+=r)o.push(s);return{ticks:o,dec:n??P(r)}}var oe=[1,5,10,15,30,60,120,300,600,900,1800,3600,7200,10800,14400,21600,43200,86400,172800,604800,2592e3,7776e3,31536e3].map(t=>t*1e3);function Ie(t,e){let i=90/t.bw*e.step(),n=oe.find(s=>s>=i)??oe[oe.length-1],r=[],o=null;for(let s=Math.max(0,t.first-1);s<=t.last;s++){let a=e.times[s];if(a===void 0)continue;let l=Math.floor(a/n);o!==null&&l!==o&&s>=t.first&&r.push(s),o=l}return r}var I=t=>String(t).padStart(2,"0");function et(t){return t.getUTCMonth()===0&&t.getUTCDate()===1?String(t.getUTCFullYear()):`${t.getUTCDate()} ${xe[t.getUTCMonth()]}`}function tt(t,e,i,n){let r=new Date(t),o=e===null||Math.floor(e/Z)!==Math.floor(t/Z);if(!n.timeVisible||i>=Z||o&&t%Z===0)return et(r);let s=`${I(r.getUTCHours())}:${I(r.getUTCMinutes())}`;return n.secondsVisible?`${s}:${I(r.getUTCSeconds())}`:s}function it(t,e){let i=new Date(t),n=`${I(i.getUTCDate())} ${xe[i.getUTCMonth()]} ${i.getUTCFullYear()}`;if(!e.timeVisible)return n;let r=e.secondsVisible?`:${I(i.getUTCSeconds())}`:"";return`${n} ${I(i.getUTCHours())}:${I(i.getUTCMinutes())}${r}`}function Ae(t,e,i,n,r){if(r.grid!=="none"){t.strokeStyle=e.theme.grid,t.lineWidth=1,t.setLineDash(r.grid==="dotted"?[1,3]:[]),t.beginPath();for(let o of i){let s=Math.round(e.y(o))+.5;t.moveTo(0,s),t.lineTo(e.plotW,s)}for(let o of n){let s=Math.round(e.x(o))+.5;t.moveTo(s,0),t.lineTo(s,e.plotH)}t.stroke(),t.setLineDash([])}}var k=18;function nt(t,e=1/0,i=k){let n=t.map((a,l)=>({y:a,i:l})).sort((a,l)=>a.y-l.y),r=n.map(a=>a.y);for(let a=1;a<r.length;a++)r[a]=Math.max(r[a],r[a-1]+i);let o=e;for(let a=r.length-1;a>=0;a--)r[a]=Math.min(r[a],o),o=r[a]-i;let s=new Array(t.length);return n.forEach((a,l)=>s[a.i]=r[l]),s}function Re(t,e,i,n,r,o=ne(r)){i<-k/2||i>e.plotH+k/2||(t.fillStyle=r,t.fillRect(e.plotW,Math.round(i)-9,e.width-e.plotW,k),t.fillStyle=o,t.textBaseline="middle",t.fillText(n,e.plotW+6,Math.round(i)))}function rt(t,e,i,n,r){let o=t.measureText(n).width+10;t.fillStyle=r,t.fillRect(e.plotW-o-2,Math.round(i)-9,o,k),t.fillStyle=ne(r),t.textBaseline="middle",t.fillText(n,e.plotW-o+3,Math.round(i))}function ot(t,e,i){let n=[];for(let r of t){if(!r.visible)continue;let o=r.opts.priceDecimals??i;for(let a of r.lines){if(a.opts.axisLabel===!1)continue;let l=a.opts.color??e.theme.muted;n.push({y:e.y(a.opts.price),text:y(a.opts.price,o),bg:l,title:a.opts.title})}let s=r.opts.lastValueLabel!==!1?re(r,e.theme):null;s&&n.push({y:e.y(s.value),text:y(s.value,o),bg:s.color})}return n.filter(r=>r.y>=-k&&r.y<=e.plotH+k)}function Pe(t,e,i,n,r){let o=e.theme;t.fillStyle=o.bg,t.fillRect(e.plotW,0,e.width-e.plotW,e.height),t.strokeStyle=o.grid,t.beginPath(),t.moveTo(e.plotW+.5,0),t.lineTo(e.plotW+.5,e.plotH),t.stroke(),t.font=`11px ${o.mono}`,t.textBaseline="middle",t.fillStyle=o.muted;for(let l of n)t.fillText(y(l,r),e.plotW+6,e.y(l));let s=ot(i,e,r),a=nt(s.map(l=>l.y),e.plotH-k/2);s.forEach((l,h)=>{l.title&&rt(t,e,a[h],l.title,l.bg),Re(t,e,a[h],l.text,l.bg)})}function He(t,e,i,n,r){let o=e.theme;t.fillStyle=o.bg,t.fillRect(0,e.plotH,e.width,e.height-e.plotH),t.strokeStyle=o.grid,t.beginPath(),t.moveTo(0,e.plotH+.5),t.lineTo(e.width,e.plotH+.5),t.stroke(),t.font=`11px ${o.font}`,t.textBaseline="middle",t.textAlign="center",t.fillStyle=o.muted;let s=i.step(),a=n[0]!==void 0?i.toTime(n[0]-1):null,l=e.plotH+(e.height-e.plotH)/2;for(let h of n){let m=i.toTime(h);if(m===null)continue;let u=e.x(h);u>20&&u<e.plotW-20&&t.fillText(tt(m,a,s,r),u,l),a=m}t.textAlign="left",r.timeLabel&&t.fillText(r.timeLabel,e.plotW+6,l)}function De(t,e,i,n,r,o,s){let a=e.theme,l=Math.round(e.x(n.index))+.5;t.strokeStyle=a.muted,t.lineWidth=1,t.setLineDash([4,4]),t.beginPath(),t.moveTo(l,0),t.lineTo(l,e.plotH),n.y>=0&&n.y<=e.plotH&&(t.moveTo(0,Math.round(n.y)+.5),t.lineTo(e.plotW,Math.round(n.y)+.5)),t.stroke(),t.setLineDash([]),t.font=`11px ${a.mono}`,Re(t,e,n.y,y(r,o),a.grid,a.text);let h=i.toTime(n.index);if(h===null)return;let m=it(h,s),u=t.measureText(m).width+12,c=Math.max(0,Math.min(e.plotW-u,l-u/2));t.fillStyle=a.grid,t.fillRect(c,e.plotH+1,u,e.height-e.plotH-1),t.fillStyle=a.text,t.textBaseline="middle",t.fillText(m,c+6,e.plotH+(e.height-e.plotH)/2)}function st(t,e,i,n){let r=1/0,o=-1/0;for(let s of t){if(!s.visible)continue;let a=1/0,l=-1/0;for(let u of s.data()){let c=e.exact(u.time);if(c===void 0||c<i||c>n)continue;let[g,v]=s.span(u);Number.isFinite(g)&&g<a&&(a=g),Number.isFinite(v)&&v>l&&(l=v)}let h=a<=l?[a,l]:null,m=s.opts.autoscale?s.opts.autoscale(h):h;m&&(r=Math.min(r,m[0]),o=Math.max(o,m[1]))}return r===1/0?null:r===o?[r-1,o+1]:[r,o]}function at(t,e){let i=Math.max(0,t.width-t.axisW),n=Math.max(0,t.height-t.axisH),{end:r,bw:o}=t.view,s=t.timeline.length,a=Math.max(0,Math.floor(r-i/o)),l=Math.min(s-1,Math.ceil(r));return{width:t.width,height:t.height,plotW:i,plotH:n,bw:o,first:a,last:l,x:h=>i-(r-h+.5)*o,y:h=>e.top+(e.hi-h)/(e.hi-e.lo)*e.inner,at:h=>t.timeline.exact(h),theme:t.theme}}function se(t,e){let i=Math.max(0,t.width-t.axisW),n=Math.max(0,t.height-t.axisH),r=Math.max(0,Math.floor(t.view.end-i/t.view.bw)),o=Math.min(t.timeline.length-1,Math.ceil(t.view.end)),s=st(t.series,t.timeline,r,o),[a,l]=s??(e?[e.lo,e.hi]:[0,1]),h=n*.2;return{lo:a,hi:l,top:h,inner:Math.max(1,n-h-n*.1)}}function Ee(t,e,i){let n=at(e,i);t.clearRect(0,0,e.width,e.height),t.fillStyle=e.theme.bg,t.fillRect(0,0,e.width,e.height);let r=e.axis.priceDecimals??e.series.find(u=>u.visible)?.opts.priceDecimals,{ticks:o,dec:s}=ke(i.lo,i.hi,n.plotH,r),a=Ie(n,e.timeline);Ae(t,n,o,a,e.axis),t.save(),t.beginPath(),t.rect(0,0,n.plotW,n.plotH),t.clip();let l={width:n.plotW,height:n.plotH},h=u=>{t.save(),u.draw(t,l),t.restore()};for(let u of e.overlays)u.zOrder==="bottom"&&h(u);let m=["histogram","candles","line"];for(let u of m)for(let c of e.series)c.kind===u&&Ce(t,c,n);for(let u of e.series)Se(t,u,n);for(let u of e.series)Me(t,u,n);for(let u of e.overlays)u.zOrder!=="bottom"&&h(u);if(t.restore(),Pe(t,n,e.series,o,s),He(t,n,e.timeline,a,e.axis),e.hover){let u=i.hi-(e.hover.y-i.top)/i.inner*(i.hi-i.lo);De(t,n,e.timeline,e.hover,u,s,e.axis)}return n}var j=class{constructor(e,i){this.el=e;this.t=i;p(this,"pointers",new Map);p(this,"drag",null);p(this,"pinch",0);p(this,"off",[]);this.on("wheel",n=>this.wheel(n),{passive:!1}),this.on("pointerdown",n=>this.down(n)),this.on("pointermove",n=>this.move(n)),this.on("pointerup",n=>this.up(n)),this.on("pointercancel",n=>this.end(n)),this.on("pointerleave",n=>{n.pointerType==="mouse"&&this.t.hover(null,0)})}on(e,i,n){this.el.addEventListener(e,i,n),this.off.push(()=>this.el.removeEventListener(e,i,n))}pos(e){let i=this.el.getBoundingClientRect();return{x:e.clientX-i.left,y:e.clientY-i.top}}wheel(e){if(!this.t.enabled())return;e.preventDefault();let{x:i}=this.pos(e);Math.abs(e.deltaX)>Math.abs(e.deltaY)?this.t.pan(this.t.viewEnd(),-e.deltaX):this.t.zoom(Math.exp(-e.deltaY*.002),i)}down(e){let i=this.pos(e);this.pointers.set(e.pointerId,i),this.el.setPointerCapture?.(e.pointerId),this.pointers.size===2?(this.drag=null,this.pinch=this.spread()):this.drag={x:i.x,end:this.t.viewEnd(),moved:!1}}move(e){let i=this.pos(e);if(this.pointers.has(e.pointerId)&&this.pointers.set(e.pointerId,i),this.pointers.size===2&&this.pinch>0){let n=this.spread();if(this.t.enabled()&&n>0){let r=[...this.pointers.values()].reduce((o,s)=>o+s.x,0)/2;this.t.zoom(n/this.pinch,r)}this.pinch=n;return}if(this.drag){let n=i.x-this.drag.x;Math.abs(n)>3&&(this.drag.moved=!0),this.drag.moved&&this.t.enabled()&&this.t.pan(this.drag.end,n)}this.t.hover(i.x,i.y)}up(e){let i=this.pos(e);this.drag&&!this.drag.moved&&this.pointers.size===1&&this.t.click(i.x,i.y),this.end(e)}end(e){this.pointers.delete(e.pointerId),this.drag=null,this.pointers.size<2&&(this.pinch=0)}spread(){let[e,i]=[...this.pointers.values()];return e&&i?Math.hypot(e.x-i.x,e.y-i.y):0}dispose(){for(let e of this.off)e()}};var Y=class{constructor(e,i,n){this.host=e;this.opts=i;this.owner=n}update(e){this.opts={...this.opts,...e},this.host.redraw()}remove(){this.owner.removePriceLine(this)}};function lt(t,e){let i=t[t.length-1];if(!i||e.time>i.time){t.push(e);return}let n=0,r=t.length;for(;n<r;){let o=n+r>>1;t[o].time<e.time?n=o+1:r=o}t[n]?.time===e.time?t[n]=e:t.splice(n,0,e)}var F=class{constructor(e,i){this.host=e;this.opts=i;p(this,"points",[]);p(this,"lines",[]);p(this,"markers",[])}setData(e){this.points=[...e].sort((i,n)=>i.time-n.time),this.host.dataChanged()}update(e){lt(this.points,e),this.host.dataChanged()}data(){return this.points}times(){return this.points.map(e=>e.time)}setOptions(e){this.opts={...this.opts,...e},this.host.redraw()}get visible(){return this.opts.visible!==!1}addPriceLine(e){let i=new Y(this.host,e,this);return this.lines.push(i),this.host.redraw(),i}removePriceLine(e){let i=this.lines.indexOf(e);i>=0&&this.lines.splice(i,1),this.host.redraw()}setMarkers(e){this.markers=[...e].sort((i,n)=>i.time-n.time),this.host.redraw()}priceToY(e){return this.host.priceToY(e)}yToPrice(e){return this.host.yToPrice(e)}},B=class extends F{constructor(){super(...arguments);p(this,"kind","candles")}span(i){return[i.low,i.high]}value(i){return i.close}},V=class extends F{constructor(){super(...arguments);p(this,"kind","line")}span(i){return[i.value,i.value]}value(i){return i.value}},N=class extends F{constructor(){super(...arguments);p(this,"kind","histogram")}span(i){let n=this.opts.base??0;return[Math.min(n,i.value),Math.max(n,i.value)]}value(i){return i.value}};var X=class{constructor(){p(this,"times",[]);p(this,"index",new Map)}rebuild(e){let i=new Set;for(let n of e)for(let r of n)i.add(r);this.times=[...i].sort((n,r)=>n-r),this.index=new Map(this.times.map((n,r)=>[n,r]))}get length(){return this.times.length}exact(e){return this.index.get(e)}step(){let e=this.times.length;return e>=2?this.times[e-1]-this.times[e-2]:6e4}toIndex(e){let i=this.times,n=i.length;if(n===0)return null;let r=this.index.get(e);if(r!==void 0)return r;if(e<i[0])return n>=2?(e-i[0])/(i[1]-i[0]):-1;if(e>i[n-1])return n-1+(e-i[n-1])/this.step();let o=0,s=n-1;for(;s-o>1;){let a=o+s>>1;i[a]<=e?o=a:s=a}return o+(e-i[o])/(i[s]-i[o])}toTime(e){let i=this.times,n=i.length;if(n===0)return null;let r=Math.round(e);return r>=0&&r<n?i[r]:r<0?i[0]+r*(n>=2?i[1]-i[0]:6e4):i[n-1]+(r-n+1)*this.step()}};var ht=1,mt=60,J=class{constructor(e,i={}){this.opts=i;p(this,"el");p(this,"canvas");p(this,"legendEl");p(this,"series",[]);p(this,"overlays",[]);p(this,"timeline",new X);p(this,"view");p(this,"scale",null);p(this,"hover",null);p(this,"clicks",new Set);p(this,"rangeSubs",new Set);p(this,"lastRange","");p(this,"raf",0);p(this,"resize");p(this,"host");p(this,"gestures");this.view={end:0,bw:i.barSpacing??8},this.el=document.createElement("div"),this.el.className="glot-chart",this.el.style.cssText="position:relative;width:100%;height:100%;overflow:hidden;touch-action:none",this.canvas=document.createElement("canvas"),this.canvas.style.cssText="position:absolute;inset:0;width:100%;height:100%;cursor:crosshair",this.canvas.setAttribute("role","img"),this.legendEl=document.createElement("div"),this.legendEl.className="glot-chart-legend",this.legendEl.hidden=i.legend===!1,this.el.append(this.canvas,this.legendEl),i.attributionLogo!==!1&&this.el.append(we(i)),_(e.ownerDocument),e.append(this.el),this.host={dataChanged:()=>this.dataChanged(),redraw:()=>this.invalidate(),priceToY:n=>this.priceToY(n),yToPrice:n=>this.yToPrice(n)},this.gestures=new j(this.canvas,{enabled:()=>this.opts.interactive!==!1,pan:(n,r)=>this.panTo(n-r/this.view.bw),viewEnd:()=>this.view.end,zoom:(n,r)=>this.zoomAt(n,r),hover:(n,r)=>this.setHover(n,r),click:(n,r)=>this.emitClick(n,r)}),this.resize=new ResizeObserver(()=>this.invalidate()),this.resize.observe(this.el)}addCandles(e={}){return this.add(new B(this.host,{lastPriceLine:!0,...e}))}addLine(e={}){return this.add(new V(this.host,e))}addHistogram(e={}){return this.add(new N(this.host,e))}add(e){return this.series.push(e),this.dataChanged(),e}removeSeries(e){this.series=this.series.filter(i=>i!==e),this.dataChanged()}addOverlay(e){return this.overlays.push(e),this.invalidate(),()=>{this.overlays=this.overlays.filter(i=>i!==e),this.invalidate()}}setOptions(e){let i=this.timeline.length;e.rightOffset!==void 0&&e.rightOffset!==this.opts.rightOffset&&i&&(this.view.end=i-1+e.rightOffset),e.barSpacing!==void 0&&(this.view.bw=ae(e.barSpacing)),e.legend!==void 0&&(this.legendEl.hidden=e.legend===!1),this.opts={...this.opts,...e},this.invalidate()}options(){return{...this.opts,barSpacing:this.view.bw,rightOffset:this.opts.rightOffset??6}}plotSize(){let e=this.el.clientWidth-(this.opts.priceAxisWidth??72),i=this.el.clientHeight-(this.opts.timeAxisHeight??24);return{width:Math.max(0,e),height:Math.max(0,i)}}indexToX(e){return this.plotSize().width-(this.view.end-e+.5)*this.view.bw}xToIndex(e){return this.view.end+.5-(this.plotSize().width-e)/this.view.bw}timeToX(e){let i=this.timeline.toIndex(e);return i===null?null:this.indexToX(i)}xToTime(e){return this.timeline.toTime(this.xToIndex(e))}timeToIndex(e){return this.timeline.exact(e)??null}priceToY(e){let i=this.currentScale();return i?i.top+(i.hi-e)/(i.hi-i.lo)*i.inner:null}yToPrice(e){let i=this.currentScale();return i?i.hi-(e-i.top)/i.inner*(i.hi-i.lo):null}getVisibleIndexRange(){if(!this.timeline.length)return null;let e=this.plotSize().width;return{from:this.view.end-e/this.view.bw+1,to:this.view.end}}setVisibleIndexRange(e){let i=this.plotSize().width,n=Math.max(1,e.to-e.from+1);i>0&&(this.view.bw=ae(i/n)),this.view.end=e.to,this.invalidate()}getVisibleRange(){let e=this.getVisibleIndexRange(),i=this.timeline.length;if(!e||!i)return null;let n=Math.min(i-1,Math.max(0,Math.ceil(e.from))),r=Math.min(i-1,Math.max(0,Math.floor(e.to)));return{from:this.timeline.times[n],to:this.timeline.times[r]}}setVisibleRange(e){let i=this.timeline.toIndex(e.from),n=this.timeline.toIndex(e.to);i===null||n===null||this.setVisibleIndexRange({from:i,to:n})}scrollToEnd(){this.view.end=Math.max(0,this.timeline.length-1)+(this.opts.rightOffset??6),this.invalidate()}fitContent(){let e=this.timeline.length;e&&this.setVisibleIndexRange({from:0,to:e-1})}onVisibleRangeChange(e){return this.rangeSubs.add(e),()=>this.rangeSubs.delete(e)}onClick(e){return this.clicks.add(e),()=>this.clicks.delete(e)}invalidate(){this.scale=null,cancelAnimationFrame(this.raf),this.raf=requestAnimationFrame(()=>this.draw())}dispose(){this.resize.disconnect(),this.gestures.dispose(),cancelAnimationFrame(this.raf),this.el.remove()}dataChanged(){let e=this.timeline.length,i=this.view.end>=e-1;this.timeline.rebuild(this.series.map(r=>r.times()));let n=this.timeline.length;e===0&&n>0?this.view.end=n-1+(this.opts.rightOffset??6):i&&n>e&&(this.view.end+=n-e),this.canvas.setAttribute("aria-label",`${n} bars`),this.invalidate()}panTo(e){let i=this.timeline.length,n=this.plotSize().width/this.view.bw;this.view.end=Math.min(i-1+n*.8,Math.max(Math.min(i-1,2),e)),this.invalidate()}zoomAt(e,i){let n=this.plotSize().width,r=this.xToIndex(Math.min(i,n)),o=ae(this.view.bw*e);this.view.end=r-.5+(n-Math.min(i,n))/o,this.view.bw=o,this.invalidate()}setHover(e,i){let n=this.timeline.length;e===null||!n||e>this.plotSize().width?this.hover=null:this.hover={index:Math.round(this.xToIndex(e)-.5),y:i},this.invalidate()}emitClick(e,i){let n=Math.round(this.xToIndex(e)-.5),r=n>=0&&n<this.timeline.length,o={x:e,y:i,index:r?n:null,time:r?this.timeline.times[n]:null,price:this.yToPrice(i)};for(let s of this.clicks)s(o)}state(){let e=this.opts;return{width:this.el.clientWidth,height:this.el.clientHeight,axisW:e.priceAxisWidth??72,axisH:e.timeAxisHeight??24,view:this.view,timeline:this.timeline,series:this.series,overlays:this.overlays,theme:W(this.el,e.theme),axis:{grid:e.grid??"solid",timeVisible:e.timeVisible!==!1,secondsVisible:e.secondsVisible===!0,timeLabel:e.timeLabel??"UTC",priceDecimals:e.priceDecimals},hover:e.crosshair===!1?null:this.hover}}currentScale(){return this.timeline.length?(this.scale??(this.scale=se(this.state(),null)),this.scale):null}draw(){let e=window.devicePixelRatio||1,i=this.el.clientWidth,n=this.el.clientHeight;if(i===0||n===0)return;(this.canvas.width!==Math.round(i*e)||this.canvas.height!==Math.round(n*e))&&(this.canvas.width=Math.round(i*e),this.canvas.height=Math.round(n*e));let r=this.canvas.getContext("2d");if(!r)return;r.setTransform(e,0,0,e,0,0);let o=this.state();U(this.el,o.theme),this.scale=se(o,this.scale),Ee(r,o,this.scale),this.renderLegend(),this.emitRange()}renderLegend(){if(this.legendEl.hidden)return;let e=this.timeline.length,i=this.hover&&this.hover.index<e?this.hover.index:e-1,n=this.timeline.times[i];if(n===void 0){this.legendEl.textContent="";return}let r=[];for(let o of this.series){if(!o.visible)continue;let s=o.data().find(h=>h.time===n);if(!s)continue;let a=o.opts.priceDecimals??this.opts.priceDecimals??2,l=h=>y(h,a);if(o.kind==="candles"){let h=s;r.push(`O ${l(h.open)} H ${l(h.high)} L ${l(h.low)} C ${l(h.close)}`)}else o.opts.title&&r.push(`${o.opts.title} ${l(s.value)}`)}this.legendEl.textContent=r.join(" ")}emitRange(){let e=this.getVisibleRange(),i=e?`${e.from}:${e.to}`:"";if(i!==this.lastRange){this.lastRange=i;for(let n of this.rangeSubs)n(e)}}};function ae(t){return Math.min(mt,Math.max(ht,t))}function ut(t,e={}){return new J(t,e)}export{O as ATTRIBUTION_HREF,E as ATTRIBUTION_SRC,B as CandleSeries,G as GlotChart,N as HistogramSeries,V as LineSeriesApi,Y as PriceLine,te as THEMES,J as TimeChart,je as VERSION,q as barAt,Ye as barsFromCsv,ge as bisect,Ze as createChart,ut as createTimeChart,P as decimalsFor,K as extent,y as formatNumber,R as niceStep,W as readTheme,z as resolveColor,de as visibleRange,Q as xOf};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/*! Glot Charts 0.2.0 | Apache-2.0 with NOTICE | https://github.com/tradeglot/glot-charts */
|
|
2
|
+
"use strict";var GlotCharts=(()=>{var G=Object.defineProperty;var Le=Object.getOwnPropertyDescriptor;var ze=Object.getOwnPropertyNames;var _e=Object.prototype.hasOwnProperty;var Ue=(t,e,i)=>e in t?G(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i;var Ge=(t,e)=>{for(var i in e)G(t,i,{get:e[i],enumerable:!0})},Ze=(t,e,i,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of ze(e))!_e.call(t,r)&&r!==i&&G(t,r,{get:()=>e[r],enumerable:!(n=Le(e,r))||n.enumerable});return t};var je=t=>Ze(G({},"__esModule",{value:!0}),t);var p=(t,e,i)=>Ue(t,typeof e!="symbol"?e+"":e,i);var vt={};Ge(vt,{ATTRIBUTION_HREF:()=>D,ATTRIBUTION_SRC:()=>H,CandleSeries:()=>O,GlotChart:()=>$,HistogramSeries:()=>F,LineSeriesApi:()=>W,PriceLine:()=>L,THEMES:()=>q,TimeChart:()=>_,VERSION:()=>Ce,barAt:()=>j,barsFromCsv:()=>Me,bisect:()=>re,createChart:()=>Te,createTimeChart:()=>Ve,decimalsFor:()=>P,extent:()=>Y,formatNumber:()=>y,niceStep:()=>R,readTheme:()=>E,resolveColor:()=>B,visibleRange:()=>ie,xOf:()=>Z});function ie(t,e,i){let n=Math.ceil(e/i.barWidth)+1,r=Math.min(t-1,Math.floor(i.end));return[Math.max(0,r-n+1),r]}function Z(t,e,i){return e-(i.end-t+.5)*i.barWidth}function j(t,e,i){return Math.round(i.end+.5-(e-t)/i.barWidth)}function Y(t,e=.05){let i=1/0,n=-1/0;for(let o of t)o===null||!Number.isFinite(o)||(o<i&&(i=o),o>n&&(n=o));if(i===1/0)return[0,1];if(i===n)return[i-1,n+1];let r=(n-i)*e;return[i-r,n+r]}function R(t,e){let i=t/Math.max(1,e),n=10**Math.floor(Math.log10(i)),r=i/n;return(r<1.5?1:r<3?2:r<7?5:10)*n}function P(t){return Math.max(0,Math.min(8,-Math.floor(Math.log10(t)+1e-9)))}function y(t,e){let i=Math.abs(t).toFixed(e),[n="0",r]=i.split("."),o=n.replace(/\B(?=(\d{3})+(?!\d))/g,",");return(t<0?"\u2212":"")+o+(r?"."+r:"")}function B(t,e){if(!t)return null;switch(t){case"up":return e.up;case"down":return e.down;case"accent":return e.accent;case"neutral":return e.muted;default:return t}}function ne(t,e,i,n,r,o,s,a){t.lineWidth=1.5;for(let l=Math.max(r,1);l<=o;l++){let h=e.values[l-1],m=e.values[l];h==null||m===null||m===void 0||(t.strokeStyle=B(e.colors?.[l],n)??i,t.beginPath(),t.moveTo(s(l-1),a(h)),t.lineTo(s(l),a(m)),t.stroke())}t.lineWidth=1}function fe(t,e,i,n,r,o,s,a){let l=i.find(m=>m.name===e.a)?.values,h=i.find(m=>m.name===e.b)?.values;if(!(!l||!h))for(let m=Math.max(r,1);m<=o;m++){let u=[l[m-1],l[m],h[m],h[m-1]],c=B(e.colors[m],n);if(!c||u.some(b=>b==null))continue;let[g,v,S,A]=u;t.fillStyle=c,t.beginPath(),t.moveTo(s(m-1),a(g)),t.lineTo(s(m),a(v)),t.lineTo(s(m),a(S)),t.lineTo(s(m-1),a(A)),t.closePath(),t.fill()}}function be(t,e,i,n,r,o,s,a,l){for(let m=r;m<=o;m++){if(!e.values[m])continue;let u=i[m],c=s(m),g=e.at==="below_bar"?a(u.low)+12+2:e.at==="top"?12:e.at==="bottom"?l-12:a(u.high)-12-2,v=B(e.colors?.[m],n)??n.accent;if(t.fillStyle=t.strokeStyle=v,Ye(t,e.shape,c,g,6),e.text){t.font=`11px ${n.font}`,t.textAlign="center";let S=e.at==="below_bar"||e.at==="bottom";t.fillText(e.text,c,S?g+12+4:g-12-4),t.textAlign="start"}}}function Ye(t,e,i,n,r){switch(t.beginPath(),e){case"triangle_up":case"arrow_up":case"label_up":X(t,[i,n-r,i+r,n+r,i-r,n+r]);break;case"triangle_down":case"arrow_down":case"label_down":X(t,[i,n+r,i+r,n-r,i-r,n-r]);break;case"square":t.rect(i-r*.8,n-r*.8,r*1.6,r*1.6);break;case"diamond":X(t,[i,n-r,i+r,n,i,n+r,i-r,n]);break;case"cross":case"x_cross":{let o=e==="cross"?0:Math.PI/4;t.lineWidth=2;for(let s of[o,o+Math.PI/2])t.moveTo(i-r*Math.cos(s),n-r*Math.sin(s)),t.lineTo(i+r*Math.cos(s),n+r*Math.sin(s));t.stroke(),t.lineWidth=1;return}case"flag":X(t,[i-r*.6,n-r,i+r,n-r*.4,i-r*.6,n+r*.2]);break;default:t.arc(i,n,r*.7,0,Math.PI*2)}t.fill()}function X(t,e){t.moveTo(e[0],e[1]);for(let i=2;i<e.length;i+=2)t.lineTo(e[i],e[i+1]);t.closePath()}var x=72,V=24;function ve(t,e,i,n,r){let o=r.width-x,s=e.series??[],a=s.filter(d=>!d.overlay),l=(r.height-V)*(a.length?.72:1),h=l,m=r.height-V-l;if(t.clearRect(0,0,r.width,r.height),t.fillStyle=n.bg,t.fillRect(0,0,r.width,r.height),e.bars.length===0)return;let[u,c]=ie(e.bars.length,o,i),g=e.bars.slice(u,c+1),v=s.filter(d=>d.overlay),[S,A]=Y([...g.flatMap(d=>[d.low,d.high]),...v.flatMap(d=>d.values.slice(u,c+1))]),b=d=>(A-d)/(A-S)*(l-8)+4,w=d=>Z(d,o,i),U=R(A-S,Math.max(2,Math.floor(l/60))),ue=P(U);t.font=`12px ${n.mono}`,t.textBaseline="middle";for(let d=Math.ceil(S/U)*U;d<=A;d+=U)N(t,n.grid,0,b(d),o,b(d)),t.fillStyle=n.muted,t.fillText(y(d,ue),o+6,b(d));r.marked!==null&&r.marked>=u&&r.marked<=c&&(t.fillStyle=n.grid,t.fillRect(w(r.marked)-i.barWidth/2,0,i.barWidth,r.height-V));let de=Math.max(1,i.barWidth*.7);for(let d=u;d<=c;d++){let f=e.bars[d],T=f.close>=f.open;t.strokeStyle=t.fillStyle=T?n.up:n.down;let C=Math.round(w(d))+.5;N(t,t.strokeStyle,C,b(f.high),C,b(f.low));let M=b(Math.max(f.open,f.close));t.fillRect(C-de/2,M,de,Math.max(1,b(Math.min(f.open,f.close))-M))}for(let d of e.fills??[])fe(t,d,s,n,u,c,w,b);v.forEach((d,f)=>{let T=n.series[f%n.series.length];d.colors?.some(C=>C)?ne(t,d,T,n,u,c,w,b):ge(t,T,d.values,u,c,w,b,f>=n.series.length)});for(let d of e.shapes??[])be(t,d,e.bars,n,u,c,w,b,l);let pe=d=>re(e.bars,d);for(let d of e.trades??[]){let f=pe(d.entryTime),T=pe(d.exitTime),C=d.side==="buy"?n.up:n.down;f>=u&&f<=c&&Qe(t,C,w(f),b(d.entryPrice),d.side==="buy"),T>=u&&T<=c&&qe(t,C,w(T),b(d.exitPrice))}if(a.length){N(t,n.grid,0,h,r.width,h);let[d,f]=Y(a.flatMap(M=>M.values.slice(u,c+1))),T=M=>h+4+(f-M)/(f-d)*(m-8);a.forEach((M,Ne)=>{let ce=n.series[Ne%n.series.length];M.colors?.some($e=>$e)?ne(t,M,ce,n,u,c,w,T):ge(t,ce,M.values,u,c,w,T,!1)});let C=P(R(f-d,2));t.fillStyle=n.muted,t.fillText(y(f,C),o+6,h+10),t.fillText(y(d,C),o+6,h+m-10)}Xe(t,e,i,n,r,u,c),Je(t,e,n,r,w,b,l,ue)}function Xe(t,e,i,n,r,o,s){let a=r.width-x,l=r.height-V;N(t,n.grid,0,l,r.width,l),t.fillStyle=n.muted,t.font=`12px ${n.font}`;let h=Math.max(1,Math.ceil(110/i.barWidth));for(let m=o-o%h;m<=s;m+=h){if(m<o)continue;let u=new Date(e.bars[m].time).toISOString();t.fillText(`${u.slice(5,10)} ${u.slice(11,16)}`,Z(m,a,i)-30,l+12)}t.fillText("UTC",a+6,l+12)}function Je(t,e,i,n,r,o,s,a){if(n.hover===null||!e.bars[n.hover])return;let l=e.bars[n.hover];t.setLineDash([4,4]),N(t,i.muted,Math.round(r(n.hover))+.5,0,Math.round(r(n.hover))+.5,n.height-V),t.setLineDash([]);let h=o(l.close);h>=0&&h<=s&&(t.fillStyle=i.grid,t.fillRect(n.width-x,h-9,x,18),t.fillStyle=i.text,t.font=`12px ${i.mono}`,t.fillText(y(l.close,a+1),n.width-x+6,h))}function ge(t,e,i,n,r,o,s,a){t.strokeStyle=e,t.lineWidth=1.5,t.setLineDash(a?[6,3]:[]),t.beginPath();let l=!1;for(let h=n;h<=r;h++){let m=i[h];if(m==null||!Number.isFinite(m)){l=!1;continue}l?t.lineTo(o(h),s(m)):t.moveTo(o(h),s(m)),l=!0}t.stroke(),t.setLineDash([]),t.lineWidth=1}function N(t,e,i,n,r,o){t.strokeStyle=e,t.beginPath(),t.moveTo(i,n),t.lineTo(r,o),t.stroke()}function Qe(t,e,i,n,r){let s=r?n+10:n-10;t.fillStyle=e,t.beginPath(),t.moveTo(i,r?s-6:s+6),t.lineTo(i-6,r?s+6:s-6),t.lineTo(i+6,r?s+6:s-6),t.fill()}function qe(t,e,i,n){t.strokeStyle=e,t.lineWidth=2,t.beginPath(),t.arc(i,n,4,0,Math.PI*2),t.stroke(),t.lineWidth=1}function re(t,e){let i=0,n=t.length-1;for(;i<n;){let r=i+n+1>>1;t[r].time<=e?i=r:n=r-1}return i}var H="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI5NiIgaGVpZ2h0PSIyMCIgdmlld0JveD0iMCAwIDk2IDIwIiByb2xlPSJpbWciIGFyaWEtbGFiZWw9Ikdsb3QgQ2hhcnRzIj4KPHJlY3QgeD0iMiIgeT0iMiIgd2lkdGg9IjE2IiBoZWlnaHQ9IjE2IiByeD0iNCIgZmlsbD0iIzZENUJGRiIvPgo8cGF0aCBkPSJNNyA2LjVMNC44IDEwIDcgMTMuNU0xMyA2LjVMMTUuMiAxMCAxMyAxMy41IiBmaWxsPSJub25lIiBzdHJva2U9IiNGRkZGRkYiIHN0cm9rZS13aWR0aD0iMS40IiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiLz4KPHJlY3QgeD0iOC42IiB5PSI3IiB3aWR0aD0iMi44IiBoZWlnaHQ9IjYiIHJ4PSIwLjgiIGZpbGw9IiNGRkZGRkYiLz4KPHRleHQgeD0iMjMiIHk9IjE0LjUiIGZvbnQtZmFtaWx5PSJTcGFjZSBHcm90ZXNrLCBBcmlhbCwgc2Fucy1zZXJpZiIgZm9udC1zaXplPSIxMiIgZm9udC13ZWlnaHQ9IjYwMCIgZmlsbD0iIzVBNUY3QSI+R2xvdCBDaGFydHM8L3RleHQ+Cjwvc3ZnPgo=",D="https://tradeglot.com/";var Ke=`
|
|
3
|
+
:where(.glot-chart-legend){position:absolute;left:8px;top:6px;right:80px;font:12px var(--glot-chart-mono);color:var(--glot-chart-text);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;pointer-events:none}
|
|
4
|
+
:where(.glot-chart-label){position:absolute;right:80px;bottom:30px;font:600 12px var(--glot-chart-font);color:var(--glot-chart-muted);border:1px solid var(--glot-chart-grid);border-radius:999px;padding:2px 10px;pointer-events:none}
|
|
5
|
+
`;function J(t){if(t.querySelector("style[data-glot-charts]"))return;let e=t.createElement("style");e.dataset.glotCharts="",e.textContent=Ke,t.head.append(e)}function Q(t,e){t.style.setProperty("--glot-chart-text",e.text),t.style.setProperty("--glot-chart-muted",e.muted),t.style.setProperty("--glot-chart-grid",e.grid),t.style.setProperty("--glot-chart-font",e.font),t.style.setProperty("--glot-chart-mono",e.mono)}var ye='"Be Vietnam Pro", "Inter", sans-serif',we='"JetBrains Mono", Menlo, monospace',q={dark:{bg:"#0E0F1A",text:"#ECEEF8",muted:"#A3A8C3",grid:"#2A2E48",up:"#3D8BFF",down:"#FF7A3D",accent:"#A99FFF",font:ye,mono:we,series:["#A99FFF","#ECEEF8","#A3A8C3"]},light:{bg:"#F6F6FB",text:"#14152B",muted:"#5A5F7A",grid:"#DCDDEA",up:"#2266DE",down:"#BA481A",accent:"#5B4BE0",font:ye,mono:we,series:["#5B4BE0","#14152B","#5A5F7A"]}};function E(t,e="dark"){let i=typeof e=="string"?q[e]:{...q.dark,...e},n=getComputedStyle(t),r=(h,m)=>n.getPropertyValue(h).trim()||m,o=r("--tg-text-accent",i.accent),s=r("--tg-text",i.text),a=r("--tg-muted",i.muted),l=n.getPropertyValue("--tg-text-accent").trim()!=="";return{bg:r("--tg-bg",i.bg),text:s,muted:a,grid:r("--tg-border",i.grid),up:r("--tg-chart-candle-up",i.up),down:r("--tg-chart-candle-down",i.down),accent:o,font:r("--tg-font-ui",i.font),mono:r("--tg-font-mono",i.mono),series:l?[o,s,a]:i.series}}var et=2,tt=40,$=class{constructor(e,i={}){this.opts=i;p(this,"el");p(this,"canvas");p(this,"legend");p(this,"labelEl");p(this,"data",{bars:[]});p(this,"view",{end:0,barWidth:8});p(this,"frame",{width:0,height:0,hover:null,marked:null});p(this,"drag",null);p(this,"moved",!1);p(this,"raf",0);p(this,"resize");if(this.el=document.createElement("div"),this.el.className="glot-chart",this.el.style.cssText="position:relative;width:100%;height:100%;overflow:hidden;touch-action:none",this.canvas=document.createElement("canvas"),this.canvas.style.cssText="position:absolute;inset:0;width:100%;height:100%;cursor:crosshair",this.canvas.setAttribute("role","img"),this.legend=document.createElement("div"),this.legend.className="glot-chart-legend",this.labelEl=document.createElement("span"),this.labelEl.className="glot-chart-label",this.el.append(this.canvas,this.legend,this.labelEl),i.attributionLogo!==!1){let n=document.createElement("a");n.className="glot-chart-attribution",n.href=i.attributionHref??D,n.target="_blank",n.rel="noopener",n.title="Charts by Glot Charts (TradeGlot)",n.style.cssText="position:absolute;left:8px;bottom:28px;height:18px;opacity:0.7";let r=document.createElement("img");r.src=i.attributionSrc??H,r.alt="Glot Charts",r.height=18,r.style.cssText="height:18px;display:block",n.append(r),this.el.append(n)}J(e.ownerDocument),e.append(this.el),this.bind(),this.resize=new ResizeObserver(()=>this.schedule()),this.resize.observe(this.el)}setData(e,i=!1){let n=this.view.end>=this.data.bars.length-1;this.data=e,(!i||n)&&(this.view.end=Math.max(0,e.bars.length-1)),this.labelEl.textContent=e.label??"",this.labelEl.hidden=!e.label,this.canvas.setAttribute("aria-label",this.ariaLabel()),this.schedule()}update(e){let i=this.data.bars,n=i[i.length-1],r=this.view.end>=i.length-1;if(n&&e.time<n.time)throw new RangeError(`update: bar time ${e.time} is older than the last bar ${n.time}`);n&&e.time===n.time?i[i.length-1]=e:(i.push(e),r&&(this.view.end=i.length-1)),this.canvas.setAttribute("aria-label",this.ariaLabel()),this.schedule()}setTheme(e){this.opts={...this.opts,theme:e},this.schedule()}getData(){return this.data}mark(e){if(this.frame.marked=e,e!==null){let i=(this.frame.width-x)/this.view.barWidth;(e>this.view.end||e<this.view.end-i+1)&&(this.view.end=Math.min(this.data.bars.length-1,e+Math.floor(i/2)))}this.schedule()}refresh(){this.schedule()}dispose(){this.resize.disconnect(),cancelAnimationFrame(this.raf),this.el.remove()}ariaLabel(){let e=this.data.label;return`${this.data.bars.length} bars${e?`, ${e}`:""}`}bind(){let e=this.canvas;e.addEventListener("wheel",i=>{i.preventDefault();let n=i.deltaY>0?.85:1.15;this.view.barWidth=Math.min(tt,Math.max(et,this.view.barWidth*n)),this.schedule()},{passive:!1}),e.addEventListener("pointerdown",i=>{this.drag={x:i.clientX,end:this.view.end},this.moved=!1,e.setPointerCapture(i.pointerId)}),e.addEventListener("pointermove",i=>{let n=e.getBoundingClientRect();if(this.drag){let r=i.clientX-this.drag.x;Math.abs(r)>3&&(this.moved=!0);let o=this.data.bars.length;this.view.end=Math.min(o-1+20,Math.max(0,this.drag.end-r/this.view.barWidth))}this.hover(j(i.clientX-n.left,n.width-x,this.view))}),e.addEventListener("pointerup",i=>{let n=e.getBoundingClientRect();if(this.drag&&!this.moved){let r=j(i.clientX-n.left,n.width-x,this.view);r>=0&&r<this.data.bars.length&&this.opts.onBarClick?.(r)}this.drag=null}),e.addEventListener("pointerleave",()=>this.hover(null))}hover(e){let i=e!==null&&e>=0&&e<this.data.bars.length?e:null;this.frame.hover=i,this.renderLegend(i??this.frame.marked??this.data.bars.length-1),this.schedule()}renderLegend(e){let i=this.data.bars[e];if(!i){this.legend.textContent="";return}let n=o=>y(o,2),r=[`O ${n(i.open)} H ${n(i.high)} L ${n(i.low)} C ${n(i.close)}`];for(let o of this.data.series??[]){let s=o.values[e];r.push(`${o.name} ${s==null?"na":n(s)}`)}this.legend.textContent=r.join(" ")}schedule(){cancelAnimationFrame(this.raf),this.raf=requestAnimationFrame(()=>this.draw())}draw(){let e=window.devicePixelRatio||1,i=this.el.clientWidth,n=this.el.clientHeight;if(i===0||n===0)return;(this.canvas.width!==Math.round(i*e)||this.canvas.height!==Math.round(n*e))&&(this.canvas.width=Math.round(i*e),this.canvas.height=Math.round(n*e));let r=this.canvas.getContext("2d");if(!r)return;r.setTransform(e,0,0,e,0,0),this.frame.width=i,this.frame.height=n,this.frame.hover===null&&this.renderLegend(this.frame.marked??this.data.bars.length-1);let o=E(this.el,this.opts.theme);Q(this.el,o),ve(r,this.data,this.view,o,this.frame)}};function Te(t,e={}){return new $(t,e)}var Ce="0.2.0";function Me(t){let e=t.split(`
|
|
6
|
+
`).filter(m=>m.trim()),i=(e.shift()??"").split(",").map(m=>m.trim().toLowerCase()),n=m=>i.indexOf(m),[r,o,s,a,l]=["time","open","high","low","close"].map(n);if([r,o,s,a,l].some(m=>m===void 0||m<0))return[];let h=[];for(let m of e){let u=m.split(","),c={time:Number(u[r]),open:Number(u[o]),high:Number(u[s]),low:Number(u[a]),close:Number(u[l])};Object.values(c).every(Number.isFinite)&&h.push(c)}return h}function Se(t){let e=document.createElement("a");e.className="glot-chart-attribution",e.href=t.attributionHref??D,e.target="_blank",e.rel="noopener",e.title="Charts by Glot Charts (TradeGlot)";let i=t.timeAxisHeight??24;e.style.cssText=`position:absolute;left:8px;bottom:${i+6}px;height:18px;opacity:0.7;z-index:3`;let n=document.createElement("img");return n.src=t.attributionSrc??H,n.alt="Glot Charts",n.height=18,n.style.cssText="height:18px;display:block",e.append(n),e}function xe(t,e){switch(t){case"dotted":return[e,e];case"dashed":return[2*e,2*e];case"large-dashed":return[6*e,6*e];case"sparse-dotted":return[e,4*e];default:return[]}}function*oe(t,e){for(let i of t){let n=e.at(i.time);n===void 0||n<e.first-1||n>e.last+1||(yield[i,n])}}function ke(t,e,i){e.visible&&(e.kind==="candles"?it(t,e,i):e.kind==="line"?nt(t,e,i):rt(t,e,i))}function it(t,e,i){let n=e.opts,r=n.upColor??i.theme.up,o=n.downColor??i.theme.down,s=Math.max(1,Math.min(i.bw*.7,i.bw-1));t.lineWidth=1,t.setLineDash([]);for(let[a,l]of oe(e.data(),i)){let h=a.close>=a.open,m=Math.round(i.x(l))+.5;t.strokeStyle=h?n.wickUpColor??r:n.wickDownColor??o,t.beginPath(),t.moveTo(m,i.y(a.high)),t.lineTo(m,i.y(a.low)),t.stroke(),t.fillStyle=h?r:o;let u=i.y(Math.max(a.open,a.close)),c=Math.max(1,i.y(Math.min(a.open,a.close))-u);t.fillRect(Math.round(m-s/2),u,Math.max(1,Math.round(s)),c)}}function nt(t,e,i){let n=e.opts.width??1.5;t.strokeStyle=e.opts.color??i.theme.series[0],t.lineWidth=n,t.setLineDash(xe(e.opts.style,n)),t.beginPath();let r=!1,o=-2;for(let[s,a]of oe(e.data(),i)){if(!Number.isFinite(s.value)){r=!1;continue}r&&a>o?t.lineTo(i.x(a),i.y(s.value)):t.moveTo(i.x(a),i.y(s.value)),r=!0,o=a}t.stroke(),t.setLineDash([]),t.lineWidth=1}function rt(t,e,i){let n=i.y(e.opts.base??0),r=Math.max(1,Math.round(i.bw*.8)),o=e.opts.color??i.theme.series[0];for(let[s,a]of oe(e.data(),i)){if(!Number.isFinite(s.value))continue;let l=i.y(s.value);t.fillStyle=s.color??o,t.fillRect(Math.round(i.x(a)-r/2),Math.min(l,n),r,Math.max(1,Math.abs(n-l)))}}function Ie(t,e,i){if(!e.visible)return;t.font=`11px ${i.theme.font}`,t.textBaseline="bottom",t.textAlign="right";for(let r of e.lines){let o=r.opts,s=Math.round(i.y(o.price))+.5;if(s<0||s>i.plotH)continue;let a=o.width??1;t.strokeStyle=o.color??i.theme.muted,t.lineWidth=a,t.setLineDash(xe(o.style,a)),t.beginPath(),t.moveTo(0,s),t.lineTo(i.plotW,s),t.stroke(),o.title&&o.axisLabel===!1&&(t.setLineDash([]),t.fillStyle=o.color??i.theme.muted,t.fillText(o.title,i.plotW-6,s-2))}let n=ae(e,i.theme);if(n&&e.opts.lastPriceLine===!0){let r=Math.round(i.y(n.value))+.5;t.strokeStyle=n.color,t.lineWidth=1,t.setLineDash([1,2]),t.beginPath(),t.moveTo(0,r),t.lineTo(i.plotW,r),t.stroke()}t.setLineDash([]),t.lineWidth=1,t.textAlign="left"}function se(t){let e=0,i=0,n=0,r=/^#([0-9a-f]{3}|[0-9a-f]{6})/i.exec(t),o=/rgba?\(([^)]+)\)/i.exec(t);if(r){let s=r[1].length===3?[...r[1]].map(a=>a+a).join(""):r[1];[e,i,n]=[0,2,4].map(a=>parseInt(s.slice(a,a+2),16))}else if(o)[e,i,n]=o[1].split(",").map(s=>parseFloat(s));else return"#ffffff";return .299*e+.587*i+.114*n>150?"#000000":"#ffffff"}function ae(t,e){let i=t.data(),n=i[i.length-1];if(!n)return null;if(t.kind==="candles"){let s=n,a=s.close>=s.open;return{value:s.close,color:(a?t.opts.upColor:t.opts.downColor)??(a?e.up:e.down)}}let r=n,o=r.color??t.opts.color??e.series[0];return{value:r.value,color:o}}function Ae(t,e,i){if(!e.visible||e.markers.length===0)return;let n=e.data(),r=new Map(n.map(a=>[a.time,a])),o=new Map,s=Math.max(7,Math.min(12,i.bw*.9));t.font=`11px ${i.theme.font}`,t.textAlign="center";for(let a of e.markers){let l=i.at(a.time),h=r.get(a.time);if(l===void 0||!h||l<i.first||l>i.last)continue;let m="high"in h?[h.high,h.low]:[h.value,h.value],u=`${a.time}:${a.position}`,c=o.get(u)??0,g=s*(a.size??1),v=ot(t,a,i.x(l),m,i,g,c);o.set(u,c+v)}t.textAlign="left"}function ot(t,e,i,[n,r],o,s,a){let l=e.color??o.theme.accent,h=e.position==="above",m=e.position==="inside"?o.y(n):h?o.y(n)-4:o.y(r)+4,u=h?-1:1,c=m+u*a,g=e.position==="inside"?m:c+u*s/2;t.fillStyle=l,s>=3&&st(t,e.shape,i,g,s);let v=s+2;if(e.text){t.textBaseline=h?"bottom":"top";let S=e.position==="inside"?g-s:c+u*(s+2);t.fillText(e.text,i,S),v+=13}return v}function st(t,e,i,n,r){let o=r/2;if(t.beginPath(),e==="circle")t.arc(i,n,o*.8,0,Math.PI*2);else if(e==="square")t.rect(i-o*.8,n-o*.8,o*1.6,o*1.6);else{let s=e==="arrow_up"?-1:1;t.moveTo(i,n+s*o),t.lineTo(i-o,n),t.lineTo(i-o*.35,n),t.lineTo(i-o*.35,n-s*o),t.lineTo(i+o*.35,n-s*o),t.lineTo(i+o*.35,n),t.lineTo(i+o,n),t.closePath()}t.fill()}var Re="Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec".split(" "),K=864e5;function Pe(t,e,i,n){let r=R(e-t,Math.max(2,Math.floor(i/50))),o=[];for(let s=Math.ceil(t/r)*r;s<=e;s+=r)o.push(s);return{ticks:o,dec:n??P(r)}}var le=[1,5,10,15,30,60,120,300,600,900,1800,3600,7200,10800,14400,21600,43200,86400,172800,604800,2592e3,7776e3,31536e3].map(t=>t*1e3);function He(t,e){let i=90/t.bw*e.step(),n=le.find(s=>s>=i)??le[le.length-1],r=[],o=null;for(let s=Math.max(0,t.first-1);s<=t.last;s++){let a=e.times[s];if(a===void 0)continue;let l=Math.floor(a/n);o!==null&&l!==o&&s>=t.first&&r.push(s),o=l}return r}var I=t=>String(t).padStart(2,"0");function at(t){return t.getUTCMonth()===0&&t.getUTCDate()===1?String(t.getUTCFullYear()):`${t.getUTCDate()} ${Re[t.getUTCMonth()]}`}function lt(t,e,i,n){let r=new Date(t),o=e===null||Math.floor(e/K)!==Math.floor(t/K);if(!n.timeVisible||i>=K||o&&t%K===0)return at(r);let s=`${I(r.getUTCHours())}:${I(r.getUTCMinutes())}`;return n.secondsVisible?`${s}:${I(r.getUTCSeconds())}`:s}function ht(t,e){let i=new Date(t),n=`${I(i.getUTCDate())} ${Re[i.getUTCMonth()]} ${i.getUTCFullYear()}`;if(!e.timeVisible)return n;let r=e.secondsVisible?`:${I(i.getUTCSeconds())}`:"";return`${n} ${I(i.getUTCHours())}:${I(i.getUTCMinutes())}${r}`}function De(t,e,i,n,r){if(r.grid!=="none"){t.strokeStyle=e.theme.grid,t.lineWidth=1,t.setLineDash(r.grid==="dotted"?[1,3]:[]),t.beginPath();for(let o of i){let s=Math.round(e.y(o))+.5;t.moveTo(0,s),t.lineTo(e.plotW,s)}for(let o of n){let s=Math.round(e.x(o))+.5;t.moveTo(s,0),t.lineTo(s,e.plotH)}t.stroke(),t.setLineDash([])}}var k=18;function mt(t,e=1/0,i=k){let n=t.map((a,l)=>({y:a,i:l})).sort((a,l)=>a.y-l.y),r=n.map(a=>a.y);for(let a=1;a<r.length;a++)r[a]=Math.max(r[a],r[a-1]+i);let o=e;for(let a=r.length-1;a>=0;a--)r[a]=Math.min(r[a],o),o=r[a]-i;let s=new Array(t.length);return n.forEach((a,l)=>s[a.i]=r[l]),s}function Ee(t,e,i,n,r,o=se(r)){i<-k/2||i>e.plotH+k/2||(t.fillStyle=r,t.fillRect(e.plotW,Math.round(i)-9,e.width-e.plotW,k),t.fillStyle=o,t.textBaseline="middle",t.fillText(n,e.plotW+6,Math.round(i)))}function ut(t,e,i,n,r){let o=t.measureText(n).width+10;t.fillStyle=r,t.fillRect(e.plotW-o-2,Math.round(i)-9,o,k),t.fillStyle=se(r),t.textBaseline="middle",t.fillText(n,e.plotW-o+3,Math.round(i))}function dt(t,e,i){let n=[];for(let r of t){if(!r.visible)continue;let o=r.opts.priceDecimals??i;for(let a of r.lines){if(a.opts.axisLabel===!1)continue;let l=a.opts.color??e.theme.muted;n.push({y:e.y(a.opts.price),text:y(a.opts.price,o),bg:l,title:a.opts.title})}let s=r.opts.lastValueLabel!==!1?ae(r,e.theme):null;s&&n.push({y:e.y(s.value),text:y(s.value,o),bg:s.color})}return n.filter(r=>r.y>=-k&&r.y<=e.plotH+k)}function Oe(t,e,i,n,r){let o=e.theme;t.fillStyle=o.bg,t.fillRect(e.plotW,0,e.width-e.plotW,e.height),t.strokeStyle=o.grid,t.beginPath(),t.moveTo(e.plotW+.5,0),t.lineTo(e.plotW+.5,e.plotH),t.stroke(),t.font=`11px ${o.mono}`,t.textBaseline="middle",t.fillStyle=o.muted;for(let l of n)t.fillText(y(l,r),e.plotW+6,e.y(l));let s=dt(i,e,r),a=mt(s.map(l=>l.y),e.plotH-k/2);s.forEach((l,h)=>{l.title&&ut(t,e,a[h],l.title,l.bg),Ee(t,e,a[h],l.text,l.bg)})}function We(t,e,i,n,r){let o=e.theme;t.fillStyle=o.bg,t.fillRect(0,e.plotH,e.width,e.height-e.plotH),t.strokeStyle=o.grid,t.beginPath(),t.moveTo(0,e.plotH+.5),t.lineTo(e.width,e.plotH+.5),t.stroke(),t.font=`11px ${o.font}`,t.textBaseline="middle",t.textAlign="center",t.fillStyle=o.muted;let s=i.step(),a=n[0]!==void 0?i.toTime(n[0]-1):null,l=e.plotH+(e.height-e.plotH)/2;for(let h of n){let m=i.toTime(h);if(m===null)continue;let u=e.x(h);u>20&&u<e.plotW-20&&t.fillText(lt(m,a,s,r),u,l),a=m}t.textAlign="left",r.timeLabel&&t.fillText(r.timeLabel,e.plotW+6,l)}function Fe(t,e,i,n,r,o,s){let a=e.theme,l=Math.round(e.x(n.index))+.5;t.strokeStyle=a.muted,t.lineWidth=1,t.setLineDash([4,4]),t.beginPath(),t.moveTo(l,0),t.lineTo(l,e.plotH),n.y>=0&&n.y<=e.plotH&&(t.moveTo(0,Math.round(n.y)+.5),t.lineTo(e.plotW,Math.round(n.y)+.5)),t.stroke(),t.setLineDash([]),t.font=`11px ${a.mono}`,Ee(t,e,n.y,y(r,o),a.grid,a.text);let h=i.toTime(n.index);if(h===null)return;let m=ht(h,s),u=t.measureText(m).width+12,c=Math.max(0,Math.min(e.plotW-u,l-u/2));t.fillStyle=a.grid,t.fillRect(c,e.plotH+1,u,e.height-e.plotH-1),t.fillStyle=a.text,t.textBaseline="middle",t.fillText(m,c+6,e.plotH+(e.height-e.plotH)/2)}function pt(t,e,i,n){let r=1/0,o=-1/0;for(let s of t){if(!s.visible)continue;let a=1/0,l=-1/0;for(let u of s.data()){let c=e.exact(u.time);if(c===void 0||c<i||c>n)continue;let[g,v]=s.span(u);Number.isFinite(g)&&g<a&&(a=g),Number.isFinite(v)&&v>l&&(l=v)}let h=a<=l?[a,l]:null,m=s.opts.autoscale?s.opts.autoscale(h):h;m&&(r=Math.min(r,m[0]),o=Math.max(o,m[1]))}return r===1/0?null:r===o?[r-1,o+1]:[r,o]}function ct(t,e){let i=Math.max(0,t.width-t.axisW),n=Math.max(0,t.height-t.axisH),{end:r,bw:o}=t.view,s=t.timeline.length,a=Math.max(0,Math.floor(r-i/o)),l=Math.min(s-1,Math.ceil(r));return{width:t.width,height:t.height,plotW:i,plotH:n,bw:o,first:a,last:l,x:h=>i-(r-h+.5)*o,y:h=>e.top+(e.hi-h)/(e.hi-e.lo)*e.inner,at:h=>t.timeline.exact(h),theme:t.theme}}function he(t,e){let i=Math.max(0,t.width-t.axisW),n=Math.max(0,t.height-t.axisH),r=Math.max(0,Math.floor(t.view.end-i/t.view.bw)),o=Math.min(t.timeline.length-1,Math.ceil(t.view.end)),s=pt(t.series,t.timeline,r,o),[a,l]=s??(e?[e.lo,e.hi]:[0,1]),h=n*.2;return{lo:a,hi:l,top:h,inner:Math.max(1,n-h-n*.1)}}function Be(t,e,i){let n=ct(e,i);t.clearRect(0,0,e.width,e.height),t.fillStyle=e.theme.bg,t.fillRect(0,0,e.width,e.height);let r=e.axis.priceDecimals??e.series.find(u=>u.visible)?.opts.priceDecimals,{ticks:o,dec:s}=Pe(i.lo,i.hi,n.plotH,r),a=He(n,e.timeline);De(t,n,o,a,e.axis),t.save(),t.beginPath(),t.rect(0,0,n.plotW,n.plotH),t.clip();let l={width:n.plotW,height:n.plotH},h=u=>{t.save(),u.draw(t,l),t.restore()};for(let u of e.overlays)u.zOrder==="bottom"&&h(u);let m=["histogram","candles","line"];for(let u of m)for(let c of e.series)c.kind===u&&ke(t,c,n);for(let u of e.series)Ae(t,u,n);for(let u of e.series)Ie(t,u,n);for(let u of e.overlays)u.zOrder!=="bottom"&&h(u);if(t.restore(),Oe(t,n,e.series,o,s),We(t,n,e.timeline,a,e.axis),e.hover){let u=i.hi-(e.hover.y-i.top)/i.inner*(i.hi-i.lo);Fe(t,n,e.timeline,e.hover,u,s,e.axis)}return n}var ee=class{constructor(e,i){this.el=e;this.t=i;p(this,"pointers",new Map);p(this,"drag",null);p(this,"pinch",0);p(this,"off",[]);this.on("wheel",n=>this.wheel(n),{passive:!1}),this.on("pointerdown",n=>this.down(n)),this.on("pointermove",n=>this.move(n)),this.on("pointerup",n=>this.up(n)),this.on("pointercancel",n=>this.end(n)),this.on("pointerleave",n=>{n.pointerType==="mouse"&&this.t.hover(null,0)})}on(e,i,n){this.el.addEventListener(e,i,n),this.off.push(()=>this.el.removeEventListener(e,i,n))}pos(e){let i=this.el.getBoundingClientRect();return{x:e.clientX-i.left,y:e.clientY-i.top}}wheel(e){if(!this.t.enabled())return;e.preventDefault();let{x:i}=this.pos(e);Math.abs(e.deltaX)>Math.abs(e.deltaY)?this.t.pan(this.t.viewEnd(),-e.deltaX):this.t.zoom(Math.exp(-e.deltaY*.002),i)}down(e){let i=this.pos(e);this.pointers.set(e.pointerId,i),this.el.setPointerCapture?.(e.pointerId),this.pointers.size===2?(this.drag=null,this.pinch=this.spread()):this.drag={x:i.x,end:this.t.viewEnd(),moved:!1}}move(e){let i=this.pos(e);if(this.pointers.has(e.pointerId)&&this.pointers.set(e.pointerId,i),this.pointers.size===2&&this.pinch>0){let n=this.spread();if(this.t.enabled()&&n>0){let r=[...this.pointers.values()].reduce((o,s)=>o+s.x,0)/2;this.t.zoom(n/this.pinch,r)}this.pinch=n;return}if(this.drag){let n=i.x-this.drag.x;Math.abs(n)>3&&(this.drag.moved=!0),this.drag.moved&&this.t.enabled()&&this.t.pan(this.drag.end,n)}this.t.hover(i.x,i.y)}up(e){let i=this.pos(e);this.drag&&!this.drag.moved&&this.pointers.size===1&&this.t.click(i.x,i.y),this.end(e)}end(e){this.pointers.delete(e.pointerId),this.drag=null,this.pointers.size<2&&(this.pinch=0)}spread(){let[e,i]=[...this.pointers.values()];return e&&i?Math.hypot(e.x-i.x,e.y-i.y):0}dispose(){for(let e of this.off)e()}};var L=class{constructor(e,i,n){this.host=e;this.opts=i;this.owner=n}update(e){this.opts={...this.opts,...e},this.host.redraw()}remove(){this.owner.removePriceLine(this)}};function ft(t,e){let i=t[t.length-1];if(!i||e.time>i.time){t.push(e);return}let n=0,r=t.length;for(;n<r;){let o=n+r>>1;t[o].time<e.time?n=o+1:r=o}t[n]?.time===e.time?t[n]=e:t.splice(n,0,e)}var z=class{constructor(e,i){this.host=e;this.opts=i;p(this,"points",[]);p(this,"lines",[]);p(this,"markers",[])}setData(e){this.points=[...e].sort((i,n)=>i.time-n.time),this.host.dataChanged()}update(e){ft(this.points,e),this.host.dataChanged()}data(){return this.points}times(){return this.points.map(e=>e.time)}setOptions(e){this.opts={...this.opts,...e},this.host.redraw()}get visible(){return this.opts.visible!==!1}addPriceLine(e){let i=new L(this.host,e,this);return this.lines.push(i),this.host.redraw(),i}removePriceLine(e){let i=this.lines.indexOf(e);i>=0&&this.lines.splice(i,1),this.host.redraw()}setMarkers(e){this.markers=[...e].sort((i,n)=>i.time-n.time),this.host.redraw()}priceToY(e){return this.host.priceToY(e)}yToPrice(e){return this.host.yToPrice(e)}},O=class extends z{constructor(){super(...arguments);p(this,"kind","candles")}span(i){return[i.low,i.high]}value(i){return i.close}},W=class extends z{constructor(){super(...arguments);p(this,"kind","line")}span(i){return[i.value,i.value]}value(i){return i.value}},F=class extends z{constructor(){super(...arguments);p(this,"kind","histogram")}span(i){let n=this.opts.base??0;return[Math.min(n,i.value),Math.max(n,i.value)]}value(i){return i.value}};var te=class{constructor(){p(this,"times",[]);p(this,"index",new Map)}rebuild(e){let i=new Set;for(let n of e)for(let r of n)i.add(r);this.times=[...i].sort((n,r)=>n-r),this.index=new Map(this.times.map((n,r)=>[n,r]))}get length(){return this.times.length}exact(e){return this.index.get(e)}step(){let e=this.times.length;return e>=2?this.times[e-1]-this.times[e-2]:6e4}toIndex(e){let i=this.times,n=i.length;if(n===0)return null;let r=this.index.get(e);if(r!==void 0)return r;if(e<i[0])return n>=2?(e-i[0])/(i[1]-i[0]):-1;if(e>i[n-1])return n-1+(e-i[n-1])/this.step();let o=0,s=n-1;for(;s-o>1;){let a=o+s>>1;i[a]<=e?o=a:s=a}return o+(e-i[o])/(i[s]-i[o])}toTime(e){let i=this.times,n=i.length;if(n===0)return null;let r=Math.round(e);return r>=0&&r<n?i[r]:r<0?i[0]+r*(n>=2?i[1]-i[0]:6e4):i[n-1]+(r-n+1)*this.step()}};var bt=1,gt=60,_=class{constructor(e,i={}){this.opts=i;p(this,"el");p(this,"canvas");p(this,"legendEl");p(this,"series",[]);p(this,"overlays",[]);p(this,"timeline",new te);p(this,"view");p(this,"scale",null);p(this,"hover",null);p(this,"clicks",new Set);p(this,"rangeSubs",new Set);p(this,"lastRange","");p(this,"raf",0);p(this,"resize");p(this,"host");p(this,"gestures");this.view={end:0,bw:i.barSpacing??8},this.el=document.createElement("div"),this.el.className="glot-chart",this.el.style.cssText="position:relative;width:100%;height:100%;overflow:hidden;touch-action:none",this.canvas=document.createElement("canvas"),this.canvas.style.cssText="position:absolute;inset:0;width:100%;height:100%;cursor:crosshair",this.canvas.setAttribute("role","img"),this.legendEl=document.createElement("div"),this.legendEl.className="glot-chart-legend",this.legendEl.hidden=i.legend===!1,this.el.append(this.canvas,this.legendEl),i.attributionLogo!==!1&&this.el.append(Se(i)),J(e.ownerDocument),e.append(this.el),this.host={dataChanged:()=>this.dataChanged(),redraw:()=>this.invalidate(),priceToY:n=>this.priceToY(n),yToPrice:n=>this.yToPrice(n)},this.gestures=new ee(this.canvas,{enabled:()=>this.opts.interactive!==!1,pan:(n,r)=>this.panTo(n-r/this.view.bw),viewEnd:()=>this.view.end,zoom:(n,r)=>this.zoomAt(n,r),hover:(n,r)=>this.setHover(n,r),click:(n,r)=>this.emitClick(n,r)}),this.resize=new ResizeObserver(()=>this.invalidate()),this.resize.observe(this.el)}addCandles(e={}){return this.add(new O(this.host,{lastPriceLine:!0,...e}))}addLine(e={}){return this.add(new W(this.host,e))}addHistogram(e={}){return this.add(new F(this.host,e))}add(e){return this.series.push(e),this.dataChanged(),e}removeSeries(e){this.series=this.series.filter(i=>i!==e),this.dataChanged()}addOverlay(e){return this.overlays.push(e),this.invalidate(),()=>{this.overlays=this.overlays.filter(i=>i!==e),this.invalidate()}}setOptions(e){let i=this.timeline.length;e.rightOffset!==void 0&&e.rightOffset!==this.opts.rightOffset&&i&&(this.view.end=i-1+e.rightOffset),e.barSpacing!==void 0&&(this.view.bw=me(e.barSpacing)),e.legend!==void 0&&(this.legendEl.hidden=e.legend===!1),this.opts={...this.opts,...e},this.invalidate()}options(){return{...this.opts,barSpacing:this.view.bw,rightOffset:this.opts.rightOffset??6}}plotSize(){let e=this.el.clientWidth-(this.opts.priceAxisWidth??72),i=this.el.clientHeight-(this.opts.timeAxisHeight??24);return{width:Math.max(0,e),height:Math.max(0,i)}}indexToX(e){return this.plotSize().width-(this.view.end-e+.5)*this.view.bw}xToIndex(e){return this.view.end+.5-(this.plotSize().width-e)/this.view.bw}timeToX(e){let i=this.timeline.toIndex(e);return i===null?null:this.indexToX(i)}xToTime(e){return this.timeline.toTime(this.xToIndex(e))}timeToIndex(e){return this.timeline.exact(e)??null}priceToY(e){let i=this.currentScale();return i?i.top+(i.hi-e)/(i.hi-i.lo)*i.inner:null}yToPrice(e){let i=this.currentScale();return i?i.hi-(e-i.top)/i.inner*(i.hi-i.lo):null}getVisibleIndexRange(){if(!this.timeline.length)return null;let e=this.plotSize().width;return{from:this.view.end-e/this.view.bw+1,to:this.view.end}}setVisibleIndexRange(e){let i=this.plotSize().width,n=Math.max(1,e.to-e.from+1);i>0&&(this.view.bw=me(i/n)),this.view.end=e.to,this.invalidate()}getVisibleRange(){let e=this.getVisibleIndexRange(),i=this.timeline.length;if(!e||!i)return null;let n=Math.min(i-1,Math.max(0,Math.ceil(e.from))),r=Math.min(i-1,Math.max(0,Math.floor(e.to)));return{from:this.timeline.times[n],to:this.timeline.times[r]}}setVisibleRange(e){let i=this.timeline.toIndex(e.from),n=this.timeline.toIndex(e.to);i===null||n===null||this.setVisibleIndexRange({from:i,to:n})}scrollToEnd(){this.view.end=Math.max(0,this.timeline.length-1)+(this.opts.rightOffset??6),this.invalidate()}fitContent(){let e=this.timeline.length;e&&this.setVisibleIndexRange({from:0,to:e-1})}onVisibleRangeChange(e){return this.rangeSubs.add(e),()=>this.rangeSubs.delete(e)}onClick(e){return this.clicks.add(e),()=>this.clicks.delete(e)}invalidate(){this.scale=null,cancelAnimationFrame(this.raf),this.raf=requestAnimationFrame(()=>this.draw())}dispose(){this.resize.disconnect(),this.gestures.dispose(),cancelAnimationFrame(this.raf),this.el.remove()}dataChanged(){let e=this.timeline.length,i=this.view.end>=e-1;this.timeline.rebuild(this.series.map(r=>r.times()));let n=this.timeline.length;e===0&&n>0?this.view.end=n-1+(this.opts.rightOffset??6):i&&n>e&&(this.view.end+=n-e),this.canvas.setAttribute("aria-label",`${n} bars`),this.invalidate()}panTo(e){let i=this.timeline.length,n=this.plotSize().width/this.view.bw;this.view.end=Math.min(i-1+n*.8,Math.max(Math.min(i-1,2),e)),this.invalidate()}zoomAt(e,i){let n=this.plotSize().width,r=this.xToIndex(Math.min(i,n)),o=me(this.view.bw*e);this.view.end=r-.5+(n-Math.min(i,n))/o,this.view.bw=o,this.invalidate()}setHover(e,i){let n=this.timeline.length;e===null||!n||e>this.plotSize().width?this.hover=null:this.hover={index:Math.round(this.xToIndex(e)-.5),y:i},this.invalidate()}emitClick(e,i){let n=Math.round(this.xToIndex(e)-.5),r=n>=0&&n<this.timeline.length,o={x:e,y:i,index:r?n:null,time:r?this.timeline.times[n]:null,price:this.yToPrice(i)};for(let s of this.clicks)s(o)}state(){let e=this.opts;return{width:this.el.clientWidth,height:this.el.clientHeight,axisW:e.priceAxisWidth??72,axisH:e.timeAxisHeight??24,view:this.view,timeline:this.timeline,series:this.series,overlays:this.overlays,theme:E(this.el,e.theme),axis:{grid:e.grid??"solid",timeVisible:e.timeVisible!==!1,secondsVisible:e.secondsVisible===!0,timeLabel:e.timeLabel??"UTC",priceDecimals:e.priceDecimals},hover:e.crosshair===!1?null:this.hover}}currentScale(){return this.timeline.length?(this.scale??(this.scale=he(this.state(),null)),this.scale):null}draw(){let e=window.devicePixelRatio||1,i=this.el.clientWidth,n=this.el.clientHeight;if(i===0||n===0)return;(this.canvas.width!==Math.round(i*e)||this.canvas.height!==Math.round(n*e))&&(this.canvas.width=Math.round(i*e),this.canvas.height=Math.round(n*e));let r=this.canvas.getContext("2d");if(!r)return;r.setTransform(e,0,0,e,0,0);let o=this.state();Q(this.el,o.theme),this.scale=he(o,this.scale),Be(r,o,this.scale),this.renderLegend(),this.emitRange()}renderLegend(){if(this.legendEl.hidden)return;let e=this.timeline.length,i=this.hover&&this.hover.index<e?this.hover.index:e-1,n=this.timeline.times[i];if(n===void 0){this.legendEl.textContent="";return}let r=[];for(let o of this.series){if(!o.visible)continue;let s=o.data().find(h=>h.time===n);if(!s)continue;let a=o.opts.priceDecimals??this.opts.priceDecimals??2,l=h=>y(h,a);if(o.kind==="candles"){let h=s;r.push(`O ${l(h.open)} H ${l(h.high)} L ${l(h.low)} C ${l(h.close)}`)}else o.opts.title&&r.push(`${o.opts.title} ${l(s.value)}`)}this.legendEl.textContent=r.join(" ")}emitRange(){let e=this.getVisibleRange(),i=e?`${e.from}:${e.to}`:"";if(i!==this.lastRange){this.lastRange=i;for(let n of this.rangeSubs)n(e)}}};function me(t){return Math.min(gt,Math.max(bt,t))}function Ve(t,e={}){return new _(t,e)}return je(vt);})();
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { GlotChart, createChart } from "./chart.js";
|
|
2
|
+
export { ATTRIBUTION_HREF, ATTRIBUTION_SRC } from "./attribution.js";
|
|
3
|
+
export { VERSION } from "./version.js";
|
|
4
|
+
export { THEMES, readTheme, type ChartTheme, type ThemeOption } from "./theme.js";
|
|
5
|
+
export { barsFromCsv } from "./csv.js";
|
|
6
|
+
export { bisect } from "./draw.js";
|
|
7
|
+
export * from "./scale.js";
|
|
8
|
+
export { resolveColor } from "./marks.js";
|
|
9
|
+
export type { Bar, ChartData, ChartOptions, FillSeries, LineSeries, ProgramColor, ShapeSeries, TradeMark, } from "./types.js";
|
|
10
|
+
export { TimeChart, createTimeChart } from "./series/time-chart";
|
|
11
|
+
export { PriceLine, CandleSeries, LineSeriesApi, HistogramSeries } from "./series/series";
|
|
12
|
+
export type { AutoscaleFn, CandleOptions, ClickInfo, HistogramOptions, LineOptions, LineStyleName, Marker, Overlay, PriceLineOptions, Range, SeriesOptions, TimeChartOptions, TimeValue, } from "./series/types";
|