diff --git a/src/traces/bar/cross_trace_calc.js b/src/traces/bar/cross_trace_calc.js index a50a4d41228..628bfb1396d 100644 --- a/src/traces/bar/cross_trace_calc.js +++ b/src/traces/bar/cross_trace_calc.js @@ -501,7 +501,7 @@ function setBaseAndTop(sa, sieve) { var calcTrace = calcTraces[i]; var fullTrace = calcTrace[0].trace; var pts = []; - var allBaseAboveZero = true; + var tozero = false; for(var j = 0; j < calcTrace.length; j++) { var bar = calcTrace[j]; @@ -512,13 +512,13 @@ function setBaseAndTop(sa, sieve) { pts.push(top); if(bar.hasB) pts.push(base); - if(!bar.hasB || !(bar.b > 0 && bar.s > 0)) { - allBaseAboveZero = false; + if(!bar.hasB || !bar.b) { + tozero = true; } } fullTrace._extremes[sa._id] = Axes.findExtremes(sa, pts, { - tozero: !allBaseAboveZero, + tozero: tozero, padded: true }); } @@ -667,7 +667,7 @@ function normalizeBars(sa, sieve, opts) { var calcTrace = calcTraces[i]; var fullTrace = calcTrace[0].trace; var pts = []; - var allBaseAboveZero = true; + var tozero = false; var padded = false; for(var j = 0; j < calcTrace.length; j++) { @@ -690,14 +690,14 @@ function normalizeBars(sa, sieve, opts) { padded = padded || needsPadding(base); } - if(!bar.hasB || !(bar.b > 0 && bar.s > 0)) { - allBaseAboveZero = false; + if(!bar.hasB || !bar.b) { + tozero = true; } } } fullTrace._extremes[sa._id] = Axes.findExtremes(sa, pts, { - tozero: !allBaseAboveZero, + tozero: tozero, padded: padded }); } diff --git a/test/image/baselines/bar-like_traces_no-tozero.png b/test/image/baselines/bar-like_traces_no-tozero.png new file mode 100644 index 00000000000..5b2944a3e14 Binary files /dev/null and b/test/image/baselines/bar-like_traces_no-tozero.png differ diff --git a/test/image/baselines/bar-like_traces_no-tozero_negative.png b/test/image/baselines/bar-like_traces_no-tozero_negative.png new file mode 100644 index 00000000000..bf9d5044c18 Binary files /dev/null and b/test/image/baselines/bar-like_traces_no-tozero_negative.png differ diff --git a/test/image/baselines/bar-like_traces_no-tozero_stack.png b/test/image/baselines/bar-like_traces_no-tozero_stack.png new file mode 100644 index 00000000000..9c67d2ee6f1 Binary files /dev/null and b/test/image/baselines/bar-like_traces_no-tozero_stack.png differ diff --git a/test/image/baselines/bar-like_traces_tozero.png b/test/image/baselines/bar-like_traces_tozero.png new file mode 100644 index 00000000000..483264a31c4 Binary files /dev/null and b/test/image/baselines/bar-like_traces_tozero.png differ diff --git a/test/image/baselines/bar_attrs_group.png b/test/image/baselines/bar_attrs_group.png index 70303cdec40..66ae212f49a 100644 Binary files a/test/image/baselines/bar_attrs_group.png and b/test/image/baselines/bar_attrs_group.png differ diff --git a/test/image/baselines/bar_attrs_overlay.png b/test/image/baselines/bar_attrs_overlay.png index 63e845af88a..d3650cdfeea 100644 Binary files a/test/image/baselines/bar_attrs_overlay.png and b/test/image/baselines/bar_attrs_overlay.png differ diff --git a/test/image/mocks/bar-like_traces_no-tozero.json b/test/image/mocks/bar-like_traces_no-tozero.json new file mode 100644 index 00000000000..b9b30af11fb --- /dev/null +++ b/test/image/mocks/bar-like_traces_no-tozero.json @@ -0,0 +1,164 @@ +{ + "data": [ + { + "xaxis": "x", + "yaxis": "y", + "type": "bar", + "orientation": "h", + "y": [ + "A", + "B", + "C" + ], + "x": [ + 1, + -1, + 1 + ], + "text": [ + "+1", + "-1", + "+1" + ], + "textposition": "inside", + "insidetextanchor": "middle", + "base": 10 + }, + { + "xaxis": "x2", + "yaxis": "y2", + "type": "bar", + "x": [ + "E", + "F", + "G" + ], + "y": [ + 1, + -1, + 1 + ], + "text": [ + "+1", + "-1", + "+1" + ], + "textposition": "inside", + "insidetextanchor": "middle", + "base": 10 + }, + { + "xaxis": "x3", + "yaxis": "y3", + "type": "waterfall", + "x": [ + "E", + "F", + "G" + ], + "y": [ + 1, + -2, + 1 + ], + "text": [ + "+1", + "-2", + "+1" + ], + "textposition": "inside", + "insidetextanchor": "middle", + "base": 10 + }, + { + "xaxis": "x4", + "yaxis": "y4", + "type": "waterfall", + "orientation": "h", + "y": [ + "A", + "B", + "C" + ], + "x": [ + 1, + -2, + 1 + ], + "text": [ + "+1", + "-2", + "+1" + ], + "textposition": "inside", + "insidetextanchor": "middle", + "base": 10 + } + ], + "layout": { + "width": 400, + "height": 400, + "template": { + "layout": { + "showlegend": false, + "title": { + "text": "non-zero autorange with
base and negative size" + }, + "xaxis": { + "domain": [ + 0, + 0.45 + ] + }, + "yaxis": { + "domain": [ + 0, + 0.45 + ] + }, + "xaxis2": { + "anchor": "y2", + "domain": [ + 0.55, + 1 + ] + }, + "yaxis2": { + "anchor": "x2", + "domain": [ + 0.55, + 1 + ] + }, + "xaxis3": { + "anchor": "y3", + "domain": [ + 0, + 0.45 + ] + }, + "yaxis3": { + "anchor": "x3", + "domain": [ + 0.55, + 1 + ] + }, + "xaxis4": { + "anchor": "y4", + "domain": [ + 0.55, + 1 + ] + }, + "yaxis4": { + "anchor": "x4", + "domain": [ + 0, + 0.45 + ] + } + } + } + } +} diff --git a/test/image/mocks/bar-like_traces_no-tozero_negative.json b/test/image/mocks/bar-like_traces_no-tozero_negative.json new file mode 100644 index 00000000000..432232d68fe --- /dev/null +++ b/test/image/mocks/bar-like_traces_no-tozero_negative.json @@ -0,0 +1,164 @@ +{ + "data": [ + { + "xaxis": "x", + "yaxis": "y", + "type": "bar", + "orientation": "h", + "y": [ + "A", + "B", + "C" + ], + "x": [ + 1, + -1, + 1 + ], + "text": [ + "+1", + "-1", + "+1" + ], + "textposition": "inside", + "insidetextanchor": "middle", + "base": [-10, -10, -10] + }, + { + "xaxis": "x2", + "yaxis": "y2", + "type": "bar", + "x": [ + "E", + "F", + "G" + ], + "y": [ + 1, + -1, + 1 + ], + "text": [ + "+1", + "-1", + "+1" + ], + "textposition": "inside", + "insidetextanchor": "middle", + "base": [-10, -10, -10] + }, + { + "xaxis": "x3", + "yaxis": "y3", + "type": "waterfall", + "x": [ + "E", + "F", + "G" + ], + "y": [ + 1, + -2, + 1 + ], + "text": [ + "+1", + "-2", + "+1" + ], + "textposition": "inside", + "insidetextanchor": "middle", + "base": -10 + }, + { + "xaxis": "x4", + "yaxis": "y4", + "type": "waterfall", + "orientation": "h", + "y": [ + "A", + "B", + "C" + ], + "x": [ + 1, + -2, + 1 + ], + "text": [ + "+1", + "-2", + "+1" + ], + "textposition": "inside", + "insidetextanchor": "middle", + "base": -10 + } + ], + "layout": { + "width": 400, + "height": 400, + "template": { + "layout": { + "showlegend": false, + "title": { + "text": "non-zero autorange with
base and negative size" + }, + "xaxis": { + "domain": [ + 0, + 0.45 + ] + }, + "yaxis": { + "domain": [ + 0, + 0.45 + ] + }, + "xaxis2": { + "anchor": "y2", + "domain": [ + 0.55, + 1 + ] + }, + "yaxis2": { + "anchor": "x2", + "domain": [ + 0.55, + 1 + ] + }, + "xaxis3": { + "anchor": "y3", + "domain": [ + 0, + 0.45 + ] + }, + "yaxis3": { + "anchor": "x3", + "domain": [ + 0.55, + 1 + ] + }, + "xaxis4": { + "anchor": "y4", + "domain": [ + 0.55, + 1 + ] + }, + "yaxis4": { + "anchor": "x4", + "domain": [ + 0, + 0.45 + ] + } + } + } + } +} diff --git a/test/image/mocks/bar-like_traces_no-tozero_stack.json b/test/image/mocks/bar-like_traces_no-tozero_stack.json new file mode 100644 index 00000000000..f1903bc26b2 --- /dev/null +++ b/test/image/mocks/bar-like_traces_no-tozero_stack.json @@ -0,0 +1,259 @@ +{ + "data": [ + { + "xaxis": "x", + "yaxis": "y", + "type": "bar", + "orientation": "h", + "y": [ + "A", + "B", + "C" + ], + "x": [ + 2, + -2, + 2 + ], + "text": [ + "+2", + "-2", + "+2" + ], + "textposition": "inside", + "textangle": 0, + "base": 10 + }, + { + "xaxis": "x2", + "yaxis": "y2", + "type": "bar", + "x": [ + "E", + "F", + "G" + ], + "y": [ + 2, + -2, + 2 + ], + "text": [ + "+2", + "-2", + "+2" + ], + "textposition": "inside", + "textangle": 0, + "base": -10 + }, + { + "xaxis": "x3", + "yaxis": "y3", + "type": "bar", + "x": [ + "E", + "F", + "G" + ], + "y": [ + 2, + -2, + 2 + ], + "text": [ + "+2", + "-2", + "+2" + ], + "textposition": "inside", + "textangle": 0, + "base": 10 + }, + { + "xaxis": "x4", + "yaxis": "y4", + "type": "bar", + "orientation": "h", + "y": [ + "A", + "B", + "C" + ], + "x": [ + 2, + -2, + 2 + ], + "text": [ + "+2", + "-2", + "+2" + ], + "textposition": "inside", + "textangle": 0, + "base": -10 + }, + { + "xaxis": "x", + "yaxis": "y", + "type": "bar", + "orientation": "h", + "y": [ + "A", + "B", + "C" + ], + "x": [ + 1, + -1, + 1 + ], + "text": [ + "+1", + "-1", + "+1" + ], + "textposition": "inside", + "textangle": 0, + "base": 10 + }, + { + "xaxis": "x2", + "yaxis": "y2", + "type": "bar", + "x": [ + "E", + "F", + "G" + ], + "y": [ + 1, + -1, + 1 + ], + "text": [ + "+1", + "-1", + "+1" + ], + "textposition": "inside", + "textangle": 0, + "base": -10 + }, + { + "xaxis": "x3", + "yaxis": "y3", + "type": "bar", + "x": [ + "E", + "F", + "G" + ], + "y": [ + 1, + -1, + 1 + ], + "text": [ + "+1", + "-1", + "+1" + ], + "textposition": "inside", + "textangle": 0, + "base": 10 + }, + { + "xaxis": "x4", + "yaxis": "y4", + "type": "bar", + "orientation": "h", + "y": [ + "A", + "B", + "C" + ], + "x": [ + 1, + -1, + 1 + ], + "text": [ + "+1", + "-1", + "+1" + ], + "textposition": "inside", + "textangle": 0, + "base": -10 + } + ], + "layout": { + "width": 400, + "height": 400, + "template": { + "layout": { + "barmode": "stack", + "showlegend": false, + "title": { + "text": "non-zero autorange with
base and negative size" + }, + "xaxis": { + "domain": [ + 0, + 0.45 + ] + }, + "yaxis": { + "domain": [ + 0, + 0.45 + ] + }, + "xaxis2": { + "anchor": "y2", + "domain": [ + 0.55, + 1 + ] + }, + "yaxis2": { + "anchor": "x2", + "domain": [ + 0.55, + 1 + ] + }, + "xaxis3": { + "anchor": "y3", + "domain": [ + 0, + 0.45 + ] + }, + "yaxis3": { + "anchor": "x3", + "domain": [ + 0.55, + 1 + ] + }, + "xaxis4": { + "anchor": "y4", + "domain": [ + 0.55, + 1 + ] + }, + "yaxis4": { + "anchor": "x4", + "domain": [ + 0, + 0.45 + ] + } + } + } + } +} diff --git a/test/image/mocks/bar-like_traces_tozero.json b/test/image/mocks/bar-like_traces_tozero.json new file mode 100644 index 00000000000..53da2ba1107 --- /dev/null +++ b/test/image/mocks/bar-like_traces_tozero.json @@ -0,0 +1,164 @@ +{ + "data": [ + { + "xaxis": "x", + "yaxis": "y", + "type": "bar", + "orientation": "h", + "y": [ + "A", + "B", + "C" + ], + "x": [ + 1, + -11, + 1 + ], + "text": [ + "+1", + "-11", + "+1" + ], + "textposition": "auto", + "insidetextanchor": "middle", + "base": 10 + }, + { + "xaxis": "x2", + "yaxis": "y2", + "type": "bar", + "x": [ + "E", + "F", + "G" + ], + "y": [ + -1, + 11, + -1 + ], + "text": [ + "-1", + "+11", + "-1" + ], + "textposition": "auto", + "insidetextanchor": "middle", + "base": -10 + }, + { + "xaxis": "x3", + "yaxis": "y3", + "type": "waterfall", + "x": [ + "E", + "F", + "G" + ], + "y": [ + 1, + -12, + 1 + ], + "text": [ + "+1", + "-12", + "+1" + ], + "textposition": "auto", + "insidetextanchor": "middle", + "base": 10 + }, + { + "xaxis": "x4", + "yaxis": "y4", + "type": "waterfall", + "orientation": "h", + "y": [ + "A", + "B", + "C" + ], + "x": [ + -1, + 12, + -1 + ], + "text": [ + "-1", + "+12", + "-1" + ], + "textposition": "auto", + "insidetextanchor": "middle", + "base": -10 + } + ], + "layout": { + "width": 400, + "height": 400, + "template": { + "layout": { + "showlegend": false, + "title": { + "text": "tozero autorange with
base and negative size" + }, + "xaxis": { + "domain": [ + 0, + 0.45 + ] + }, + "yaxis": { + "domain": [ + 0, + 0.45 + ] + }, + "xaxis2": { + "anchor": "y2", + "domain": [ + 0.55, + 1 + ] + }, + "yaxis2": { + "anchor": "x2", + "domain": [ + 0.55, + 1 + ] + }, + "xaxis3": { + "anchor": "y3", + "domain": [ + 0, + 0.45 + ] + }, + "yaxis3": { + "anchor": "x3", + "domain": [ + 0.55, + 1 + ] + }, + "xaxis4": { + "anchor": "y4", + "domain": [ + 0.55, + 1 + ] + }, + "yaxis4": { + "anchor": "x4", + "domain": [ + 0, + 0.45 + ] + } + } + } + } +}