This repository has been archived by the owner on Jun 28, 2020. It is now read-only.
forked from lbondaryk/PlayerProto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lineGraphTests.html
595 lines (528 loc) · 17.9 KB
/
lineGraphTests.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
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="Author" content="Leslie Bondaryk" />
<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="Carmen Santiago, Demo Book" name="description" />
<title class="setTitle"></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_fiftyFifty lc_ec_pageInner">
<div class="lc_ec_content">
<h2 class="lc_ec_bHead"><span class='number setId'></span>
<span class="setTitle"></span>
</h2>
<div class="lc_ec_leading">
<div id="widgetTarget0n"><p>0. Line Graph one line linear</p></div>
<div id="widgetTarget1n"><p>1. Line graph several traces linear</p>
</div>
<div id="widgetTarget2n"><p>2. Scatter graph</p></div>
<div id="widgetTarget3n"><p>3. Lines and points several traces linear</p>
</div>
<div id="ordX"><p>4. Ordinal x values are strings</p></div>
</div>
<div class="lc_ec_trailing">
<div id="widgetTarget50n"><p>5. Several traces log scale</p></div>
<div id="widgetTarget60n"><p>6. Several traces Ordinal <span style="color: red">BUG: this graph doesn't use the full available width, it should.</span></p>
</div>
<div id="widgetTarget70n"><p>7. Small multiples (several line graphs in container) <span style="color: red">BUG: the first axis shoves over too far leaving not enough remaining space to draw the graph. Need to rethink sizing when it doesn't fit.</span></p></div>
<div id="widgetTarget80n"><p>8. Lines with Legend</p></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/eventmanager.js"></script>
<script src="js/widget-base.js"></script>
<script src="js/widget-prototype-axes.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/widget-labelgroup.js"></script>
<script src="js/widget-callouts.js"></script>
<script src="js/widget-markergroup.js"></script>
<script src="js/widget-barchart.js"></script>
<script src="js/widget-linegraph.js"></script>
<script src="js/widget-legend.js"></script>
-->
<script>
// local aliases for convenience
var EventManager = pearson.utils.EventManager;
var Rect = pearson.utils.Rect;
var Size = pearson.utils.Size;
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 LabelGroup = pearson.brix.LabelGroup;
var MarkerGroup = pearson.brix.MarkerGroup;
var BarChart = pearson.brix.BarChart;
var LineGraph = pearson.brix.LineGraph;
var Legend = pearson.brix.Legend;
var eventManager = new EventManager();
var testData = [
{ x: 0, y: 0 },
{ x: 5, y: 5 },
{ x: 1000, y: 1000 }
];
var ordinalData = [
{ x: 3, y: "Energy 2" },
{ x: 6, y: "Energy 2" }
];
var ordinalData2 = [
{ x: 1, y: "Energy 1" },
{ x: 4, y: "Energy 1" },
];
var lineData1 = [
{ x: 1, y: 0.0011 },
{ x: 150, y: 0.02 },
{ x: 500, y: 0.2 },
{ x: 1300, y: 0.36 },
{ x: 1400, y: 0.34 },
{ x: 1500, y: 0.425 },
{ x: 1600, y: 0.545 },
{ x: 1700, y: 0.61 },
{ x: 1750, y: 0.7 },
{ x: 1800, y: 0.9 },
{ x: 1850, y: 1.128 },
{ x: 1900, y: 1.55 },
{ x: 1910, y: 1.75 },
{ x: 1920, y: 1.86 },
{ x: 1925, y: 2.0 },
{ x: 1940, y: 2.3 },
{ x: 1950, y: 2.529346 },
{ x: 1960, y: 3.023358 },
{ x: 1965, y: 3.33167 },
{ x: 1970, y: 3.685777 },
{ x: 1974, y: 4.00 },
{ x: 1980, y: 4.437609 },
{ x: 1985, y: 4.846247 },
{ x: 1990, y: 5.290452 },
{ x: 1996, y: 6.00 },
{ x: 2000, y: 6.115367 },
{ x: 2005, y: 6.512276 },
{ x: 2010, y: 6.908688 }
]; // array of line data
var lineData2 = [
{ x: 12, y: -3.1 },
{ x: 16.7, y: -2.02 },
{ x: 19.8, y: -1.2 },
{ x: 124.9, y: -0.36 },
{ x: 156.0, y: -0.34 },
{ x: 234, y: 0.425 },
{ x: 456.7, y: 0.545 },
{ x: 555, y: 0.61 },
{ x: 666.6, y: 0.7 },
{ x: 700, y: 0.9 },
{ x: 892.1, y: 1.128 },
{ x: 899, y: 1.55 },
{ x: 910, y: 1.75 },
{ x: 920, y: 1.86 }
]; // array of line data
var specData = [
{ x: 280.0, y: 8.2000E-02 },
{ x: 290.0, y: 5.6300E-01 },
{ x: 300.0, y: 4.5794E-01 },
{ x: 310.0, y: 5.3300E-01 },
{ x: 320.0, y: 7.7500E-01 },
{ x: 330.0, y: 1.1098E+00 },
{ x: 340.0, y: 1.0544E+00 },
{ x: 340.5, y: 1.0463E+00 },
{ x: 341.0, y: 9.7100E-01 },
{ x: 341.5, y: 9.5900E-01 },
{ x: 350.0, y: 1.0122E+00 },
{ x: 360.0, y: 1.0890E+00 },
{ x: 370.0, y: 1.2934E+00 },
{ x: 370.5, y: 1.1660E+00 },
{ x: 380.0, y: 1.1520E+00 },
{ x: 380.5, y: 1.2310E+00 },
{ x: 390.0, y: 1.2519E+00 },
{ x: 400.0, y: 1.6885E+00 },
{ x: 420.0, y: 1.5990E+00 },
{ x: 430.0, y: 1.2120E+00 },
{ x: 450.0, y: 2.0690E+00 },
{ x: 460.0, y: 1.9973E+00 },
{ x: 470.0, y: 1.9390E+00 },
{ x: 480.0, y: 2.0680E+00 },
{ x: 490.0, y: 2.0320E+00 },
{ x: 500.0, y: 1.9160E+00 },
{ x: 510.0, y: 1.9100E+00 },
{ x: 520.0, y: 1.8600E+00 },
{ x: 530.0, y: 1.8920E+00 },
{ x: 540.0, y: 1.8000E+00 },
{ x: 550.0, y: 1.8630E+00 },
{ x: 560.0, y: 1.7860E+00 },
{ x: 570.0, y: 1.8280E+00 },
{ x: 580.0, y: 1.8340E+00 },
{ x: 590.0, y: 1.7218E+00 },
{ x: 600.0, y: 1.7700E+00 },
{ x: 630.0, y: 1.6650E+00 },
{ x: 660.0, y: 1.5580E+00 },
{ x: 690.0, y: 1.4790E+00 },
{ x: 700.0, y: 1.4220E+00 },
{ x: 730.0, y: 1.3357E+00 },
{ x: 760.0, y: 1.2590E+00 },
{ x: 780.0, y: 1.1930E+00 },
{ x: 800.0, y: 1.1248E+00 },
{ x: 830.0, y: 1.0563E+00 },
{ x: 860.0, y: 1.0000E+00 },
{ x: 890.0, y: 9.4236E-01 },
{ x: 900.0, y: 9.1378E-01 },
{ x: 925.0, y: 8.7642E-01 },
{ x: 950.0, y: 8.2867E-01 },
{ x: 975.0, y: 7.7348E-01 },
{ x: 1000.0, y: 7.4255E-01 },
{ x: 1025.0, y: 6.9918E-01 },
{ x: 1050.0, y: 6.6117E-01 },
{ x: 1150.0, y: 5.4623E-01 },
{ x: 1175.0, y: 5.1852E-01 }
];
var lineData = [
{x: 1900, y: 1.55 },
{x: 1910, y: 1.75 },
{x: 1920, y: 1.86 },
{x: 1930, y: 2.07 },
{x: 1940, y: 2.3 },
{x: 1950, y: 2.529346 },
{x: 1955, y: 2.763453 },
{x: 1960, y: 3.023358 },
{x: 1965, y: 3.33167 },
{x: 1970, y: 3.685777 },
{x: 1975, y: 4.061317 },
{x: 1980, y: 4.437609 },
{x: 1985, y: 4.846247 },
{x: 1990, y: 5.290452 },
{x: 1995, y: 5.713073 },
{x: 2000, y: 6.115367 },
{x: 2005, y: 6.512276 },
{x: 2010, y: 6.908688 }
]; // array of data - could be read from file
var ordinalxData = [
{x: "1900", y: 2000.55 },
{x: "string value", y: 3056 },
{x: "10-1-1980", y: 210 },
]; // array of data - could be read from file
projected = [];
for ( i = 0; i < 10; i++) {
projected[i] = { x: 2010 + i*5,
y: 6.908688*Math.exp(0.12*(.5*i)) };
}
nineB = [
{ x: 1900, y: 9 },
{ x: 2050, y: 9 }
];
//<div id="widgetTarget0"><p>0. Line Graph one line linear</p></div>
var n = 0; // test case index we're graphing
var config = []; // array of config objects for creating containers and line graph widgets
var cntr = []; // array of containers
var lineGraph = []; // array of line graph widgets
n = config.push({cntr: null, lg: null}) - 1;
config[n].cntr = {
node: d3.select("#widgetTarget0n"),
maxWid: 400,
maxHt: 300
};
config[n].lg = {
id: "lg" + n,
Data: [lineData1],
type: "lines",
xAxisFormat: { type: "linear",
ticks: 5,
orientation: "bottom",
label: "one line with markup <span class='math'>y=x<sup>2</sup></span>" },
yAxisFormat: { type: "linear",
ticks: 5,
orientation: "right",
label: "Labels can have extended chars (μm)" },
};
cntr[n] = new SVGContainer(config[n].cntr);
lineGraph[n] = new LineGraph(config[n].lg);
cntr[n].append(lineGraph[n], {topPercentOffset: 0, leftPercentOffset: 0, heightPercent: 1, widthPercent: 1});
// <div id="widgetTarget1"><p>1. Line graph several traces linear</p></div>
n = config.push({cntr: null, lg: null}) - 1;
config[n].cntr = {
node: d3.select("#widgetTarget1n"),
maxWid: 400,
maxHt: 300
};
config[n].lg = {
id: "lg" + n,
Data: [lineData1, lineData2],
type: "lines",
xAxisFormat: { type: "linear",
ticks: 5,
orientation: "bottom",
label: "an x axis on bottom" },
yAxisFormat: { type: "linear",
ticks: 5,
orientation: "left",
label: "Population (Billions)" },
};
cntr[n] = new SVGContainer(config[n].cntr);
lineGraph[n] = new LineGraph(config[n].lg);
cntr[n].append(lineGraph[n], {topPercentOffset: 0, leftPercentOffset: 0, heightPercent: 1, widthPercent: 1});
// <div id="widgetTarget2"><p>2. Scatter graph</p></div>
n = config.push({cntr: null, lg: null}) - 1;
config[n].cntr = {
node: d3.select("#widgetTarget2n"),
maxWid: 400,
maxHt: 300
};
config[n].lg = {
id: "lg" + n,
Data: [lineData1],
type: "points",
xAxisFormat: { type: "linear",
ticks: [1200, 1500, 1900, 2050],
orientation: "bottom",
label: "Year (explicit ticks)" },
yAxisFormat: { type: "linear",
ticks: 5,
orientation: "left",
label: "Population (Billions)" },
};
cntr[n] = new SVGContainer(config[n].cntr);
lineGraph[n] = new LineGraph(config[n].lg);
cntr[n].append(lineGraph[n], {topPercentOffset: 0, leftPercentOffset: 0, heightPercent: 1, widthPercent: 1});
// <div id="widgetTarget3"><p>3. Lines and points several traces linear</p></div>
n = config.push({cntr: null, lg: null}) - 1;
config[n].cntr = {
node: d3.select("#widgetTarget3n"),
maxWid: 400,
maxHt: 200
};
config[n].lg = {
id: "lg" + n,
Data: [lineData2, specData],
type: "lines+points",
xAxisFormat: { type: "linear",
ticks: [400, 600, 800, 1000],
orientation: "top",
label: "x axis on the top" },
yAxisFormat: { type: "linear",
ticks: 5,
orientation: "right",
label: "a y axis on the right" },
};
cntr[n] = new SVGContainer(config[n].cntr);
lineGraph[n] = new LineGraph(config[n].lg);
cntr[n].append(lineGraph[n], {topPercentOffset: 0, leftPercentOffset: 0, heightPercent: 1, widthPercent: 1});
// <div id="widgetTarget50"><p>4. Several traces log scale</p></div>
n = config.push({cntr: null, lg: null}) - 1;
config[n].cntr = {
node: d3.select("#widgetTarget50n"),
maxWid: 400,
maxHt: 300
};
config[n].lg = {
id: "lg" + n,
Data: [specData],
type: "lines",
xAxisFormat: { type: "log",
ticks: 5,
orientation: "bottom",
label: "log scale" },
yAxisFormat: { type: "linear",
ticks: 5,
orientation: "left",
label: "linear scale" },
};
cntr[n] = new SVGContainer(config[n].cntr);
lineGraph[n] = new LineGraph(config[n].lg);
cntr[n].append(lineGraph[n], {topPercentOffset: 0, leftPercentOffset: 0, heightPercent: 1, widthPercent: 1});
// <div id="ordX"><p>4. Ordinal x values are strings</p></div>
var ordXSVG = new SVGContainer( {
node: d3.select("#ordX"),
maxWid: 400,
maxHt: 400
});
var ordXGraph = new LineGraph({
Data: [ordinalxData],
type: "lines+points",
xAxisFormat: { type: "ordinal",
orientation: "bottom",
label: "ordinal scale" },
yAxisFormat: { type: "linear",
orientation: "left",
ticks: 2,
label: "linear scale" },
});
ordXSVG.append(ordXGraph);
// <div id="widgetTarget60"><p>5. traces Ordinal</p></div>
n = config.push({cntr: null, lg: null}) - 1;
config[n].cntr = {
node: d3.select("#widgetTarget60n"),
maxWid: 400,
maxHt: 400
};
config[n].lg = {
id: "lg" + n,
Data: [ordinalData, ordinalData2],
type: "lines",
xAxisFormat: { type: "linear",
ticks: [0, 10],
orientation: "bottom",
label: "linear scale" },
yAxisFormat: { type: "ordinal",
orientation: "left",
label: "ordinal scale" },
};
cntr[n] = new SVGContainer(config[n].cntr);
lineGraph[n] = new LineGraph(config[n].lg);
cntr[n].append(lineGraph[n], {topPercentOffset: 0, leftPercentOffset: 0, heightPercent: 1, widthPercent: 1});
// <div id="widgetTarget70"><p>6. Small multiples (several line graphs in container)</p></div>
n = config.push({cntr: null, lg: null}) - 1;
config[n].cntr = {
node: d3.select("#widgetTarget70n"),
maxWid: 500,
maxHt:200
};
config[n].lg = {
id: "lg" + n,
Data: [testData],
type: "lines",
xAxisFormat: { type: "linear",
ticks: 3,
orientation: "bottom",
label: "x vals" },
yAxisFormat: { type: "linear",
ticks: 3,
orientation: "left",
label: "vertical" },
};
config[n].lg2 = {
id: "lg2_" + n,
Data: [lineData1],
type: "lines",
xAxisFormat: { type: "linear",
ticks: 3,
orientation: "bottom",
label: "x vals" },
yAxisFormat: { type: "linear",
ticks: 3,
orientation: "left",
label: "vertical" },
};
config[n].lg3 = {
id: "lg3_" + n,
Data: [specData],
type: "lines",
xAxisFormat: { type: "linear",
ticks: 3,
orientation: "bottom",
label: "x vals" },
yAxisFormat: { type: "linear",
ticks: 3,
orientation: "left",
label: "vertical" },
};
cntr[n] = new SVGContainer(config[n].cntr);
lineGraph[n] = new LineGraph(config[n].lg);
cntr[n].append(lineGraph[n], {topPercentOffset: 0, leftPercentOffset: 0, heightPercent: 1, widthPercent: 1/3});
lineGraph2 = new LineGraph(config[n].lg2);
cntr[n].append(lineGraph2, {topPercentOffset: 0, leftPercentOffset: 1/3, heightPercent: 1, widthPercent: 1/3});
lineGraph3 = new LineGraph(config[n].lg3);
cntr[n].append(lineGraph3, {topPercentOffset: 0, leftPercentOffset: 2/3, heightPercent: 1, widthPercent: 1/3});
// <div id="widgetTarget80"><p>80n. Lines with Legend</p></div>
n = config.push({cntr: null, lg: null}) - 1;
config[n].cntr = {
node: d3.select("#widgetTarget80n"),
maxWid: 500,
maxHt: 400
};
config[n].lg = {
id: "lg" + n,
Data: [lineData, projected, nineB],
type: "lines",
xAxisFormat: { type: "linear",
ticks: [1900, 1950, 1990, 2010, 2030, 2050],
orientation: "bottom",
label: "Year" },
yAxisFormat: { type: "linear",
ticks: 8,
orientation: "left",
label: "Human Population (Billions)" },
};
var lblGrpConfig80 = {
id: "lbls80",
type: "numbered",
labels:
[
{ content: "historical data", xyPos: [1960, 3], width: 100},
{ content: "predicted", xyPos: [2011, 7], width: 100 },
{ content: "threshold" , xyPos: [1980, 9], width: 100 },
]
};
// create a label group that emits events
var labelGroup80 = new LabelGroup(lblGrpConfig80, eventManager);
cntr[n] = new SVGContainer(config[n].cntr);
lineGraph[n] = new LineGraph(config[n].lg,eventManager);
var legLines = new Legend({
xPos: "left", yPos: "top",
labels: [{ content: "historical data long discription", },
{ content: "predicted", },
{ content: "threshold" ,}],
type: "line"
},eventManager);
// draw the lineGraph in the container
cntr[n].append(lineGraph[n], {topPercentOffset: 0, leftPercentOffset: 0, heightPercent: 1,
widthPercent: 1});
// draw the legend and the labels on the line graph
lineGraph[n].append([legLines, labelGroup80]);
eventManager.subscribe(labelGroup80.selectedEventId,
handleSelectionChanged);
eventManager.subscribe(legLines.selectedEventId,
handleSelectionChanged);
eventManager.subscribe(lineGraph[n].selectedEventId,
handleSelectionChanged);
handleSelectionChanged({selectKey: "0"});
/************************************************************************
* handleSelectionChanged *//**
*
* handleInputValueChanged is called from the event handler for one of
* the input widgets when the user changes its value. It updates the
* given matching input widget's value to match the new value and then
* updates the bar chart.
*
* @param eventDetails These are the keyed values returned by
* the event, in this case, a selection
* (click).
*************************************************************************/
function handleSelectionChanged(eventDetails)
{
//Handler needs to get written into each page,
//each widget will have it's own way of responding
//since these are all highlight events, they have the
//lite method name
labelGroup80.lite(eventDetails.selectKey);
lineGraph[n].lite(eventDetails.selectKey);
legLines.lite(eventDetails.selectKey);
}
</script>
</body>
</html>