forked from svgdotjs/svg.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmarker.js
More file actions
89 lines (69 loc) · 2.64 KB
/
Copy pathmarker.js
File metadata and controls
89 lines (69 loc) · 2.64 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
describe('Marker', function() {
describe('on a container element', function() {
var marker
beforeEach(function() {
marker = draw.marker(10, 12, function(add) {
add.rect(10, 12)
this.ref(5, 6)
})
})
it('creates an instance of SVG.Marker', function() {
expect(marker instanceof SVG.Marker).toBeTruthy()
})
it('creates marker in defs', function() {
expect(marker.parent() instanceof SVG.Defs).toBeTruthy()
})
describe('marker()', function() {
it('returns the marker element', function() {
expect(marker = draw.marker(10, 12)).toBe(marker)
})
it('sets the refX to half of the given width', function() {
marker = draw.marker(10, 12)
expect(marker.node.getAttribute('refX')).toBe('5')
})
it('sets the refY to half of the given height', function() {
marker = draw.marker(13, 15)
expect(marker.node.getAttribute('refY')).toBe('7.5')
})
})
})
describe('on a target path', function() {
var path, marker
beforeEach(function() {
path = draw.path('M 100 200 C 200 100 300 0 400 100 C 500 200 600 300 700 200 C 800 100 900 100 900 100')
path.marker('mid', 10, 12, function(add) {
add.rect(10, 12)
this.ref(5, 6)
})
marker = path.marker('mid', 10, 10)
})
it('creates an instance of SVG.Marker', function() {
expect(path.reference('marker-mid') instanceof SVG.Marker).toBeTruthy()
})
describe('marker()', function() {
it('returns the target element', function() {
expect(path.marker('start', 10, 12)).toBe(path)
})
it('creates a marker and applies it to the marker-start attribute', function() {
path.marker('start', 10, 12)
marker = path.reference('marker-start')
expect(path.node.getAttribute('marker-start')).toBe(marker.toString())
})
it('creates a marker and applies it to the marker-mid attribute', function() {
path.marker('mid', 10, 12)
marker = path.reference('marker-mid')
expect(path.node.getAttribute('marker-mid')).toBe(marker.toString())
})
it('creates a marker and applies it to the marker-end attribute', function() {
path.marker('end', 10, 12)
marker = path.reference('marker-end')
expect(path.node.getAttribute('marker-end')).toBe(marker.toString())
})
it('accepts an instance of an existing marker element as the second argument', function() {
marker = draw.marker(11, 11)
path.marker('mid', marker)
expect(path.node.getAttribute('marker-mid')).toBe(marker.toString())
})
})
})
})