aboutsummaryrefslogtreecommitdiffstats
path: root/src/textpath.js
blob: 0ee9d7771611d777d53924ce2ced204fe2527eee (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
SVG.TextPath = SVG.invent({
  // Initialize node
  create: 'textPath'

  // Inherit from
, inherit: SVG.Element

  // Define parent class
, parent: SVG.Text

  // Add parent method
, construct: {
    // Create path for text to run on
    path: function(d) {
      /* create textPath element */
      this.textPath = new SVG.TextPath

      /* move lines to textpath */
      while(this.node.hasChildNodes())
        this.textPath.node.appendChild(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)

      /* create circular reference */
      this.textPath.parent = this

      /* link textPath to path and add content */
      this.textPath.attr('href', '#' + this.track, SVG.xlink)

      return this
    }
    // Plot path if any
  , plot: function(d) {
      if (this.track) this.track.plot(d)
      return this
    }
  }
})