diff options
Diffstat (limited to 'src/elements/Marker.js')
-rw-r--r-- | src/elements/Marker.js | 80 |
1 files changed, 29 insertions, 51 deletions
diff --git a/src/elements/Marker.js b/src/elements/Marker.js index 1054987..238f559 100644 --- a/src/elements/Marker.js +++ b/src/elements/Marker.js @@ -3,103 +3,81 @@ import { registerMethods } from '../utils/methods.js' import Container from './Container.js' export default class Marker extends Container { - // Initialize node - constructor ( node ) { - - super( nodeOrNew( 'marker', node ), node ) - + constructor (node) { + super(nodeOrNew('marker', node), node) } // Set width of element - width ( width ) { - - return this.attr( 'markerWidth', width ) - + width (width) { + return this.attr('markerWidth', width) } // Set height of element - height ( height ) { - - return this.attr( 'markerHeight', height ) - + height (height) { + return this.attr('markerHeight', height) } // Set marker refX and refY - ref ( x, y ) { - - return this.attr( 'refX', x ).attr( 'refY', y ) - + ref (x, y) { + return this.attr('refX', x).attr('refY', y) } // Update marker - update ( block ) { - + update (block) { // remove all content this.clear() // invoke passed block - if ( typeof block === 'function' ) { - - block.call( this, this ) - + if (typeof block === 'function') { + block.call(this, this) } return this - } // Return the fill id toString () { - return 'url(#' + this.id() + ')' - } - } -registerMethods( { +registerMethods({ Container: { - marker ( ...args ) { - + marker (...args) { // Create marker element in defs - return this.defs().marker( ...args ) - + return this.defs().marker(...args) } }, Defs: { // Create marker - marker: wrapWithAttrCheck( function ( width, height, block ) { - + marker: wrapWithAttrCheck(function (width, height, block) { // Set default viewbox to match the width and height, set ref to cx and cy and set orient to auto - return this.put( new Marker() ) - .size( width, height ) - .ref( width / 2, height / 2 ) - .viewbox( 0, 0, width, height ) - .attr( 'orient', 'auto' ) - .update( block ) - - } ) + return this.put(new Marker()) + .size(width, height) + .ref(width / 2, height / 2) + .viewbox(0, 0, width, height) + .attr('orient', 'auto') + .update(block) + }) }, marker: { // Create and attach markers - marker ( marker, width, height, block ) { - + marker (marker, width, height, block) { var attr = [ 'marker' ] // Build attribute name - if ( marker !== 'all' ) attr.push( marker ) - attr = attr.join( '-' ) + if (marker !== 'all') attr.push(marker) + attr = attr.join('-') // Set marker attribute marker = arguments[1] instanceof Marker ? arguments[1] - : this.defs().marker( width, height, block ) - - return this.attr( attr, marker ) + : this.defs().marker(width, height, block) + return this.attr(attr, marker) } } -} ) +}) -register( Marker ) +register(Marker) |