Skip to content

Commit fdc5be8

Browse files
Data reset option
1 parent acf2584 commit fdc5be8

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed

src/static/js/graph/index.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import { updateSelection, setLastSelectedNode } from "../selection";
44

55
let shiftKey, ctrlKey,
66
width = window.innerWidth,
7-
height = window.innerHeight,
8-
foreverUniq = 0;
7+
height = window.innerHeight;
98

109
let svg = null,
1110
brush = null,
@@ -132,12 +131,19 @@ export function init () {
132131
.on("keyup", keyUp);
133132
}
134133

135-
export function update () {
134+
export function update (reset = false) {
136135

137136
let graph = getGraphData();
138137

138+
if (reset) {
139+
link = link.data([]);
140+
link.exit().remove();
141+
node = node.data([]);
142+
node.exit().remove();
143+
}
144+
139145
link = link
140-
.data(graph.edges, (d) => foreverUniq++);
146+
.data(graph.edges, (d) => `${ d.source }-${ d.target }`);
141147
link.exit().remove();
142148
link = link.enter().append("line")
143149
.attr("class", d => d.type === "similar"
@@ -148,7 +154,7 @@ export function update () {
148154
);
149155

150156
node = node
151-
.data(graph.nodes, (d) => foreverUniq++);
157+
.data(graph.nodes, (d) => d.id);
152158
node.exit().remove();
153159
node = node.enter().append("g")
154160
.attr("class", "node")

src/static/js/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ window.init = () => {
1212
settings.init();
1313
source.init();
1414
graph.init();
15-
model.update(() => graph.update());
15+
model.update(() => graph.update(true));
1616

1717
};

src/static/js/model/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import sampleData from "../sample_output2.json";
22
import { getData, getOption } from "../source";
33
import { toggleLoader } from "../utils";
44

5+
let SIZE_CRITERIA = "frequency",
6+
FOLDING_CRITERIA = "frequency";
7+
58
function preprocess (graph) {
69
let zeroID = null;
710
graph.nodes.forEach(node => { if (!zeroID && node.id === 0) zeroID = node; });
@@ -16,7 +19,8 @@ function preprocess (graph) {
1619
}]
1720
});
1821
}
19-
graph.nodes.forEach(node => node.radius = 5 + Math.sqrt(node.entities[0].frequency / 4 || 25));
22+
graph.nodes.forEach(node =>
23+
node.radius = 5 + Math.sqrt(node.entities[0][SIZE_CRITERIA] / 4 || 25));
2024
console.log(graph);
2125
return graph;
2226
}

src/static/js/settings/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function toggleSettings (uiStateModel) {
66
d3.select("#settings").classed("active", uiStateModel.settingsToggled);
77
d3.select("#windows").classed("offScreen", uiStateModel.settingsToggled);
88
if (!uiStateModel.settingsToggled) {
9-
model.update(() => graph.update());
9+
model.update(() => graph.update(true));
1010
}
1111
}
1212

0 commit comments

Comments
 (0)