Пример #1
0
    def _y_axis(self):
        """Make the y axis: labels and guides"""
        if not self._y_labels or not self.show_y_labels:
            return

        axis = self.svg.node(self.nodes['plot'], class_="axis y")

        if (0 not in [label[1] for label in self._y_labels] and
                self.show_y_guides):
            self.svg.node(
                axis, 'path',
                d='M%f %f h%f' % (0, self.view.height, self.view.width),
                class_='line'
            )
        for label, position in self._y_labels:
            major = is_major(position)
            guides = self.svg.node(axis, class_='%sguides' % (
                'logarithmic ' if self.logarithmic else ''
            ))
            x = -5
            y = self.view.y(position)
            if not y:
                continue
            if self.show_y_guides:
                self.svg.node(
                    guides, 'path',
                    d='M%f %f h%f' % (0, y, self.view.width),
                    class_='%s%sline' % (
                        'major ' if major else '',
                        'guide ' if position != 0 else ''))
            text = self.svg.node(
                guides, 'text',
                x=x,
                y=y + .35 * self.label_font_size,
                class_='major' if major else ''
            )
            text.text = label
            if self.y_label_rotation:
                text.attrib['transform'] = "rotate(%d %f %f)" % (
                    self.y_label_rotation, x, y)

        if self._y_2nd_labels:
            secondary_ax = self.svg.node(
                self.nodes['plot'], class_="axis y2")
            for label, position in self._y_2nd_labels:
                major = is_major(position)
                # it is needed, to have the same structure as primary axis
                guides = self.svg.node(secondary_ax, class_='guides')
                x = self.view.width + 5
                y = self.view.y(position)
                text = self.svg.node(
                    guides, 'text',
                    x=x,
                    y=y + .35 * self.label_font_size,
                    class_='major' if major else ''
                )
                text.text = label
                if self.y_label_rotation:
                    text.attrib['transform'] = "rotate(%d %f %f)" % (
                        self.y_label_rotation, x, y)
Пример #2
0
    def _y_axis(self):
        """Make the y axis: labels and guides"""
        if not self._y_labels or not self.show_y_labels:
            return

        axis = self.svg.node(self.nodes['plot'], class_="axis y")

        if (0 not in [label[1] for label in self._y_labels]
                and self.show_y_guides):
            self.svg.node(axis,
                          'path',
                          d='M%f %f h%f' %
                          (0, self.view.height, self.view.width),
                          class_='line')
        for label, position in self._y_labels:
            major = is_major(position)
            guides = self.svg.node(
                axis,
                class_='%sguides' %
                ('logarithmic ' if self.logarithmic else ''))
            x = -5
            y = self.view.y(position)
            if not y:
                continue
            if self.show_y_guides:
                self.svg.node(guides,
                              'path',
                              d='M%f %f h%f' % (0, y, self.view.width),
                              class_='%s%sline' %
                              ('major ' if major else '',
                               'guide ' if position != 0 else ''))
            text = self.svg.node(guides,
                                 'text',
                                 x=x,
                                 y=y + .35 * self.label_font_size,
                                 class_='major' if major else '')
            text.text = label
            if self.y_label_rotation:
                text.attrib['transform'] = "rotate(%d %f %f)" % (
                    self.y_label_rotation, x, y)

        if self._y_2nd_labels:
            secondary_ax = self.svg.node(self.nodes['plot'], class_="axis y2")
            for label, position in self._y_2nd_labels:
                major = is_major(position)
                # it is needed, to have the same structure as primary axis
                guides = self.svg.node(secondary_ax, class_='guides')
                x = self.view.width + 5
                y = self.view.y(position)
                text = self.svg.node(guides,
                                     'text',
                                     x=x,
                                     y=y + .35 * self.label_font_size,
                                     class_='major' if major else '')
                text.text = label
                if self.y_label_rotation:
                    text.attrib['transform'] = "rotate(%d %f %f)" % (
                        self.y_label_rotation, x, y)
Пример #3
0
    def _y_axis(self, draw_axes=True):
        """Make the y axis: labels and guides"""
        if not self._y_labels:
            return

        axis = self.svg.node(self.nodes['plot'], class_="axis y")

        if 0 not in [label[1] for label in self._y_labels] and draw_axes:
            self.svg.node(axis, 'path',
                      d='M%f %f h%f' % (0, self.view.height, self.view.width),
                      class_='line')
        for label, position in self._y_labels:
            major = is_major(position)
            guides = self.svg.node(axis, class_='%sguides' % (
                'logarithmic ' if self.logarithmic else ''
            ))
            x = -5
            y = self.view.y(position)
            if draw_axes:
                self.svg.node(
                    guides, 'path',
                    d='M%f %f h%f' % (0, y, self.view.width),
                    class_='%s%sline' % (
                        'major ' if major else '',
                        'guide ' if position != 0 else ''))
            text = self.svg.node(guides, 'text',
                                 x=x,
                                 y=y + .35 * self.label_font_size,
                                 class_='major' if major else ''
            )
            text.text = label
            if self.y_label_rotation:
                text.attrib['transform'] = "rotate(%d %f %f)" % (
                    self.y_label_rotation, x, y)
Пример #4
0
    def _y_axis(self, draw_axes=True):
        """Make the y axis: labels and guides"""
        if not self._y_labels:
            return

        axis = self.svg.node(self.nodes["plot"], class_="axis y")

        if 0 not in [label[1] for label in self._y_labels] and draw_axes:
            self.svg.node(axis, "path", d="M%f %f h%f" % (0, self.view.height, self.view.width), class_="line")
        for label, position in self._y_labels:
            major = is_major(position)
            guides = self.svg.node(axis, class_="%sguides" % ("logarithmic " if self.logarithmic else ""))
            x = -5
            y = self.view.y(position)
            if draw_axes:
                self.svg.node(
                    guides,
                    "path",
                    d="M%f %f h%f" % (0, y, self.view.width),
                    class_="%s%sline" % ("major " if major else "", "guide " if position != 0 else ""),
                )
            text = self.svg.node(
                guides, "text", x=x, y=y + 0.35 * self.label_font_size, class_="major" if major else ""
            )
            text.text = label
            if self.y_label_rotation:
                text.attrib["transform"] = "rotate(%d %f %f)" % (self.y_label_rotation, x, y)
Пример #5
0
    def _y_axis(self):
        """Make the y axis: labels and guides"""
        if not self._y_labels or not self.show_y_labels:
            return

        axis = self.svg.node(self.nodes["plot"], class_="axis y")

        if 0 not in [label[1] for label in self._y_labels] and self.show_y_guides:
            self.svg.node(axis, "path", d="M%f %f h%f" % (0, self.view.height, self.view.width), class_="line")
        for label, position in self._y_labels:
            major = is_major(position)
            guides = self.svg.node(axis, class_="%sguides" % ("logarithmic " if self.logarithmic else ""))
            x = -5
            y = self.view.y(position)
            if not y:
                continue
            if self.show_y_guides:
                self.svg.node(
                    guides,
                    "path",
                    d="M%f %f h%f" % (0, y, self.view.width),
                    class_="%s%sline" % ("major " if major else "", "guide " if position != 0 else ""),
                )
            text = self.svg.node(
                guides, "text", x=x, y=y + 0.35 * self.label_font_size, class_="major" if major else ""
            )
            text.text = label
            if self.y_label_rotation:
                text.attrib["transform"] = "rotate(%d %f %f)" % (self.y_label_rotation, x, y)

        if self._y_2nd_labels:
            secondary_ax = self.svg.node(self.nodes["plot"], class_="axis y2")
            for label, position in self._y_2nd_labels:
                major = is_major(position)
                # it is needed, to have the same structure as primary axis
                guides = self.svg.node(secondary_ax, class_="guides")
                x = self.view.width + 5
                y = self.view.y(position)
                text = self.svg.node(
                    guides, "text", x=x, y=y + 0.35 * self.label_font_size, class_="major" if major else ""
                )
                text.text = label
                if self.y_label_rotation:
                    text.attrib["transform"] = "rotate(%d %f %f)" % (self.y_label_rotation, x, y)
Пример #6
0
    def _x_axis(self, draw_axes=True):
        """Make the x axis: labels and guides"""
        if not self._x_labels:
            return
        axis = self.svg.node(self.nodes['plot'], class_="axis x")
        truncation = self.truncate_label
        if not truncation:
            if self.x_label_rotation or len(self._x_labels) <= 1:
                truncation = 25
            else:
                first_label_position = self.view.x(self._x_labels[0][1])
                last_label_position = self.view.x(self._x_labels[-1][1])
                available_space = (
                    last_label_position - first_label_position) / (
                        len(self._x_labels) - 1)
                truncation = reverse_text_len(
                    available_space, self.label_font_size)

        if 0 not in [label[1] for label in self._x_labels] and draw_axes:
            self.svg.node(axis, 'path',
                          d='M%f %f v%f' % (0, 0, self.view.height),
                          class_='line')
        for label, position in self._x_labels:
            major = is_major(position)
            guides = self.svg.node(axis, class_='guides')
            x = self.view.x(position)
            y = self.view.height + 5
            if draw_axes:
                self.svg.node(
                    guides, 'path',
                    d='M%f %f v%f' % (x, 0, self.view.height),
                    class_='%s%sline' % (
                        'major ' if major else '',
                        'guide ' if position != 0 else ''))
            y += .5 * self.label_font_size + 5
            text = self.svg.node(
                guides, 'text',
                x=x,
                y=y,
                class_='major' if major else ''
            )
            text.text = truncate(label, truncation)
            if text.text != label:
                self.svg.node(guides, 'title').text = label
            if self.x_label_rotation:
                text.attrib['transform'] = "rotate(%d %f %f)" % (
                    self.x_label_rotation, x, y)
Пример #7
0
    def _y_axis(self, draw_axes=True):
        if not self._y_labels:
            return

        axis = self.svg.node(self.nodes["plot"], class_="axis y web")

        for label, r in reversed(self._y_labels):
            major = is_major(r)
            guides = self.svg.node(axis, class_="guides")
            self.svg.line(
                guides,
                [self.view((r, theta)) for theta in self.x_pos],
                close=True,
                class_="%sguide line" % ("major " if major else ""),
            )
            x, y = self.view((r, self.x_pos[0]))
            self.svg.node(guides, "text", x=x - 5, y=y, class_="major" if major else "").text = label
Пример #8
0
    def _x_axis(self, draw_axes=True):
        """Make the x axis: labels and guides"""
        if not self._x_labels:
            return
        axis = self.svg.node(self.nodes['plot'], class_="axis x")
        truncation = self.truncate_label
        if not truncation:
            if self.x_label_rotation or len(self._x_labels) <= 1:
                truncation = 25
            else:
                first_label_position = self.view.x(self._x_labels[0][1])
                last_label_position = self.view.x(self._x_labels[-1][1])
                available_space = (last_label_position - first_label_position
                                   ) / (len(self._x_labels) - 1)
                truncation = reverse_text_len(available_space,
                                              self.label_font_size)

        if 0 not in [label[1] for label in self._x_labels] and draw_axes:
            self.svg.node(axis,
                          'path',
                          d='M%f %f v%f' % (0, 0, self.view.height),
                          class_='line')
        for label, position in self._x_labels:
            major = is_major(position)
            guides = self.svg.node(axis, class_='guides')
            x = self.view.x(position)
            y = self.view.height + 5
            if draw_axes:
                self.svg.node(guides,
                              'path',
                              d='M%f %f v%f' % (x, 0, self.view.height),
                              class_='%s%sline' %
                              ('major ' if major else '',
                               'guide ' if position != 0 else ''))
            y += .5 * self.label_font_size + 5
            text = self.svg.node(guides,
                                 'text',
                                 x=x,
                                 y=y,
                                 class_='major' if major else '')
            text.text = truncate(label, truncation)
            if text.text != label:
                self.svg.node(guides, 'title').text = label
            if self.x_label_rotation:
                text.attrib['transform'] = "rotate(%d %f %f)" % (
                    self.x_label_rotation, x, y)
Пример #9
0
    def _y_axis(self, draw_axes=True):
        if not self._y_labels:
            return

        axis = self.svg.node(self.nodes['plot'], class_="axis y web")

        for label, r in reversed(self._y_labels):
            major = is_major(r)
            guides = self.svg.node(axis, class_='guides')
            self.svg.line(guides,
                          [self.view((r, theta)) for theta in self.x_pos],
                          close=True,
                          class_='%sguide line' % ('major ' if major else ''))
            x, y = self.view((r, self.x_pos[0]))
            self.svg.node(guides,
                          'text',
                          x=x - 5,
                          y=y,
                          class_='major' if major else '').text = label
Пример #10
0
    def _y_axis(self, draw_axes=True):
        if not self._y_labels:
            return

        axis = self.svg.node(self.nodes['plot'], class_="axis y web")

        for label, r in reversed(self._y_labels):
            major = is_major(r)
            guides = self.svg.node(axis, class_='guides')
            self.svg.line(
                guides, [self.view((r, theta)) for theta in self.x_pos],
                close=True,
                class_='%sguide line' % (
                    'major ' if major else ''))
            x, y = self.view((r, self.x_pos[0]))
            self.svg.node(
                guides, 'text',
                x=x - 5,
                y=y,
                class_='major' if major else ''
            ).text = label
Пример #11
0
def test_is_major():
    for n in (0, 1, 1000, 10., 0.1, 0.000001, -10, -.001000, -100.):
        assert is_major(n)
    for n in (2, 10002., 100000.0003, -200, -0.0005):
        assert not is_major(n)
Пример #12
0
def test_is_major():
    for n in (0, 1, 1000, 10., 0.1, 0.000001, -10, -.001000, -100.):
        assert is_major(n)
    for n in (2, 10002., 100000.0003, -200, -0.0005):
        assert not is_major(n)