Skip to content

Display bar outlines with height zero #3848

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 5 commits into from
May 21, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
22 changes: 14 additions & 8 deletions src/traces/bar/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,12 @@ 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 = !(isWaterfall || 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 +104,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 || (isBar && isHorizontal)) &&
(y0 !== y1 || (isBar && !isHorizontal))
);

// in waterfall mode `between` we need to adjust bar end points to match the connector width
Expand Down Expand Up @@ -231,7 +235,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 +517,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 +548,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 +558,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.
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
]
}
}
}