Skip to content

Commit

Permalink
discontinuous line in cases where null data values should be represen…
Browse files Browse the repository at this point in the history
…ted by no line rather than a line connecting only the coords with data.
  • Loading branch information
chriserin committed Nov 13, 2012
1 parent 25698d6 commit 10826cb
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions lib/morris.line.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class Morris.Line extends Morris.Grid
hideHover: false
xLabels: 'auto'
xLabelFormat: null
continuousLine: false

# Do any size-related calculations
#
Expand Down Expand Up @@ -84,7 +85,8 @@ class Morris.Line extends Morris.Grid
generatePaths: ->
@paths = for i in [0...@options.ykeys.length]
smooth = @options.smooth is true or @options.ykeys[i] in @options.smooth
coords = ({x: r._x, y: r._y[i]} for r in @data when r._y[i] isnt null)
coords = ({x: r._x, y: r._y[i]} for r in @data )
coords = coords.filter((c)-> c.y != null ) if @options.continuousLine
if coords.length > 1
@createPath coords, smooth
else
Expand Down Expand Up @@ -161,10 +163,16 @@ class Morris.Line extends Morris.Grid
path = ""
if smooth
grads = @gradients coords
nextPathType = "M"
for i in [0..coords.length-1]
c = coords[i]
if i is 0
if c.y == null
nextPathType = "M"
continue

if nextPathType == "M"
path += "M#{c.x},#{c.y}"
nextPathType = "C"
else
g = grads[i]
lc = coords[i - 1]
Expand All @@ -183,13 +191,23 @@ class Morris.Line extends Morris.Grid
#
# @private
gradients: (coords) ->
coordA = null
coordB = null
for c, i in coords
if i is 0
(coords[1].y - c.y) / (coords[1].x - c.x)
coordA = coords[1]
coordB = c
else if i is (coords.length - 1)
(c.y - coords[i - 1].y) / (c.x - coords[i - 1].x)
coordA = c
coordB = coords[i - 1]
else
coordA = coords[i + 1]
coordB = coords[i - 1]

if coordA.y != null and coordB.y != null and coordA.x != null and coordB.x != null
(coordA.y - coordB.y) / (coordA.x - coordB.x)
else
(coords[i + 1].y - coords[i - 1].y) / (coords[i + 1].x - coords[i - 1].x)
null

# draw the hover tooltip
#
Expand Down

0 comments on commit 10826cb

Please sign in to comment.