Skip to content

Commit

Permalink
Cycle lineColors (#78)
Browse files Browse the repository at this point in the history
Fixes crashes when number of series is larger than number of line colors.
  • Loading branch information
oesmith committed Sep 25, 2012
1 parent 50833b0 commit a9b0e03
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
10 changes: 7 additions & 3 deletions lib/morris.line.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ class Morris.Line
if coords.length > 1
path = @createPath coords, @options.marginTop, @left, @options.marginTop + @height, @left + @width
@r.path(path)
.attr('stroke', @options.lineColors[i])
.attr('stroke', @colorForSeries(i))
.attr('stroke-width', @options.lineWidth)
@seriesPoints = ([] for i in [0..@seriesCoords.length-1])
for i in [@seriesCoords.length-1..0]
Expand All @@ -292,7 +292,7 @@ class Morris.Line
circle = null
else
circle = @r.circle(c.x, c.y, @options.pointSize)
.attr('fill', @options.lineColors[i])
.attr('fill', @colorForSeries(i))
.attr('stroke-width', 1)
.attr('stroke', '#ffffff')
@seriesPoints[i].push(circle)
Expand Down Expand Up @@ -355,7 +355,7 @@ class Morris.Line
@yLabels = []
for i in [0..@series.length-1]
yLabel = @r.text(0, @options.hoverFontSize * 1.5 * (i + 1.5) - @hoverHeight / 2, '')
.attr('fill', @options.lineColors[i])
.attr('fill', @colorForSeries(i))
.attr('font-size', @options.hoverFontSize)
@yLabels.push(yLabel)
@hoverSet.push(yLabel)
Expand Down Expand Up @@ -423,6 +423,10 @@ class Morris.Line
yLabelFormat: (label) ->
"#{@options.preUnits}#{Morris.commas(label)}#{@options.postUnits}"

# @private
colorForSeries: (index) ->
@options.lineColors[index % @options.lineColors.length]


# Parse a date into a javascript timestamp
#
Expand Down
10 changes: 7 additions & 3 deletions morris.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a9b0e03

Please sign in to comment.