Esempio n. 1
0
    def dimension(self, expand=(0, 0, 0, 0), limits=None):
        """
        The phyical size of the scale, if a position scale
        Unlike limits, this always returns a numeric vector of length 2
        """
        if limits is None:
            limits = self.limits

        c_range = self.range_c.range
        d_range = self.limits

        if self.is_empty():
            return (0, 1)
        elif self.range.range is None:  # only continuous
            return expand_range_distinct(c_range, expand)
        elif c_range is None:  # only discrete
            # FIXME: I think this branch should not exist
            return expand_range_distinct((1, len(d_range)), expand)
        else:  # both
            # e.g categorical bar plot have discrete items, but
            # are plot on a continuous x scale
            a = np.hstack([
                c_range,
                expand_range_distinct((1, len(d_range)), expand)
                ])
            return a.min(), a.max()
Esempio n. 2
0
 def _expand_range_distinct(x, expand):
     # Expand ascending and descending order range
     if x[0] > x[1]:
         x = expand_range_distinct(x[::-1], expand)[::-1]
     else:
         x = expand_range_distinct(x, expand)
     return x
Esempio n. 3
0
        def train(scale, limits, name):
            """
            Train a single coordinate axis
            """
            # Which axis are we dealing with
            name = scale.aesthetics[0]

            if self.expand:
                expand = self.expand_default(scale)
            else:
                expand = (0, 0, 0, 0)

            if limits is None:
                rangee = scale.dimension(expand)
            else:
                rangee = scale.transform(limits)
                rangee = expand_range_distinct(rangee, expand)

            out = scale.break_info(rangee)
            # This is where
            # x_major, x_labels, x_minor, ...
            # range keys are created
            for key in list(out.keys()):
                new_key = '{}_{}'.format(name, key)
                out[new_key] = out.pop(key)
            return out
Esempio n. 4
0
        def train(scale, limits, trans, name):
            """
            Train a single coordinate axis
            """
            if limits is None:
                rangee = scale.dimension()
            else:
                rangee = scale.transform(limits)

            # data space
            out = scale.break_info(rangee)

            # trans'd range
            out['range'] = np.sort(trans.transform(out['range']))

            if limits is None:
                expand = self.expand_default(scale)
                out['range'] = expand_range_distinct(out['range'], expand)

            # major and minor breaks in plot space
            out['major'] = transform_value(trans, out['major'], out['range'])
            out['minor'] = transform_value(trans, out['minor'], out['range'])

            for key in list(out.keys()):
                new_key = '{}_{}'.format(name, key)
                out[new_key] = out.pop(key)

            return out
Esempio n. 5
0
        def train(scale, limits, trans, name):
            """
            Train a single coordinate axis
            """
            if limits is None:
                rangee = scale.dimension()
            else:
                rangee = scale.transform(limits)

            # data space
            out = scale.break_info(rangee)

            # trans'd range
            out['range'] = trans.transform(out['range'])

            if limits is None:
                expand = self.expand_default(scale)
                out['range'] = expand_range_distinct(out['range'], expand)

            # major and minor breaks in plot space
            out['major'] = transform_value(trans, out['major'], out['range'])
            out['minor'] = transform_value(trans, out['minor'], out['range'])

            for key in list(out.keys()):
                new_key = '{}_{}'.format(name, key)
                out[new_key] = out.pop(key)

            return out
Esempio n. 6
0
 def dimension(self, expand=(0, 0, 0, 0), limits=None):
     """
     The phyical size of the scale, if a position scale
     Unlike limits, this always returns a numeric vector of length 2
     """
     if limits is None:
         limits = self.limits
     return expand_range_distinct(limits, expand)
Esempio n. 7
0
def test_expand_range_distinct():
    assert expand_range_distinct((0, 1)) == (0, 1)
    assert expand_range_distinct((0, 1), (2, 0)) == (-2, 3)
    assert expand_range_distinct((0, 1), (2, 0, 2, 0)) == (-2, 3)
    assert expand_range_distinct((0, 1), (0, 2)) == (-2, 3)
    assert expand_range_distinct((0, 1), (0, 2, 0, 2)) == (-2, 3)
    assert expand_range_distinct((0, 1), (2, 2, 2, 2)) == (-4, 5)
    assert expand_range_distinct((1, 1), (2, 2), zero_width=1) == (0.5, 1.5)
Esempio n. 8
0
def test_expand_range_distinct():
    assert expand_range_distinct((0, 1)) == (0, 1)
    assert expand_range_distinct((0, 1), (2, 0)) == (-2, 3)
    assert expand_range_distinct((0, 1), (2, 0, 2, 0)) == (-2, 3)
    assert expand_range_distinct((0, 1), (0, 2)) == (-2, 3)
    assert expand_range_distinct((0, 1), (0, 2, 0, 2)) == (-2, 3)
    assert expand_range_distinct((0, 1), (2, 2, 2, 2)) == (-4, 5)
    assert expand_range_distinct((1, 1), (2, 2), zero_width=1) == (0.5, 1.5)
Esempio n. 9
0
    def dimension(self, expand=(0, 0, 0, 0)):
        """
        The phyical size of the scale, if a position scale
        Unlike limits, this always returns a numeric vector of length 2
        """
        c_range = self.range_c.range
        d_range = self.limits

        if self.is_empty():
            return (0, 1)
        elif self.range.range is None:  # only continuous
            return expand_range_distinct(c_range, expand)
        elif c_range is None:  # only discrete
            # FIXME: I think this branch should not exist
            return expand_range_distinct((1, len(d_range)), expand)
        else:  # both
            # e.g categorical bar plot have discrete items, but
            # are plot on a continuous x scale
            a = np.hstack([
                c_range,
                expand_range_distinct((1, len(d_range)), expand)
                ])
            return a.min(), a.max()