-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
65 lines (58 loc) · 1.23 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<script type="module">
import '../dist/trend-line.esm.js';
</script>
</head>
<style>
/*
CSS custom properties penetrate the Shadow DOM.
They are useful to provide custom styling.
*/
trend-line {
--color: #333; /* default black */
--stroke-width: 2px; /* default 2px */
--background: #eee; /* default transparent */
}
</style>
<body>
<trend-line
data="[[0, 1], [1, 2], [2, 4], [3, 8]]"
x-interval="[0, 3]"
y-interval="[1, 8]"
width="100"
height="100"
margin="20"
></trend-line>
<trend-line
id="js"
width="100"
height="100"
margin="20"
></trend-line>
<button>Update</button>
</body>
<script>
const N = 10;
const element = document.querySelector("#js");
update(element);
function update(element) {
element.data = getRandomData(N);
/*
element.xInterval and element.yInterval default to
the ranges observed in data.
*/
}
const button = document.querySelector('button');
button.addEventListener('click', event => {
update(element);
});
function getRandomData (length) {
return Array.from({length}, getRandomDatum);
}
function getRandomDatum (el, index) {
return [index, Math.random()];
}
</script>
</html>