MCPcopy Index your code
hub / github.com/bqplot/bqplot / updateLabels

Method updateLabels

js/src/Pie.ts:355–434  ·  view source on GitHub ↗
(animate?: boolean)

Source from the content-addressed store, hash-verified

353 }
354
355 private updateLabels(animate?: boolean) {
356 const that = this;
357 const animation_duration =
358 animate === true ? this.parent.model.get('animation_duration') : 0;
359
360 // Update labels
361 const display_labels = this.model.get('display_labels');
362 const display_values = this.model.get('display_values');
363
364 const values_format = d3.format(this.model.get('values_format'));
365
366 const labels = this.pieSelection
367 .select('.labels')
368 .selectAll('text')
369 .data(this.d3Pie(this.model.mark_data));
370
371 const labelsTransition = labels
372 .enter()
373 .append('text')
374 .classed('pie_label', true)
375 .attr('dy', '.35em')
376 .style('opacity', 0)
377 .each(function (d) {
378 this._current = d;
379 })
380 .merge(labels)
381 .transition('draw')
382 .duration(animation_duration)
383 .text((d) => {
384 if (d.data.label === '') {
385 return '';
386 }
387
388 if (display_values) {
389 return d.data.label + ': ' + values_format(d.data.size);
390 }
391
392 return d.data.label;
393 })
394 .style('font-weight', this.model.get('font_weight'))
395 .style('font-size', this.model.get('font_size'))
396 .style('opacity', (d) =>
397 display_labels === 'none' || d.value == 0 ? 0 : 1
398 );
399
400 const color = this.model.get('label_color');
401 if (color !== undefined) {
402 labelsTransition.style('fill', color);
403 }
404
405 if (display_labels === 'inside') {
406 labelsTransition
407 .attr('transform', (d) => 'translate(' + this.arc.centroid(d) + ')')
408 .style('text-anchor', 'middle');
409 } else if (display_labels === 'outside') {
410 labelsTransition
411 .attrTween('transform', function (d) {
412 const interpolate = d3.interpolate(this._current, d);

Callers 2

create_listenersMethod · 0.95
drawMethod · 0.95

Calls 2

midAngleLocationMethod · 0.80
removeMethod · 0.45

Tested by

no test coverage detected