From 28cb48bb365b6f195f74a9395599029464f496bb Mon Sep 17 00:00:00 2001 From: Olly Smith Date: Tue, 6 Mar 2012 22:05:00 +0000 Subject: [PATCH] Coffeescript non-date X values. --- morris.coffee | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/morris.coffee b/morris.coffee index 65d8b4c..b87c5af 100644 --- a/morris.coffee +++ b/morris.coffee @@ -57,6 +57,7 @@ class Morris.Line hoverFontSize: 12 smooth: true hideHover: false + parseTime: true # Do any necessary pre-processing for a new dataset # @@ -74,7 +75,10 @@ class Morris.Line # translate x labels into nominal dates # note: currently using decimal years to specify dates - @xvals = $.map @columnLabels, (x) => @parseYear x + if @options.parseTime + @xvals = $.map @columnLabels, (x) => @parseYear x + else + @xvals = [(@columnLabels.length-1)..0] @xmin = Math.min.apply null, @xvals @xmax = Math.max.apply null, @xvals if @xmin is @xmax @@ -132,7 +136,8 @@ class Morris.Line prevLabelMargin = null xLabelMargin = 50 # make this an option? for i in [Math.ceil(@xmin)..Math.floor(@xmax)] - label = @r.text(transX(i), @options.marginTop + height + @options.marginBottom / 2, i) + labelText = if @options.parseTime then i else @columnLabels[@columnLabels.length-i-1] + label = @r.text(transX(i), @options.marginTop + height + @options.marginBottom / 2, labelText) .attr('font-size', @options.gridTextSize) .attr('fill', @options.gridTextColor) labelBox = label.getBBox()