def line(self, node, coords, close=False, **kwargs): """Draw a svg line""" if len(coords) < 2: return root = "M%s L%s Z" if close else "M%s L%s" origin_index = 0 while None in coords[origin_index]: origin_index += 1 origin = coord_format(coords[origin_index]) line = " ".join([coord_format(c) for c in coords[origin_index + 1 :] if None not in c]) self.node(node, "path", d=root % (origin, line), **kwargs)
def line(self, node, coords, close=False, **kwargs): """Draw a svg line""" line_len = len(coords) if line_len < 2: return root = 'M%s L%s Z' if close else 'M%s L%s' origin_index = 0 while origin_index < line_len and None in coords[origin_index]: origin_index += 1 if origin_index == line_len: return origin = coord_format(coords[origin_index]) line = ' '.join([ coord_format(c) for c in coords[origin_index + 1:] if None not in c ]) self.node(node, 'path', d=root % (origin, line), **kwargs)
def line(self, node, coords, close=False, **kwargs): """Draw a svg line""" line_len = len(coords) if line_len < 2: return root = 'M%s L%s Z' if close else 'M%s L%s' origin_index = 0 while origin_index < line_len and None in coords[origin_index]: origin_index += 1 if origin_index == line_len: return origin = coord_format(coords[origin_index]) line = ' '.join([coord_format(c) for c in coords[origin_index + 1:] if None not in c]) self.node(node, 'path', d=root % (origin, line), **kwargs)
def line(self, node, coords, close=False, **kwargs): """Draw a svg line""" line_len = len(coords) if len([c for c in coords if c[1] is not None]) < 2: return root = "M%s L%s Z" if close else "M%s L%s" origin_index = 0 while origin_index < line_len and None in coords[origin_index]: origin_index += 1 if origin_index == line_len: return if self.graph.horizontal: coord_format = lambda xy: "%f %f" % (xy[1], xy[0]) else: coord_format = lambda xy: "%f %f" % xy origin = coord_format(coords[origin_index]) line = " ".join([coord_format(c) for c in coords[origin_index + 1 :] if None not in c]) return self.node(node, "path", d=root % (origin, line), **kwargs)
def line(self, node, coords, close=False, **kwargs): """Draw a svg line""" line_len = len(coords) if len([c for c in coords if c[1] is not None]) < 2: return root = 'M%s L%s Z' if close else 'M%s L%s' origin_index = 0 while origin_index < line_len and None in coords[origin_index]: origin_index += 1 if origin_index == line_len: return if self.graph.horizontal: coord_format = lambda xy: '%f %f' % (xy[1], xy[0]) else: coord_format = lambda xy: '%f %f' % xy origin = coord_format(coords[origin_index]) line = ' '.join([ coord_format(c) for c in coords[origin_index + 1:] if None not in c ]) return self.node(node, 'path', d=root % (origin, line), **kwargs)
def _x_axis(self, draw_axes=True): """Override x axis to make it polar""" if not self._x_labels or not self.show_x_labels: return axis = self.svg.node(self.nodes['plot'], class_="axis x web%s" % (' always_show' if self.show_x_guides else '')) format_ = coord_format(x) center = self.view((0, 0)) r = self._rmax # Can't simply determine truncation truncation = self.truncate_label or 25 for label, theta in self._x_labels: major = label in self._x_labels_major if not (self.show_minor_x_labels or major): continue guides = self.svg.node(axis, class_='guides') end = self.view((r, theta)) self.svg.node( guides, 'path', d='M%s L%s' % (format_(center), format_(end)), class_='%s%sline' % ('axis ' if label == "0" else '', 'major ' if major else '')) r_txt = (1 - self._box.__class__.margin) * self._box.ymax pos_text = self.view((r_txt, theta)) text = self.svg.node(guides, 'text', x=pos_text[0], y=pos_text[1], class_='major' if major else '') text.text = truncate(label, truncation) if text.text != label: self.svg.node(guides, 'title').text = label else: self.svg.node( guides, 'title', ).text = self._x_format(theta) angle = -theta + pi / 2 if cos(angle) < 0: angle -= pi text.attrib['transform'] = 'rotate(%s %s)' % (float_format( self.x_label_rotation or deg(angle)), format_(pos_text))
def _x_axis(self, draw_axes=True): """Override x axis to make it polar""" if not self._x_labels or not self.show_x_labels: return axis = self.svg.node(self.nodes['plot'], class_="axis x web%s" % ( ' always_show' if self.show_x_guides else '' )) format_ = coord_format(x) center = self.view((0, 0)) r = self._rmax # Can't simply determine truncation truncation = self.truncate_label or 25 for label, theta in self._x_labels: major = label in self._x_labels_major if not (self.show_minor_x_labels or major): continue guides = self.svg.node(axis, class_='guides') end = self.view((r, theta)) self.svg.node( guides, 'path', d='M%s L%s' % (format_(center), format_(end)), class_='%s%sline' % ( 'axis ' if label == "0" else '', 'major ' if major else '')) r_txt = (1 - self._box.__class__.margin) * self._box.ymax pos_text = self.view((r_txt, theta)) text = self.svg.node( guides, 'text', x=pos_text[0], y=pos_text[1], class_='major' if major else '') text.text = truncate(label, truncation) if text.text != label: self.svg.node(guides, 'title').text = label else: self.svg.node( guides, 'title', ).text = self._x_format(theta) angle = - theta + pi / 2 if cos(angle) < 0: angle -= pi text.attrib['transform'] = 'rotate(%s %s)' % ( float_format(self.x_label_rotation or deg(angle)), format_(pos_text))
def line(self, node, coords, close=False, **kwargs): """Draw a svg line""" line_len = len(coords) if len([c for c in coords if c[1] is not None]) < 2: return root = 'M%s L%s Z' if close else 'M%s L%s' origin_index = 0 while origin_index < line_len and None in coords[origin_index]: origin_index += 1 if origin_index == line_len: return if self.graph.horizontal: coord_format_ = lambda xy: coord_format((xy[1], xy[0])) #lambda xy: '%f %f' % (xy[1], xy[0]) else: coord_format_ = coord_format #lambda xy: '%f %f' % xy origin = coord_format_(coords[origin_index]) line = ' '.join([coord_format_(c) for c in coords[origin_index + 1:] if None not in c]) return self.node( node, 'path', d=root % (origin, line), **kwargs)
def point(x, y): return coord_format(self.view((x, y)))