-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathcompose.html
81 lines (73 loc) · 1.98 KB
/
compose.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
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>d3.compose - compose</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="../build/d3.compose.css">
<style>
#charts {width: 600px;}
path {stroke: black;}
</style>
</head>
<body>
<div id="charts"></div>
<script src="../node_modules/d3/d3.js"></script>
<script src="../build/d3.compose.js"></script>
<script type="text/javascript">
var charts = d3.select('#charts');
var id = 1;
function getSelection() {
return charts.append('div')
.attr('id', 'chart-' + (id++))
.attr('class', 'chart');
}
// A
var Custom = d3c.Overlay.extend({
render: function() {
this.base.text('Howdy!');
}
});
var xScale = d3.scale.linear();
var yScale = d3.scale.linear();
var containerA = new d3c.Compose(getSelection(), {
responsive: true,
width: 1200
});
containerA.draw(
d3c.layered(
[
d3c.title({text: 'Title', margin: {top: 30, bottom: 30}}),
[
d3c.axisTitle({text: 'y-axis', rotation: -90}),
d3c.axis({position: 'left', scale: yScale}),
d3c.layered([d3c.lines({data: [
{x: 0, y: 0},
{x: 0.5, y: 0.5},
{x: 1, y: 1}
], xScale: xScale, yScale: yScale})])
],
d3c.axis({position: 'bottom', scale: xScale}),
d3c.axisTitle({text: 'x-axis'})
],
{type: Custom, props: {left: 100, top: 100}}
)
);
// B
var containerB = new d3c.Compose(getSelection())
var count = 0;
var intId = setInterval(drawB, 1000);
drawB();
function drawB() {
if (count++ >= 5) {
clearInterval(intId);
return;
}
containerB.draw(d3c.layered(
d3c.title({text: 'Title ' + count})
))
}
</script>
</body>
</html>