How to use the leather.utils.Y function in leather

To help you get started, we’ve selected a few leather examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wireservice / leather / tests / test_series.py View on Github external
def test_dicts(self):
        data = [
            {'a': 'foo', 'b': 1, 'c': 4},
            {'a': 'bar', 'b': 2, 'c': 5},
            {'a': 'baz', 'b': 3, 'c': 6}
        ]

        with self.assertRaises(KeyError):
            series = leather.Series(data)

        series = leather.Series(data, x='c', y='a')

        self.assertSequenceEqual(series.values(X), [4, 5, 6])
        self.assertSequenceEqual(series.values(Y), ['foo', 'bar', 'baz'])
github wireservice / leather / leather / shapes / dots.py View on Github external
def validate_series(self, series):
        """
        Verify this shape can be used to render a given series.
        """
        if series.data_type(X) is Text or series.data_type(Y) is Text:
            raise ValueError('Dots do not support Text values.')

        return True
github wireservice / leather / leather / series / base.py View on Github external
def __init__(self, data, x=None, y=None, name=None):
        self._data = data
        self._name = name

        self._keys = [
            self._make_key(x if x is not None else X),
            self._make_key(y if y is not None else Y)
        ]

        self._types = [
            self._infer_type(X),
            self._infer_type(Y)
        ]
github wireservice / leather / leather / series / base.py View on Github external
def data(self):
        """
        Return data for this series.
        """
        x = self._keys[X]
        y = self._keys[Y]

        for i, row in enumerate(self._data):
            yield Datum(i, x(row, i), y(row, i), None, row)
github wireservice / leather / leather / lattice.py View on Github external
def set_y_scale(self, scale):
        """
        See :meth:`.Lattice.set_x_scale`.
        """
        self._scales[Y] = scale
github wireservice / leather / leather / lattice.py View on Github external
Render the lattice to an SVG.

        See :class:`.Grid` for additional documentation.
        """
        layers = [(s, self._shape) for s in self._series]

        if not self._scales[X]:
            self._scales[X] = Scale.infer(layers, X, self._types[X])

        if not self._scales[Y]:
            self._scales[Y]= Scale.infer(layers, 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, self._shape)

            grid.add_one(chart)

        return grid.to_svg(path, width, height)
github wireservice / leather / leather / chart.py View on Github external
header_group.append(legend_group)

        margin_group.append(header_group)

        # Body
        body_group = ET.Element('g')
        body_group.set('transform', svg.translate(0, header_margin))

        body_width = margin_width
        body_height = margin_height - header_margin

        margin_group.append(body_group)

        # Axes
        x_scale, x_axis = self._validate_dimension(X)
        y_scale, y_axis = self._validate_dimension(Y)

        bottom_margin = x_axis.estimate_label_margin(x_scale, 'bottom')
        left_margin = y_axis.estimate_label_margin(y_scale, 'left')

        canvas_width = body_width - left_margin
        canvas_height = body_height - bottom_margin

        axes_group = ET.Element('g')
        axes_group.set('transform', svg.translate(left_margin, 0))

        axes_group.append(x_axis.to_svg(canvas_width, canvas_height, x_scale, 'bottom'))
        axes_group.append(y_axis.to_svg(canvas_width, canvas_height, y_scale, 'left'))

        header_group.set('transform', svg.translate(left_margin, 0))

        body_group.append(axes_group)
github wireservice / leather / leather / shapes / line.py View on Github external
def validate_series(self, series):
        """
        Verify this shape can be used to render a given series.
        """
        if isinstance(series, CategorySeries):
            raise ValueError('Line can not be used to render CategorySeries.')

        if series.data_type(X) is Text or series.data_type(Y) is Text:
            raise ValueError('Line does not support Text values.')
github wireservice / leather / leather / shapes / columns.py View on Github external
def validate_series(self, series):
        """
        Verify this shape can be used to render a given series.
        """
        if isinstance(series, CategorySeries):
            raise ValueError('Columns can not be used to render CategorySeries.')

        if series.data_type(X) is not Text:
            raise ValueError('Bars only support Text values for the X axis.')

        if series.data_type(Y) is not Number:
            raise ValueError('Bars only support Number values for the Y axis.')
github wireservice / leather / leather / shapes / bars.py View on Github external
def validate_series(self, series):
        """
        Verify this shape can be used to render a given series.
        """
        if isinstance(series, CategorySeries):
            raise ValueError('Bars can not be used to render CategorySeries.')

        if series.data_type(X) is not Number:
            raise ValueError('Bars only support Number values for the Y axis.')

        if series.data_type(Y) is not Text:
            raise ValueError('Bars only support Text values for the X axis.')