morris.area.coffee 1.7 KB

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