@@ -18,13 +18,13 @@ var svgTextUtils = require('../../lib/svg_text_utils');
18
18
var Color = require ( '../../components/color' ) ;
19
19
var Drawing = require ( '../../components/drawing' ) ;
20
20
var Registry = require ( '../../registry' ) ;
21
+ var tickText = require ( '../../plots/cartesian/axes' ) . tickText ;
21
22
22
23
var attributes = require ( './attributes' ) ;
23
24
var attributeText = attributes . text ;
24
25
var attributeTextPosition = attributes . textposition ;
25
26
var style = require ( './style' ) ;
26
27
var helpers = require ( './helpers' ) ;
27
- var pieHelpers = require ( '../pie/helpers' ) ;
28
28
29
29
// padding in pixels around text
30
30
var TEXTPAD = 3 ;
@@ -175,6 +175,9 @@ module.exports = function plot(gd, plotinfo, cdModule, traceLayer) {
175
175
} ;
176
176
177
177
function appendBarText ( gd , plotinfo , bar , calcTrace , i , x0 , x1 , y0 , y1 ) {
178
+ var xa = plotinfo . xaxis ;
179
+ var ya = plotinfo . yaxis ;
180
+
178
181
var fullLayout = gd . _fullLayout ;
179
182
var textPosition ;
180
183
@@ -199,7 +202,7 @@ function appendBarText(gd, plotinfo, bar, calcTrace, i, x0, x1, y0, y1) {
199
202
var trace = calcTrace [ 0 ] . trace ;
200
203
var orientation = trace . orientation ;
201
204
202
- var text = getText ( calcTrace , i , fullLayout ) ;
205
+ var text = getText ( calcTrace , i , xa , ya ) ;
203
206
textPosition = getTextPosition ( trace , i ) ;
204
207
205
208
// compute text position
@@ -225,7 +228,6 @@ function appendBarText(gd, plotinfo, bar, calcTrace, i, x0, x1, y0, y1) {
225
228
// so that we can get correctly inside text scaling
226
229
var di = bar . datum ( ) ;
227
230
if ( orientation === 'h' ) {
228
- var xa = plotinfo . xaxis ;
229
231
if ( xa . type === 'log' && di . s0 <= 0 ) {
230
232
if ( xa . range [ 0 ] < xa . range [ 1 ] ) {
231
233
x0 = 0 ;
@@ -234,7 +236,6 @@ function appendBarText(gd, plotinfo, bar, calcTrace, i, x0, x1, y0, y1) {
234
236
}
235
237
}
236
238
} else {
237
- var ya = plotinfo . yaxis ;
238
239
if ( ya . type === 'log' && di . s0 <= 0 ) {
239
240
if ( ya . range [ 0 ] < ya . range [ 1 ] ) {
240
241
y0 = ya . _length ;
@@ -470,14 +471,14 @@ function getTransform(textX, textY, targetX, targetY, scale, rotate) {
470
471
return transformTranslate + transformScale + transformRotate ;
471
472
}
472
473
473
- function getText ( calcTrace , index , fullLayout ) {
474
+ function getText ( calcTrace , index , xa , ya ) {
474
475
var trace = calcTrace [ 0 ] . trace ;
475
476
476
477
var value ;
477
478
if ( ! trace . textinfo || trace . textinfo === 'none' ) {
478
479
value = helpers . getValue ( trace . text , index ) ;
479
480
} else {
480
- value = calcTextinfo ( calcTrace , index , fullLayout ) ;
481
+ value = calcTextinfo ( calcTrace , index , xa , ya ) ;
481
482
}
482
483
483
484
return helpers . coerceString ( attributeText , value ) ;
@@ -488,19 +489,26 @@ function getTextPosition(trace, index) {
488
489
return helpers . coerceEnumerated ( attributeTextPosition , value ) ;
489
490
}
490
491
491
- function calcTextinfo ( calcTrace , index , fullLayout ) {
492
+ function calcTextinfo ( calcTrace , index , xa , ya ) {
492
493
var trace = calcTrace [ 0 ] . trace ;
494
+ var isHorizontal = ( trace . orientation === 'h' ) ;
495
+
496
+ function formatNumber ( v ) {
497
+ var sAxis = isHorizontal ? xa : ya ;
498
+ var hover = false ;
499
+ return tickText ( sAxis , + v , hover ) . text ;
500
+ }
501
+
493
502
var textinfo = trace . textinfo ;
494
503
var cdi = calcTrace [ index ] ;
495
504
496
- var separators = fullLayout . separators ;
497
505
var parts = textinfo . split ( '+' ) ;
498
506
var text = [ ] ;
499
507
500
508
var hasFlag = function ( flag ) { return parts . indexOf ( flag ) !== - 1 ; } ;
501
509
502
510
if ( hasFlag ( 'label' ) ) {
503
- if ( trace . orientation === 'h' ) {
511
+ if ( isHorizontal ) {
504
512
text . push ( trace . y [ index ] ) ;
505
513
} else {
506
514
text . push ( trace . x [ index ] ) ;
@@ -517,9 +525,9 @@ function calcTextinfo(calcTrace, index, fullLayout) {
517
525
var final = cdi . v ;
518
526
var initial = final - delta ;
519
527
520
- if ( hasFlag ( 'initial' ) ) text . push ( pieHelpers . formatPieValue ( initial , separators ) ) ;
521
- if ( hasFlag ( 'delta' ) ) text . push ( pieHelpers . formatPieValue ( delta , separators ) ) ;
522
- if ( hasFlag ( 'final' ) ) text . push ( pieHelpers . formatPieValue ( final , separators ) ) ;
528
+ if ( hasFlag ( 'initial' ) ) text . push ( formatNumber ( initial ) ) ;
529
+ if ( hasFlag ( 'delta' ) ) text . push ( formatNumber ( delta ) ) ;
530
+ if ( hasFlag ( 'final' ) ) text . push ( formatNumber ( final ) ) ;
523
531
}
524
532
525
533
return text . join ( '<br>' ) ;
0 commit comments