From ec6e752905e8eb450e0d6984aa7b7b6192a92b3d Mon Sep 17 00:00:00 2001 From: ksheehy Date: Fri, 26 Jan 2024 12:50:14 +0100 Subject: [PATCH 1/2] _bullet has an issue building measure and range bars if the data set has negative values --- .../python/plotly/plotly/figure_factory/_bullet.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/python/plotly/plotly/figure_factory/_bullet.py b/packages/python/plotly/plotly/figure_factory/_bullet.py index ce51e9360c8..1bee4a83503 100644 --- a/packages/python/plotly/plotly/figure_factory/_bullet.py +++ b/packages/python/plotly/plotly/figure_factory/_bullet.py @@ -88,19 +88,19 @@ def _bullet( range_colors[0], range_colors[1], len(df.iloc[row]["ranges"]), "rgb" ) x = ( - [sorted(df.iloc[row]["ranges"])[-1 - idx]] + [sorted(df.iloc[row]["ranges"], key=abs, reverse=True)[idx]] if orientation == "h" else [0] ) y = ( [0] if orientation == "h" - else [sorted(df.iloc[row]["ranges"])[-1 - idx]] + else [sorted(df.iloc[row]["ranges"], key=abs, reverse=True)[idx]] ) bar = go.Bar( x=x, y=y, - marker=dict(color=inter_colors[-1 - idx]), + marker=dict(color=inter_colors[sorted(df.iloc[row]["ranges"]).index(sorted(df.iloc[row]["ranges"], key=abs, reverse=True)[idx])]), name="ranges", hoverinfo="x" if orientation == "h" else "y", orientation=orientation, @@ -120,19 +120,19 @@ def _bullet( "rgb", ) x = ( - [sorted(df.iloc[row]["measures"])[-1 - idx]] + [sorted(df.iloc[row]["measures"], key=abs, reverse=True)[idx]] if orientation == "h" else [0.5] ) y = ( [0.5] if orientation == "h" - else [sorted(df.iloc[row]["measures"])[-1 - idx]] + else [sorted(df.iloc[row]["measures"], key=abs, reverse=True)[idx]] ) bar = go.Bar( x=x, y=y, - marker=dict(color=inter_colors[-1 - idx]), + marker=dict(color=inter_colors[sorted(df.iloc[row]["measures"]).index(sorted(df.iloc[row]["measures"], key=abs, reverse=True)[idx])]), name="measures", hoverinfo="x" if orientation == "h" else "y", orientation=orientation, From 2a1933526daa3ba9c8602dd2befb507cb5b45ac8 Mon Sep 17 00:00:00 2001 From: Mojtaba Samimi <33888540+archmoj@users.noreply.github.com> Date: Thu, 28 Mar 2024 12:40:43 -0400 Subject: [PATCH 2/2] Apply suggestions from code review Reformat --- .../plotly/plotly/figure_factory/_bullet.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/python/plotly/plotly/figure_factory/_bullet.py b/packages/python/plotly/plotly/figure_factory/_bullet.py index 1bee4a83503..578b47a9eef 100644 --- a/packages/python/plotly/plotly/figure_factory/_bullet.py +++ b/packages/python/plotly/plotly/figure_factory/_bullet.py @@ -100,7 +100,13 @@ def _bullet( bar = go.Bar( x=x, y=y, - marker=dict(color=inter_colors[sorted(df.iloc[row]["ranges"]).index(sorted(df.iloc[row]["ranges"], key=abs, reverse=True)[idx])]), + marker=dict( + color=inter_colors[ + sorted(df.iloc[row]["ranges"]).index( + sorted(df.iloc[row]["ranges"], key=abs, reverse=True)[idx] + ) + ] + ), name="ranges", hoverinfo="x" if orientation == "h" else "y", orientation=orientation, @@ -132,7 +138,13 @@ def _bullet( bar = go.Bar( x=x, y=y, - marker=dict(color=inter_colors[sorted(df.iloc[row]["measures"]).index(sorted(df.iloc[row]["measures"], key=abs, reverse=True)[idx])]), + marker=dict( + color=inter_colors[ + sorted(df.iloc[row]["measures"]).index( + sorted(df.iloc[row]["measures"], key=abs, reverse=True)[idx] + ) + ] + ), name="measures", hoverinfo="x" if orientation == "h" else "y", orientation=orientation,