Commit 9fce2faf by ichuang

Merge pull request #100 from MITx/ps-fix-histogram

Fix histogram and sequence navigation bug

looks good, works in my tests. thanks.
parents 3bfe8112 b4ed14f4
...@@ -11,7 +11,7 @@ describe 'Histogram', -> ...@@ -11,7 +11,7 @@ describe 'Histogram', ->
describe 'calculate', -> describe 'calculate', ->
beforeEach -> 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', -> it 'store the correct value for data', ->
expect(@histogram.data).toEqual [[1, Math.log(2)], [2, Math.log(3)], [3, Math.log(4)]] expect(@histogram.data).toEqual [[1, Math.log(2)], [2, Math.log(3)], [3, Math.log(4)]]
......
...@@ -24,7 +24,6 @@ describe 'Sequence', -> ...@@ -24,7 +24,6 @@ describe 'Sequence', ->
expect(titles).toEqual ['Video 1', 'Video 2', 'Sample Problem'] expect(titles).toEqual ['Video 1', 'Video 2', 'Sample Problem']
it 'bind the page events', -> it 'bind the page events', ->
expect(@sequence.element).toHandleWith 'contentChanged', @sequence.toggleArrows
expect($('#sequence-list a')).toHandleWith 'click', @sequence.goto expect($('#sequence-list a')).toHandleWith 'click', @sequence.goto
it 'render the active sequence content', -> it 'render the active sequence content', ->
...@@ -76,6 +75,7 @@ describe 'Sequence', -> ...@@ -76,6 +75,7 @@ describe 'Sequence', ->
spyOn $, 'postWithPrefix' spyOn $, 'postWithPrefix'
@sequence = new Sequence '1', @items, 'sequence' @sequence = new Sequence '1', @items, 'sequence'
spyOnEvent @sequence.element, 'contentChanged' spyOnEvent @sequence.element, 'contentChanged'
spyOn(@sequence, 'toggleArrows').andCallThrough()
describe 'with a different position than the current one', -> describe 'with a different position than the current one', ->
beforeEach -> beforeEach ->
...@@ -105,6 +105,9 @@ describe 'Sequence', -> ...@@ -105,6 +105,9 @@ describe 'Sequence', ->
it 'update the position', -> it 'update the position', ->
expect(@sequence.position).toEqual 1 expect(@sequence.position).toEqual 1
it 're-update the arrows', ->
expect(@sequence.toggleArrows).toHaveBeenCalled()
it 'trigger contentChanged event', -> it 'trigger contentChanged event', ->
expect('contentChanged').toHaveBeenTriggeredOn @sequence.element expect('contentChanged').toHaveBeenTriggeredOn @sequence.element
......
...@@ -8,6 +8,7 @@ class @Histogram ...@@ -8,6 +8,7 @@ class @Histogram
calculate: -> calculate: ->
for [score, count] in @rawData for [score, count] in @rawData
continue if score == null
log_count = Math.log(count + 1) log_count = Math.log(count + 1)
@data.push [score, log_count] @data.push [score, log_count]
@xTicks.push [score, score.toString()] @xTicks.push [score, score.toString()]
......
...@@ -9,7 +9,6 @@ class @Sequence ...@@ -9,7 +9,6 @@ class @Sequence
$(selector, @element) $(selector, @element)
bind: -> bind: ->
@element.bind 'contentChanged', @toggleArrows
@$('#sequence-list a').click @goto @$('#sequence-list a').click @goto
buildNavigation: -> buildNavigation: ->
...@@ -43,6 +42,7 @@ class @Sequence ...@@ -43,6 +42,7 @@ class @Sequence
MathJax.Hub.Queue(["Typeset", MathJax.Hub]) MathJax.Hub.Queue(["Typeset", MathJax.Hub])
@position = new_position @position = new_position
@toggleArrows()
@element.trigger 'contentChanged' @element.trigger 'contentChanged'
goto: (event) => goto: (event) =>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment