-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstoplight.html
More file actions
57 lines (48 loc) · 1.56 KB
/
stoplight.html
File metadata and controls
57 lines (48 loc) · 1.56 KB
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
<!DOCTYPE html>
<html>
<head>
<script src="https://d3js.org/d3.v4.min.js"></script>
</head>
<body>
<svg id="svg" style="width:100%; height:800px"/>
</body>
<script>
const svg = d3.select('#svg');
svg.append('rect')
.attr('x', 100)
.attr('y', 10)
.attr('width', 200)
.attr('height', 500)
.style('fill', 'black');
const red = svg.append('circle')
.attr('cx', 200)
.attr('cy', 100)
.attr('r', 75)
.style('fill', 'grey');
const yellow = svg.append('circle')
.attr('cx', 200)
.attr('cy', 260)
.attr('r', 75)
.style('fill', 'grey');
const green = svg.append('circle')
.attr('cx', 200)
.attr('cy', 420)
.attr('r', 75)
.style('fill', 'grey');
red.on('click', () => {
red.style('fill', 'red');
yellow.style('fill', 'grey');
green.style('fill', 'grey');
});
yellow.on('click', () => {
red.style('fill', 'grey');
yellow.style('fill', 'yellow');
green.style('fill', 'grey');
});
green.on('click', () => {
red.style('fill', 'grey');
yellow.style('fill', 'grey');
green.style('fill', 'green');
});
</script>
</html>