summaryrefslogtreecommitdiffstats
path: root/src/elements/TextPath.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/elements/TextPath.js')
-rw-r--r--src/elements/TextPath.js78
1 files changed, 52 insertions, 26 deletions
diff --git a/src/elements/TextPath.js b/src/elements/TextPath.js
index 91c48ae..af89ef7 100644
--- a/src/elements/TextPath.js
+++ b/src/elements/TextPath.js
@@ -7,80 +7,106 @@ import Text from './Text.js'
import baseFind from '../modules/core/selector.js'
export default class TextPath extends Text {
+
// Initialize node
- constructor (node) {
- super(nodeOrNew('textPath', node), node)
+ constructor ( node ) {
+
+ super( nodeOrNew( 'textPath', node ), node )
+
}
// return the array of the path track element
array () {
+
var track = this.track()
return track ? track.array() : null
+
}
// Plot path if any
- plot (d) {
+ plot ( d ) {
+
var track = this.track()
var pathArray = null
- if (track) {
- pathArray = track.plot(d)
+ if ( track ) {
+
+ pathArray = track.plot( d )
+
}
- return (d == null) ? pathArray : this
+ return ( d == null ) ? pathArray : this
+
}
// Get the path element
track () {
- return this.reference('href')
+
+ return this.reference( 'href' )
+
}
+
}
-registerMethods({
+registerMethods( {
Container: {
- textPath: wrapWithAttrCheck(function (text, path) {
- return this.defs().path(path).text(text).addTo(this)
- })
+ textPath: wrapWithAttrCheck( function ( text, path ) {
+
+ return this.defs().path( path ).text( text ).addTo( this )
+
+ } )
},
Text: {
// Create path for text to run on
- path: wrapWithAttrCheck(function (track) {
+ path: wrapWithAttrCheck( function ( track ) {
+
var path = new TextPath()
// if track is a path, reuse it
- if (!(track instanceof Path)) {
+ if ( !( track instanceof Path ) ) {
+
// create path element
- track = this.root().defs().path(track)
+ track = this.root().defs().path( track )
+
}
// link textPath to path and add content
- path.attr('href', '#' + track, xlink)
+ path.attr( 'href', '#' + track, xlink )
// add textPath element as child node and return textPath
- return this.put(path)
- }),
+ return this.put( path )
+
+ } ),
// Get the textPath children
textPath () {
- return this.find('textPath')[0]
+
+ return this.find( 'textPath' )[0]
+
}
},
Path: {
// creates a textPath from this path
- text: wrapWithAttrCheck(function (text) {
- if (text instanceof Text) {
+ text: wrapWithAttrCheck( function ( text ) {
+
+ if ( text instanceof Text ) {
+
var txt = text.text()
- return text.clear().path(this).text(txt)
+ return text.clear().path( this ).text( txt )
+
}
- return this.parent().put(new Text()).path(this).text(text)
- }),
+ return this.parent().put( new Text() ).path( this ).text( text )
+
+ } ),
targets () {
- return baseFind('svg [href*="' + this.id() + '"]')
+
+ return baseFind( 'svg [href*="' + this.id() + '"]' )
+
}
}
-})
+} )
TextPath.prototype.MorphArray = PathArray
-register(TextPath)
+register( TextPath )