Skip to content

Commit 7c4d51f

Browse files
committed
Some minor fixes about term streams
Some minor fixes about term streams
1 parent 59999d3 commit 7c4d51f

1 file changed

Lines changed: 41 additions & 20 deletions

File tree

index.html

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@
108108
//Display the vertical gridline
109109
var xGridlineScale = d3.scale.ordinal().domain(d3.range(0, dates.length+1)).rangeBands([0, width+width/boxes.data.length]);
110110
var xGridlinesAxis = d3.svg.axis().orient('bottom').scale(xGridlineScale);
111-
var xGridlinesGroup = svg.append('g').attr('transform', 'translate(' + (margins.left-width/boxes.data.length/2) + ',' + (height+margins.top + axisPadding+legendHeight) + ')');
112-
var gridlineNodes = xGridlinesGroup.call(xGridlinesAxis.tickSize(-height-axisPadding-legendHeight, 0, 0).tickFormat(''));
111+
var xGridlinesGroup = svg.append('g').attr('transform', 'translate(' + (margins.left-width/boxes.data.length/2) + ',' + (height+margins.top + axisPadding+legendHeight+margins.bottom) + ')');
112+
var gridlineNodes = xGridlinesGroup.call(xGridlinesAxis.tickSize(-height-axisPadding-legendHeight-margins.bottom, 0, 0).tickFormat(''));
113113
styleGridlineNodes(gridlineNodes);
114114
//Main group
115115
var mainGroup = svg.append('g').attr('transform', 'translate(' + margins.left + ',' + margins.top + ')');
@@ -168,7 +168,7 @@
168168
});
169169
//Try
170170
var prevColor;
171-
171+
//Highlight
172172
mainGroup.selectAll('text').on('mouseenter', function(){
173173
var thisText = d3.select(this);
174174
prevColor = thisText.attr('fill');
@@ -177,7 +177,38 @@
177177
var allTexts = mainGroup.selectAll('text').filter(t =>{
178178
return t.text === text && t.topic === topic;
179179
});
180-
allTexts.attr('fill', 'red');
180+
allTexts.attr({
181+
stroke: 'red',
182+
'stroke-width': 1
183+
});
184+
});
185+
mainGroup.selectAll('text').on('mouseout', function(){
186+
var thisText = d3.select(this);
187+
var text = thisText.text();
188+
var topic = thisText.attr('topic');
189+
var allTexts = mainGroup.selectAll('text').filter(t =>{
190+
return t.text === text && t.topic === topic;
191+
});
192+
allTexts.attr({
193+
stroke: 'none',
194+
'stroke-width': '0'
195+
});
196+
wordStreamG.selectAll('path').remove();
197+
//Set the other text visibles
198+
//Hide all other texts
199+
var allOtherTexts = mainGroup.selectAll('text').filter(t =>{
200+
return t.text != text && t.topic === topic;
201+
});
202+
allOtherTexts.attr('visibility', 'visible');
203+
});
204+
//Click
205+
mainGroup.selectAll('text').on('click', 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+
});
181212
//Push all points
182213
var points = [];
183214
allTexts[0].forEach(t => {
@@ -199,18 +230,12 @@
199230
.attr({
200231
'fill-opacity': 1,
201232
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;
233+
'stroke-width': 0.3});
234+
//Hide all other texts
235+
var allOtherTexts = mainGroup.selectAll('text').filter(t =>{
236+
return t.text != text && t.topic === topic;
211237
});
212-
allTexts.attr('fill', prevColor);
213-
wordStreamG.selectAll('path').remove();
238+
allOtherTexts.attr('visibility', 'hidden');
214239
});
215240

216241
//Build the legends
@@ -232,14 +257,10 @@
232257
};
233258
function styleAxis(axisNodes){
234259
axisNodes.selectAll('.domain').attr({
235-
fill: 'none',
236-
'stroke-width': 1,
237-
stroke: 'black'
260+
fill: 'none'
238261
});
239262
axisNodes.selectAll('.tick line').attr({
240263
fill: 'none',
241-
'stroke-width': 1,
242-
stroke: 'black'
243264
});
244265
}
245266
function styleGridlineNodes(gridlineNodes){

0 commit comments

Comments
 (0)