Handle the case where histogram score can be null

This will leave out the student that never attempt the question and
fixes the error with histogram rendering.
This commit is contained in:
Prem Sichanugrist
2012-06-11 16:07:09 -04:00
parent eb70ef4c07
commit b4ed14f4f7
2 changed files with 2 additions and 1 deletions

View File

@@ -11,7 +11,7 @@ describe 'Histogram', ->
describe 'calculate', ->
beforeEach ->
@histogram = new Histogram(1, [[1, 1], [2, 2], [3, 3]])
@histogram = new Histogram(1, [[null, 1], [1, 1], [2, 2], [3, 3]])
it 'store the correct value for data', ->
expect(@histogram.data).toEqual [[1, Math.log(2)], [2, Math.log(3)], [3, Math.log(4)]]

View File

@@ -8,6 +8,7 @@ class @Histogram
calculate: ->
for [score, count] in @rawData
continue if score == null
log_count = Math.log(count + 1)
@data.push [score, log_count]
@xTicks.push [score, score.toString()]