-
Notifications
You must be signed in to change notification settings - Fork 99
/
index.html
186 lines (149 loc) · 6.66 KB
/
index.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
<!DOCTYPE html>
<meta charset="utf-8">
<head>
<link rel="stylesheet" type="text/css" href="css/dependency.css">
<link rel="stylesheet" type="text/css" href="components/sidr/stylesheets/jquery.sidr.dark.css">
<link rel="stylesheet" type="text/css" href="components/editor/editor.css">
</head>
<body>
<!-- A lot of Javascript here :) -->
<script type="text/javascript" src="components/jquery/jquery-2.1.4.min.js"></script>
<script type="text/javascript" src="components/underscore/underscore-min.js"></script>
<script type="text/javascript" src="components/d3/d3.js"></script>
<!-- ================================================= -->
<!-- ===========ACTUAL HTML ================ -->
<!-- ================================================= -->
<form id="form">
<label><input type="range" name="circle_size" min="1" max="50" value="15"/> Circle size</label><br>
<label><input type="range" name="charge_multiplier" min="1" max="500" value="100"/> Charge multiplier</label><br>
<label><input type="range" name="link_strength" min="0.1" max="100" value="7"/> Link strength</label><br>
<label><input type="checkbox" name="show_texts_near_circles"/> Show names</label><br>
<input id="search_input" placeholder="Type regexp to filter nodes" style="width:100%;"><br>
</form>
<!-- Add editor logic with button and everything else -->
<script type="text/javascript" src="components/sidr/jquery.sidr.js"></script>
<script type="text/javascript" src="components/ace/ace.js"></script>
<script type="text/javascript" src="components/editor/editor.js"></script>
<a id="simple-menu" class="editor-button" href="#sidr">Live editor</a>
<div id="chart">
<!-- Here the SVG will be placed-->
</div>
<script type="text/javascript" src="origin.js"></script>
<script src="components/depvis/depvis-graph-actions-select.js"></script>
<script src="components/depvis/depvis-parse.js"></script>
<script src="components/depvis/depvis-config.js"></script>
<script src="components/depvis/depvis-visualizer.js"></script>
<script>
// ===================================================
// =============== CONFIGURABLE PARAMS ==============
// ===================================================
let config = dvconfig.create();
const dvgraph = objcdv.parse_dependencies_graph(dependencies);
const d3graph = dvgraph.d3jsGraph();
var w = window,
d = document,
e = d.documentElement,
g = d.getElementsByTagName('body')[0],
x = w.innerWidth || e.clientWidth || g.clientWidth,
y = w.innerHeight || e.clientHeight || g.clientHeight;
// ===================================================
// =============== http://d3js.org/ Magic ===========
// ===================================================
const container = d3.select("#chart").append("svg")
.attr("width", x)
.attr("height", y)
.style("overflow", "hidden");
const svg = container.append('g');
const actions = graph_actions.create(svg, dvgraph);
let visualizer = dvvisualizer.create(svg, config, d3graph);
visualizer.initialize();
visualizer.setupZoom(container);
// ===================================================
// =============== NODES SETUP ==================
// ===================================================
// Handling pressing
visualizer.objectNodes
.on("click", d => {
if (d3.event.defaultPrevented) { return }
actions.selectNodesStartingFromNode(d, 1);
visualizer.reapply_charge_and_links()
})
.on("contextmenu", d => {
if (d3.event.defaultPrevented) { return }
// Don't actually show context menu
d3.event.preventDefault();
actions.selectNodesStartingFromNode(d);
visualizer.reapply_charge_and_links()
});
/*
Window resize update
*/
w.onresize = () => {
x = w.innerWidth || e.clientWidth || g.clientWidth;
y = w.innerHeight || e.clientHeight || g.clientHeight;
container.attr("width", Math.ceil(x)).attr("height", Math.ceil(y));
visualizer.updateCenter(x / 2, y / 2);
};
</script>
<script>
// ===================================================
// =============== INPUTS HANDLING ==============
// ===================================================
d3.selectAll("input").on("change", function change() {
if (this.name === "circle_size") {
config.default_circle_radius = parseInt(this.value);
visualizer.updateRadiuses(parseInt(this.value));
}
if (this.name === "charge_multiplier") {
let chargeMultiplier = parseInt(this.value);
visualizer.reapply_charge(chargeMultiplier)
}
if (this.name === "link_strength") {
let linkStrength = parseInt(this.value) / 10;
visualizer.reapply_links_strength(linkStrength)
}
if (this.name === "show_texts_near_circles") {
visualizer.updateTextVisibility(this.checked)
}
});
</script>
<script>
// ===================================================
// =============== LIVE FILTERING ==============
// ===================================================
function live_filter_graph(regexp, classname, invert) {
classname = setDefaultValue(classname, "filtered");
invert = setDefaultValue(invert, false);
const re = new RegExp(regexp, "i");
visualizer.allNodes
.classed(classname, node => {
let filtered = !node.name.match(re);
filtered = invert ? !filtered : filtered;
node.filtered = filtered;
node.neighbours = !filtered;
return filtered;
})
.transition();
svg.selectAll('.link')
.classed(classname, l => {
let filtered = !(l.sourceNode.name.match(re) && l.targetNode.name.match(re));
filtered = invert ? !filtered : filtered;
return filtered;
})
.attr("marker-end", l => {
let filtered = !(l.sourceNode.name.match(re) && l.targetNode.name.match(re));
filtered = invert ? !filtered : filtered;
return filtered ? "" : "url(#default)"
})
.transition()
}
d3.select("#search_input").on("input", function () {
// Filter all items
console.log("Input changed to" + this.value);
actions.deselect_selected_node();
if (this.value && this.value.length) {
live_filter_graph(this.value, "filtered");
}
visualizer.reapply_charge_and_links();
});
</script>