Exemple #1
0
 def _lcg_presentation(self):
     presentation = lcg.Presentation()
     if self._vmargin == 0:
         presentation.separator_margin = lcg.UMm(0)
     else:
         presentation.separator_margin = lcg.UFont(0.2)
     return presentation
Exemple #2
0
 def body(self):
     content_1 = lcg.coerce('xxx')
     content_2 = lcg.VSpace(lcg.UMm(500))
     return pytis.output.Document(
         lcg.Container((
             content_1,
             content_2,
             content_1,
         )))
Exemple #3
0
 def _lcg(self):
     if self._orientation == self.VERTICAL:
         mark = lcg.VSpace
     elif self._orientation == self.HORIZONTAL:
         mark = lcg.HSpace
     else:
         raise Exception('Unexpected orientation', self._orientation)
     size = self._size
     if size is None:
         size = lcg.UAny(1)
     elif not isinstance(size, lcg.Unit):
         size = lcg.UMm(self._size)
     return mark(size)
Exemple #4
0
 def page_layout(self):
     return {
         pytis.output.PAGE_WIDTH: lcg.UMm(210),
         pytis.output.PAGE_HEIGHT: lcg.UMm(297),
         pytis.output.PAGE_LANDSCAPE_MODE: False,
         pytis.output.PAGE_TOP_MARGIN: lcg.UMm(10),
         pytis.output.PAGE_BOTTOM_MARGIN: lcg.UMm(20),
         pytis.output.PAGE_LEFT_MARGIN: lcg.UMm(10),
         pytis.output.PAGE_RIGHT_MARGIN: lcg.UMm(10),
     }
Exemple #5
0
    def __init__(self, data, size=(250, 120), title=None, xlabel=None, ylabel=None,
                 xformatter=None, yformatter=None, legend=None, annotate=False,
                 grid=False, lines=(), plot_labels=None):
        """Arguments:

          data: 'pandas.DataFrame' instance or a sequence of sequences
            containing the data to be visualized by the plot.  If sequence,
            each item is a pair, where the first value is the x coordinate and
            the second value is the y coordinate of one graph point.  There may
            be also more y values in each item.  In this case several
            lines will appear in the plot sharing the x coordinates and
            differing y coordinates.
          size: total plot size as a pair of 'lcg.Unit' subclass instances or
            numeric values which will be converted to 'lcg.UMm'.
          title: Title to be displayed above the plot as a string.
          xlabel: x axis label as a human readable string.
          ylabel: y axis label as a human readable string.
          xformatter: x axis tick label formater as a function of three
            arguments (context, value, position), where context is the LCG
            export context, value is the matplotlib's internal value
            representation and position is the tick position numbered from 0.
            This module defines several formatter classes for most common
            cases, such as 'DateFormatter', 'DateTimeFormatter',
            'MonetaryFormatter' which respect LCG localization.
            'DateFormatter' is used automatically for the x axis if it contains
            datetime values.
          yformatter: as xformatter but for the y axis values.
          legend: optional sequence of plot labels as human readable
            strings.  Useful for distinction when there are several plots (data
            contain multiple y values).  The number of labels must correspond to
            the number of y values in 'data'.
          annotate: If True, each plot point (x, y pair present in data) will
            be labeled by the y value directly within the plot.
          grid: Controls grid lines.  May be a single value to control the
            major grid (minor is off), a tuple of two values (major, minor) or
            four values (major-x, major-y, minor-x, minor-y).  Major grid
            connects to labeled axis values, minor grid provides finer
            subdivision.  Each value may be a boolean to turn the grid on or
            off or a 'lcg.plot.Line' instance defining properties in more
            detail.
          lines: Additional vertical or horizontal lines added to the graph as
            a sequence of 'Line' instances.  Lines must define 'x' (for
            vertical lines) or 'y' (for horizontal lines) position as a value
            compatible with other values of that axis.

        """
        if not isinstance(data, pandas.DataFrame):
            data = pandas.DataFrame([x[1:] for x in data],
                                    index=[x[0] for x in data],
                                    columns=['column%d' % n for n in range(len(data[0]) - 1)])
        if not xformatter and isinstance(data.index[0], datetime.date):
            xformatter = DateFormatter()
        self._data = data
        self._size = [x if isinstance(x, lcg.Unit) else lcg.UMm(x) for x in size]
        self._title = title
        self._xlabel = xlabel
        self._ylabel = ylabel
        self._xformatter = xformatter
        self._yformatter = yformatter
        # The former (deprecated) argument name is 'plot_labels'.
        self._legend = legend or plot_labels or [None for x in data.columns]
        self._annotate = annotate
        if grid is False:
            grid = None
        elif grid is True:
            grid = (True, True, False, False)
        else:
            assert isinstance(grid, (tuple, list))
            if len(grid) == 2:
                major, minor = grid
                grid = (major, major, minor, minor)
            else:
                assert len(grid) == 4
        self._grid = grid
        self._lines = lines
        super(BasePlot, self).__init__(self._svg)
Exemple #6
0
 def _dimension(self, x):
     return x if x is None or isinstance(x, lcg.Unit) else lcg.UMm(x)
Exemple #7
0
 def _lcg_presentation(self):
     if self._vmargin == 0:
         margin = lcg.UMm(0)
     else:
         margin = lcg.UFont(0.2)
     return lcg.Presentation(separator_margin=margin)
Exemple #8
0
    def body(self):
        spec = self._parameter(pytis.output.P_NAME)
        parts = []
        row = self._parameter((
            spec,
            pytis.output.P_ROW,
        ))
        id_continent = row['id']
        pcond = pd.EQ('continent', id_continent)

        parts.append(pytis.output.Center(self._parameter('title')))

        columns = (
            pytis.output.Table.Column(
                'Alpha-2',
                lcg.UMm(10),
                label_alignment=pytis.output.Table.Column.ALIGN_LEFT,
                alignment=pytis.output.Table.Column.ALIGN_LEFT,
            ),
            pytis.output.Table.Column(
                'Alpha-3',
                lcg.UMm(10),
                label_alignment=pytis.output.Table.Column.ALIGN_LEFT,
                alignment=pytis.output.Table.Column.ALIGN_LEFT,
            ),
            pytis.output.Table.Column(
                'Numeric',
                lcg.UMm(10),
                label_alignment=pytis.output.Table.Column.ALIGN_LEFT,
                alignment=pytis.output.Table.Column.ALIGN_LEFT,
            ),
            pytis.output.Table.Column(
                'Continent',
                lcg.UMm(10),
                label_alignment=pytis.output.Table.Column.ALIGN_LEFT,
                alignment=pytis.output.Table.Column.ALIGN_LEFT,
            ),
            pytis.output.Table.Column(
                'Short name',
                lcg.UMm(60),
                label_alignment=pytis.output.Table.Column.ALIGN_LEFT,
                alignment=pytis.output.Table.Column.ALIGN_LEFT,
            ),
            pytis.output.Table.Column(
                'Full name',
                lcg.UMm(70),
                label_alignment=pytis.output.Table.Column.ALIGN_LEFT,
                alignment=pytis.output.Table.Column.ALIGN_LEFT,
            ),
        )

        def data_table(condition):
            def generator_init():
                self._data.select(condition=condition)

            def generator():
                row = self._data.fetchone()
                if row is None:
                    return None
                id_ = row['id'].export()
                id3 = row['id3'].export()
                num = row['num'].export()
                continent = row['continent'].export()
                name = row['name'].export()
                fullname = row['fullname'].export()
                return (id_, id3, num, continent, name, fullname)

            table = pytis.output.LongTable(columns,
                                           generator,
                                           row_generator_init=generator_init,
                                           separator_height=1.2,
                                           separator_margin=2)
            return table

        table_countries = data_table(pcond)
        parts.append(pytis.output.VSpace(lcg.UFont(1)))
        parts.append(pytis.output.f_smaller(table_countries))
        return pytis.output.Document(pytis.output.Group(*parts, vertical=True))