-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
230 lines (196 loc) · 5.07 KB
/
main.js
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
//Chart options
var chartOptions = {
lineWidth: 4,
animation: {
duration: 1000,
easing: 'in',
startup: true
},
curveType: 'none',
tooltip: { isHtml: true,
trigger: 'selection'}
};
/* Window resize handling */
var timer;
var chartDrawn = false;
var clientWidthOld = document.documentElement.clientWidth;
var clientHeightOld = document.documentElement.clientHeight;
window.addEventListener('resize', function(){
if ((document.documentElement.clientWidth != clientWidthOld) || //Handle mobile resizes when the address bar appears or disappears
(document.documentElement.clientHeight > clientHeightOld + 200) || //That is, resize only on width changes or significant height changes.
(document.documentElement.clientHeight < clientHeightOld - 200))
{
clientWidthOld = document.documentElement.clientWidth;
clientHeightOld = document.documentElement.clientHeight;
clearTimeout(timer);
timer = setTimeout(function(){
if (chartDrawn)
{
setChartArea();
drawChart();
}
}, 500);
}
});
/* History handling */
window.onpopstate = function(event) {
if (getUrlOptions() == 0)
{
setPageOptions();
processOptions();
// Set a timeout of 0 to push the calculation into the queue and let the spinner update on the page
setTimeout(function(){
calculate();
}, 0);
}
};
function drawChart() {
// Disable the button while the chart is drawing.
var button = document.getElementById('calcbutton');
button.disabled = true;
google.visualization.events.addListener(chartWrapper, 'ready',
function() {
button.disabled = false;
//Turn off the loading spinners
document.getElementById("calculatingspinner").style.display = "none";
document.getElementById("loadingoverlay").style.display = "none";
document.getElementById('description').style.display = "none";
document.getElementById('results').style.display = "block";
});
//Clear the chart if it has been drawn already
if (chartWrapper.getChart())
{
chartWrapper.getChart().clearChart();
}
chartDrawn = true;
chartWrapper.draw();
//Add overlays to area chart when it is ready
document.getElementById("overlaycontainer").innerHTML = "";
if (calcopts.chartmode === "area")
{
google.visualization.events.addOneTimeListener(chartWrapper.getChart(), 'animationfinish', addOverlays);
}
}
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(init);
/*
window.onload = function()
{
}
*/
function addTooltip()
{
chartWrapper.getChart().setAction({
id: 'showpmf',
text: 'Show PMF at this number of encounters',
visible: function() {
var selection = chartWrapper.getChart().getSelection();
if (selection.length > 0)
{
if (selection[0].row > 0)
{
return true;
}
}
return false;
},
action: function() {
var selection = chartWrapper.getChart().getSelection();
pageOpts.encounterstograph.setValue(data.getValue(selection[0].row,0));
pageOpts.chartmode.setValue("pmf");
setPageOptions();
processOptions();
setUrlOptions();
calculate();
}
});
chartWrapper.getChart().setAction({
id: 'showcdf',
text: 'Show 1-CDF at this number of encounters',
visible: function() {
var selection = chartWrapper.getChart().getSelection();
if (selection.length > 0)
{
if (selection[0].row > 0)
{
return true;
}
}
return false;
},
action: function() {
selection = chartWrapper.getChart().getSelection();
pageOpts.encounterstograph.setValue(data.getValue(selection[0].row,0));
pageOpts.chartmode.setValue("cdf");
setPageOptions();
processOptions();
setUrlOptions();
calculate();
}
});
}
function resetClick()
{
resetOptionDefaults();
resetUrlOptions();
setPageOptions();
processOptions();
}
function calculateClick()
{
getPageOptions();
if (!validateOptions());
{
//Save the options for this chart in the URL
setUrlOptions(true);
setPageOptions();
}
// Start the loading spinner
document.getElementById("calculatingspinner").style.display = "block";
// Set a timeout of 0 to push the calculation into the queue and let the spinner update on the page
setTimeout(function(){
calculate();
}, 0);
}
var width, height, heightpercent;
/* Set chart area.
* Call this during init.
* Don't call during button press to prevent virtual-keyboard size changes on mobile.
*/
function setChartArea()
{
width = window.innerWidth;
height = window.innerHeight;
if (height > width)
{
height = height/2;
}
else
{
height = Math.max((height - 300),(width/2.5));
}
// Decrease chart area to fit the title if it spans two lines
if (width < 1000)
{
heightpercent = '70%';
widthpercent = '75%';
}
else
{
heightpercent = '85%';
widthpercent = '90%';
}
//Reset these in calculate() as well.
chartOptions.width = "90%";
chartOptions.height = height;
chartOptions.chartArea = {width:widthpercent,height:heightpercent};
}
var chartWrapper;
function init()
{
chartWrapper = new google.visualization.ChartWrapper({'containerId':'visualization'});
setChartArea();
resetOptionDefaults();
setPageOptions();
getUrlOptions();
}