forked from svgdotjs/svg.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcircle.js
More file actions
185 lines (155 loc) · 5.08 KB
/
Copy pathcircle.js
File metadata and controls
185 lines (155 loc) · 5.08 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
describe('Circle', function() {
var circle
beforeEach(function() {
circle = draw.circle(240)
})
afterEach(function() {
draw.clear()
})
describe('x()', function() {
it('returns the value of x without an argument', function() {
expect(circle.x()).toBe(0)
})
it('sets the value of x with the first argument', function() {
circle.x(123)
var box = circle.bbox()
expect(box.x).toBe(123)
})
})
describe('y()', function() {
it('returns the value of y without an argument', function() {
expect(circle.y()).toBe(0)
})
it('sets the value of cy with the first argument', function() {
circle.y(345)
var box = circle.bbox()
expect(box.y).toBe(345)
})
})
describe('cx()', function() {
it('returns the value of cx without an argument', function() {
expect(circle.cx()).toBe(120)
})
it('sets the value of cx with the first argument', function() {
circle.cx(123)
var box = circle.bbox()
expect(box.cx).toBe(123)
})
})
describe('cy()', function() {
it('returns the value of cy without an argument', function() {
expect(circle.cy()).toBe(120)
})
it('sets the value of cy with the first argument', function() {
circle.cy(345)
var box = circle.bbox()
expect(box.cy).toBe(345)
})
})
describe('radius()', function() {
it('sets the r attribute with the first argument', function() {
circle.radius(10)
expect(circle.node.getAttribute('r')).toBe('10')
})
})
describe('rx()', function() {
it('sets the r attribute with the first argument', function() {
circle.rx(11)
expect(circle.node.getAttribute('r')).toBe('11')
})
it('gets the r attribute without and argument', function() {
circle.rx()
expect(circle.node.getAttribute('r')).toBe('120')
})
})
describe('ry()', function() {
it('sets the r attribute with the first argument', function() {
circle.ry(12)
expect(circle.node.getAttribute('r')).toBe('12')
})
it('gets the r attribute without and argument', function() {
circle.ry()
expect(circle.node.getAttribute('r')).toBe('120')
})
})
describe('move()', function() {
it('sets the x and y position', function() {
circle.move(123, 456)
var box = circle.bbox()
expect(box.x).toBe(123)
expect(box.y).toBe(456)
})
})
describe('dx()', function() {
it('moves the x positon of the element relative to the current position', function() {
circle.move(50, 60)
circle.dx(100)
expect(circle.node.getAttribute('cx')).toBe('270')
})
})
describe('dy()', function() {
it('moves the y positon of the element relative to the current position', function() {
circle.move(50, 60)
circle.dy(120)
expect(circle.node.getAttribute('cy')).toBe('300')
})
})
describe('dmove()', function() {
it('moves the x and y positon of the element relative to the current position', function() {
circle.move(50,60)
circle.dmove(80, 25)
expect(circle.node.getAttribute('cx')).toBe('250')
expect(circle.node.getAttribute('cy')).toBe('205')
})
})
describe('center()', function() {
it('sets the cx and cy position', function() {
circle.center(321,567)
var box = circle.bbox()
expect(box.cx).toBe(321)
expect(box.cy).toBe(567)
})
})
describe('width()', function() {
it('sets the width and height of the element', function() {
circle.width(82)
expect(circle.node.getAttribute('r')).toBe('41')
})
it('gets the width and height of the element if the argument is null', function() {
expect((circle.width() / 2).toString()).toBe(circle.node.getAttribute('r'))
})
})
describe('height()', function() {
it('sets the height and width of the element', function() {
circle.height(1236)
expect(circle.node.getAttribute('r')).toBe('618')
})
it('gets the height and width of the element if the argument is null', function() {
expect((circle.height() / 2).toString()).toBe(circle.node.getAttribute('r'))
})
})
describe('size()', function() {
it('defines the r of the element', function() {
circle.size(987)
expect(circle.node.getAttribute('r')).toBe((987 / 2).toString())
})
})
describe('scale()', function() {
it('should scale the element universally with one argument', function() {
var box = circle.scale(2).bbox()
expect(box.width).toBe(circle.attr('r') * 2 * 2)
expect(box.height).toBe(circle.attr('r') * 2 * 2)
})
it('should scale the element over individual x and y axes with two arguments', function() {
var box = circle.scale(2, 3.5).bbox()
expect(box.width).toBe(circle.attr('r') * 2 * 2)
expect(box.height).toBe(circle.attr('r') * 2 * 3.5)
})
})
describe('translate()', function() {
it('sets the translation of an element', function() {
circle.transform({ x: 12, y: 12 })
expect(circle.node.getAttribute('transform')).toBe('matrix(1,0,0,1,12,12)')
})
})
})