Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1 | espaco | 1 | class Morris.Area extends Morris.Line |
| 2 | # Initialise |
||
| 3 | # |
||
| 4 | areaDefaults = |
||
| 5 | fillOpacity: 'auto' |
||
| 6 | behaveLikeLine: false |
||
| 7 | |||
| 8 | constructor: (options) -> |
||
| 9 | return new Morris.Area(options) unless (@ instanceof Morris.Area) |
||
| 10 | areaOptions = $.extend {}, areaDefaults, options |
||
| 11 | |||
| 12 | @cumulative = not areaOptions.behaveLikeLine |
||
| 13 | |||
| 14 | if areaOptions.fillOpacity is 'auto' |
||
| 15 | areaOptions.fillOpacity = if areaOptions.behaveLikeLine then .8 else 1 |
||
| 16 | |||
| 17 | super(areaOptions) |
||
| 18 | |||
| 19 | # calculate series data point coordinates |
||
| 20 | # |
||
| 21 | # @private |
||
| 22 | calcPoints: -> |
||
| 23 | for row in @data |
||
| 24 | row._x = @transX(row.x) |
||
| 25 | total = 0 |
||
| 26 | row._y = for y in row.y |
||
| 27 | if @options.behaveLikeLine |
||
| 28 | @transY(y) |
||
| 29 | else |
||
| 30 | total += (y || 0) |
||
| 31 | @transY(total) |
||
| 32 | row._ymax = Math.max row._y... |
||
| 33 | |||
| 34 | # draw the data series |
||
| 35 | # |
||
| 36 | # @private |
||
| 37 | drawSeries: -> |
||
| 38 | @seriesPoints = [] |
||
| 39 | if @options.behaveLikeLine |
||
| 40 | range = [0..@options.ykeys.length-1] |
||
| 41 | else |
||
| 42 | range = [@options.ykeys.length-1..0] |
||
| 43 | |||
| 44 | for i in range |
||
| 45 | @_drawFillFor i |
||
| 46 | @_drawLineFor i |
||
| 47 | @_drawPointFor i |
||
| 48 | |||
| 49 | _drawFillFor: (index) -> |
||
| 50 | path = @paths[index] |
||
| 51 | if path isnt null |
||
| 52 | path = path + "L#{@transX(@xmax)},#{@bottom}L#{@transX(@xmin)},#{@bottom}Z" |
||
| 53 | @drawFilledPath path, @fillForSeries(index) |
||
| 54 | |||
| 55 | fillForSeries: (i) -> |
||
| 56 | color = Raphael.rgb2hsl @colorFor(@data[i], i, 'line') |
||
| 57 | Raphael.hsl( |
||
| 58 | color.h, |
||
| 59 | if @options.behaveLikeLine then color.s * 0.9 else color.s * 0.75, |
||
| 60 | Math.min(0.98, if @options.behaveLikeLine then color.l * 1.2 else color.l * 1.25)) |
||
| 61 | |||
| 62 | drawFilledPath: (path, fill) -> |
||
| 63 | @raphael.path(path) |
||
| 64 | .attr('fill', fill) |
||
| 65 | .attr('fill-opacity', @options.fillOpacity) |
||
| 66 | .attr('stroke', 'none') |