Kozea / pygal

PYthon svg GrAph plotting Library
https://www.pygal.org
GNU Lesser General Public License v3.0
2.62k stars 411 forks source link

Plot x guides only for non None x_labels #541

Open inferrna opened 1 year ago

inferrna commented 1 year ago

I need to plot a linear graph with labeled and guided points of interest. I provided x_labels as [None, None, "Interesting point 1", None, None, "Interesting point 2"] but show_x_guides just showed all lines, so it just became not informative frequent mesh. this patch did the job for me, but it also will trigger with empty strings provided by user as a labels.

--- a/pygal/graph/graph.py
+++ b/pygal/graph/graph.py
@@ -179,7 +179,7 @@ class Graph(PublicApi):
                 continue
             guides = self.svg.node(axis, class_='guides')
             x = self.view.x(position)
-            if x is None:
+            if x is None or label == '':
                 continue
             y = self.view.height + 5
             last_guide = (self._y_2nd_labels and label == lastlabel)

so, it would be nice to implement such a thing:

  1. Skip x guidelines when according labels are None.
  2. Draw x guidelines when according labels are empty strings.

The chart I got with this patch:

chart