Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make line widths customizable #272

Merged
merged 5 commits into from
Oct 12, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 30 additions & 11 deletions lib/morris.line.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ class Morris.Line extends Morris.Grid

init: ->
# Some instance variables for later
@pointGrow = Raphael.animation r: @options.pointSize + 3, 25, 'linear'
@pointShrink = Raphael.animation r: @options.pointSize, 25, 'linear'

if @options.hideHover isnt 'always'
@hover = new Morris.Hover(parent: @el)
@on('hovermove', @onHoverMove)
Expand Down Expand Up @@ -198,13 +195,13 @@ class Morris.Line extends Morris.Grid
for row in @data
circle = null
if row._y[index]?
circle = @drawLinePoint(row._x, row._y[index], @options.pointSize, @colorFor(row, index, 'point'), index)
circle = @drawLinePoint(row._x, row._y[index], @colorFor(row, index, 'point'), index)
@seriesPoints[index].push(circle)

_drawLineFor: (index) ->
path = @paths[index]
if path isnt null
@drawLinePath path, @colorFor(null, index, 'line')
@drawLinePath path, @colorFor(null, index, 'line'), index

# create a path for a data series
#
Expand Down Expand Up @@ -259,11 +256,11 @@ class Morris.Line extends Morris.Grid
if @prevHilight isnt null and @prevHilight isnt index
for i in [0..@seriesPoints.length-1]
if @seriesPoints[i][@prevHilight]
@seriesPoints[i][@prevHilight].animate @pointShrink
@seriesPoints[i][@prevHilight].animate @pointShrinkSeries(i)
if index isnt null and @prevHilight isnt index
for i in [0..@seriesPoints.length-1]
if @seriesPoints[i][index]
@seriesPoints[i][index].animate @pointGrow
@seriesPoints[i][index].animate @pointGrowSeries(i)
@prevHilight = index

colorFor: (row, sidx, type) ->
Expand All @@ -281,13 +278,13 @@ class Morris.Line extends Morris.Grid
.attr('font-weight', @options.gridTextWeight)
.attr('fill', @options.gridTextColor)

drawLinePath: (path, lineColor) ->
drawLinePath: (path, lineColor, lineIndex) ->
@raphael.path(path)
.attr('stroke', lineColor)
.attr('stroke-width', @options.lineWidth)
.attr('stroke-width', @lineWidthForSeries(lineIndex))

drawLinePoint: (xPos, yPos, size, pointColor, lineIndex) ->
@raphael.circle(xPos, yPos, size)
drawLinePoint: (xPos, yPos, pointColor, lineIndex) ->
@raphael.circle(xPos, yPos, @pointSizeForSeries(lineIndex))
.attr('fill', pointColor)
.attr('stroke-width', @strokeWidthForSeries(lineIndex))
.attr('stroke', @strokeForSeries(lineIndex))
Expand All @@ -300,6 +297,28 @@ class Morris.Line extends Morris.Grid
strokeForSeries: (index) ->
@options.pointStrokeColors[index % @options.pointStrokeColors.length]

# @private
lineWidthForSeries: (index) ->
if (@options.lineWidth instanceof Array)
@options.lineWidth[index % @options.lineWidth.length]
else
@options.lineWidth

# @private
pointSizeForSeries: (index) ->
if (@options.pointSize instanceof Array)
@options.pointSize[index % @options.pointSize.length]
else
@options.pointSize

# @private
pointGrowSeries: (index) ->
Raphael.animation r: @pointSizeForSeries(index) + 3, 25, 'linear'

# @private
pointShrinkSeries: (index) ->
Raphael.animation r: @pointSizeForSeries(index), 25, 'linear'

# generate a series of label, timestamp pairs for x-axis labels
#
# @private
Expand Down
50 changes: 36 additions & 14 deletions morris.js

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

2 changes: 1 addition & 1 deletion morris.min.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions spec/lib/line/line_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ describe 'Morris.Line', ->
Morris.Line @defaults
shouldHavePath /(M[\d\.]+,[\d\.]+C[\d\.]+(,[\d\.]+){5}){2}/

it 'should make line width customizable', ->
chart = Morris.Line $.extend(@defaults, lineWidth: [1, 2])
chart.lineWidthForSeries(0).should.equal 1
chart.lineWidthForSeries(1).should.equal 2

describe '#createPath', ->

it 'should generate a smooth line', ->
Expand Down