Commit 2d9fbef3 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Add xlabel and ylabel for graph and improve documentation.

parent ba006866
......@@ -7,12 +7,19 @@ import matplotlib
import re
from gluon.storage import Storage
from plugin_dbui import get_id, INLINE_ALERT
from report_objects import do_title, List, Metric1D, Metric2D
from selector import MySelector
from StringIO import StringIO
# A specific set of keys use to to tune matplotlib rendering
# These keys are in the plot configuration but are not arguments
# of the DataFrame.plot method
PLT_KEYS = ('index', 'xlabel', 'ylabel')
def graph_extjs():
"""Plot 2D metric as a C{Ext.char.series.Area} using the ExtJS library.
This action is kept as a test bench of ExtJS chart classes.
......@@ -73,36 +80,48 @@ def graph_mpl():
return INLINE_ALERT % ("Error", msg)
# instantiate the lists/metrics
config = db[tablename][id]
if tablename == "lists":
report = List(config, selector)
elif tablename == "metrics1d":
report = Metric1D(config, selector)
try:
config = db[tablename][id]
if tablename == "lists":
report = List(config, selector)
elif tablename == "metrics2d":
report = Metric2D(config, selector)
elif tablename == "metrics1d":
report = Metric1D(config, selector)
elif tablename == "metrics2d":
report = Metric2D(config, selector)
# decode the graph configuration
try:
# decode the graph configuration
kwargs = json.loads(graph.plot)
except ValueError, msg:
return INLINE_ALERT % ("JSON Error", msg)
# generate the plot according to user specification
except (TypeError, ValueError) as e:
return INLINE_ALERT % ("Error", e)
# extract keyword which are not arguments of the DataFrame.plot method
plt_cfg = Storage()
for k in PLT_KEYS:
plt_cfg[k] = kwargs.pop(k, None)
# generate the plot using a specific set of columns
df = report.to_df()
if 'index' in kwargs:
index = kwargs['index']
del kwargs['index']
ax = df.ix[:,index].plot(**kwargs)
if plt_cfg.index:
ax = df.ix[:,plt_cfg.index].plot(**kwargs)
# generate a plot using all columns of the DataFrame
else:
ax = df.T.plot(**kwargs)
# activate minor ticks
ax.minorticks_on()
# set x / y label(s)
if plt_cfg.xlabel:
ax.set_xlabel(plt_cfg.xlabel)
if plt_cfg.ylabel:
ax.set_ylabel(plt_cfg.ylabel)
# push legend on the top outside the plot
# from http://stackoverflow.com/questions/4700614/how-to-put-the-legend-out-of-the-plot
if ax.get_legend():
......@@ -113,19 +132,17 @@ def graph_mpl():
fontsize=10,
ncol=3)
# open a StingIO file
# save the figure into a string
fi = StringIO()
# get the figure associated to the plot and save it in the file
fig = ax.get_figure()
fig.savefig(fi, format='svg')
fig.clear()
# recuperate the data and delegate the final rendering to the view
# encode the data for URI
data = fi.getvalue()
fi.close()
# delegate the rendering of the figure to the view
return dict(data=data)
......
......@@ -18,90 +18,70 @@ The properties and their values have to follow the JSON_ syntax:
all columns
^^^^^^^^^^^
.. list-table::
:widths: 15 10 70
* -
-
-
* - ``align``
-
- String defining the alignment of the column.
Possible values are: ``"left"``, ``"center"``, and ``"right"``.
* - ``columnWidth``
-
- can be specified as a number or a percentage.
* - ``dbfield``
- (*)
- String with the address of the database field.
It is encoded as ``"tablename.fieldname"`` or
``"tablename.fieldname.keyname"``.
It should not be used with ``rownumberer`` column.
* - ``hidden``
-
- ``true`` to hide the column.
* - ``renderer``
-
- A string pointing to the javascript function rendering the value or
containing the function itself.
* - ``text``
- (*)
- String containing the label of the column.
* - ``xtype``
- (*)
- String specifying the type of the column.
The mapping between the type of the column and the one of the database field is
the following:
.. list-table::
* - ``booleancolumn``
- boolean
* - ``datecolumn``
- date or datetime
* - ``numbercolumn``
- integer or float
* - ``gridcolumn``
- string
``align``
the alignment of the column.
Possible values are: ``"left"``, ``"center"``, and ``"right"``.
``columnWidth`` or ``flex``
the column width can be specified as a number or a percentage.
``dbfield`` (*)
the address of the database field encoded as ``"tablename.fieldname"`` or
``"tablename.fieldname.keyname"``.
.. warning::
It should not be used with the ``rownumberer`` column.
``hidden``
the column is hidden when it is ``true``.
``renderer``
A string pointing to the javascript function rendering the value or
containing the function itself.
``text`` (*)
the string containing the label of the column.
``xtype`` (*)
the string specifying the type of the column.
The mapping between the type of the column and the one of the database field
is the following:
.. list-table::
* - ``booleancolumn``
- boolean
* - ``datecolumn``
- date or datetime
* - ``numbercolumn``
- integer or float
* - ``gridcolumn``
- string (default)
booleancolumn
^^^^^^^^^^^^^
.. list-table::
:widths: 15 70
``falseText``
the string return in the grid when the value is false.
* -
-
* - ``falseText``
- the string return in the grid when the value is false.
* - ``trueText``
- the string return in the grid when the value is true.
``trueText``
the string return in the grid when the value is true.
datecolumn
^^^^^^^^^^
.. list-table::
:widths: 15 70
* -
-
* - ``format``
- format string, e.g. ``"d/m/Y"``.
``format``
the format string, e.g. ``"d/m/Y"``.
numbercolumn
^^^^^^^^^^^^
.. list-table::
:widths: 15 70
* -
-
* - ``format``
- format string, e.g. ``"0,000.00"``.
* - ``summaryType``
- Summary over column values are computed.
Possible values are ``"count"``, ``"sum"``, ``"min"``, ``"max"``
and ``"average"``.
``format``
the format string, e.g. ``"0,000.00"``.
``summaryType``
Summary over column values are computed.
Possible values are ``"count"``, ``"sum"``, ``"min"``, ``"max"`` and
``"average"``.
Metric 1D
---------
......@@ -110,43 +90,36 @@ The configuration parameters for the Metric1D column is similar to
those of the ``numbercolumn`` since the table only contains number. Therefore
it is not required to specify the column type.
.. list-table::
:widths: 15 10 70
* -
-
-
* - ``aggregate``
- (*)
- name of the aggregation function, e.g. ``"count"``, ``"sum"``,
``"mean"``,...
* - ``align``
-
- String defining the alignment of the column.
Possible values are: ``"left"``, ``"center"``, and ``"right"``.
* - ``columnWidth`` or ``flex``
-
- can be specified as a number or a percentage.
* - ``dbfield``
- (*)
- String with the address of the database field.
It is encoded as ``"tablename.fieldname"`` or
``"tablename.fieldname.keyname"``.
* - ``format``
-
- format string, e.g. ``"0,000.00"``.
* - ``hidden``
-
- ``true`` to hide the column.
* - ``renderer``
-
- A string pointing to the javascript function rendering the value or
containing the function itself.
* - ``text``
- (*)
- String containing the label of the column.
* - ``summaryType``
-
- Summary over column values are computed.
Possible values are ``"count"``, ``"sum"``, ``"min"``, ``"max"``
and ``"average"``.
``aggregate`` (*)
Many aggregation functions are available: ``count``, ``max``, ``mean``,
``median``, ``min``, ``size``, ``std``, ``sum``... In fact, all the
descriptive stats methods of the DataFrame_ class.
``align``
the alignment of the column.
Possible values are: ``"left"``, ``"center"``, and ``"right"``.
``columnWidth`` or ``flex``
the column width can be specified as a number or a percentage.
``dbfield`` (*)
the address of the database field encoded as ``"tablename.fieldname"`` or
``"tablename.fieldname.keyname"``.
``format``
the format string, e.g. ``"0,000.00"``.
``hidden``
the column is hidden when it is ``true``.
``renderer``
the string pointing to the javascript function rendering the value or
containing the function itself.
``text`` (*)
the label of the column.
``summaryType``
the summary over column values are computed.
Possible values are ``"count"``, ``"sum"``, ``"min"``, ``"max"``
and ``"average"``.
......@@ -8,70 +8,75 @@ Appendix D: Graph configuration
The graph configuration is a JSON_-type object. Its properties are mainly the
keywords arguments of the DataFrame.plot_ method.
The basic
---------
The selection of the graph type is done via the ``kind`` parameter.
For each graph type, additional parameters are available. They are those of the
underlying matplotlib functions and not detailed here:
.. list-table::
* - ``line``
- line plot
-
* - ``bar``
- vertical bar plot
- `pyplot.bar`_
* - ``barh``
- horizontal bar plot
- `pyplot.barh`_
* - ``hist``
- histogram
- `pyplot.hist`_
* - ``box``
- box plot
- `pyplot.box`_
* - ``kde``
- density estimation plot
-
* - ``area``
- area plot
-
* - ``pie``
- pie plot
- `pyplot.pie`_
* - ``scatter``
- scatter plot
- `pyplot.scatter`_
* - ``hexbin``
- hexbin plot
- `pyplot.hexbin`_
* ``hist`` or ``bar(h)`` can be stacked when ``stacked`` is ``true``.
* The scale and limit can be tuned via the parameters ``logx``, ``logy``,
``loglog``, ``xlim`` and ``ylim``.
* Grid (legend) can be deactivated when the parameters ``grid``
(``legend``) is ``false``.
* Errors bar can be set via the parameter ``xerr`` and ``yerr``.
* ...
The mapping between the columns of the report and the graph is implicit when
all columns of the DataFrame are used. It can be performed via the
parameters ``index``, ``x`` and ``y`` but depends on the graph type:
.. list-table::
:widths: 20 30
* - ``index``
- ``bar``, ``barh``, ``hist``
* - ``x`` and ``y``
- ``line plot``, ``scatter plot``, ``hexbin``
The basic keywords
------------------
``kind``
select the graph type. The parameters the underlying matplotlib functions
can be used, but not detailed here:
.. list-table::
* - ``line``
- line plot
-
* - ``bar``
- vertical bar plot
- `pyplot.bar`_
* - ``barh``
- horizontal bar plot
- `pyplot.barh`_
* - ``hist``
- histogram
- `pyplot.hist`_
* - ``box``
- box plot
- `pyplot.box`_
* - ``kde``
- density estimation plot
-
* - ``area``
- area plot
-
* - ``pie``
- pie plot
- `pyplot.pie`_
* - ``scatter``
- scatter plot
- `pyplot.scatter`_
* - ``hexbin``
- hexbin plot
- `pyplot.hexbin`_
``stacked``
histograms or bar chart are stacked when it is ``true``.
``logx``, ``logy``, ``loglog``, ``xlim`` and ``ylim``
fine tuning of the scale and axis boundaries.
``grid`` or ``legend``
deactivate grid (legend) when it is ``false``.
``xerr`` and ``yerr``.
set errors bars.
``index``, ``x`` and ``y``
The mapping between the columns of the report and the graph is implicit when
all columns of the DataFrame are used. However, it can be reduced to a set
of columns depending on the graph type:
.. list-table::
:widths: 20 30
* - ``index``
- ``bar``, ``barh``, ``hist``
* - ``x`` and ``y``
- ``line plot``, ``scatter plot``, ``hexbin``
``xlabel``, ``ylabel``
set the label along the *x* and *y*-axis respectively
Column addressing
-----------------
......@@ -95,4 +100,7 @@ in columns. In order to:
.. note::
The column label is derived from the database field address by removing
the dot, *e.g* ``tablenamefieldname``.
\ No newline at end of file
the dot, *e.g* ``tablenamefieldname``.
.. note::
The column label can also be equal to column values.
\ No newline at end of file
......@@ -28,14 +28,12 @@ display the data. In order to create a new one:
The configuration form, shown in :ref:`Fig 10`, contains two tabs:
.. list-table::
:widths: 10 70
* - ``General``
- the name of the graph, the title of the report and the
link to the list / metrics.
* - ``Configure``
- the configuration of the graph.
``General``
the name of the graph, the title of the report and the link
to the list / metrics.
``Configure``
the configuration of the graph.
Details are given in the next subsections.
......
......@@ -50,20 +50,20 @@ In order to create a ``list``:
The configuration form, shown in :ref:`Fig 5`, contains four tabs:
.. list-table::
:widths: 10 70
* - ``General``
- the name of the list, the title of the report and the conditions
to select ``history`` records.
* - ``Group``
- the database field to group rows as well as the list of
database field to sort the row of the table.
* - ``Column``
- the mapping between database field and column
as well as how the values are displayed;
* - ``Summary``
- the summary information compute for each group
``General``
the name of the list, the title of the report and the conditions
to select ``history`` records.
``Group``
the database field to group rows as well as the list of
database field to sort the row of the table.
``Column``
the mapping between database field and column as well as how
the values are displayed.
``Summary``
the summary information compute for each group
and for the whole column.
Details are given in the next subsections.
......@@ -100,13 +100,11 @@ The language used is JSON_ in which:
The configuration of a column requires a minimum of two properties:
.. list-table::
:widths: 10 70
``dbfield``
the address of the database field
* - ``dbfield``
- the address of the database field
* - ``text``
- the label of the column
``text``
the label of the column
This minimal configuration will render the value as a string.
Many more properties are available. They are detailed in :ref:`Appendix C`.
......
......@@ -57,17 +57,16 @@ order to create a new one:
The configuration form, shown in :ref:`Fig 7`, contains tree tabs:
.. list-table::
:widths: 10 70
* - ``General``
- the name of the metric 1d, the title of the report and the
conditions to select the ``history`` records.
* - ``Group``
- the database field to group values.
* - ``Column``
- the mapping between the metric and the column including
how the values are displayed;
``General``
the name of the metric 1d, the title of the report and the
conditions to select the ``history`` records.
``Group``
the database field to group values.
``Column``
the mapping between the metric and the column including
how the values are displayed;
Details are given in the next subsections.
......@@ -95,19 +94,18 @@ The language used is JSON_ in which:
The configuration of a column requires a minimum of three properties:
.. list-table::
:widths: 10 70
* - ``aggregate``
- the aggregation function applied on the values
of the database field for a fixed value of the group field.
Possible values are ``count``, ``max``, ``mean``, ``median``,
``min``, ``size``, ``std``, ``sum``... In fact, all the
descriptive stats methods of the ``pandas.DataFrame`` class
* - ``dbfield``
- the address of the database field
* - ``text``
- the label of the column
``aggregate``
the aggregation function applied on the values
of the database field for a fixed value of the group field.
Possible values are ``count``, ``max``, ``mean``, ``median``,
``min``, ``size``, ``std``, ``sum``... In fact, all the
descriptive stats methods of the DataFrame_ class.
``dbfield``
the address of the database field.
``text``
the label of the column.
In order to compute a summary for the column, use the ``summaryType`` property.
Possible values are ``count``, ``sum``, ``min``, ``max`` and
......
......@@ -50,14 +50,12 @@ defines the group fields, and the metric. In order to create a new one:
The configuration form, shown in :ref:`Fig 9`, contains two tabs:
.. list-table::
:widths: 10 70
* - ``General``
- the name of the metric 2d, the title of the report and the
conditions to select the ``history`` records.
* - ``Aggregate``
- the group field along the x and y-axis and the metric.
``General``
the name of the metric 2d, the title of the report and the
conditions to select the ``history`` records.
``Aggregate``
the group field along the x and y-axis and the metric.
Details are given in the next subsections.
......
Markdown is supported
0% or .
</