()
| 35 | } |
| 36 | |
| 37 | render () { |
| 38 | this._defaultLegendItemCssClass = this._horizontal ? this._legendItemCssClassHorizontal : this._legendItemCssClassVertical; |
| 39 | this._container.select(`div.${this._htmlLegendDivCssClass}`).remove(); |
| 40 | |
| 41 | const container = this._container.append('div').attr('class', this._htmlLegendDivCssClass); |
| 42 | container.attr('style', `max-width:${this._container.nodes()[0].style.width}`); |
| 43 | |
| 44 | let legendables = this._parent.legendables(); |
| 45 | const filters = this._parent.filters(); |
| 46 | |
| 47 | if (this._maxItems !== undefined) { |
| 48 | legendables = legendables.slice(0, this._maxItems); |
| 49 | } |
| 50 | |
| 51 | const legendItemClassName = this._legendItemClass ? this._legendItemClass : this._defaultLegendItemCssClass; |
| 52 | |
| 53 | const itemEnter = container.selectAll(`div.${legendItemClassName}`) |
| 54 | .data(legendables).enter() |
| 55 | .append('div') |
| 56 | .classed(legendItemClassName, true) |
| 57 | .on('mouseover', d3compat.eventHandler(d => this._parent.legendHighlight(d))) |
| 58 | .on('mouseout', d3compat.eventHandler(d => this._parent.legendReset(d))) |
| 59 | .on('click', d3compat.eventHandler(d => this._parent.legendToggle(d))); |
| 60 | |
| 61 | if (this._highlightSelected) { |
| 62 | itemEnter.classed(constants.SELECTED_CLASS, d => filters.indexOf(d.name) !== -1); |
| 63 | } |
| 64 | |
| 65 | itemEnter.append('span') |
| 66 | .attr('class', 'dc-legend-item-color') |
| 67 | .style('background-color', pluck('color')); |
| 68 | |
| 69 | itemEnter.append('span') |
| 70 | .attr('class', 'dc-legend-item-label') |
| 71 | .classed('dc-tabbable', this._keyboardAccessible) |
| 72 | .attr('title', this._legendText) |
| 73 | .text(this._legendText); |
| 74 | |
| 75 | if (this._keyboardAccessible) { |
| 76 | this._makeLegendKeyboardAccessible(); |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Set the container selector for the legend widget. Required. |
nothing calls this directly
no test coverage detected