How to use the leather.utils.X 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_triples(self):
        data = [
            ('foo', 1, 'a'),
            ('bar', 2, 'a'),
            ('baz', 3, 'b')
        ]

        series = leather.CategorySeries(data)

        self.assertSequenceEqual(series.values(X), ['foo', 'bar', 'baz'])
        self.assertSequenceEqual(series.values(Y), [1, 2, 3])
        self.assertSequenceEqual(series.values(Z), ['a', 'a', 'b'])
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 / chart.py View on Github external
header_margin += legend_height
            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))
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 / 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.')
github wireservice / leather / leather / series / category.py View on Github external
def data(self):
        """
        Return data for this series grouped for rendering.
        """
        x = self._keys[X]
        y = self._keys[Y]
        z = self._keys[Z]

        for i, row in enumerate(self._data):
            yield Datum(i, x(row, i), y(row, i), z(row, i), row)
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 / series / category.py View on Github external
def __init__(self, data, x=None, y=None, z=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._make_key(z if z is not None else Z)
        ]

        self._types = [
            self._infer_type(X),
            self._infer_type(Y),
            self._infer_type(Z)
        ]