-
Notifications
You must be signed in to change notification settings - Fork 0
/
radio.html
166 lines (139 loc) · 4.23 KB
/
radio.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Radio Buttons</title>
<link href="https://fonts.googleapis.com/css?family=Quicksand&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.1/css/bulma.min.css">
</head>
<style type="text/css">
.line {
fill: none;
stroke: steelblue;
stroke-width: 3;
}
.overlay {
fill: none;
pointer-events: all;
}
.dot {
fill: steelblue;
stroke: #fff;
}
.focus circle {
fill: none;
stroke: steelblue;
}
h1 {
text-align: center;
}
.chart-container {
text-align: center;
}
.div-chart {
display: inline-block;
}
</style>
<body>
<div class="chart-container">
<!-- displays the chart first -->
<div id ="chart" class="div-chart"></div>
<!-- user instructions -->
<h1>Using the chart above, please select the value for <strong>y</strong> when <strong>x=2</strong>:</h1>
<!-- radio button toggle -->
<p><form action="https://www.eecs.tufts.edu/~asuh/">
<input type="radio" id="choice0" name="yvalue" value="0">
<label for="choice1">0</label><br>
<input type="radio" id="choice1" name="yvalue" value="5">
<label for="choice1">5</label><br>
<input type="radio" id="choice2" name="yvalue" value="10">
<label for="choice2">10</label><br>
<input type="radio" id="choice3" name="yvalue" value="15">
<label for="choice3">15</label><br>
<input type="radio" id="choice4" name="yvalue" value="20">
<label for="choice4">20</label><br>
<!-- when the user clicks the button, the total time spent on the page is displayed -->
<button onclick="getTime()" type="button">Submit</button>
</form></p>
</div>
</body>
<script src="https://d3js.org/d3.v5.min.js"></script>
<script>
var startTime, msec, sec;
// starts a timer once the page is loaded
window.onload=function(){
startTime = new Date();
}
// returns the total time the user spent on the page
function getTime() {
msec = new Date()-startTime;
sec = msec/1000;
window.alert("Time spent: " + sec + " seconds");
}
// THE REST IS D3 NONSENSE for drawing the graph
var margin = {top: 50, right: 50, bottom: 50, left: 50}
, width = 500 - margin.left - margin.right
, height = 350 - margin.top - margin.bottom;
var xScale = d3.scaleLinear()
.domain([0, 4])
.range([0, width]);
var yScale = d3.scaleLinear()
.domain([0, 20])
.range([height, 0]);
var line = d3.line()
.x(function(d, i) { return xScale(i); })
.y(function(d) { return yScale(d.y); })
// toy data, can change later
var dataset = [ {"y": 5}, {"y": 20}, {"y": 10}, {"y": 15}, {"y": 5} ]
console.log(dataset);
var svg = d3.select("#chart").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(d3.axisBottom(xScale)
.ticks(5)
.tickFormat(d3.format(".0s")));
svg.append("text")
.attr("class", "x label")
.attr("text-anchor", "end")
.style("font-size", "12px")
.style("font-style", "italic")
.attr("x", width)
.attr("y", height + 35)
.text("x-values");
svg.append("g")
.attr("class", "y axis")
.call(d3.axisLeft(yScale)
.ticks(5));
svg.append("path")
.datum(dataset)
.attr("class", "line")
.attr("d", line);
svg.selectAll(".dot")
.data(dataset)
.enter().append("circle")
.attr("class", "dot")
.attr("cx", function(d, i) { return xScale(i) })
.attr("cy", function(d) { return yScale(d.y) })
.attr("r", 5)
svg.append("text")
.attr("class", "y label")
.attr("text-anchor", "end")
.style("font-size", "12px")
.style("font-style", "italic")
.attr("y", -45)
.attr("dy", ".75em")
.attr("transform", "rotate(-90)")
.text("y-values");
svg.append("text")
.attr("x", (width / 2))
.attr("y", 0 - (margin.top / 2))
.attr("text-anchor", "middle")
.style("font-size", "16px")
.text("You will be performing a very simple task for us!");
</script>