aliencharts 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +94 -0
- package/dist/index.cjs +4910 -0
- package/dist/index.cjs.map +7 -0
- package/dist/index.js +4887 -0
- package/dist/index.js.map +7 -0
- package/package.json +51 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,4910 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/index.js
|
|
30
|
+
var index_exports = {};
|
|
31
|
+
__export(index_exports, {
|
|
32
|
+
ChartGrid: () => ChartGrid,
|
|
33
|
+
createMockCharts: () => createMockCharts,
|
|
34
|
+
createSeries: () => createSeries
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(index_exports);
|
|
37
|
+
|
|
38
|
+
// src/react/ChartGrid.jsx
|
|
39
|
+
var import_react9 = __toESM(require("react"), 1);
|
|
40
|
+
var import_react10 = require("@phosphor-icons/react");
|
|
41
|
+
|
|
42
|
+
// src/core/lodSeries.js
|
|
43
|
+
var DEFAULT_MAX_LEVELS = 18;
|
|
44
|
+
var toTypedArray = (value, Type) => {
|
|
45
|
+
if (value instanceof Type) return value;
|
|
46
|
+
if (ArrayBuffer.isView(value)) return new Type(value);
|
|
47
|
+
if (Array.isArray(value)) return new Type(value);
|
|
48
|
+
return new Type(0);
|
|
49
|
+
};
|
|
50
|
+
var lowerBound = (array, value) => {
|
|
51
|
+
let lo = 0;
|
|
52
|
+
let hi = array.length;
|
|
53
|
+
while (lo < hi) {
|
|
54
|
+
const mid = lo + hi >> 1;
|
|
55
|
+
if (array[mid] < value) lo = mid + 1;
|
|
56
|
+
else hi = mid;
|
|
57
|
+
}
|
|
58
|
+
return lo;
|
|
59
|
+
};
|
|
60
|
+
var upperBound = (array, value) => {
|
|
61
|
+
let lo = 0;
|
|
62
|
+
let hi = array.length;
|
|
63
|
+
while (lo < hi) {
|
|
64
|
+
const mid = lo + hi >> 1;
|
|
65
|
+
if (array[mid] <= value) lo = mid + 1;
|
|
66
|
+
else hi = mid;
|
|
67
|
+
}
|
|
68
|
+
return lo;
|
|
69
|
+
};
|
|
70
|
+
var pushUniqueSorted = (indices, index) => {
|
|
71
|
+
if (index < 0) return;
|
|
72
|
+
if (indices.includes(index)) return;
|
|
73
|
+
indices.push(index);
|
|
74
|
+
};
|
|
75
|
+
var buildLod = (rawX, rawY, bucketSize, startIndex = 0, endIndex = rawX.length) => {
|
|
76
|
+
if (bucketSize <= 1 || rawX.length <= bucketSize) {
|
|
77
|
+
return { x: rawX, y: rawY, bucketSize: 1 };
|
|
78
|
+
}
|
|
79
|
+
const alignedStart = Math.max(0, Math.floor(startIndex / bucketSize) * bucketSize);
|
|
80
|
+
const alignedEnd = Math.min(rawX.length, endIndex);
|
|
81
|
+
const estimated = Math.ceil((alignedEnd - alignedStart) / bucketSize) * 4;
|
|
82
|
+
const x = new Float64Array(estimated);
|
|
83
|
+
const y = new Float32Array(estimated);
|
|
84
|
+
let out = 0;
|
|
85
|
+
for (let start = alignedStart; start < alignedEnd; start += bucketSize) {
|
|
86
|
+
const end = Math.min(alignedEnd, start + bucketSize);
|
|
87
|
+
let minIndex = start;
|
|
88
|
+
let maxIndex = start;
|
|
89
|
+
for (let i = start + 1; i < end; i += 1) {
|
|
90
|
+
if (rawY[i] < rawY[minIndex]) minIndex = i;
|
|
91
|
+
if (rawY[i] > rawY[maxIndex]) maxIndex = i;
|
|
92
|
+
}
|
|
93
|
+
const indices = [];
|
|
94
|
+
pushUniqueSorted(indices, start);
|
|
95
|
+
pushUniqueSorted(indices, minIndex);
|
|
96
|
+
pushUniqueSorted(indices, maxIndex);
|
|
97
|
+
pushUniqueSorted(indices, end - 1);
|
|
98
|
+
indices.sort((a, b) => a - b);
|
|
99
|
+
for (let i = 0; i < indices.length; i += 1) {
|
|
100
|
+
const sourceIndex = indices[i];
|
|
101
|
+
x[out] = rawX[sourceIndex];
|
|
102
|
+
y[out] = rawY[sourceIndex];
|
|
103
|
+
out += 1;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
x: x.subarray(0, out),
|
|
108
|
+
y: y.subarray(0, out),
|
|
109
|
+
bucketSize
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
var concatTyped = (Type, left, right) => {
|
|
113
|
+
if (!left?.length) return right;
|
|
114
|
+
if (!right?.length) return left;
|
|
115
|
+
const out = new Type(left.length + right.length);
|
|
116
|
+
out.set(left, 0);
|
|
117
|
+
out.set(right, left.length);
|
|
118
|
+
return out;
|
|
119
|
+
};
|
|
120
|
+
var LineSeries = class {
|
|
121
|
+
constructor({ id, name, color, x, y, maxLevels = DEFAULT_MAX_LEVELS }) {
|
|
122
|
+
this.id = id;
|
|
123
|
+
this.name = name || id;
|
|
124
|
+
this.color = color || "#38bdf8";
|
|
125
|
+
this.maxLevels = maxLevels;
|
|
126
|
+
const initialX = toTypedArray(x, Float64Array);
|
|
127
|
+
const initialY = toTypedArray(y, Float32Array);
|
|
128
|
+
this._length = Math.min(initialX.length, initialY.length);
|
|
129
|
+
const capacity = Math.max(1, this._length);
|
|
130
|
+
this.rawX = new Float64Array(capacity);
|
|
131
|
+
this.rawY = new Float32Array(capacity);
|
|
132
|
+
this.rawX.set(initialX.subarray(0, this._length));
|
|
133
|
+
this.rawY.set(initialY.subarray(0, this._length));
|
|
134
|
+
this.levels = [];
|
|
135
|
+
this.rebuildLevels();
|
|
136
|
+
}
|
|
137
|
+
get length() {
|
|
138
|
+
return this._length;
|
|
139
|
+
}
|
|
140
|
+
append(xValues, yValues) {
|
|
141
|
+
const nextX = toTypedArray(xValues, Float64Array);
|
|
142
|
+
const nextY = toTypedArray(yValues, Float32Array);
|
|
143
|
+
const appendLength = Math.min(nextX.length, nextY.length);
|
|
144
|
+
if (appendLength === 0) return;
|
|
145
|
+
const currentLength = this.length;
|
|
146
|
+
this.ensureRawCapacity(currentLength + appendLength);
|
|
147
|
+
this.rawX.set(nextX.subarray(0, appendLength), currentLength);
|
|
148
|
+
this.rawY.set(nextY.subarray(0, appendLength), currentLength);
|
|
149
|
+
this._length = currentLength + appendLength;
|
|
150
|
+
this.markLevelsDirty(currentLength);
|
|
151
|
+
}
|
|
152
|
+
rebuildLevels() {
|
|
153
|
+
const rawX = this.rawX.subarray(0, this.length);
|
|
154
|
+
const rawY = this.rawY.subarray(0, this.length);
|
|
155
|
+
this.levels = [{ x: rawX, y: rawY, bucketSize: 1 }];
|
|
156
|
+
let bucketSize = 4;
|
|
157
|
+
while (this.levels.length < this.maxLevels && bucketSize < Math.max(8, rawX.length)) {
|
|
158
|
+
this.levels.push(buildLod(rawX, rawY, bucketSize));
|
|
159
|
+
bucketSize *= 4;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
ensureRawCapacity(requiredLength) {
|
|
163
|
+
if (requiredLength <= this.rawX.length && requiredLength <= this.rawY.length) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
const nextCapacity = Math.max(requiredLength, Math.ceil(this.rawX.length * 1.5));
|
|
167
|
+
const rawX = new Float64Array(nextCapacity);
|
|
168
|
+
const rawY = new Float32Array(nextCapacity);
|
|
169
|
+
rawX.set(this.rawX.subarray(0, this.length));
|
|
170
|
+
rawY.set(this.rawY.subarray(0, this.length));
|
|
171
|
+
this.rawX = rawX;
|
|
172
|
+
this.rawY = rawY;
|
|
173
|
+
}
|
|
174
|
+
markLevelsDirty(previousLength) {
|
|
175
|
+
const rawX = this.rawX.subarray(0, this.length);
|
|
176
|
+
const rawY = this.rawY.subarray(0, this.length);
|
|
177
|
+
this.levels[0] = { x: rawX, y: rawY, bucketSize: 1 };
|
|
178
|
+
let bucketSize = this.levels.length > 0 ? this.levels[this.levels.length - 1].bucketSize * 4 : 4;
|
|
179
|
+
while (this.levels.length < this.maxLevels && bucketSize < Math.max(8, rawX.length)) {
|
|
180
|
+
this.levels.push(buildLod(rawX, rawY, bucketSize));
|
|
181
|
+
bucketSize *= 4;
|
|
182
|
+
}
|
|
183
|
+
for (let i = 1; i < this.levels.length; i += 1) {
|
|
184
|
+
const level = this.levels[i];
|
|
185
|
+
const dirtyRawStart = Math.floor(previousLength / level.bucketSize) * level.bucketSize;
|
|
186
|
+
level.dirtyFrom = Math.min(level.dirtyFrom ?? dirtyRawStart, dirtyRawStart);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
ensureLevel(index) {
|
|
190
|
+
const level = this.levels[index];
|
|
191
|
+
if (!level || index === 0 || level.dirtyFrom == null) return level;
|
|
192
|
+
const rawX = this.rawX.subarray(0, this.length);
|
|
193
|
+
const rawY = this.rawY.subarray(0, this.length);
|
|
194
|
+
const dirtyRawStart = Math.floor(level.dirtyFrom / level.bucketSize) * level.bucketSize;
|
|
195
|
+
const cutoffX = rawX[dirtyRawStart] ?? rawX[0] ?? 0;
|
|
196
|
+
const keepCount = lowerBound(level.x, cutoffX);
|
|
197
|
+
const tail = buildLod(rawX, rawY, level.bucketSize, dirtyRawStart, rawX.length);
|
|
198
|
+
this.levels[index] = {
|
|
199
|
+
x: concatTyped(Float64Array, level.x.subarray(0, keepCount), tail.x),
|
|
200
|
+
y: concatTyped(Float32Array, level.y.subarray(0, keepCount), tail.y),
|
|
201
|
+
bucketSize: level.bucketSize
|
|
202
|
+
};
|
|
203
|
+
return this.levels[index];
|
|
204
|
+
}
|
|
205
|
+
selectLevel(xMin, xMax, pixelWidth, targetPointsPerPixel = 2.5) {
|
|
206
|
+
const rawX = this.levels[0].x;
|
|
207
|
+
if (rawX.length === 0) return this.levels[0];
|
|
208
|
+
const from = lowerBound(rawX, xMin);
|
|
209
|
+
const to = upperBound(rawX, xMax);
|
|
210
|
+
const visibleRawPoints = Math.max(0, to - from);
|
|
211
|
+
const targetPoints = Math.max(32, pixelWidth * targetPointsPerPixel);
|
|
212
|
+
const desiredBucket = Math.max(1, visibleRawPoints / targetPoints);
|
|
213
|
+
let selectedIndex = 0;
|
|
214
|
+
for (let i = 1; i < this.levels.length; i += 1) {
|
|
215
|
+
if (this.levels[i].bucketSize <= desiredBucket) {
|
|
216
|
+
selectedIndex = i;
|
|
217
|
+
} else {
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return this.ensureLevel(selectedIndex);
|
|
222
|
+
}
|
|
223
|
+
getVisiblePoints(xMin, xMax, pixelWidth) {
|
|
224
|
+
const level = this.selectLevel(xMin, xMax, pixelWidth);
|
|
225
|
+
const start = Math.max(0, lowerBound(level.x, xMin) - 1);
|
|
226
|
+
const end = Math.min(level.x.length, upperBound(level.x, xMax) + 1);
|
|
227
|
+
return {
|
|
228
|
+
x: level.x.subarray(start, end),
|
|
229
|
+
y: level.y.subarray(start, end),
|
|
230
|
+
bucketSize: level.bucketSize,
|
|
231
|
+
pointCount: Math.max(0, end - start)
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
var createSeries = (options) => new LineSeries(options);
|
|
236
|
+
|
|
237
|
+
// src/core/mockData.js
|
|
238
|
+
var palette = [
|
|
239
|
+
"#38bdf8",
|
|
240
|
+
"#22c55e",
|
|
241
|
+
"#f59e0b",
|
|
242
|
+
"#ef4444",
|
|
243
|
+
"#a855f7",
|
|
244
|
+
"#14b8a6"
|
|
245
|
+
];
|
|
246
|
+
var createRandom = (seed) => {
|
|
247
|
+
let value = seed >>> 0;
|
|
248
|
+
return () => {
|
|
249
|
+
value = value * 1664525 + 1013904223 >>> 0;
|
|
250
|
+
return value / 4294967296;
|
|
251
|
+
};
|
|
252
|
+
};
|
|
253
|
+
var makeSeries = ({ chartIndex, seriesIndex, pointCount }) => {
|
|
254
|
+
const x = new Float64Array(pointCount);
|
|
255
|
+
const y = new Float32Array(pointCount);
|
|
256
|
+
const random = createRandom((chartIndex + 1) * 1009 + seriesIndex * 9176);
|
|
257
|
+
const baseline = 15 + random() * 45 + seriesIndex * 4;
|
|
258
|
+
const waveA = 8e-4 + random() * 4e-3;
|
|
259
|
+
const waveB = 6e-3 + random() * 0.03;
|
|
260
|
+
const waveC = 5e-5 + random() * 6e-4;
|
|
261
|
+
const amplitudeA = 0.015 + random() * 0.09;
|
|
262
|
+
const amplitudeB = 5e-3 + random() * 0.04;
|
|
263
|
+
const trend = (random() - 0.5) * 4e-3;
|
|
264
|
+
const noise = 4e-3 + random() * 0.025;
|
|
265
|
+
const spikeInterval = 180 + Math.floor(random() * 900);
|
|
266
|
+
const spikeMagnitude = 0.12 + random() * 0.7;
|
|
267
|
+
let value = baseline;
|
|
268
|
+
for (let i = 0; i < pointCount; i += 1) {
|
|
269
|
+
x[i] = i;
|
|
270
|
+
const spike = (i + chartIndex * 13 + seriesIndex * 31) % spikeInterval === 0 ? spikeMagnitude * (random() > 0.45 ? 1 : -1) : 0;
|
|
271
|
+
value += Math.sin(i * waveA + chartIndex) * amplitudeA + Math.cos(i * waveB + seriesIndex) * amplitudeB + Math.sin(i * waveC) * amplitudeA * 0.35 + trend + (random() - 0.5) * noise + spike;
|
|
272
|
+
y[i] = value;
|
|
273
|
+
}
|
|
274
|
+
return createSeries({
|
|
275
|
+
id: `chart-${chartIndex}-series-${seriesIndex}`,
|
|
276
|
+
name: `Run ${seriesIndex + 1}`,
|
|
277
|
+
color: palette[(chartIndex + seriesIndex) % palette.length],
|
|
278
|
+
x,
|
|
279
|
+
y
|
|
280
|
+
});
|
|
281
|
+
};
|
|
282
|
+
var createMockCharts = ({
|
|
283
|
+
chartCount = 50,
|
|
284
|
+
seriesPerChart = 2,
|
|
285
|
+
pointCount = 5e5
|
|
286
|
+
} = {}) => {
|
|
287
|
+
return Array.from({ length: chartCount }, (_, chartIndex) => ({
|
|
288
|
+
id: `metric-${chartIndex + 1}`,
|
|
289
|
+
title: `metric_${String(chartIndex + 1).padStart(2, "0")}`,
|
|
290
|
+
series: Array.from(
|
|
291
|
+
{ length: seriesPerChart },
|
|
292
|
+
(_2, seriesIndex) => makeSeries({ chartIndex, seriesIndex, pointCount })
|
|
293
|
+
)
|
|
294
|
+
}));
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
// src/react/ChartToolbar.jsx
|
|
298
|
+
var import_react = __toESM(require("react"), 1);
|
|
299
|
+
var import_react2 = require("@phosphor-icons/react");
|
|
300
|
+
function ToolbarAction({
|
|
301
|
+
title,
|
|
302
|
+
hotkey,
|
|
303
|
+
children,
|
|
304
|
+
onClick,
|
|
305
|
+
active = false,
|
|
306
|
+
className = ""
|
|
307
|
+
}) {
|
|
308
|
+
return /* @__PURE__ */ import_react.default.createElement(
|
|
309
|
+
"button",
|
|
310
|
+
{
|
|
311
|
+
type: "button",
|
|
312
|
+
title,
|
|
313
|
+
"aria-label": title,
|
|
314
|
+
className: `relative inline-flex size-6 items-center justify-center rounded-sm text-foreground hover:bg-accent hover:text-accent-foreground disabled:pointer-events-none disabled:opacity-50 ${className} ${active ? "bg-primary/15 text-primary ring-1 ring-primary/40" : ""}`,
|
|
315
|
+
onPointerDown: (event) => {
|
|
316
|
+
event.preventDefault();
|
|
317
|
+
event.stopPropagation();
|
|
318
|
+
},
|
|
319
|
+
onClick: (event) => {
|
|
320
|
+
event.preventDefault();
|
|
321
|
+
event.stopPropagation();
|
|
322
|
+
onClick?.();
|
|
323
|
+
}
|
|
324
|
+
},
|
|
325
|
+
children,
|
|
326
|
+
hotkey ? /* @__PURE__ */ import_react.default.createElement("span", { className: "pointer-events-none absolute left-full top-1/2 -translate-y-1/2 text-[10px] font-semibold leading-none text-foreground/50" }, hotkey) : null
|
|
327
|
+
);
|
|
328
|
+
}
|
|
329
|
+
function ChartToolbar({
|
|
330
|
+
isFullscreen = false,
|
|
331
|
+
onFullscreenToggle,
|
|
332
|
+
onReset,
|
|
333
|
+
onRectangleZoomToggle,
|
|
334
|
+
rectangleZoomActive = false,
|
|
335
|
+
onMovingAverageToggle,
|
|
336
|
+
movingAverageActive = false,
|
|
337
|
+
activeDrawingTool = null,
|
|
338
|
+
onDrawingToolToggle,
|
|
339
|
+
hasDrawings = false,
|
|
340
|
+
onClearDrawingsRequest
|
|
341
|
+
}) {
|
|
342
|
+
return /* @__PURE__ */ import_react.default.createElement("div", { className: "absolute left-2 top-12 z-30 flex flex-col gap-0.5 rounded-sm bg-background/80 p-0 pr-3 text-foreground shadow-sm backdrop-blur" }, /* @__PURE__ */ import_react.default.createElement(
|
|
343
|
+
ToolbarAction,
|
|
344
|
+
{
|
|
345
|
+
title: isFullscreen ? "Exit fullscreen" : "Maximize chart",
|
|
346
|
+
hotkey: "F",
|
|
347
|
+
onClick: onFullscreenToggle
|
|
348
|
+
},
|
|
349
|
+
isFullscreen ? /* @__PURE__ */ import_react.default.createElement(import_react2.ArrowsInIcon, { size: 16, weight: "bold" }) : /* @__PURE__ */ import_react.default.createElement(import_react2.ArrowsOutIcon, { size: 16, weight: "bold" })
|
|
350
|
+
), /* @__PURE__ */ import_react.default.createElement(ToolbarAction, { title: "Reset chart", hotkey: "R", onClick: onReset }, /* @__PURE__ */ import_react.default.createElement(import_react2.ArrowCounterClockwiseIcon, { size: 16, weight: "bold" })), /* @__PURE__ */ import_react.default.createElement(
|
|
351
|
+
ToolbarAction,
|
|
352
|
+
{
|
|
353
|
+
title: "Rectangle zoom",
|
|
354
|
+
hotkey: "Z",
|
|
355
|
+
onClick: onRectangleZoomToggle,
|
|
356
|
+
active: rectangleZoomActive
|
|
357
|
+
},
|
|
358
|
+
/* @__PURE__ */ import_react.default.createElement(import_react2.MagnifyingGlassPlusIcon, { size: 16, weight: "bold" })
|
|
359
|
+
), hasDrawings ? /* @__PURE__ */ import_react.default.createElement(
|
|
360
|
+
ToolbarAction,
|
|
361
|
+
{
|
|
362
|
+
title: "Clear drawings",
|
|
363
|
+
className: "text-orange-500 dark:text-orange-300 dark:hover:text-orange-300",
|
|
364
|
+
onClick: onClearDrawingsRequest
|
|
365
|
+
},
|
|
366
|
+
/* @__PURE__ */ import_react.default.createElement(import_react2.BroomIcon, { size: 16, weight: "bold" })
|
|
367
|
+
) : null, /* @__PURE__ */ import_react.default.createElement("div", { className: "my-1 h-px w-full" }), /* @__PURE__ */ import_react.default.createElement(
|
|
368
|
+
ToolbarAction,
|
|
369
|
+
{
|
|
370
|
+
title: "Draw trendline",
|
|
371
|
+
hotkey: "T",
|
|
372
|
+
onClick: () => onDrawingToolToggle?.("trendline"),
|
|
373
|
+
active: activeDrawingTool === "trendline"
|
|
374
|
+
},
|
|
375
|
+
/* @__PURE__ */ import_react.default.createElement(import_react2.MinusIcon, { className: "-rotate-45", size: 16, weight: "bold" })
|
|
376
|
+
), /* @__PURE__ */ import_react.default.createElement(
|
|
377
|
+
ToolbarAction,
|
|
378
|
+
{
|
|
379
|
+
title: "Draw horizontal line",
|
|
380
|
+
hotkey: "H",
|
|
381
|
+
onClick: () => onDrawingToolToggle?.("hline"),
|
|
382
|
+
active: activeDrawingTool === "hline"
|
|
383
|
+
},
|
|
384
|
+
/* @__PURE__ */ import_react.default.createElement(import_react2.MinusIcon, { size: 16, weight: "bold" })
|
|
385
|
+
), /* @__PURE__ */ import_react.default.createElement(
|
|
386
|
+
ToolbarAction,
|
|
387
|
+
{
|
|
388
|
+
title: "Draw vertical line",
|
|
389
|
+
hotkey: "V",
|
|
390
|
+
onClick: () => onDrawingToolToggle?.("vline"),
|
|
391
|
+
active: activeDrawingTool === "vline"
|
|
392
|
+
},
|
|
393
|
+
/* @__PURE__ */ import_react.default.createElement(import_react2.MinusIcon, { className: "rotate-90", size: 16, weight: "bold" })
|
|
394
|
+
), /* @__PURE__ */ import_react.default.createElement(
|
|
395
|
+
ToolbarAction,
|
|
396
|
+
{
|
|
397
|
+
title: "Place pin",
|
|
398
|
+
hotkey: "P",
|
|
399
|
+
onClick: () => onDrawingToolToggle?.("pin"),
|
|
400
|
+
active: activeDrawingTool === "pin"
|
|
401
|
+
},
|
|
402
|
+
/* @__PURE__ */ import_react.default.createElement(import_react2.MapPinIcon, { size: 16, weight: "bold" })
|
|
403
|
+
), /* @__PURE__ */ import_react.default.createElement(
|
|
404
|
+
ToolbarAction,
|
|
405
|
+
{
|
|
406
|
+
title: "Toggle moving average",
|
|
407
|
+
hotkey: "M",
|
|
408
|
+
onClick: onMovingAverageToggle,
|
|
409
|
+
active: movingAverageActive
|
|
410
|
+
},
|
|
411
|
+
/* @__PURE__ */ import_react.default.createElement(import_react2.WaveSineIcon, { size: 16, weight: "bold" })
|
|
412
|
+
));
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
// src/react/DrawingOptionsToolbar.jsx
|
|
416
|
+
var import_react3 = __toESM(require("react"), 1);
|
|
417
|
+
|
|
418
|
+
// src/react/drawingUtils.js
|
|
419
|
+
var DEFAULT_DRAWING_COLOR = "#60a5fa";
|
|
420
|
+
var DRAWING_HIT_DISTANCE = 8;
|
|
421
|
+
var DRAWING_HANDLE_RADIUS = 4;
|
|
422
|
+
var DRAWING_HANDLE_HIT_DISTANCE = 10;
|
|
423
|
+
var PIN_HIT_DISTANCE = 14;
|
|
424
|
+
var DRAWING_TOOLS = /* @__PURE__ */ new Set(["trendline", "hline", "vline", "pin"]);
|
|
425
|
+
var getDrawingStyle = (drawing) => ({
|
|
426
|
+
color: drawing?.style?.color || DEFAULT_DRAWING_COLOR,
|
|
427
|
+
lineWidth: Number.isFinite(drawing?.style?.lineWidth) ? drawing.style.lineWidth : 2,
|
|
428
|
+
dashPattern: Array.isArray(drawing?.style?.dashPattern) ? drawing.style.dashPattern : [],
|
|
429
|
+
extendLeft: Boolean(drawing?.style?.extendLeft),
|
|
430
|
+
extendRight: drawing?.style?.extendRight !== false,
|
|
431
|
+
text: typeof drawing?.style?.text === "string" ? drawing.style.text : ""
|
|
432
|
+
});
|
|
433
|
+
var getDrawingsForChart = (drawings, chartId) => Array.isArray(drawings) ? drawings.filter((drawing) => drawing?.chartId === chartId) : [];
|
|
434
|
+
var getDefaultDrawingStyle = (type) => ({
|
|
435
|
+
color: DEFAULT_DRAWING_COLOR,
|
|
436
|
+
lineWidth: 2,
|
|
437
|
+
dashPattern: [],
|
|
438
|
+
extendLeft: false,
|
|
439
|
+
extendRight: type !== "vline",
|
|
440
|
+
text: ""
|
|
441
|
+
});
|
|
442
|
+
var createDrawing = ({
|
|
443
|
+
chartId,
|
|
444
|
+
type,
|
|
445
|
+
start,
|
|
446
|
+
end,
|
|
447
|
+
createDrawingId
|
|
448
|
+
}) => {
|
|
449
|
+
const id = createDrawingId?.({ chartId, type }) || `${chartId}-drawing-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
450
|
+
return {
|
|
451
|
+
id,
|
|
452
|
+
chartId,
|
|
453
|
+
type,
|
|
454
|
+
start,
|
|
455
|
+
end,
|
|
456
|
+
createdAt: Date.now(),
|
|
457
|
+
style: getDefaultDrawingStyle(type)
|
|
458
|
+
};
|
|
459
|
+
};
|
|
460
|
+
var createDraftDrawing = ({ chartId, type, start, end }) => ({
|
|
461
|
+
id: "__draft__",
|
|
462
|
+
chartId,
|
|
463
|
+
type,
|
|
464
|
+
start,
|
|
465
|
+
end,
|
|
466
|
+
createdAt: Date.now(),
|
|
467
|
+
style: getDefaultDrawingStyle(type)
|
|
468
|
+
});
|
|
469
|
+
var getDrawingGeometry = ({ drawing, layout, projectPoint }) => {
|
|
470
|
+
if (!drawing?.start || !drawing?.end) return null;
|
|
471
|
+
const start = projectPoint(drawing.start, layout);
|
|
472
|
+
const end = projectPoint(drawing.end, layout);
|
|
473
|
+
const style = getDrawingStyle(drawing);
|
|
474
|
+
let lineStart = start;
|
|
475
|
+
let lineEnd = end;
|
|
476
|
+
if (drawing.type === "pin") {
|
|
477
|
+
return { start, end: start, lineStart: start, lineEnd: start, style };
|
|
478
|
+
}
|
|
479
|
+
if (drawing.type === "hline") {
|
|
480
|
+
const lineEndX = Math.abs(end.x - start.x) > 1e-6 ? end.x : layout.plot.x + layout.plot.width;
|
|
481
|
+
lineStart = {
|
|
482
|
+
x: style.extendRight ? layout.plot.x : start.x,
|
|
483
|
+
y: start.y
|
|
484
|
+
};
|
|
485
|
+
lineEnd = {
|
|
486
|
+
x: style.extendRight ? layout.plot.x + layout.plot.width : lineEndX,
|
|
487
|
+
y: start.y
|
|
488
|
+
};
|
|
489
|
+
} else if (drawing.type === "vline") {
|
|
490
|
+
lineStart = {
|
|
491
|
+
x: start.x,
|
|
492
|
+
y: layout.plot.y
|
|
493
|
+
};
|
|
494
|
+
lineEnd = {
|
|
495
|
+
x: start.x,
|
|
496
|
+
y: layout.plot.y + layout.plot.height
|
|
497
|
+
};
|
|
498
|
+
} else if (drawing.type === "trendline") {
|
|
499
|
+
const dx = end.x - start.x;
|
|
500
|
+
const dy = end.y - start.y;
|
|
501
|
+
if (Math.abs(dx) > 1e-6) {
|
|
502
|
+
if (style.extendLeft) {
|
|
503
|
+
const leftX = layout.plot.x;
|
|
504
|
+
lineStart = {
|
|
505
|
+
x: leftX,
|
|
506
|
+
y: start.y + dy / dx * (leftX - start.x)
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
if (style.extendRight) {
|
|
510
|
+
const rightX = layout.plot.x + layout.plot.width;
|
|
511
|
+
lineEnd = {
|
|
512
|
+
x: rightX,
|
|
513
|
+
y: start.y + dy / dx * (rightX - start.x)
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
return { start, end, lineStart, lineEnd, style };
|
|
519
|
+
};
|
|
520
|
+
var distanceToSegment = (point, start, end) => {
|
|
521
|
+
const dx = end.x - start.x;
|
|
522
|
+
const dy = end.y - start.y;
|
|
523
|
+
if (dx === 0 && dy === 0) {
|
|
524
|
+
return Math.hypot(point.x - start.x, point.y - start.y);
|
|
525
|
+
}
|
|
526
|
+
const t = Math.max(
|
|
527
|
+
0,
|
|
528
|
+
Math.min(
|
|
529
|
+
1,
|
|
530
|
+
((point.x - start.x) * dx + (point.y - start.y) * dy) / (dx * dx + dy * dy)
|
|
531
|
+
)
|
|
532
|
+
);
|
|
533
|
+
return Math.hypot(point.x - (start.x + t * dx), point.y - (start.y + t * dy));
|
|
534
|
+
};
|
|
535
|
+
var hitTestDrawing = ({ point, drawing, layout, projectPoint }) => {
|
|
536
|
+
const geometry = getDrawingGeometry({
|
|
537
|
+
drawing,
|
|
538
|
+
layout,
|
|
539
|
+
projectPoint
|
|
540
|
+
});
|
|
541
|
+
if (!geometry) return null;
|
|
542
|
+
if (drawing.type !== "pin" && Math.hypot(point.x - geometry.start.x, point.y - geometry.start.y) <= DRAWING_HANDLE_HIT_DISTANCE) {
|
|
543
|
+
return { drawing, endpoint: "start" };
|
|
544
|
+
}
|
|
545
|
+
if (drawing.type === "pin" && Math.hypot(point.x - geometry.start.x, point.y - geometry.start.y) <= PIN_HIT_DISTANCE) {
|
|
546
|
+
return { drawing, endpoint: "move" };
|
|
547
|
+
}
|
|
548
|
+
if (drawing.type === "trendline" && Math.hypot(point.x - geometry.end.x, point.y - geometry.end.y) <= DRAWING_HANDLE_HIT_DISTANCE) {
|
|
549
|
+
return { drawing, endpoint: "end" };
|
|
550
|
+
}
|
|
551
|
+
const distance = distanceToSegment(point, geometry.lineStart, geometry.lineEnd);
|
|
552
|
+
return distance <= DRAWING_HIT_DISTANCE ? { drawing, endpoint: null } : null;
|
|
553
|
+
};
|
|
554
|
+
var updateDrawingById = (drawings, drawingId, updater) => (Array.isArray(drawings) ? drawings : []).map(
|
|
555
|
+
(drawing) => drawing?.id === drawingId ? updater(drawing) : drawing
|
|
556
|
+
);
|
|
557
|
+
var removeDrawingById = (drawings, drawingId) => (Array.isArray(drawings) ? drawings : []).filter(
|
|
558
|
+
(drawing) => drawing?.id !== drawingId
|
|
559
|
+
);
|
|
560
|
+
|
|
561
|
+
// src/react/DrawingOptionsToolbar.jsx
|
|
562
|
+
var isHexColor = (color) => /^#[0-9a-f]{6}$/i.test(String(color || ""));
|
|
563
|
+
var stopEvent = (event) => {
|
|
564
|
+
event.stopPropagation();
|
|
565
|
+
};
|
|
566
|
+
var stopAndPreventEvent = (event) => {
|
|
567
|
+
event.preventDefault();
|
|
568
|
+
event.stopPropagation();
|
|
569
|
+
};
|
|
570
|
+
function DrawingOptionsToolbar({
|
|
571
|
+
drawing,
|
|
572
|
+
style,
|
|
573
|
+
onToggleExtend,
|
|
574
|
+
onColorChange,
|
|
575
|
+
onTextChange
|
|
576
|
+
}) {
|
|
577
|
+
const colorInputRef = (0, import_react3.useRef)(null);
|
|
578
|
+
if (!drawing) return null;
|
|
579
|
+
const drawingStyle = getDrawingStyle(drawing);
|
|
580
|
+
const color = isHexColor(drawingStyle.color) ? drawingStyle.color : DEFAULT_DRAWING_COLOR;
|
|
581
|
+
const canExtend = drawing.type === "trendline" || drawing.type === "hline";
|
|
582
|
+
const canEditText = drawing.type === "pin";
|
|
583
|
+
return /* @__PURE__ */ import_react3.default.createElement(
|
|
584
|
+
"div",
|
|
585
|
+
{
|
|
586
|
+
className: "pointer-events-auto absolute z-40 flex items-center justify-end gap-1 rounded-sm bg-background/85 p-1 text-xs text-foreground shadow-sm backdrop-blur",
|
|
587
|
+
style,
|
|
588
|
+
onPointerDown: stopEvent,
|
|
589
|
+
onClick: (event) => event.stopPropagation()
|
|
590
|
+
},
|
|
591
|
+
canExtend ? /* @__PURE__ */ import_react3.default.createElement(
|
|
592
|
+
"button",
|
|
593
|
+
{
|
|
594
|
+
type: "button",
|
|
595
|
+
title: "Extend line",
|
|
596
|
+
"aria-label": "Extend line",
|
|
597
|
+
className: `h-6 rounded-sm px-2 text-[11px] font-semibold leading-none hover:bg-accent hover:text-accent-foreground ${drawingStyle.extendRight ? "bg-primary/15 text-primary ring-1 ring-primary/40" : "text-foreground/80"}`,
|
|
598
|
+
onPointerDown: stopAndPreventEvent,
|
|
599
|
+
onClick: (event) => {
|
|
600
|
+
event.preventDefault();
|
|
601
|
+
event.stopPropagation();
|
|
602
|
+
onToggleExtend?.();
|
|
603
|
+
}
|
|
604
|
+
},
|
|
605
|
+
"Ext"
|
|
606
|
+
) : null,
|
|
607
|
+
canEditText ? /* @__PURE__ */ import_react3.default.createElement(
|
|
608
|
+
"input",
|
|
609
|
+
{
|
|
610
|
+
type: "text",
|
|
611
|
+
value: drawingStyle.text,
|
|
612
|
+
placeholder: "Text",
|
|
613
|
+
title: "Pin text",
|
|
614
|
+
className: "h-6 w-24 rounded-sm border border-border/50 bg-background/70 px-1.5 text-xs",
|
|
615
|
+
onPointerDown: stopEvent,
|
|
616
|
+
onClick: stopEvent,
|
|
617
|
+
onChange: (event) => onTextChange?.(event.target.value)
|
|
618
|
+
}
|
|
619
|
+
) : null,
|
|
620
|
+
/* @__PURE__ */ import_react3.default.createElement(
|
|
621
|
+
"button",
|
|
622
|
+
{
|
|
623
|
+
type: "button",
|
|
624
|
+
title: "Line color",
|
|
625
|
+
"aria-label": "Line color",
|
|
626
|
+
className: "size-6 rounded-sm border border-border/70 shadow-sm",
|
|
627
|
+
style: { backgroundColor: color },
|
|
628
|
+
onPointerDown: stopAndPreventEvent,
|
|
629
|
+
onClick: (event) => {
|
|
630
|
+
event.preventDefault();
|
|
631
|
+
event.stopPropagation();
|
|
632
|
+
if (typeof colorInputRef.current?.showPicker === "function") {
|
|
633
|
+
colorInputRef.current.showPicker();
|
|
634
|
+
return;
|
|
635
|
+
}
|
|
636
|
+
colorInputRef.current?.click();
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
),
|
|
640
|
+
/* @__PURE__ */ import_react3.default.createElement(
|
|
641
|
+
"input",
|
|
642
|
+
{
|
|
643
|
+
ref: colorInputRef,
|
|
644
|
+
type: "color",
|
|
645
|
+
value: color,
|
|
646
|
+
tabIndex: -1,
|
|
647
|
+
className: "fixed left-[-1000px] top-[-1000px] size-px opacity-0",
|
|
648
|
+
style: { pointerEvents: "none" },
|
|
649
|
+
onPointerDown: (event) => event.stopPropagation(),
|
|
650
|
+
onChange: (event) => onColorChange?.(event.target.value)
|
|
651
|
+
}
|
|
652
|
+
)
|
|
653
|
+
);
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
// src/react/DrawingOverlay.jsx
|
|
657
|
+
var import_react4 = __toESM(require("react"), 1);
|
|
658
|
+
var getClipId = (chartId) => `drawing-clip-${String(chartId).replace(/[^a-zA-Z0-9_-]/g, "_")}`;
|
|
659
|
+
function PinDrawing({ drawing, geometry, selected }) {
|
|
660
|
+
const text = geometry.style.text.trim();
|
|
661
|
+
return /* @__PURE__ */ import_react4.default.createElement("g", { opacity: drawing.id === "__draft__" ? 0.72 : 1 }, /* @__PURE__ */ import_react4.default.createElement("g", { transform: `translate(${geometry.start.x} ${geometry.start.y})` }, /* @__PURE__ */ import_react4.default.createElement(
|
|
662
|
+
"path",
|
|
663
|
+
{
|
|
664
|
+
d: "M0 -11 C-6 -11 -10 -6 -10 -1 C-10 6 -2 12 0 15 C2 12 10 6 10 -1 C10 -6 6 -11 0 -11 Z",
|
|
665
|
+
fill: geometry.style.color,
|
|
666
|
+
stroke: "var(--background, #ffffff)",
|
|
667
|
+
strokeWidth: "1.5"
|
|
668
|
+
}
|
|
669
|
+
), /* @__PURE__ */ import_react4.default.createElement("circle", { cx: "0", cy: "-2", r: "3", fill: "var(--background, #ffffff)", opacity: "0.9" })), text ? /* @__PURE__ */ import_react4.default.createElement(
|
|
670
|
+
"text",
|
|
671
|
+
{
|
|
672
|
+
x: geometry.start.x + 14,
|
|
673
|
+
y: geometry.start.y,
|
|
674
|
+
fill: geometry.style.color,
|
|
675
|
+
stroke: "var(--background, #ffffff)",
|
|
676
|
+
strokeWidth: "3",
|
|
677
|
+
paintOrder: "stroke",
|
|
678
|
+
fontSize: "12",
|
|
679
|
+
fontWeight: "600",
|
|
680
|
+
dominantBaseline: "middle"
|
|
681
|
+
},
|
|
682
|
+
text
|
|
683
|
+
) : null, selected ? /* @__PURE__ */ import_react4.default.createElement(
|
|
684
|
+
"circle",
|
|
685
|
+
{
|
|
686
|
+
cx: geometry.start.x,
|
|
687
|
+
cy: geometry.start.y,
|
|
688
|
+
r: DRAWING_HANDLE_RADIUS,
|
|
689
|
+
fill: geometry.style.color,
|
|
690
|
+
stroke: "var(--background, #ffffff)",
|
|
691
|
+
strokeWidth: "1.5"
|
|
692
|
+
}
|
|
693
|
+
) : null);
|
|
694
|
+
}
|
|
695
|
+
function DrawingOverlay({
|
|
696
|
+
layouts,
|
|
697
|
+
drawings,
|
|
698
|
+
draftDrawing,
|
|
699
|
+
selectedDrawingId,
|
|
700
|
+
projectPoint,
|
|
701
|
+
height = "100%"
|
|
702
|
+
}) {
|
|
703
|
+
const allDrawings = draftDrawing ? [...Array.isArray(drawings) ? drawings : [], draftDrawing] : Array.isArray(drawings) ? drawings : [];
|
|
704
|
+
if (!allDrawings.length) return null;
|
|
705
|
+
return /* @__PURE__ */ import_react4.default.createElement(
|
|
706
|
+
"svg",
|
|
707
|
+
{
|
|
708
|
+
className: "pointer-events-none absolute left-0 top-0 z-20 block overflow-visible",
|
|
709
|
+
style: { width: "100%", height }
|
|
710
|
+
},
|
|
711
|
+
/* @__PURE__ */ import_react4.default.createElement("defs", null, layouts.map((layout) => /* @__PURE__ */ import_react4.default.createElement("clipPath", { key: getClipId(layout.chart.id), id: getClipId(layout.chart.id) }, /* @__PURE__ */ import_react4.default.createElement(
|
|
712
|
+
"rect",
|
|
713
|
+
{
|
|
714
|
+
x: layout.plot.x,
|
|
715
|
+
y: layout.plot.y,
|
|
716
|
+
width: layout.plot.width,
|
|
717
|
+
height: layout.plot.height
|
|
718
|
+
}
|
|
719
|
+
)))),
|
|
720
|
+
layouts.flatMap(
|
|
721
|
+
(layout) => getDrawingsForChart(allDrawings, layout.chart.id).map((drawing) => {
|
|
722
|
+
const geometry = getDrawingGeometry({
|
|
723
|
+
drawing,
|
|
724
|
+
layout,
|
|
725
|
+
projectPoint
|
|
726
|
+
});
|
|
727
|
+
if (!geometry) return null;
|
|
728
|
+
const selected = drawing.id === selectedDrawingId || drawing.id === "__draft__";
|
|
729
|
+
const dashArray = geometry.style.dashPattern.length ? geometry.style.dashPattern.join(" ") : void 0;
|
|
730
|
+
if (drawing.type === "pin") {
|
|
731
|
+
return /* @__PURE__ */ import_react4.default.createElement("g", { key: drawing.id, clipPath: `url(#${getClipId(layout.chart.id)})` }, /* @__PURE__ */ import_react4.default.createElement(
|
|
732
|
+
PinDrawing,
|
|
733
|
+
{
|
|
734
|
+
drawing,
|
|
735
|
+
geometry,
|
|
736
|
+
selected
|
|
737
|
+
}
|
|
738
|
+
));
|
|
739
|
+
}
|
|
740
|
+
return /* @__PURE__ */ import_react4.default.createElement("g", { key: drawing.id, clipPath: `url(#${getClipId(layout.chart.id)})` }, /* @__PURE__ */ import_react4.default.createElement(
|
|
741
|
+
"line",
|
|
742
|
+
{
|
|
743
|
+
x1: geometry.lineStart.x,
|
|
744
|
+
y1: geometry.lineStart.y,
|
|
745
|
+
x2: geometry.lineEnd.x,
|
|
746
|
+
y2: geometry.lineEnd.y,
|
|
747
|
+
stroke: geometry.style.color,
|
|
748
|
+
strokeWidth: geometry.style.lineWidth,
|
|
749
|
+
strokeDasharray: dashArray,
|
|
750
|
+
opacity: drawing.id === "__draft__" ? 0.72 : 1
|
|
751
|
+
}
|
|
752
|
+
), selected ? /* @__PURE__ */ import_react4.default.createElement(import_react4.default.Fragment, null, /* @__PURE__ */ import_react4.default.createElement(
|
|
753
|
+
"circle",
|
|
754
|
+
{
|
|
755
|
+
cx: geometry.start.x,
|
|
756
|
+
cy: geometry.start.y,
|
|
757
|
+
r: DRAWING_HANDLE_RADIUS,
|
|
758
|
+
fill: geometry.style.color,
|
|
759
|
+
stroke: "var(--background, #ffffff)",
|
|
760
|
+
strokeWidth: "1.5"
|
|
761
|
+
}
|
|
762
|
+
), drawing.type === "trendline" ? /* @__PURE__ */ import_react4.default.createElement(
|
|
763
|
+
"circle",
|
|
764
|
+
{
|
|
765
|
+
cx: geometry.end.x,
|
|
766
|
+
cy: geometry.end.y,
|
|
767
|
+
r: DRAWING_HANDLE_RADIUS,
|
|
768
|
+
fill: geometry.style.color,
|
|
769
|
+
stroke: "var(--background, #ffffff)",
|
|
770
|
+
strokeWidth: "1.5"
|
|
771
|
+
}
|
|
772
|
+
) : null) : null);
|
|
773
|
+
}).filter(Boolean)
|
|
774
|
+
)
|
|
775
|
+
);
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
// src/react/MovingAverageOptionsToolbar.jsx
|
|
779
|
+
var import_react5 = __toESM(require("react"), 1);
|
|
780
|
+
var import_react6 = require("@phosphor-icons/react");
|
|
781
|
+
var stopEvent2 = (event) => {
|
|
782
|
+
event.stopPropagation();
|
|
783
|
+
};
|
|
784
|
+
var stopAndPreventEvent2 = (event) => {
|
|
785
|
+
event.preventDefault();
|
|
786
|
+
event.stopPropagation();
|
|
787
|
+
};
|
|
788
|
+
function MovingAverageOptionsToolbar({
|
|
789
|
+
movingAverage,
|
|
790
|
+
style,
|
|
791
|
+
onChange
|
|
792
|
+
}) {
|
|
793
|
+
if (!movingAverage?.enabled) return null;
|
|
794
|
+
const period = Number.isFinite(Number(movingAverage.period)) ? Math.max(1, Math.round(Number(movingAverage.period))) : 21;
|
|
795
|
+
const type = movingAverage.type === "sma" ? "sma" : "ema";
|
|
796
|
+
const hideBase = Boolean(movingAverage.hideBase);
|
|
797
|
+
return /* @__PURE__ */ import_react5.default.createElement(
|
|
798
|
+
"div",
|
|
799
|
+
{
|
|
800
|
+
className: "pointer-events-auto absolute z-40 flex items-center gap-1 rounded-sm bg-background/85 p-1 text-xs text-foreground shadow-sm backdrop-blur",
|
|
801
|
+
style,
|
|
802
|
+
onPointerDown: stopEvent2,
|
|
803
|
+
onClick: (event) => event.stopPropagation()
|
|
804
|
+
},
|
|
805
|
+
/* @__PURE__ */ import_react5.default.createElement(
|
|
806
|
+
"button",
|
|
807
|
+
{
|
|
808
|
+
type: "button",
|
|
809
|
+
title: hideBase ? "Show base series" : "Hide base series",
|
|
810
|
+
"aria-label": hideBase ? "Show base series" : "Hide base series",
|
|
811
|
+
className: `inline-flex size-6 items-center justify-center rounded-sm text-foreground/80 hover:bg-accent hover:text-accent-foreground ${hideBase ? "bg-primary/15 text-primary ring-1 ring-primary/40" : ""}`,
|
|
812
|
+
onPointerDown: stopAndPreventEvent2,
|
|
813
|
+
onClick: (event) => {
|
|
814
|
+
event.preventDefault();
|
|
815
|
+
event.stopPropagation();
|
|
816
|
+
onChange?.({
|
|
817
|
+
...movingAverage,
|
|
818
|
+
hideBase: !hideBase
|
|
819
|
+
});
|
|
820
|
+
}
|
|
821
|
+
},
|
|
822
|
+
/* @__PURE__ */ import_react5.default.createElement(import_react6.EyeIcon, { size: 14, weight: "bold" })
|
|
823
|
+
),
|
|
824
|
+
/* @__PURE__ */ import_react5.default.createElement(
|
|
825
|
+
"button",
|
|
826
|
+
{
|
|
827
|
+
type: "button",
|
|
828
|
+
title: "Toggle moving average type",
|
|
829
|
+
"aria-label": "Toggle moving average type",
|
|
830
|
+
className: "h-6 rounded-sm px-2 text-[11px] font-semibold uppercase leading-none text-foreground/80 hover:bg-accent hover:text-accent-foreground",
|
|
831
|
+
onPointerDown: stopAndPreventEvent2,
|
|
832
|
+
onClick: (event) => {
|
|
833
|
+
event.preventDefault();
|
|
834
|
+
event.stopPropagation();
|
|
835
|
+
onChange?.({
|
|
836
|
+
...movingAverage,
|
|
837
|
+
type: type === "sma" ? "ema" : "sma"
|
|
838
|
+
});
|
|
839
|
+
}
|
|
840
|
+
},
|
|
841
|
+
type
|
|
842
|
+
),
|
|
843
|
+
/* @__PURE__ */ import_react5.default.createElement(
|
|
844
|
+
"input",
|
|
845
|
+
{
|
|
846
|
+
type: "number",
|
|
847
|
+
min: 1,
|
|
848
|
+
step: 1,
|
|
849
|
+
value: period,
|
|
850
|
+
title: "Moving average period",
|
|
851
|
+
className: "h-6 w-14 rounded-sm border border-border/50 bg-background/70 px-1 text-xs tabular-nums",
|
|
852
|
+
onPointerDown: stopEvent2,
|
|
853
|
+
onClick: stopEvent2,
|
|
854
|
+
onChange: (event) => {
|
|
855
|
+
const nextPeriod = Math.max(1, Math.round(Number(event.target.value)));
|
|
856
|
+
if (!Number.isFinite(nextPeriod)) return;
|
|
857
|
+
onChange?.({
|
|
858
|
+
...movingAverage,
|
|
859
|
+
period: nextPeriod
|
|
860
|
+
});
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
)
|
|
864
|
+
);
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
// src/react/useAppendAnimations.js
|
|
868
|
+
var import_react7 = require("react");
|
|
869
|
+
var APPEND_ANIMATION_SETTINGS = {
|
|
870
|
+
enabled: true,
|
|
871
|
+
durationMs: 300,
|
|
872
|
+
maxBucketSize: 64,
|
|
873
|
+
// Zoom threshold
|
|
874
|
+
maxRevealPoints: 100
|
|
875
|
+
// Larger appends skips in-between points
|
|
876
|
+
};
|
|
877
|
+
var easeOutQuad = (value) => 1 - (1 - value) * (1 - value);
|
|
878
|
+
function useAppendAnimations({
|
|
879
|
+
charts,
|
|
880
|
+
dataRevision,
|
|
881
|
+
requestRender,
|
|
882
|
+
settings = APPEND_ANIMATION_SETTINGS
|
|
883
|
+
}) {
|
|
884
|
+
const latestPointRef = (0, import_react7.useRef)(/* @__PURE__ */ new Map());
|
|
885
|
+
const animationsRef = (0, import_react7.useRef)(/* @__PURE__ */ new Map());
|
|
886
|
+
const animationRafRef = (0, import_react7.useRef)(null);
|
|
887
|
+
const stopAnimationLoop = (0, import_react7.useCallback)(() => {
|
|
888
|
+
if (animationRafRef.current != null) {
|
|
889
|
+
cancelAnimationFrame(animationRafRef.current);
|
|
890
|
+
animationRafRef.current = null;
|
|
891
|
+
}
|
|
892
|
+
}, []);
|
|
893
|
+
const startAnimationLoop = (0, import_react7.useCallback)(() => {
|
|
894
|
+
if (!settings.enabled || animationRafRef.current != null) return;
|
|
895
|
+
const tick = () => {
|
|
896
|
+
const now = performance.now();
|
|
897
|
+
let hasActiveAnimation = false;
|
|
898
|
+
animationsRef.current.forEach((animation, seriesId) => {
|
|
899
|
+
if (now - animation.startedAt >= animation.duration) {
|
|
900
|
+
animationsRef.current.delete(seriesId);
|
|
901
|
+
} else {
|
|
902
|
+
hasActiveAnimation = true;
|
|
903
|
+
}
|
|
904
|
+
});
|
|
905
|
+
requestRender();
|
|
906
|
+
animationRafRef.current = hasActiveAnimation ? requestAnimationFrame(tick) : null;
|
|
907
|
+
};
|
|
908
|
+
animationRafRef.current = requestAnimationFrame(tick);
|
|
909
|
+
}, [requestRender, settings.enabled]);
|
|
910
|
+
(0, import_react7.useEffect)(() => {
|
|
911
|
+
if (!settings.enabled) {
|
|
912
|
+
animationsRef.current.clear();
|
|
913
|
+
stopAnimationLoop();
|
|
914
|
+
}
|
|
915
|
+
}, [settings.enabled, stopAnimationLoop]);
|
|
916
|
+
(0, import_react7.useLayoutEffect)(() => {
|
|
917
|
+
if (!settings.enabled) return;
|
|
918
|
+
const now = performance.now();
|
|
919
|
+
charts.forEach((chart) => {
|
|
920
|
+
chart.series.forEach((series) => {
|
|
921
|
+
if (series.length === 0) return;
|
|
922
|
+
const next = {
|
|
923
|
+
x: series.rawX[series.length - 1],
|
|
924
|
+
y: series.rawY[series.length - 1],
|
|
925
|
+
length: series.length
|
|
926
|
+
};
|
|
927
|
+
const previous = latestPointRef.current.get(series.id);
|
|
928
|
+
if (previous && Number.isFinite(previous.x) && Number.isFinite(previous.y) && next.x > previous.x) {
|
|
929
|
+
animationsRef.current.set(series.id, {
|
|
930
|
+
fromX: previous.x,
|
|
931
|
+
fromY: previous.y,
|
|
932
|
+
toX: next.x,
|
|
933
|
+
toY: next.y,
|
|
934
|
+
appendedCount: next.length - previous.length,
|
|
935
|
+
startedAt: now,
|
|
936
|
+
duration: settings.durationMs
|
|
937
|
+
});
|
|
938
|
+
startAnimationLoop();
|
|
939
|
+
}
|
|
940
|
+
latestPointRef.current.set(series.id, next);
|
|
941
|
+
});
|
|
942
|
+
});
|
|
943
|
+
}, [
|
|
944
|
+
charts,
|
|
945
|
+
dataRevision,
|
|
946
|
+
settings.durationMs,
|
|
947
|
+
settings.enabled,
|
|
948
|
+
startAnimationLoop
|
|
949
|
+
]);
|
|
950
|
+
(0, import_react7.useEffect)(() => stopAnimationLoop, [stopAnimationLoop]);
|
|
951
|
+
const getAppendAnimatedPoint = (0, import_react7.useCallback)(
|
|
952
|
+
({ seriesId, visiblePoints, now }) => {
|
|
953
|
+
if (!settings.enabled || visiblePoints.bucketSize > settings.maxBucketSize) {
|
|
954
|
+
return null;
|
|
955
|
+
}
|
|
956
|
+
const animation = animationsRef.current.get(seriesId);
|
|
957
|
+
if (!animation || visiblePoints.x[0] > animation.fromX || visiblePoints.x[visiblePoints.pointCount - 1] < animation.toX) {
|
|
958
|
+
return null;
|
|
959
|
+
}
|
|
960
|
+
let stableCount = 0;
|
|
961
|
+
while (stableCount < visiblePoints.pointCount && visiblePoints.x[stableCount] <= animation.fromX) {
|
|
962
|
+
stableCount += 1;
|
|
963
|
+
}
|
|
964
|
+
if (stableCount === 0) return null;
|
|
965
|
+
const progress = Math.min(
|
|
966
|
+
1,
|
|
967
|
+
Math.max(0, (now - animation.startedAt) / animation.duration)
|
|
968
|
+
);
|
|
969
|
+
const eased = easeOutQuad(progress);
|
|
970
|
+
if (animation.appendedCount <= settings.maxRevealPoints) {
|
|
971
|
+
const appendedVisibleCount = visiblePoints.pointCount - stableCount;
|
|
972
|
+
const revealPosition = eased * appendedVisibleCount;
|
|
973
|
+
const revealedPoints = Math.min(
|
|
974
|
+
appendedVisibleCount,
|
|
975
|
+
Math.floor(revealPosition)
|
|
976
|
+
);
|
|
977
|
+
const nextIndex = Math.min(
|
|
978
|
+
visiblePoints.pointCount - 1,
|
|
979
|
+
stableCount + revealedPoints
|
|
980
|
+
);
|
|
981
|
+
const previousIndex = Math.max(stableCount - 1, nextIndex - 1);
|
|
982
|
+
const partial = revealPosition - revealedPoints;
|
|
983
|
+
const hasPartial = revealedPoints < appendedVisibleCount;
|
|
984
|
+
const x = hasPartial ? visiblePoints.x[previousIndex] + (visiblePoints.x[nextIndex] - visiblePoints.x[previousIndex]) * partial : visiblePoints.x[nextIndex];
|
|
985
|
+
const y = hasPartial ? visiblePoints.y[previousIndex] + (visiblePoints.y[nextIndex] - visiblePoints.y[previousIndex]) * partial : visiblePoints.y[nextIndex];
|
|
986
|
+
return {
|
|
987
|
+
index: nextIndex,
|
|
988
|
+
pointCount: Math.min(visiblePoints.pointCount, nextIndex + 1),
|
|
989
|
+
x,
|
|
990
|
+
y
|
|
991
|
+
};
|
|
992
|
+
}
|
|
993
|
+
return {
|
|
994
|
+
index: stableCount,
|
|
995
|
+
pointCount: stableCount + 1,
|
|
996
|
+
x: animation.fromX + (animation.toX - animation.fromX) * eased,
|
|
997
|
+
y: animation.fromY + (animation.toY - animation.fromY) * eased
|
|
998
|
+
};
|
|
999
|
+
},
|
|
1000
|
+
[settings.enabled, settings.maxBucketSize, settings.maxRevealPoints]
|
|
1001
|
+
);
|
|
1002
|
+
return { getAppendAnimatedPoint };
|
|
1003
|
+
}
|
|
1004
|
+
|
|
1005
|
+
// src/react/useDrawingInteractions.js
|
|
1006
|
+
var import_react8 = require("react");
|
|
1007
|
+
function useDrawingInteractions({
|
|
1008
|
+
drawings,
|
|
1009
|
+
onDrawingsChange,
|
|
1010
|
+
activeDrawingTool,
|
|
1011
|
+
onActiveDrawingToolChange,
|
|
1012
|
+
selectedDrawingId,
|
|
1013
|
+
onSelectedDrawingIdChange,
|
|
1014
|
+
createDrawingId,
|
|
1015
|
+
focusedChartId = null,
|
|
1016
|
+
requireFocusedChart = false,
|
|
1017
|
+
onModeChange
|
|
1018
|
+
}) {
|
|
1019
|
+
const drawingSessionRef = (0, import_react8.useRef)({ chartId: null, startPoint: null });
|
|
1020
|
+
const drawingEditRef = (0, import_react8.useRef)(null);
|
|
1021
|
+
const [draftDrawing, setDraftDrawing] = (0, import_react8.useState)(null);
|
|
1022
|
+
const clearDraft = (0, import_react8.useCallback)(() => {
|
|
1023
|
+
setDraftDrawing(null);
|
|
1024
|
+
drawingSessionRef.current = { chartId: null, startPoint: null };
|
|
1025
|
+
}, []);
|
|
1026
|
+
const cancelDrawing = (0, import_react8.useCallback)(() => {
|
|
1027
|
+
onActiveDrawingToolChange?.(null);
|
|
1028
|
+
onSelectedDrawingIdChange?.(null);
|
|
1029
|
+
setDraftDrawing(null);
|
|
1030
|
+
drawingSessionRef.current = { chartId: null, startPoint: null };
|
|
1031
|
+
drawingEditRef.current = null;
|
|
1032
|
+
}, [onActiveDrawingToolChange, onSelectedDrawingIdChange]);
|
|
1033
|
+
const toggleDrawingTool = (0, import_react8.useCallback)(
|
|
1034
|
+
(tool) => {
|
|
1035
|
+
if (!DRAWING_TOOLS.has(tool)) return;
|
|
1036
|
+
if (requireFocusedChart && !focusedChartId) return;
|
|
1037
|
+
onModeChange?.();
|
|
1038
|
+
clearDraft();
|
|
1039
|
+
onActiveDrawingToolChange?.(activeDrawingTool === tool ? null : tool);
|
|
1040
|
+
},
|
|
1041
|
+
[
|
|
1042
|
+
activeDrawingTool,
|
|
1043
|
+
clearDraft,
|
|
1044
|
+
focusedChartId,
|
|
1045
|
+
onActiveDrawingToolChange,
|
|
1046
|
+
onModeChange,
|
|
1047
|
+
requireFocusedChart
|
|
1048
|
+
]
|
|
1049
|
+
);
|
|
1050
|
+
const commitDrawing = (0, import_react8.useCallback)(
|
|
1051
|
+
({ chartId, type, start, end }) => {
|
|
1052
|
+
const drawing = createDrawing({
|
|
1053
|
+
chartId,
|
|
1054
|
+
type,
|
|
1055
|
+
start,
|
|
1056
|
+
end,
|
|
1057
|
+
createDrawingId
|
|
1058
|
+
});
|
|
1059
|
+
onDrawingsChange?.([...Array.isArray(drawings) ? drawings : [], drawing]);
|
|
1060
|
+
onSelectedDrawingIdChange?.(drawing.id);
|
|
1061
|
+
onActiveDrawingToolChange?.(null);
|
|
1062
|
+
clearDraft();
|
|
1063
|
+
},
|
|
1064
|
+
[
|
|
1065
|
+
clearDraft,
|
|
1066
|
+
createDrawingId,
|
|
1067
|
+
drawings,
|
|
1068
|
+
onActiveDrawingToolChange,
|
|
1069
|
+
onDrawingsChange,
|
|
1070
|
+
onSelectedDrawingIdChange
|
|
1071
|
+
]
|
|
1072
|
+
);
|
|
1073
|
+
const startDraftDrawing = (0, import_react8.useCallback)(
|
|
1074
|
+
({ chartId, type, start, end = start }) => {
|
|
1075
|
+
drawingSessionRef.current = { chartId, startPoint: start };
|
|
1076
|
+
setDraftDrawing(createDraftDrawing({ chartId, type, start, end }));
|
|
1077
|
+
},
|
|
1078
|
+
[]
|
|
1079
|
+
);
|
|
1080
|
+
const updateDraftDrawing = (0, import_react8.useCallback)(({ chartId, type, start, end }) => {
|
|
1081
|
+
setDraftDrawing(createDraftDrawing({ chartId, type, start, end }));
|
|
1082
|
+
}, []);
|
|
1083
|
+
const startEditDrawing = (0, import_react8.useCallback)(({ drawingId, endpoint }) => {
|
|
1084
|
+
drawingEditRef.current = {
|
|
1085
|
+
id: drawingId,
|
|
1086
|
+
endpoint: endpoint || "move"
|
|
1087
|
+
};
|
|
1088
|
+
}, []);
|
|
1089
|
+
const finishEditDrawing = (0, import_react8.useCallback)(() => {
|
|
1090
|
+
drawingEditRef.current = null;
|
|
1091
|
+
}, []);
|
|
1092
|
+
const deleteSelectedDrawing = (0, import_react8.useCallback)(() => {
|
|
1093
|
+
if (!selectedDrawingId) return false;
|
|
1094
|
+
onDrawingsChange?.(removeDrawingById(drawings, selectedDrawingId));
|
|
1095
|
+
onSelectedDrawingIdChange?.(null);
|
|
1096
|
+
return true;
|
|
1097
|
+
}, [
|
|
1098
|
+
drawings,
|
|
1099
|
+
onDrawingsChange,
|
|
1100
|
+
onSelectedDrawingIdChange,
|
|
1101
|
+
selectedDrawingId
|
|
1102
|
+
]);
|
|
1103
|
+
(0, import_react8.useEffect)(() => {
|
|
1104
|
+
if (activeDrawingTool) return;
|
|
1105
|
+
clearDraft();
|
|
1106
|
+
}, [activeDrawingTool, clearDraft]);
|
|
1107
|
+
return {
|
|
1108
|
+
draftDrawing,
|
|
1109
|
+
drawingSessionRef,
|
|
1110
|
+
drawingEditRef,
|
|
1111
|
+
clearDraft,
|
|
1112
|
+
cancelDrawing,
|
|
1113
|
+
toggleDrawingTool,
|
|
1114
|
+
commitDrawing,
|
|
1115
|
+
startDraftDrawing,
|
|
1116
|
+
updateDraftDrawing,
|
|
1117
|
+
startEditDrawing,
|
|
1118
|
+
finishEditDrawing,
|
|
1119
|
+
deleteSelectedDrawing
|
|
1120
|
+
};
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
// src/react/ChartGrid.jsx
|
|
1124
|
+
var CHART_HEIGHT = 360;
|
|
1125
|
+
var RIGHT_AXIS_WIDTH = 58;
|
|
1126
|
+
var PLOT_PADDING = {
|
|
1127
|
+
left: 38,
|
|
1128
|
+
right: RIGHT_AXIS_WIDTH,
|
|
1129
|
+
top: 34,
|
|
1130
|
+
bottom: 28
|
|
1131
|
+
};
|
|
1132
|
+
var FOLLOW_VISIBLE_RIGHT_EDGE_RATIO = 0.15;
|
|
1133
|
+
var Y_SCALE_MIN = 0.05;
|
|
1134
|
+
var Y_SCALE_MAX = 40;
|
|
1135
|
+
var Y_AXIS_TICK_COUNT = 5;
|
|
1136
|
+
var X_AXIS_TICK_COUNT = 5;
|
|
1137
|
+
var X_SCALE_MIN_SPAN = 10;
|
|
1138
|
+
var X_SCALE_MAX_SPAN = 1e9;
|
|
1139
|
+
var JUMP_LATEST_RIGHT_PADDING_RATIO = 0.1;
|
|
1140
|
+
var INITIAL_GPU_VERTEX_CAPACITY = 4096;
|
|
1141
|
+
var AA_VERTEX_FLOAT_STRIDE = 6;
|
|
1142
|
+
var AA_LINE_WIDTH_PX = 1.5;
|
|
1143
|
+
var AA_EDGE_WIDTH_PX = 1;
|
|
1144
|
+
var DASH_LENGTH_PX = 7;
|
|
1145
|
+
var DASH_GAP_PX = 5;
|
|
1146
|
+
var TOOLTIP_WIDTH = 220;
|
|
1147
|
+
var TOOLTIP_OFFSET = 12;
|
|
1148
|
+
var DEFAULT_CHART_BACKGROUND = "#f5f9ff";
|
|
1149
|
+
var EMPTY_ARRAY = [];
|
|
1150
|
+
var EMPTY_OBJECT = {};
|
|
1151
|
+
var withAlpha = (color, alpha) => {
|
|
1152
|
+
const value = String(color || DEFAULT_CHART_BACKGROUND).trim();
|
|
1153
|
+
if (/^#[0-9a-f]{6}$/i.test(value)) {
|
|
1154
|
+
const r = Number.parseInt(value.slice(1, 3), 16);
|
|
1155
|
+
const g = Number.parseInt(value.slice(3, 5), 16);
|
|
1156
|
+
const b = Number.parseInt(value.slice(5, 7), 16);
|
|
1157
|
+
return `rgba(${r}, ${g}, ${b}, ${alpha})`;
|
|
1158
|
+
}
|
|
1159
|
+
if (/^#[0-9a-f]{3}$/i.test(value)) {
|
|
1160
|
+
const r = Number.parseInt(value[1] + value[1], 16);
|
|
1161
|
+
const g = Number.parseInt(value[2] + value[2], 16);
|
|
1162
|
+
const b = Number.parseInt(value[3] + value[3], 16);
|
|
1163
|
+
return `rgba(${r}, ${g}, ${b}, ${alpha})`;
|
|
1164
|
+
}
|
|
1165
|
+
return value;
|
|
1166
|
+
};
|
|
1167
|
+
var hexToRgb = (color) => {
|
|
1168
|
+
const value = String(color || "#38bdf8").replace("#", "");
|
|
1169
|
+
const normalized = value.length === 3 ? value.split("").map((char) => char + char).join("") : value.padEnd(6, "0").slice(0, 6);
|
|
1170
|
+
const number = Number.parseInt(normalized, 16);
|
|
1171
|
+
return [
|
|
1172
|
+
(number >> 16 & 255) / 255,
|
|
1173
|
+
(number >> 8 & 255) / 255,
|
|
1174
|
+
(number & 255) / 255
|
|
1175
|
+
];
|
|
1176
|
+
};
|
|
1177
|
+
var getReadableTextColor = (backgroundColor) => {
|
|
1178
|
+
const [r, g, b] = hexToRgb(backgroundColor);
|
|
1179
|
+
const toLinear = (value) => value <= 0.03928 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;
|
|
1180
|
+
const luminance = 0.2126 * toLinear(r) + 0.7152 * toLinear(g) + 0.0722 * toLinear(b);
|
|
1181
|
+
return luminance > 0.45 ? "#111827" : "#ffffff";
|
|
1182
|
+
};
|
|
1183
|
+
var getSeriesLabelTextColor = (series) => {
|
|
1184
|
+
if (series.__labelTextColorFor !== series.color) {
|
|
1185
|
+
series.__labelTextColorFor = series.color;
|
|
1186
|
+
series.__labelTextColor = getReadableTextColor(series.color);
|
|
1187
|
+
}
|
|
1188
|
+
return series.__labelTextColor;
|
|
1189
|
+
};
|
|
1190
|
+
var getSelectedDrawingLayout = (layouts, drawings, selectedDrawingId) => {
|
|
1191
|
+
if (!selectedDrawingId || !Array.isArray(drawings)) return null;
|
|
1192
|
+
const drawing = drawings.find((candidate) => candidate?.id === selectedDrawingId);
|
|
1193
|
+
if (!drawing) return null;
|
|
1194
|
+
const layout = layouts.find(
|
|
1195
|
+
(candidate) => candidate.visible && candidate.chart.id === drawing.chartId
|
|
1196
|
+
);
|
|
1197
|
+
return layout ? { drawing, layout } : null;
|
|
1198
|
+
};
|
|
1199
|
+
var getDrawingOptionsToolbarStyle = (layout) => ({
|
|
1200
|
+
left: Math.max(
|
|
1201
|
+
layout.rect.x + 42,
|
|
1202
|
+
layout.rect.x + layout.rect.width - PLOT_PADDING.right - 8
|
|
1203
|
+
),
|
|
1204
|
+
top: layout.rect.y + PLOT_PADDING.top + 6,
|
|
1205
|
+
transform: "translateX(-100%)"
|
|
1206
|
+
});
|
|
1207
|
+
var getMovingAverageOptionsToolbarStyle = (layout) => ({
|
|
1208
|
+
left: Math.max(
|
|
1209
|
+
layout.rect.x + 120,
|
|
1210
|
+
layout.rect.x + layout.rect.width - PLOT_PADDING.right - 8
|
|
1211
|
+
),
|
|
1212
|
+
top: layout.rect.y + 8,
|
|
1213
|
+
transform: "translateX(-100%)"
|
|
1214
|
+
});
|
|
1215
|
+
var getChartContextMenuPoint = ({
|
|
1216
|
+
point,
|
|
1217
|
+
chart,
|
|
1218
|
+
layout,
|
|
1219
|
+
initialVisiblePoints,
|
|
1220
|
+
viewStateRef,
|
|
1221
|
+
yScaleRef,
|
|
1222
|
+
yCenterOffsetRef
|
|
1223
|
+
}) => {
|
|
1224
|
+
const inPlot = point.x >= layout.plot.x && point.x <= layout.plot.x + layout.plot.width && point.y >= layout.plot.y && point.y <= layout.plot.y + layout.plot.height;
|
|
1225
|
+
if (!inPlot) {
|
|
1226
|
+
return {
|
|
1227
|
+
x: point.x,
|
|
1228
|
+
y: point.y,
|
|
1229
|
+
inPlot: false,
|
|
1230
|
+
data: null
|
|
1231
|
+
};
|
|
1232
|
+
}
|
|
1233
|
+
return {
|
|
1234
|
+
x: point.x,
|
|
1235
|
+
y: point.y,
|
|
1236
|
+
inPlot: true,
|
|
1237
|
+
data: screenPointToDataPoint({
|
|
1238
|
+
point,
|
|
1239
|
+
chart,
|
|
1240
|
+
plot: layout.plot,
|
|
1241
|
+
initialVisiblePoints,
|
|
1242
|
+
viewStateRef,
|
|
1243
|
+
yScaleRef,
|
|
1244
|
+
yCenterOffsetRef
|
|
1245
|
+
})
|
|
1246
|
+
};
|
|
1247
|
+
};
|
|
1248
|
+
var createProgram = (gl) => {
|
|
1249
|
+
const vertexSource = `#version 300 es
|
|
1250
|
+
in vec2 a_xy;
|
|
1251
|
+
uniform vec2 u_resolution;
|
|
1252
|
+
uniform vec4 u_rect;
|
|
1253
|
+
uniform vec2 u_xRange;
|
|
1254
|
+
uniform vec2 u_yRange;
|
|
1255
|
+
|
|
1256
|
+
void main() {
|
|
1257
|
+
float xDenom = max(0.000000000001, abs(u_xRange.y - u_xRange.x));
|
|
1258
|
+
float yDenom = max(0.000000000001, abs(u_yRange.y - u_yRange.x));
|
|
1259
|
+
float nx = (a_xy.x - u_xRange.x) / xDenom;
|
|
1260
|
+
float ny = (a_xy.y - u_yRange.x) / yDenom;
|
|
1261
|
+
float px = u_rect.x + nx * u_rect.z;
|
|
1262
|
+
float py = u_rect.y + (1.0 - ny) * u_rect.w;
|
|
1263
|
+
vec2 zeroToOne = vec2(px, py) / u_resolution;
|
|
1264
|
+
vec2 clip = zeroToOne * 2.0 - 1.0;
|
|
1265
|
+
gl_Position = vec4(clip.x, -clip.y, 0.0, 1.0);
|
|
1266
|
+
}
|
|
1267
|
+
`;
|
|
1268
|
+
const fragmentSource = `#version 300 es
|
|
1269
|
+
precision highp float;
|
|
1270
|
+
uniform vec3 u_color;
|
|
1271
|
+
out vec4 outColor;
|
|
1272
|
+
|
|
1273
|
+
void main() {
|
|
1274
|
+
outColor = vec4(u_color, 1.0);
|
|
1275
|
+
}
|
|
1276
|
+
`;
|
|
1277
|
+
const compile = (type, source) => {
|
|
1278
|
+
const shader = gl.createShader(type);
|
|
1279
|
+
gl.shaderSource(shader, source);
|
|
1280
|
+
gl.compileShader(shader);
|
|
1281
|
+
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
|
|
1282
|
+
throw new Error(gl.getShaderInfoLog(shader) || "Shader compile failed");
|
|
1283
|
+
}
|
|
1284
|
+
return shader;
|
|
1285
|
+
};
|
|
1286
|
+
const program = gl.createProgram();
|
|
1287
|
+
gl.attachShader(program, compile(gl.VERTEX_SHADER, vertexSource));
|
|
1288
|
+
gl.attachShader(program, compile(gl.FRAGMENT_SHADER, fragmentSource));
|
|
1289
|
+
gl.linkProgram(program);
|
|
1290
|
+
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
|
|
1291
|
+
throw new Error(gl.getProgramInfoLog(program) || "Program link failed");
|
|
1292
|
+
}
|
|
1293
|
+
return program;
|
|
1294
|
+
};
|
|
1295
|
+
var createAntialiasProgram = (gl) => {
|
|
1296
|
+
const vertexSource = `#version 300 es
|
|
1297
|
+
in vec2 a_start;
|
|
1298
|
+
in vec2 a_end;
|
|
1299
|
+
in float a_side;
|
|
1300
|
+
in float a_along;
|
|
1301
|
+
uniform vec2 u_resolution;
|
|
1302
|
+
uniform vec4 u_rect;
|
|
1303
|
+
uniform vec2 u_xRange;
|
|
1304
|
+
uniform vec2 u_yRange;
|
|
1305
|
+
uniform float u_lineHalfWidth;
|
|
1306
|
+
uniform float u_edgeWidth;
|
|
1307
|
+
out float v_side;
|
|
1308
|
+
|
|
1309
|
+
vec2 toPixel(vec2 value) {
|
|
1310
|
+
float xDenom = max(0.000000000001, abs(u_xRange.y - u_xRange.x));
|
|
1311
|
+
float yDenom = max(0.000000000001, abs(u_yRange.y - u_yRange.x));
|
|
1312
|
+
float nx = (value.x - u_xRange.x) / xDenom;
|
|
1313
|
+
float ny = (value.y - u_yRange.x) / yDenom;
|
|
1314
|
+
return vec2(
|
|
1315
|
+
u_rect.x + nx * u_rect.z,
|
|
1316
|
+
u_rect.y + (1.0 - ny) * u_rect.w
|
|
1317
|
+
);
|
|
1318
|
+
}
|
|
1319
|
+
|
|
1320
|
+
void main() {
|
|
1321
|
+
vec2 startPx = toPixel(a_start);
|
|
1322
|
+
vec2 endPx = toPixel(a_end);
|
|
1323
|
+
vec2 delta = endPx - startPx;
|
|
1324
|
+
float segmentLength = max(0.000001, length(delta));
|
|
1325
|
+
vec2 direction = delta / segmentLength;
|
|
1326
|
+
vec2 normal = vec2(-direction.y, direction.x);
|
|
1327
|
+
float expand = u_lineHalfWidth + u_edgeWidth;
|
|
1328
|
+
float cap = min(expand, segmentLength * 0.5);
|
|
1329
|
+
vec2 px = mix(startPx, endPx, a_along)
|
|
1330
|
+
+ direction * ((a_along * 2.0 - 1.0) * cap)
|
|
1331
|
+
+ normal * a_side * expand;
|
|
1332
|
+
vec2 zeroToOne = px / u_resolution;
|
|
1333
|
+
vec2 clip = zeroToOne * 2.0 - 1.0;
|
|
1334
|
+
v_side = a_side;
|
|
1335
|
+
gl_Position = vec4(clip.x, -clip.y, 0.0, 1.0);
|
|
1336
|
+
}
|
|
1337
|
+
`;
|
|
1338
|
+
const fragmentSource = `#version 300 es
|
|
1339
|
+
precision highp float;
|
|
1340
|
+
uniform vec3 u_color;
|
|
1341
|
+
uniform float u_lineHalfWidth;
|
|
1342
|
+
uniform float u_edgeWidth;
|
|
1343
|
+
in float v_side;
|
|
1344
|
+
out vec4 outColor;
|
|
1345
|
+
|
|
1346
|
+
void main() {
|
|
1347
|
+
float expand = u_lineHalfWidth + u_edgeWidth;
|
|
1348
|
+
float distanceFromCenter = abs(v_side) * expand;
|
|
1349
|
+
float alpha = 1.0 - smoothstep(u_lineHalfWidth, expand, distanceFromCenter);
|
|
1350
|
+
outColor = vec4(u_color, alpha);
|
|
1351
|
+
}
|
|
1352
|
+
`;
|
|
1353
|
+
const compile = (type, source) => {
|
|
1354
|
+
const shader = gl.createShader(type);
|
|
1355
|
+
gl.shaderSource(shader, source);
|
|
1356
|
+
gl.compileShader(shader);
|
|
1357
|
+
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
|
|
1358
|
+
throw new Error(gl.getShaderInfoLog(shader) || "Shader compile failed");
|
|
1359
|
+
}
|
|
1360
|
+
return shader;
|
|
1361
|
+
};
|
|
1362
|
+
const program = gl.createProgram();
|
|
1363
|
+
gl.attachShader(program, compile(gl.VERTEX_SHADER, vertexSource));
|
|
1364
|
+
gl.attachShader(program, compile(gl.FRAGMENT_SHADER, fragmentSource));
|
|
1365
|
+
gl.linkProgram(program);
|
|
1366
|
+
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
|
|
1367
|
+
throw new Error(gl.getProgramInfoLog(program) || "Program link failed");
|
|
1368
|
+
}
|
|
1369
|
+
return program;
|
|
1370
|
+
};
|
|
1371
|
+
var createSeriesBufferCache = () => /* @__PURE__ */ new Map();
|
|
1372
|
+
var getNextVertexCapacity = (currentCapacity, requiredCapacity) => {
|
|
1373
|
+
let nextCapacity = Math.max(
|
|
1374
|
+
INITIAL_GPU_VERTEX_CAPACITY,
|
|
1375
|
+
currentCapacity || 0
|
|
1376
|
+
);
|
|
1377
|
+
while (nextCapacity < requiredCapacity) {
|
|
1378
|
+
nextCapacity *= 2;
|
|
1379
|
+
}
|
|
1380
|
+
return nextCapacity;
|
|
1381
|
+
};
|
|
1382
|
+
var getSeriesBuffer = (gl, cache, seriesId, pointCount) => {
|
|
1383
|
+
const requiredVertexFloats = pointCount * 2;
|
|
1384
|
+
let entry = cache.get(seriesId);
|
|
1385
|
+
if (!entry) {
|
|
1386
|
+
entry = {
|
|
1387
|
+
buffer: gl.createBuffer(),
|
|
1388
|
+
gpuCapacity: 0,
|
|
1389
|
+
vertices: new Float32Array(
|
|
1390
|
+
getNextVertexCapacity(0, requiredVertexFloats)
|
|
1391
|
+
)
|
|
1392
|
+
};
|
|
1393
|
+
cache.set(seriesId, entry);
|
|
1394
|
+
}
|
|
1395
|
+
if (entry.vertices.length < requiredVertexFloats) {
|
|
1396
|
+
entry.vertices = new Float32Array(
|
|
1397
|
+
getNextVertexCapacity(entry.vertices.length, requiredVertexFloats)
|
|
1398
|
+
);
|
|
1399
|
+
}
|
|
1400
|
+
if (entry.gpuCapacity < entry.vertices.length) {
|
|
1401
|
+
entry.gpuCapacity = entry.vertices.length;
|
|
1402
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, entry.buffer);
|
|
1403
|
+
gl.bufferData(
|
|
1404
|
+
gl.ARRAY_BUFFER,
|
|
1405
|
+
entry.gpuCapacity * Float32Array.BYTES_PER_ELEMENT,
|
|
1406
|
+
gl.DYNAMIC_DRAW
|
|
1407
|
+
);
|
|
1408
|
+
}
|
|
1409
|
+
return entry;
|
|
1410
|
+
};
|
|
1411
|
+
var getAntialiasSeriesBuffer = (gl, cache, seriesId, pointCount) => {
|
|
1412
|
+
const segmentCount = Math.max(0, pointCount - 1);
|
|
1413
|
+
const requiredVertexFloats = segmentCount * 6 * AA_VERTEX_FLOAT_STRIDE;
|
|
1414
|
+
let entry = cache.get(seriesId);
|
|
1415
|
+
if (!entry) {
|
|
1416
|
+
entry = {
|
|
1417
|
+
buffer: gl.createBuffer(),
|
|
1418
|
+
gpuCapacity: 0,
|
|
1419
|
+
vertices: new Float32Array(
|
|
1420
|
+
getNextVertexCapacity(0, requiredVertexFloats)
|
|
1421
|
+
)
|
|
1422
|
+
};
|
|
1423
|
+
cache.set(seriesId, entry);
|
|
1424
|
+
}
|
|
1425
|
+
if (entry.vertices.length < requiredVertexFloats) {
|
|
1426
|
+
entry.vertices = new Float32Array(
|
|
1427
|
+
getNextVertexCapacity(entry.vertices.length, requiredVertexFloats)
|
|
1428
|
+
);
|
|
1429
|
+
}
|
|
1430
|
+
if (entry.gpuCapacity < entry.vertices.length) {
|
|
1431
|
+
entry.gpuCapacity = entry.vertices.length;
|
|
1432
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, entry.buffer);
|
|
1433
|
+
gl.bufferData(
|
|
1434
|
+
gl.ARRAY_BUFFER,
|
|
1435
|
+
entry.gpuCapacity * Float32Array.BYTES_PER_ELEMENT,
|
|
1436
|
+
gl.DYNAMIC_DRAW
|
|
1437
|
+
);
|
|
1438
|
+
}
|
|
1439
|
+
return entry;
|
|
1440
|
+
};
|
|
1441
|
+
var deleteSeriesBuffers = (gl, cache) => {
|
|
1442
|
+
cache.forEach((entry) => {
|
|
1443
|
+
if (entry.buffer) gl.deleteBuffer(entry.buffer);
|
|
1444
|
+
});
|
|
1445
|
+
cache.clear();
|
|
1446
|
+
};
|
|
1447
|
+
var fillSeriesPoints = ({ vertices, visiblePoints, pointCount, animatedPoint }) => {
|
|
1448
|
+
for (let i = 0; i < pointCount; i += 1) {
|
|
1449
|
+
if (animatedPoint && i === animatedPoint.index) {
|
|
1450
|
+
vertices[i * 2] = animatedPoint.x;
|
|
1451
|
+
vertices[i * 2 + 1] = animatedPoint.y;
|
|
1452
|
+
continue;
|
|
1453
|
+
}
|
|
1454
|
+
vertices[i * 2] = visiblePoints.x[i];
|
|
1455
|
+
vertices[i * 2 + 1] = visiblePoints.y[i];
|
|
1456
|
+
}
|
|
1457
|
+
};
|
|
1458
|
+
var projectDataToPixel = ({ x, y, state, yRange, plot }) => ({
|
|
1459
|
+
x: plot.x + (x - state.xMin) / (state.xMax - state.xMin) * plot.width,
|
|
1460
|
+
y: plot.y + (yRange.maxY - y) / (yRange.maxY - yRange.minY) * plot.height
|
|
1461
|
+
});
|
|
1462
|
+
var toViewportLayout = (layout, scrollLeft, scrollTop) => ({
|
|
1463
|
+
...layout,
|
|
1464
|
+
rect: {
|
|
1465
|
+
...layout.rect,
|
|
1466
|
+
x: layout.rect.x - scrollLeft,
|
|
1467
|
+
y: layout.rect.y - scrollTop
|
|
1468
|
+
},
|
|
1469
|
+
plot: {
|
|
1470
|
+
...layout.plot,
|
|
1471
|
+
x: layout.plot.x - scrollLeft,
|
|
1472
|
+
y: layout.plot.y - scrollTop
|
|
1473
|
+
}
|
|
1474
|
+
});
|
|
1475
|
+
var writeLineVertex = (vertices, offset, x, y) => {
|
|
1476
|
+
vertices[offset] = x;
|
|
1477
|
+
vertices[offset + 1] = y;
|
|
1478
|
+
};
|
|
1479
|
+
var fillDashedSeriesSegments = ({
|
|
1480
|
+
vertices,
|
|
1481
|
+
visiblePoints,
|
|
1482
|
+
pointCount,
|
|
1483
|
+
state,
|
|
1484
|
+
yRange,
|
|
1485
|
+
plot
|
|
1486
|
+
}) => {
|
|
1487
|
+
let offset = 0;
|
|
1488
|
+
let distance = 0;
|
|
1489
|
+
const dashTotal = DASH_LENGTH_PX + DASH_GAP_PX;
|
|
1490
|
+
for (let i = 0; i < pointCount - 1; i += 1) {
|
|
1491
|
+
const start = {
|
|
1492
|
+
x: visiblePoints.x[i],
|
|
1493
|
+
y: visiblePoints.y[i]
|
|
1494
|
+
};
|
|
1495
|
+
const end = {
|
|
1496
|
+
x: visiblePoints.x[i + 1],
|
|
1497
|
+
y: visiblePoints.y[i + 1]
|
|
1498
|
+
};
|
|
1499
|
+
const startPx = projectDataToPixel({ ...start, state, yRange, plot });
|
|
1500
|
+
const endPx = projectDataToPixel({ ...end, state, yRange, plot });
|
|
1501
|
+
const pixelLength = Math.hypot(endPx.x - startPx.x, endPx.y - startPx.y);
|
|
1502
|
+
if (!Number.isFinite(pixelLength) || pixelLength <= 0) continue;
|
|
1503
|
+
let consumed = 0;
|
|
1504
|
+
while (consumed < pixelLength) {
|
|
1505
|
+
const phase = distance % dashTotal;
|
|
1506
|
+
const boundary = phase < DASH_LENGTH_PX ? DASH_LENGTH_PX - phase : dashTotal - phase;
|
|
1507
|
+
const step = Math.min(boundary, pixelLength - consumed);
|
|
1508
|
+
if (phase < DASH_LENGTH_PX) {
|
|
1509
|
+
if (offset + 4 > vertices.length) {
|
|
1510
|
+
return offset / 2;
|
|
1511
|
+
}
|
|
1512
|
+
const t0 = consumed / pixelLength;
|
|
1513
|
+
const t1 = (consumed + step) / pixelLength;
|
|
1514
|
+
writeLineVertex(
|
|
1515
|
+
vertices,
|
|
1516
|
+
offset,
|
|
1517
|
+
start.x + (end.x - start.x) * t0,
|
|
1518
|
+
start.y + (end.y - start.y) * t0
|
|
1519
|
+
);
|
|
1520
|
+
offset += 2;
|
|
1521
|
+
writeLineVertex(
|
|
1522
|
+
vertices,
|
|
1523
|
+
offset,
|
|
1524
|
+
start.x + (end.x - start.x) * t1,
|
|
1525
|
+
start.y + (end.y - start.y) * t1
|
|
1526
|
+
);
|
|
1527
|
+
offset += 2;
|
|
1528
|
+
}
|
|
1529
|
+
consumed += step;
|
|
1530
|
+
distance += step;
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
1533
|
+
return offset / 2;
|
|
1534
|
+
};
|
|
1535
|
+
var getSeriesPoint = (visiblePoints, animatedPoint, index) => {
|
|
1536
|
+
if (animatedPoint && index === animatedPoint.index) {
|
|
1537
|
+
return { x: animatedPoint.x, y: animatedPoint.y };
|
|
1538
|
+
}
|
|
1539
|
+
return { x: visiblePoints.x[index], y: visiblePoints.y[index] };
|
|
1540
|
+
};
|
|
1541
|
+
var getSinglePointSegment = ({ series, state, yRange, plot }) => {
|
|
1542
|
+
if (series.length !== 1) return null;
|
|
1543
|
+
const x = series.rawX[0];
|
|
1544
|
+
const y = series.rawY[0];
|
|
1545
|
+
if (x < state.xMin || x > state.xMax || y < yRange.minY || y > yRange.maxY) {
|
|
1546
|
+
return null;
|
|
1547
|
+
}
|
|
1548
|
+
const halfWidth = (state.xMax - state.xMin) / Math.max(1, plot.width) * 3;
|
|
1549
|
+
return {
|
|
1550
|
+
x: new Float64Array([x - halfWidth, x + halfWidth]),
|
|
1551
|
+
y: new Float32Array([y, y]),
|
|
1552
|
+
bucketSize: 1,
|
|
1553
|
+
pointCount: 2,
|
|
1554
|
+
endpoint: { x, y }
|
|
1555
|
+
};
|
|
1556
|
+
};
|
|
1557
|
+
var writeAntialiasVertex = (vertices, offset, start, end, side, along) => {
|
|
1558
|
+
vertices[offset] = start.x;
|
|
1559
|
+
vertices[offset + 1] = start.y;
|
|
1560
|
+
vertices[offset + 2] = end.x;
|
|
1561
|
+
vertices[offset + 3] = end.y;
|
|
1562
|
+
vertices[offset + 4] = side;
|
|
1563
|
+
vertices[offset + 5] = along;
|
|
1564
|
+
};
|
|
1565
|
+
var fillAntialiasSeriesSegments = ({
|
|
1566
|
+
vertices,
|
|
1567
|
+
visiblePoints,
|
|
1568
|
+
pointCount,
|
|
1569
|
+
animatedPoint
|
|
1570
|
+
}) => {
|
|
1571
|
+
let offset = 0;
|
|
1572
|
+
for (let i = 0; i < pointCount - 1; i += 1) {
|
|
1573
|
+
const start = getSeriesPoint(visiblePoints, animatedPoint, i);
|
|
1574
|
+
const end = getSeriesPoint(visiblePoints, animatedPoint, i + 1);
|
|
1575
|
+
writeAntialiasVertex(vertices, offset, start, end, -1, 0);
|
|
1576
|
+
offset += AA_VERTEX_FLOAT_STRIDE;
|
|
1577
|
+
writeAntialiasVertex(vertices, offset, start, end, 1, 0);
|
|
1578
|
+
offset += AA_VERTEX_FLOAT_STRIDE;
|
|
1579
|
+
writeAntialiasVertex(vertices, offset, start, end, -1, 1);
|
|
1580
|
+
offset += AA_VERTEX_FLOAT_STRIDE;
|
|
1581
|
+
writeAntialiasVertex(vertices, offset, start, end, -1, 1);
|
|
1582
|
+
offset += AA_VERTEX_FLOAT_STRIDE;
|
|
1583
|
+
writeAntialiasVertex(vertices, offset, start, end, 1, 0);
|
|
1584
|
+
offset += AA_VERTEX_FLOAT_STRIDE;
|
|
1585
|
+
writeAntialiasVertex(vertices, offset, start, end, 1, 1);
|
|
1586
|
+
offset += AA_VERTEX_FLOAT_STRIDE;
|
|
1587
|
+
}
|
|
1588
|
+
return offset / AA_VERTEX_FLOAT_STRIDE;
|
|
1589
|
+
};
|
|
1590
|
+
var lowerBound2 = (array, value) => {
|
|
1591
|
+
let lo = 0;
|
|
1592
|
+
let hi = array.length;
|
|
1593
|
+
while (lo < hi) {
|
|
1594
|
+
const mid = lo + hi >> 1;
|
|
1595
|
+
if (array[mid] < value) lo = mid + 1;
|
|
1596
|
+
else hi = mid;
|
|
1597
|
+
}
|
|
1598
|
+
return lo;
|
|
1599
|
+
};
|
|
1600
|
+
var getNearestPointIndex = (xValues, xValue) => {
|
|
1601
|
+
if (!xValues.length) return -1;
|
|
1602
|
+
const nextIndex = lowerBound2(xValues, xValue);
|
|
1603
|
+
if (nextIndex <= 0) return 0;
|
|
1604
|
+
if (nextIndex >= xValues.length) return xValues.length - 1;
|
|
1605
|
+
const previousIndex = nextIndex - 1;
|
|
1606
|
+
return Math.abs(xValues[nextIndex] - xValue) < Math.abs(xValue - xValues[previousIndex]) ? nextIndex : previousIndex;
|
|
1607
|
+
};
|
|
1608
|
+
var getChartXBounds = (chart) => {
|
|
1609
|
+
let minX = Infinity;
|
|
1610
|
+
let maxX = -Infinity;
|
|
1611
|
+
chart.series.forEach((series) => {
|
|
1612
|
+
if (series.length === 0) return;
|
|
1613
|
+
minX = Math.min(minX, series.rawX[0]);
|
|
1614
|
+
maxX = Math.max(maxX, series.rawX[series.length - 1]);
|
|
1615
|
+
});
|
|
1616
|
+
return { minX, maxX };
|
|
1617
|
+
};
|
|
1618
|
+
var getOrderedSeries = (chart, seriesOrderByChart) => {
|
|
1619
|
+
const series = Array.isArray(chart?.series) ? chart.series : [];
|
|
1620
|
+
const order = seriesOrderByChart?.[chart?.id];
|
|
1621
|
+
if (!Array.isArray(order) || order.length !== series.length) {
|
|
1622
|
+
return series;
|
|
1623
|
+
}
|
|
1624
|
+
const used = /* @__PURE__ */ new Set();
|
|
1625
|
+
const ordered = [];
|
|
1626
|
+
order.forEach((seriesIndex) => {
|
|
1627
|
+
if (!Number.isInteger(seriesIndex)) return;
|
|
1628
|
+
if (seriesIndex < 0 || seriesIndex >= series.length) return;
|
|
1629
|
+
if (used.has(seriesIndex)) return;
|
|
1630
|
+
used.add(seriesIndex);
|
|
1631
|
+
ordered.push(series[seriesIndex]);
|
|
1632
|
+
});
|
|
1633
|
+
if (ordered.length !== series.length) return series;
|
|
1634
|
+
return ordered;
|
|
1635
|
+
};
|
|
1636
|
+
var normalizeMovingAverage = (movingAverage) => {
|
|
1637
|
+
if (!movingAverage?.enabled) return null;
|
|
1638
|
+
return {
|
|
1639
|
+
enabled: true,
|
|
1640
|
+
period: Number.isFinite(Number(movingAverage.period)) ? Math.max(1, Math.round(Number(movingAverage.period))) : 21,
|
|
1641
|
+
type: movingAverage.type === "sma" ? "sma" : "ema"
|
|
1642
|
+
};
|
|
1643
|
+
};
|
|
1644
|
+
var getMovingAverageCacheKey = (series, movingAverage) => `${series.id}::ma:${movingAverage.type}:${movingAverage.period}`;
|
|
1645
|
+
var calculateMovingAverageChunk = ({
|
|
1646
|
+
sourceY,
|
|
1647
|
+
startIndex,
|
|
1648
|
+
period,
|
|
1649
|
+
type,
|
|
1650
|
+
previousAverage
|
|
1651
|
+
}) => {
|
|
1652
|
+
const out = new Float32Array(Math.max(0, sourceY.length - startIndex));
|
|
1653
|
+
if (out.length === 0) return out;
|
|
1654
|
+
if (type === "sma") {
|
|
1655
|
+
let sum = 0;
|
|
1656
|
+
const firstWindowStart = Math.max(0, startIndex - period + 1);
|
|
1657
|
+
for (let i = firstWindowStart; i < startIndex; i += 1) {
|
|
1658
|
+
sum += sourceY[i];
|
|
1659
|
+
}
|
|
1660
|
+
for (let sourceIndex = startIndex; sourceIndex < sourceY.length; sourceIndex += 1) {
|
|
1661
|
+
sum += sourceY[sourceIndex];
|
|
1662
|
+
const removeIndex = sourceIndex - period;
|
|
1663
|
+
if (removeIndex >= firstWindowStart) {
|
|
1664
|
+
sum -= sourceY[removeIndex];
|
|
1665
|
+
}
|
|
1666
|
+
const safePeriod = Math.min(period, sourceIndex + 1);
|
|
1667
|
+
out[sourceIndex - startIndex] = sum / safePeriod;
|
|
1668
|
+
}
|
|
1669
|
+
return out;
|
|
1670
|
+
}
|
|
1671
|
+
const multiplier = 2 / (period + 1);
|
|
1672
|
+
let prev = Number.isFinite(previousAverage) ? previousAverage : sourceY[startIndex];
|
|
1673
|
+
for (let sourceIndex = startIndex; sourceIndex < sourceY.length; sourceIndex += 1) {
|
|
1674
|
+
prev = sourceY[sourceIndex] * multiplier + prev * (1 - multiplier);
|
|
1675
|
+
out[sourceIndex - startIndex] = prev;
|
|
1676
|
+
}
|
|
1677
|
+
return out;
|
|
1678
|
+
};
|
|
1679
|
+
var getMovingAverageSeriesForChart = ({
|
|
1680
|
+
chart,
|
|
1681
|
+
movingAverage,
|
|
1682
|
+
cache
|
|
1683
|
+
}) => {
|
|
1684
|
+
const normalized = normalizeMovingAverage(movingAverage);
|
|
1685
|
+
if (!normalized || !cache) return [];
|
|
1686
|
+
return chart.series.map((series) => {
|
|
1687
|
+
if (series.length === 0) return null;
|
|
1688
|
+
const cacheKey = getMovingAverageCacheKey(series, normalized);
|
|
1689
|
+
const cached = cache.get(cacheKey);
|
|
1690
|
+
if (cached && cached.sourceSeries === series && cached.sourceLength <= series.length) {
|
|
1691
|
+
const appendStart = cached.sourceLength;
|
|
1692
|
+
if (appendStart < series.length) {
|
|
1693
|
+
const appendedY = calculateMovingAverageChunk({
|
|
1694
|
+
sourceY: series.rawY.subarray(0, series.length),
|
|
1695
|
+
startIndex: appendStart,
|
|
1696
|
+
period: normalized.period,
|
|
1697
|
+
type: normalized.type,
|
|
1698
|
+
previousAverage: appendStart > 0 ? cached.series.rawY[appendStart - 1] : void 0
|
|
1699
|
+
});
|
|
1700
|
+
cached.series.append(
|
|
1701
|
+
series.rawX.subarray(appendStart, series.length),
|
|
1702
|
+
appendedY
|
|
1703
|
+
);
|
|
1704
|
+
cached.sourceLength = series.length;
|
|
1705
|
+
}
|
|
1706
|
+
cached.series.color = series.color;
|
|
1707
|
+
cached.series.name = `${series.name} ${normalized.type.toUpperCase()} ${normalized.period}`;
|
|
1708
|
+
return cached.series;
|
|
1709
|
+
}
|
|
1710
|
+
const y = calculateMovingAverageChunk({
|
|
1711
|
+
sourceY: series.rawY.subarray(0, series.length),
|
|
1712
|
+
startIndex: 0,
|
|
1713
|
+
period: normalized.period,
|
|
1714
|
+
type: normalized.type
|
|
1715
|
+
});
|
|
1716
|
+
const maSeries = createSeries({
|
|
1717
|
+
id: cacheKey,
|
|
1718
|
+
name: `${series.name} ${normalized.type.toUpperCase()} ${normalized.period}`,
|
|
1719
|
+
color: series.color,
|
|
1720
|
+
x: series.rawX.subarray(0, series.length),
|
|
1721
|
+
y
|
|
1722
|
+
});
|
|
1723
|
+
cache.set(cacheKey, {
|
|
1724
|
+
sourceSeries: series,
|
|
1725
|
+
sourceLength: series.length,
|
|
1726
|
+
series: maSeries
|
|
1727
|
+
});
|
|
1728
|
+
return maSeries;
|
|
1729
|
+
}).filter(Boolean);
|
|
1730
|
+
};
|
|
1731
|
+
var getInitialView = (chart, initialVisiblePoints = null) => {
|
|
1732
|
+
const { minX, maxX } = getChartXBounds(chart);
|
|
1733
|
+
if (!Number.isFinite(minX) || !Number.isFinite(maxX)) {
|
|
1734
|
+
return { xMin: 0, xMax: 1 };
|
|
1735
|
+
}
|
|
1736
|
+
if (minX === maxX) {
|
|
1737
|
+
const span2 = Number.isFinite(initialVisiblePoints) && initialVisiblePoints > 0 ? Math.max(10, initialVisiblePoints) : 10;
|
|
1738
|
+
const rightPadding2 = span2 * JUMP_LATEST_RIGHT_PADDING_RATIO;
|
|
1739
|
+
const nextMax = maxX + rightPadding2;
|
|
1740
|
+
return { xMin: nextMax - span2, xMax: nextMax };
|
|
1741
|
+
}
|
|
1742
|
+
let span = maxX - minX;
|
|
1743
|
+
if (Number.isFinite(initialVisiblePoints) && initialVisiblePoints > 0) {
|
|
1744
|
+
span = Math.min(span, initialVisiblePoints);
|
|
1745
|
+
const rightPadding2 = span * JUMP_LATEST_RIGHT_PADDING_RATIO;
|
|
1746
|
+
const nextMax = maxX + rightPadding2;
|
|
1747
|
+
return { xMin: nextMax - span, xMax: nextMax };
|
|
1748
|
+
}
|
|
1749
|
+
const rightPadding = span * JUMP_LATEST_RIGHT_PADDING_RATIO;
|
|
1750
|
+
return { xMin: minX, xMax: maxX + rightPadding };
|
|
1751
|
+
};
|
|
1752
|
+
var getYRange = (chart, xMin, xMax, width) => {
|
|
1753
|
+
let minY = Infinity;
|
|
1754
|
+
let maxY = -Infinity;
|
|
1755
|
+
let renderedPoints = 0;
|
|
1756
|
+
let bucketSize = 1;
|
|
1757
|
+
chart.series.forEach((series) => {
|
|
1758
|
+
const visible = series.getVisiblePoints(xMin, xMax, width);
|
|
1759
|
+
renderedPoints += visible.pointCount;
|
|
1760
|
+
bucketSize = Math.max(bucketSize, visible.bucketSize);
|
|
1761
|
+
for (let i = 0; i < visible.y.length; i += 1) {
|
|
1762
|
+
const value = visible.y[i];
|
|
1763
|
+
if (value < minY) minY = value;
|
|
1764
|
+
if (value > maxY) maxY = value;
|
|
1765
|
+
}
|
|
1766
|
+
});
|
|
1767
|
+
if (!Number.isFinite(minY) || !Number.isFinite(maxY)) {
|
|
1768
|
+
return { minY: 0, maxY: 1, renderedPoints, bucketSize };
|
|
1769
|
+
}
|
|
1770
|
+
if (minY === maxY) {
|
|
1771
|
+
minY -= 1;
|
|
1772
|
+
maxY += 1;
|
|
1773
|
+
}
|
|
1774
|
+
const pad = (maxY - minY) * 0.08;
|
|
1775
|
+
return { minY: minY - pad, maxY: maxY + pad, renderedPoints, bucketSize };
|
|
1776
|
+
};
|
|
1777
|
+
var applyYScale = (yRange, scale = 1, centerOffset = 0) => {
|
|
1778
|
+
const clampedScale = Math.min(Y_SCALE_MAX, Math.max(Y_SCALE_MIN, scale));
|
|
1779
|
+
const center = (yRange.minY + yRange.maxY) / 2 + centerOffset;
|
|
1780
|
+
const halfRange = (yRange.maxY - yRange.minY) * clampedScale / 2;
|
|
1781
|
+
return {
|
|
1782
|
+
...yRange,
|
|
1783
|
+
minY: center - halfRange,
|
|
1784
|
+
maxY: center + halfRange
|
|
1785
|
+
};
|
|
1786
|
+
};
|
|
1787
|
+
var getLatestYBounds = (chart) => {
|
|
1788
|
+
let minY = Infinity;
|
|
1789
|
+
let maxY = -Infinity;
|
|
1790
|
+
chart.series.forEach((series) => {
|
|
1791
|
+
if (series.length === 0) return;
|
|
1792
|
+
const value = series.rawY[series.length - 1];
|
|
1793
|
+
if (value < minY) minY = value;
|
|
1794
|
+
if (value > maxY) maxY = value;
|
|
1795
|
+
});
|
|
1796
|
+
return { minY, maxY };
|
|
1797
|
+
};
|
|
1798
|
+
var getPlotWidth = (node) => node ? Math.max(1, node.offsetWidth - PLOT_PADDING.left - PLOT_PADDING.right) : 1;
|
|
1799
|
+
var trimFormattedNumber = (value) => value.replace(/(\.\d*?)0+$/, "$1").replace(/\.$/, "");
|
|
1800
|
+
var formatNumber = (value) => {
|
|
1801
|
+
if (!Number.isFinite(value)) return "";
|
|
1802
|
+
const abs = Math.abs(value);
|
|
1803
|
+
if (abs !== 0 && abs < 1e-4) return value.toExponential(2);
|
|
1804
|
+
if (abs < 1) return trimFormattedNumber(value.toPrecision(5));
|
|
1805
|
+
if (abs >= 1e5) return value.toFixed(0);
|
|
1806
|
+
if (abs >= 1e3) return trimFormattedNumber(value.toFixed(1));
|
|
1807
|
+
if (abs >= 10) return trimFormattedNumber(value.toFixed(2));
|
|
1808
|
+
return trimFormattedNumber(value.toFixed(4));
|
|
1809
|
+
};
|
|
1810
|
+
var formatCompactNumber = (value) => {
|
|
1811
|
+
if (!Number.isFinite(value)) return "";
|
|
1812
|
+
const abs = Math.abs(value);
|
|
1813
|
+
if (abs >= 1e9) return `${(value / 1e9).toFixed(abs >= 1e10 ? 0 : 1)}B`;
|
|
1814
|
+
if (abs >= 1e6) return `${(value / 1e6).toFixed(abs >= 1e7 ? 0 : 1)}M`;
|
|
1815
|
+
if (abs >= 1e3) return `${(value / 1e3).toFixed(abs >= 1e4 ? 0 : 1)}k`;
|
|
1816
|
+
return formatNumber(value);
|
|
1817
|
+
};
|
|
1818
|
+
var normalizeRect = (start, end) => {
|
|
1819
|
+
if (!start || !end) return null;
|
|
1820
|
+
const left = Math.min(start.x, end.x);
|
|
1821
|
+
const top = Math.min(start.y, end.y);
|
|
1822
|
+
return {
|
|
1823
|
+
left,
|
|
1824
|
+
top,
|
|
1825
|
+
width: Math.abs(end.x - start.x),
|
|
1826
|
+
height: Math.abs(end.y - start.y)
|
|
1827
|
+
};
|
|
1828
|
+
};
|
|
1829
|
+
var clampPointToPlot = (point, plot) => ({
|
|
1830
|
+
x: Math.min(plot.x + plot.width, Math.max(plot.x, point.x)),
|
|
1831
|
+
y: Math.min(plot.y + plot.height, Math.max(plot.y, point.y))
|
|
1832
|
+
});
|
|
1833
|
+
var applyRectangleZoom = ({
|
|
1834
|
+
chart,
|
|
1835
|
+
plot,
|
|
1836
|
+
start,
|
|
1837
|
+
end,
|
|
1838
|
+
initialVisiblePoints,
|
|
1839
|
+
viewStateRef,
|
|
1840
|
+
yScaleRef,
|
|
1841
|
+
yCenterOffsetRef,
|
|
1842
|
+
yManualScaleRef
|
|
1843
|
+
}) => {
|
|
1844
|
+
const clampedStart = clampPointToPlot(start, plot);
|
|
1845
|
+
const clampedEnd = clampPointToPlot(end, plot);
|
|
1846
|
+
const rect = normalizeRect(clampedStart, clampedEnd);
|
|
1847
|
+
if (!rect || rect.width < 6 || rect.height < 6) return false;
|
|
1848
|
+
const state = viewStateRef.current.get(chart.id) || getInitialView(chart, initialVisiblePoints);
|
|
1849
|
+
const currentYRange = applyYScale(
|
|
1850
|
+
getYRange(chart, state.xMin, state.xMax, plot.width),
|
|
1851
|
+
yScaleRef.current.get(chart.id) ?? 1,
|
|
1852
|
+
yCenterOffsetRef.current.get(chart.id) ?? 0
|
|
1853
|
+
);
|
|
1854
|
+
const leftRatio = (rect.left - plot.x) / plot.width;
|
|
1855
|
+
const rightRatio = (rect.left + rect.width - plot.x) / plot.width;
|
|
1856
|
+
const topRatio = (rect.top - plot.y) / plot.height;
|
|
1857
|
+
const bottomRatio = (rect.top + rect.height - plot.y) / plot.height;
|
|
1858
|
+
const nextMin = state.xMin + leftRatio * (state.xMax - state.xMin);
|
|
1859
|
+
const nextMax = state.xMin + rightRatio * (state.xMax - state.xMin);
|
|
1860
|
+
if (nextMax - nextMin < X_SCALE_MIN_SPAN) return false;
|
|
1861
|
+
const selectedMaxY = currentYRange.maxY - topRatio * (currentYRange.maxY - currentYRange.minY);
|
|
1862
|
+
const selectedMinY = currentYRange.maxY - bottomRatio * (currentYRange.maxY - currentYRange.minY);
|
|
1863
|
+
const selectedSpan = selectedMaxY - selectedMinY;
|
|
1864
|
+
if (!Number.isFinite(selectedSpan) || selectedSpan <= 0) return false;
|
|
1865
|
+
viewStateRef.current.set(chart.id, { xMin: nextMin, xMax: nextMax });
|
|
1866
|
+
const baseYRange = getYRange(chart, nextMin, nextMax, plot.width);
|
|
1867
|
+
const baseSpan = baseYRange.maxY - baseYRange.minY;
|
|
1868
|
+
if (Number.isFinite(baseSpan) && baseSpan > 0) {
|
|
1869
|
+
const selectedCenter = (selectedMinY + selectedMaxY) / 2;
|
|
1870
|
+
const baseCenter = (baseYRange.minY + baseYRange.maxY) / 2;
|
|
1871
|
+
const nextScale = Math.min(
|
|
1872
|
+
Y_SCALE_MAX,
|
|
1873
|
+
Math.max(Y_SCALE_MIN, selectedSpan / baseSpan)
|
|
1874
|
+
);
|
|
1875
|
+
yScaleRef.current.set(chart.id, nextScale);
|
|
1876
|
+
yCenterOffsetRef.current.set(chart.id, selectedCenter - baseCenter);
|
|
1877
|
+
yManualScaleRef.current.add(chart.id);
|
|
1878
|
+
}
|
|
1879
|
+
return true;
|
|
1880
|
+
};
|
|
1881
|
+
var getChartState = (chart, initialVisiblePoints, viewStateRef) => viewStateRef.current.get(chart.id) || getInitialView(chart, initialVisiblePoints);
|
|
1882
|
+
var getScaledYRangeForLayout = ({
|
|
1883
|
+
chart,
|
|
1884
|
+
state,
|
|
1885
|
+
plot,
|
|
1886
|
+
yScaleRef,
|
|
1887
|
+
yCenterOffsetRef
|
|
1888
|
+
}) => applyYScale(
|
|
1889
|
+
getYRange(chart, state.xMin, state.xMax, plot.width),
|
|
1890
|
+
yScaleRef.current.get(chart.id) ?? 1,
|
|
1891
|
+
yCenterOffsetRef.current.get(chart.id) ?? 0
|
|
1892
|
+
);
|
|
1893
|
+
var screenPointToDataPoint = ({
|
|
1894
|
+
point,
|
|
1895
|
+
chart,
|
|
1896
|
+
plot,
|
|
1897
|
+
initialVisiblePoints,
|
|
1898
|
+
viewStateRef,
|
|
1899
|
+
yScaleRef,
|
|
1900
|
+
yCenterOffsetRef
|
|
1901
|
+
}) => {
|
|
1902
|
+
const state = getChartState(chart, initialVisiblePoints, viewStateRef);
|
|
1903
|
+
const yRange = getScaledYRangeForLayout({
|
|
1904
|
+
chart,
|
|
1905
|
+
state,
|
|
1906
|
+
plot,
|
|
1907
|
+
yScaleRef,
|
|
1908
|
+
yCenterOffsetRef
|
|
1909
|
+
});
|
|
1910
|
+
const xRatio = (point.x - plot.x) / plot.width;
|
|
1911
|
+
const yRatio = (point.y - plot.y) / plot.height;
|
|
1912
|
+
return {
|
|
1913
|
+
x: state.xMin + xRatio * (state.xMax - state.xMin),
|
|
1914
|
+
y: yRange.maxY - yRatio * (yRange.maxY - yRange.minY)
|
|
1915
|
+
};
|
|
1916
|
+
};
|
|
1917
|
+
var dataPointToScreenPoint = ({ point, state, yRange, plot }) => {
|
|
1918
|
+
const xRatio = (point.x - state.xMin) / (state.xMax - state.xMin);
|
|
1919
|
+
const yRatio = (yRange.maxY - point.y) / (yRange.maxY - yRange.minY);
|
|
1920
|
+
return {
|
|
1921
|
+
x: plot.x + xRatio * plot.width,
|
|
1922
|
+
y: plot.y + yRatio * plot.height
|
|
1923
|
+
};
|
|
1924
|
+
};
|
|
1925
|
+
var projectDataPointToScreenPoint = ({
|
|
1926
|
+
point,
|
|
1927
|
+
layout,
|
|
1928
|
+
initialVisiblePoints,
|
|
1929
|
+
viewStateRef,
|
|
1930
|
+
yScaleRef,
|
|
1931
|
+
yCenterOffsetRef
|
|
1932
|
+
}) => {
|
|
1933
|
+
const state = getChartState(layout.chart, initialVisiblePoints, viewStateRef);
|
|
1934
|
+
const yRange = getScaledYRangeForLayout({
|
|
1935
|
+
chart: layout.chart,
|
|
1936
|
+
state,
|
|
1937
|
+
plot: layout.plot,
|
|
1938
|
+
yScaleRef,
|
|
1939
|
+
yCenterOffsetRef
|
|
1940
|
+
});
|
|
1941
|
+
return dataPointToScreenPoint({
|
|
1942
|
+
point,
|
|
1943
|
+
state,
|
|
1944
|
+
yRange,
|
|
1945
|
+
plot: layout.plot
|
|
1946
|
+
});
|
|
1947
|
+
};
|
|
1948
|
+
var createAxisOverlay = ({
|
|
1949
|
+
chart,
|
|
1950
|
+
plot,
|
|
1951
|
+
state,
|
|
1952
|
+
yRange,
|
|
1953
|
+
seriesEndpoints,
|
|
1954
|
+
seriesOrderByChart = {}
|
|
1955
|
+
}) => {
|
|
1956
|
+
const { maxX } = getChartXBounds(chart);
|
|
1957
|
+
const ticks = Array.from({ length: Y_AXIS_TICK_COUNT }, (_, index) => {
|
|
1958
|
+
const ratio = Y_AXIS_TICK_COUNT === 1 ? 0 : index / (Y_AXIS_TICK_COUNT - 1);
|
|
1959
|
+
const value = yRange.maxY - ratio * (yRange.maxY - yRange.minY);
|
|
1960
|
+
return {
|
|
1961
|
+
id: `${chart.id}-tick-${index}`,
|
|
1962
|
+
value,
|
|
1963
|
+
top: ratio * plot.height
|
|
1964
|
+
};
|
|
1965
|
+
});
|
|
1966
|
+
const xTicks = Array.from({ length: X_AXIS_TICK_COUNT }, (_, index) => {
|
|
1967
|
+
const ratio = X_AXIS_TICK_COUNT === 1 ? 0 : index / (X_AXIS_TICK_COUNT - 1);
|
|
1968
|
+
return {
|
|
1969
|
+
id: `${chart.id}-x-tick-${index}`,
|
|
1970
|
+
value: state.xMin + ratio * (state.xMax - state.xMin),
|
|
1971
|
+
left: 18 + ratio * Math.max(1, plot.width - 36)
|
|
1972
|
+
};
|
|
1973
|
+
});
|
|
1974
|
+
const latestValues = getOrderedSeries(chart, seriesOrderByChart).map((series) => {
|
|
1975
|
+
if (series.length === 0) return null;
|
|
1976
|
+
const value = series.rawY[series.length - 1];
|
|
1977
|
+
const x = series.rawX[series.length - 1];
|
|
1978
|
+
const endpoint = seriesEndpoints.get(series.id) || { x, y: value };
|
|
1979
|
+
const ratio = (yRange.maxY - endpoint.y) / (yRange.maxY - yRange.minY);
|
|
1980
|
+
const xRatio = (endpoint.x - state.xMin) / (state.xMax - state.xMin);
|
|
1981
|
+
return {
|
|
1982
|
+
id: series.id,
|
|
1983
|
+
color: series.color,
|
|
1984
|
+
textColor: getSeriesLabelTextColor(series),
|
|
1985
|
+
value: endpoint.y,
|
|
1986
|
+
rawValue: value,
|
|
1987
|
+
x,
|
|
1988
|
+
left: xRatio * plot.width,
|
|
1989
|
+
top: ratio * plot.height
|
|
1990
|
+
};
|
|
1991
|
+
}).filter(
|
|
1992
|
+
(value) => value && Number.isFinite(value.top) && value.top >= -10 && value.top <= plot.height + 10
|
|
1993
|
+
);
|
|
1994
|
+
return {
|
|
1995
|
+
ticks,
|
|
1996
|
+
xTicks,
|
|
1997
|
+
latestValues,
|
|
1998
|
+
plotWidth: plot.width,
|
|
1999
|
+
showJumpLatest: Number.isFinite(maxX) && (maxX < state.xMin || maxX > state.xMax)
|
|
2000
|
+
};
|
|
2001
|
+
};
|
|
2002
|
+
function ChartCell({
|
|
2003
|
+
chart,
|
|
2004
|
+
setRef,
|
|
2005
|
+
axisOverlay,
|
|
2006
|
+
focused,
|
|
2007
|
+
onFocus,
|
|
2008
|
+
onFullscreenToggle,
|
|
2009
|
+
onReset,
|
|
2010
|
+
onJumpLatest,
|
|
2011
|
+
onRectangleZoomToggle,
|
|
2012
|
+
rectangleZoomActive = false,
|
|
2013
|
+
movingAverage = null,
|
|
2014
|
+
onMovingAverageToggle,
|
|
2015
|
+
activeDrawingTool = null,
|
|
2016
|
+
onDrawingToolToggle,
|
|
2017
|
+
hasDrawings = false,
|
|
2018
|
+
onClearDrawingsRequest,
|
|
2019
|
+
height = CHART_HEIGHT,
|
|
2020
|
+
isFullscreen = false,
|
|
2021
|
+
backgroundColor = DEFAULT_CHART_BACKGROUND
|
|
2022
|
+
}) {
|
|
2023
|
+
const headerBackground = withAlpha(backgroundColor, 0.82);
|
|
2024
|
+
const controlBackground = withAlpha(backgroundColor, 0.78);
|
|
2025
|
+
const mutedControlBackground = withAlpha(backgroundColor, 0.7);
|
|
2026
|
+
const jumpLatestStyle = typeof height === "number" ? {
|
|
2027
|
+
right: RIGHT_AXIS_WIDTH + 6,
|
|
2028
|
+
top: height - PLOT_PADDING.bottom - 34
|
|
2029
|
+
} : {
|
|
2030
|
+
right: RIGHT_AXIS_WIDTH + 6,
|
|
2031
|
+
bottom: PLOT_PADDING.bottom + 6
|
|
2032
|
+
};
|
|
2033
|
+
return /* @__PURE__ */ import_react9.default.createElement(
|
|
2034
|
+
"div",
|
|
2035
|
+
{
|
|
2036
|
+
ref: setRef,
|
|
2037
|
+
className: "relative select-none overflow-hidden rounded-sm",
|
|
2038
|
+
style: { height, backgroundColor },
|
|
2039
|
+
onPointerDown: () => onFocus(chart.id)
|
|
2040
|
+
},
|
|
2041
|
+
/* @__PURE__ */ import_react9.default.createElement(
|
|
2042
|
+
"div",
|
|
2043
|
+
{
|
|
2044
|
+
className: "pointer-events-none absolute inset-x-0 top-0 z-10 flex h-8 items-center justify-between px-2 backdrop-blur",
|
|
2045
|
+
style: { backgroundColor: headerBackground }
|
|
2046
|
+
},
|
|
2047
|
+
/* @__PURE__ */ import_react9.default.createElement(
|
|
2048
|
+
"div",
|
|
2049
|
+
{
|
|
2050
|
+
className: `flex min-w-0 items-center gap-1 rounded-sm px-1 text-sm font-semibold text-foreground ${focused ? "ring-1 ring-primary/70" : ""}`
|
|
2051
|
+
},
|
|
2052
|
+
chart.pinned ? /* @__PURE__ */ import_react9.default.createElement(
|
|
2053
|
+
import_react10.PushPinSimpleIcon,
|
|
2054
|
+
{
|
|
2055
|
+
size: 14,
|
|
2056
|
+
weight: "fill",
|
|
2057
|
+
className: "shrink-0 text-foreground/80"
|
|
2058
|
+
}
|
|
2059
|
+
) : null,
|
|
2060
|
+
/* @__PURE__ */ import_react9.default.createElement("span", { className: "truncate" }, chart.title)
|
|
2061
|
+
)
|
|
2062
|
+
),
|
|
2063
|
+
axisOverlay?.showJumpLatest ? /* @__PURE__ */ import_react9.default.createElement(
|
|
2064
|
+
"button",
|
|
2065
|
+
{
|
|
2066
|
+
type: "button",
|
|
2067
|
+
"aria-label": "Jump to latest",
|
|
2068
|
+
className: "absolute z-30 inline-flex size-7 items-center justify-center rounded-sm text-foreground hover:bg-accent hover:text-accent-foreground",
|
|
2069
|
+
style: {
|
|
2070
|
+
...jumpLatestStyle,
|
|
2071
|
+
backgroundColor: mutedControlBackground
|
|
2072
|
+
},
|
|
2073
|
+
onPointerDown: (event) => {
|
|
2074
|
+
event.preventDefault();
|
|
2075
|
+
event.stopPropagation();
|
|
2076
|
+
},
|
|
2077
|
+
onClick: (event) => {
|
|
2078
|
+
event.preventDefault();
|
|
2079
|
+
event.stopPropagation();
|
|
2080
|
+
onJumpLatest(chart.id);
|
|
2081
|
+
}
|
|
2082
|
+
},
|
|
2083
|
+
/* @__PURE__ */ import_react9.default.createElement(import_react10.ArrowLineRightIcon, { size: 16, weight: "bold" })
|
|
2084
|
+
) : null,
|
|
2085
|
+
focused ? /* @__PURE__ */ import_react9.default.createElement(
|
|
2086
|
+
ChartToolbar,
|
|
2087
|
+
{
|
|
2088
|
+
isFullscreen,
|
|
2089
|
+
onFullscreenToggle,
|
|
2090
|
+
onReset: () => onReset?.(chart.id),
|
|
2091
|
+
onRectangleZoomToggle: () => onRectangleZoomToggle?.(chart.id),
|
|
2092
|
+
rectangleZoomActive,
|
|
2093
|
+
onMovingAverageToggle: () => onMovingAverageToggle?.(chart.id),
|
|
2094
|
+
movingAverageActive: Boolean(movingAverage?.enabled),
|
|
2095
|
+
activeDrawingTool,
|
|
2096
|
+
onDrawingToolToggle,
|
|
2097
|
+
hasDrawings,
|
|
2098
|
+
onClearDrawingsRequest: () => onClearDrawingsRequest?.(chart.id)
|
|
2099
|
+
}
|
|
2100
|
+
) : null,
|
|
2101
|
+
/* @__PURE__ */ import_react9.default.createElement("div", { className: "pointer-events-none absolute inset-y-8 left-9 border-l border-border/40" }),
|
|
2102
|
+
axisOverlay?.latestValues.map(
|
|
2103
|
+
(latest) => latest.left >= 0 && latest.left <= axisOverlay.plotWidth ? /* @__PURE__ */ import_react9.default.createElement(
|
|
2104
|
+
"div",
|
|
2105
|
+
{
|
|
2106
|
+
key: `${latest.id}-connector`,
|
|
2107
|
+
className: "pointer-events-none absolute z-10 opacity-70",
|
|
2108
|
+
style: {
|
|
2109
|
+
left: PLOT_PADDING.left + latest.left,
|
|
2110
|
+
top: PLOT_PADDING.top + latest.top,
|
|
2111
|
+
height: 1,
|
|
2112
|
+
width: Math.max(0, axisOverlay.plotWidth - latest.left),
|
|
2113
|
+
backgroundImage: `repeating-linear-gradient(to right, ${latest.color} 0 4px, transparent 4px 8px)`
|
|
2114
|
+
}
|
|
2115
|
+
}
|
|
2116
|
+
) : null
|
|
2117
|
+
),
|
|
2118
|
+
/* @__PURE__ */ import_react9.default.createElement(
|
|
2119
|
+
"div",
|
|
2120
|
+
{
|
|
2121
|
+
className: "absolute right-0 z-20 cursor-ns-resize",
|
|
2122
|
+
style: {
|
|
2123
|
+
top: PLOT_PADDING.top,
|
|
2124
|
+
bottom: PLOT_PADDING.bottom,
|
|
2125
|
+
width: RIGHT_AXIS_WIDTH,
|
|
2126
|
+
backgroundColor: controlBackground,
|
|
2127
|
+
cursor: "ns-resize"
|
|
2128
|
+
}
|
|
2129
|
+
},
|
|
2130
|
+
axisOverlay?.ticks.map((tick) => /* @__PURE__ */ import_react9.default.createElement(
|
|
2131
|
+
"div",
|
|
2132
|
+
{
|
|
2133
|
+
key: tick.id,
|
|
2134
|
+
className: "pointer-events-none absolute left-1/2 -translate-x-1/2 -translate-y-1/2 text-center text-[11px] font-medium tabular-nums text-foreground/70 dark:text-foreground/80",
|
|
2135
|
+
style: { top: tick.top }
|
|
2136
|
+
},
|
|
2137
|
+
formatNumber(tick.value)
|
|
2138
|
+
)),
|
|
2139
|
+
axisOverlay?.latestValues.map((latest) => /* @__PURE__ */ import_react9.default.createElement(
|
|
2140
|
+
"div",
|
|
2141
|
+
{
|
|
2142
|
+
key: latest.id,
|
|
2143
|
+
className: "pointer-events-none absolute left-1/2 -translate-x-1/2 -translate-y-1/2 rounded-sm px-1.5 py-0.5 text-center text-[10px] font-bold tabular-nums shadow-sm",
|
|
2144
|
+
style: {
|
|
2145
|
+
top: latest.top,
|
|
2146
|
+
backgroundColor: latest.color,
|
|
2147
|
+
color: latest.textColor
|
|
2148
|
+
}
|
|
2149
|
+
},
|
|
2150
|
+
formatNumber(latest.value)
|
|
2151
|
+
))
|
|
2152
|
+
),
|
|
2153
|
+
/* @__PURE__ */ import_react9.default.createElement(
|
|
2154
|
+
"div",
|
|
2155
|
+
{
|
|
2156
|
+
className: "absolute bottom-0 z-20 cursor-ew-resize",
|
|
2157
|
+
style: {
|
|
2158
|
+
left: PLOT_PADDING.left,
|
|
2159
|
+
right: RIGHT_AXIS_WIDTH,
|
|
2160
|
+
height: PLOT_PADDING.bottom,
|
|
2161
|
+
backgroundColor: mutedControlBackground,
|
|
2162
|
+
cursor: "ew-resize"
|
|
2163
|
+
}
|
|
2164
|
+
},
|
|
2165
|
+
axisOverlay?.xTicks.map((tick) => /* @__PURE__ */ import_react9.default.createElement(
|
|
2166
|
+
"div",
|
|
2167
|
+
{
|
|
2168
|
+
key: tick.id,
|
|
2169
|
+
className: "pointer-events-none absolute top-1/2 -translate-x-1/2 -translate-y-1/2 text-center text-[11px] font-medium tabular-nums text-foreground/70 dark:text-foreground/80",
|
|
2170
|
+
style: { left: tick.left }
|
|
2171
|
+
},
|
|
2172
|
+
formatCompactNumber(tick.value)
|
|
2173
|
+
))
|
|
2174
|
+
)
|
|
2175
|
+
);
|
|
2176
|
+
}
|
|
2177
|
+
function CrosshairOverlay({
|
|
2178
|
+
crosshair,
|
|
2179
|
+
height = "100%",
|
|
2180
|
+
xAxisLabel = "STEP"
|
|
2181
|
+
}) {
|
|
2182
|
+
if (!crosshair) return null;
|
|
2183
|
+
return /* @__PURE__ */ import_react9.default.createElement(import_react9.default.Fragment, null, /* @__PURE__ */ import_react9.default.createElement(
|
|
2184
|
+
"div",
|
|
2185
|
+
{
|
|
2186
|
+
className: "pointer-events-none absolute z-20 border-l border-foreground/40",
|
|
2187
|
+
style: {
|
|
2188
|
+
left: crosshair.x,
|
|
2189
|
+
top: 0,
|
|
2190
|
+
height
|
|
2191
|
+
}
|
|
2192
|
+
}
|
|
2193
|
+
), /* @__PURE__ */ import_react9.default.createElement(
|
|
2194
|
+
"div",
|
|
2195
|
+
{
|
|
2196
|
+
className: "pointer-events-none absolute z-20 border-t border-foreground/40",
|
|
2197
|
+
style: { left: 0, top: crosshair.y, width: "100%" }
|
|
2198
|
+
}
|
|
2199
|
+
), crosshair.points.map((point) => /* @__PURE__ */ import_react9.default.createElement(
|
|
2200
|
+
"div",
|
|
2201
|
+
{
|
|
2202
|
+
key: point.id,
|
|
2203
|
+
className: "pointer-events-none absolute z-30 size-2.5 -translate-x-1/2 -translate-y-1/2 rounded-full border border-background shadow-sm",
|
|
2204
|
+
style: {
|
|
2205
|
+
left: point.x,
|
|
2206
|
+
top: point.y,
|
|
2207
|
+
backgroundColor: point.color
|
|
2208
|
+
}
|
|
2209
|
+
}
|
|
2210
|
+
)), /* @__PURE__ */ import_react9.default.createElement(
|
|
2211
|
+
"div",
|
|
2212
|
+
{
|
|
2213
|
+
className: "pointer-events-none absolute z-30 w-[220px] rounded-sm border border-border bg-popover px-2 py-1.5 text-xs text-popover-foreground shadow-sm",
|
|
2214
|
+
style: {
|
|
2215
|
+
left: crosshair.tooltipX,
|
|
2216
|
+
top: crosshair.tooltipY
|
|
2217
|
+
}
|
|
2218
|
+
},
|
|
2219
|
+
/* @__PURE__ */ import_react9.default.createElement("div", { className: "mb-1 font-medium" }, xAxisLabel, ": ", formatNumber(crosshair.xValue)),
|
|
2220
|
+
crosshair.points.map((point) => /* @__PURE__ */ import_react9.default.createElement(
|
|
2221
|
+
"div",
|
|
2222
|
+
{
|
|
2223
|
+
key: `${point.id}-tooltip`,
|
|
2224
|
+
className: "grid grid-cols-[auto_1fr] gap-x-2 gap-y-0.5"
|
|
2225
|
+
},
|
|
2226
|
+
/* @__PURE__ */ import_react9.default.createElement(
|
|
2227
|
+
"span",
|
|
2228
|
+
{
|
|
2229
|
+
className: "mt-1 size-2 rounded-full",
|
|
2230
|
+
style: { backgroundColor: point.color }
|
|
2231
|
+
}
|
|
2232
|
+
),
|
|
2233
|
+
/* @__PURE__ */ import_react9.default.createElement("div", { className: "min-w-0" }, /* @__PURE__ */ import_react9.default.createElement("div", { className: "truncate text-muted-foreground" }, point.name), /* @__PURE__ */ import_react9.default.createElement("div", { className: "tabular-nums" }, formatNumber(point.yValue)))
|
|
2234
|
+
))
|
|
2235
|
+
));
|
|
2236
|
+
}
|
|
2237
|
+
function RectangleZoomOverlay({ rect }) {
|
|
2238
|
+
if (!rect) return null;
|
|
2239
|
+
const normalized = normalizeRect(rect.start, rect.end);
|
|
2240
|
+
if (!normalized) return null;
|
|
2241
|
+
return /* @__PURE__ */ import_react9.default.createElement(
|
|
2242
|
+
"div",
|
|
2243
|
+
{
|
|
2244
|
+
className: "pointer-events-none absolute z-40 rounded-sm border border-primary/70 bg-primary/10",
|
|
2245
|
+
style: {
|
|
2246
|
+
left: normalized.left,
|
|
2247
|
+
top: normalized.top,
|
|
2248
|
+
width: normalized.width,
|
|
2249
|
+
height: normalized.height
|
|
2250
|
+
}
|
|
2251
|
+
}
|
|
2252
|
+
);
|
|
2253
|
+
}
|
|
2254
|
+
function TopMarkersOverlay({
|
|
2255
|
+
layouts,
|
|
2256
|
+
markers,
|
|
2257
|
+
viewStateRef,
|
|
2258
|
+
initialVisiblePoints,
|
|
2259
|
+
onMarkerClick,
|
|
2260
|
+
height = "100%"
|
|
2261
|
+
}) {
|
|
2262
|
+
const safeMarkers = Array.isArray(markers) ? markers : [];
|
|
2263
|
+
if (!safeMarkers.length || !layouts.length) return null;
|
|
2264
|
+
const markerItems = layouts.flatMap((layout) => {
|
|
2265
|
+
const state = viewStateRef.current.get(layout.chart.id) || getInitialView(layout.chart, initialVisiblePoints);
|
|
2266
|
+
const span = state.xMax - state.xMin;
|
|
2267
|
+
if (!Number.isFinite(span) || span <= 0) return [];
|
|
2268
|
+
return safeMarkers.map((marker) => {
|
|
2269
|
+
const xValue = Number(marker?.x ?? marker?.step);
|
|
2270
|
+
if (!Number.isFinite(xValue)) return null;
|
|
2271
|
+
const ratio = (xValue - state.xMin) / span;
|
|
2272
|
+
if (ratio < 0 || ratio > 1) return null;
|
|
2273
|
+
return {
|
|
2274
|
+
marker,
|
|
2275
|
+
key: `${layout.chart.id}-${marker.id ?? xValue}-${xValue}`,
|
|
2276
|
+
left: layout.plot.x + ratio * layout.plot.width,
|
|
2277
|
+
top: layout.plot.y + 4
|
|
2278
|
+
};
|
|
2279
|
+
}).filter(Boolean);
|
|
2280
|
+
});
|
|
2281
|
+
if (!markerItems.length) return null;
|
|
2282
|
+
return /* @__PURE__ */ import_react9.default.createElement(
|
|
2283
|
+
"div",
|
|
2284
|
+
{
|
|
2285
|
+
className: "pointer-events-none absolute left-0 top-0 z-30",
|
|
2286
|
+
style: { width: "100%", height }
|
|
2287
|
+
},
|
|
2288
|
+
markerItems.map((item) => /* @__PURE__ */ import_react9.default.createElement(
|
|
2289
|
+
"button",
|
|
2290
|
+
{
|
|
2291
|
+
key: item.key,
|
|
2292
|
+
type: "button",
|
|
2293
|
+
className: "pointer-events-auto absolute -translate-x-1/2 rounded-full",
|
|
2294
|
+
style: { left: item.left, top: item.top },
|
|
2295
|
+
title: item.marker.title || "",
|
|
2296
|
+
"aria-label": item.marker.ariaLabel || item.marker.title || "Chart marker",
|
|
2297
|
+
onPointerDown: (event) => {
|
|
2298
|
+
event.stopPropagation();
|
|
2299
|
+
},
|
|
2300
|
+
onClick: (event) => {
|
|
2301
|
+
event.preventDefault();
|
|
2302
|
+
event.stopPropagation();
|
|
2303
|
+
onMarkerClick?.(item.marker);
|
|
2304
|
+
}
|
|
2305
|
+
},
|
|
2306
|
+
/* @__PURE__ */ import_react9.default.createElement(
|
|
2307
|
+
"span",
|
|
2308
|
+
{
|
|
2309
|
+
className: "block size-2.5 rounded-full border border-background shadow-sm",
|
|
2310
|
+
style: { backgroundColor: item.marker.color || "#f97316" }
|
|
2311
|
+
}
|
|
2312
|
+
)
|
|
2313
|
+
))
|
|
2314
|
+
);
|
|
2315
|
+
}
|
|
2316
|
+
var drawChartLayouts = ({
|
|
2317
|
+
canvas,
|
|
2318
|
+
width,
|
|
2319
|
+
height,
|
|
2320
|
+
gl,
|
|
2321
|
+
program,
|
|
2322
|
+
antialiasProgram,
|
|
2323
|
+
antialiasLines = false,
|
|
2324
|
+
layouts,
|
|
2325
|
+
viewStateRef,
|
|
2326
|
+
yScaleRef,
|
|
2327
|
+
yCenterOffsetRef,
|
|
2328
|
+
seriesBufferCache,
|
|
2329
|
+
antialiasSeriesBufferCache,
|
|
2330
|
+
initialVisiblePoints,
|
|
2331
|
+
getAppendAnimatedPoint,
|
|
2332
|
+
movingAverageByChart = EMPTY_OBJECT,
|
|
2333
|
+
movingAverageCache,
|
|
2334
|
+
seriesOrderByChart = EMPTY_OBJECT
|
|
2335
|
+
}) => {
|
|
2336
|
+
const dpr = Math.min(2, window.devicePixelRatio || 1);
|
|
2337
|
+
const pixelWidth = Math.max(1, Math.floor(width * dpr));
|
|
2338
|
+
const pixelHeight = Math.max(1, Math.floor(height * dpr));
|
|
2339
|
+
if (canvas.width !== pixelWidth || canvas.height !== pixelHeight) {
|
|
2340
|
+
canvas.width = pixelWidth;
|
|
2341
|
+
canvas.height = pixelHeight;
|
|
2342
|
+
canvas.style.width = `${width}px`;
|
|
2343
|
+
canvas.style.height = `${height}px`;
|
|
2344
|
+
}
|
|
2345
|
+
gl.viewport(0, 0, pixelWidth, pixelHeight);
|
|
2346
|
+
gl.clearColor(0, 0, 0, 0);
|
|
2347
|
+
gl.clear(gl.COLOR_BUFFER_BIT);
|
|
2348
|
+
const activeAntialiasLines = antialiasLines && antialiasProgram;
|
|
2349
|
+
const activeProgram = activeAntialiasLines ? antialiasProgram : program;
|
|
2350
|
+
gl.useProgram(activeProgram);
|
|
2351
|
+
const uResolution = gl.getUniformLocation(activeProgram, "u_resolution");
|
|
2352
|
+
const uRect = gl.getUniformLocation(activeProgram, "u_rect");
|
|
2353
|
+
const uXRange = gl.getUniformLocation(activeProgram, "u_xRange");
|
|
2354
|
+
const uYRange = gl.getUniformLocation(activeProgram, "u_yRange");
|
|
2355
|
+
const uColor = gl.getUniformLocation(activeProgram, "u_color");
|
|
2356
|
+
let aXy = -1;
|
|
2357
|
+
let aStart = -1;
|
|
2358
|
+
let aEnd = -1;
|
|
2359
|
+
let aSide = -1;
|
|
2360
|
+
let aAlong = -1;
|
|
2361
|
+
let uLineHalfWidth = null;
|
|
2362
|
+
let uEdgeWidth = null;
|
|
2363
|
+
if (activeAntialiasLines) {
|
|
2364
|
+
aStart = gl.getAttribLocation(activeProgram, "a_start");
|
|
2365
|
+
aEnd = gl.getAttribLocation(activeProgram, "a_end");
|
|
2366
|
+
aSide = gl.getAttribLocation(activeProgram, "a_side");
|
|
2367
|
+
aAlong = gl.getAttribLocation(activeProgram, "a_along");
|
|
2368
|
+
uLineHalfWidth = gl.getUniformLocation(activeProgram, "u_lineHalfWidth");
|
|
2369
|
+
uEdgeWidth = gl.getUniformLocation(activeProgram, "u_edgeWidth");
|
|
2370
|
+
gl.enableVertexAttribArray(aStart);
|
|
2371
|
+
gl.enableVertexAttribArray(aEnd);
|
|
2372
|
+
gl.enableVertexAttribArray(aSide);
|
|
2373
|
+
gl.enableVertexAttribArray(aAlong);
|
|
2374
|
+
gl.uniform1f(uLineHalfWidth, AA_LINE_WIDTH_PX * dpr / 2);
|
|
2375
|
+
gl.uniform1f(uEdgeWidth, AA_EDGE_WIDTH_PX * dpr);
|
|
2376
|
+
gl.enable(gl.BLEND);
|
|
2377
|
+
gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
|
|
2378
|
+
} else {
|
|
2379
|
+
aXy = gl.getAttribLocation(activeProgram, "a_xy");
|
|
2380
|
+
gl.enableVertexAttribArray(aXy);
|
|
2381
|
+
gl.disable(gl.BLEND);
|
|
2382
|
+
}
|
|
2383
|
+
gl.uniform2f(uResolution, pixelWidth, pixelHeight);
|
|
2384
|
+
const now = performance.now();
|
|
2385
|
+
const nextAxisOverlays = {};
|
|
2386
|
+
layouts.forEach(({ chart, plot, visible }) => {
|
|
2387
|
+
if (!visible) return;
|
|
2388
|
+
if (activeAntialiasLines) {
|
|
2389
|
+
gl.useProgram(activeProgram);
|
|
2390
|
+
gl.uniform2f(uResolution, pixelWidth, pixelHeight);
|
|
2391
|
+
}
|
|
2392
|
+
const state = viewStateRef.current.get(chart.id) || getInitialView(chart, initialVisiblePoints);
|
|
2393
|
+
const scaledPlot = {
|
|
2394
|
+
x: plot.x * dpr,
|
|
2395
|
+
y: plot.y * dpr,
|
|
2396
|
+
width: plot.width * dpr,
|
|
2397
|
+
height: plot.height * dpr
|
|
2398
|
+
};
|
|
2399
|
+
const yRange = applyYScale(
|
|
2400
|
+
getYRange(chart, state.xMin, state.xMax, plot.width),
|
|
2401
|
+
yScaleRef.current.get(chart.id) ?? 1,
|
|
2402
|
+
yCenterOffsetRef.current.get(chart.id) ?? 0
|
|
2403
|
+
);
|
|
2404
|
+
const seriesEndpoints = /* @__PURE__ */ new Map();
|
|
2405
|
+
const chartMovingAverage = movingAverageByChart?.[chart.id];
|
|
2406
|
+
const hideBaseSeries = Boolean(chartMovingAverage?.enabled) && Boolean(chartMovingAverage?.hideBase);
|
|
2407
|
+
gl.enable(gl.SCISSOR_TEST);
|
|
2408
|
+
gl.scissor(
|
|
2409
|
+
Math.floor(scaledPlot.x),
|
|
2410
|
+
Math.floor(pixelHeight - scaledPlot.y - scaledPlot.height),
|
|
2411
|
+
Math.ceil(scaledPlot.width),
|
|
2412
|
+
Math.ceil(scaledPlot.height)
|
|
2413
|
+
);
|
|
2414
|
+
gl.uniform4f(
|
|
2415
|
+
uRect,
|
|
2416
|
+
scaledPlot.x,
|
|
2417
|
+
scaledPlot.y,
|
|
2418
|
+
scaledPlot.width,
|
|
2419
|
+
scaledPlot.height
|
|
2420
|
+
);
|
|
2421
|
+
gl.uniform2f(uXRange, state.xMin, state.xMax);
|
|
2422
|
+
gl.uniform2f(uYRange, yRange.minY, yRange.maxY);
|
|
2423
|
+
if (!hideBaseSeries) getOrderedSeries(chart, seriesOrderByChart).forEach((series) => {
|
|
2424
|
+
let visiblePoints = series.getVisiblePoints(
|
|
2425
|
+
state.xMin,
|
|
2426
|
+
state.xMax,
|
|
2427
|
+
plot.width
|
|
2428
|
+
);
|
|
2429
|
+
let singlePointEndpoint = null;
|
|
2430
|
+
if (visiblePoints.pointCount < 2) {
|
|
2431
|
+
const singlePointSegment = getSinglePointSegment({
|
|
2432
|
+
series,
|
|
2433
|
+
state,
|
|
2434
|
+
yRange,
|
|
2435
|
+
plot
|
|
2436
|
+
});
|
|
2437
|
+
if (!singlePointSegment) return;
|
|
2438
|
+
visiblePoints = singlePointSegment;
|
|
2439
|
+
singlePointEndpoint = singlePointSegment.endpoint;
|
|
2440
|
+
}
|
|
2441
|
+
const animatedPoint = singlePointEndpoint ? null : getAppendAnimatedPoint({
|
|
2442
|
+
seriesId: series.id,
|
|
2443
|
+
visiblePoints,
|
|
2444
|
+
now
|
|
2445
|
+
});
|
|
2446
|
+
const pointCount = animatedPoint?.pointCount ?? visiblePoints.pointCount;
|
|
2447
|
+
if (animatedPoint) {
|
|
2448
|
+
seriesEndpoints.set(series.id, {
|
|
2449
|
+
x: animatedPoint.x,
|
|
2450
|
+
y: animatedPoint.y
|
|
2451
|
+
});
|
|
2452
|
+
} else if (singlePointEndpoint) {
|
|
2453
|
+
seriesEndpoints.set(series.id, singlePointEndpoint);
|
|
2454
|
+
}
|
|
2455
|
+
const [r, g, b] = hexToRgb(series.color);
|
|
2456
|
+
gl.uniform3f(uColor, r, g, b);
|
|
2457
|
+
if (activeAntialiasLines) {
|
|
2458
|
+
const bufferEntry2 = getAntialiasSeriesBuffer(
|
|
2459
|
+
gl,
|
|
2460
|
+
antialiasSeriesBufferCache,
|
|
2461
|
+
series.id,
|
|
2462
|
+
pointCount
|
|
2463
|
+
);
|
|
2464
|
+
const drawVertexCount = fillAntialiasSeriesSegments({
|
|
2465
|
+
vertices: bufferEntry2.vertices,
|
|
2466
|
+
visiblePoints,
|
|
2467
|
+
pointCount,
|
|
2468
|
+
animatedPoint
|
|
2469
|
+
});
|
|
2470
|
+
const stride = AA_VERTEX_FLOAT_STRIDE * Float32Array.BYTES_PER_ELEMENT;
|
|
2471
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, bufferEntry2.buffer);
|
|
2472
|
+
gl.vertexAttribPointer(aStart, 2, gl.FLOAT, false, stride, 0);
|
|
2473
|
+
gl.vertexAttribPointer(
|
|
2474
|
+
aEnd,
|
|
2475
|
+
2,
|
|
2476
|
+
gl.FLOAT,
|
|
2477
|
+
false,
|
|
2478
|
+
stride,
|
|
2479
|
+
2 * Float32Array.BYTES_PER_ELEMENT
|
|
2480
|
+
);
|
|
2481
|
+
gl.vertexAttribPointer(
|
|
2482
|
+
aSide,
|
|
2483
|
+
1,
|
|
2484
|
+
gl.FLOAT,
|
|
2485
|
+
false,
|
|
2486
|
+
stride,
|
|
2487
|
+
4 * Float32Array.BYTES_PER_ELEMENT
|
|
2488
|
+
);
|
|
2489
|
+
gl.vertexAttribPointer(
|
|
2490
|
+
aAlong,
|
|
2491
|
+
1,
|
|
2492
|
+
gl.FLOAT,
|
|
2493
|
+
false,
|
|
2494
|
+
stride,
|
|
2495
|
+
5 * Float32Array.BYTES_PER_ELEMENT
|
|
2496
|
+
);
|
|
2497
|
+
gl.bufferSubData(
|
|
2498
|
+
gl.ARRAY_BUFFER,
|
|
2499
|
+
0,
|
|
2500
|
+
bufferEntry2.vertices,
|
|
2501
|
+
0,
|
|
2502
|
+
drawVertexCount * AA_VERTEX_FLOAT_STRIDE
|
|
2503
|
+
);
|
|
2504
|
+
gl.drawArrays(gl.TRIANGLES, 0, drawVertexCount);
|
|
2505
|
+
return;
|
|
2506
|
+
}
|
|
2507
|
+
const bufferEntry = getSeriesBuffer(
|
|
2508
|
+
gl,
|
|
2509
|
+
seriesBufferCache,
|
|
2510
|
+
series.id,
|
|
2511
|
+
pointCount
|
|
2512
|
+
);
|
|
2513
|
+
fillSeriesPoints({
|
|
2514
|
+
vertices: bufferEntry.vertices,
|
|
2515
|
+
visiblePoints,
|
|
2516
|
+
pointCount,
|
|
2517
|
+
animatedPoint
|
|
2518
|
+
});
|
|
2519
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, bufferEntry.buffer);
|
|
2520
|
+
gl.vertexAttribPointer(aXy, 2, gl.FLOAT, false, 0, 0);
|
|
2521
|
+
gl.bufferSubData(
|
|
2522
|
+
gl.ARRAY_BUFFER,
|
|
2523
|
+
0,
|
|
2524
|
+
bufferEntry.vertices,
|
|
2525
|
+
0,
|
|
2526
|
+
pointCount * 2
|
|
2527
|
+
);
|
|
2528
|
+
gl.drawArrays(gl.LINE_STRIP, 0, pointCount);
|
|
2529
|
+
});
|
|
2530
|
+
const movingAverageSeries = getMovingAverageSeriesForChart({
|
|
2531
|
+
chart,
|
|
2532
|
+
movingAverage: chartMovingAverage,
|
|
2533
|
+
cache: movingAverageCache
|
|
2534
|
+
});
|
|
2535
|
+
const orderedMovingAverageSeries = getOrderedSeries(
|
|
2536
|
+
{ ...chart, series: movingAverageSeries },
|
|
2537
|
+
seriesOrderByChart
|
|
2538
|
+
);
|
|
2539
|
+
let maAXy = aXy;
|
|
2540
|
+
let maUColor = uColor;
|
|
2541
|
+
if (movingAverageSeries.length > 0 && activeAntialiasLines) {
|
|
2542
|
+
gl.useProgram(program);
|
|
2543
|
+
const maUResolution = gl.getUniformLocation(program, "u_resolution");
|
|
2544
|
+
const maURect = gl.getUniformLocation(program, "u_rect");
|
|
2545
|
+
const maUXRange = gl.getUniformLocation(program, "u_xRange");
|
|
2546
|
+
const maUYRange = gl.getUniformLocation(program, "u_yRange");
|
|
2547
|
+
maUColor = gl.getUniformLocation(program, "u_color");
|
|
2548
|
+
maAXy = gl.getAttribLocation(program, "a_xy");
|
|
2549
|
+
gl.enableVertexAttribArray(maAXy);
|
|
2550
|
+
gl.uniform2f(maUResolution, pixelWidth, pixelHeight);
|
|
2551
|
+
gl.uniform4f(
|
|
2552
|
+
maURect,
|
|
2553
|
+
scaledPlot.x,
|
|
2554
|
+
scaledPlot.y,
|
|
2555
|
+
scaledPlot.width,
|
|
2556
|
+
scaledPlot.height
|
|
2557
|
+
);
|
|
2558
|
+
gl.uniform2f(maUXRange, state.xMin, state.xMax);
|
|
2559
|
+
gl.uniform2f(maUYRange, yRange.minY, yRange.maxY);
|
|
2560
|
+
}
|
|
2561
|
+
orderedMovingAverageSeries.forEach((series) => {
|
|
2562
|
+
const visiblePoints = series.getVisiblePoints(
|
|
2563
|
+
state.xMin,
|
|
2564
|
+
state.xMax,
|
|
2565
|
+
plot.width
|
|
2566
|
+
);
|
|
2567
|
+
if (visiblePoints.pointCount < 2) return;
|
|
2568
|
+
const pointCount = visiblePoints.pointCount;
|
|
2569
|
+
const [r, g, b] = hexToRgb(series.color);
|
|
2570
|
+
gl.uniform3f(maUColor, r, g, b);
|
|
2571
|
+
const bufferEntry = getSeriesBuffer(
|
|
2572
|
+
gl,
|
|
2573
|
+
seriesBufferCache,
|
|
2574
|
+
series.id,
|
|
2575
|
+
pointCount * 8
|
|
2576
|
+
);
|
|
2577
|
+
const drawVertexCount = fillDashedSeriesSegments({
|
|
2578
|
+
vertices: bufferEntry.vertices,
|
|
2579
|
+
visiblePoints,
|
|
2580
|
+
pointCount,
|
|
2581
|
+
state,
|
|
2582
|
+
yRange,
|
|
2583
|
+
plot
|
|
2584
|
+
});
|
|
2585
|
+
if (drawVertexCount < 2) return;
|
|
2586
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, bufferEntry.buffer);
|
|
2587
|
+
gl.vertexAttribPointer(maAXy, 2, gl.FLOAT, false, 0, 0);
|
|
2588
|
+
gl.bufferSubData(
|
|
2589
|
+
gl.ARRAY_BUFFER,
|
|
2590
|
+
0,
|
|
2591
|
+
bufferEntry.vertices,
|
|
2592
|
+
0,
|
|
2593
|
+
drawVertexCount * 2
|
|
2594
|
+
);
|
|
2595
|
+
gl.drawArrays(gl.LINES, 0, drawVertexCount);
|
|
2596
|
+
});
|
|
2597
|
+
nextAxisOverlays[chart.id] = createAxisOverlay({
|
|
2598
|
+
chart,
|
|
2599
|
+
plot,
|
|
2600
|
+
state,
|
|
2601
|
+
yRange,
|
|
2602
|
+
seriesEndpoints,
|
|
2603
|
+
seriesOrderByChart
|
|
2604
|
+
});
|
|
2605
|
+
gl.disable(gl.SCISSOR_TEST);
|
|
2606
|
+
});
|
|
2607
|
+
if (activeAntialiasLines) {
|
|
2608
|
+
gl.disable(gl.BLEND);
|
|
2609
|
+
}
|
|
2610
|
+
return nextAxisOverlays;
|
|
2611
|
+
};
|
|
2612
|
+
function LeanChartFullscreenOverlay({
|
|
2613
|
+
chart,
|
|
2614
|
+
dataRevision,
|
|
2615
|
+
renderRevision,
|
|
2616
|
+
initialVisiblePoints,
|
|
2617
|
+
backgroundColor,
|
|
2618
|
+
antialiasLines = false,
|
|
2619
|
+
getAppendAnimatedPoint,
|
|
2620
|
+
viewStateRef,
|
|
2621
|
+
yScaleRef,
|
|
2622
|
+
yCenterOffsetRef,
|
|
2623
|
+
yManualScaleRef,
|
|
2624
|
+
movingAverageByChart = {},
|
|
2625
|
+
movingAverageCache,
|
|
2626
|
+
onMovingAverageToggle,
|
|
2627
|
+
onMovingAverageChange,
|
|
2628
|
+
seriesOrderByChart = {},
|
|
2629
|
+
onClose,
|
|
2630
|
+
onReset,
|
|
2631
|
+
onJumpLatest,
|
|
2632
|
+
xAxisLabel = "STEP",
|
|
2633
|
+
drawings = EMPTY_ARRAY,
|
|
2634
|
+
onDrawingsChange,
|
|
2635
|
+
activeDrawingTool = null,
|
|
2636
|
+
onActiveDrawingToolChange,
|
|
2637
|
+
selectedDrawingId = null,
|
|
2638
|
+
onSelectedDrawingIdChange,
|
|
2639
|
+
createDrawingId,
|
|
2640
|
+
onClearDrawingsRequest,
|
|
2641
|
+
onChartContextMenu,
|
|
2642
|
+
topMarkers = EMPTY_ARRAY,
|
|
2643
|
+
onTopMarkerClick
|
|
2644
|
+
}) {
|
|
2645
|
+
const containerRef = (0, import_react9.useRef)(null);
|
|
2646
|
+
const chartRef = (0, import_react9.useRef)(null);
|
|
2647
|
+
const canvasRef = (0, import_react9.useRef)(null);
|
|
2648
|
+
const glRef = (0, import_react9.useRef)(null);
|
|
2649
|
+
const programRef = (0, import_react9.useRef)(null);
|
|
2650
|
+
const antialiasProgramRef = (0, import_react9.useRef)(null);
|
|
2651
|
+
const seriesBufferCacheRef = (0, import_react9.useRef)(createSeriesBufferCache());
|
|
2652
|
+
const antialiasSeriesBufferCacheRef = (0, import_react9.useRef)(createSeriesBufferCache());
|
|
2653
|
+
const movingAverageCacheRef = (0, import_react9.useRef)(/* @__PURE__ */ new Map());
|
|
2654
|
+
const dragRef = (0, import_react9.useRef)(null);
|
|
2655
|
+
const rectangleZoomDragRef = (0, import_react9.useRef)(null);
|
|
2656
|
+
const closeTimeoutRef = (0, import_react9.useRef)(null);
|
|
2657
|
+
const [revision, setRevision] = (0, import_react9.useState)(0);
|
|
2658
|
+
const [axisOverlay, setAxisOverlay] = (0, import_react9.useState)(null);
|
|
2659
|
+
const [crosshair, setCrosshair] = (0, import_react9.useState)(null);
|
|
2660
|
+
const [visible, setVisible] = (0, import_react9.useState)(false);
|
|
2661
|
+
const [rectangleZoomActive, setRectangleZoomActive] = (0, import_react9.useState)(false);
|
|
2662
|
+
const [rectangleZoomRect, setRectangleZoomRect] = (0, import_react9.useState)(null);
|
|
2663
|
+
const requestRender = (0, import_react9.useCallback)(() => {
|
|
2664
|
+
setRevision((value) => value + 1);
|
|
2665
|
+
}, []);
|
|
2666
|
+
const closeWithTransition = (0, import_react9.useCallback)(() => {
|
|
2667
|
+
setVisible(false);
|
|
2668
|
+
closeTimeoutRef.current = window.setTimeout(onClose, 120);
|
|
2669
|
+
}, [onClose]);
|
|
2670
|
+
const {
|
|
2671
|
+
draftDrawing,
|
|
2672
|
+
drawingSessionRef,
|
|
2673
|
+
drawingEditRef,
|
|
2674
|
+
clearDraft,
|
|
2675
|
+
cancelDrawing,
|
|
2676
|
+
toggleDrawingTool,
|
|
2677
|
+
commitDrawing,
|
|
2678
|
+
startDraftDrawing,
|
|
2679
|
+
updateDraftDrawing,
|
|
2680
|
+
startEditDrawing,
|
|
2681
|
+
finishEditDrawing,
|
|
2682
|
+
deleteSelectedDrawing
|
|
2683
|
+
} = useDrawingInteractions({
|
|
2684
|
+
drawings,
|
|
2685
|
+
onDrawingsChange,
|
|
2686
|
+
activeDrawingTool,
|
|
2687
|
+
onActiveDrawingToolChange,
|
|
2688
|
+
selectedDrawingId,
|
|
2689
|
+
onSelectedDrawingIdChange,
|
|
2690
|
+
createDrawingId,
|
|
2691
|
+
onModeChange: () => {
|
|
2692
|
+
setRectangleZoomActive(false);
|
|
2693
|
+
setRectangleZoomRect(null);
|
|
2694
|
+
rectangleZoomDragRef.current = null;
|
|
2695
|
+
}
|
|
2696
|
+
});
|
|
2697
|
+
const toggleRectangleZoom = (0, import_react9.useCallback)(() => {
|
|
2698
|
+
setRectangleZoomActive((value) => !value);
|
|
2699
|
+
setRectangleZoomRect(null);
|
|
2700
|
+
rectangleZoomDragRef.current = null;
|
|
2701
|
+
clearDraft();
|
|
2702
|
+
onActiveDrawingToolChange?.(null);
|
|
2703
|
+
}, [clearDraft, onActiveDrawingToolChange]);
|
|
2704
|
+
const toggleSelectedDrawingExtend = (0, import_react9.useCallback)(() => {
|
|
2705
|
+
if (!selectedDrawingId || !onDrawingsChange) return;
|
|
2706
|
+
onDrawingsChange(
|
|
2707
|
+
updateDrawingById(drawings, selectedDrawingId, (drawing) => ({
|
|
2708
|
+
...drawing,
|
|
2709
|
+
style: {
|
|
2710
|
+
...drawing.style,
|
|
2711
|
+
extendRight: drawing.style?.extendRight === false
|
|
2712
|
+
}
|
|
2713
|
+
}))
|
|
2714
|
+
);
|
|
2715
|
+
}, [drawings, onDrawingsChange, selectedDrawingId]);
|
|
2716
|
+
const updateSelectedDrawingColor = (0, import_react9.useCallback)(
|
|
2717
|
+
(color) => {
|
|
2718
|
+
if (!selectedDrawingId || !onDrawingsChange) return;
|
|
2719
|
+
onDrawingsChange(
|
|
2720
|
+
updateDrawingById(drawings, selectedDrawingId, (drawing) => ({
|
|
2721
|
+
...drawing,
|
|
2722
|
+
style: {
|
|
2723
|
+
...drawing.style,
|
|
2724
|
+
color
|
|
2725
|
+
}
|
|
2726
|
+
}))
|
|
2727
|
+
);
|
|
2728
|
+
},
|
|
2729
|
+
[drawings, onDrawingsChange, selectedDrawingId]
|
|
2730
|
+
);
|
|
2731
|
+
const updateSelectedDrawingText = (0, import_react9.useCallback)(
|
|
2732
|
+
(text) => {
|
|
2733
|
+
if (!selectedDrawingId || !onDrawingsChange) return;
|
|
2734
|
+
onDrawingsChange(
|
|
2735
|
+
updateDrawingById(drawings, selectedDrawingId, (drawing) => ({
|
|
2736
|
+
...drawing,
|
|
2737
|
+
style: {
|
|
2738
|
+
...drawing.style,
|
|
2739
|
+
text
|
|
2740
|
+
}
|
|
2741
|
+
}))
|
|
2742
|
+
);
|
|
2743
|
+
},
|
|
2744
|
+
[drawings, onDrawingsChange, selectedDrawingId]
|
|
2745
|
+
);
|
|
2746
|
+
(0, import_react9.useEffect)(() => {
|
|
2747
|
+
const frame = requestAnimationFrame(() => setVisible(true));
|
|
2748
|
+
return () => {
|
|
2749
|
+
cancelAnimationFrame(frame);
|
|
2750
|
+
if (closeTimeoutRef.current != null) {
|
|
2751
|
+
clearTimeout(closeTimeoutRef.current);
|
|
2752
|
+
closeTimeoutRef.current = null;
|
|
2753
|
+
}
|
|
2754
|
+
};
|
|
2755
|
+
}, []);
|
|
2756
|
+
const getLayout = (0, import_react9.useCallback)(() => {
|
|
2757
|
+
const node = chartRef.current;
|
|
2758
|
+
if (!node) return null;
|
|
2759
|
+
const rect = {
|
|
2760
|
+
x: node.offsetLeft,
|
|
2761
|
+
y: node.offsetTop,
|
|
2762
|
+
width: node.offsetWidth,
|
|
2763
|
+
height: node.offsetHeight
|
|
2764
|
+
};
|
|
2765
|
+
const plot = {
|
|
2766
|
+
x: rect.x + PLOT_PADDING.left,
|
|
2767
|
+
y: rect.y + PLOT_PADDING.top,
|
|
2768
|
+
width: Math.max(1, rect.width - PLOT_PADDING.left - PLOT_PADDING.right),
|
|
2769
|
+
height: Math.max(1, rect.height - PLOT_PADDING.top - PLOT_PADDING.bottom)
|
|
2770
|
+
};
|
|
2771
|
+
return { chart, rect, plot, visible: true };
|
|
2772
|
+
}, [chart]);
|
|
2773
|
+
const getLocalPoint = (0, import_react9.useCallback)((event) => {
|
|
2774
|
+
const rect = containerRef.current?.getBoundingClientRect();
|
|
2775
|
+
if (!rect) return null;
|
|
2776
|
+
return {
|
|
2777
|
+
x: event.clientX - rect.left,
|
|
2778
|
+
y: event.clientY - rect.top
|
|
2779
|
+
};
|
|
2780
|
+
}, []);
|
|
2781
|
+
(0, import_react9.useEffect)(() => {
|
|
2782
|
+
const canvas = canvasRef.current;
|
|
2783
|
+
if (!canvas) return;
|
|
2784
|
+
const gl = canvas.getContext("webgl2", {
|
|
2785
|
+
antialias: true,
|
|
2786
|
+
alpha: true,
|
|
2787
|
+
depth: false,
|
|
2788
|
+
stencil: false,
|
|
2789
|
+
preserveDrawingBuffer: false
|
|
2790
|
+
});
|
|
2791
|
+
if (!gl) return;
|
|
2792
|
+
glRef.current = gl;
|
|
2793
|
+
programRef.current = createProgram(gl);
|
|
2794
|
+
antialiasProgramRef.current = createAntialiasProgram(gl);
|
|
2795
|
+
requestRender();
|
|
2796
|
+
return () => {
|
|
2797
|
+
deleteSeriesBuffers(gl, seriesBufferCacheRef.current);
|
|
2798
|
+
deleteSeriesBuffers(gl, antialiasSeriesBufferCacheRef.current);
|
|
2799
|
+
glRef.current = null;
|
|
2800
|
+
programRef.current = null;
|
|
2801
|
+
antialiasProgramRef.current = null;
|
|
2802
|
+
};
|
|
2803
|
+
}, [requestRender]);
|
|
2804
|
+
(0, import_react9.useEffect)(() => {
|
|
2805
|
+
const container = containerRef.current;
|
|
2806
|
+
if (!container) return;
|
|
2807
|
+
const observer = new ResizeObserver(requestRender);
|
|
2808
|
+
observer.observe(container);
|
|
2809
|
+
return () => observer.disconnect();
|
|
2810
|
+
}, [requestRender]);
|
|
2811
|
+
(0, import_react9.useEffect)(() => {
|
|
2812
|
+
const container = containerRef.current;
|
|
2813
|
+
const canvas = canvasRef.current;
|
|
2814
|
+
const gl = glRef.current;
|
|
2815
|
+
const program = programRef.current;
|
|
2816
|
+
const antialiasProgram = antialiasProgramRef.current;
|
|
2817
|
+
const layout = getLayout();
|
|
2818
|
+
if (!container || !canvas || !gl || !program || !layout) return;
|
|
2819
|
+
const nextAxisOverlays = drawChartLayouts({
|
|
2820
|
+
canvas,
|
|
2821
|
+
width: container.clientWidth,
|
|
2822
|
+
height: container.clientHeight,
|
|
2823
|
+
gl,
|
|
2824
|
+
program,
|
|
2825
|
+
antialiasProgram,
|
|
2826
|
+
antialiasLines,
|
|
2827
|
+
layouts: [layout],
|
|
2828
|
+
viewStateRef,
|
|
2829
|
+
yScaleRef,
|
|
2830
|
+
yCenterOffsetRef,
|
|
2831
|
+
seriesBufferCache: seriesBufferCacheRef.current,
|
|
2832
|
+
antialiasSeriesBufferCache: antialiasSeriesBufferCacheRef.current,
|
|
2833
|
+
initialVisiblePoints,
|
|
2834
|
+
getAppendAnimatedPoint,
|
|
2835
|
+
movingAverageByChart,
|
|
2836
|
+
movingAverageCache,
|
|
2837
|
+
seriesOrderByChart
|
|
2838
|
+
});
|
|
2839
|
+
setAxisOverlay(nextAxisOverlays[chart.id] || null);
|
|
2840
|
+
}, [
|
|
2841
|
+
chart,
|
|
2842
|
+
antialiasLines,
|
|
2843
|
+
dataRevision,
|
|
2844
|
+
getAppendAnimatedPoint,
|
|
2845
|
+
getLayout,
|
|
2846
|
+
initialVisiblePoints,
|
|
2847
|
+
movingAverageByChart,
|
|
2848
|
+
movingAverageCache,
|
|
2849
|
+
seriesOrderByChart,
|
|
2850
|
+
renderRevision,
|
|
2851
|
+
revision,
|
|
2852
|
+
viewStateRef,
|
|
2853
|
+
yCenterOffsetRef,
|
|
2854
|
+
yScaleRef
|
|
2855
|
+
]);
|
|
2856
|
+
const updateCrosshair = (0, import_react9.useCallback)(
|
|
2857
|
+
(event) => {
|
|
2858
|
+
const point = getLocalPoint(event);
|
|
2859
|
+
const layout = getLayout();
|
|
2860
|
+
if (!point || !layout) return;
|
|
2861
|
+
if (point.x < layout.plot.x || point.x > layout.plot.x + layout.plot.width || point.y < layout.plot.y || point.y > layout.plot.y + layout.plot.height) {
|
|
2862
|
+
setCrosshair(null);
|
|
2863
|
+
return;
|
|
2864
|
+
}
|
|
2865
|
+
const state = viewStateRef.current.get(chart.id) || getInitialView(chart, initialVisiblePoints);
|
|
2866
|
+
const xRatio = (point.x - layout.plot.x) / layout.plot.width;
|
|
2867
|
+
const xValue = state.xMin + xRatio * (state.xMax - state.xMin);
|
|
2868
|
+
const yRange = getYRange(
|
|
2869
|
+
chart,
|
|
2870
|
+
state.xMin,
|
|
2871
|
+
state.xMax,
|
|
2872
|
+
layout.plot.width
|
|
2873
|
+
);
|
|
2874
|
+
const scaledYRange = applyYScale(
|
|
2875
|
+
yRange,
|
|
2876
|
+
yScaleRef.current.get(chart.id) ?? 1,
|
|
2877
|
+
yCenterOffsetRef.current.get(chart.id) ?? 0
|
|
2878
|
+
);
|
|
2879
|
+
const yRatio = (point.y - layout.plot.y) / layout.plot.height;
|
|
2880
|
+
const yValue = scaledYRange.maxY - yRatio * (scaledYRange.maxY - scaledYRange.minY);
|
|
2881
|
+
const nearestPoints = getOrderedSeries(chart, seriesOrderByChart).map((series) => {
|
|
2882
|
+
const visiblePoints = series.getVisiblePoints(
|
|
2883
|
+
state.xMin,
|
|
2884
|
+
state.xMax,
|
|
2885
|
+
layout.plot.width
|
|
2886
|
+
);
|
|
2887
|
+
const index = getNearestPointIndex(visiblePoints.x, xValue);
|
|
2888
|
+
if (index < 0) return null;
|
|
2889
|
+
const pointX = visiblePoints.x[index];
|
|
2890
|
+
const pointY = visiblePoints.y[index];
|
|
2891
|
+
const pointXRatio = (pointX - state.xMin) / (state.xMax - state.xMin);
|
|
2892
|
+
const pointYRatio = (scaledYRange.maxY - pointY) / (scaledYRange.maxY - scaledYRange.minY);
|
|
2893
|
+
return {
|
|
2894
|
+
id: series.id,
|
|
2895
|
+
name: series.name,
|
|
2896
|
+
color: series.color,
|
|
2897
|
+
xValue: pointX,
|
|
2898
|
+
yValue: pointY,
|
|
2899
|
+
x: layout.plot.x + pointXRatio * layout.plot.width,
|
|
2900
|
+
y: layout.plot.y + pointYRatio * layout.plot.height
|
|
2901
|
+
};
|
|
2902
|
+
}).filter(Boolean).filter(
|
|
2903
|
+
(nearestPoint) => nearestPoint.x >= layout.plot.x - 1 && nearestPoint.x <= layout.plot.x + layout.plot.width + 1 && nearestPoint.y >= layout.plot.y - 1 && nearestPoint.y <= layout.plot.y + layout.plot.height + 1
|
|
2904
|
+
);
|
|
2905
|
+
const primaryPoint = nearestPoints[0];
|
|
2906
|
+
const tooltipLeft = primaryPoint && primaryPoint.x + TOOLTIP_WIDTH + TOOLTIP_OFFSET > layout.rect.x + layout.rect.width ? primaryPoint.x - TOOLTIP_WIDTH - TOOLTIP_OFFSET : (primaryPoint?.x ?? point.x) + TOOLTIP_OFFSET;
|
|
2907
|
+
const tooltipTop = Math.max(
|
|
2908
|
+
layout.rect.y + PLOT_PADDING.top,
|
|
2909
|
+
Math.min(
|
|
2910
|
+
(primaryPoint?.y ?? point.y) + TOOLTIP_OFFSET,
|
|
2911
|
+
layout.rect.y + layout.rect.height - 96
|
|
2912
|
+
)
|
|
2913
|
+
);
|
|
2914
|
+
setCrosshair({
|
|
2915
|
+
chartId: chart.id,
|
|
2916
|
+
title: chart.title,
|
|
2917
|
+
x: point.x,
|
|
2918
|
+
y: point.y,
|
|
2919
|
+
xValue: primaryPoint?.xValue ?? xValue,
|
|
2920
|
+
yValue: primaryPoint?.yValue ?? yValue,
|
|
2921
|
+
points: nearestPoints,
|
|
2922
|
+
tooltipX: Math.max(layout.rect.x + 6, tooltipLeft),
|
|
2923
|
+
tooltipY: tooltipTop
|
|
2924
|
+
});
|
|
2925
|
+
},
|
|
2926
|
+
[
|
|
2927
|
+
chart,
|
|
2928
|
+
getLayout,
|
|
2929
|
+
getLocalPoint,
|
|
2930
|
+
initialVisiblePoints,
|
|
2931
|
+
seriesOrderByChart,
|
|
2932
|
+
viewStateRef,
|
|
2933
|
+
yCenterOffsetRef,
|
|
2934
|
+
yScaleRef
|
|
2935
|
+
]
|
|
2936
|
+
);
|
|
2937
|
+
const handlePointerDown = (0, import_react9.useCallback)(
|
|
2938
|
+
(event) => {
|
|
2939
|
+
const point = getLocalPoint(event);
|
|
2940
|
+
const layout = getLayout();
|
|
2941
|
+
if (!point || !layout) return;
|
|
2942
|
+
const inPlot = point.x >= layout.plot.x && point.x <= layout.plot.x + layout.plot.width && point.y >= layout.plot.y && point.y <= layout.plot.y + layout.plot.height;
|
|
2943
|
+
if (activeDrawingTool && DRAWING_TOOLS.has(activeDrawingTool)) {
|
|
2944
|
+
if (!inPlot || event.button !== 0) return;
|
|
2945
|
+
event.preventDefault();
|
|
2946
|
+
const dataPoint = screenPointToDataPoint({
|
|
2947
|
+
point,
|
|
2948
|
+
chart,
|
|
2949
|
+
plot: layout.plot,
|
|
2950
|
+
initialVisiblePoints,
|
|
2951
|
+
viewStateRef,
|
|
2952
|
+
yScaleRef,
|
|
2953
|
+
yCenterOffsetRef
|
|
2954
|
+
});
|
|
2955
|
+
if (activeDrawingTool === "hline" || activeDrawingTool === "vline" || activeDrawingTool === "pin") {
|
|
2956
|
+
commitDrawing({
|
|
2957
|
+
chartId: chart.id,
|
|
2958
|
+
type: activeDrawingTool,
|
|
2959
|
+
start: dataPoint,
|
|
2960
|
+
end: dataPoint
|
|
2961
|
+
});
|
|
2962
|
+
return;
|
|
2963
|
+
}
|
|
2964
|
+
if (!drawingSessionRef.current.startPoint) {
|
|
2965
|
+
startDraftDrawing({
|
|
2966
|
+
chartId: chart.id,
|
|
2967
|
+
type: "trendline",
|
|
2968
|
+
start: dataPoint,
|
|
2969
|
+
end: dataPoint
|
|
2970
|
+
});
|
|
2971
|
+
return;
|
|
2972
|
+
}
|
|
2973
|
+
commitDrawing({
|
|
2974
|
+
chartId: chart.id,
|
|
2975
|
+
type: "trendline",
|
|
2976
|
+
start: drawingSessionRef.current.startPoint,
|
|
2977
|
+
end: dataPoint
|
|
2978
|
+
});
|
|
2979
|
+
return;
|
|
2980
|
+
}
|
|
2981
|
+
if (inPlot && Array.isArray(drawings) && drawings.length > 0) {
|
|
2982
|
+
const chartDrawings = getDrawingsForChart(drawings, chart.id);
|
|
2983
|
+
for (let i = chartDrawings.length - 1; i >= 0; i -= 1) {
|
|
2984
|
+
const hit = hitTestDrawing({
|
|
2985
|
+
point,
|
|
2986
|
+
drawing: chartDrawings[i],
|
|
2987
|
+
layout,
|
|
2988
|
+
projectPoint: (dataPoint, targetLayout) => projectDataPointToScreenPoint({
|
|
2989
|
+
point: dataPoint,
|
|
2990
|
+
layout: targetLayout,
|
|
2991
|
+
initialVisiblePoints,
|
|
2992
|
+
viewStateRef,
|
|
2993
|
+
yScaleRef,
|
|
2994
|
+
yCenterOffsetRef
|
|
2995
|
+
})
|
|
2996
|
+
});
|
|
2997
|
+
if (hit) {
|
|
2998
|
+
event.preventDefault();
|
|
2999
|
+
onSelectedDrawingIdChange?.(hit.drawing.id);
|
|
3000
|
+
if (hit.endpoint || hit.drawing.type === "hline" || hit.drawing.type === "vline" || hit.drawing.type === "pin") {
|
|
3001
|
+
startEditDrawing({
|
|
3002
|
+
drawingId: hit.drawing.id,
|
|
3003
|
+
endpoint: hit.endpoint || "move"
|
|
3004
|
+
});
|
|
3005
|
+
event.currentTarget.setPointerCapture?.(event.pointerId);
|
|
3006
|
+
}
|
|
3007
|
+
return;
|
|
3008
|
+
}
|
|
3009
|
+
}
|
|
3010
|
+
onSelectedDrawingIdChange?.(null);
|
|
3011
|
+
}
|
|
3012
|
+
if (rectangleZoomActive) {
|
|
3013
|
+
if (!inPlot || event.button !== 0) return;
|
|
3014
|
+
event.preventDefault();
|
|
3015
|
+
const start = clampPointToPlot(point, layout.plot);
|
|
3016
|
+
rectangleZoomDragRef.current = { start, end: start };
|
|
3017
|
+
setRectangleZoomRect({ start, end: start });
|
|
3018
|
+
event.currentTarget.setPointerCapture?.(event.pointerId);
|
|
3019
|
+
return;
|
|
3020
|
+
}
|
|
3021
|
+
const inYAxis = point.x >= layout.plot.x + layout.plot.width && point.x <= layout.rect.x + layout.rect.width && point.y >= layout.plot.y && point.y <= layout.plot.y + layout.plot.height;
|
|
3022
|
+
if (inYAxis) {
|
|
3023
|
+
event.preventDefault();
|
|
3024
|
+
dragRef.current = {
|
|
3025
|
+
type: "y-scale",
|
|
3026
|
+
startY: point.y,
|
|
3027
|
+
startScale: yScaleRef.current.get(chart.id) ?? 1
|
|
3028
|
+
};
|
|
3029
|
+
event.currentTarget.setPointerCapture?.(event.pointerId);
|
|
3030
|
+
return;
|
|
3031
|
+
}
|
|
3032
|
+
const inXAxis = point.x >= layout.plot.x && point.x <= layout.plot.x + layout.plot.width && point.y >= layout.plot.y + layout.plot.height && point.y <= layout.rect.y + layout.rect.height;
|
|
3033
|
+
if (inXAxis) {
|
|
3034
|
+
event.preventDefault();
|
|
3035
|
+
const state2 = viewStateRef.current.get(chart.id) || getInitialView(chart, initialVisiblePoints);
|
|
3036
|
+
dragRef.current = {
|
|
3037
|
+
type: "x-scale",
|
|
3038
|
+
startX: point.x,
|
|
3039
|
+
startMin: state2.xMin,
|
|
3040
|
+
startMax: state2.xMax
|
|
3041
|
+
};
|
|
3042
|
+
event.currentTarget.setPointerCapture?.(event.pointerId);
|
|
3043
|
+
return;
|
|
3044
|
+
}
|
|
3045
|
+
if (!inPlot) return;
|
|
3046
|
+
const state = viewStateRef.current.get(chart.id) || getInitialView(chart, initialVisiblePoints);
|
|
3047
|
+
const yRange = getYRange(
|
|
3048
|
+
chart,
|
|
3049
|
+
state.xMin,
|
|
3050
|
+
state.xMax,
|
|
3051
|
+
layout.plot.width
|
|
3052
|
+
);
|
|
3053
|
+
const scaledYRange = applyYScale(
|
|
3054
|
+
yRange,
|
|
3055
|
+
yScaleRef.current.get(chart.id) ?? 1,
|
|
3056
|
+
yCenterOffsetRef.current.get(chart.id) ?? 0
|
|
3057
|
+
);
|
|
3058
|
+
dragRef.current = {
|
|
3059
|
+
type: "x-pan",
|
|
3060
|
+
startX: point.x,
|
|
3061
|
+
startY: point.y,
|
|
3062
|
+
startMin: state.xMin,
|
|
3063
|
+
startMax: state.xMax,
|
|
3064
|
+
startYOffset: yCenterOffsetRef.current.get(chart.id) ?? 0,
|
|
3065
|
+
canPanY: yManualScaleRef.current.has(chart.id),
|
|
3066
|
+
yValueSpan: scaledYRange.maxY - scaledYRange.minY,
|
|
3067
|
+
width: layout.plot.width,
|
|
3068
|
+
height: layout.plot.height
|
|
3069
|
+
};
|
|
3070
|
+
event.currentTarget.setPointerCapture?.(event.pointerId);
|
|
3071
|
+
},
|
|
3072
|
+
[
|
|
3073
|
+
chart,
|
|
3074
|
+
getLayout,
|
|
3075
|
+
getLocalPoint,
|
|
3076
|
+
initialVisiblePoints,
|
|
3077
|
+
activeDrawingTool,
|
|
3078
|
+
chart,
|
|
3079
|
+
commitDrawing,
|
|
3080
|
+
drawings,
|
|
3081
|
+
onSelectedDrawingIdChange,
|
|
3082
|
+
rectangleZoomActive,
|
|
3083
|
+
viewStateRef,
|
|
3084
|
+
yCenterOffsetRef,
|
|
3085
|
+
yManualScaleRef,
|
|
3086
|
+
yScaleRef
|
|
3087
|
+
]
|
|
3088
|
+
);
|
|
3089
|
+
const handlePointerMove = (0, import_react9.useCallback)(
|
|
3090
|
+
(event) => {
|
|
3091
|
+
updateCrosshair(event);
|
|
3092
|
+
const drawingPoint = getLocalPoint(event);
|
|
3093
|
+
const drawingLayout = getLayout();
|
|
3094
|
+
if (drawingPoint && drawingLayout) {
|
|
3095
|
+
if (drawingEditRef.current) {
|
|
3096
|
+
const dataPoint = screenPointToDataPoint({
|
|
3097
|
+
point: clampPointToPlot(drawingPoint, drawingLayout.plot),
|
|
3098
|
+
chart,
|
|
3099
|
+
plot: drawingLayout.plot,
|
|
3100
|
+
initialVisiblePoints,
|
|
3101
|
+
viewStateRef,
|
|
3102
|
+
yScaleRef,
|
|
3103
|
+
yCenterOffsetRef
|
|
3104
|
+
});
|
|
3105
|
+
const edit = drawingEditRef.current;
|
|
3106
|
+
const nextDrawings = updateDrawingById(drawings, edit.id, (drawing) => {
|
|
3107
|
+
if (drawing.type === "hline") {
|
|
3108
|
+
const deltaX = (drawing.end?.x ?? drawing.start.x) - drawing.start.x;
|
|
3109
|
+
return {
|
|
3110
|
+
...drawing,
|
|
3111
|
+
start: { ...drawing.start, x: dataPoint.x, y: dataPoint.y },
|
|
3112
|
+
end: {
|
|
3113
|
+
...drawing.end,
|
|
3114
|
+
x: dataPoint.x + deltaX,
|
|
3115
|
+
y: dataPoint.y
|
|
3116
|
+
}
|
|
3117
|
+
};
|
|
3118
|
+
}
|
|
3119
|
+
if (drawing.type === "vline") {
|
|
3120
|
+
return { ...drawing, start: { ...drawing.start, x: dataPoint.x }, end: { ...drawing.end, x: dataPoint.x } };
|
|
3121
|
+
}
|
|
3122
|
+
if (drawing.type === "pin") {
|
|
3123
|
+
return { ...drawing, start: dataPoint, end: dataPoint };
|
|
3124
|
+
}
|
|
3125
|
+
if (edit.endpoint === "start" || edit.endpoint === "end") {
|
|
3126
|
+
return { ...drawing, [edit.endpoint]: dataPoint };
|
|
3127
|
+
}
|
|
3128
|
+
return drawing;
|
|
3129
|
+
});
|
|
3130
|
+
onDrawingsChange?.(nextDrawings);
|
|
3131
|
+
return;
|
|
3132
|
+
}
|
|
3133
|
+
if (activeDrawingTool && DRAWING_TOOLS.has(activeDrawingTool)) {
|
|
3134
|
+
if (drawingPoint.x < drawingLayout.plot.x || drawingPoint.x > drawingLayout.plot.x + drawingLayout.plot.width || drawingPoint.y < drawingLayout.plot.y || drawingPoint.y > drawingLayout.plot.y + drawingLayout.plot.height) {
|
|
3135
|
+
return;
|
|
3136
|
+
}
|
|
3137
|
+
const dataPoint = screenPointToDataPoint({
|
|
3138
|
+
point: drawingPoint,
|
|
3139
|
+
chart,
|
|
3140
|
+
plot: drawingLayout.plot,
|
|
3141
|
+
initialVisiblePoints,
|
|
3142
|
+
viewStateRef,
|
|
3143
|
+
yScaleRef,
|
|
3144
|
+
yCenterOffsetRef
|
|
3145
|
+
});
|
|
3146
|
+
const startPoint = activeDrawingTool === "trendline" ? drawingSessionRef.current.startPoint : dataPoint;
|
|
3147
|
+
if (startPoint || activeDrawingTool !== "trendline") {
|
|
3148
|
+
updateDraftDrawing({
|
|
3149
|
+
chartId: chart.id,
|
|
3150
|
+
type: activeDrawingTool,
|
|
3151
|
+
start: startPoint || dataPoint,
|
|
3152
|
+
end: dataPoint
|
|
3153
|
+
});
|
|
3154
|
+
}
|
|
3155
|
+
return;
|
|
3156
|
+
}
|
|
3157
|
+
}
|
|
3158
|
+
if (rectangleZoomDragRef.current) {
|
|
3159
|
+
const point2 = getLocalPoint(event);
|
|
3160
|
+
const layout = getLayout();
|
|
3161
|
+
if (!point2 || !layout) return;
|
|
3162
|
+
const end = clampPointToPlot(point2, layout.plot);
|
|
3163
|
+
rectangleZoomDragRef.current = {
|
|
3164
|
+
...rectangleZoomDragRef.current,
|
|
3165
|
+
end
|
|
3166
|
+
};
|
|
3167
|
+
setRectangleZoomRect({
|
|
3168
|
+
start: rectangleZoomDragRef.current.start,
|
|
3169
|
+
end
|
|
3170
|
+
});
|
|
3171
|
+
return;
|
|
3172
|
+
}
|
|
3173
|
+
const drag = dragRef.current;
|
|
3174
|
+
if (!drag) return;
|
|
3175
|
+
const point = getLocalPoint(event);
|
|
3176
|
+
if (!point) return;
|
|
3177
|
+
if (drag.type === "y-scale") {
|
|
3178
|
+
yScaleRef.current.set(
|
|
3179
|
+
chart.id,
|
|
3180
|
+
Math.min(
|
|
3181
|
+
Y_SCALE_MAX,
|
|
3182
|
+
Math.max(
|
|
3183
|
+
Y_SCALE_MIN,
|
|
3184
|
+
drag.startScale * Math.exp((point.y - drag.startY) * 0.01)
|
|
3185
|
+
)
|
|
3186
|
+
)
|
|
3187
|
+
);
|
|
3188
|
+
yManualScaleRef.current.add(chart.id);
|
|
3189
|
+
requestRender();
|
|
3190
|
+
return;
|
|
3191
|
+
}
|
|
3192
|
+
if (drag.type === "x-scale") {
|
|
3193
|
+
const startSpan = drag.startMax - drag.startMin;
|
|
3194
|
+
const nextSpan = Math.min(
|
|
3195
|
+
X_SCALE_MAX_SPAN,
|
|
3196
|
+
Math.max(
|
|
3197
|
+
X_SCALE_MIN_SPAN,
|
|
3198
|
+
startSpan * Math.exp((drag.startX - point.x) * 0.01)
|
|
3199
|
+
)
|
|
3200
|
+
);
|
|
3201
|
+
viewStateRef.current.set(chart.id, {
|
|
3202
|
+
xMin: drag.startMax - nextSpan,
|
|
3203
|
+
xMax: drag.startMax
|
|
3204
|
+
});
|
|
3205
|
+
requestRender();
|
|
3206
|
+
return;
|
|
3207
|
+
}
|
|
3208
|
+
const range = drag.startMax - drag.startMin;
|
|
3209
|
+
const delta = (point.x - drag.startX) / drag.width * range;
|
|
3210
|
+
viewStateRef.current.set(chart.id, {
|
|
3211
|
+
xMin: drag.startMin - delta,
|
|
3212
|
+
xMax: drag.startMax - delta
|
|
3213
|
+
});
|
|
3214
|
+
if (drag.canPanY) {
|
|
3215
|
+
const yDelta = (point.y - drag.startY) / drag.height * drag.yValueSpan;
|
|
3216
|
+
yCenterOffsetRef.current.set(chart.id, drag.startYOffset + yDelta);
|
|
3217
|
+
}
|
|
3218
|
+
requestRender();
|
|
3219
|
+
},
|
|
3220
|
+
[
|
|
3221
|
+
chart.id,
|
|
3222
|
+
chart,
|
|
3223
|
+
activeDrawingTool,
|
|
3224
|
+
drawings,
|
|
3225
|
+
getLayout,
|
|
3226
|
+
getLocalPoint,
|
|
3227
|
+
initialVisiblePoints,
|
|
3228
|
+
onDrawingsChange,
|
|
3229
|
+
requestRender,
|
|
3230
|
+
updateCrosshair,
|
|
3231
|
+
viewStateRef,
|
|
3232
|
+
yCenterOffsetRef,
|
|
3233
|
+
yManualScaleRef,
|
|
3234
|
+
yScaleRef
|
|
3235
|
+
]
|
|
3236
|
+
);
|
|
3237
|
+
const handlePointerUp = (0, import_react9.useCallback)(
|
|
3238
|
+
(event) => {
|
|
3239
|
+
if (drawingEditRef.current) {
|
|
3240
|
+
finishEditDrawing();
|
|
3241
|
+
event.currentTarget.releasePointerCapture?.(event.pointerId);
|
|
3242
|
+
return;
|
|
3243
|
+
}
|
|
3244
|
+
if (rectangleZoomDragRef.current) {
|
|
3245
|
+
const layout = getLayout();
|
|
3246
|
+
const { start, end } = rectangleZoomDragRef.current;
|
|
3247
|
+
rectangleZoomDragRef.current = null;
|
|
3248
|
+
setRectangleZoomRect(null);
|
|
3249
|
+
event.currentTarget.releasePointerCapture?.(event.pointerId);
|
|
3250
|
+
if (layout) {
|
|
3251
|
+
const applied = applyRectangleZoom({
|
|
3252
|
+
chart,
|
|
3253
|
+
plot: layout.plot,
|
|
3254
|
+
start,
|
|
3255
|
+
end,
|
|
3256
|
+
initialVisiblePoints,
|
|
3257
|
+
viewStateRef,
|
|
3258
|
+
yScaleRef,
|
|
3259
|
+
yCenterOffsetRef,
|
|
3260
|
+
yManualScaleRef
|
|
3261
|
+
});
|
|
3262
|
+
if (applied) {
|
|
3263
|
+
setRectangleZoomActive(false);
|
|
3264
|
+
requestRender();
|
|
3265
|
+
}
|
|
3266
|
+
}
|
|
3267
|
+
return;
|
|
3268
|
+
}
|
|
3269
|
+
dragRef.current = null;
|
|
3270
|
+
event.currentTarget.releasePointerCapture?.(event.pointerId);
|
|
3271
|
+
},
|
|
3272
|
+
[
|
|
3273
|
+
chart,
|
|
3274
|
+
getLayout,
|
|
3275
|
+
initialVisiblePoints,
|
|
3276
|
+
requestRender,
|
|
3277
|
+
viewStateRef,
|
|
3278
|
+
yCenterOffsetRef,
|
|
3279
|
+
yManualScaleRef,
|
|
3280
|
+
yScaleRef
|
|
3281
|
+
]
|
|
3282
|
+
);
|
|
3283
|
+
const handleWheel = (0, import_react9.useCallback)(
|
|
3284
|
+
(event) => {
|
|
3285
|
+
const point = getLocalPoint(event);
|
|
3286
|
+
const layout = getLayout();
|
|
3287
|
+
if (!point || !layout) return;
|
|
3288
|
+
if (point.x < layout.plot.x || point.x > layout.plot.x + layout.plot.width || point.y < layout.plot.y || point.y > layout.plot.y + layout.plot.height) {
|
|
3289
|
+
return;
|
|
3290
|
+
}
|
|
3291
|
+
event.preventDefault();
|
|
3292
|
+
if (event.shiftKey) {
|
|
3293
|
+
const currentScale = yScaleRef.current.get(chart.id) ?? 1;
|
|
3294
|
+
yScaleRef.current.set(
|
|
3295
|
+
chart.id,
|
|
3296
|
+
Math.min(
|
|
3297
|
+
Y_SCALE_MAX,
|
|
3298
|
+
Math.max(
|
|
3299
|
+
Y_SCALE_MIN,
|
|
3300
|
+
currentScale * Math.exp(event.deltaY * 0.01)
|
|
3301
|
+
)
|
|
3302
|
+
)
|
|
3303
|
+
);
|
|
3304
|
+
yManualScaleRef.current.add(chart.id);
|
|
3305
|
+
requestRender();
|
|
3306
|
+
return;
|
|
3307
|
+
}
|
|
3308
|
+
const state = viewStateRef.current.get(chart.id) || getInitialView(chart, initialVisiblePoints);
|
|
3309
|
+
const ratio = (point.x - layout.plot.x) / layout.plot.width;
|
|
3310
|
+
const anchor = state.xMin + ratio * (state.xMax - state.xMin);
|
|
3311
|
+
const zoom = Math.exp(event.deltaY * 15e-4);
|
|
3312
|
+
const nextMin = anchor - (anchor - state.xMin) * zoom;
|
|
3313
|
+
const nextMax = anchor + (state.xMax - anchor) * zoom;
|
|
3314
|
+
if (nextMax - nextMin < X_SCALE_MIN_SPAN) return;
|
|
3315
|
+
viewStateRef.current.set(chart.id, {
|
|
3316
|
+
xMin: nextMin,
|
|
3317
|
+
xMax: nextMax
|
|
3318
|
+
});
|
|
3319
|
+
requestRender();
|
|
3320
|
+
},
|
|
3321
|
+
[
|
|
3322
|
+
chart,
|
|
3323
|
+
getLayout,
|
|
3324
|
+
getLocalPoint,
|
|
3325
|
+
initialVisiblePoints,
|
|
3326
|
+
requestRender,
|
|
3327
|
+
viewStateRef,
|
|
3328
|
+
yScaleRef,
|
|
3329
|
+
yManualScaleRef
|
|
3330
|
+
]
|
|
3331
|
+
);
|
|
3332
|
+
(0, import_react9.useEffect)(() => {
|
|
3333
|
+
const container = containerRef.current;
|
|
3334
|
+
if (!container) return void 0;
|
|
3335
|
+
container.addEventListener("wheel", handleWheel, { passive: false });
|
|
3336
|
+
return () => container.removeEventListener("wheel", handleWheel);
|
|
3337
|
+
}, [handleWheel]);
|
|
3338
|
+
const handleContextMenu = (0, import_react9.useCallback)(
|
|
3339
|
+
(event) => {
|
|
3340
|
+
const point = getLocalPoint(event);
|
|
3341
|
+
const layout = getLayout();
|
|
3342
|
+
if (!point || !layout) return;
|
|
3343
|
+
event.preventDefault();
|
|
3344
|
+
onChartContextMenu?.({
|
|
3345
|
+
chart,
|
|
3346
|
+
event,
|
|
3347
|
+
point: getChartContextMenuPoint({
|
|
3348
|
+
point,
|
|
3349
|
+
chart,
|
|
3350
|
+
layout,
|
|
3351
|
+
initialVisiblePoints,
|
|
3352
|
+
viewStateRef,
|
|
3353
|
+
yScaleRef,
|
|
3354
|
+
yCenterOffsetRef
|
|
3355
|
+
})
|
|
3356
|
+
});
|
|
3357
|
+
},
|
|
3358
|
+
[
|
|
3359
|
+
chart,
|
|
3360
|
+
getLayout,
|
|
3361
|
+
getLocalPoint,
|
|
3362
|
+
initialVisiblePoints,
|
|
3363
|
+
onChartContextMenu,
|
|
3364
|
+
viewStateRef,
|
|
3365
|
+
yCenterOffsetRef,
|
|
3366
|
+
yScaleRef
|
|
3367
|
+
]
|
|
3368
|
+
);
|
|
3369
|
+
(0, import_react9.useEffect)(() => {
|
|
3370
|
+
const handleKeyDown = (event) => {
|
|
3371
|
+
const target = event.target;
|
|
3372
|
+
const editable = target instanceof HTMLElement && (target.isContentEditable || ["INPUT", "TEXTAREA", "SELECT"].includes(target.tagName));
|
|
3373
|
+
if (editable) return;
|
|
3374
|
+
if (event.key.toLowerCase() === "r") {
|
|
3375
|
+
event.preventDefault();
|
|
3376
|
+
onReset?.(chart.id);
|
|
3377
|
+
setRectangleZoomActive(false);
|
|
3378
|
+
setRectangleZoomRect(null);
|
|
3379
|
+
requestRender();
|
|
3380
|
+
return;
|
|
3381
|
+
}
|
|
3382
|
+
if (event.key.toLowerCase() === "z") {
|
|
3383
|
+
event.preventDefault();
|
|
3384
|
+
toggleRectangleZoom();
|
|
3385
|
+
return;
|
|
3386
|
+
}
|
|
3387
|
+
if (event.key.toLowerCase() === "m") {
|
|
3388
|
+
event.preventDefault();
|
|
3389
|
+
onMovingAverageToggle?.(chart.id);
|
|
3390
|
+
requestRender();
|
|
3391
|
+
return;
|
|
3392
|
+
}
|
|
3393
|
+
if (["t", "h", "v", "p"].includes(event.key.toLowerCase())) {
|
|
3394
|
+
event.preventDefault();
|
|
3395
|
+
const toolByKey = { t: "trendline", h: "hline", v: "vline", p: "pin" };
|
|
3396
|
+
toggleDrawingTool(toolByKey[event.key.toLowerCase()]);
|
|
3397
|
+
return;
|
|
3398
|
+
}
|
|
3399
|
+
if (event.key === "Delete" || event.key === "Backspace") {
|
|
3400
|
+
if (!selectedDrawingId) return;
|
|
3401
|
+
event.preventDefault();
|
|
3402
|
+
deleteSelectedDrawing();
|
|
3403
|
+
return;
|
|
3404
|
+
}
|
|
3405
|
+
if (event.key === "Escape" || event.key.toLowerCase() === "f") {
|
|
3406
|
+
event.preventDefault();
|
|
3407
|
+
if (activeDrawingTool || draftDrawing || drawingEditRef.current) {
|
|
3408
|
+
cancelDrawing();
|
|
3409
|
+
return;
|
|
3410
|
+
}
|
|
3411
|
+
if (rectangleZoomActive) {
|
|
3412
|
+
setRectangleZoomActive(false);
|
|
3413
|
+
setRectangleZoomRect(null);
|
|
3414
|
+
rectangleZoomDragRef.current = null;
|
|
3415
|
+
return;
|
|
3416
|
+
}
|
|
3417
|
+
closeWithTransition();
|
|
3418
|
+
}
|
|
3419
|
+
};
|
|
3420
|
+
window.addEventListener("keydown", handleKeyDown);
|
|
3421
|
+
return () => window.removeEventListener("keydown", handleKeyDown);
|
|
3422
|
+
}, [
|
|
3423
|
+
chart.id,
|
|
3424
|
+
closeWithTransition,
|
|
3425
|
+
activeDrawingTool,
|
|
3426
|
+
cancelDrawing,
|
|
3427
|
+
deleteSelectedDrawing,
|
|
3428
|
+
draftDrawing,
|
|
3429
|
+
onReset,
|
|
3430
|
+
onMovingAverageToggle,
|
|
3431
|
+
rectangleZoomActive,
|
|
3432
|
+
requestRender,
|
|
3433
|
+
toggleRectangleZoom,
|
|
3434
|
+
toggleDrawingTool,
|
|
3435
|
+
selectedDrawingId
|
|
3436
|
+
]);
|
|
3437
|
+
const fullscreenLayout = getLayout();
|
|
3438
|
+
const selectedDrawingLayout = getSelectedDrawingLayout(
|
|
3439
|
+
fullscreenLayout ? [fullscreenLayout] : [],
|
|
3440
|
+
drawings,
|
|
3441
|
+
selectedDrawingId
|
|
3442
|
+
);
|
|
3443
|
+
return /* @__PURE__ */ import_react9.default.createElement(
|
|
3444
|
+
"div",
|
|
3445
|
+
{
|
|
3446
|
+
className: `fixed inset-0 z-50 bg-background/95 backdrop-blur transition-opacity duration-150 ${visible ? "opacity-100" : "opacity-0"}`
|
|
3447
|
+
},
|
|
3448
|
+
/* @__PURE__ */ import_react9.default.createElement(
|
|
3449
|
+
"div",
|
|
3450
|
+
{
|
|
3451
|
+
ref: containerRef,
|
|
3452
|
+
className: `relative h-full overflow-hidden transition-transform duration-150 ${visible ? "scale-100" : "scale-[0.985]"}`,
|
|
3453
|
+
style: {
|
|
3454
|
+
cursor: rectangleZoomActive || activeDrawingTool ? "crosshair" : void 0
|
|
3455
|
+
},
|
|
3456
|
+
onPointerDown: handlePointerDown,
|
|
3457
|
+
onPointerMove: handlePointerMove,
|
|
3458
|
+
onPointerLeave: () => setCrosshair(null),
|
|
3459
|
+
onPointerUp: handlePointerUp,
|
|
3460
|
+
onPointerCancel: handlePointerUp,
|
|
3461
|
+
onContextMenu: handleContextMenu
|
|
3462
|
+
},
|
|
3463
|
+
/* @__PURE__ */ import_react9.default.createElement(
|
|
3464
|
+
"canvas",
|
|
3465
|
+
{
|
|
3466
|
+
ref: canvasRef,
|
|
3467
|
+
className: "pointer-events-none absolute left-0 top-0 z-10 block",
|
|
3468
|
+
style: { width: "100%", height: "100%" }
|
|
3469
|
+
}
|
|
3470
|
+
),
|
|
3471
|
+
/* @__PURE__ */ import_react9.default.createElement(
|
|
3472
|
+
ChartCell,
|
|
3473
|
+
{
|
|
3474
|
+
chart,
|
|
3475
|
+
axisOverlay,
|
|
3476
|
+
focused: true,
|
|
3477
|
+
height: "100%",
|
|
3478
|
+
isFullscreen: true,
|
|
3479
|
+
backgroundColor,
|
|
3480
|
+
onFocus: () => {
|
|
3481
|
+
},
|
|
3482
|
+
onFullscreenToggle: closeWithTransition,
|
|
3483
|
+
onReset,
|
|
3484
|
+
onJumpLatest,
|
|
3485
|
+
onRectangleZoomToggle: toggleRectangleZoom,
|
|
3486
|
+
rectangleZoomActive,
|
|
3487
|
+
movingAverage: movingAverageByChart?.[chart.id],
|
|
3488
|
+
onMovingAverageToggle,
|
|
3489
|
+
activeDrawingTool,
|
|
3490
|
+
onDrawingToolToggle: toggleDrawingTool,
|
|
3491
|
+
hasDrawings: getDrawingsForChart(drawings, chart.id).length > 0,
|
|
3492
|
+
onClearDrawingsRequest,
|
|
3493
|
+
setRef: (node) => {
|
|
3494
|
+
chartRef.current = node;
|
|
3495
|
+
}
|
|
3496
|
+
}
|
|
3497
|
+
),
|
|
3498
|
+
/* @__PURE__ */ import_react9.default.createElement(
|
|
3499
|
+
DrawingOverlay,
|
|
3500
|
+
{
|
|
3501
|
+
layouts: fullscreenLayout ? [fullscreenLayout] : [],
|
|
3502
|
+
drawings,
|
|
3503
|
+
draftDrawing,
|
|
3504
|
+
selectedDrawingId,
|
|
3505
|
+
projectPoint: (dataPoint, targetLayout) => projectDataPointToScreenPoint({
|
|
3506
|
+
point: dataPoint,
|
|
3507
|
+
layout: targetLayout,
|
|
3508
|
+
initialVisiblePoints,
|
|
3509
|
+
viewStateRef,
|
|
3510
|
+
yScaleRef,
|
|
3511
|
+
yCenterOffsetRef
|
|
3512
|
+
}),
|
|
3513
|
+
height: "100%"
|
|
3514
|
+
}
|
|
3515
|
+
),
|
|
3516
|
+
/* @__PURE__ */ import_react9.default.createElement(
|
|
3517
|
+
TopMarkersOverlay,
|
|
3518
|
+
{
|
|
3519
|
+
layouts: fullscreenLayout ? [fullscreenLayout] : [],
|
|
3520
|
+
markers: topMarkers,
|
|
3521
|
+
viewStateRef,
|
|
3522
|
+
initialVisiblePoints,
|
|
3523
|
+
onMarkerClick: (marker) => {
|
|
3524
|
+
closeWithTransition();
|
|
3525
|
+
requestAnimationFrame(() => {
|
|
3526
|
+
onTopMarkerClick?.(marker);
|
|
3527
|
+
});
|
|
3528
|
+
},
|
|
3529
|
+
height: "100%"
|
|
3530
|
+
}
|
|
3531
|
+
),
|
|
3532
|
+
selectedDrawingLayout ? /* @__PURE__ */ import_react9.default.createElement(
|
|
3533
|
+
DrawingOptionsToolbar,
|
|
3534
|
+
{
|
|
3535
|
+
drawing: selectedDrawingLayout.drawing,
|
|
3536
|
+
style: getDrawingOptionsToolbarStyle(selectedDrawingLayout.layout),
|
|
3537
|
+
onToggleExtend: toggleSelectedDrawingExtend,
|
|
3538
|
+
onColorChange: updateSelectedDrawingColor,
|
|
3539
|
+
onTextChange: updateSelectedDrawingText
|
|
3540
|
+
}
|
|
3541
|
+
) : null,
|
|
3542
|
+
fullscreenLayout && movingAverageByChart?.[chart.id]?.enabled ? /* @__PURE__ */ import_react9.default.createElement(
|
|
3543
|
+
MovingAverageOptionsToolbar,
|
|
3544
|
+
{
|
|
3545
|
+
movingAverage: movingAverageByChart[chart.id],
|
|
3546
|
+
style: getMovingAverageOptionsToolbarStyle(fullscreenLayout),
|
|
3547
|
+
onChange: (nextMovingAverage) => onMovingAverageChange?.(chart.id, nextMovingAverage)
|
|
3548
|
+
}
|
|
3549
|
+
) : null,
|
|
3550
|
+
/* @__PURE__ */ import_react9.default.createElement(
|
|
3551
|
+
CrosshairOverlay,
|
|
3552
|
+
{
|
|
3553
|
+
crosshair,
|
|
3554
|
+
height: "100%",
|
|
3555
|
+
xAxisLabel
|
|
3556
|
+
}
|
|
3557
|
+
),
|
|
3558
|
+
/* @__PURE__ */ import_react9.default.createElement(RectangleZoomOverlay, { rect: rectangleZoomRect })
|
|
3559
|
+
)
|
|
3560
|
+
);
|
|
3561
|
+
}
|
|
3562
|
+
function ChartGrid({
|
|
3563
|
+
charts,
|
|
3564
|
+
columns = 2,
|
|
3565
|
+
className = "",
|
|
3566
|
+
dataRevision = 0,
|
|
3567
|
+
initialVisiblePoints = null,
|
|
3568
|
+
backgroundColor = DEFAULT_CHART_BACKGROUND,
|
|
3569
|
+
antialiasLines = false,
|
|
3570
|
+
followLatest = false,
|
|
3571
|
+
followVisibleLatest = true,
|
|
3572
|
+
jumpToLatestRevision = 0,
|
|
3573
|
+
drawings = EMPTY_ARRAY,
|
|
3574
|
+
onDrawingsChange,
|
|
3575
|
+
activeDrawingTool = null,
|
|
3576
|
+
onActiveDrawingToolChange,
|
|
3577
|
+
selectedDrawingId = null,
|
|
3578
|
+
onSelectedDrawingIdChange,
|
|
3579
|
+
createDrawingId,
|
|
3580
|
+
onClearDrawingsRequest,
|
|
3581
|
+
onChartContextMenu,
|
|
3582
|
+
movingAverageByChart = EMPTY_OBJECT,
|
|
3583
|
+
onMovingAverageToggle,
|
|
3584
|
+
onMovingAverageChange,
|
|
3585
|
+
seriesOrderByChart = EMPTY_OBJECT,
|
|
3586
|
+
topMarkers = EMPTY_ARRAY,
|
|
3587
|
+
onTopMarkerClick,
|
|
3588
|
+
xAxisLabel = "STEP"
|
|
3589
|
+
}) {
|
|
3590
|
+
const containerRef = (0, import_react9.useRef)(null);
|
|
3591
|
+
const gridRef = (0, import_react9.useRef)(null);
|
|
3592
|
+
const canvasRef = (0, import_react9.useRef)(null);
|
|
3593
|
+
const glRef = (0, import_react9.useRef)(null);
|
|
3594
|
+
const programRef = (0, import_react9.useRef)(null);
|
|
3595
|
+
const antialiasProgramRef = (0, import_react9.useRef)(null);
|
|
3596
|
+
const seriesBufferCacheRef = (0, import_react9.useRef)(createSeriesBufferCache());
|
|
3597
|
+
const antialiasSeriesBufferCacheRef = (0, import_react9.useRef)(createSeriesBufferCache());
|
|
3598
|
+
const movingAverageCacheRef = (0, import_react9.useRef)(/* @__PURE__ */ new Map());
|
|
3599
|
+
const chartRefs = (0, import_react9.useRef)(/* @__PURE__ */ new Map());
|
|
3600
|
+
const viewStateRef = (0, import_react9.useRef)(/* @__PURE__ */ new Map());
|
|
3601
|
+
const yScaleRef = (0, import_react9.useRef)(/* @__PURE__ */ new Map());
|
|
3602
|
+
const yCenterOffsetRef = (0, import_react9.useRef)(/* @__PURE__ */ new Map());
|
|
3603
|
+
const yManualScaleRef = (0, import_react9.useRef)(/* @__PURE__ */ new Set());
|
|
3604
|
+
const latestXRef = (0, import_react9.useRef)(/* @__PURE__ */ new Map());
|
|
3605
|
+
const latestJumpRevisionRef = (0, import_react9.useRef)(jumpToLatestRevision);
|
|
3606
|
+
const dragRef = (0, import_react9.useRef)(null);
|
|
3607
|
+
const rectangleZoomDragRef = (0, import_react9.useRef)(null);
|
|
3608
|
+
const scrollRafRef = (0, import_react9.useRef)(null);
|
|
3609
|
+
const [revision, setRevision] = (0, import_react9.useState)(0);
|
|
3610
|
+
const [crosshair, setCrosshair] = (0, import_react9.useState)(null);
|
|
3611
|
+
const [axisOverlays, setAxisOverlays] = (0, import_react9.useState)({});
|
|
3612
|
+
const [focusedChartId, setFocusedChartId] = (0, import_react9.useState)(null);
|
|
3613
|
+
const [fullscreenChartId, setFullscreenChartId] = (0, import_react9.useState)(null);
|
|
3614
|
+
const [rectangleZoomChartId, setRectangleZoomChartId] = (0, import_react9.useState)(null);
|
|
3615
|
+
const [rectangleZoomRect, setRectangleZoomRect] = (0, import_react9.useState)(null);
|
|
3616
|
+
const requestRender = (0, import_react9.useCallback)(() => {
|
|
3617
|
+
setRevision((value) => value + 1);
|
|
3618
|
+
}, []);
|
|
3619
|
+
const {
|
|
3620
|
+
draftDrawing,
|
|
3621
|
+
drawingSessionRef,
|
|
3622
|
+
drawingEditRef,
|
|
3623
|
+
clearDraft,
|
|
3624
|
+
cancelDrawing,
|
|
3625
|
+
toggleDrawingTool,
|
|
3626
|
+
commitDrawing,
|
|
3627
|
+
startDraftDrawing,
|
|
3628
|
+
updateDraftDrawing,
|
|
3629
|
+
startEditDrawing,
|
|
3630
|
+
finishEditDrawing,
|
|
3631
|
+
deleteSelectedDrawing
|
|
3632
|
+
} = useDrawingInteractions({
|
|
3633
|
+
drawings,
|
|
3634
|
+
onDrawingsChange,
|
|
3635
|
+
activeDrawingTool,
|
|
3636
|
+
onActiveDrawingToolChange,
|
|
3637
|
+
selectedDrawingId,
|
|
3638
|
+
onSelectedDrawingIdChange,
|
|
3639
|
+
createDrawingId,
|
|
3640
|
+
focusedChartId,
|
|
3641
|
+
requireFocusedChart: true,
|
|
3642
|
+
onModeChange: () => {
|
|
3643
|
+
setRectangleZoomChartId(null);
|
|
3644
|
+
setRectangleZoomRect(null);
|
|
3645
|
+
rectangleZoomDragRef.current = null;
|
|
3646
|
+
}
|
|
3647
|
+
});
|
|
3648
|
+
const closeFullscreen = (0, import_react9.useCallback)(() => {
|
|
3649
|
+
setFullscreenChartId(null);
|
|
3650
|
+
setCrosshair(null);
|
|
3651
|
+
requestRender();
|
|
3652
|
+
}, [requestRender]);
|
|
3653
|
+
const openFullscreen = (0, import_react9.useCallback)(
|
|
3654
|
+
(chartId) => {
|
|
3655
|
+
setFocusedChartId(chartId);
|
|
3656
|
+
setFullscreenChartId(chartId);
|
|
3657
|
+
setCrosshair(null);
|
|
3658
|
+
setRectangleZoomChartId(null);
|
|
3659
|
+
setRectangleZoomRect(null);
|
|
3660
|
+
rectangleZoomDragRef.current = null;
|
|
3661
|
+
clearDraft();
|
|
3662
|
+
requestRender();
|
|
3663
|
+
},
|
|
3664
|
+
[clearDraft, requestRender]
|
|
3665
|
+
);
|
|
3666
|
+
const toggleRectangleZoom = (0, import_react9.useCallback)((chartId) => {
|
|
3667
|
+
setFocusedChartId(chartId);
|
|
3668
|
+
setRectangleZoomRect(null);
|
|
3669
|
+
rectangleZoomDragRef.current = null;
|
|
3670
|
+
clearDraft();
|
|
3671
|
+
onActiveDrawingToolChange?.(null);
|
|
3672
|
+
setRectangleZoomChartId((current) => current === chartId ? null : chartId);
|
|
3673
|
+
}, [clearDraft, onActiveDrawingToolChange]);
|
|
3674
|
+
const toggleMovingAverage = (0, import_react9.useCallback)(
|
|
3675
|
+
(chartId) => {
|
|
3676
|
+
onMovingAverageToggle?.(chartId);
|
|
3677
|
+
setFocusedChartId(chartId);
|
|
3678
|
+
setRectangleZoomChartId(null);
|
|
3679
|
+
clearDraft();
|
|
3680
|
+
onActiveDrawingToolChange?.(null);
|
|
3681
|
+
requestRender();
|
|
3682
|
+
},
|
|
3683
|
+
[
|
|
3684
|
+
clearDraft,
|
|
3685
|
+
onActiveDrawingToolChange,
|
|
3686
|
+
onMovingAverageToggle,
|
|
3687
|
+
requestRender
|
|
3688
|
+
]
|
|
3689
|
+
);
|
|
3690
|
+
const toggleSelectedDrawingExtend = (0, import_react9.useCallback)(() => {
|
|
3691
|
+
if (!selectedDrawingId || !onDrawingsChange) return;
|
|
3692
|
+
onDrawingsChange(
|
|
3693
|
+
updateDrawingById(drawings, selectedDrawingId, (drawing) => ({
|
|
3694
|
+
...drawing,
|
|
3695
|
+
style: {
|
|
3696
|
+
...drawing.style,
|
|
3697
|
+
extendRight: drawing.style?.extendRight === false
|
|
3698
|
+
}
|
|
3699
|
+
}))
|
|
3700
|
+
);
|
|
3701
|
+
}, [drawings, onDrawingsChange, selectedDrawingId]);
|
|
3702
|
+
const updateSelectedDrawingColor = (0, import_react9.useCallback)(
|
|
3703
|
+
(color) => {
|
|
3704
|
+
if (!selectedDrawingId || !onDrawingsChange) return;
|
|
3705
|
+
onDrawingsChange(
|
|
3706
|
+
updateDrawingById(drawings, selectedDrawingId, (drawing) => ({
|
|
3707
|
+
...drawing,
|
|
3708
|
+
style: {
|
|
3709
|
+
...drawing.style,
|
|
3710
|
+
color
|
|
3711
|
+
}
|
|
3712
|
+
}))
|
|
3713
|
+
);
|
|
3714
|
+
},
|
|
3715
|
+
[drawings, onDrawingsChange, selectedDrawingId]
|
|
3716
|
+
);
|
|
3717
|
+
const updateSelectedDrawingText = (0, import_react9.useCallback)(
|
|
3718
|
+
(text) => {
|
|
3719
|
+
if (!selectedDrawingId || !onDrawingsChange) return;
|
|
3720
|
+
onDrawingsChange(
|
|
3721
|
+
updateDrawingById(drawings, selectedDrawingId, (drawing) => ({
|
|
3722
|
+
...drawing,
|
|
3723
|
+
style: {
|
|
3724
|
+
...drawing.style,
|
|
3725
|
+
text
|
|
3726
|
+
}
|
|
3727
|
+
}))
|
|
3728
|
+
);
|
|
3729
|
+
},
|
|
3730
|
+
[drawings, onDrawingsChange, selectedDrawingId]
|
|
3731
|
+
);
|
|
3732
|
+
const { getAppendAnimatedPoint } = useAppendAnimations({
|
|
3733
|
+
charts,
|
|
3734
|
+
dataRevision,
|
|
3735
|
+
requestRender
|
|
3736
|
+
});
|
|
3737
|
+
(0, import_react9.useEffect)(() => {
|
|
3738
|
+
if (!focusedChartId) return;
|
|
3739
|
+
if (charts.some((chart) => chart.id === focusedChartId)) return;
|
|
3740
|
+
setFocusedChartId(null);
|
|
3741
|
+
}, [charts, focusedChartId]);
|
|
3742
|
+
(0, import_react9.useEffect)(() => {
|
|
3743
|
+
if (!fullscreenChartId) return;
|
|
3744
|
+
if (charts.some((chart) => chart.id === fullscreenChartId)) return;
|
|
3745
|
+
setFullscreenChartId(null);
|
|
3746
|
+
}, [charts, fullscreenChartId]);
|
|
3747
|
+
(0, import_react9.useEffect)(() => {
|
|
3748
|
+
const gl = glRef.current;
|
|
3749
|
+
if (!gl) return;
|
|
3750
|
+
const activeSeriesIds = new Set(
|
|
3751
|
+
charts.flatMap((chart) => chart.series.map((series) => series.id))
|
|
3752
|
+
);
|
|
3753
|
+
charts.forEach((chart) => {
|
|
3754
|
+
const movingAverage = normalizeMovingAverage(movingAverageByChart?.[chart.id]);
|
|
3755
|
+
if (!movingAverage) return;
|
|
3756
|
+
chart.series.forEach((series) => {
|
|
3757
|
+
activeSeriesIds.add(getMovingAverageCacheKey(series, movingAverage));
|
|
3758
|
+
});
|
|
3759
|
+
});
|
|
3760
|
+
seriesBufferCacheRef.current.forEach((entry, seriesId) => {
|
|
3761
|
+
if (activeSeriesIds.has(seriesId)) return;
|
|
3762
|
+
if (entry.buffer) gl.deleteBuffer(entry.buffer);
|
|
3763
|
+
seriesBufferCacheRef.current.delete(seriesId);
|
|
3764
|
+
});
|
|
3765
|
+
antialiasSeriesBufferCacheRef.current.forEach((entry, seriesId) => {
|
|
3766
|
+
if (activeSeriesIds.has(seriesId)) return;
|
|
3767
|
+
if (entry.buffer) gl.deleteBuffer(entry.buffer);
|
|
3768
|
+
antialiasSeriesBufferCacheRef.current.delete(seriesId);
|
|
3769
|
+
});
|
|
3770
|
+
movingAverageCacheRef.current.forEach((entry, seriesId) => {
|
|
3771
|
+
if (activeSeriesIds.has(seriesId)) return;
|
|
3772
|
+
movingAverageCacheRef.current.delete(seriesId);
|
|
3773
|
+
});
|
|
3774
|
+
}, [charts, movingAverageByChart]);
|
|
3775
|
+
(0, import_react9.useEffect)(() => {
|
|
3776
|
+
charts.forEach((chart) => {
|
|
3777
|
+
if (!viewStateRef.current.has(chart.id)) {
|
|
3778
|
+
viewStateRef.current.set(
|
|
3779
|
+
chart.id,
|
|
3780
|
+
getInitialView(chart, initialVisiblePoints)
|
|
3781
|
+
);
|
|
3782
|
+
}
|
|
3783
|
+
if (!yScaleRef.current.has(chart.id)) {
|
|
3784
|
+
yScaleRef.current.set(chart.id, 1);
|
|
3785
|
+
}
|
|
3786
|
+
if (!yCenterOffsetRef.current.has(chart.id)) {
|
|
3787
|
+
yCenterOffsetRef.current.set(chart.id, 0);
|
|
3788
|
+
}
|
|
3789
|
+
if (!latestXRef.current.has(chart.id)) {
|
|
3790
|
+
latestXRef.current.set(chart.id, getChartXBounds(chart).maxX);
|
|
3791
|
+
}
|
|
3792
|
+
});
|
|
3793
|
+
}, [charts, initialVisiblePoints]);
|
|
3794
|
+
(0, import_react9.useEffect)(() => {
|
|
3795
|
+
charts.forEach((chart) => {
|
|
3796
|
+
const previousMax = latestXRef.current.get(chart.id);
|
|
3797
|
+
const { maxX } = getChartXBounds(chart);
|
|
3798
|
+
if (!Number.isFinite(maxX)) return;
|
|
3799
|
+
if (!Number.isFinite(previousMax)) {
|
|
3800
|
+
latestXRef.current.set(chart.id, maxX);
|
|
3801
|
+
return;
|
|
3802
|
+
}
|
|
3803
|
+
if (maxX !== previousMax) {
|
|
3804
|
+
const state = viewStateRef.current.get(chart.id) || getInitialView(chart, initialVisiblePoints);
|
|
3805
|
+
const span = state.xMax - state.xMin;
|
|
3806
|
+
const rightEdgeFollowMin = state.xMax - span * FOLLOW_VISIBLE_RIGHT_EDGE_RATIO;
|
|
3807
|
+
const previousMaxVisible = previousMax >= state.xMin && previousMax <= state.xMax;
|
|
3808
|
+
const previousMaxNearRightEdge = previousMax >= rightEdgeFollowMin;
|
|
3809
|
+
if (followLatest || followVisibleLatest && previousMaxVisible && previousMaxNearRightEdge) {
|
|
3810
|
+
const delta = maxX - previousMax;
|
|
3811
|
+
const nextState = {
|
|
3812
|
+
xMin: state.xMin + delta,
|
|
3813
|
+
xMax: state.xMax + delta
|
|
3814
|
+
};
|
|
3815
|
+
viewStateRef.current.set(chart.id, nextState);
|
|
3816
|
+
const latestYBounds = getLatestYBounds(chart);
|
|
3817
|
+
if (Number.isFinite(latestYBounds.minY) && Number.isFinite(latestYBounds.maxY)) {
|
|
3818
|
+
const baseYRange = getYRange(
|
|
3819
|
+
chart,
|
|
3820
|
+
nextState.xMin,
|
|
3821
|
+
nextState.xMax,
|
|
3822
|
+
getPlotWidth(chartRefs.current.get(chart.id))
|
|
3823
|
+
);
|
|
3824
|
+
const scale = yScaleRef.current.get(chart.id) ?? 1;
|
|
3825
|
+
const currentOffset = yCenterOffsetRef.current.get(chart.id) ?? 0;
|
|
3826
|
+
const scaledYRange = applyYScale(baseYRange, scale, currentOffset);
|
|
3827
|
+
const pad = (scaledYRange.maxY - scaledYRange.minY) * 0.08;
|
|
3828
|
+
let nextOffset = currentOffset;
|
|
3829
|
+
if (latestYBounds.maxY > scaledYRange.maxY - pad) {
|
|
3830
|
+
nextOffset += latestYBounds.maxY - (scaledYRange.maxY - pad);
|
|
3831
|
+
} else if (latestYBounds.minY < scaledYRange.minY + pad) {
|
|
3832
|
+
nextOffset += latestYBounds.minY - (scaledYRange.minY + pad);
|
|
3833
|
+
}
|
|
3834
|
+
if (nextOffset !== currentOffset) {
|
|
3835
|
+
yCenterOffsetRef.current.set(chart.id, nextOffset);
|
|
3836
|
+
}
|
|
3837
|
+
}
|
|
3838
|
+
}
|
|
3839
|
+
}
|
|
3840
|
+
latestXRef.current.set(chart.id, maxX);
|
|
3841
|
+
});
|
|
3842
|
+
}, [
|
|
3843
|
+
charts,
|
|
3844
|
+
dataRevision,
|
|
3845
|
+
followLatest,
|
|
3846
|
+
followVisibleLatest,
|
|
3847
|
+
initialVisiblePoints
|
|
3848
|
+
]);
|
|
3849
|
+
(0, import_react9.useEffect)(() => {
|
|
3850
|
+
if (latestJumpRevisionRef.current === jumpToLatestRevision) return;
|
|
3851
|
+
latestJumpRevisionRef.current = jumpToLatestRevision;
|
|
3852
|
+
charts.forEach((chart) => {
|
|
3853
|
+
const { maxX } = getChartXBounds(chart);
|
|
3854
|
+
if (!Number.isFinite(maxX)) return;
|
|
3855
|
+
const state = viewStateRef.current.get(chart.id) || getInitialView(chart, initialVisiblePoints);
|
|
3856
|
+
const span = Math.max(10, state.xMax - state.xMin);
|
|
3857
|
+
const rightPadding = span * JUMP_LATEST_RIGHT_PADDING_RATIO;
|
|
3858
|
+
const nextMax = maxX + rightPadding;
|
|
3859
|
+
viewStateRef.current.set(chart.id, {
|
|
3860
|
+
xMin: nextMax - span,
|
|
3861
|
+
xMax: nextMax
|
|
3862
|
+
});
|
|
3863
|
+
});
|
|
3864
|
+
requestRender();
|
|
3865
|
+
}, [charts, initialVisiblePoints, jumpToLatestRevision, requestRender]);
|
|
3866
|
+
const getChartLayout = (0, import_react9.useCallback)(() => {
|
|
3867
|
+
const container = containerRef.current;
|
|
3868
|
+
const grid = gridRef.current;
|
|
3869
|
+
if (!container) return [];
|
|
3870
|
+
return charts.map((chart) => {
|
|
3871
|
+
const node = chartRefs.current.get(chart.id);
|
|
3872
|
+
if (!node) return null;
|
|
3873
|
+
const rect = {
|
|
3874
|
+
x: node.offsetLeft,
|
|
3875
|
+
y: node.offsetTop,
|
|
3876
|
+
width: node.offsetWidth,
|
|
3877
|
+
height: node.offsetHeight
|
|
3878
|
+
};
|
|
3879
|
+
let parent = node.offsetParent;
|
|
3880
|
+
while (parent && parent !== container && parent !== grid) {
|
|
3881
|
+
rect.x += parent.offsetLeft;
|
|
3882
|
+
rect.y += parent.offsetTop;
|
|
3883
|
+
parent = parent.offsetParent;
|
|
3884
|
+
}
|
|
3885
|
+
const plot = {
|
|
3886
|
+
x: rect.x + PLOT_PADDING.left,
|
|
3887
|
+
y: rect.y + PLOT_PADDING.top,
|
|
3888
|
+
width: Math.max(
|
|
3889
|
+
1,
|
|
3890
|
+
rect.width - PLOT_PADDING.left - PLOT_PADDING.right
|
|
3891
|
+
),
|
|
3892
|
+
height: Math.max(
|
|
3893
|
+
1,
|
|
3894
|
+
rect.height - PLOT_PADDING.top - PLOT_PADDING.bottom
|
|
3895
|
+
)
|
|
3896
|
+
};
|
|
3897
|
+
const visibleTop = container.scrollTop;
|
|
3898
|
+
const visibleBottom = visibleTop + container.clientHeight;
|
|
3899
|
+
const visible = rect.y + rect.height >= visibleTop && rect.y <= visibleBottom;
|
|
3900
|
+
return { chart, rect, plot, visible };
|
|
3901
|
+
}).filter(Boolean);
|
|
3902
|
+
}, [charts]);
|
|
3903
|
+
(0, import_react9.useEffect)(() => {
|
|
3904
|
+
const canvas = canvasRef.current;
|
|
3905
|
+
if (!canvas) return;
|
|
3906
|
+
const gl = canvas.getContext("webgl2", {
|
|
3907
|
+
antialias: true,
|
|
3908
|
+
alpha: true,
|
|
3909
|
+
depth: false,
|
|
3910
|
+
stencil: false,
|
|
3911
|
+
preserveDrawingBuffer: false
|
|
3912
|
+
});
|
|
3913
|
+
if (!gl) return;
|
|
3914
|
+
glRef.current = gl;
|
|
3915
|
+
programRef.current = createProgram(gl);
|
|
3916
|
+
antialiasProgramRef.current = createAntialiasProgram(gl);
|
|
3917
|
+
requestRender();
|
|
3918
|
+
return () => {
|
|
3919
|
+
deleteSeriesBuffers(gl, seriesBufferCacheRef.current);
|
|
3920
|
+
deleteSeriesBuffers(gl, antialiasSeriesBufferCacheRef.current);
|
|
3921
|
+
glRef.current = null;
|
|
3922
|
+
programRef.current = null;
|
|
3923
|
+
antialiasProgramRef.current = null;
|
|
3924
|
+
};
|
|
3925
|
+
}, [requestRender]);
|
|
3926
|
+
(0, import_react9.useEffect)(() => {
|
|
3927
|
+
const container = containerRef.current;
|
|
3928
|
+
if (!container) return;
|
|
3929
|
+
const observer = new ResizeObserver(requestRender);
|
|
3930
|
+
observer.observe(container);
|
|
3931
|
+
return () => observer.disconnect();
|
|
3932
|
+
}, [requestRender]);
|
|
3933
|
+
(0, import_react9.useEffect)(() => {
|
|
3934
|
+
const container = containerRef.current;
|
|
3935
|
+
if (!container) return void 0;
|
|
3936
|
+
const handleScroll = () => {
|
|
3937
|
+
setCrosshair(null);
|
|
3938
|
+
if (scrollRafRef.current != null) return;
|
|
3939
|
+
scrollRafRef.current = requestAnimationFrame(() => {
|
|
3940
|
+
scrollRafRef.current = null;
|
|
3941
|
+
requestRender();
|
|
3942
|
+
});
|
|
3943
|
+
};
|
|
3944
|
+
container.addEventListener("scroll", handleScroll, { passive: true });
|
|
3945
|
+
return () => {
|
|
3946
|
+
container.removeEventListener("scroll", handleScroll);
|
|
3947
|
+
if (scrollRafRef.current != null) {
|
|
3948
|
+
cancelAnimationFrame(scrollRafRef.current);
|
|
3949
|
+
scrollRafRef.current = null;
|
|
3950
|
+
}
|
|
3951
|
+
};
|
|
3952
|
+
}, [requestRender]);
|
|
3953
|
+
(0, import_react9.useEffect)(() => {
|
|
3954
|
+
const container = containerRef.current;
|
|
3955
|
+
const canvas = canvasRef.current;
|
|
3956
|
+
const gl = glRef.current;
|
|
3957
|
+
const program = programRef.current;
|
|
3958
|
+
const antialiasProgram = antialiasProgramRef.current;
|
|
3959
|
+
const seriesBufferCache = seriesBufferCacheRef.current;
|
|
3960
|
+
const antialiasSeriesBufferCache = antialiasSeriesBufferCacheRef.current;
|
|
3961
|
+
if (!container || !canvas || !gl || !program) return;
|
|
3962
|
+
if (fullscreenChartId) {
|
|
3963
|
+
canvas.style.transform = "";
|
|
3964
|
+
gl.viewport(0, 0, canvas.width || 1, canvas.height || 1);
|
|
3965
|
+
gl.clearColor(0, 0, 0, 0);
|
|
3966
|
+
gl.clear(gl.COLOR_BUFFER_BIT);
|
|
3967
|
+
setAxisOverlays({});
|
|
3968
|
+
return;
|
|
3969
|
+
}
|
|
3970
|
+
const scrollLeft = container.scrollLeft;
|
|
3971
|
+
const scrollTop = container.scrollTop;
|
|
3972
|
+
canvas.style.transform = `translate(${scrollLeft}px, ${scrollTop}px)`;
|
|
3973
|
+
const nextAxisOverlays = drawChartLayouts({
|
|
3974
|
+
canvas,
|
|
3975
|
+
width: container.clientWidth,
|
|
3976
|
+
height: container.clientHeight,
|
|
3977
|
+
gl,
|
|
3978
|
+
program,
|
|
3979
|
+
antialiasProgram,
|
|
3980
|
+
antialiasLines,
|
|
3981
|
+
layouts: getChartLayout().map(
|
|
3982
|
+
(layout) => toViewportLayout(layout, scrollLeft, scrollTop)
|
|
3983
|
+
),
|
|
3984
|
+
viewStateRef,
|
|
3985
|
+
yScaleRef,
|
|
3986
|
+
yCenterOffsetRef,
|
|
3987
|
+
seriesBufferCache,
|
|
3988
|
+
antialiasSeriesBufferCache,
|
|
3989
|
+
initialVisiblePoints,
|
|
3990
|
+
getAppendAnimatedPoint,
|
|
3991
|
+
movingAverageByChart,
|
|
3992
|
+
movingAverageCache: movingAverageCacheRef.current,
|
|
3993
|
+
seriesOrderByChart
|
|
3994
|
+
});
|
|
3995
|
+
setAxisOverlays(nextAxisOverlays);
|
|
3996
|
+
}, [
|
|
3997
|
+
charts,
|
|
3998
|
+
antialiasLines,
|
|
3999
|
+
dataRevision,
|
|
4000
|
+
fullscreenChartId,
|
|
4001
|
+
getAppendAnimatedPoint,
|
|
4002
|
+
getChartLayout,
|
|
4003
|
+
initialVisiblePoints,
|
|
4004
|
+
movingAverageByChart,
|
|
4005
|
+
seriesOrderByChart,
|
|
4006
|
+
revision
|
|
4007
|
+
]);
|
|
4008
|
+
const findLayoutAt = (0, import_react9.useCallback)(
|
|
4009
|
+
(clientX, clientY) => getChartLayout().find(
|
|
4010
|
+
({ plot, visible }) => visible && clientX >= plot.x && clientX <= plot.x + plot.width && clientY >= plot.y && clientY <= plot.y + plot.height
|
|
4011
|
+
),
|
|
4012
|
+
[getChartLayout]
|
|
4013
|
+
);
|
|
4014
|
+
const findYAxisLayoutAt = (0, import_react9.useCallback)(
|
|
4015
|
+
(clientX, clientY) => getChartLayout().find(
|
|
4016
|
+
({ rect, plot, visible }) => visible && clientX >= plot.x + plot.width && clientX <= rect.x + rect.width && clientY >= plot.y && clientY <= plot.y + plot.height
|
|
4017
|
+
),
|
|
4018
|
+
[getChartLayout]
|
|
4019
|
+
);
|
|
4020
|
+
const findXAxisLayoutAt = (0, import_react9.useCallback)(
|
|
4021
|
+
(clientX, clientY) => getChartLayout().find(
|
|
4022
|
+
({ rect, plot, visible }) => visible && clientX >= plot.x && clientX <= plot.x + plot.width && clientY >= plot.y + plot.height && clientY <= rect.y + rect.height
|
|
4023
|
+
),
|
|
4024
|
+
[getChartLayout]
|
|
4025
|
+
);
|
|
4026
|
+
const getLocalPoint = (0, import_react9.useCallback)((event) => {
|
|
4027
|
+
const container = containerRef.current;
|
|
4028
|
+
const rect = container?.getBoundingClientRect();
|
|
4029
|
+
if (!rect) return null;
|
|
4030
|
+
return {
|
|
4031
|
+
x: event.clientX - rect.left,
|
|
4032
|
+
y: event.clientY - rect.top + container.scrollTop
|
|
4033
|
+
};
|
|
4034
|
+
}, []);
|
|
4035
|
+
const updateCrosshair = (0, import_react9.useCallback)(
|
|
4036
|
+
(event) => {
|
|
4037
|
+
const point = getLocalPoint(event);
|
|
4038
|
+
if (!point) return;
|
|
4039
|
+
const layout = findLayoutAt(point.x, point.y);
|
|
4040
|
+
if (!layout) {
|
|
4041
|
+
setCrosshair(null);
|
|
4042
|
+
return;
|
|
4043
|
+
}
|
|
4044
|
+
const state = viewStateRef.current.get(layout.chart.id) || getInitialView(layout.chart, initialVisiblePoints);
|
|
4045
|
+
const xRatio = (point.x - layout.plot.x) / layout.plot.width;
|
|
4046
|
+
const xValue = state.xMin + xRatio * (state.xMax - state.xMin);
|
|
4047
|
+
const yRange = getYRange(
|
|
4048
|
+
layout.chart,
|
|
4049
|
+
state.xMin,
|
|
4050
|
+
state.xMax,
|
|
4051
|
+
layout.plot.width
|
|
4052
|
+
);
|
|
4053
|
+
const scaledYRange = applyYScale(
|
|
4054
|
+
yRange,
|
|
4055
|
+
yScaleRef.current.get(layout.chart.id) ?? 1,
|
|
4056
|
+
yCenterOffsetRef.current.get(layout.chart.id) ?? 0
|
|
4057
|
+
);
|
|
4058
|
+
const yRatio = (point.y - layout.plot.y) / layout.plot.height;
|
|
4059
|
+
const yValue = scaledYRange.maxY - yRatio * (scaledYRange.maxY - scaledYRange.minY);
|
|
4060
|
+
const nearestPoints = getOrderedSeries(layout.chart, seriesOrderByChart).map((series) => {
|
|
4061
|
+
const visiblePoints = series.getVisiblePoints(
|
|
4062
|
+
state.xMin,
|
|
4063
|
+
state.xMax,
|
|
4064
|
+
layout.plot.width
|
|
4065
|
+
);
|
|
4066
|
+
const index = getNearestPointIndex(visiblePoints.x, xValue);
|
|
4067
|
+
if (index < 0) return null;
|
|
4068
|
+
const pointX = visiblePoints.x[index];
|
|
4069
|
+
const pointY = visiblePoints.y[index];
|
|
4070
|
+
const pointXRatio = (pointX - state.xMin) / (state.xMax - state.xMin);
|
|
4071
|
+
const pointYRatio = (scaledYRange.maxY - pointY) / (scaledYRange.maxY - scaledYRange.minY);
|
|
4072
|
+
return {
|
|
4073
|
+
id: series.id,
|
|
4074
|
+
name: series.name,
|
|
4075
|
+
color: series.color,
|
|
4076
|
+
xValue: pointX,
|
|
4077
|
+
yValue: pointY,
|
|
4078
|
+
x: layout.plot.x + pointXRatio * layout.plot.width,
|
|
4079
|
+
y: layout.plot.y + pointYRatio * layout.plot.height
|
|
4080
|
+
};
|
|
4081
|
+
}).filter(Boolean).filter(
|
|
4082
|
+
(nearestPoint) => nearestPoint.x >= layout.plot.x - 1 && nearestPoint.x <= layout.plot.x + layout.plot.width + 1 && nearestPoint.y >= layout.plot.y - 1 && nearestPoint.y <= layout.plot.y + layout.plot.height + 1
|
|
4083
|
+
);
|
|
4084
|
+
const primaryPoint = nearestPoints[0];
|
|
4085
|
+
const tooltipLeft = primaryPoint && primaryPoint.x + TOOLTIP_WIDTH + TOOLTIP_OFFSET > layout.rect.x + layout.rect.width ? primaryPoint.x - TOOLTIP_WIDTH - TOOLTIP_OFFSET : (primaryPoint?.x ?? point.x) + TOOLTIP_OFFSET;
|
|
4086
|
+
const tooltipTop = Math.max(
|
|
4087
|
+
layout.rect.y + PLOT_PADDING.top,
|
|
4088
|
+
Math.min(
|
|
4089
|
+
(primaryPoint?.y ?? point.y) + TOOLTIP_OFFSET,
|
|
4090
|
+
layout.rect.y + layout.rect.height - 96
|
|
4091
|
+
)
|
|
4092
|
+
);
|
|
4093
|
+
setCrosshair({
|
|
4094
|
+
chartId: layout.chart.id,
|
|
4095
|
+
title: layout.chart.title,
|
|
4096
|
+
x: point.x,
|
|
4097
|
+
y: point.y,
|
|
4098
|
+
xValue: primaryPoint?.xValue ?? xValue,
|
|
4099
|
+
yValue: primaryPoint?.yValue ?? yValue,
|
|
4100
|
+
points: nearestPoints,
|
|
4101
|
+
tooltipX: Math.max(layout.rect.x + 6, tooltipLeft),
|
|
4102
|
+
tooltipY: tooltipTop,
|
|
4103
|
+
bucketSize: scaledYRange.bucketSize,
|
|
4104
|
+
renderedPoints: scaledYRange.renderedPoints
|
|
4105
|
+
});
|
|
4106
|
+
},
|
|
4107
|
+
[findLayoutAt, getLocalPoint, initialVisiblePoints, seriesOrderByChart]
|
|
4108
|
+
);
|
|
4109
|
+
const jumpChartToLatest = (0, import_react9.useCallback)(
|
|
4110
|
+
(chartId) => {
|
|
4111
|
+
const chart = charts.find((candidate) => candidate.id === chartId);
|
|
4112
|
+
if (!chart) return;
|
|
4113
|
+
const { maxX } = getChartXBounds(chart);
|
|
4114
|
+
if (!Number.isFinite(maxX)) return;
|
|
4115
|
+
const state = viewStateRef.current.get(chart.id) || getInitialView(chart, initialVisiblePoints);
|
|
4116
|
+
const span = Math.max(X_SCALE_MIN_SPAN, state.xMax - state.xMin);
|
|
4117
|
+
const rightPadding = span * JUMP_LATEST_RIGHT_PADDING_RATIO;
|
|
4118
|
+
const nextMax = maxX + rightPadding;
|
|
4119
|
+
viewStateRef.current.set(chart.id, {
|
|
4120
|
+
xMin: nextMax - span,
|
|
4121
|
+
xMax: nextMax
|
|
4122
|
+
});
|
|
4123
|
+
yCenterOffsetRef.current.set(chart.id, 0);
|
|
4124
|
+
requestRender();
|
|
4125
|
+
},
|
|
4126
|
+
[charts, initialVisiblePoints, requestRender]
|
|
4127
|
+
);
|
|
4128
|
+
const resetChartView = (0, import_react9.useCallback)(
|
|
4129
|
+
(chartId) => {
|
|
4130
|
+
const chart = charts.find((candidate) => candidate.id === chartId);
|
|
4131
|
+
if (!chart) return;
|
|
4132
|
+
viewStateRef.current.set(chart.id, getInitialView(chart, initialVisiblePoints));
|
|
4133
|
+
yScaleRef.current.set(chart.id, 1);
|
|
4134
|
+
yCenterOffsetRef.current.set(chart.id, 0);
|
|
4135
|
+
yManualScaleRef.current.delete(chart.id);
|
|
4136
|
+
if (rectangleZoomChartId === chart.id) {
|
|
4137
|
+
setRectangleZoomChartId(null);
|
|
4138
|
+
setRectangleZoomRect(null);
|
|
4139
|
+
rectangleZoomDragRef.current = null;
|
|
4140
|
+
}
|
|
4141
|
+
requestRender();
|
|
4142
|
+
},
|
|
4143
|
+
[charts, initialVisiblePoints, rectangleZoomChartId, requestRender]
|
|
4144
|
+
);
|
|
4145
|
+
const handleContextMenu = (0, import_react9.useCallback)(
|
|
4146
|
+
(event) => {
|
|
4147
|
+
if (fullscreenChartId) return;
|
|
4148
|
+
const point = getLocalPoint(event);
|
|
4149
|
+
if (!point) return;
|
|
4150
|
+
const layout = findLayoutAt(point.x, point.y);
|
|
4151
|
+
if (!layout) return;
|
|
4152
|
+
event.preventDefault();
|
|
4153
|
+
setFocusedChartId(layout.chart.id);
|
|
4154
|
+
onChartContextMenu?.({
|
|
4155
|
+
chart: layout.chart,
|
|
4156
|
+
event,
|
|
4157
|
+
point: getChartContextMenuPoint({
|
|
4158
|
+
point,
|
|
4159
|
+
chart: layout.chart,
|
|
4160
|
+
layout,
|
|
4161
|
+
initialVisiblePoints,
|
|
4162
|
+
viewStateRef,
|
|
4163
|
+
yScaleRef,
|
|
4164
|
+
yCenterOffsetRef
|
|
4165
|
+
})
|
|
4166
|
+
});
|
|
4167
|
+
},
|
|
4168
|
+
[
|
|
4169
|
+
findLayoutAt,
|
|
4170
|
+
fullscreenChartId,
|
|
4171
|
+
getLocalPoint,
|
|
4172
|
+
initialVisiblePoints,
|
|
4173
|
+
onChartContextMenu
|
|
4174
|
+
]
|
|
4175
|
+
);
|
|
4176
|
+
const handlePointerDown = (0, import_react9.useCallback)(
|
|
4177
|
+
(event) => {
|
|
4178
|
+
if (fullscreenChartId) return;
|
|
4179
|
+
const point = getLocalPoint(event);
|
|
4180
|
+
if (!point) return;
|
|
4181
|
+
const drawingLayout = findLayoutAt(point.x, point.y);
|
|
4182
|
+
if (drawingLayout && activeDrawingTool && DRAWING_TOOLS.has(activeDrawingTool)) {
|
|
4183
|
+
if (event.button !== 0) return;
|
|
4184
|
+
event.preventDefault();
|
|
4185
|
+
setFocusedChartId(drawingLayout.chart.id);
|
|
4186
|
+
const dataPoint = screenPointToDataPoint({
|
|
4187
|
+
point,
|
|
4188
|
+
chart: drawingLayout.chart,
|
|
4189
|
+
plot: drawingLayout.plot,
|
|
4190
|
+
initialVisiblePoints,
|
|
4191
|
+
viewStateRef,
|
|
4192
|
+
yScaleRef,
|
|
4193
|
+
yCenterOffsetRef
|
|
4194
|
+
});
|
|
4195
|
+
if (activeDrawingTool === "hline" || activeDrawingTool === "vline" || activeDrawingTool === "pin") {
|
|
4196
|
+
commitDrawing({
|
|
4197
|
+
chartId: drawingLayout.chart.id,
|
|
4198
|
+
type: activeDrawingTool,
|
|
4199
|
+
start: dataPoint,
|
|
4200
|
+
end: dataPoint
|
|
4201
|
+
});
|
|
4202
|
+
return;
|
|
4203
|
+
}
|
|
4204
|
+
const session = drawingSessionRef.current;
|
|
4205
|
+
if (!session.startPoint || session.chartId !== drawingLayout.chart.id) {
|
|
4206
|
+
startDraftDrawing({
|
|
4207
|
+
chartId: drawingLayout.chart.id,
|
|
4208
|
+
type: "trendline",
|
|
4209
|
+
start: dataPoint,
|
|
4210
|
+
end: dataPoint
|
|
4211
|
+
});
|
|
4212
|
+
return;
|
|
4213
|
+
}
|
|
4214
|
+
commitDrawing({
|
|
4215
|
+
chartId: drawingLayout.chart.id,
|
|
4216
|
+
type: "trendline",
|
|
4217
|
+
start: session.startPoint,
|
|
4218
|
+
end: dataPoint
|
|
4219
|
+
});
|
|
4220
|
+
return;
|
|
4221
|
+
}
|
|
4222
|
+
if (drawingLayout && Array.isArray(drawings) && drawings.length > 0) {
|
|
4223
|
+
const chartDrawings = getDrawingsForChart(
|
|
4224
|
+
drawings,
|
|
4225
|
+
drawingLayout.chart.id
|
|
4226
|
+
);
|
|
4227
|
+
for (let i = chartDrawings.length - 1; i >= 0; i -= 1) {
|
|
4228
|
+
const hit = hitTestDrawing({
|
|
4229
|
+
point,
|
|
4230
|
+
drawing: chartDrawings[i],
|
|
4231
|
+
layout: drawingLayout,
|
|
4232
|
+
projectPoint: (dataPoint, targetLayout) => projectDataPointToScreenPoint({
|
|
4233
|
+
point: dataPoint,
|
|
4234
|
+
layout: targetLayout,
|
|
4235
|
+
initialVisiblePoints,
|
|
4236
|
+
viewStateRef,
|
|
4237
|
+
yScaleRef,
|
|
4238
|
+
yCenterOffsetRef
|
|
4239
|
+
})
|
|
4240
|
+
});
|
|
4241
|
+
if (hit) {
|
|
4242
|
+
event.preventDefault();
|
|
4243
|
+
setFocusedChartId(drawingLayout.chart.id);
|
|
4244
|
+
onSelectedDrawingIdChange?.(hit.drawing.id);
|
|
4245
|
+
if (hit.endpoint || hit.drawing.type === "hline" || hit.drawing.type === "vline" || hit.drawing.type === "pin") {
|
|
4246
|
+
startEditDrawing({
|
|
4247
|
+
drawingId: hit.drawing.id,
|
|
4248
|
+
endpoint: hit.endpoint || "move"
|
|
4249
|
+
});
|
|
4250
|
+
event.currentTarget.setPointerCapture?.(event.pointerId);
|
|
4251
|
+
}
|
|
4252
|
+
return;
|
|
4253
|
+
}
|
|
4254
|
+
}
|
|
4255
|
+
onSelectedDrawingIdChange?.(null);
|
|
4256
|
+
}
|
|
4257
|
+
if (rectangleZoomChartId) {
|
|
4258
|
+
const layout2 = findLayoutAt(point.x, point.y);
|
|
4259
|
+
if (!layout2 || layout2.chart.id !== rectangleZoomChartId || event.button !== 0) {
|
|
4260
|
+
return;
|
|
4261
|
+
}
|
|
4262
|
+
event.preventDefault();
|
|
4263
|
+
const start = clampPointToPlot(point, layout2.plot);
|
|
4264
|
+
rectangleZoomDragRef.current = {
|
|
4265
|
+
chartId: layout2.chart.id,
|
|
4266
|
+
start,
|
|
4267
|
+
end: start
|
|
4268
|
+
};
|
|
4269
|
+
setRectangleZoomRect({ start, end: start });
|
|
4270
|
+
event.currentTarget.setPointerCapture?.(event.pointerId);
|
|
4271
|
+
return;
|
|
4272
|
+
}
|
|
4273
|
+
const yAxisLayout = findYAxisLayoutAt(point.x, point.y);
|
|
4274
|
+
if (yAxisLayout) {
|
|
4275
|
+
event.preventDefault();
|
|
4276
|
+
dragRef.current = {
|
|
4277
|
+
type: "y-scale",
|
|
4278
|
+
chartId: yAxisLayout.chart.id,
|
|
4279
|
+
startY: point.y,
|
|
4280
|
+
startScale: yScaleRef.current.get(yAxisLayout.chart.id) ?? 1
|
|
4281
|
+
};
|
|
4282
|
+
event.currentTarget.setPointerCapture?.(event.pointerId);
|
|
4283
|
+
return;
|
|
4284
|
+
}
|
|
4285
|
+
const xAxisLayout = findXAxisLayoutAt(point.x, point.y);
|
|
4286
|
+
if (xAxisLayout) {
|
|
4287
|
+
event.preventDefault();
|
|
4288
|
+
const state2 = viewStateRef.current.get(xAxisLayout.chart.id) || getInitialView(xAxisLayout.chart, initialVisiblePoints);
|
|
4289
|
+
dragRef.current = {
|
|
4290
|
+
type: "x-scale",
|
|
4291
|
+
chartId: xAxisLayout.chart.id,
|
|
4292
|
+
startX: point.x,
|
|
4293
|
+
startMin: state2.xMin,
|
|
4294
|
+
startMax: state2.xMax
|
|
4295
|
+
};
|
|
4296
|
+
event.currentTarget.setPointerCapture?.(event.pointerId);
|
|
4297
|
+
return;
|
|
4298
|
+
}
|
|
4299
|
+
const layout = findLayoutAt(point.x, point.y);
|
|
4300
|
+
if (!layout) return;
|
|
4301
|
+
const state = viewStateRef.current.get(layout.chart.id) || getInitialView(layout.chart, initialVisiblePoints);
|
|
4302
|
+
const yRange = getYRange(
|
|
4303
|
+
layout.chart,
|
|
4304
|
+
state.xMin,
|
|
4305
|
+
state.xMax,
|
|
4306
|
+
layout.plot.width
|
|
4307
|
+
);
|
|
4308
|
+
const scaledYRange = applyYScale(
|
|
4309
|
+
yRange,
|
|
4310
|
+
yScaleRef.current.get(layout.chart.id) ?? 1,
|
|
4311
|
+
yCenterOffsetRef.current.get(layout.chart.id) ?? 0
|
|
4312
|
+
);
|
|
4313
|
+
dragRef.current = {
|
|
4314
|
+
type: "x-pan",
|
|
4315
|
+
chartId: layout.chart.id,
|
|
4316
|
+
startX: point.x,
|
|
4317
|
+
startY: point.y,
|
|
4318
|
+
startMin: state.xMin,
|
|
4319
|
+
startMax: state.xMax,
|
|
4320
|
+
startYOffset: yCenterOffsetRef.current.get(layout.chart.id) ?? 0,
|
|
4321
|
+
canPanY: yManualScaleRef.current.has(layout.chart.id),
|
|
4322
|
+
yValueSpan: scaledYRange.maxY - scaledYRange.minY,
|
|
4323
|
+
width: layout.plot.width,
|
|
4324
|
+
height: layout.plot.height
|
|
4325
|
+
};
|
|
4326
|
+
event.currentTarget.setPointerCapture?.(event.pointerId);
|
|
4327
|
+
},
|
|
4328
|
+
[
|
|
4329
|
+
findLayoutAt,
|
|
4330
|
+
findXAxisLayoutAt,
|
|
4331
|
+
findYAxisLayoutAt,
|
|
4332
|
+
getLocalPoint,
|
|
4333
|
+
initialVisiblePoints,
|
|
4334
|
+
fullscreenChartId,
|
|
4335
|
+
rectangleZoomChartId,
|
|
4336
|
+
activeDrawingTool,
|
|
4337
|
+
commitDrawing,
|
|
4338
|
+
drawings,
|
|
4339
|
+
onSelectedDrawingIdChange
|
|
4340
|
+
]
|
|
4341
|
+
);
|
|
4342
|
+
const handlePointerMove = (0, import_react9.useCallback)(
|
|
4343
|
+
(event) => {
|
|
4344
|
+
if (fullscreenChartId) return;
|
|
4345
|
+
updateCrosshair(event);
|
|
4346
|
+
const drawingPoint = getLocalPoint(event);
|
|
4347
|
+
if (drawingPoint) {
|
|
4348
|
+
if (drawingEditRef.current) {
|
|
4349
|
+
const editLayout = getChartLayout().find(
|
|
4350
|
+
(layout) => getDrawingsForChart(drawings, layout.chart.id).some(
|
|
4351
|
+
(drawing) => drawing.id === drawingEditRef.current.id
|
|
4352
|
+
)
|
|
4353
|
+
);
|
|
4354
|
+
if (editLayout) {
|
|
4355
|
+
const dataPoint = screenPointToDataPoint({
|
|
4356
|
+
point: clampPointToPlot(drawingPoint, editLayout.plot),
|
|
4357
|
+
chart: editLayout.chart,
|
|
4358
|
+
plot: editLayout.plot,
|
|
4359
|
+
initialVisiblePoints,
|
|
4360
|
+
viewStateRef,
|
|
4361
|
+
yScaleRef,
|
|
4362
|
+
yCenterOffsetRef
|
|
4363
|
+
});
|
|
4364
|
+
const edit = drawingEditRef.current;
|
|
4365
|
+
const nextDrawings = updateDrawingById(drawings, edit.id, (drawing) => {
|
|
4366
|
+
if (drawing.type === "hline") {
|
|
4367
|
+
const deltaX = (drawing.end?.x ?? drawing.start.x) - drawing.start.x;
|
|
4368
|
+
return {
|
|
4369
|
+
...drawing,
|
|
4370
|
+
start: { ...drawing.start, x: dataPoint.x, y: dataPoint.y },
|
|
4371
|
+
end: {
|
|
4372
|
+
...drawing.end,
|
|
4373
|
+
x: dataPoint.x + deltaX,
|
|
4374
|
+
y: dataPoint.y
|
|
4375
|
+
}
|
|
4376
|
+
};
|
|
4377
|
+
}
|
|
4378
|
+
if (drawing.type === "vline") {
|
|
4379
|
+
return { ...drawing, start: { ...drawing.start, x: dataPoint.x }, end: { ...drawing.end, x: dataPoint.x } };
|
|
4380
|
+
}
|
|
4381
|
+
if (drawing.type === "pin") {
|
|
4382
|
+
return { ...drawing, start: dataPoint, end: dataPoint };
|
|
4383
|
+
}
|
|
4384
|
+
if (edit.endpoint === "start" || edit.endpoint === "end") {
|
|
4385
|
+
return { ...drawing, [edit.endpoint]: dataPoint };
|
|
4386
|
+
}
|
|
4387
|
+
return drawing;
|
|
4388
|
+
});
|
|
4389
|
+
onDrawingsChange?.(nextDrawings);
|
|
4390
|
+
}
|
|
4391
|
+
return;
|
|
4392
|
+
}
|
|
4393
|
+
if (activeDrawingTool && DRAWING_TOOLS.has(activeDrawingTool)) {
|
|
4394
|
+
const drawingLayout = findLayoutAt(drawingPoint.x, drawingPoint.y);
|
|
4395
|
+
if (!drawingLayout) return;
|
|
4396
|
+
const dataPoint = screenPointToDataPoint({
|
|
4397
|
+
point: drawingPoint,
|
|
4398
|
+
chart: drawingLayout.chart,
|
|
4399
|
+
plot: drawingLayout.plot,
|
|
4400
|
+
initialVisiblePoints,
|
|
4401
|
+
viewStateRef,
|
|
4402
|
+
yScaleRef,
|
|
4403
|
+
yCenterOffsetRef
|
|
4404
|
+
});
|
|
4405
|
+
const session = drawingSessionRef.current;
|
|
4406
|
+
const startPoint = activeDrawingTool === "trendline" && session.chartId === drawingLayout.chart.id ? session.startPoint : dataPoint;
|
|
4407
|
+
if (startPoint || activeDrawingTool !== "trendline") {
|
|
4408
|
+
updateDraftDrawing({
|
|
4409
|
+
chartId: drawingLayout.chart.id,
|
|
4410
|
+
type: activeDrawingTool,
|
|
4411
|
+
start: startPoint || dataPoint,
|
|
4412
|
+
end: dataPoint
|
|
4413
|
+
});
|
|
4414
|
+
}
|
|
4415
|
+
return;
|
|
4416
|
+
}
|
|
4417
|
+
}
|
|
4418
|
+
if (rectangleZoomDragRef.current) {
|
|
4419
|
+
const point2 = getLocalPoint(event);
|
|
4420
|
+
if (!point2) return;
|
|
4421
|
+
const layout = getChartLayout().find(
|
|
4422
|
+
(candidate) => candidate.chart.id === rectangleZoomDragRef.current.chartId
|
|
4423
|
+
);
|
|
4424
|
+
if (!layout) return;
|
|
4425
|
+
const end = clampPointToPlot(point2, layout.plot);
|
|
4426
|
+
rectangleZoomDragRef.current = {
|
|
4427
|
+
...rectangleZoomDragRef.current,
|
|
4428
|
+
end
|
|
4429
|
+
};
|
|
4430
|
+
setRectangleZoomRect({
|
|
4431
|
+
start: rectangleZoomDragRef.current.start,
|
|
4432
|
+
end
|
|
4433
|
+
});
|
|
4434
|
+
return;
|
|
4435
|
+
}
|
|
4436
|
+
const drag = dragRef.current;
|
|
4437
|
+
if (!drag) return;
|
|
4438
|
+
const point = getLocalPoint(event);
|
|
4439
|
+
if (!point) return;
|
|
4440
|
+
if (drag.type === "y-scale") {
|
|
4441
|
+
const nextScale = Math.min(
|
|
4442
|
+
Y_SCALE_MAX,
|
|
4443
|
+
Math.max(
|
|
4444
|
+
Y_SCALE_MIN,
|
|
4445
|
+
drag.startScale * Math.exp((point.y - drag.startY) * 0.01)
|
|
4446
|
+
)
|
|
4447
|
+
);
|
|
4448
|
+
yScaleRef.current.set(drag.chartId, nextScale);
|
|
4449
|
+
yManualScaleRef.current.add(drag.chartId);
|
|
4450
|
+
requestRender();
|
|
4451
|
+
return;
|
|
4452
|
+
}
|
|
4453
|
+
if (drag.type === "x-scale") {
|
|
4454
|
+
const startSpan = drag.startMax - drag.startMin;
|
|
4455
|
+
const nextSpan = Math.min(
|
|
4456
|
+
X_SCALE_MAX_SPAN,
|
|
4457
|
+
Math.max(
|
|
4458
|
+
X_SCALE_MIN_SPAN,
|
|
4459
|
+
startSpan * Math.exp((drag.startX - point.x) * 0.01)
|
|
4460
|
+
)
|
|
4461
|
+
);
|
|
4462
|
+
viewStateRef.current.set(drag.chartId, {
|
|
4463
|
+
xMin: drag.startMax - nextSpan,
|
|
4464
|
+
xMax: drag.startMax
|
|
4465
|
+
});
|
|
4466
|
+
requestRender();
|
|
4467
|
+
return;
|
|
4468
|
+
}
|
|
4469
|
+
const range = drag.startMax - drag.startMin;
|
|
4470
|
+
const delta = (point.x - drag.startX) / drag.width * range;
|
|
4471
|
+
viewStateRef.current.set(drag.chartId, {
|
|
4472
|
+
xMin: drag.startMin - delta,
|
|
4473
|
+
xMax: drag.startMax - delta
|
|
4474
|
+
});
|
|
4475
|
+
if (drag.canPanY) {
|
|
4476
|
+
const yDelta = (point.y - drag.startY) / drag.height * drag.yValueSpan;
|
|
4477
|
+
yCenterOffsetRef.current.set(drag.chartId, drag.startYOffset + yDelta);
|
|
4478
|
+
}
|
|
4479
|
+
requestRender();
|
|
4480
|
+
},
|
|
4481
|
+
[
|
|
4482
|
+
fullscreenChartId,
|
|
4483
|
+
activeDrawingTool,
|
|
4484
|
+
drawings,
|
|
4485
|
+
findLayoutAt,
|
|
4486
|
+
getChartLayout,
|
|
4487
|
+
getLocalPoint,
|
|
4488
|
+
initialVisiblePoints,
|
|
4489
|
+
onDrawingsChange,
|
|
4490
|
+
requestRender,
|
|
4491
|
+
updateCrosshair
|
|
4492
|
+
]
|
|
4493
|
+
);
|
|
4494
|
+
const handlePointerUp = (0, import_react9.useCallback)(
|
|
4495
|
+
(event) => {
|
|
4496
|
+
if (drawingEditRef.current) {
|
|
4497
|
+
finishEditDrawing();
|
|
4498
|
+
event.currentTarget.releasePointerCapture?.(event.pointerId);
|
|
4499
|
+
return;
|
|
4500
|
+
}
|
|
4501
|
+
if (rectangleZoomDragRef.current) {
|
|
4502
|
+
const { chartId, start, end } = rectangleZoomDragRef.current;
|
|
4503
|
+
const layout = getChartLayout().find(
|
|
4504
|
+
(candidate) => candidate.chart.id === chartId
|
|
4505
|
+
);
|
|
4506
|
+
rectangleZoomDragRef.current = null;
|
|
4507
|
+
setRectangleZoomRect(null);
|
|
4508
|
+
event.currentTarget.releasePointerCapture?.(event.pointerId);
|
|
4509
|
+
if (layout) {
|
|
4510
|
+
const applied = applyRectangleZoom({
|
|
4511
|
+
chart: layout.chart,
|
|
4512
|
+
plot: layout.plot,
|
|
4513
|
+
start,
|
|
4514
|
+
end,
|
|
4515
|
+
initialVisiblePoints,
|
|
4516
|
+
viewStateRef,
|
|
4517
|
+
yScaleRef,
|
|
4518
|
+
yCenterOffsetRef,
|
|
4519
|
+
yManualScaleRef
|
|
4520
|
+
});
|
|
4521
|
+
if (applied) {
|
|
4522
|
+
setRectangleZoomChartId(null);
|
|
4523
|
+
requestRender();
|
|
4524
|
+
}
|
|
4525
|
+
}
|
|
4526
|
+
return;
|
|
4527
|
+
}
|
|
4528
|
+
dragRef.current = null;
|
|
4529
|
+
event.currentTarget.releasePointerCapture?.(event.pointerId);
|
|
4530
|
+
},
|
|
4531
|
+
[
|
|
4532
|
+
getChartLayout,
|
|
4533
|
+
initialVisiblePoints,
|
|
4534
|
+
requestRender,
|
|
4535
|
+
viewStateRef,
|
|
4536
|
+
yCenterOffsetRef,
|
|
4537
|
+
yManualScaleRef,
|
|
4538
|
+
yScaleRef
|
|
4539
|
+
]
|
|
4540
|
+
);
|
|
4541
|
+
const handleWheel = (0, import_react9.useCallback)(
|
|
4542
|
+
(event) => {
|
|
4543
|
+
if (fullscreenChartId) return;
|
|
4544
|
+
if (event.altKey) {
|
|
4545
|
+
event.preventDefault();
|
|
4546
|
+
const container = containerRef.current;
|
|
4547
|
+
if (!container) return;
|
|
4548
|
+
const deltaScale = event.deltaMode === WheelEvent.DOM_DELTA_LINE ? 16 : event.deltaMode === WheelEvent.DOM_DELTA_PAGE ? container.clientHeight : 1;
|
|
4549
|
+
container.scrollBy({
|
|
4550
|
+
left: event.deltaX * deltaScale,
|
|
4551
|
+
top: event.deltaY * deltaScale,
|
|
4552
|
+
behavior: "auto"
|
|
4553
|
+
});
|
|
4554
|
+
return;
|
|
4555
|
+
}
|
|
4556
|
+
const point = getLocalPoint(event);
|
|
4557
|
+
if (!point) return;
|
|
4558
|
+
const layout = findLayoutAt(point.x, point.y);
|
|
4559
|
+
if (!layout) return;
|
|
4560
|
+
event.preventDefault();
|
|
4561
|
+
if (event.shiftKey) {
|
|
4562
|
+
const currentScale = yScaleRef.current.get(layout.chart.id) ?? 1;
|
|
4563
|
+
yScaleRef.current.set(
|
|
4564
|
+
layout.chart.id,
|
|
4565
|
+
Math.min(
|
|
4566
|
+
Y_SCALE_MAX,
|
|
4567
|
+
Math.max(
|
|
4568
|
+
Y_SCALE_MIN,
|
|
4569
|
+
currentScale * Math.exp(event.deltaY * 0.01)
|
|
4570
|
+
)
|
|
4571
|
+
)
|
|
4572
|
+
);
|
|
4573
|
+
yManualScaleRef.current.add(layout.chart.id);
|
|
4574
|
+
requestRender();
|
|
4575
|
+
return;
|
|
4576
|
+
}
|
|
4577
|
+
const state = viewStateRef.current.get(layout.chart.id) || getInitialView(layout.chart, initialVisiblePoints);
|
|
4578
|
+
const ratio = (point.x - layout.plot.x) / layout.plot.width;
|
|
4579
|
+
const anchor = state.xMin + ratio * (state.xMax - state.xMin);
|
|
4580
|
+
const zoom = Math.exp(event.deltaY * 15e-4);
|
|
4581
|
+
const nextMin = anchor - (anchor - state.xMin) * zoom;
|
|
4582
|
+
const nextMax = anchor + (state.xMax - anchor) * zoom;
|
|
4583
|
+
if (nextMax - nextMin < 10) return;
|
|
4584
|
+
viewStateRef.current.set(layout.chart.id, {
|
|
4585
|
+
xMin: nextMin,
|
|
4586
|
+
xMax: nextMax
|
|
4587
|
+
});
|
|
4588
|
+
requestRender();
|
|
4589
|
+
},
|
|
4590
|
+
[
|
|
4591
|
+
findLayoutAt,
|
|
4592
|
+
fullscreenChartId,
|
|
4593
|
+
getLocalPoint,
|
|
4594
|
+
initialVisiblePoints,
|
|
4595
|
+
requestRender,
|
|
4596
|
+
yScaleRef
|
|
4597
|
+
]
|
|
4598
|
+
);
|
|
4599
|
+
(0, import_react9.useEffect)(() => {
|
|
4600
|
+
const container = containerRef.current;
|
|
4601
|
+
if (!container) return void 0;
|
|
4602
|
+
container.addEventListener("wheel", handleWheel, { passive: false });
|
|
4603
|
+
return () => {
|
|
4604
|
+
container.removeEventListener("wheel", handleWheel);
|
|
4605
|
+
};
|
|
4606
|
+
}, [handleWheel]);
|
|
4607
|
+
const focusChartByKeyboard = (0, import_react9.useCallback)(
|
|
4608
|
+
(direction) => {
|
|
4609
|
+
if (fullscreenChartId || charts.length === 0) return false;
|
|
4610
|
+
if (!focusedChartId) {
|
|
4611
|
+
setFocusedChartId(charts[0].id);
|
|
4612
|
+
chartRefs.current.get(charts[0].id)?.scrollIntoView({
|
|
4613
|
+
block: "nearest",
|
|
4614
|
+
inline: "nearest"
|
|
4615
|
+
});
|
|
4616
|
+
return true;
|
|
4617
|
+
}
|
|
4618
|
+
const currentIndex = Math.max(
|
|
4619
|
+
0,
|
|
4620
|
+
charts.findIndex((chart) => chart.id === focusedChartId)
|
|
4621
|
+
);
|
|
4622
|
+
const safeColumns = Math.max(1, Math.min(charts.length, Number(columns) || 1));
|
|
4623
|
+
const rowStart = Math.floor(currentIndex / safeColumns) * safeColumns;
|
|
4624
|
+
const rowEnd = Math.min(charts.length - 1, rowStart + safeColumns - 1);
|
|
4625
|
+
let nextIndex = currentIndex;
|
|
4626
|
+
if (direction === "left") {
|
|
4627
|
+
nextIndex = Math.max(rowStart, currentIndex - 1);
|
|
4628
|
+
} else if (direction === "right") {
|
|
4629
|
+
nextIndex = Math.min(rowEnd, currentIndex + 1);
|
|
4630
|
+
} else if (direction === "up") {
|
|
4631
|
+
nextIndex = Math.max(0, currentIndex - safeColumns);
|
|
4632
|
+
} else if (direction === "down") {
|
|
4633
|
+
nextIndex = Math.min(charts.length - 1, currentIndex + safeColumns);
|
|
4634
|
+
}
|
|
4635
|
+
const nextChart = charts[nextIndex];
|
|
4636
|
+
if (!nextChart || nextChart.id === focusedChartId) return false;
|
|
4637
|
+
setFocusedChartId(nextChart.id);
|
|
4638
|
+
setCrosshair(null);
|
|
4639
|
+
setRectangleZoomChartId(null);
|
|
4640
|
+
setRectangleZoomRect(null);
|
|
4641
|
+
rectangleZoomDragRef.current = null;
|
|
4642
|
+
clearDraft();
|
|
4643
|
+
onActiveDrawingToolChange?.(null);
|
|
4644
|
+
chartRefs.current.get(nextChart.id)?.scrollIntoView({
|
|
4645
|
+
block: "nearest",
|
|
4646
|
+
inline: "nearest"
|
|
4647
|
+
});
|
|
4648
|
+
return true;
|
|
4649
|
+
},
|
|
4650
|
+
[
|
|
4651
|
+
charts,
|
|
4652
|
+
clearDraft,
|
|
4653
|
+
columns,
|
|
4654
|
+
focusedChartId,
|
|
4655
|
+
fullscreenChartId,
|
|
4656
|
+
onActiveDrawingToolChange
|
|
4657
|
+
]
|
|
4658
|
+
);
|
|
4659
|
+
(0, import_react9.useEffect)(() => {
|
|
4660
|
+
const handleKeyDown = (event) => {
|
|
4661
|
+
const target = event.target;
|
|
4662
|
+
const editable = target instanceof HTMLElement && (target.isContentEditable || ["INPUT", "TEXTAREA", "SELECT"].includes(target.tagName));
|
|
4663
|
+
if (editable) {
|
|
4664
|
+
return;
|
|
4665
|
+
}
|
|
4666
|
+
const arrowDirectionByKey = {
|
|
4667
|
+
ArrowLeft: "left",
|
|
4668
|
+
ArrowRight: "right",
|
|
4669
|
+
ArrowUp: "up",
|
|
4670
|
+
ArrowDown: "down"
|
|
4671
|
+
};
|
|
4672
|
+
const arrowDirection = arrowDirectionByKey[event.key];
|
|
4673
|
+
if (arrowDirection) {
|
|
4674
|
+
if (focusChartByKeyboard(arrowDirection)) {
|
|
4675
|
+
event.preventDefault();
|
|
4676
|
+
}
|
|
4677
|
+
return;
|
|
4678
|
+
}
|
|
4679
|
+
if (event.key.toLowerCase() === "r") {
|
|
4680
|
+
event.preventDefault();
|
|
4681
|
+
resetChartView(focusedChartId);
|
|
4682
|
+
return;
|
|
4683
|
+
}
|
|
4684
|
+
if (event.key.toLowerCase() === "z") {
|
|
4685
|
+
event.preventDefault();
|
|
4686
|
+
toggleRectangleZoom(focusedChartId);
|
|
4687
|
+
return;
|
|
4688
|
+
}
|
|
4689
|
+
if (event.key.toLowerCase() === "m") {
|
|
4690
|
+
event.preventDefault();
|
|
4691
|
+
toggleMovingAverage(focusedChartId);
|
|
4692
|
+
return;
|
|
4693
|
+
}
|
|
4694
|
+
if (["t", "h", "v", "p"].includes(event.key.toLowerCase())) {
|
|
4695
|
+
event.preventDefault();
|
|
4696
|
+
const toolByKey = { t: "trendline", h: "hline", v: "vline", p: "pin" };
|
|
4697
|
+
toggleDrawingTool(toolByKey[event.key.toLowerCase()]);
|
|
4698
|
+
return;
|
|
4699
|
+
}
|
|
4700
|
+
if (event.key === "Delete" || event.key === "Backspace") {
|
|
4701
|
+
if (!selectedDrawingId) return;
|
|
4702
|
+
event.preventDefault();
|
|
4703
|
+
deleteSelectedDrawing();
|
|
4704
|
+
return;
|
|
4705
|
+
}
|
|
4706
|
+
if (event.key === "Escape" && (activeDrawingTool || draftDrawing || drawingEditRef.current)) {
|
|
4707
|
+
event.preventDefault();
|
|
4708
|
+
cancelDrawing();
|
|
4709
|
+
return;
|
|
4710
|
+
}
|
|
4711
|
+
if (event.key === "Escape" && rectangleZoomChartId) {
|
|
4712
|
+
event.preventDefault();
|
|
4713
|
+
setRectangleZoomChartId(null);
|
|
4714
|
+
setRectangleZoomRect(null);
|
|
4715
|
+
rectangleZoomDragRef.current = null;
|
|
4716
|
+
return;
|
|
4717
|
+
}
|
|
4718
|
+
if (event.key.toLowerCase() === "f") {
|
|
4719
|
+
if (fullscreenChartId) return;
|
|
4720
|
+
event.preventDefault();
|
|
4721
|
+
openFullscreen(focusedChartId);
|
|
4722
|
+
}
|
|
4723
|
+
};
|
|
4724
|
+
window.addEventListener("keydown", handleKeyDown);
|
|
4725
|
+
return () => window.removeEventListener("keydown", handleKeyDown);
|
|
4726
|
+
}, [
|
|
4727
|
+
focusedChartId,
|
|
4728
|
+
fullscreenChartId,
|
|
4729
|
+
activeDrawingTool,
|
|
4730
|
+
cancelDrawing,
|
|
4731
|
+
deleteSelectedDrawing,
|
|
4732
|
+
draftDrawing,
|
|
4733
|
+
focusChartByKeyboard,
|
|
4734
|
+
openFullscreen,
|
|
4735
|
+
rectangleZoomChartId,
|
|
4736
|
+
resetChartView,
|
|
4737
|
+
selectedDrawingId,
|
|
4738
|
+
toggleMovingAverage,
|
|
4739
|
+
toggleDrawingTool,
|
|
4740
|
+
toggleRectangleZoom
|
|
4741
|
+
]);
|
|
4742
|
+
const fullscreenChart = fullscreenChartId ? charts.find((chart) => chart.id === fullscreenChartId) : null;
|
|
4743
|
+
const chartLayouts = fullscreenChart ? [] : getChartLayout();
|
|
4744
|
+
const selectedDrawingLayout = getSelectedDrawingLayout(
|
|
4745
|
+
chartLayouts,
|
|
4746
|
+
drawings,
|
|
4747
|
+
selectedDrawingId
|
|
4748
|
+
);
|
|
4749
|
+
return /* @__PURE__ */ import_react9.default.createElement(
|
|
4750
|
+
"div",
|
|
4751
|
+
{
|
|
4752
|
+
ref: containerRef,
|
|
4753
|
+
className: `relative h-full overflow-y-auto ${className}`,
|
|
4754
|
+
style: {
|
|
4755
|
+
cursor: rectangleZoomChartId || activeDrawingTool ? "crosshair" : void 0
|
|
4756
|
+
},
|
|
4757
|
+
onPointerDown: handlePointerDown,
|
|
4758
|
+
onPointerMove: handlePointerMove,
|
|
4759
|
+
onPointerLeave: () => setCrosshair(null),
|
|
4760
|
+
onPointerUp: handlePointerUp,
|
|
4761
|
+
onPointerCancel: handlePointerUp,
|
|
4762
|
+
onContextMenu: handleContextMenu
|
|
4763
|
+
},
|
|
4764
|
+
/* @__PURE__ */ import_react9.default.createElement(
|
|
4765
|
+
"canvas",
|
|
4766
|
+
{
|
|
4767
|
+
ref: canvasRef,
|
|
4768
|
+
className: "pointer-events-none absolute left-0 top-0 z-10 block",
|
|
4769
|
+
style: {
|
|
4770
|
+
width: "100%"
|
|
4771
|
+
}
|
|
4772
|
+
}
|
|
4773
|
+
),
|
|
4774
|
+
/* @__PURE__ */ import_react9.default.createElement(
|
|
4775
|
+
"div",
|
|
4776
|
+
{
|
|
4777
|
+
ref: gridRef,
|
|
4778
|
+
className: "relative z-0 grid gap-1 pt-1",
|
|
4779
|
+
style: {
|
|
4780
|
+
gridTemplateColumns: `repeat(${columns}, minmax(18rem, 1fr))`
|
|
4781
|
+
}
|
|
4782
|
+
},
|
|
4783
|
+
charts.map((chart) => /* @__PURE__ */ import_react9.default.createElement(
|
|
4784
|
+
ChartCell,
|
|
4785
|
+
{
|
|
4786
|
+
key: chart.id,
|
|
4787
|
+
chart,
|
|
4788
|
+
axisOverlay: axisOverlays[chart.id],
|
|
4789
|
+
focused: focusedChartId === chart.id,
|
|
4790
|
+
backgroundColor,
|
|
4791
|
+
onFocus: setFocusedChartId,
|
|
4792
|
+
onFullscreenToggle: () => openFullscreen(chart.id),
|
|
4793
|
+
onReset: resetChartView,
|
|
4794
|
+
onJumpLatest: jumpChartToLatest,
|
|
4795
|
+
onRectangleZoomToggle: toggleRectangleZoom,
|
|
4796
|
+
rectangleZoomActive: rectangleZoomChartId === chart.id,
|
|
4797
|
+
movingAverage: movingAverageByChart?.[chart.id],
|
|
4798
|
+
onMovingAverageToggle: toggleMovingAverage,
|
|
4799
|
+
activeDrawingTool: focusedChartId === chart.id ? activeDrawingTool : null,
|
|
4800
|
+
onDrawingToolToggle: toggleDrawingTool,
|
|
4801
|
+
hasDrawings: getDrawingsForChart(drawings, chart.id).length > 0,
|
|
4802
|
+
onClearDrawingsRequest,
|
|
4803
|
+
setRef: (node) => {
|
|
4804
|
+
if (node) chartRefs.current.set(chart.id, node);
|
|
4805
|
+
else chartRefs.current.delete(chart.id);
|
|
4806
|
+
}
|
|
4807
|
+
}
|
|
4808
|
+
))
|
|
4809
|
+
),
|
|
4810
|
+
/* @__PURE__ */ import_react9.default.createElement(
|
|
4811
|
+
CrosshairOverlay,
|
|
4812
|
+
{
|
|
4813
|
+
crosshair: fullscreenChart ? null : crosshair,
|
|
4814
|
+
height: containerRef.current?.scrollHeight ?? "100%",
|
|
4815
|
+
xAxisLabel
|
|
4816
|
+
}
|
|
4817
|
+
),
|
|
4818
|
+
/* @__PURE__ */ import_react9.default.createElement(
|
|
4819
|
+
DrawingOverlay,
|
|
4820
|
+
{
|
|
4821
|
+
layouts: chartLayouts,
|
|
4822
|
+
drawings,
|
|
4823
|
+
draftDrawing: fullscreenChart ? null : draftDrawing,
|
|
4824
|
+
selectedDrawingId,
|
|
4825
|
+
projectPoint: (dataPoint, targetLayout) => projectDataPointToScreenPoint({
|
|
4826
|
+
point: dataPoint,
|
|
4827
|
+
layout: targetLayout,
|
|
4828
|
+
initialVisiblePoints,
|
|
4829
|
+
viewStateRef,
|
|
4830
|
+
yScaleRef,
|
|
4831
|
+
yCenterOffsetRef
|
|
4832
|
+
}),
|
|
4833
|
+
height: containerRef.current?.scrollHeight ?? "100%"
|
|
4834
|
+
}
|
|
4835
|
+
),
|
|
4836
|
+
/* @__PURE__ */ import_react9.default.createElement(
|
|
4837
|
+
TopMarkersOverlay,
|
|
4838
|
+
{
|
|
4839
|
+
layouts: fullscreenChart ? [] : chartLayouts,
|
|
4840
|
+
markers: topMarkers,
|
|
4841
|
+
viewStateRef,
|
|
4842
|
+
initialVisiblePoints,
|
|
4843
|
+
onMarkerClick: onTopMarkerClick,
|
|
4844
|
+
height: containerRef.current?.scrollHeight ?? "100%"
|
|
4845
|
+
}
|
|
4846
|
+
),
|
|
4847
|
+
selectedDrawingLayout ? /* @__PURE__ */ import_react9.default.createElement(
|
|
4848
|
+
DrawingOptionsToolbar,
|
|
4849
|
+
{
|
|
4850
|
+
drawing: selectedDrawingLayout.drawing,
|
|
4851
|
+
style: getDrawingOptionsToolbarStyle(selectedDrawingLayout.layout),
|
|
4852
|
+
onToggleExtend: toggleSelectedDrawingExtend,
|
|
4853
|
+
onColorChange: updateSelectedDrawingColor,
|
|
4854
|
+
onTextChange: updateSelectedDrawingText
|
|
4855
|
+
}
|
|
4856
|
+
) : null,
|
|
4857
|
+
!fullscreenChart && focusedChartId && movingAverageByChart?.[focusedChartId]?.enabled ? (() => {
|
|
4858
|
+
const layout = chartLayouts.find(
|
|
4859
|
+
(candidate) => candidate.chart.id === focusedChartId
|
|
4860
|
+
);
|
|
4861
|
+
if (!layout) return null;
|
|
4862
|
+
return /* @__PURE__ */ import_react9.default.createElement(
|
|
4863
|
+
MovingAverageOptionsToolbar,
|
|
4864
|
+
{
|
|
4865
|
+
movingAverage: movingAverageByChart[focusedChartId],
|
|
4866
|
+
style: getMovingAverageOptionsToolbarStyle(layout),
|
|
4867
|
+
onChange: (nextMovingAverage) => onMovingAverageChange?.(focusedChartId, nextMovingAverage)
|
|
4868
|
+
}
|
|
4869
|
+
);
|
|
4870
|
+
})() : null,
|
|
4871
|
+
/* @__PURE__ */ import_react9.default.createElement(RectangleZoomOverlay, { rect: fullscreenChart ? null : rectangleZoomRect }),
|
|
4872
|
+
fullscreenChart ? /* @__PURE__ */ import_react9.default.createElement(
|
|
4873
|
+
LeanChartFullscreenOverlay,
|
|
4874
|
+
{
|
|
4875
|
+
chart: fullscreenChart,
|
|
4876
|
+
dataRevision,
|
|
4877
|
+
renderRevision: revision,
|
|
4878
|
+
initialVisiblePoints,
|
|
4879
|
+
backgroundColor,
|
|
4880
|
+
antialiasLines,
|
|
4881
|
+
getAppendAnimatedPoint,
|
|
4882
|
+
viewStateRef,
|
|
4883
|
+
yScaleRef,
|
|
4884
|
+
yCenterOffsetRef,
|
|
4885
|
+
yManualScaleRef,
|
|
4886
|
+
movingAverageByChart,
|
|
4887
|
+
movingAverageCache: movingAverageCacheRef.current,
|
|
4888
|
+
onMovingAverageToggle: toggleMovingAverage,
|
|
4889
|
+
onMovingAverageChange,
|
|
4890
|
+
seriesOrderByChart,
|
|
4891
|
+
onClose: closeFullscreen,
|
|
4892
|
+
onReset: resetChartView,
|
|
4893
|
+
onJumpLatest: jumpChartToLatest,
|
|
4894
|
+
xAxisLabel,
|
|
4895
|
+
drawings,
|
|
4896
|
+
onDrawingsChange,
|
|
4897
|
+
activeDrawingTool,
|
|
4898
|
+
onActiveDrawingToolChange,
|
|
4899
|
+
selectedDrawingId,
|
|
4900
|
+
onSelectedDrawingIdChange,
|
|
4901
|
+
createDrawingId,
|
|
4902
|
+
onClearDrawingsRequest,
|
|
4903
|
+
onChartContextMenu,
|
|
4904
|
+
topMarkers,
|
|
4905
|
+
onTopMarkerClick
|
|
4906
|
+
}
|
|
4907
|
+
) : null
|
|
4908
|
+
);
|
|
4909
|
+
}
|
|
4910
|
+
//# sourceMappingURL=index.cjs.map
|