-
Notifications
You must be signed in to change notification settings - Fork 4
/
sketchTests.html
417 lines (359 loc) · 14.3 KB
/
sketchTests.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
<!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="rectTest"><p>0. Rectangle { shape: "rectangle", xyPos: [ 0.1, .1], width: 0.75, height: 0.2 }.</p>
</div>
<div id="circTest"><p>1. Three concentric circles centered on space { shape: "circle", xyPos: [0.5, 0.5], radius: .5 }</p>
</div>
<div id="molecule"><p>2. hexagon and lines</p></div>
<div id="compass"><p>3. compass rose (vector precursor)</p></div>
</div>
<div class="lc_ec_trailing">
<div id="hotSpot"><p>4.Click the shapes to lite the label</p></div>
<div id="description"></div>
<div id="redraw"><p>5. Slide the size</p></div>
<div id="someText"><p>6. Text in Sketch (SVG text)</p></div>
<div id="full"><p>7. Filled shapes (black, white, one of sequenced fills for textbook)</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.touchSwipe.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-legend.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-piechart.js"></script>
<script src="js/widget-sketch.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 PieChart = pearson.brix.PieChart;
var Legend = pearson.brix.Legend;
var Sketch = pearson.brix.Sketch;
var Slider = pearson.brix.Slider;
var eventManager = new EventManager();
// Case 0 rectangle
var svgRect = new SVGContainer(
{node: d3.select("#rectTest"),
maxWid: 200,
maxHt: 200
}
);
var rect0 = new Sketch({
id: "rect0",
drawShape: [
{shape: "rectangle", data: [{ xyPos: [ .1, .9], width: 0.75, height:.2 }]}
]
});
svgRect.append(rect0, {topPercentOffset: 0, leftPercentOffset: 0, heightPercent: 1, widthPercent: 1});
// Case 1 circle
var svgCirc = new SVGContainer(
{node: d3.select("#circTest"),
maxWid: 200,
maxHt: 200
}
);
var circ0 = new Sketch({
id: "circle0",
drawShape:
[
{ shape: "circle", data: [{xyPos: [0.5, 0.5], radius: .5 }]},
{ shape: "circle", data: [{xyPos: [0.5, 0.5], radius: .25 }]},
{ shape: "circle", data: [{xyPos: [0.5, 0.5], radius: .15 }]},
],
});
svgCirc.append(circ0, {topPercentOffset: 0, leftPercentOffset: 0, heightPercent: 1, widthPercent: 1});
// Case 2 hexagon and lines
var svgMole = new SVGContainer(
{node: d3.select("#molecule"),
maxWid: 200,
maxHt: 200
}
);
var mole = new Sketch({
id: "carbon",
drawShape:
[
{ shape: "hexagon", data: [{xyPos: [.1, .5], side: .1 }]},
{ shape: "line", data: [{xyPos: [0.19, 0.55], length: .1, angle: Math.PI/5}] },
{ shape: "line", data: [{xyPos: [0.27, 0.61], length: .1, angle: -Math.PI/5}] },
{ shape: "line", data: [{xyPos: [0.34, 0.55], length: .1, angle: Math.PI/5}] },
{ shape: "line", data: [{xyPos: [0.41, 0.61], length: .1, angle: -Math.PI/5}] }
],
});
svgMole.append(mole, {topPercentOffset: 0, leftPercentOffset: 0, heightPercent: 1, widthPercent: 1});
// Case 3 compass rose
var svgCompass = new SVGContainer({
node: d3.select("#compass"),
maxWid: 200,
maxHt: 200
});
var roseLines = new Sketch({
id: "rose",
drawShape:
[
{ shape: "line", data: [{xyPos: [.5, 0], length: .5, angle: 0, type: "vector",}] },
{ shape: "line", data: [{xyPos: [.5, 0], length: .5, angle: Math.PI/4, type: "vector", }] },
{ shape: "line", data: [{xyPos: [.5, 0], length: .5, angle: Math.PI/2, type: "vector", }] },
{ shape: "line", data: [{xyPos: [.5, 0], length: .5,
angle: 2*Math.PI/3,
type: "vector", }] },
{ shape: "line", data: [{xyPos: [.5, 0], length: .5,
angle: 5*Math.PI/6,
type: "vector", }] },
{ shape: "line", data: [{xyPos: [.5, 0], length: .5, angle: Math.PI}] },
],
});
svgCompass.append(roseLines, {topPercentOffset: 0, leftPercentOffset: 0, heightPercent: 1, widthPercent: 1});
// Case 4 highlight events with labels
var svgLabel = new SVGContainer({
node: d3.select("#hotSpot"),
maxWid: 300,
maxHt: 200
});
var clicks = new Sketch({
id: "shapes",
drawShape:
[ { shape: "rectangle", data: [{ xyPos: [0, .5], width: .25, height: .5 }]},
{ shape: "circle", data: [{ xyPos: [0.5, 0.8], radius: .1 }]},
{ shape: "hexagon", data: [{ xyPos: [0.3, 0.5], side: .15 }]},
{ shape: "line", data: [{ xyPos: [0, 1], length: 0.7, angle: -Math.PI/3 }]},
{ shape: "triangle", data: [{ xyPos: [0.3, 0.5], side: .15 }]},
{ shape: "path", fill: "Black",
data: [ {d: "M139.25,157.5l18,3c0,0-2-13,11-21s10-9,20-14s22-12,29-12s-2-17-2-17s15-8,14-15s-10-9-19-4s-41,14-47,22s-22,35-25,45"}]},
],
},eventManager);
var newLabels = new LabelGroup(
{id: "shapeLabel",
labels:
[ {content: "rectangle", xyPos:[.7,1], width: 70},
{content: "circle", xyPos: [.7,.85], width: 70},
{content: "hexagon", xyPos:[.7,.7], width: 70},
{content:"line", xyPos:[.7,.55], width: 70},
{content:"triangle", xyPos:[.7,.4], width: 70},
{content:"path", xyPos:[.7,.25], width: 70},
]
}, eventManager);
//make a set of callouts in a table that lights up with the labels.
var someCalls = new Callouts ({
id: "texty",
headers: ["Shape"],
textBits: [
{
cols: ["A rectangle is a shape with four sides. If all sides are equal then it's a square."]
},
{
cols: ["A circle is a perfectly round shape. We will have to decide whether it makes sense to start drawing it out from it's center, or from the top left, like rectangles." ]
},
{
cols: ["A hexagon is provided because it's a carbon ring."]
},
{
cols: ["lines might need to not start in a group or maybe need a whole different method of specifying. They are really hard to select."]
},
{
cols: ["triangles are equilateral."]
},
{
cols: ["Paths have the same data format as line graphs, as they are done identically."]
},
]
});
someCalls.draw(d3.select("#description"));
// TODO: there is a bug here that prevents me from stacking up both the sketch and the newLabels in an
// array in the svg append function. One expects the other to have axes, or something. Need mjl
// to have a look - lb
svgLabel.append([clicks]);
svgLabel.append([newLabels]);
//case 5 update the size of a sketch object on a slider
var sizeSlide = new Slider ({
id: "setSize",
startVal: 0.5,
minVal: .05,
maxVal: .5,
stepVal: .05,
unit: "unitless",
label: "Size =",
format: '5.2f',
}, eventManager);
sizeSlide.draw(d3.select("#redraw"));
var updateMe = new SVGContainer(
{node: d3.select("#redraw"),
maxWid: 100,
maxHt: 100
}
);
var length = sizeSlide.getValue();
var width = length*Math.cos(45*Math.PI/180);
var height = length*Math.sin(45*Math.PI/180);
var shapeIt = new Sketch({
id: "shapes",
drawShape:
[ { shape: "rectangle", data: [{xyPos: [.5, .5], width: sizeSlide.getValue(), height: sizeSlide.getValue() }]},
{ shape: "circle", data: [{xyPos: [0.5, 0.5], radius: sizeSlide.getValue() }]},
{ shape: "line", data: [{xyPos: [0.5, 0.5], length: sizeSlide.getValue(), angle: 45}]},
],
});
updateMe.append([shapeIt], {topPercentOffset: 0, leftPercentOffset: 0, heightPercent: 1, widthPercent: 1});
// 6. Text test
var svgText = new SVGContainer({
node: d3.select("#someText"),
maxWid: 150,
maxHt: 150
});
var textLines = new Sketch({
id: "thing",
drawShape:
[
{ shape: "line", data: [{ xyPos: [.24, .9], length: 0.1, angle: -Math.PI/5 }]},
{ shape: "line", data: [{ xyPos: [.6, .9], length: 0.1, angle: -4*Math.PI/5 }]},
{ shape: "line", data: [{ xyPos: [.36, .8], length: 0.1, angle: 0 }]},
{ shape: "line", data: [{ xyPos: [.36, .83], length: 0.1, angle: 0 }]},
{ shape: "line", data: [{ xyPos: [.24, .71], length: 0.1, angle: Math.PI/5 }]},
{ shape: "line", data: [{ xyPos: [.6, .71], length: 0.1, angle: 4*Math.PI/5 }]},
{ shape: "textBit", data: [{ xyPos: [.22, .91], text: 'H'}]},
{ shape: "textBit", data: [{ xyPos: [.66, .91], text: 'CH3'}]},
{ shape: "textBit", data: [{ xyPos: [.33, .79], text: 'C'}]},
{ shape: "textBit", data: [{ xyPos: [.5, .79], text: 'C'}]},
{ shape: "textBit", data: [{ xyPos: [.18, .66], text: 'H3C'}]},
{ shape: "textBit", data: [{ xyPos: [.62, .66], text: 'H'}]},
],
});
svgText.append(textLines, {topPercentOffset: 0, leftPercentOffset: 0, heightPercent: 1, widthPercent: 1});
// 7. Fill test, and path
var fillShapes = new SVGContainer({
node: d3.select("#full"),
maxWid: 200,
maxHt: 200
});
var filled = new Sketch({
id: "itIs",
drawShape:
[
{ shape: "hexagon", fill: 2,
data: [{ xyPos: [0.3, 0.4], side: .15 }]},
{ shape: "triangle", fill: 1, data: [{ xyPos: [0.3, 0.6], side: .15 }]},
{ shape: "rectangle", fill: "Black",
data: [{ xyPos: [.05, .25], width: 0.1, height: 0.2 }]},
{ shape: "circle", fill: "White",
data: [{ xyPos: [0.5, 0.5], radius: .1 }]},
],
});
fillShapes.append(filled);
//Test: set the start highlight state of 0 key by calling the
//handler with a hard-set index of 0. This should result in the
//first label getting highlighted and the first callout being displayed.
handleSelectionChanged({selectKey: '0'});
eventManager.subscribe(clicks.selectedEventId, handleSelectionChanged);
eventManager.subscribe(newLabels.selectedEventId, handleSelectionChanged);
eventManager.subscribe(sizeSlide.changedValueEventId,
handleChangedValue);
/* **************************************************************************
* handleChangedValue *//**
*
* 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 {NumericInput} otherInputWidget -This is the other input widget
* whose value needs to be updated
* to match the user changed widget.
* @param {number} newValue - The value of the widget that was changed.
*
****************************************************************************/
function handleChangedValue(newValue)
{
var length = sizeSlide.getValue();
var width = length*Math.cos(45*Math.PI/180);
var height = length*Math.sin(45*Math.PI/180);
shapeIt.drawShape =
[ { shape: "rectangle", data: [{xyPos: [.5, .5], width: sizeSlide.getValue(), height: sizeSlide.getValue() }]},
{ shape: "circle", data: [{xyPos: [0.5, 0.5], radius: sizeSlide.getValue() }]},
{ shape: "line", data: [{xyPos: [0.5, 0.5], length: sizeSlide.getValue(), angle: 45}]},
],
//redraw the dots
shapeIt.redraw();
}
/************************************************************************
* 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
//lite should be a part of the interface for each widget
clicks.lite(eventDetails.selectKey);
newLabels.lite(eventDetails.selectKey);
someCalls.lite(eventDetails.selectKey);
}
</script>
</body>
</html>