-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
51 lines (48 loc) · 1.71 KB
/
script.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
// Load Hilbert Basis lookup dictionary.
var hilbertBases = {}
$(document).ready(function() {
$.getJSON('bases.json', function(data) {
console.log('bases loaded');
hilbertBases = data;
calculate();
})
});
function drawHilbertBasis(basis) {
console.log(basis);
update();
svg.selectAll("circle.basisCircles").remove();
// svgContainer.selectAll("circle.basisCircles").remove();
if (basis != undefined) {
basis.forEach(function(element) {
basisCircles.append("circle")
.attr("class", "basisCircles")
.attr("r", 4)
.attr("fill", "yellow")
.attr("fill-opacity", 1.0)
.attr("cx", element[0] * scaleFactor)
.attr("cy", element[1] * -scaleFactor);
});
} else {
console.log("Error: Basis not loaded")
}
}
function calculate() {
if (hilbertBases == undefined) {
$.getJSON('bases.json', function(data) {
console.log('bases loaded');
hilbertBases = data;
})
}
var sourceEnc = escape($("#sourceInput").val());
var compareEnc = escape($("#compareInput").val());
var [sx, sy] = sourceEnc.split('%2C');
var [cx, cy] = compareEnc.split('%2C');
var vectorCombination = '[' + String(sx) + ', ' + String(sy) + '],[' + String(cx) + ', ' + String(cy) + ']';
var output = JSON.stringify(hilbertBases[vectorCombination]);
$("#output").html(output);
sourceVector.datum().x = sx * scaleFactor;
sourceVector.datum().y = -sy * scaleFactor;
compareVector.datum().x = cx * scaleFactor;
compareVector.datum().y = -cy * scaleFactor;
drawHilbertBasis(hilbertBases[vectorCombination]);
};