From 3371209ab87530181c2a556d72fcbadcf9d1f618 Mon Sep 17 00:00:00 2001 From: Steve Cockram Date: Tue, 28 Feb 2012 13:30:52 +0000 Subject: [PATCH] Added option to draw straight lines --- example.html | 3 ++- morris.coffee | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/example.html b/example.html index f66fbad..5d211b6 100644 --- a/example.html +++ b/example.html @@ -82,7 +82,8 @@ data: month_data, xkey: 'period', ykeys: ['licensed', 'sorned'], - labels: ['Licensed', 'SORN'] + labels: ['Licensed', 'SORN'], + lineDrawer: 'straight' }); }); diff --git a/morris.coffee b/morris.coffee index c7db91d..22bce15 100644 --- a/morris.coffee +++ b/morris.coffee @@ -50,6 +50,7 @@ class Morris.Line hoverOpacity: 0.95 hoverLabelColor: '#444' hoverFontSize: 12 + lineDrawer: 'spline' # Do any necessary pre-processing for a new dataset # @@ -141,7 +142,10 @@ class Morris.Line for i in [seriesCoords.length-1..0] coords = seriesCoords[i] if coords.length > 1 - path = @createPath coords, @options.marginTop, left, @options.marginTop + height, left + width + 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 @r.path(path) .attr('stroke', @options.lineColors[i]) .attr('stroke-width', @options.lineWidth) @@ -255,6 +259,18 @@ class Morris.Line path += "C#{x1},#{y1},#{x2},#{y2},#{c.x},#{c.y}" 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 # gradients: (coords) ->