Skip to content

Commit 0743a99

Browse files
committed
[Bars] Option to display totals on top of each bar
Rename option Refactor code according to comments Contributes to plotly#85
1 parent 9493050 commit 0743a99

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

src/traces/bar/layout_attributes.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,18 @@ module.exports = {
6464
'the same location coordinate.'
6565
].join(' ')
6666
},
67-
displaytotal: {
67+
barshowtotal: {
6868
valType: 'boolean',
6969
dflt: false,
7070
role: 'style',
71+
editType: 'plot',
7172
description: 'Display the total value of each bar.'
7273
},
7374
totaltemplate: {
7475
valType: 'string',
7576
dflt: '%{total}',
7677
role: 'style',
78+
editType: 'plot',
7779
description: 'Template to display the total value of each bar.'
7880
},
7981
};

src/traces/bar/layout_defaults.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,6 @@ module.exports = function(layoutIn, layoutOut, fullData) {
5555

5656
coerce('bargap', (shouldBeGapless && !gappedAnyway) ? 0 : 0.2);
5757
coerce('bargroupgap');
58-
coerce('displaytotal');
59-
coerce('totaltemplate');
58+
var showTotal = coerce('barshowtotal');
59+
if(showTotal) coerce('totaltemplate');
6060
};

src/traces/bar/plot.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ function appendBarText(gd, plotinfo, bar, cd, i, x0, x1, y0, y1, opts, makeOnCom
298298
var isHorizontal = (trace.orientation === 'h');
299299

300300
var text = getText(fullLayout, cd, i, xa, ya);
301-
textPosition = getTextPosition(trace, i, fullLayout.displaytotal);
301+
textPosition = fullLayout.barshowtotal ? 'inside' : getTextPosition(trace, i);
302302

303303
// compute text position
304304
var inStackOrRelativeMode =
@@ -673,8 +673,7 @@ function getText(fullLayout, cd, index, xa, ya) {
673673
return helpers.coerceString(attributeText, value);
674674
}
675675

676-
function getTextPosition(trace, index, forceInside) {
677-
if(forceInside) return 'inside';
676+
function getTextPosition(trace, index) {
678677
var value = helpers.getValue(trace.textposition, index);
679678
return helpers.coerceEnumerated(attributeTextPosition, value);
680679
}

0 commit comments

Comments
 (0)