Skip to content

Text does not show up on bars with empty area #3115

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

Closed
eivindjahren opened this issue Oct 17, 2018 · 7 comments · Fixed by #3701
Closed

Text does not show up on bars with empty area #3115

eivindjahren opened this issue Oct 17, 2018 · 7 comments · Fixed by #3701
Labels
bug something broken

Comments

@eivindjahren
Copy link
Contributor

eivindjahren commented Oct 17, 2018

If a bar does not have any width or height, text does not show up, even when {textposition: 'outside'} is set.

https://codepen.io/haskellelephant/pen/PyQemG

@alexcjohnson
Copy link
Collaborator

Confirmed, thanks for the report @eivindjahren!

@eivindjahren
Copy link
Contributor Author

eivindjahren commented Oct 25, 2018

The relevant lines are

if(!isNumeric(x0) || !isNumeric(x1) ||
!isNumeric(y0) || !isNumeric(y1) ||
x0 === x1 || y0 === y1) {
bar.remove();
return;
}
as it removes a bar group if the associated bar is empty so text is never attached to it.

However, changing this behavior to for instance

var text = getText(trace, i);
if(!isNumeric(x0) || !isNumeric(x1) ||
        !isNumeric(y0) || !isNumeric(y1) ||
        ((x0 === x1 || y0 === y1) && !text)) {
    bar.remove();
    return;
}

breaks a lot of tests.

@etpinard
Copy link
Contributor

etpinard commented Oct 25, 2018

Perhaps we should do like barpolar does and draw invalid bars with a blank path

// do not remove blank bars, to keep data-to-node
// mapping intact during radial drag, that we
// can skip calling _module.style during interactions
dPath = 'M0,0Z';

instead of removing them?

@weilu
Copy link

weilu commented Oct 25, 2019

Still doesn't show the text for default textposition, which is "auto". Setting {textposition: "outside"} explicitly fixed it for me.

@alb-erandelcastillo
Copy link

alb-erandelcastillo commented Nov 26, 2019

@etpinard Issue still occurs for bar charts within subplots, where label text doesn't appear for traces with 0 height. The issue can be recreated with this:

chart = make_subplots(rows=2, cols=1)
                
chart.append_trace(
    go.Bar(
        x=['a','b','c','d'],
        y=[2, 4, 0, 4],
        hoverinfo=["y"],
        text=['a text','b text','c text','d text'],
        textposition="outside"
        ),
    row=2, col=1
    )
    
chart.append_trace(
    go.Bar(
        x=['a','b','c','d'],
        y=[0, 0, 0, 1],
        hoverinfo=["y"],
        text=['a text','b text','c text','d text'],
        textposition="outside"
        ),
    row=2, col=1
    )
        
chart.append_trace(
    go.Bar(
        x=['a','b','c','d'],
        y=[0, 5, 3, 1],
        hoverinfo=["y"],
        text=['a 2','b 2', 'c 2', 'd 2'],
        textposition="outside"
        ),
    row=1, col=1
    )
            
chart.update_layout(
        barmode="stack", showlegend=False, xaxis=dict(showticklabels=False))

@xmagor
Copy link

xmagor commented Dec 14, 2019

Hi, I am puting labels with the total value of the each bar.

with {textposition: "auto"}, I had this result:

imagen

When I change that value by "outsite", I get this:

imagen

I really apreciate that when I put {textposition: "outside"} zero values are visibles. But my question is : Is there any option to do that the textposition would be always in the bar's top? I was reading the reference: https://plot.ly/python/reference/#bar-textposition and there is only 4 options to this parameter ( "inside" | "outside" | "auto" | "none" ) .

I also tried adding annotations in the plot's layer, and thats works, but with annotations is slower. because of that I am trying to put the labels when I define the data of the chart instead add annotations in the layer.

Thanks for your attention.

@archmoj
Copy link
Contributor

archmoj commented Dec 14, 2019

@mangel2095
Thanks for using plotly.
I think you should be able to achieve that by using textposition: 'outside' in every bar trace in your graph.
We appreciate if you use https://community.plot.ly/ for questions like this in future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants