MCPcopy Create free account
hub / github.com/bqplot/bqplot / draw_legend

Method draw_legend

js/src/Lines.ts:358–459  ·  view source on GitHub ↗
(elem, xDisp, yDisp, interXDisp, interYDisp: number)

Source from the content-addressed store, hash-verified

356 }
357
358 draw_legend(elem, xDisp, yDisp, interXDisp, interYDisp: number): number[] {
359 const curveLabels = this.model.get_labels();
360 const legendData = this.model.mark_data.map((d) => {
361 return { index: d.index, name: d.name, color: d.color };
362 });
363 this.legendEl = elem.selectAll('.legend' + this.uuid).data(legendData);
364
365 const rectDim = interYDisp * 0.8,
366 fillColors = this.model.get('fill_colors');
367
368 this.legendLine = d3
369 .line()
370 .curve(this.get_interpolation())
371 .x((d) => {
372 return d[0];
373 })
374 .y((d) => {
375 return d[1];
376 });
377
378 this.legendPathData = [
379 [0, rectDim],
380 [rectDim / 2, 0],
381 [rectDim, rectDim / 2],
382 ];
383
384 const legend = this.legendEl
385 .enter()
386 .append('g')
387 .attr('class', 'legend' + this.uuid)
388 .attr('transform', (d, i) => {
389 return 'translate(0, ' + (i * interYDisp + yDisp) + ')';
390 })
391 .on(
392 'mouseover',
393 _.bind(() => {
394 this.event_dispatcher('legend_mouse_over');
395 }, this)
396 )
397 .on(
398 'mouseout',
399 _.bind(() => {
400 this.event_dispatcher('legend_mouse_out');
401 }, this)
402 )
403 .on(
404 'click',
405 _.bind(() => {
406 this.event_dispatcher('legend_clicked');
407 }, this)
408 );
409
410 legend
411 .append('path')
412 .attr('class', 'line')
413 .attr('fill', 'none')
414 .attr('d', this.legendLine(this.legendPathData) + this.path_closure())
415 .style('stroke', (d, i) => {

Callers

nothing calls this directly

Calls 6

get_interpolationMethod · 0.95
path_closureMethod · 0.95
get_fill_colorMethod · 0.95
get_labelsMethod · 0.80
get_mark_colorMethod · 0.80
removeMethod · 0.45

Tested by

no test coverage detected