How to use the leather.scales.Scale.infer 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 / leather / chart.py View on Github external
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)
github wireservice / leather / leather / lattice.py View on Github external
def to_svg(self, path=None, width=None, height=None):
        """
        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)
github wireservice / leather / leather / lattice.py View on Github external
def to_svg(self, path=None, width=None, height=None):
        """
        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])