Skip to content

Commit a0076d7

Browse files
author
wout
committed
Added plot() method to SVG.Line
1 parent 20e9f67 commit a0076d7

5 files changed

Lines changed: 33 additions & 5 deletions

File tree

dist/svg.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* svg.js v0.11 - svg regex default color viewbox bbox element container fx event group arrange defs mask clip pattern gradient doc shape rect ellipse line poly path plotable image text nested sugar - svgjs.com/license */
1+
/* svg.js v0.11-4-g20e9f67 - svg regex default color viewbox bbox element container fx event group arrange defs mask clip pattern gradient doc shape rect ellipse line poly path plotable image text nested sugar - svgjs.com/license */
22
;(function() {
33

44
this.SVG = function(element) {
@@ -846,7 +846,7 @@
846846
}
847847
// Create a line element
848848
, line: function(x1, y1, x2, y2) {
849-
return this.put(new SVG.Line().attr({ x1: x1, y1: y1, x2: x2, y2: y2 }))
849+
return this.put(new SVG.Line().plot(x1, y1, x2, y2))
850850
}
851851
// Create a wrapped polyline element
852852
, polyline: function(points) {
@@ -1740,6 +1740,15 @@
17401740
.attr(this.attr('x1') < this.attr('x2') ? 'x2' : 'x1', b.x + width)
17411741
.attr(this.attr('y1') < this.attr('y2') ? 'y2' : 'y1', b.y + height)
17421742
}
1743+
// Set path data
1744+
, plot: function(x1, y1, x2, y2) {
1745+
return this.attr({
1746+
x1: x1
1747+
, y1: y1
1748+
, x2: x2
1749+
, y2: y2
1750+
})
1751+
}
17431752

17441753
})
17451754

dist/svg.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/spec/line.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,16 @@ describe('Line', function() {
9999
})
100100
})
101101

102+
describe('plot()', function() {
103+
it('should update the start and end points', function() {
104+
line.plot(100,200,300,400)
105+
expect(line.node.getAttribute('x1')).toBe('100')
106+
expect(line.node.getAttribute('y1')).toBe('200')
107+
expect(line.node.getAttribute('x2')).toBe('300')
108+
expect(line.node.getAttribute('y2')).toBe('400')
109+
})
110+
})
111+
102112
})
103113

104114

src/container.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ SVG.extend(SVG.Container, {
8787
}
8888
// Create a line element
8989
, line: function(x1, y1, x2, y2) {
90-
return this.put(new SVG.Line().attr({ x1: x1, y1: y1, x2: x2, y2: y2 }))
90+
return this.put(new SVG.Line().plot(x1, y1, x2, y2))
9191
}
9292
// Create a wrapped polyline element
9393
, polyline: function(points) {

src/line.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,14 @@ SVG.extend(SVG.Line, {
4343
.attr(this.attr('x1') < this.attr('x2') ? 'x2' : 'x1', b.x + width)
4444
.attr(this.attr('y1') < this.attr('y2') ? 'y2' : 'y1', b.y + height)
4545
}
46+
// Set path data
47+
, plot: function(x1, y1, x2, y2) {
48+
return this.attr({
49+
x1: x1
50+
, y1: y1
51+
, x2: x2
52+
, y2: y2
53+
})
54+
}
4655

4756
})

0 commit comments

Comments
 (0)