Skip to content
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
23 changes: 15 additions & 8 deletions src/traces/bar/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,13 @@ module.exports = function plot(gd, plotinfo, cdModule, traceLayer, opts) {
var bartraces = Lib.makeTraceGroups(traceLayer, cdModule, 'trace bars').each(function(cd) {
var plotGroup = d3.select(this);
var trace = cd[0].trace;
var isWaterfall = (trace.type === 'waterfall');
var isFunnel = (trace.type === 'funnel');
var isBar = (trace.type === 'bar');
var shouldDisplayZeros = isBar || isFunnel;

var adjustPixel = 0;
if(trace.type === 'waterfall' && trace.connector.visible && trace.connector.mode === 'between') {
if(isWaterfall && trace.connector.visible && trace.connector.mode === 'between') {
adjustPixel = trace.connector.line.width / 2;
}

Expand Down Expand Up @@ -101,10 +105,11 @@ module.exports = function plot(gd, plotinfo, cdModule, traceLayer, opts) {
var y0 = xy[1][0];
var y1 = xy[1][1];

var isBlank = di.isBlank = (
!isNumeric(x0) || !isNumeric(x1) ||
!isNumeric(y0) || !isNumeric(y1) ||
x0 === x1 || y0 === y1
var isBlank = di.isBlank = !(
isNumeric(x0) && isNumeric(x1) &&
isNumeric(y0) && isNumeric(y1) &&
(x0 !== x1 || (shouldDisplayZeros && isHorizontal)) &&
(y0 !== y1 || (shouldDisplayZeros && !isHorizontal))
);

// in waterfall mode `between` we need to adjust bar end points to match the connector width
Expand Down Expand Up @@ -231,7 +236,7 @@ function appendBarText(gd, plotinfo, bar, calcTrace, i, x0, x1, y0, y1, opts) {

if(!text ||
textPosition === 'none' ||
(calcBar.isBlank && (
((calcBar.isBlank || x0 === x1 || y0 === y1) && (
textPosition === 'auto' ||
textPosition === 'inside'))) {
bar.select('text').remove();
Expand Down Expand Up @@ -513,6 +518,8 @@ function getTextPosition(trace, index) {
function calcTextinfo(calcTrace, index, xa, ya) {
var trace = calcTrace[0].trace;
var isHorizontal = (trace.orientation === 'h');
var isWaterfall = (trace.type === 'waterfall');
var isFunnel = (trace.type === 'funnel');

function formatLabel(u) {
var pAxis = isHorizontal ? ya : xa;
Expand Down Expand Up @@ -542,7 +549,7 @@ function calcTextinfo(calcTrace, index, xa, ya) {
if(tx === 0 || tx) text.push(tx);
}

if(trace.type === 'waterfall') {
if(isWaterfall) {
var delta = +cdi.rawS || cdi.s;
var final = cdi.v;
var initial = final - delta;
Expand All @@ -552,7 +559,7 @@ function calcTextinfo(calcTrace, index, xa, ya) {
if(hasFlag('final')) text.push(formatNumber(final));
}

if(trace.type === 'funnel') {
if(isFunnel) {
if(hasFlag('value')) text.push(formatNumber(cdi.s));

var nPercent = 0;
Expand Down
Binary file modified test/image/baselines/bar-marker-line-colorscales.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/image/baselines/bar_display_height_zero.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/error_bar_bar_ids.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/funnel_horizontal_group_basic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/funnel_vertical_overlay_custom_arrays.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
180 changes: 180 additions & 0 deletions test/image/mocks/bar_display_height_zero.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
{
"data": [
{
"type": "bar",
"marker": {
"line": {
"width": 10
}
},
"x": [
"A",
"B",
"C"
],
"y": [
0,
null,
1
],
"text": [
0,
null,
1
],
"textposition": "auto",
"insidetextanchor": "middle",
"cliponaxis": false
},
{
"type": "bar",
"marker": {
"line": {
"width": 10
}
},
"x": [
"A",
"B",
"C"
],
"y": [
0,
null,
1
],
"text": [
0,
null,
1
],
"textposition": "auto",
"insidetextanchor": "middle",
"cliponaxis": false,
"xaxis": "x2",
"yaxis": "y2"
},
{
"type": "bar",
"marker": {
"line": {
"width": 10
}
},
"orientation": "h",
"x": [
0,
null,
1
],
"y": [
"A",
"B",
"C"
],
"text": [
0,
null,
1
],
"textposition": "auto",
"insidetextanchor": "middle",
"cliponaxis": false,
"xaxis": "x3",
"yaxis": "y3"
},
{
"type": "bar",
"marker": {
"line": {
"width": 10
}
},
"orientation": "h",
"x": [
0,
null,
1
],
"y": [
"A",
"B",
"C"
],
"text": [
0,
null,
1
],
"textposition": "auto",
"insidetextanchor": "middle",
"cliponaxis": false,
"xaxis": "x4",
"yaxis": "y4"
}
],
"layout": {
"showlegend": true,
"width": 800,
"height": 800,
"dragmode": "pan",
"xaxis": {
"domain": [
0,
0.48
]
},
"xaxis2": {
"autorange": "reversed",
"anchor": "y2",
"domain": [
0.52,
1
]
},
"xaxis3": {
"anchor": "y3",
"domain": [
0,
0.48
]
},
"xaxis4": {
"autorange": "reversed",
"anchor": "y4",
"domain": [
0.52,
1
]
},
"yaxis": {
"domain": [
0,
0.48
]
},
"yaxis2": {
"autorange": "reversed",
"anchor": "x2",
"domain": [
0.52,
1
]
},
"yaxis3": {
"anchor": "x3",
"domain": [
0.52,
1
]
},
"yaxis4": {
"autorange": "reversed",
"anchor": "x4",
"domain": [
0,
0.48
]
}
}
}
Loading