Skip to content

Commit 5d051e7

Browse files
authored
Merge pull request #3762 from plotly/fix-bar-inside-text-log-size-axes
Handle special bar insidetext case on log size axes
2 parents d574efb + 490c8dc commit 5d051e7

File tree

3 files changed

+70
-2
lines changed

3 files changed

+70
-2
lines changed

src/traces/bar/plot.js

+17-2
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ module.exports = function plot(gd, plotinfo, cdModule, traceLayer) {
162162
.attr('d', isBlank ? 'M0,0Z' : 'M' + x0 + ',' + y0 + 'V' + y1 + 'H' + x1 + 'V' + y0 + 'Z')
163163
.call(Drawing.setClipUrl, plotinfo.layerClipId, gd);
164164

165-
appendBarText(gd, bar, cd, i, x0, x1, y0, y1);
165+
appendBarText(gd, plotinfo, bar, cd, i, x0, x1, y0, y1);
166166

167167
if(plotinfo.layerClipId) {
168168
Drawing.hideOutsideRangePoint(di, bar.select('text'), xa, ya, trace.xcalendar, trace.ycalendar);
@@ -179,7 +179,7 @@ module.exports = function plot(gd, plotinfo, cdModule, traceLayer) {
179179
Registry.getComponentMethod('errorbars', 'plot')(gd, bartraces, plotinfo);
180180
};
181181

182-
function appendBarText(gd, bar, calcTrace, i, x0, x1, y0, y1) {
182+
function appendBarText(gd, plotinfo, bar, calcTrace, i, x0, x1, y0, y1) {
183183
var fullLayout = gd._fullLayout;
184184
var textPosition;
185185

@@ -226,6 +226,21 @@ function appendBarText(gd, bar, calcTrace, i, x0, x1, y0, y1) {
226226
var insideTextFont = style.getInsideTextFont(trace, i, layoutFont, barColor);
227227
var outsideTextFont = style.getOutsideTextFont(trace, i, layoutFont);
228228

229+
// Special case: don't use the c2p(v, true) value on log size axes,
230+
// so that we can get correctly inside text scaling
231+
var di = bar.datum();
232+
if(orientation === 'h') {
233+
var xa = plotinfo.xaxis;
234+
if(xa.type === 'log' && di.s0 <= 0) {
235+
x0 = xa._length;
236+
}
237+
} else {
238+
var ya = plotinfo.yaxis;
239+
if(ya.type === 'log' && di.s0 <= 0) {
240+
y0 = ya._length;
241+
}
242+
}
243+
229244
// padding excluded
230245
var barWidth = Math.abs(x1 - x0) - 2 * TEXTPAD;
231246
var barHeight = Math.abs(y1 - y0) - 2 * TEXTPAD;
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"data": [
3+
{
4+
"x": [
5+
"giraffes",
6+
"orangutans",
7+
"monkeys"
8+
],
9+
"y": [
10+
50,
11+
14,
12+
23
13+
],
14+
"name": "SF Zoo",
15+
"type": "bar",
16+
"text": "SF Zoo",
17+
"textposition": [
18+
"none",
19+
"auto",
20+
"none"
21+
]
22+
},
23+
{
24+
"x": [
25+
"giraffes",
26+
"orangutans",
27+
"monkeys"
28+
],
29+
"y": [
30+
12,
31+
180,
32+
29
33+
],
34+
"name": "LA Zoo",
35+
"type": "bar",
36+
"text": "LA Zoo",
37+
"textposition": [
38+
"inside",
39+
"none",
40+
"none"
41+
]
42+
}
43+
],
44+
"layout": {
45+
"barmode": "stack",
46+
"font": {
47+
"size": 16
48+
},
49+
"yaxis": {
50+
"type": "log"
51+
}
52+
}
53+
}

0 commit comments

Comments
 (0)