Merge branch 'partialseries' of https://github.com/tangerilli/morris.js into tangerilli-partialseries

This commit is contained in:
Olly Smith 2012-03-18 18:24:06 +00:00
commit 64cfa4a0ff

View File

@ -74,7 +74,10 @@ class Morris.Line
# extract series data # extract series data
@series = [] @series = []
for ykey in @options.ykeys for ykey in @options.ykeys
@series.push $.map @options.data, (d) -> d[ykey] series_data = []
for d in @options.data
series_data.push(d[ykey])
@series.push(series_data)
# translate x labels into nominal dates # translate x labels into nominal dates
# note: currently using decimal years to specify dates # note: currently using decimal years to specify dates
@ -183,7 +186,13 @@ class Morris.Line
columns = (transX(x) for x in @xvals) columns = (transX(x) for x in @xvals)
seriesCoords = [] seriesCoords = []
for s in @series for s in @series
seriesCoords.push($.map(s, (y, i) -> x: columns[i], y: transY(y))) scoords = []
$.each s, (i, y) =>
if y == null
scoords.push(null)
else
scoords.push(x: columns[i], y: transY(y))
seriesCoords.push(scoords)
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
@ -194,10 +203,13 @@ class Morris.Line
seriesPoints = ([] for i in [0..seriesCoords.length-1]) seriesPoints = ([] for i in [0..seriesCoords.length-1])
for i in [seriesCoords.length-1..0] for i in [seriesCoords.length-1..0]
for c in seriesCoords[i] for c in seriesCoords[i]
circle = @r.circle(c.x, c.y, @options.pointSize) if c == null
.attr('fill', @options.lineColors[i]) circle = null
.attr('stroke-width', 1) else
.attr('stroke', '#ffffff') circle = @r.circle(c.x, c.y, @options.pointSize)
.attr('fill', @options.lineColors[i])
.attr('stroke-width', 1)
.attr('stroke', '#ffffff')
seriesPoints[i].push(circle) seriesPoints[i].push(circle)
# hover labels # hover labels
@ -225,7 +237,7 @@ class Morris.Line
hoverSet.show() hoverSet.show()
xLabel.attr('text', @columnLabels[index]) xLabel.attr('text', @columnLabels[index])
for i in [0..@series.length-1] for i in [0..@series.length-1]
yLabels[i].attr('text', "#{@seriesLabels[i]}: #{@commas(@series[i][index])}#{@options.units}") yLabels[i].attr('text', "#{@seriesLabels[i]}: #{@prettifylabel(@series[i][index])}#{@options.units}")
# recalculate hover box width # recalculate hover box width
maxLabelWidth = Math.max.apply null, $.map yLabels, (l) -> maxLabelWidth = Math.max.apply null, $.map yLabels, (l) ->
l.getBBox().width l.getBBox().width
@ -255,10 +267,12 @@ class Morris.Line
hilight = (index) => hilight = (index) =>
if prevHilight isnt null and prevHilight isnt index if prevHilight isnt null and prevHilight isnt index
for i in [0..seriesPoints.length-1] for i in [0..seriesPoints.length-1]
seriesPoints[i][prevHilight].animate pointShrink if seriesPoints[i][prevHilight]
seriesPoints[i][prevHilight].animate pointShrink
if index isnt null and prevHilight isnt index if index isnt null and prevHilight isnt index
for i in [0..seriesPoints.length-1] for i in [0..seriesPoints.length-1]
seriesPoints[i][index].animate pointGrow if seriesPoints[i][index]
seriesPoints[i][index].animate pointGrow
updateHover index updateHover index
prevHilight = index prevHilight = index
if index is null if index is null
@ -285,8 +299,9 @@ class Morris.Line
# create a path for a data series # create a path for a data series
# #
createPath: (coords, top, left, bottom, right) -> createPath: (all_coords, top, left, bottom, right) ->
path = "" path = ""
coords = $.map(all_coords, (c) -> c)
if @options.smooth if @options.smooth
grads = @gradients coords grads = @gradients coords
for i in [0..coords.length-1] for i in [0..coords.length-1]
@ -378,6 +393,11 @@ class Morris.Line
else else
new Date(parseInt(date, 10), 0, 1) new Date(parseInt(date, 10), 0, 1)
prettifylabel: (num) ->
if num == null
return "n/a"
return @commas(num)
# make long numbers prettier by inserting commas # make long numbers prettier by inserting commas
# eg: commas(1234567) -> '1,234,567' # eg: commas(1234567) -> '1,234,567'
# #