-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
shapes.coffee
32 lines (30 loc) · 999 Bytes
/
shapes.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
###
Supports keys of the form "shape class class ..."
where "shape" is one of "circle" or "square" or "triangle",
and "class" are CSS classes.
###
export shapes =
circle: (attrs) ->
<symbol viewBox="-50 -50 100 100">
<circle {...attrs} r="40"/>
</symbol>
square: (attrs) ->
<symbol viewBox="-10 -10 100 100">
<rect {...attrs} width="80" height="80"/>
</symbol>
triangle: (attrs) ->
r = 45
coords =
for i in [0...3]
[r * Math.cos (i/3+1/12) * Math.PI*2
r * Math.sin (i/3+1/12) * Math.PI*2]
<symbol viewBox="-50 -50 100 100">
<path {...attrs} d={'M' + coords.join('L') + 'Z'}/>
</symbol>
(key) ->
[shape, classes...] = key.split /\s+/
attrs = class: classes.join(' ') or undefined
# `or undefined` needed or SVG parser complains about empty class attribute
## `svgtiler.static` wrapper indicates that symbol depends only on key,
## not any other context in the drawing.
svgtiler.static shapes[shape] attrs