-
Notifications
You must be signed in to change notification settings - Fork 0
/
functionPlotView.js
49 lines (40 loc) · 1.08 KB
/
functionPlotView.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
document.addEventListener('joplin-noteDidUpdate', plotFunctions );
if (/WebKit/i.test(navigator.userAgent)) { // sniff
var _timer_fplot = setInterval(function() {
if (/loaded|complete/.test(document.readyState)) {
plotFunctions()
}
}, 10);
}
function uuid(rid, counters){
var uid = rid;
if (rid in counters){
counters[rid] = counters[rid] + 1;
uid = rid + "-" + counters[rid];
} else {
counters[rid] = 1
}
return uid
}
function plotFunctions() {
if (_timer_fplot) clearInterval(_timer_fplot);
const plots = document.getElementsByClassName('function-plot-view');
const counters = {};
for (var i=0; i<plots.length; i++){
var plot = plots[i];
try {
var options = JSON.parse(plot.textContent);
var rid = options["target"] || "#fplotABC";
var uid = uuid(rid, counters);
options["target"] = uid;
setTimeout(makeFunctionPlot(plot, options),60);
} catch (e) {
plot.innerHTML = "Parsing Error";
}
}
}
function makeFunctionPlot(plot, options) {
plot.innerHTML = ''; // Clear element content
plot.id = options["target"].substring(1)
functionPlot(options)
}