Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9984e90

Browse files
authored
Merge pull request plotly#6070 from plotly/histogram-format-x-y-texttemplate
Correct formatted x/y `texttempate` for `histogram` trace
2 parents 19efc29 + 1a4637c commit 9984e90

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

src/traces/bar/plot.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,7 @@ function calcTexttemplate(fullLayout, cd, index, xa, ya) {
629629
var trace = cd[0].trace;
630630
var texttemplate = Lib.castOption(trace, index, 'texttemplate');
631631
if(!texttemplate) return '';
632+
var isHistogram = (trace.type === 'histogram');
632633
var isWaterfall = (trace.type === 'waterfall');
633634
var isFunnel = (trace.type === 'funnel');
634635
var isHorizontal = trace.orientation === 'h';
@@ -670,10 +671,10 @@ function calcTexttemplate(fullLayout, cd, index, xa, ya) {
670671
var pt = {};
671672
appendArrayPointValue(pt, trace, cdi.i);
672673

673-
if(pt.x === undefined) pt.x = isHorizontal ? obj.value : obj.label;
674-
if(pt.y === undefined) pt.y = isHorizontal ? obj.label : obj.value;
675-
if(pt.xLabel === undefined) pt.xLabel = isHorizontal ? obj.valueLabel : obj.labelLabel;
676-
if(pt.yLabel === undefined) pt.yLabel = isHorizontal ? obj.labelLabel : obj.valueLabel;
674+
if(isHistogram || pt.x === undefined) pt.x = isHorizontal ? obj.value : obj.label;
675+
if(isHistogram || pt.y === undefined) pt.y = isHorizontal ? obj.label : obj.value;
676+
if(isHistogram || pt.xLabel === undefined) pt.xLabel = isHorizontal ? obj.valueLabel : obj.labelLabel;
677+
if(isHistogram || pt.yLabel === undefined) pt.yLabel = isHorizontal ? obj.labelLabel : obj.valueLabel;
677678

678679
if(isWaterfall) {
679680
obj.delta = +cdi.rawS || cdi.s;

test/image/baselines/hist_summed.png

660 Bytes
Loading

test/image/mocks/hist_summed.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"Oranges",
1717
"Bananas"
1818
],
19-
"texttemplate": "%{value}<br>%{label}",
19+
"texttemplate": "%{y:.1f}<br>%{x}",
2020
"type": "histogram"
2121
}
2222
],

0 commit comments

Comments
 (0)