-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Feature request: rounded corners for trace bars #2196
Comments
The dataviz purist in me is a little squeamish - the area of the bar, the most important component of its visual weight, loses proportionality with the data value, and lacking a straight line at the end it's hard to compare two similar bars and tell which is bigger. But you're right that it's a pleasant effect, we'd entertain a PR about this. |
What happens when bars are stacked? |
@etpinard the stacking part is a problem. Basically, one way is to manually handle it when passing data object by ensuring appropriate round corners are only on data bars that are on top or on the bottom of the stack. Of course, this isn't ideal since bar can be in different positions in different stacks. Which limits the use of round corners on stacked bars. |
What is the status of this feature request? |
|
Any updates on this? |
Unfortunately no |
+1. I need this as well. Much more subtle but there is a need to fit charts into a brand. |
Any updates? |
I would say rounded corners are essential for professional graphs. As Steve Jobs would have said: "Even something as basic as a traffic sign has rounded corners". For now I'll use shapes with plotly.py: |
FWIW the shape solution doesn't need two overlaid shapes - just take out the extra |
@alexcjohnson Thanks for this simple solution to round the corners. @Jonathan-MW I updated this notebook https://plot.ly/~empet/14945 defining the path like in the above pen. |
Any updates? This an important feature and not optional if you want to fit your chart to a design system brand. |
Any update, 7mo later? |
I'd also appreciate to see this feature. |
2.5 years later and still no round corners...please add this feature! :,( |
We'd be happy to work with someone who wants to implement this and get it merged in but it's not on our roadmap at the moment :) |
@nicolaskruchten, what would be the ideal approach to implementing this change? |
Hi @BrianRuizy ! The first step would be to propose one or more new attributes in the Plotly.js schema to control this new behaviour. Something like "a new attribute Once we can agree to a 'spec' like this, it's usually a question of figuring out a test plan and then writing the code. The test plan will involve some static image tests that prove the new attribute works and some Jasmine tests to prove that it can work when turned on and off via |
This issue has been tagged with A community PR for this feature would certainly be welcome, but our experience is deeper features like this are difficult to complete without the Plotly maintainers leading the effort. What Sponsorship includes:
Please include the link to this issue when contacting us to discuss. |
I'm using Plotly along with Dash at my company. While Plotly is great, it pales in comparison to the overall visual pleasantness provided by Tableau. My dashboard is really heavy on Bar Charts and this feature would be most welcome. I don't know if this is very hard to implement or just not a priority. But if the kind developers out there entertain this feature request, I'd be very grateful. Judging from this thread, clearly so many people are interested in it. |
One workaround is to programmatically insert a half circle on the top of your bar charts. While we are in the This approach relies on knowing the width of each of the bars, which you can set. If you know the widths, you can programmatically run through all the data points The chart on the left is This is what import random
import dash
import plotly
import plotly.graph_objs as go
import dash_core_components as dcc
import dash_html_components as html
X_ARRAY = [1, 2, 3, 4, 5, 6, 7, 8, 9]
Y_ARRAY = [10, 4, 7, 11, 12, 8, 3, 6, 6]
GRAPH_STYLE = {
"width": "50%",
"display": "inline-block",
}
app = dash.Dash(
__name__,
suppress_callback_exceptions=True,
meta_tags=[
{"name": "viewport", "content": "width=device-width, initial-scale=1.0"}
],
)
server = app.server
def bar_graph(x_array, y_array, marker_color=None):
if not marker_color:
marker_color = "DodgerBlue"
fig = go.Figure(
data=go.Bar(x=x_array, y=y_array, marker=dict(color=marker_color)),
layout=go.Layout(
height=300, margin=dict(l=0, r=0, t=0, b=0,), yaxis=dict(range=[0, 15])
),
)
return fig
def rounded_bar_graph(x_array, y_array, marker_color=None):
if not marker_color:
marker_color = "DodgerBlue"
fig = bar_graph(x_array, y_array)
bw = 0.4 # half of the bar width
curve_height = 2.7
no_color = "rgba(0,0,0,0)"
shapes = []
for x, y in zip(fig["data"][0]["x"], fig["data"][0]["y"]):
path = f"""
M {x-bw},{y}
C {x-bw} {y+curve_height}, {x+bw} {y+curve_height}, {x+bw} {y}
V 0
H {x-bw}
Z
"""
shapes.append(
dict(type="path", path=path, line_color=no_color, fillcolor=marker_color,)
)
fig.update_layout(shapes=shapes,)
return fig
layout = html.Div(
children=[
dcc.Graph(
id="bar-graph-2", style=GRAPH_STYLE, figure=bar_graph(X_ARRAY, Y_ARRAY)
),
dcc.Graph(
id="bar-graph",
style=GRAPH_STYLE,
figure=rounded_bar_graph(X_ARRAY, Y_ARRAY),
),
]
)
app.layout = layout
while __name__ == "__main__":
app.run_server(debug=True) |
One thing to note about rounded corners is that they're (potentially, I haven't dug up any studies!) problematic for visualization in two ways:
|
For a full half circle, I can see how this is a problem for sure. However, with only a slight
This is a really good point as well. If the point of the visualization is to compare areas, having rounded corners could absolutely mislead. |
One challenge with visualization is that we have little control over how people actually perceive what we produce, so even if comparing areas isn't "the point" of the visualization author, people who read it most likely will take areas into account when comparing at a glance. But yes, this is minimized when using small corner-radii compared to the bar widths. |
This is very true. And it tessellates so neatly with questions such as:
@nicolaskruchten Are there any resources/books you know of that talk about these kinds of viz choices and their affect (conscious or not) on the end user/viewer? |
Yes, there is lots of research about perception. A good starting point, if dated, is Colin Ware's Information Visualization: Perception for Design. |
Side note: these issues also pertain in a long-dormant problem with dash-daq thermometers plotly/dash-daq#68 |
Ahh I didn't know that, thank you for the heads up. |
Thank you very much for this recommendation. I'll check it out. 🙂 |
almost 4 years now and still no round corners...... |
+1 for Rounded Corners |
just so its known, some of us are still hoping for rounded corners 5 years on |
Absent a sponsor this is unlikely to make it onto Plotly's roadmap - but we'd gladly accept a PR and help get it finished, if any of the folks giving this issue a 👍 would like to give it a go! |
Also for plotly.js/src/traces/treemap/plot_one.js Line 220 in 6f01227
@alexcjohnson it would be great if we declare the potential (per trace?) attribute name (& a |
Hi all. I've handled this feature by using scatter charts! You can see the code in my Gist |
I found a quick workaround in CSS if anyone is interested: Find the CSS selector for the bar(s) you want to make to have rounded. It can be done by selecting it in your inspector panel, and click "Copy > Copy Selector". Then, apply a CSS inset clip path. In my case, I just wanted some bars to be rounded, here is how it looked like:
I hope it helps someone |
The solution provided by @axel-rock works well for a regular bar chart. In the case of a stacked bar chart, I didn't find a way to target only the start plot and trailing plot for the rounded cornes. The SVGs are positionned "randomly" and there is no group and similar className between plot making a bar. |
+1 |
+1 |
I think for stacked bar chart should work the follow:
Where #stacked-bar-chart - the id of the graph container. g:nth-last-child(1) - this part is for choosing only top bars, round 0.3rem 0.3rem 0 0 - this is for round only top of the bar And a bit update on @axel-rock great solution, to apply rounded corner for the entire chart, you can apply following style:
This works fine with vertical/horizontal bars and histograms, you just need to change #id-of-the-bar-chart to the actual graph id |
This is a request to pass attributes to trace bar component to adjust bar corner roundness.
That way bar visual variety would be extended.
Each bar corners roundness could individually adjusted with percentage value from 0 to 1 where 1 is full circle arc.
Attribute could be passed like this:
"cornerroundness": { "bottomleft": 0.3, "bottomright": 0, "topleft": 0.3, "topright": 0 }
Maximum arc radius could be set to least wide bar edge width divided by two otherwise there could arise visual problems with bar.
Visually that would result that bars would be able to look like this:
The text was updated successfully, but these errors were encountered: