summaryrefslogtreecommitdiffstats
path: root/src/line.js
diff options
context:
space:
mode:
authorwout <wout@impinc.co.uk>2014-02-03 15:14:47 +0100
committerwout <wout@impinc.co.uk>2014-02-03 15:14:47 +0100
commite2304534e0cfb6f6f4ab8c37ea5275ae26cd455a (patch)
tree2386e9f361d9c5fa1308387aeeaf33f00241b3c5 /src/line.js
parent7a29817ffd764cf7ab6906250b57f234801c94e0 (diff)
downloadsvg.js-e2304534e0cfb6f6f4ab8c37ea5275ae26cd455a.tar.gz
svg.js-e2304534e0cfb6f6f4ab8c37ea5275ae26cd455a.zip
Implemented SVG.invent function and bumped to v1.0rc3
Diffstat (limited to 'src/line.js')
-rwxr-xr-xsrc/line.js131
1 files changed, 65 insertions, 66 deletions
diff --git a/src/line.js b/src/line.js
index e049ccb..bdbbcde 100755
--- a/src/line.js
+++ b/src/line.js
@@ -1,75 +1,74 @@
-SVG.Line = function() {
- this.constructor.call(this, SVG.create('line'))
-}
+SVG.Line = SVG.invent({
+ // Initialize node
+ create: 'line'
-// Inherit from SVG.Shape
-SVG.Line.prototype = new SVG.Shape
+ // Inherit from
+, inherit: SVG.Shape
-// Add required methods
-SVG.extend(SVG.Line, {
- // Move over x-axis
- x: function(x) {
- var b = this.bbox()
-
- return x == null ? b.x : this.attr({
- x1: this.attr('x1') - b.x + x
- , x2: this.attr('x2') - b.x + x
- })
- }
- // Move over y-axis
-, y: function(y) {
- var b = this.bbox()
-
- return y == null ? b.y : this.attr({
- y1: this.attr('y1') - b.y + y
- , y2: this.attr('y2') - b.y + y
- })
- }
- // Move by center over x-axis
-, cx: function(x) {
- var half = this.bbox().width / 2
- return x == null ? this.x() + half : this.x(x - half)
- }
- // Move by center over y-axis
-, cy: function(y) {
- var half = this.bbox().height / 2
- return y == null ? this.y() + half : this.y(y - half)
- }
- // Set width of element
-, width: function(width) {
- var b = this.bbox()
+ // Add class methods
+, extend: {
+ // Move over x-axis
+ x: function(x) {
+ var b = this.bbox()
+
+ return x == null ? b.x : this.attr({
+ x1: this.attr('x1') - b.x + x
+ , x2: this.attr('x2') - b.x + x
+ })
+ }
+ // Move over y-axis
+ , y: function(y) {
+ var b = this.bbox()
+
+ return y == null ? b.y : this.attr({
+ y1: this.attr('y1') - b.y + y
+ , y2: this.attr('y2') - b.y + y
+ })
+ }
+ // Move by center over x-axis
+ , cx: function(x) {
+ var half = this.bbox().width / 2
+ return x == null ? this.x() + half : this.x(x - half)
+ }
+ // Move by center over y-axis
+ , cy: function(y) {
+ var half = this.bbox().height / 2
+ return y == null ? this.y() + half : this.y(y - half)
+ }
+ // Set width of element
+ , width: function(width) {
+ var b = this.bbox()
- return width == null ? b.width : this.attr(this.attr('x1') < this.attr('x2') ? 'x2' : 'x1', b.x + width)
- }
- // Set height of element
-, height: function(height) {
- var b = this.bbox()
+ return width == null ? b.width : this.attr(this.attr('x1') < this.attr('x2') ? 'x2' : 'x1', b.x + width)
+ }
+ // Set height of element
+ , height: function(height) {
+ var b = this.bbox()
- return height == null ? b.height : this.attr(this.attr('y1') < this.attr('y2') ? 'y2' : 'y1', b.y + height)
- }
- // Set line size by width and height
-, size: function(width, height) {
- var p = this._proportionalSize(width, height)
+ return height == null ? b.height : this.attr(this.attr('y1') < this.attr('y2') ? 'y2' : 'y1', b.y + height)
+ }
+ // Set line size by width and height
+ , size: function(width, height) {
+ var p = this._proportionalSize(width, height)
- return this.width(p.width).height(p.height)
- }
- // Set path data
-, plot: function(x1, y1, x2, y2) {
- return this.attr({
- x1: x1
- , y1: y1
- , x2: x2
- , y2: y2
- })
+ return this.width(p.width).height(p.height)
+ }
+ // Set path data
+ , plot: function(x1, y1, x2, y2) {
+ return this.attr({
+ x1: x1
+ , y1: y1
+ , x2: x2
+ , y2: y2
+ })
+ }
}
-})
-
-//
-SVG.extend(SVG.Container, {
- // Create a line element
- line: function(x1, y1, x2, y2) {
- return this.put(new SVG.Line().plot(x1, y1, x2, y2))
+ // Add parent method
+, construct: {
+ // Create a line element
+ line: function(x1, y1, x2, y2) {
+ return this.put(new SVG.Line().plot(x1, y1, x2, y2))
+ }
}
-
})