()
| 261 | } |
| 262 | |
| 263 | render () { |
| 264 | this._parent.svg().select('g.dc-legend').remove(); |
| 265 | this._g = this._parent.svg().append('g') |
| 266 | .attr('class', 'dc-legend') |
| 267 | .attr('transform', `translate(${this._x},${this._y})`); |
| 268 | let legendables = this._parent.legendables(); |
| 269 | const filters = this._parent.filters(); |
| 270 | |
| 271 | if (this._maxItems !== undefined) { |
| 272 | legendables = legendables.slice(0, this._maxItems); |
| 273 | } |
| 274 | |
| 275 | const itemEnter = this._g.selectAll('g.dc-legend-item') |
| 276 | .data(legendables) |
| 277 | .enter() |
| 278 | .append('g') |
| 279 | .attr('class', 'dc-legend-item') |
| 280 | .on('mouseover', d3compat.eventHandler(d => { |
| 281 | this._parent.legendHighlight(d); |
| 282 | })) |
| 283 | .on('mouseout', d3compat.eventHandler(d => { |
| 284 | this._parent.legendReset(d); |
| 285 | })) |
| 286 | .on('click', d3compat.eventHandler(d => { |
| 287 | d.chart.legendToggle(d); |
| 288 | })); |
| 289 | |
| 290 | if (this._highlightSelected) { |
| 291 | itemEnter.classed(constants.SELECTED_CLASS, |
| 292 | d => filters.indexOf(d.name) !== -1); |
| 293 | } |
| 294 | |
| 295 | |
| 296 | this._g.selectAll('g.dc-legend-item') |
| 297 | .classed('fadeout', d => d.chart.isLegendableHidden(d)); |
| 298 | |
| 299 | if (legendables.some(pluck('dashstyle'))) { |
| 300 | itemEnter |
| 301 | .append('line') |
| 302 | .attr('x1', 0) |
| 303 | .attr('y1', this._itemHeight / 2) |
| 304 | .attr('x2', this._itemHeight) |
| 305 | .attr('y2', this._itemHeight / 2) |
| 306 | .attr('stroke-width', 2) |
| 307 | .attr('stroke-dasharray', pluck('dashstyle')) |
| 308 | .attr('stroke', pluck('color')); |
| 309 | } else { |
| 310 | itemEnter |
| 311 | .append('rect') |
| 312 | .attr('width', this._itemHeight) |
| 313 | .attr('height', this._itemHeight) |
| 314 | .attr('fill', d => d ? d.color : 'blue'); |
| 315 | } |
| 316 | |
| 317 | { |
| 318 | const self = this; |
| 319 | |
| 320 | itemEnter.append('text') |
no test coverage detected