aboutsummaryrefslogtreecommitdiffstats
path: root/src/elements/Line.js
diff options
context:
space:
mode:
authorSaivan <savian@me.com>2018-11-25 16:21:53 +1300
committerSaivan <savian@me.com>2018-11-25 16:21:53 +1300
commit62de7d0a1b994b69032a759b796b486e6bc382e3 (patch)
tree112b19f2903b4dc5b4cf61ebef0d021c6ca2f14d /src/elements/Line.js
parent2b37d7ba5b4267b39c86f9aba5fb14a1b376e846 (diff)
downloadsvg.js-62de7d0a1b994b69032a759b796b486e6bc382e3.tar.gz
svg.js-62de7d0a1b994b69032a759b796b486e6bc382e3.zip
Changed the esLint rules to avoid silly ternary operators, and to let code breathe!
This commit modifies some of the eslint rules, to allow our code to be a little bit more readable. This came about because we had a particularly pesky problem, where the code was indenting ternary operators. This fixes that, and makes it easy to add new rules to eslint as we please in the future. Changes ======= - Rebuilt the library with new eslint rules - Changed the eslintrc file to a yaml file by default
Diffstat (limited to 'src/elements/Line.js')
-rw-r--r--src/elements/Line.js68
1 files changed, 44 insertions, 24 deletions
diff --git a/src/elements/Line.js b/src/elements/Line.js
index 99e7497..123f2bb 100644
--- a/src/elements/Line.js
+++ b/src/elements/Line.js
@@ -11,58 +11,78 @@ import Shape from './Shape.js'
import * as pointed from '../modules/core/pointed.js'
export default class Line extends Shape {
+
// Initialize node
- constructor (node) {
- super(nodeOrNew('line', node), node)
+ constructor ( node ) {
+
+ super( nodeOrNew( 'line', node ), node )
+
}
// Get array
array () {
- return new PointArray([
- [ this.attr('x1'), this.attr('y1') ],
- [ this.attr('x2'), this.attr('y2') ]
- ])
+
+ return new PointArray( [
+ [ this.attr( 'x1' ), this.attr( 'y1' ) ],
+ [ this.attr( 'x2' ), this.attr( 'y2' ) ]
+ ] )
+
}
// Overwrite native plot() method
- plot (x1, y1, x2, y2) {
- if (x1 == null) {
+ plot ( x1, y1, x2, y2 ) {
+
+ if ( x1 == null ) {
+
return this.array()
- } else if (typeof y1 !== 'undefined') {
+
+ } else if ( typeof y1 !== 'undefined' ) {
+
x1 = { x1: x1, y1: y1, x2: x2, y2: y2 }
+
} else {
- x1 = new PointArray(x1).toLine()
+
+ x1 = new PointArray( x1 ).toLine()
+
}
- return this.attr(x1)
+ return this.attr( x1 )
+
}
// Move by left top corner
- move (x, y) {
- return this.attr(this.array().move(x, y).toLine())
+ move ( x, y ) {
+
+ return this.attr( this.array().move( x, y ).toLine() )
+
}
// Set element size to given width and height
- size (width, height) {
- var p = proportionalSize(this, width, height)
- return this.attr(this.array().size(p.width, p.height).toLine())
+ size ( width, height ) {
+
+ var p = proportionalSize( this, width, height )
+ return this.attr( this.array().size( p.width, p.height ).toLine() )
+
}
+
}
-extend(Line, pointed)
+extend( Line, pointed )
-registerMethods({
+registerMethods( {
Container: {
// Create a line element
- line: wrapWithAttrCheck(function (...args) {
+ line: wrapWithAttrCheck( function ( ...args ) {
+
// make sure plot is called as a setter
// x1 is not necessarily a number, it can also be an array, a string and a PointArray
return Line.prototype.plot.apply(
- this.put(new Line())
- , args[0] != null ? args : [0, 0, 0, 0]
+ this.put( new Line() )
+ , args[0] != null ? args : [ 0, 0, 0, 0 ]
)
- })
+
+ } )
}
-})
+} )
-register(Line)
+register( Line )