Skip to content

Handle special bar insidetext case on log size axes #3762

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/traces/bar/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;

Expand Down Expand Up @@ -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,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See

function toLog(v, clip) {
if(v > 0) return Math.log(v) / Math.LN10;
else if(v <= 0 && clip && ax.range && ax.range.length === 2) {
// clip NaN (ie past negative infinity) to LOG_CLIP axis
// length past the negative edge
var r0 = ax.range[0];
var r1 = ax.range[1];
return 0.5 * (r0 + r1 - 2 * LOG_CLIP * Math.abs(r0 - r1));
}
else return BADNUM;
}

for more info that true option.

// 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;
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
53 changes: 53 additions & 0 deletions test/image/mocks/bar-insidetext-log-size-axis.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}