Added option to draw straight lines

This commit is contained in:
Steve Cockram 2012-02-28 13:30:52 +00:00
parent 8d6cb3ee8e
commit 3371209ab8
2 changed files with 19 additions and 2 deletions

View File

@ -82,7 +82,8 @@
data: month_data, data: month_data,
xkey: 'period', xkey: 'period',
ykeys: ['licensed', 'sorned'], ykeys: ['licensed', 'sorned'],
labels: ['Licensed', 'SORN'] labels: ['Licensed', 'SORN'],
lineDrawer: 'straight'
}); });
}); });
</script> </script>

View File

@ -50,6 +50,7 @@ class Morris.Line
hoverOpacity: 0.95 hoverOpacity: 0.95
hoverLabelColor: '#444' hoverLabelColor: '#444'
hoverFontSize: 12 hoverFontSize: 12
lineDrawer: 'spline'
# Do any necessary pre-processing for a new dataset # Do any necessary pre-processing for a new dataset
# #
@ -141,6 +142,9 @@ class Morris.Line
for i in [seriesCoords.length-1..0] for i in [seriesCoords.length-1..0]
coords = seriesCoords[i] coords = seriesCoords[i]
if coords.length > 1 if coords.length > 1
if @options.lineDrawer == 'straight'
path = @createStraightPath coords, @options.marginTop, left, @options.marginTop + height, left + width
else
path = @createPath coords, @options.marginTop, left, @options.marginTop + height, left + width path = @createPath coords, @options.marginTop, left, @options.marginTop + height, left + width
@r.path(path) @r.path(path)
.attr('stroke', @options.lineColors[i]) .attr('stroke', @options.lineColors[i])
@ -255,6 +259,18 @@ class Morris.Line
path += "C#{x1},#{y1},#{x2},#{y2},#{c.x},#{c.y}" path += "C#{x1},#{y1},#{x2},#{y2},#{c.x},#{c.y}"
return path return path
# creates a straight path for a data series
#
createStraightPath: (coords, top, left, bottom, right) ->
path = ""
for i in [0..coords.length-1]
c = coords[i]
if i is 0
path += "M#{c.x},#{c.y}"
else
path += "L#{c.x},#{c.y}"
return path
# calculate a gradient at each point for a series of points # calculate a gradient at each point for a series of points
# #
gradients: (coords) -> gradients: (coords) ->