svgwrite_diagram: implement draw_circle, draw_line and draw_rect
authorAntonio Ospite <ao2@ao2.it>
Tue, 26 Jun 2018 13:49:50 +0000 (15:49 +0200)
committerAntonio Ospite <ao2@ao2.it>
Wed, 27 Jun 2018 13:17:03 +0000 (15:17 +0200)
Complete the implementation of the svgwrite diagram backend by
implementing the missing methods.

src/diagram/svgwrite_diagram.py

index 1da39a2..c4b76af 100755 (executable)
@@ -138,6 +138,34 @@ class SvgwriteDiagram(Diagram):
             self._stroke(line, stroke_color)
             self.add(line)
 
             self._stroke(line, stroke_color)
             self.add(line)
 
+    def draw_circle(self, cx, cy, radius=10.0,
+                    stroke_color=None,
+                    fill_color=(0, 0, 0, 0.5)):
+        circle = self.svg.circle((cx, cy), radius)
+
+        self._fill(circle, fill_color)
+        self._stroke(circle, stroke_color)
+
+        self.add(circle)
+
+    def draw_line(self, x1, y1, x2, y2, stroke_color=(0, 0, 0, 1)):
+        line = self.svg.line((x1, y1), (x1, y2))
+        self._stroke(line, stroke_color)
+
+        self.add(line)
+
+    def draw_rect(self, x, y, width, height, theta=0,
+                  stroke_color=None,
+                  fill_color=(1, 1, 1, 0.8)):
+        rect = self.svg.rect((x, y), (width, height))
+
+        rect['transform'] = 'rotate(%f, %f, %f)' % (degrees(theta), x, y)
+
+        self._fill(rect, fill_color)
+        self._stroke(rect, stroke_color)
+
+        self.add(rect)
+
     def draw_centered_text(self, cx, cy, text, theta=0.0,
                            color=(0, 0, 0),
                            align_baseline=False,
     def draw_centered_text(self, cx, cy, text, theta=0.0,
                            color=(0, 0, 0),
                            align_baseline=False,