コード例 #1
0
ファイル: lattice.py プロジェクト: imoapps/leather
    def to_svg(self, path=None, width=None, height=None):
        """
        Render the lattice to an SVG.

        See :class:`.Grid` for additional documentation.
        """
        if not self._scales[X]:
            self._scales[X] = Scale.infer(self._series, X, self._types[X])

        if not self._scales[Y]:
            self._scales[Y] = Scale.infer(self._series, Y, self._types[Y])

        if not self._axes[X]:
            self._axes[X] = Axis()

        if not self._axes[Y]:
            self._axes[Y] = Axis()

        grid = Grid()

        for i, series in enumerate(self._series):
            chart = Chart(title=series._name)
            chart.set_x_scale(self._scales[X])
            chart.set_y_scale(self._scales[Y])
            chart.set_x_axis(self._axes[X])
            chart.set_y_axis(self._axes[Y])
            chart.add_series(series)

            grid.add_one(chart)

        return grid.to_svg(path, width, height)
コード例 #2
0
    def _validate_dimension(self, dimension):
        """
        Validates that the given scale and axis are valid for the data that
        has been added to this chart. If a scale or axis has not been set,
        generates automated ones.
        """
        scale = self._scales[dimension]
        axis = self._axes[dimension]

        if not scale:
            scale = Scale.infer(self._layers, dimension,
                                self._types[dimension])
        else:
            for series, shape in self._layers:
                if not scale.contains(
                        series.min(dimension)) or not scale.contains(
                            series.max(dimension)):
                    d = DIMENSION_NAMES[dimension]
                    warn(
                        'Data contains values outside %s scale domain. All data points may not be visible on the chart.'
                        % d)

                    # Only display once per axis
                    break

        if not axis:
            axis = Axis()

        return (scale, axis)
コード例 #3
0
ファイル: chart.py プロジェクト: imoapps/leather
    def add_x_axis(self, ticks=None, tick_values=None, tick_formatter=None, name=None):
        """
        Create and add an X :class:`.Axis`.

        If you want to set a custom axis class use :meth:`.set_x_axis` instead.
        """
        self._axes[X] = Axis(ticks, tick_values, tick_formatter, name)
コード例 #4
0
 def add_y_axis(self, ticks=None, tick_formatter=None, name=None):
     """
     See :meth:`.Lattice.add_x_axis`.
     """
     self._axes[Y] = Axis(ticks=ticks,
                          tick_formatter=tick_formatter,
                          name=name)
コード例 #5
0
ファイル: chart.py プロジェクト: imoapps/leather
    def _validate_dimension(self, dimension):
        """
        Validates that the given scale and axis are valid for the data that
        has been added to this chart. If a scale or axis has not been set,
        generates automated ones.
        """
        scale = self._scales[dimension]
        axis = self._axes[dimension]

        if not scale:
            scale = Scale.infer(self._layers, dimension, self._types[dimension])
        else:
            scale = scale

        if not axis:
            axis = Axis()

        return (scale, axis)