|
113 | 113 | styleGridlineNodes(gridlineNodes); |
114 | 114 | //Main group |
115 | 115 | var mainGroup = svg.append('g').attr('transform', 'translate(' + margins.left + ',' + margins.top + ')'); |
| 116 | + var wordStreamG = mainGroup.append('g'); |
| 117 | + |
116 | 118 | mainGroup.selectAll('path') |
117 | 119 | .data(boxes.layers) |
118 | 120 | .enter() |
|
161 | 163 | //fill: function(d, i){return color(i);}, |
162 | 164 | fill: function(d, i){return termColorMap(d.text);}, |
163 | 165 | 'text-anchor': 'middle', |
164 | | - 'alignment-baseline': 'middle' |
| 166 | + 'alignment-baseline': 'middle', |
| 167 | + topic: function(d){return d.topic;} |
165 | 168 | }); |
| 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 | + |
166 | 216 | //Build the legends |
167 | 217 | var legendGroup = svg.append('g').attr('transform', 'translate(' + margins.left + ',' + (height+margins.top) + ')'); |
168 | 218 | var legendNodes = legendGroup.selectAll('g').data(boxes.topics).enter().append('g') |
|
0 commit comments