-
Notifications
You must be signed in to change notification settings - Fork 98
/
Copy pathd3.html
204 lines (166 loc) · 5.18 KB
/
d3.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
<script src="../aight.js"></script>
<script src="http://d3js.org/d3.v3.min.js"></script>
<!--[if IE 8]>
<script src="../d3/d3.ie8.js"></script>
<![endif]-->
<!--[if lt IE 8]><script>
alert("Sorry, aight doesn't work with IE7 or earlier!");
</script><![endif]-->
<style type="text/css">
body {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 12px;
line-height: 18px:
}
h2 {
margin-bottom: 0;
}
.error {
background: #fcc;
padding: 2px 4px;
}
span {
margin-right: 2px;
}
#classed-boxes span {
display: inline-block;
width: 20px;
height: 20px;
background: black;
}
#classed-boxes .red {
background: red;
}
#opacity span {
/* see: <http://www.sitepoint.com/web-foundations/internet-explorer-haslayout-property/> */
display: inline-block;
}
</style>
</head>
<body>
<h1>d3 + aight</h1>
<h2>Text replacement</h2>
<p>This is a random number: <tt id="random-number"></tt></p>
<script defer>
(function() {
d3.select("#random-number")
.text(Math.random() * 1000);
})();
</script>
<h2>Data binding, sorting</h2>
<p>There should be 4 list items here with text in them, sorted naturally ascending:</p>
<ol id="text-list"></ol>
<script defer>
(function() {
var items = d3.select("#text-list")
.selectAll("li")
.data(["foo", "bar", "baz", "qux"])
.enter().append("li")
.text(function(d) { return d; });
items.sort(d3.ascending);
})();
</script>
<p class="error"><strong>NOTE:</strong> <tt>d3.selection.sort()</tt> does
<strong>not</strong> work in IE8 at this time.</p>
<h2>Classed elements</h2>
<p>Every other one of these boxes should be red:</p>
<p id="classed-boxes">
<span></span><span></span><span></span><span></span><span></span><span></span>
</p>
<script defer>
(function() {
d3.selectAll("#classed-boxes span")
.classed("red", function(d, i) {
return (i % 2 === 0) ? true : false;
});
})();
</script>
<h2>Scales, inline styles</h2>
<p>There should be a series of colored boxes below:</p>
<p id="colored-boxes"></p>
<script defer>
(function() {
var scale = d3.scale.linear()
.domain([0, 1])
.range(["#f99", "#9cf"]),
numbers = d3.range(0, 1, .1).map(scale);
d3.select("#colored-boxes")
.selectAll("span")
.data(numbers)
.enter().append("span")
.style("display", "inline-block")
.style("width", "20px")
.style("height", "20px")
.style("background", function(d) { return d; });
})();
</script>
<h2>DOM data binding with map(), text transitions</h2>
<p>These numbers should transition from 0 over 10 seconds:</p>
<ul id="transition-text">
<li data-end="1000">0</li>
<li data-end="5000">0</li>
<li data-end="1000000">0</li>
</ul>
<script defer>
(function() {
var format = d3.format(",d"),
numbers = d3.selectAll("#transition-text li")
.datum(function() {
return {
start: +this.textContent,
end: +this.getAttribute("data-end")
};
});
numbers.transition()
.ease("linear")
.duration(2000)
.tween("text", function(d) {
var i = d3.interpolate(d.start, d.end);
return function(t) {
this.textContent = format(i(t));
};
});
})();
</script>
<h2>Backgrounds</h2>
<p>Tests for background properties in IE8 (with <tt>aight.d3.js</tt>):</p>
<div class="bg" id="bg-color">color: red</div>
<div class="bg" id="bg-position">position: bottom right</div>
<div class="bg" id="bg-image">image: a.png<br>position: bottom left</div>
<script defer>
(function() {
d3.selectAll(".bg")
.style("width", "150px")
.style("height", "150px")
.style("margin", "10px 0")
.style("background", "#f90 url(http://www.imagemagick.org/Usage/formats/circle.png) no-repeat center");
var bg = d3.select("#bg-color")
.style("background-color", "red");
bg = d3.select("#bg-position")
.style("background-position", "bottom right");
bg = d3.select("#bg-image")
.style("background-position", "bottom left")
.style("background-image", "url(http://www.imagemagick.org/Usage/formats/a.png)");
})();
</script>
<h2>Opacity</h2>
<p>Tests for the <tt>opacity</tt> style shim.</p>
<div id="opacity"></div>
<script defer>
(function() {
d3.select("#opacity")
.selectAll("span")
.data(d3.range(0, 1.1, .1))
.enter()
.append("span")
.style("opacity", function(d) { return d; })
.text(function(d) { return d * 100 + "%"; });
})();
</script>
</body>
</html>