blob: dfe015231b5e08a3c42ce27640fa79b8057257db (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
SVG.TextPath = function() {
this.constructor.call(this, SVG.create('textPath'))
}
// Inherit from SVG.Element
SVG.TextPath.prototype = new SVG.Path
//
SVG.extend(SVG.TextPath, {
text: function(text) {
/* remove children */
while (this.node.firstChild)
this.node.removeChild(this.node.firstChild)
/* add text */
this.node.appendChild(document.createTextNode(text))
return this.parent
}
})
//
SVG.extend(SVG.Text, {
// Create path for text to run on
path: function(d) {
/* create textPath element */
this.textPath = new SVG.TextPath
/* remove all child nodes */
while (this.node.firstChild)
this.node.removeChild(this.node.firstChild)
/* add textPath element as child node */
this.node.appendChild(this.textPath.node)
/* create path in defs */
this.track = this.doc().defs().path(d, true)
/* create circular reference */
this.textPath.parent = this
/* alias local text() method to textPath's text() method */
this.text = function(text) {
return this.textPath.text(text)
}
/* alias plot() method on track */
this.plot = function(d) {
this.track.plot(d)
return this
}
/* link textPath to path and add content */
return this.textPath.attr('href', '#' + this.track, SVG.xlink).text(this.content)
}
})
|