63 lines
1.5 KiB
JavaScript
63 lines
1.5 KiB
JavaScript
SVG.TextPath = SVG.invent({
|
|
// Initialize node
|
|
create: 'textPath'
|
|
|
|
// Inherit from
|
|
, inherit: SVG.Parent
|
|
|
|
// Define parent class
|
|
, parent: SVG.Text
|
|
|
|
// Add parent method
|
|
, construct: {
|
|
morphArray: SVG.PathArray
|
|
// Create path for text to run on
|
|
, path: function(d) {
|
|
// create textPath element
|
|
var path = new SVG.TextPath
|
|
, track = this.doc().defs().path(d)
|
|
|
|
// move lines to textpath
|
|
while (this.node.hasChildNodes())
|
|
path.node.appendChild(this.node.firstChild)
|
|
|
|
// add textPath element as child node
|
|
this.node.appendChild(path.node)
|
|
|
|
// link textPath to path and add content
|
|
path.attr('href', '#' + track, SVG.xlink)
|
|
|
|
return this
|
|
}
|
|
// return the array of the path track element
|
|
, array: function() {
|
|
var track = this.track()
|
|
|
|
return track ? track.array() : null
|
|
}
|
|
// Plot path if any
|
|
, plot: function(d) {
|
|
var track = this.track()
|
|
, pathArray = null
|
|
|
|
if (track) {
|
|
pathArray = track.plot(d)
|
|
}
|
|
|
|
return (d == null) ? pathArray : this
|
|
}
|
|
// Get the path track element
|
|
, track: function() {
|
|
var path = this.textPath()
|
|
|
|
if (path)
|
|
return path.reference('href')
|
|
}
|
|
// Get the textPath child
|
|
, textPath: function() {
|
|
if (this.node.firstChild && this.node.firstChild.nodeName == 'textPath')
|
|
return SVG.adopt(this.node.firstChild)
|
|
}
|
|
}
|
|
})
|