-
-
Notifications
You must be signed in to change notification settings - Fork 372
/
y-shifted-series.html
104 lines (94 loc) 路 2.4 KB
/
y-shifted-series.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Y-shifted Series</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="../dist/uPlot.min.css">
</head>
<body>
<script src="../dist/uPlot.iife.js"></script>
<script>
let xs = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30];
let vals = [0,1,2,3,4,5,6,7,8,9,10];
let data = [
xs,
xs.map((t, i) => vals[Math.floor(Math.random() * vals.length)]),
xs.map((t, i) => vals[Math.floor(Math.random() * vals.length)]),
xs.map((t, i) => vals[Math.floor(Math.random() * vals.length)]),
];
const normal = {
values: (u, splits) => splits,
fillTo: (u, seriesIdx) => 0,
value: (u, v, seriesIdx) => v,
data: (data) => data,
range: [0, 10],
};
const shifted = {
values: (u, splits) => splits.map(v => v % 10 == 0 ? "Core #" + (Math.floor(v/10) + 1) : v % 10),
fillTo: (u, seriesIdx) => 10 * (seriesIdx - 1),
value: (u, v, seriesIdx) => v - 10 * (seriesIdx - 1),
data: (data) => data.map((vals, seriesIdx) => seriesIdx < 1 ? vals : vals.map(xVal => xVal + 10 * (seriesIdx - 1))),
range: [0, 30],
};
let mode = shifted;
const fillTo = (u, seriesIdx) => mode.fillTo(u, seriesIdx);
const value = (u, v, seriesIdx) => mode.value(u, v, seriesIdx);
const values = (u, splits) => mode.values(u, splits);
const range = (u) => mode.range;
const opts = {
width: 1920,
height: 600,
title: "Y-shifted Series",
scales: {
x: {
time: false,
},
y: {
range,
},
},
axes: [
{},
{
size: 70,
values,
},
],
series: [
{},
{
stroke: "red",
label: "Core #1",
fill: "rgba(255,0,0,0.1)",
fillTo,
value,
},
{
stroke: "green",
label: "Core #2",
fill: "rgba(0,255,0,0.1)",
fillTo,
value,
},
{
paths: uPlot.paths.bars(),
stroke: "blue",
label: "Core #3",
fill: "rgba(0,0,255,0.1)",
fillTo,
value,
},
],
};
let u = new uPlot(opts, mode.data(data), document.body);
setInterval(() => {
if (mode == shifted)
mode = normal;
else
mode = shifted;
u.setData(mode.data(data));
}, 2000);
</script>
</body>
</html>