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
|
SVG.Path = SVG.invent({
// Initialize node
create: 'path'
// Inherit from
, inherit: SVG.Shape
// Add class methods
, extend: {
// Define morphable array
morphArray: SVG.PathArray
// Get array
, array: function() {
return this._array || (this._array = new SVG.PathArray(this.attr('d')))
}
// Plot new poly points
, plot: function(p) {
return this.attr('d', (this._array = new SVG.PathArray(p)))
}
// Move by left top corner
, move: function(x, y) {
return this.attr('d', this.array().move(x, y))
}
// Move by left top corner over x-axis
, x: function(x) {
return x == null ? this.bbox().x : this.move(x, this.bbox().y)
}
// Move by left top corner over y-axis
, y: function(y) {
return y == null ? this.bbox().y : this.move(this.bbox().x, y)
}
// Set element size to given width and height
, size: function(width, height) {
var p = proportionalSize(this, width, height)
return this.attr('d', this.array().size(p.width, p.height))
}
// Set width of element
, width: function(width) {
return width == null ? this.bbox().width : this.size(width, this.bbox().height)
}
// Set height of element
, height: function(height) {
return height == null ? this.bbox().height : this.size(this.bbox().width, height)
}
}
// Add parent method
, construct: {
// Create a wrapped path element
path: function(d) {
return this.put(new SVG.Path).plot(d)
}
}
})
|