1
-
Removed:
import { fetchCorrelation } from "./api.js";
2
-
Removed:
import { PRIMARY_CHART_COLOR } from "./constants.js";
3
-
Removed:
4
-
Removed:
let chart = null;
5
-
Removed:
let activeRequest = null;
6
-
Removed:
7
-
Removed:
function createScatterChart(canvas, points, labelX, labelY, unitX, unitY) {
8
-
Removed:
return new Chart(canvas, {
9
-
Removed:
type: "scatter",
10
-
Removed:
data: {
11
-
Removed:
datasets: [{
12
-
Removed:
label: `${labelX} vs ${labelY}`,
13
-
Removed:
data: points,
14
-
Removed:
backgroundColor: PRIMARY_CHART_COLOR,
15
-
Removed:
borderColor: PRIMARY_CHART_COLOR,
16
-
Removed:
pointRadius: 3,
17
-
Removed:
pointHoverRadius: 5
18
-
Removed:
}]
19
-
Removed:
},
20
-
Removed:
options: {
21
-
Removed:
responsive: true,
22
-
Removed:
maintainAspectRatio: false,
23
-
Removed:
animation: false,
24
-
Removed:
scales: {
25
-
Removed:
x: {
26
-
Removed:
title: { display: true, text: `${labelX} (${unitX})` }
27
-
Removed:
},
28
-
Removed:
y: {
29
-
Removed:
title: { display: true, text: `${labelY} (${unitY})` }
30
-
Removed:
}
31
-
Removed:
},
32
-
Removed:
plugins: {
33
-
Removed:
tooltip: {
34
-
Removed:
callbacks: {
35
-
Removed:
label: context => {
36
-
Removed:
const point = context.raw;
37
-
Removed:
return `${labelX}: ${point.x.toFixed(2)} ${unitX} ${labelY}: ${point.y.toFixed(2)} ${unitY}`;
38
-
Removed:
}
39
-
Removed:
}
40
-
Removed:
}
41
-
Removed:
}
42
-
Removed:
}
43
-
Removed:
});
44
-
Removed:
}
45
-
Removed:
46
-
Removed:
export function createCorrelationChart(timeframe, probeX, probeY, config) {
47
-
Removed:
const canvas = document.getElementById("chart-correlation");
48
-
Removed:
if (!canvas) return { reload: () => {} };
49
-
Removed:
50
-
Removed:
async function load() {
51
-
Removed:
if (activeRequest) activeRequest.abort();
52
-
Removed:
53
-
Removed:
const controller = new AbortController();
54
-
Removed:
activeRequest = controller;
55
-
Removed:
56
-
Removed:
try {
57
-
Removed:
const points = await fetchCorrelation(
58
-
Removed:
probeX, probeY, timeframe.selected(), timeframe.range(), controller.signal
59
-
Removed:
);
60
-
Removed:
61
-
Removed:
if (!chart) {
62
-
Removed:
chart = createScatterChart(canvas, points, config.labelX, config.labelY, config.unitX, config.unitY);
63
-
Removed:
} else {
64
-
Removed:
chart.data.datasets[0].data = points;
65
-
Removed:
chart.update();
66
-
Removed:
}
67
-
Removed:
} catch (error) {
68
-
Removed:
if (error.name === "AbortError") return;
69
-
Removed:
} finally {
70
-
Removed:
if (activeRequest === controller) activeRequest = null;
71
-
Removed:
}
72
-
Removed:
}
73
-
Removed:
74
-
Removed:
load();
75
-
Removed:
76
-
Removed:
return { reload: load };
77
-
Removed:
}