summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrekado <rekado@elephly.net>2016-09-28 22:49:22 +0200
committerrekado <rekado@elephly.net>2016-09-28 22:49:22 +0200
commite1923c04a61926cb570e7d4f63e321e7eff3b74f (patch)
treeb5c4ef7cfc4db3d91f99f95036be29ae27fad7a6
parent35237b4ac87ba94553df339a39a0988b027bf191 (diff)
Add simple SVG helper procedures.
-rw-r--r--scales/svg.scm61
1 files changed, 61 insertions, 0 deletions
diff --git a/scales/svg.scm b/scales/svg.scm
new file mode 100644
index 0000000..f07034a
--- /dev/null
+++ b/scales/svg.scm
@@ -0,0 +1,61 @@
+(define-module (scales svg)
+ #:use-module (sxml simple)
+ #:export (line
+ circle
+ rectangle
+ text
+ svg
+
+ translate))
+
+(define* (line x1 y1 x2 y2
+ #:optional (style ""))
+ `(line (@ (x1 ,x1)
+ (y1 ,y1)
+ (x2 ,x2)
+ (y2 ,y2)
+ (style ,style))))
+
+(define* (circle x y radius
+ #:optional (style ""))
+ `(circle (@ (cx ,x)
+ (cy ,y)
+ (r ,radius)
+ (style ,style))))
+
+(define* (rectangle x y width height
+ #:optional
+ (rx 0)
+ (ry 0)
+ (style ""))
+ `(rect (@ (x ,x)
+ (y ,y)
+ (width ,width)
+ (height ,height)
+ (rx ,rx)
+ (ry ,ry)
+ (style ,style))))
+
+(define* (text x y text
+ #:optional (style ""))
+ `(text (@ (x ,x)
+ (y ,y)
+ (style ,style))
+ ,text))
+
+(define* (svg exp
+ #:optional
+ (attributes
+ '((width 1200)
+ (height 1200)
+ (viewBox "0 0 1200 1200")
+ (xmlns "http://www.w3.org/2000/svg"))))
+ (call-with-output-string
+ (lambda (port)
+ (sxml->xml `(svg (@ ,@attributes) ,exp) port))))
+
+(define (translate x y exp)
+ `(g (@ (transform ,(string-append "translate("
+ (number->string x) ","
+ (number->string y) ")")))
+ ,exp))