|
108 | 108 | //Display the vertical gridline |
109 | 109 | var xGridlineScale = d3.scale.ordinal().domain(d3.range(0, dates.length+1)).rangeBands([0, width+width/boxes.data.length]); |
110 | 110 | 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('')); |
113 | 113 | styleGridlineNodes(gridlineNodes); |
114 | 114 | //Main group |
115 | 115 | var mainGroup = svg.append('g').attr('transform', 'translate(' + margins.left + ',' + margins.top + ')'); |
|
168 | 168 | }); |
169 | 169 | //Try |
170 | 170 | var prevColor; |
171 | | - |
| 171 | + //Highlight |
172 | 172 | mainGroup.selectAll('text').on('mouseenter', function(){ |
173 | 173 | var thisText = d3.select(this); |
174 | 174 | prevColor = thisText.attr('fill'); |
|
177 | 177 | var allTexts = mainGroup.selectAll('text').filter(t =>{ |
178 | 178 | return t.text === text && t.topic === topic; |
179 | 179 | }); |
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 | + }); |
181 | 212 | //Push all points |
182 | 213 | var points = []; |
183 | 214 | allTexts[0].forEach(t => { |
|
199 | 230 | .attr({ |
200 | 231 | 'fill-opacity': 1, |
201 | 232 | 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; |
211 | 237 | }); |
212 | | - allTexts.attr('fill', prevColor); |
213 | | - wordStreamG.selectAll('path').remove(); |
| 238 | + allOtherTexts.attr('visibility', 'hidden'); |
214 | 239 | }); |
215 | 240 |
|
216 | 241 | //Build the legends |
|
232 | 257 | }; |
233 | 258 | function styleAxis(axisNodes){ |
234 | 259 | axisNodes.selectAll('.domain').attr({ |
235 | | - fill: 'none', |
236 | | - 'stroke-width': 1, |
237 | | - stroke: 'black' |
| 260 | + fill: 'none' |
238 | 261 | }); |
239 | 262 | axisNodes.selectAll('.tick line').attr({ |
240 | 263 | fill: 'none', |
241 | | - 'stroke-width': 1, |
242 | | - stroke: 'black' |
243 | 264 | }); |
244 | 265 | } |
245 | 266 | function styleGridlineNodes(gridlineNodes){ |
|
0 commit comments