MCPcopy Index your code
hub / github.com/plotly/plotly.js / drawNumbers

Function drawNumbers

src/traces/indicator/plot.js:518–786  ·  view source on GitHub ↗
(gd, plotGroup, cd, opts)

Source from the content-addressed store, hash-verified

516}
517
518function drawNumbers(gd, plotGroup, cd, opts) {
519 var trace = cd[0].trace;
520
521 var numbersX = opts.numbersX;
522 var numbersY = opts.numbersY;
523 var numbersAlign = trace.align || 'center';
524 var numbersAnchor = anchor[numbersAlign];
525
526 var transitionOpts = opts.transitionOpts;
527 var onComplete = opts.onComplete;
528
529 var numbers = Lib.ensureSingle(plotGroup, 'g', 'numbers');
530 var bignumberbBox, deltabBox;
531 var numbersbBox;
532
533 var data = [];
534 if(trace._hasNumber) data.push('number');
535 if(trace._hasDelta) {
536 data.push('delta');
537 if(trace.delta.position === 'left') data.reverse();
538 }
539 var sel = numbers.selectAll('text').data(data);
540 sel.enter().append('text');
541 sel
542 .attr('text-anchor', function() {return numbersAnchor;})
543 .attr('class', function(d) { return d;})
544 .attr('x', null)
545 .attr('y', null)
546 .attr('dx', null)
547 .attr('dy', null);
548 sel.exit().remove();
549
550 // Function to override the number formatting used during transitions
551 function transitionFormat(valueformat, fmt, from, to) {
552 // For now, do not display SI prefix if start and end value do not have any
553 if(valueformat.match('s') && // If using SI prefix
554 (from >= 0 !== to >= 0) && // If sign change
555 (!fmt(from).slice(-1).match(SI_PREFIX) && !fmt(to).slice(-1).match(SI_PREFIX)) // Has no SI prefix
556 ) {
557 var transitionValueFormat = valueformat.slice().replace('s', 'f').replace(/\d+/, function(m) { return parseInt(m) - 1;});
558 var transitionAx = mockAxis(gd, {tickformat: transitionValueFormat});
559 return function(v) {
560 // Switch to fixed precision if number is smaller than one
561 if(Math.abs(v) < 1) return Axes.tickText(transitionAx, v).text;
562 return fmt(v);
563 };
564 } else {
565 return fmt;
566 }
567 }
568
569 function drawBignumber() {
570 var bignumberAx = mockAxis(gd, {tickformat: trace.number.valueformat}, trace._range);
571 bignumberAx.setScale();
572 Axes.prepTicks(bignumberAx);
573
574 var bignumberFmt = function(v) { return Axes.tickText(bignumberAx, v).text;};
575 var bignumberSuffix = trace.number.suffix;

Callers 1

plot.jsFile · 0.85

Calls 3

drawDeltaFunction · 0.85
drawBignumberFunction · 0.85
cacheFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…