Skip to content

Commit 5b8f8bb

Browse files
committed
brush top vis when switching root
1 parent d608e21 commit 5b8f8bb

File tree

3 files changed

+37
-25
lines changed

3 files changed

+37
-25
lines changed

js/GraphLayout.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class GraphLayout {
103103
if (word !== source) {
104104
const newNode = addNode(word, depth + 1, node);
105105

106-
if (node.arrowDirections[i] === 1) {
106+
if (node.arrowDirections[i] === -1) {
107107
newNode.receivesArrow = true;
108108
}
109109

@@ -218,6 +218,18 @@ class GraphLayout {
218218
});
219219
}
220220
drawNodes(root, i, el) {
221+
function handleNodeClick(d) {
222+
let newArray = this.words.slice();
223+
let word = newArray.splice(i, 1, d.node)[0];
224+
if (word instanceof Word) {
225+
word.toggleHighlight(false);
226+
}
227+
if (d.node instanceof Word) {
228+
d.node.toggleHighlight(true);
229+
}
230+
this.graph(newArray);
231+
}
232+
221233
let node = el.selectAll('.node')
222234
.data(root.descendants());
223235

@@ -247,17 +259,13 @@ class GraphLayout {
247259

248260
nodeMerge.select('path')
249261
.attr('d', d3.symbol()
250-
.type((d) => d.data.receivesArrow ? d3.symbolTriangle : (d.data.type === 'Word' ? d3.symbolSquare : d3.symbolCircle))
262+
.type((d) => d.data.type === 'Word' ? (d.data.receivesArrow ? d3.symbolTriangle : d3.symbolSquare) : d3.symbolCircle)
251263
.size(20)
252264
)
253-
.attr('transform', (d) => d.data.receivesArrow ? 'rotate(-30)' : 'rotate(45)')
265+
.attr('transform', (d) => d.data.receivesArrow && d.data.type === 'Word' ? 'rotate(-30)' : 'rotate(45)')
254266
.attr('stroke', 'grey')
255267
.attr('fill', (d) => d.data.type === 'Word' ? 'black' : 'white')
256-
.on('click', (d) => {
257-
let newArray = this.words.slice();
258-
newArray.splice(i, 1, d.data.node);
259-
this.graph(newArray);
260-
});
268+
.on('click', (d) => handleNodeClick.bind(this)(d.data));
261269

262270
nodeMerge.select('text')
263271
.text((d) => d.data.name)
@@ -308,11 +316,7 @@ class GraphLayout {
308316
.attr('transform', (d, i) => 'translate(-30,' + (-20 * i - 20) + ')');
309317

310318
inMerge.select('circle')
311-
.on('click', (d) => {
312-
let newArray = this.words.slice();
313-
newArray.splice(i, 1, d.node);
314-
this.graph(newArray);
315-
});
319+
.on('click', (d) => handleNodeClick.bind(this)(d));
316320

317321
inMerge.select('path')
318322
.attr('d', (d, i) => {

js/annotate.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,24 @@ class Word {
288288
return [].concat(this.parentsL, this.parentsC, this.parentsR);
289289
}
290290

291+
toggleHighlight(select) {
292+
if (select === undefined) {
293+
this.isSelected = !this.isSelected;
294+
}
295+
else {
296+
this.isSelected = select;
297+
}
298+
299+
let style;
300+
if (this.isSelected) {
301+
style = this.isHovered ? "hoverAndSelect" : "select";
302+
}
303+
else {
304+
style = this.isHovered ? "hover" : "style";
305+
}
306+
this.underneathRect.style(styles.wordFill[style]);
307+
}
308+
291309
toString() {
292310
return this.id;
293311
}

js/render.js

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -489,20 +489,10 @@ function drawWord(word) {
489489
setUpWordDraggable(word);
490490
setupMouseOverInteractions(word);
491491

492-
word.aboveRect.dblclick(function() {
493-
word.isSelected = !word.isSelected;
494-
495-
if (word.isSelected) {
496-
style = word.isHovered ? "hoverAndSelect" : "select";
497-
}
498-
else {
499-
style = word.isHovered ? "hover" : "style";
500-
}
501-
word.underneathRect.style(styles.wordFill[style]);
502-
492+
word.aboveRect.dblclick( () => {
493+
word.toggleHighlight();
503494
draw.fire('wordSelected', { arbitrary: word });
504495
});
505-
506496
}
507497

508498

0 commit comments

Comments
 (0)