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

Discontinuous Lines #116

Merged
merged 1 commit into from
Dec 3, 2012
Merged
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
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 [[email protected]]
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