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

Skip to content

Commit db95a97

Browse files
authored
Merge pull request plotly#6069 from plotly/histogram-x-y-texttemplate
Fix x/y `texttemplate` for `histogram`, `bar`, `funnel` and `waterfall` traces
2 parents 7433f7a + d3e168a commit db95a97

File tree

9 files changed

+15
-4
lines changed

9 files changed

+15
-4
lines changed

src/traces/bar/plot.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,10 +631,11 @@ function calcTexttemplate(fullLayout, cd, index, xa, ya) {
631631
if(!texttemplate) return '';
632632
var isWaterfall = (trace.type === 'waterfall');
633633
var isFunnel = (trace.type === 'funnel');
634+
var isHorizontal = trace.orientation === 'h';
634635

635636
var pLetter, pAxis;
636637
var vLetter, vAxis;
637-
if(trace.orientation === 'h') {
638+
if(isHorizontal) {
638639
pLetter = 'y';
639640
pAxis = ya;
640641
vLetter = 'x';
@@ -669,6 +670,11 @@ function calcTexttemplate(fullLayout, cd, index, xa, ya) {
669670
var pt = {};
670671
appendArrayPointValue(pt, trace, cdi.i);
671672

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;
677+
672678
if(isWaterfall) {
673679
obj.delta = +cdi.rawS || cdi.s;
674680
obj.deltaLabel = formatNumber(obj.delta);

src/traces/histogram/calc.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ var getBinSpanLabelRound = require('./bin_label_vals');
1515
function calc(gd, trace) {
1616
var pos = [];
1717
var size = [];
18-
var pa = Axes.getFromId(gd, trace.orientation === 'h' ? trace.yaxis : trace.xaxis);
19-
var mainData = trace.orientation === 'h' ? 'y' : 'x';
18+
var isHorizontal = trace.orientation === 'h';
19+
var pa = Axes.getFromId(gd, isHorizontal ? trace.yaxis : trace.xaxis);
20+
var mainData = isHorizontal ? 'y' : 'x';
2021
var counterData = {x: 'y', y: 'x'}[mainData];
2122
var calendar = trace[mainData + 'calendar'];
2223
var cumulativeSpec = trace.cumulative;
Loading
3.55 KB
Loading
4.77 KB
Loading

test/image/mocks/bar-marker-line-colorscales.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"data": [
33
{
4+
"texttemplate": "%{x}",
45
"marker": {
56
"color": [
67
0,

test/image/mocks/bar_marker_array.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"data": [
33
{
4+
"texttemplate": "%{y:(}",
5+
"textfont": { "size": 32 },
46
"x": [
57
1,
68
2,

test/image/mocks/date_histogram.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"data": [
33
{
4+
"texttemplate": "<b>%{y:.1f}</b><br><br>%{x}",
45
"x": [
56
"2012-01-01 00:00:00",
67
"2012-02-01 00:00:00",

test/image/mocks/histogram_colorscale.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"cmax": 5
1414
},
1515
"x": [ 0, 1, 1, 2, 2, 2, 3, 3, 4 ],
16-
"texttemplate": "%{value}",
16+
"texttemplate": "%{y}",
1717
"textposition": "inside",
1818
"textfont": {
1919
"size": 64

0 commit comments

Comments
 (0)