-
Notifications
You must be signed in to change notification settings - Fork 0
/
interactivity.html
258 lines (240 loc) · 11.4 KB
/
interactivity.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
<!DOCTYPE html>
<html>
<head>
<title>Deeper Interactivity</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="canonical" href="http://www.vizitsolutions.com/portfolio/vfield/interactivity.html" />
<link rel="stylesheet" href="nstyle.css" type="text/css" />
<link rel="stylesheet" href="vfield.css" type="text/css" />
<!-- Lesson.js uses these styles -->
<link rel="stylesheet" type="text/css"
href="http://vizit.github.io/lesson/css/Lesson.css">
<link rel="prev" href="sideBySide.html">
<link rel="next" href="interactiveField.html">
<link rel="stylesheet" type="text/css"
href="https://cdnjs.cloudflare.com/ajax/libs/prettify/r298/prettify.min.css" />
<script async src=https://cdnjs.cloudflare.com/ajax/libs/prettify/r298/prettify.min.js></script>
<script defer src="http://vizit.github.io/lesson/js/Lesson.min.js">
</script>
<script defer src="http://vizit.github.io/vfield/js/VField.min.js">
</script>
<script>
// This object is loaded by the VizBuilder on the DOMReady event.
var VISUALIZATION_CONFIG
= {
// This is a simple vector field, so we draw
// vectors representing the field along the field lines.
type: "simple vector field",
// The id of the canvas we draw into
canvas: "chargeCanvas",
scale: 5.0,
arrowSize: 1.0,
// f is a vector valued function.
// In this case the electric field from a single charge.
f:
{
type: "charge", charge: 5.0,
x: 0.0, y: 0.0, z: 0.0,
nfieldLines: 25.0,
// Set the charge to q1 when it changes.
bind: {set: "charge", from: "q1"}
}
};
</script>
</head>
<body onload="prettyPrint()">
<div class="wrapper">
<div id="main">
<div id="header">
<span class="logo2 Fell drawOnResize"><a href = "http://www.vizitsolutions.com/">Vizit Solutions</a></span>
<ul>
<li class="drawOnResize"><a href="http://www.vizitsolutions.com/portfolio/catalog/" title="Catalog">Catalog</a></li>
<li class="drawOnResize"><a href="http://www.vizitsolutions.com/portfolio/" title="Portfolio">Portfolio</a></li>
<li class="drawOnResize"><a href="http://blog.vizitsolutions.com/" title="Blog">Blog</a></li>
<li class="drawOnResize"><a href="mailto:[email protected]?subject=Vector+Fields" title="[email protected]">Contact</a></li>
</ul>
</div>
<div class="content">
<h1>Deeper Interactivity</h1>
<p id="nowebgl" class="error"></p>
<p>
Effective use of technology in education invites the learner to explore,
to ask what if, and to see the results of their curiosity. These tools
make it not only possible, but comparatively easy to build this type of
content. Try clicking and dragging to adjust the charge in the figure
caption.
</p>
<figure class="center">
<!--This is the canvas for our electric field visualization. -->
<canvas id="chargeCanvas" width="300" height="300"></canvas>
<!-- This lesson element controls q1 ranging from -5 to 5 in steps of .2 -->
<figcaption>The electric field from a
<span class="lessonElement"
data-type="rangedSource"
data-name="q1"
data-value="5.0"
data-min="-5.0"
data-max="5.0"
data-step="0.2"></span>
statC<sup>1</sup> charge .</figcaption>
</figure>
<p>
This slightly more sophisticated example requires a slightly more
sophisticated approach.
</p>
<ul>
<li>Include the VField and Lesson toolkits on your page.</li>
<li>Configure the visualization.</li>
<li>Give a place to draw the visualization.</li>
<li>Define interactions.</li>
</ul>
<h3>Include VField and Lesson toolkits</h3>
<pre class="prettyprint"><code class="language-js">
<!-- Lesson.js uses these styles -->
<link rel="stylesheet" type="text/css"
href="http://vizit.github.io/lesson/css/Lesson.css">
<script defer src="http://vizit.github.io/lesson/js/Lesson.min.js">
</script>
<script defer src="http://vizit.github.io/vfield/js/VField.min.js">
</script>
</code></pre>
<p>
In addition to VField we also include two other files, the Lesson
JavaScript toolkit and its supporting Lesson.css. The lesson toolkit
addresses the more general question of how to write interactive content
and so is the home for functionality that we want, but is not
specifically associated with vector fields.
</p>
<p>
This is where the <samp>defer</samp> attribute comes into play. It
loads the scripts asynchronously, but keeps them in order. This is
critical because the VField toolkit depends on the Lesson toolkit
for interactivity.
</p>
<h3>Configure the visualization</h3>
<pre class="prettyprint"><code class="language-js">
<script>
// This object is loaded by the VizBuilder on the DOMReady event.
var VISUALIZATION_CONFIG
= {
// This is a simple vector field, so we draw
// vectors representing the field along the field lines.
type: "simple vector field",
// The id of the canvas we draw into
canvas: "chargeCanvas",
scale: 5.0,
arrowSize: 1.0,
// f is a vector valued function.
// In this case the electric field from a single charge.
f:
{
type: "charge", charge: 5.0,
x: 0.0, y: 0.0, z: 0.0,
nfieldLines: 25.0,
// Set the charge to q1 when it changes.
bind: {set: "charge", from: "q1"}
}
};
</script>
</code></pre>
<p>
This is the same configuration as the first example, with
one exception. Again we draw a simple vector field generated
by a point charge at the origin onto the <code>chargeCanvas</code>.
But this time we add a binding that sets the charge from the
variable <code>q1</code>. This means that when a <code>q1Changed</code>
event happens, the charge on <code>f</code>, is set to the new value
for <code>q1</code>. This does not care how the <code>q1Changed</code>
event is generated, or even if is generated at all. This means that
the event can be generated by any of several Lesson components, or
even by your own code.
</p>
<h3>Give a place to draw and define interactions</h3>
<pre class="prettyprint"><code class="language-html">
<figure class="center">
<!--This is the canvas for our electric field visualization. -->
<canvas id="chargeCanvas" width="300" height="300"></canvas>
<!-- This lesson element controls q1 ranging from -5 to 5 in steps of .2 -->
<figcaption>The electric field from a
<span class="lessonElement"
data-type="rangedSource"
data-name="q1"
data-value="5.0"
data-min="-5.0"
data-max="5.0"
data-step="0.2"></span>
statC<sup>1</sup> charge .</figcaption>
</figure>
</code></pre>
<p>
This is where the Lesson toolkit comes into play. The Lesson toolkit
helps build interactive instructions, that is lessons. Elements of a
lesson have the HTML class <code>lessonElement</code>, and their
functionality is described by <a href
= "https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Using_data_attributes">HTML5
data attributes</a>. The <code>span class="lessonElement"</code>
with <code>data-type="rangedSource"</code> controls the <code>q1</code>
variable, which ranges from -5.0 to 5.0 in steps of 0.2 and an initial
value of 5.0. A full description of the attributes:
</p>
<table class="explanation">
<tr>
<th>attribute</th><th>meaning</th><th class="optional">example</th>
</tr>
<tr>
<td>class</td><td>Identifies a component of a lesson.</td><td class="optional"><code>lessonElement</code></td>
</tr>
<tr>
<td>data-type</td><td>The type of component.</td><td class="optional"><code>data-type="rangedSource"</code></td>
</tr>
<tr>
<td>data-name</td><td>The name of the variable that this component effects.</td><td class="optional"><code>data-name="q1"</code></td>
</tr>
<tr>
<td>data-value</td><td>The initial value.</td><td class="optional"><code>data-value="5.0"</code></td>
</tr>
<tr>
<td>data-min</td><td>The min value for the control.</td><td class="optional"><code>data-min="-5.0"</code></td>
</tr>
<tr>
<td>data-max</td><td>The max value for the control.</td><td class="optional"><code>data-max="5.0"</code></td>
</tr>
<tr>
<td>data-step</td><td>The variable changes by this amount as the control is moved.</td><td class="optional"><code>data-step="0.2"</code></td>
</tr>
</table>
<p>
This example incorporates the control into the figure caption. You are free to place it
anywhere in your content as it best meets your goals.
</p>
<p>
Let's take a look at what happens when we provide this same <a href
= "interactiveField.html">interactivity to the second example</a>, the field lines for
our point charge.
</p>
<div class="footnote">
<ol>
<li>
<a href = "http://en.wikipedia.org/wiki/Gaussian_units#Unit_of_charge">statC,
rationalized cgs unit of charge.</a>
</li>
<li>
<a href = "https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent">HTML5
custom events</a>
</li>
</ol>
</div>
<div class="center license">
<span xmlns:dct="http://purl.org/dc/terms/" href="http://purl.org/dc/dcmitype/InteractiveResource"
property="dct:title" rel="dct:type">VField Documentation</span> by <a xmlns:cc="http://creativecommons.org/ns#"
href="http://www.vizitsolutions.com/" property="cc:attributionName" rel="cc:attributionURL">Vizit Solutions</a>
is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by/4.0/">Creative Commons
Attribution 4.0 International License</a>.
</div>
</div>
<script src="../../js/vizit.js"></script>
</div>
</div>
</body>
</html>