From 7da1e05980997686a551bf15b731603cb06735ce Mon Sep 17 00:00:00 2001 From: Florian Mounier Date: Mon, 27 Jul 2015 14:38:24 +0200 Subject: [PATCH] Add box documentation and x/y labels with labels documentation. --- docs/changelog.rst | 5 +++ docs/documentation/configuration/label.rst | 42 ++++++++++++++++++++++ docs/documentation/types/box.rst | 31 +++++++++++++--- pygal/__init__.py | 2 +- pygal/graph/box.py | 9 +++-- pygal/graph/graph.py | 4 +++ 6 files changed, 83 insertions(+), 10 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 78e89a9..623aaf5 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -2,6 +2,11 @@ Changelog ========= +2.0.1 UNRELEASED +================ + +* Fix the missing title on x_labels with labels. + 2.0.0 ===== * Rework the ghost mechanism to come back to a more object oriented behavior, storing all state in a state object which is created on every render. (#161) diff --git a/docs/documentation/configuration/label.rst b/docs/documentation/configuration/label.rst index da1c909..66e74d7 100644 --- a/docs/documentation/configuration/label.rst +++ b/docs/documentation/configuration/label.rst @@ -14,6 +14,34 @@ x_labels chart.x_labels = 'Red', 'Blue', 'Green' chart.add('line', [.0002, .0005, .00035]) +It is possible for dual charts to define a custom scale: + +.. pygal-code:: + + chart = pygal.XY() + chart.x_labels = (.00012, .00024, .00048, .00096) + chart.add('line', [(.0002, 10), (.0005, 20), (.00035, 15)]) + + +And in this case it is possible to set text labels in place of values: + +.. pygal-code:: + + chart = pygal.XY() + chart.x_labels = ({ + 'label': 'Twelve', + 'value': .00012 + }, { + 'label': 'Twenty four', + 'value': .00024 + }, { + 'label': 'Forty eight', + 'value': .00048 + }, { + 'label': 'Ninety six', + 'value': .00096}) + chart.add('line', [(.0002, 10), (.0005, 20), (.00035, 15)]) + y_labels -------- @@ -25,6 +53,20 @@ y_labels chart.add('line', [.0002, .0005, .00035]) +It is now possible to add text to labels values: + +.. pygal-code:: + + chart = pygal.Line() + chart.y_labels = [ + {'label': 'One', 'value': .0001}, + {'label': 'Three', 'value': .0003}, + {'label': 'Four', 'value': .0004}, + {'label': 'Four and a half', 'value': .00045}, + {'label': 'Five', 'value': .0005}] + chart.add('line', [.0002, .0005, .00035]) + + show_x_labels ------------- diff --git a/docs/documentation/types/box.rst b/docs/documentation/types/box.rst index ea85890..952178a 100644 --- a/docs/documentation/types/box.rst +++ b/docs/documentation/types/box.rst @@ -1,10 +1,11 @@ Box --- -Basic -~~~~~ -Here's some whiskers: +Extremes (default) +~~~~~~~~~~~~~~~~~~ + +By default, the extremes mode is used that is the whiskers are the extremes of the data set, the box goes from the first quartile to the third and the middle line is the median. .. pygal-code:: @@ -15,7 +16,11 @@ Here's some whiskers: box_plot.add('Opera', [3472, 2933, 4203, 5229, 5810, 1828, 9013, 4669]) box_plot.add('IE', [43, 41, 59, 79, 144, 136, 34, 102]) -and variations: + +1.5 interquartile range +~~~~~~~~~~~~~~~~~~~~~~~ + +Same as above except the whiskers are the first quartile minus 1.5 times the interquartile range and the third quartile plus 1.5 times the interquartile range. .. pygal-code:: @@ -26,6 +31,12 @@ and variations: box_plot.add('Opera', [3472, 2933, 4203, 5229, 5810, 1828, 9013, 4669]) box_plot.add('IE', [43, 41, 59, 79, 144, 136, 34, 102]) + +Tukey +~~~~~ + +The whiskers are the lowest datum whithin the 1.5 IQR of the lower quartile and the highest datum still within 1.5 IQR of the upper quartile. The outliers are shown too. + .. pygal-code:: box_plot = pygal.Box(box_mode="tukey") @@ -35,6 +46,12 @@ and variations: box_plot.add('Opera', [3472, 2933, 4203, 5229, 5810, 1828, 9013, 4669]) box_plot.add('IE', [43, 41, 59, 79, 144, 136, 34, 102]) + +Standard deviation +~~~~~~~~~~~~~~~~~~ + +The whiskers are defined here by the standard deviation of the data. + .. pygal-code:: box_plot = pygal.Box(box_mode="stdev") @@ -44,6 +61,12 @@ and variations: box_plot.add('Opera', [3472, 2933, 4203, 5229, 5810, 1828, 9013, 4669]) box_plot.add('IE', [43, 41, 59, 79, 144, 136, 34, 102]) + +Population standard deviation +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The whiskers are defined here by the population standard deviation of the data. + .. pygal-code:: box_plot = pygal.Box(box_mode="pstdev") diff --git a/pygal/__init__.py b/pygal/__init__.py index 32ddd7f..ade522a 100644 --- a/pygal/__init__.py +++ b/pygal/__init__.py @@ -24,7 +24,7 @@ and the maps extensions namespace module. """ -__version__ = '2.0.0' +__version__ = '2.0.1' import pkg_resources import sys diff --git a/pygal/graph/box.py b/pygal/graph/box.py index 5ccda59..aa0e3e9 100644 --- a/pygal/graph/box.py +++ b/pygal/graph/box.py @@ -179,12 +179,12 @@ class Box(Graph): @staticmethod def _box_points(values, mode='extremes'): """ - Default mode: (mode='1.5IQR' or unset) - Return a 7-tuple of min, Q1 - 1.5 * IQR, Q1, Median, Q3, - Q3 + 1.5 * IQR and max for a list of numeric values. - Extremes mode: (mode='extremes') + Default mode: (mode='extremes' or unset) Return a 7-tuple of 2x minimum, Q1, Median, Q3, and 2x maximum for a list of numeric values. + 1.5IQR mode: (mode='1.5IQR') + Return a 7-tuple of min, Q1 - 1.5 * IQR, Q1, Median, Q3, + Q3 + 1.5 * IQR and max for a list of numeric values. Tukey mode: (mode='tukey') Return a 7-tuple of min, q[0..4], max and a list of outliers Outliers are considered values x: x < q1 - IQR or x > q3 + IQR @@ -195,7 +195,6 @@ class Box(Graph): Return a 7-tuple of min, q[0..4], max and a list of outliers Outliers are considered values x: x < q2 - SDp or x > q2 + SDp - The iterator values may include None values. Uses quartile definition from Mendenhall, W. and diff --git a/pygal/graph/graph.py b/pygal/graph/graph.py index f1748c9..a8ba5e5 100644 --- a/pygal/graph/graph.py +++ b/pygal/graph/graph.py @@ -173,6 +173,10 @@ class Graph(PublicApi): text.text = truncate(label, truncation) if text.text != label: self.svg.node(guides, 'title').text = label + else: + self.svg.node( + guides, 'title', + ).text = self._x_format(position) if self.x_label_rotation: text.attrib['transform'] = "rotate(%d %f %f)" % (