forked from rue-a/rdf_viz
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsketch.js
More file actions
109 lines (97 loc) · 2.59 KB
/
sketch.js
File metadata and controls
109 lines (97 loc) · 2.59 KB
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
/*
global variable initialization
Variables that are used by more than one of
the P5JS functions preload(), setup() and
draw(), need to be initialzied globally.
*/
let canvas;
let inconsolata;
let open_sans_light_italic;
let left_clicked_x;
let left_clicked_y;
let coords_old = {};
let clicked_node;
let strg_pressed = false;
const width = window.innerWidth;
const height = window.innerHeight - 0.1;
const horizontal_margin = width / 5;
const vertical_margin = height / 5;
const node_model = new Model();
const view = new View();
// P5JS method that is executed before setup()
function preload() {
/* load fonts */
inconsolata = loadFont('./assets/Inconsolata.otf');
open_sans_light_italic = loadFont('./assets/OpenSans-LightItalic.ttf')
open_sans_light = loadFont('./assets/OpenSans-Light.ttf')
}
// P5JS method that is executed at program start
function setup() {
/*
- create canvas
- initialize view
- initialize model
- calc initial view (view.update_data())
*/
canvas = createCanvas(width, height);
view.init(
node_model,
width,
height,
horizontal_margin,
vertical_margin,
config.style.radius,
config.style.node_colors,
inconsolata,
open_sans_light,
config.style.label_color,
config.style.label_container_color,
config.style.description_color,
config.style.description_container_color,
config.style.label_container_width,
config.style.description_container_width
);
node_model.init(
config.content.endpoint,
config.content.initial_node,
config.content.prefixes,
config.content.predicates,
config.content.labels,
config.content.descriptions,
config.content.metadata_predicates,
).then(() => {
view.update_data();
})
// view.switch_mode()
}
// P5JS method that is called in a loop and draws on canvas
function draw() {
/*
- reset drawing pane
- draw current view
- draw hover content, if hover is enabled
- draw controls
*/
background('white');
view.update_canvas();
if (config.style.hover) {
for (let p5node of view.get_nodes()) {
p5node.hover();
}
};
print_controls();
}
function print_controls() {
textFont(inconsolata);
let controls = `Double left click on a node: Expand this node
Left click and hold a node: Drag this node
Strg plus left click on a node: Open this this node\'s IRI in a new tab
Wheel click on a node: Remove this node from the visualization`
textAlign(RIGHT, BOTTOM)
text(controls, width - 8, height - 8)
fill(150)
line(0, 0, width, 0)
line(width, 0, width, height)
line(width, height, 0, height)
line(0, 0, 0, height)
}