aboutsummaryrefslogtreecommitdiffstats
path: root/src/pattern.js
blob: 48070498b63b286a3adbd8727c610065fe575143 (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
SVG.Pattern = function(type) {
  this.constructor.call(this, SVG.create('pattern'))
}

// Inherit from SVG.Container
SVG.Pattern.prototype = new SVG.Container

//
SVG.extend(SVG.Pattern, {
  // Return the fill id
  fill: function() {
    return 'url(#' + this.attr('id') + ')'
  }
  // Alias string convertion to fill
, toString: function() {
    return this.fill()
  }
  
})

//
SVG.extend(SVG.Defs, {
  // Define gradient
  pattern: function(width, height, block) {
    var element = this.put(new SVG.Pattern)
    
    /* invoke passed block */
    block(element)
    
    return element.attr({
      x:            0
    , y:            0
    , width:        width
    , height:       height
    , patternUnits: 'userSpaceOnUse'
    })
  }
  
})

//
SVG.extend(SVG.Container, {
  // Create pattern element in defs
  pattern: function(width, height, block) {
    return this.defs().pattern(width, height, block)
  }

})