-
Notifications
You must be signed in to change notification settings - Fork 4
/
NeffFuelCompare.html
383 lines (324 loc) · 12.7 KB
/
NeffFuelCompare.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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta charset="UTF-8">
<meta name="Author" content="Jason Neff" />
<meta name="Owner" content="Pearson" />
<meta name="Copyright" content="Copyright (c) 2013 Pearson. All rights reserved." />
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
<meta content="Our Changing Planet" name="description" />
<title class="setTitle">Ch. 18 Energy Usage Comparisons</title>
<!-- bootstrap_plus.css contains styling for the dropdown menu and other common core styles -->
<link href="css/bootstrap_plus.css" rel="stylesheet" media="screen">
<!-- widgets.css contains styling for the interactive brix -->
<link href="css/widgets.css" rel="stylesheet">
<!-- eCourse-master.css contains styling for all the navigation -->
<link href="css/eCourse-master.css" rel="stylesheet" media="screen">
<!-- content_styles.css contains styling for the narrative layout and responsive design -->
<link href="css/content_styles.css" rel="stylesheet" media="screen">
</head>
<body>
<div class="container">
<div class="span12 lc_ec_page">
<section class="lc_ec_minorMajor lc_ec_pageInner">
<div class="lc_ec_content">
<h2 class="lc_ec_bHead"><span class='number setId'></span>
<span class="setTitle">Ch. 18 Fuel Type Comparisons</span>
</h2>
<div class="lc_ec_leading">
<p>Select one or more countries to compare their energy usage. Highlight one country in the legend to see the data for just that country.</p>
<span id = "checkBoxes0">Countries: </span>
<div id="earth"></div>
</div>
<div class="lc_ec_trailing">
<div id="graph1"></div>
</div>
</div>
</section>
</div>
</div>
<script src="js/jquery-latest.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/jquery-ui-1.10.2.custom.js"></script>
<script src="js/toc-structure.js"></script>
<script src="js/eCourse-master.js"></script>
<script src="js/d3.v3.min.js"></script>
<!--
<script src="js/brixlib-compiled.js"></script>
-->
<script src="../closure/closure-library/closure/goog/base.js"></script>
<script src="../closure/closure-library/closure/goog/deps.js"></script>
<script src="js/ipsproxy.js"></script>
<script src="js/eventmanager.js"></script>
<script src="js/fakeactivitydb.js"></script>
<script src="js/answerman.js"></script>
<script src="js/localanswerman.js"></script>
<script src="js/submitmanager.js"></script>
<script src="js/mortar-base.js"></script>
<script src="js/widget-base.js"></script>
<script src="js/bricworks.js"></script>
<script src="js/widget-numeric.js"></script>
<script src="js/widget-legend.js"></script>
<script src="js/widget-callouts.js"></script>
<script src="js/widget-button.js"></script>
<script src="js/widget-sketch.js"></script>
<script src="js/widget-prototype-axes.js"></script>
<script src="js/widget-linegraph.js"></script>
<script src="js/widget-barchart.js"></script>
<script src="js/widget-piechart.js"></script>
<script src="js/widget-image.js"></script>
<script src="js/widget-carousel.js"></script>
<script src="js/widget-imageviewer.js"></script>
<script src="js/brix-labelselector.js"></script>
<script src="js/brix-labelcarousel.js"></script>
<script src="js/widget-labelgroup.js"></script>
<script src="js/widget-markergroup.js"></script>
<script src="js/widget-radiogroup.js"></script>
<script src="js/widget-checkgroup.js"></script>
<script src="js/widget-selectgroup.js"></script>
<script src="js/widget-multiplechoicequestion.js"></script>
<script src="js/widget-multiselectquestion.js"></script>
<script src="js/widget-numericquestion.js"></script>
<script src="js/widget-slider.js"></script>
<script src="js/mortar-dataswap.js"></script>
<script src="js/mortar-hilite.js"></script>
<script src="js/mortar-agestructure.js"></script>
<script src="js/briclayer.js"></script>
<script>
// local aliases for convenience
var EventManager = pearson.utils.EventManager;
var Rect = pearson.utils.Rect;
var Size = pearson.utils.Size;
var SubmitManager = pearson.brix.utils.SubmitManager;
var SVGContainer = pearson.brix.SVGContainer;
var Image = pearson.brix.Image;
var CaptionedImage = pearson.brix.CaptionedImage;
var Carousel = pearson.brix.Carousel;
var ImageViewer = pearson.brix.ImageViewer;
var Callouts = pearson.brix.Callouts;
var RadioGroup = pearson.brix.RadioGroup;
var CheckGroup = pearson.brix.CheckGroup;
var SelectGroup = pearson.brix.SelectGroup;
var LabelGroup = pearson.brix.LabelGroup;
var MarkerGroup = pearson.brix.MarkerGroup;
var BarChart = pearson.brix.BarChart;
var LineGraph = pearson.brix.LineGraph;
var PieChart = pearson.brix.PieChart;
var Legend = pearson.brix.Legend;
var Sketch = pearson.brix.Sketch;
var Readout = pearson.brix.Readout;
var NumericInput = pearson.brix.NumericInput;
var Slider = pearson.brix.Slider;
var MultipleChoiceQuestion = pearson.brix.MultipleChoiceQuestion;
var NumericQuestion = pearson.brix.NumericQuestion;
//the eventManager and submitManager are created for every page for Brix on that page
var eventManager = new EventManager();
var submitManager = new SubmitManager(eventManager);
//country selector
var countries = new CheckGroup ({
choices: [
{
content: "US", answerKey: '0'
},
{
content: "Germany", answerKey: '1'
},
{
content: "China", answerKey: '2'
},
{
content: "Japan",answerKey: '3'
},
{
content: "Malaysia", answerKey: '4'
},
{
content: "India",answerKey: '5'
},
],
type: 'ordered',
}, eventManager);
countries.draw(d3.select('#checkBoxes0'));
//data for each country and energy type
//
//
var fuelSources = {
"source": ['Oil', 'Natural Gas', 'Coal', 'Nuclear Energy', 'Hydroelectric', 'Renewables'],
"US": [819.87189587887, 654.030201580966, 437.755692740848, 183.242604735581, 63.2050497736556, 50.7217530882212],
"Germany": [111.526, 67.7128116938951, 79.2012993216776, 22.5143684663075, 4.79703127121327, 25.9934380232609],
"China": [483.662640213053, 129.459654, 1873.31312, 22.0369280897858, 194.788885369053, 31.9011750476266],
"Japan": [218.194590348259, 105.063134135855, 124.377646411, 4.07091460379235, 18.3133457030365, 8.16332232429738],
"Malaysia": [29.8206660057211, 29.9974998107764, 14.3363, 0, 1.842729, 0.31759756923807],
"India": [171.596151999999, 49.102434, 298.253834859999, 7.49868986740278, 26.1698239580032, 10.8693908760238],
"labels": {xLabel: 'Million tonnes oil equivalent', yLabel: 'Fuel Sources'}
};
/************************************************************************
* makeGraphPoints *//**
*
* makeGraphPoint takes vectors of x and y data and constructs the array of
* of x: and y: keyed objects that is expected by Brix graphing routines.
*
* @param {Array} x,y These are the arrays of x and y data.
*************************************************************************/
function makeGraphPoints(x,y)
{
//Handler needs to get written into each page,
//each widget will have it's own way of responding
var dataArray = [];
x.forEach( function(o, i) {
dataArray.push({x: o, y: y[i]});
});
return dataArray;
}
/************************************************************************
* makeGraphData *//**
*
* makeGraphPoint takes vectors of x and y data and constructs the array of
* of x: and y: keyed objects that is expected by Brix graphing routines.
*
* @param {Array} dataSet These are the arrays of objects containing multiple
* data series.
* @param {Array} groupKey The series to omit because it's the common axis
*************************************************************************/
function makeGraphData(dataSet, groupKey)
{
//Handler needs to get written into each page,
//each widget will have it's own way of responding
var seriesArray = [];
var keyArray = d3.keys(dataSet).filter(function (o) {return (o != groupKey && o != "labels");});
keyArray.forEach( function(o, i) {
seriesArray.push(makeGraphPoints(dataSet[groupKey], dataSet[o]));
});
return seriesArray;
}
/************************************************************************
* makeChartData *//**
*
* makeGraphPoint takes vectors of x and y data and constructs the array of
* of x: and y: keyed objects that is expected by Brix graphing routines.
*
* @param {Array} dataSet These are the arrays of objects containing multiple
* data series.
* @param {Array} groupKey The series to omit because it's the common axis
*************************************************************************/
function makeChartData(dataSet, groupKey)
{
//Handler needs to get written into each page,
//each widget will have it's own way of responding
var seriesArray = [];
var legendArray = [];
var keyArray = d3.keys(dataSet).filter(function (o) {return (o != groupKey && o != "labels");});
keyArray.forEach( function(o, i) {
seriesArray.push(makeGraphPoints(dataSet[o], dataSet[groupKey]));
legendArray.push({content: o})
});
var chartLegendConfig = {
xPos: "right", yPos: "top",
type: 'box',
labels: legendArray
}
return [seriesArray, chartLegendConfig];
}
var fuelData = makeChartData(fuelSources, "source");
var svg1 = new SVGContainer({
node: d3.select("#graph1"),
maxWid: 577,
maxHt: 650
});
//exploded view graph
var graph0 = new BarChart({
Data: [fuelData[0][0]],
xAxisFormat: { type: "linear",
ticks: 3,
orientation: "top",
//label: fuelSources.labels.xLabel
},
yAxisFormat: { type: "ordinal",
orientation: "left",
ticks: [],
label: d3.keys(fuelSources)[1],
}
}, eventManager);
// large grouped bar graph showing all fuel sources for all countries
var graph3 = new BarChart({
Data: fuelData[0],
type: 'grouped',
xAxisFormat: { type: "linear",
ticks: 3,
orientation: "bottom",
label: fuelSources.labels.xLabel
},
yAxisFormat: { type: "ordinal",
orientation: "left",
label: fuelSources.labels.yLabel,
}
}, eventManager);
svg1.append(graph3);
svg1.append(graph0, {topPercentOffset: .6, leftPercentOffset: .65, heightPercent: 0.3, widthPercent: 0.3});
// configure and append the legend to the bargraph
var fuelLegend = new Legend(fuelData[1], eventManager);
graph3.append(fuelLegend);
eventManager.subscribe(countries.selectedEventId,
displayData);
eventManager.subscribe(fuelLegend.selectedEventId,
liteData);
eventManager.subscribe(graph3.selectedEventId,
liteData);
countries.selectItemAtIndex(0);
/************************************************************************
* displayData *//**
*
* displays the data associated with the selected items in the Checkgroup
*
*************************************************************************/
function displayData(eventDetails)
{
//Handler needs to get written into each page,
//each widget will have it's own way of responding
var fuelDataSubset = [];
for (var i = 0; i <= fuelData[0].length; i++)
{
fuelDataSubset[i] = [];
}
countries.selectedItems().forEach( function (o,i)
{
var index = Number(o.answerKey);
fuelDataSubset[index] = fuelData[0][index];
}
);
liteData(eventDetails);
graph3.setData(fuelDataSubset);
graph3.redraw();
}
/************************************************************************
* liteData *//**
*
* Lites up the data associated with the selection in the legend, and
* draws the detailed graph of just that data
*
*************************************************************************/
function liteData(eventDetails)
{
var index = eventDetails.selectKey;
var fuelDataSmall = [];
if(index){
for (var i = 0; i <= fuelData[0].length - 1; i++)
{
// fill the data array with empty series (to spoof color)
fuelDataSmall[i] = [];
}
fuelDataSmall[index] = fuelData[0][index];
yLabelSmall = fuelData[1].labels[index].content;
//get rid of the tiny graph, update it's data, then put it back with new axes
svg1.remove(graph0);
graph0.setData(fuelDataSmall);
graph0.yAxisFormat.label = yLabelSmall;
svg1.append(graph0, {topPercentOffset: .6, leftPercentOffset: .65, heightPercent: 0.3, widthPercent: 0.3});
graph3.lite(index);
fuelLegend.lite(index);
}
}
</script>
</body>
</html>