Skip to content

Commit 59999d3

Browse files
committed
Added stream of a single term on mouse over
Added stream of a single term on mouse over
1 parent fe78eba commit 59999d3

1 file changed

Lines changed: 51 additions & 1 deletion

File tree

index.html

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@
113113
styleGridlineNodes(gridlineNodes);
114114
//Main group
115115
var mainGroup = svg.append('g').attr('transform', 'translate(' + margins.left + ',' + margins.top + ')');
116+
var wordStreamG = mainGroup.append('g');
117+
116118
mainGroup.selectAll('path')
117119
.data(boxes.layers)
118120
.enter()
@@ -161,8 +163,56 @@
161163
//fill: function(d, i){return color(i);},
162164
fill: function(d, i){return termColorMap(d.text);},
163165
'text-anchor': 'middle',
164-
'alignment-baseline': 'middle'
166+
'alignment-baseline': 'middle',
167+
topic: function(d){return d.topic;}
165168
});
169+
//Try
170+
var prevColor;
171+
172+
mainGroup.selectAll('text').on('mouseenter', function(){
173+
var thisText = d3.select(this);
174+
prevColor = thisText.attr('fill');
175+
var text = thisText.text();
176+
var topic = thisText.attr('topic');
177+
var allTexts = mainGroup.selectAll('text').filter(t =>{
178+
return t.text === text && t.topic === topic;
179+
});
180+
allTexts.attr('fill', 'red');
181+
//Push all points
182+
var points = [];
183+
allTexts[0].forEach(t => {
184+
var data = t.__data__;
185+
var x = data.x;
186+
var y = data.y;
187+
var fontSize = data.fontSize;
188+
points.push({
189+
x: x,
190+
y0: y-(fontSize>>1),
191+
y: fontSize
192+
});
193+
});
194+
//Append stream
195+
wordStreamG.append('path')
196+
.datum(points)
197+
.attr('d', area)
198+
.style('fill', prevColor)
199+
.attr({
200+
'fill-opacity': 1,
201+
stroke: 'black',
202+
'stroke-width': 0.3
203+
});
204+
});
205+
mainGroup.selectAll('text').on('mouseout', function(){
206+
var thisText = d3.select(this);
207+
var text = thisText.text();
208+
var topic = thisText.attr('topic');
209+
var allTexts = mainGroup.selectAll('text').filter(t =>{
210+
return t.text === text && t.topic === topic;
211+
});
212+
allTexts.attr('fill', prevColor);
213+
wordStreamG.selectAll('path').remove();
214+
});
215+
166216
//Build the legends
167217
var legendGroup = svg.append('g').attr('transform', 'translate(' + margins.left + ',' + (height+margins.top) + ')');
168218
var legendNodes = legendGroup.selectAll('g').data(boxes.topics).enter().append('g')

0 commit comments

Comments
 (0)