MCPcopy
hub / github.com/dc-js/dc.js / render

Method render

src/charts/legend.js:263–354  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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')

Callers 15

renderAllFunction · 0.45
_preprocessDataMethod · 0.45
startOrdinalFunction · 0.45
row-chart-spec.jsFile · 0.45
heatmap-spec.jsFile · 0.45
legend-spec.jsFile · 0.45
buildPieChartFunction · 0.45
buildLineChartFunction · 0.45

Calls 14

pluckFunction · 0.90
selectMethod · 0.80
svgMethod · 0.80
filtersMethod · 0.80
onMethod · 0.80
dataMethod · 0.80
selectAllMethod · 0.80
_legendItemHeightMethod · 0.80
legendablesMethod · 0.45
legendHighlightMethod · 0.45
legendResetMethod · 0.45

Tested by

no test coverage detected