Skip to content
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

Add color to bars for Plotly #6294

Merged
merged 2 commits into from
Jul 4, 2024
Merged

Add color to bars for Plotly #6294

merged 2 commits into from
Jul 4, 2024

Conversation

hoxbro
Copy link
Member

@hoxbro hoxbro commented Jun 24, 2024

Fixes #5658

image

@hoxbro hoxbro added the type: enhancement Minor feature or improvement to an existing feature label Jun 24, 2024
Copy link

codecov bot commented Jun 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.50%. Comparing base (e243fe0) to head (5d99c25).
Report is 10 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6294      +/-   ##
==========================================
- Coverage   88.55%   88.50%   -0.06%     
==========================================
  Files         323      323              
  Lines       68000    68079      +79     
==========================================
+ Hits        60218    60250      +32     
- Misses       7782     7829      +47     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@hoxbro hoxbro modified the milestone: 1.19.1 Jun 24, 2024
@@ -280,6 +281,10 @@ def get_data(self, element, ranges, style, **kwargs):
for d in (xdim, group_dim)],
y: np.nan_to_num(values)})

if self.color:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a better method to put this in?

@hoxbro hoxbro requested a review from philippjfr June 25, 2024 06:56
@hoxbro hoxbro requested a review from maximlt July 4, 2024 10:15
Copy link
Member

@maximlt maximlt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think making color a plot option is the right approach here. I've tried something else that seemed to work, it'd need some more testing and unit tests.

I'm also not sure what convention HoloViews follows on naming style options, does it attempt to standardize them across backends or does it instead try to stay closer to the backend naming scheme?

diff --git a/holoviews/plotting/plotly/chart.py b/holoviews/plotting/plotly/chart.py
index a7a831bbd..bcb7c82ee 100644
--- a/holoviews/plotting/plotly/chart.py
+++ b/holoviews/plotting/plotly/chart.py
@@ -198,9 +198,7 @@ class BarPlot(BarsMixin, ElementPlot):
     show_legend = param.Boolean(default=True, doc="""
         Whether to show legend for the plot.""")
 
-    color = param.String(default=None, doc="The color of the bars.")
-
-    style_opts = ['visible']
+    style_opts = ['visible', 'color']
 
     selection_display = PlotlyOverlaySelectionDisplay()
 
@@ -281,12 +279,14 @@ class BarPlot(BarsMixin, ElementPlot):
                     for d in (xdim, group_dim)],
                 y: np.nan_to_num(values)})
 
-        if self.color:
-            for bar in bars:
-                bar['marker_color'] = self.color
-
         return bars
 
+    def graph_options(self, element, ranges, style, **kwargs):
+        if 'color' in style:
+            style['marker_color'] = style.pop('color')
+        opts = super().graph_options(element, ranges, style, **kwargs)
+        return opts
+
     def init_layout(self, key, element, ranges, **kwargs):
         layout = super().init_layout(key, element, ranges)
         stack_dim = None

image

@maximlt
Copy link
Member

maximlt commented Jul 4, 2024

it'd need some more testing and unit tests.

@hoxbro in fact you already added a test which I didn't need to touch, so we're good.

@hoxbro hoxbro enabled auto-merge (squash) July 4, 2024 13:19
@hoxbro hoxbro merged commit d0d535b into main Jul 4, 2024
13 checks passed
@hoxbro hoxbro deleted the color_plotly_bars branch July 4, 2024 13:44
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: enhancement Minor feature or improvement to an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

color option not working for Bars plot with Plotly backend
2 participants