-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest.html
More file actions
93 lines (91 loc) · 3.62 KB
/
test.html
File metadata and controls
93 lines (91 loc) · 3.62 KB
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
Skip to content
Features
Business
Explore
Marketplace
Pricing
This repository
Search
Sign in or Sign up
Watch 20 Star 1 Fork 1 concord-consortium/codap-data-interactives
Code Issues 0 Pull requests 1 Projects 0 Insights
Branch: master Find file Copy pathcodap-data-interactives/RandomNumbers/RandomNumbers.html
6ffd4ee on Nov 3, 2015
@jsandoe jsandoe Refer to local instances of common libraries.
2 contributors @bfinzer @jsandoe
RawBlameHistory
80 lines (72 sloc) 3.05 KB
<!--This page is an example simulation for CODAP.
When embedded in CODAP it will generate samples of random numbers.-->
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<!--These two scripts take care of the communication with CODAP-->
<script src="../Common/js/iframe-phone.js" language="javascript"></script>
<script src="../Common/js/codap_helper.js" language="javascript"></script>
<title>Random Numbers</title>
</head>
<body bgcolor="white">
<h1>Random Numbers</h1>
<form name="form1">
How many numbers: <input type="text" name="howMany" value="10"><br>
<input type="button" onClick="RandomNumbers.generateNumbers();" value="Generate Them!">
</form>
</body>
<script>
// Modify this Javascript to create your own simulation.
// The following runs as the page is loaded. If it finds that it is embedded in CODAP, it sets
// things up for the simulation to send data.
codapHelper.initSim({
name: 'Random Numbers',
dimensions: {width: 300, height: 150},
collections: [ // There are two collections: a parent and a child
{
name: 'samples',
// The parent collection has just one attribute
attrs: [ {name: "sample", type: 'categorical'}],
childAttrName: "sample"
},
{
name: 'numbers',
labels: {
pluralCase: "numbers",
setOfCasesWithArticle: "a sample"
},
// The child collection also has just one attribute
attrs: [{name: "number", type: 'numeric', precision: 1}]
}
]
});
var RandomNumbers = {
sampleNumber: 0,
// Here is the function that is triggered when the user presses the button
generateNumbers: function () {
// If we're not embedded in CODAP, we bring up an alert and don't draw the sample
if( !codapHelper.checkForCODAP())
return;
// This function is called once the parent case is opened
var doSample = function( iResult) {
var tID = iResult.caseID,
tHowMany = document.forms.form1.howMany.value.trim(),
addOneNumber = function() {
if( tHowMany > 0) {
var tRandom = Math.random() * 100 + 1; // Choose a random number between 1 and 100
// Tell CODAP to create a case in the child collection
codapHelper.createCase('numbers', tRandom, tID, addOneNumber);
tHowMany--;
}
else codapHelper.closeCase('samples', null, tID);
};
addOneNumber(); // This starts an asynchronous recursion
};
// generateNumbers starts here
this.sampleNumber++;
// Tell CODAP to open a parent case and call doSample when done
codapHelper.openCase( 'samples', this.sampleNumber, doSample);
}
};
</script></html>
Contact GitHub API Training Shop Blog About
© 2017 GitHub, Inc. Terms Privacy Security Status Help