-
Notifications
You must be signed in to change notification settings - Fork 0
/
graph.html
408 lines (339 loc) · 11.5 KB
/
graph.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
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width", initial-scale="1.0">
<meta http-equiv="Content-Type" value="application/xhtml+xml;charset=utf-8" />
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<link rel="manifest" href="/manifest.json">
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5">
<meta name="apple-mobile-web-app-title" content="Demo">
<meta name="application-name" content="Demo">
<meta name="theme-color" content="#ffffff">
<title>Desmos Api Demo</title>
<link rel="stylesheet" href="/static/mathquill/mathquill.css"/>
<script src="/static/js/jquery-3.2.1.min.js"></script>
<script src="/static/mathquill/mathquill.js"></script>
<script src="https://www.desmos.com/api/v0.9/calculator.js?apiKey=dcb31709b452b1cf9dc26972add0fda6"></script>
<script src="/static/js/handlebars.min-latest.js"></script>
<script id="group-template" type="text/x-handlebars-template">
<div class="group" id="{{expression}}group" numRange="0">
<div class="line">
<label>Equation:</label>
<span class="equation-holder expression">
<span class="equation" id="{{expression}}equation">
0=sin(x)-y
</span>
</span>
<img class="minus-expression button" id="{{expression}}minus" src="/static/img/subtract.svg"/>
</div>
<div class="line">
<div class="split range">
<div class="side left min">
<input checked="true" type="checkbox" class="isEnabled" id="{{expression}}check-min">
<label>Min:</label>
<span class="equation-holder">
<span class="equation" id="{{expression}}min">
0
</span>
</span>
</div>
<div class="side right max">
<input checked="true" type="checkbox" class="isEnabled" id="{{expression}}check-max">
<label>Max:</label>
<span class="equation-holder">
<span class="equation" id="{{expression}}max">
5
</span>
</span>
</div>
</div>
<img class="button plus" id="{{expression}}plus" src="/static/img/add.svg"/>
</div>
</div>
</script>
<script id="range-template" type="text/x-handlebars-template">
<div class="line" id="{{expression}}range{{range}}">
<div class="split range-dynamic">
<div class="side left min">
<input type="checkbox" text="" class="checkbox-hidden" disabled>
<label>Min:</label>
<span class="equation-holder">
<span class="equation" id="{{expression}}min{{range}}">
0
</span>
</span>
</div>
<div class="side right max">
<input type="checkbox" text="" class="checkbox-hidden" disabled>
<label>Max:</label>
<span class="equation-holder">
<span class="equation" id="{{expression}}max{{range}}">
5
</span>
</span>
</div>
</div>
<img class="button minus" id="{{expression}}minus{{range}}" src="/static/img/subtract.svg"/>
</div>
</script>
<script>
/*
$(".group").each(function () {a=this;});
OR
a = $(".group")[INDEX]
$(".equation", a)
$(".expression .equation", a).each(function () { MQ(this).latex(); });
$(".range [.min/.max] .equation", a) .latex()
$("[.min/.max] .isEnabled", a)[0].checked
*/
var MQ = MathQuill.getInterface(2);
var range_template = Handlebars.compile(document.getElementById("range-template").innerHTML);
var group_template = Handlebars.compile(document.getElementById("group-template").innerHTML);
function makeGroupName(x) {
return "#"+x+"group";
}
function makeRangeName(x, y) {
return "#"+x+"range"+y;
}
function createNewExpressionButton() { // call after each append to #settings to make button be on bottom
$("#addExpression").remove();
$("#settings").append("<img class=\"button\" id=\"addExpression\" src=\"/static/img/add.svg\"/>")
//$("#addExpression").click(function(){alert("Not Implemented");});
$("#addExpression").click(newExpression);
}
function createMathField(id) {
return MQ.MathField ( document.getElementById(id), {handler: {edit: refresh } } );
}
function newExpression() {
var x = $("#settings").attr("numGroup");
$("#settings").attr("numGroup", parseInt(x)+1);
var groupName = makeGroupName(x);
$("#settings").append ( group_template( {expression: x} ) );
createNewExpressionButton();
createMathField(x+"equation");
createMathField(x+"min");
createMathField(x+"max");
// Register checkboxes to enable/disable each min/max edit
$("#"+x+"plus").click(function () {newRange(x);});
$("#"+x+"minus").click(function () {deleteExpression(x);});
console.log("#"+x+"check-min")
$("#"+x+"check-min").click(function () {onCheckbox(this, "#"+x+"min");});
$("#"+x+"check-max").click(function () {onCheckbox(this, "#"+x+"max");});
}
function newRange(x) {
var groupName = makeGroupName(x);
var y = $(groupName).attr("numRange");
$(groupName).attr("numRange", parseInt(y)+1);
$(groupName).append(
range_template(
{expression: x, range: y}
)
);
createMathField(x+"min"+y);
createMathField(x+"max"+y);
$("#"+x+"minus"+y).click(function () {deleteRange(x, y);});
}
function deleteExpression(x) {
var groupName = makeGroupName(x);
$(groupName).remove();
}
function deleteRange(x, y) {
var rangeName = makeRangeName(x, y);
//$(rangeName+" .equation").each( function (i) {
// MQ(this).revert();
//});
$(rangeName).remove();
}
function onCheckbox(box, id) {
console.log(box);
console.log(id);
if (box.checked) {
//$(id).removeAttr("disabled");
$(id).show()
} else {
//$(id).attr("disabled", true);
$(id).hide()
}
}
function refresh() {
/*var eq = equation.latex()
calc.setExpression({id: "equation", latex: eq})*/
// $(".equation").each( function () { console.log(MQ.MathField(this).latex()) });
}
function go() {
var div = document.getElementById('calculator');
calc = Desmos.GraphingCalculator(div,
{keypad: false, settingsMenu: false,
expressionsTopbar: false, images: false,
expressions: false});
calc.setExpression({id:'equation', latex:''})
/*equation = MQ.MathField(document.getElementById("equation"),
{handlers: {
edit: onEquationEdit
}});
min = MQ.MathField(document.getElementById("min"),
{handlers: {
edit: onEquationEdit
}});
max = MQ.MathField(document.getElementById("max"),
{handlers: {
edit: onEquationEdit
}});
/*min1 = MQ.MathField(document.getElementById("min1"),
{handlers: {
edit: onEquationEdit
}});
max1 = MQ.MathField(document.getElementById("max1"),
{handlers: {
edit: onEquationEdit
}}); */
var expression = 0;
var range = 0;
createNewExpressionButton();
/*newExpression(0);
newExpression(1);
newExpression(2);
newExpression(3);
newExpression(4);
newRange(1);
newRange(2);
newRange(2);
newRange(3);
newRange(3);
newRange(3);
newRange(4);
newRange(4);
newRange(4);
newRange(4);
refresh();*/
}
$(go);
</script>
<style>
html, body {
height: 100%;
overflow: hidden;
}
#main {
overflow: hidden;
}
.split { /* .split as container, .side .left and .side .right as equal splits*/
height: 100%;
width: 100%;
overflow: hidden;
float: left;
/*margin: 0 auto;
/*float: left;*/
/*vertical-align: middle;
height: 100%;
display: inline-block;*/
}
.side {
display: block;
vertical-align: top;
height: 100%;
width: calc(50% - 4px);
margin: 2px;
}
.left {
float: left;
}
.right {
float: right;
}
#settings {
overflow: auto;
height: calc(100% - 20px);
overflow-x: auto;
}
#calculator {
height: calc(100% - 20px);
padding: 0px;
overflow: visible;
}
.equation-holder {
display: block;
overflow: hidden;
padding: 0 4px 0 6px;
height: 24px;
}
.expression {
margin-right: 26px;
}
.equation {
/*min-width: 100px;*/
width: 100%
}
label {
float: left;
font-size: 18px;
padding: 1px;
}
.group {
padding: 2px;
border: 1px #444444 solid;
margin: 8px 1px;
overflow: hidden;
min-width: 225px;
}
.line {
margin: 1px 0;
display: inline;
width: 100%;
overflow: hidden;
height: 28px !important;
/*outline:1px #000 solid;*/
}
input[type='checkbox'] {
float: left;
vertical-align: middle;
}
.button {
float: right;
display: inline;
vertical-align: middle;
margin: 1px 0px;
width: 24px;
height: 24px;
}
#addExpression {
margin-top: 10px;
margin-right: 5px;
}
.minus-expression {
margin-top: -25px;
}
.range, .range-dynamic {
width: calc(100% - 24px);
}
/*.range-dynamic {
width: calc(50% - 20px); margin-left: 20px;
}*/
.checkbox-hidden {
opacity: 0;
}
@media all and (max-width:600px) {
#settings, #calculator {
height: calc(50% - 10px);
width: calc(100% - 4px);
margin: 2px;
}
#calculator {
display: block;
}
}
</style>
</head>
<body>
<div class="split" id="main">
<div class="side left" id="settings" numGroup="0">
<h1>Settings</h1>
</div>
<div class="side right" id="calculator">
</div>
</div>
</body>
</html>