From e1923c04a61926cb570e7d4f63e321e7eff3b74f Mon Sep 17 00:00:00 2001 From: rekado Date: Wed, 28 Sep 2016 22:49:22 +0200 Subject: Add simple SVG helper procedures. --- scales/svg.scm | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 scales/svg.scm 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)) -- cgit v1.2.3