forked from ExarcaFidalgo/3dshex
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
136 lines (121 loc) · 3.15 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
const shexParser = require("./src/ShExParser.js");
import TresDGen from './src/TresDGen.js';
import autocomplete from './src/search/Search.js';
import $ from "jquery";
import SpriteText from 'three-spritetext';
class ShExTo3D {
constructor () {
this.graph = null;
this.gData = null;
this.highlightLinks = null;
}
shExTo3D(text, id, dimensions) {
let nodeList = [];
try {
this.gData = shexParser.parseShExToGraph(text);
this.gData.nodes.forEach(node => {
nodeList.push(node.id);
});
} catch(ex) {
alert("An error has occurred when generating the graph data: \n" + ex);
}
if(this.gData.nodes.length > 69) {
$('#chStNode').prop('checked', false);
TresDGen.hiddenNodes = true;
}
if(this.gData.links.length > 288) {
$('#chStEdge').prop('checked', false);
TresDGen.hiddenEdges = true;
}
try {
this.graph = TresDGen.run(this.gData, id);
this.highlightLinks = TresDGen.getHighlightLinks();
let nodeInput = document.getElementById("nodeInput");
if (nodeInput) {
autocomplete(nodeInput, nodeList, this);
}
if(dimensions) {
this.graph.width(dimensions.width);
this.graph.height(dimensions.height);
}
} catch(ex) {
alert("An error has occurred when generating the visualization: \n" + ex);
}
return this.graph;
}
nodeCloseup(id) {
const node = this.gData.nodes.find(obj => {
return obj.id === id
});
const distance = 60;
const distRatio = 1 + distance/Math.hypot(node.x, node.y, node.z);
this.graph.cameraPosition(
{ x: node.x * distRatio, y: node.y * distRatio, z: node.z * distRatio },
node,
2000
);
}
setWikidataTooltips(val) {
TresDGen.wikidataTooltips = val;
}
setNodeLabels(val) {
if(val) { //Ponerlos
$( ".node-label" ).each(function() {
$(this).removeClass('hidden');
});
TresDGen.hiddenNodes = !val;
this.graph.nodeLabel(node => "");
}
else { //Quitarlos
$( ".node-label" ).each(function() {
$(this).addClass('hidden');
});
TresDGen.hiddenNodes = !val;
this.graph.nodeLabel(node => node.id);
}
}
setStaticEdges(val) {
TresDGen.hiddenEdges = !val;
if(val) {
this.graph.linkThreeObject(link => {
let cardinality = TresDGen.edgeCardinality ? link.cardinality : "";
return this.createSprite(link.nname + cardinality, link);
})
this.gData.links.forEach(link => {
link.name = undefined;
});
}
else {
this.graph.linkThreeObject(link => {
return this.createSprite("", link);
})
this.gData.links.forEach(link => {
link.name = link.nname;
});
}
}
setEdgeCardinality(val) {
TresDGen.edgeCardinality = val;
if(!TresDGen.hiddenEdges) {
if(val) {
this.graph.linkThreeObject(link => {
return this.createSprite(`${link.nname}` + `${link.cardinality}`, link);
})
}
else {
this.graph.linkThreeObject(link => {
return this.createSprite(`${link.nname}`, link);
})
}
}
}
createSprite(text, link) {
const sprite = new SpriteText(text);
sprite.color = 'lightgrey';
sprite.textHeight = 2;
sprite.link = link;
link.sprite = sprite;
return sprite;
}
}
export default new ShExTo3D();