diff --git a/src/traces/bar/plot.js b/src/traces/bar/plot.js index 6f281d90d1e..d013f7ec46f 100644 --- a/src/traces/bar/plot.js +++ b/src/traces/bar/plot.js @@ -162,7 +162,7 @@ module.exports = function plot(gd, plotinfo, cdModule, traceLayer) { .attr('d', isBlank ? 'M0,0Z' : 'M' + x0 + ',' + y0 + 'V' + y1 + 'H' + x1 + 'V' + y0 + 'Z') .call(Drawing.setClipUrl, plotinfo.layerClipId, gd); - appendBarText(gd, bar, cd, i, x0, x1, y0, y1); + appendBarText(gd, plotinfo, bar, cd, i, x0, x1, y0, y1); if(plotinfo.layerClipId) { Drawing.hideOutsideRangePoint(di, bar.select('text'), xa, ya, trace.xcalendar, trace.ycalendar); @@ -179,7 +179,7 @@ module.exports = function plot(gd, plotinfo, cdModule, traceLayer) { Registry.getComponentMethod('errorbars', 'plot')(gd, bartraces, plotinfo); }; -function appendBarText(gd, bar, calcTrace, i, x0, x1, y0, y1) { +function appendBarText(gd, plotinfo, bar, calcTrace, i, x0, x1, y0, y1) { var fullLayout = gd._fullLayout; var textPosition; @@ -226,6 +226,21 @@ function appendBarText(gd, bar, calcTrace, i, x0, x1, y0, y1) { var insideTextFont = style.getInsideTextFont(trace, i, layoutFont, barColor); var outsideTextFont = style.getOutsideTextFont(trace, i, layoutFont); + // Special case: don't use the c2p(v, true) value on log size axes, + // so that we can get correctly inside text scaling + var di = bar.datum(); + if(orientation === 'h') { + var xa = plotinfo.xaxis; + if(xa.type === 'log' && di.s0 <= 0) { + x0 = xa._length; + } + } else { + var ya = plotinfo.yaxis; + if(ya.type === 'log' && di.s0 <= 0) { + y0 = ya._length; + } + } + // padding excluded var barWidth = Math.abs(x1 - x0) - 2 * TEXTPAD; var barHeight = Math.abs(y1 - y0) - 2 * TEXTPAD; diff --git a/test/image/baselines/bar-insidetext-log-size-axis.png b/test/image/baselines/bar-insidetext-log-size-axis.png new file mode 100644 index 00000000000..82f44542cc4 Binary files /dev/null and b/test/image/baselines/bar-insidetext-log-size-axis.png differ diff --git a/test/image/mocks/bar-insidetext-log-size-axis.json b/test/image/mocks/bar-insidetext-log-size-axis.json new file mode 100644 index 00000000000..742b769fc45 --- /dev/null +++ b/test/image/mocks/bar-insidetext-log-size-axis.json @@ -0,0 +1,53 @@ +{ + "data": [ + { + "x": [ + "giraffes", + "orangutans", + "monkeys" + ], + "y": [ + 50, + 14, + 23 + ], + "name": "SF Zoo", + "type": "bar", + "text": "SF Zoo", + "textposition": [ + "none", + "auto", + "none" + ] + }, + { + "x": [ + "giraffes", + "orangutans", + "monkeys" + ], + "y": [ + 12, + 180, + 29 + ], + "name": "LA Zoo", + "type": "bar", + "text": "LA Zoo", + "textposition": [ + "inside", + "none", + "none" + ] + } + ], + "layout": { + "barmode": "stack", + "font": { + "size": 16 + }, + "yaxis": { + "type": "log" + } + } +}