-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
360 lines (254 loc) · 9.96 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
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
<!doctype html>
<!-- paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/ -->
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8" lang="en"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<!-- Use the .htaccess and remove these lines to avoid edge case issues.
More info: h5bp.com/i/378 -->
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title></title>
<meta name="description" content="">
<!-- Mobile viewport optimized: h5bp.com/viewport -->
<meta name="viewport" content="width=device-width">
<!-- Place favicon.ico and apple-touch-icon.png in the root directory: mathiasbynens.be/notes/touch-icons -->
<link rel="stylesheet" href="css/style.css">
<!-- More ideas for your <head> here: h5bp.com/d/head-Tips -->
<!-- All JavaScript at the bottom, except this Modernizr build.
Modernizr enables HTML5 elements & feature detects for optimal performance.
Create your own custom Modernizr build: www.modernizr.com/download/ -->
<script src="js/vendor/modernizr-2.5.3.min.js"></script>
<style>
svg {
}
path{
fill: none;
}
.actual{
stroke: #2C99F2;
stroke-width: 1;
}
.target {
stroke: red;
stroke-width: 1;
}
.prior_year {
stroke: #CCCCCC;
stroke-width: 1;
}
g .actual {
fill: #2C99F2;
stroke: white;
}
g .target {
fill: red;
stroke: white;
}
g .prior_year {
fill: #CCCCCC;
stroke: white;
}
.axis {
fill: none;
stroke: #CCCCCC;
stroke-width: 1;
shape-rendering: crispEdges;
}
.axis text {
font-family: sans-serif;
font-size: 11px;
color: #2C99F2;
fill: #2C99F2;
stroke: #2C99F2;
shape-rendering: crispEdges;
}
</style>
</head>
<body>
<!-- Prompt IE 6 users to install Chrome Frame. Remove this if you support IE 6.
chromium.org/developers/how-tos/chrome-frame-getting-started -->
<!--[if lt IE 7]><p class=chromeframe>Your browser is <em>ancient!</em> <a href="http://browsehappy.com/">Upgrade to a different browser</a> or <a href="http://www.google.com/chromeframe/?redirect=true">install Google Chrome Frame</a> to experience this site.</p><![endif]-->
<!-- Add your site or application content here -->
<div id="chart1"></div>
<div id="chart2" style="padding-left: 50px"></div>
<!-- JavaScript at the bottom for fast page loading: http://developer.yahoo.com/performance/rules.html#js_bottom -->
<!-- Grab Google CDN's jQuery, with a protocol relative URL; fall back to local if offline -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/vendor/jquery-1.7.2.min.js"><\/script>')</script>
<!-- scripts concatenated and minified via build script -->
<script src="js/plugins.js"></script>
<script src="js/main.js"></script>
<!-- D3 -->
<script src="http://d3js.org/d3.v2.js"></script>
<script>
var h = 300;
var w = 600;
var xpadding = 100;
var ypadding = 25;
var data;
var lineChart = d3.select("#chart1").append("svg")
.attr("id", "line-chart")
.attr("height", h)
.attr("width", w);
var quarter = function(date, i){
if(i > 0){
var date2 = new Date();
date2.setMonth(date.getMonth() - 1);
q = Math.ceil(( date2.getMonth()) / 3 );
return "Q" + q;
}
}
var getMinDate = function(pdata){
return d3.min(pdata, function(d){return d3.min(d.intervals, function(d){ return d.dttm; }); });
}
var getMaxDate = function(pdata){
return d3.max(pdata, function(d){return d3.max(d.intervals, function(d){ return d.dttm; }); });
}
var getMaxValue = function(pdata){
return d3.max(pdata, function(d){return d3.max(d.intervals, function(d){ return d.value; }); });
}
d3.json("http://wazi.dev/d3/data.json", function(json) {
data = json;
var dataByIntervalType = d3.nest()
.key(function(d) { return d.interval_type; })
.map(data.revenues);
var format = d3.time.format("%Y-%m-%d %H:%M:%S");
var yearData = dataByIntervalType.YEAR[0];
var minDate = format.parse(getMinDate(yearData.revenue_type_intervals));
var maxDate = format.parse(getMaxDate(yearData.revenue_type_intervals));
maxDate.setMonth(maxDate.getMonth() + 1);
var maxValue = Math.ceil(getMaxValue(yearData.revenue_type_intervals) / 5000000) * 5000000;
console.log("Min Date: " + minDate);
console.log("Max Date: " + maxDate);
console.log("Max Value: " + maxValue);
var x = d3.time.scale()
.domain([minDate, maxDate]).range([xpadding, w]);
var y = d3.scale.linear()
.domain([0, maxValue])
.range([h - ypadding, ypadding]);
var xAxis = d3.svg.axis()
.scale(x)
.orient("bottom")
.ticks(d3.time.months, 3)
.tickFormat(quarter);
var yAxis = d3.svg.axis()
.scale(y)
.orient("left")
.ticks(5)
.tickFormat(d3.format("s"));
var line = d3.svg.line()
// assign the X function to plot our line as we wish
.x(function(d, i) {
// verbose logging to show what's actually being done
console.log('Plotting X value for data point: ' + d + ' using index: ' + i + ' to be at: ' + x(format.parse(d.dttm)) + ' using our xScale.');
// return the X coordinate where we want to plot this datapoint
return x(format.parse(d.dttm));
})
.y(function(d) {
// verbose logging to show what's actually being done
console.log('Plotting Y value for data point: ' + d + ' to be at: ' + y(d.value) + " using our yScale.");
// return the Y coordinate where we want to plot this datapoint
return y(d.value);
})
.interpolate("basis");
lineChart.selectAll("svg")
.data(yearData.revenue_type_intervals)
.enter()
.append("svg:path")
.attr("class", function(d){return d.revenue_type; } )
.attr("d", function(d){ return line(d.intervals);} );
lineChart.append("g")
.attr("class", "axis")
.attr("transform", "translate(0," + (h - ypadding) + ")")
.call(xAxis);
lineChart.append("g")
.attr("class", "axis")
.attr("transform", "translate(" + xpadding + ",0)")
.call(yAxis);
});
d3.json("http://wazi.dev/d3/data.json", function(json) {
data = json;
var dataByIntervalType = d3.nest()
.key(function(d) { return d.interval_type; })
.map(data.revenues);
var quarterData = dataByIntervalType.QUARTER
// First, we define sizes and colours...
var outerW = 600; // outer width
var outerH = 300; // outer height
var padding = { t: 0, r: 0, b: 30, l: 0 };
var w = outerW - padding.l - padding.r; // inner width
var h = outerH - padding.t - padding.b; // inner
var labels = ["myCW", "CWO", "WF", "OFFLINE"];
// Third, we define our scales...
// Groups scale, x axis
var x0 = d3.scale.ordinal()
.domain(d3.range(4))
.rangeBands([0, w], 0.2);
// Series scale, x axis
// It might help to think of the series scale as a child of the groups scale
var x1 = d3.scale.ordinal()
.domain(d3.range(3))
.rangeBands([0, x0.rangeBand()]);
// Values scale, y axis
var y0 = d3.scale.linear()
.domain([0, 3000000])
.range([0,h]);
var barGraph = d3.select("#chart2").append("svg")
.attr("id", "barGraph")
.attr("height", outerH)
.attr("width", outerW)
.append("svg:g")
.attr("transform", "translate(30,-10)");
var g = barGraph.selectAll("g.series")
.data(quarterData)
.enter()
.append("svg:g")
.attr("class", function(d){return d.revenue_category; })
.attr("transform", function(d, i) { return "translate(" + x0(i) + ",0)"; });
var rect = g.selectAll("rect")
.data(function(d){
return d.revenue_summaries;
})
.enter()
.append("svg:rect")
.attr("x", 0)
.attr("y", function(d){ return h - y0(d.value); })
.attr("width", x1.rangeBand())
.attr("height", function(d) { return y0(d.value); })
.attr("class", function(d){ return d.revenue_type; })
.attr("transform", function(d, i) { return "translate(" + x1(i) + ",0)"; });
var yAxisScale = d3.scale.linear()
.domain([0, 3000000])
.range([h,0]);
var yAxis2 = d3.svg.axis()
.scale(yAxisScale)
.orient("left")
.ticks(5)
.tickFormat(d3.format("s"));
barGraph.append("g")
.attr("class", "axis")
.call(yAxis2);
var xAxis2 = d3.svg.axis()
.scale(x0)
.ticks(4)
.tickValues(labels)
.orient("bottom");
barGraph.append("g")
.attr("class", "axis")
.call(xAxis2)
.attr("transform", function(d, i) { return "translate(0," + h + ")"; });
});
</script>
<!-- end scripts -->
<!-- Asynchronous Google Analytics snippet. Change UA-XXXXX-X to be your site's ID.
mathiasbynens.be/notes/async-analytics-snippet -->
<script>
var _gaq=[['_setAccount','UA-XXXXX-X'],['_trackPageview']];
(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];
g.src=('https:'==location.protocol?'//ssl':'//www')+'.google-analytics.com/ga.js';
s.parentNode.insertBefore(g,s)}(document,'script'));
</script>
</body>
</html>