Skip to content

Commit

Permalink
Merge pull request #196 from woozyking/feature/redraw
Browse files Browse the repository at this point in the history
Epoch.Chart.Canvas#redraw() method
  • Loading branch information
rsandor committed Oct 17, 2015
2 parents d7e663a + 9a86243 commit 76b30d6
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
5 changes: 5 additions & 0 deletions dist/js/epoch.js
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,11 @@ Epoch.Chart.Canvas = (function(superClass) {
});
};

Canvas.prototype.redraw = function() {
Epoch.QueryCSS.purge();
return this.draw();
};

return Canvas;

})(Epoch.Chart.Base);
Expand Down
4 changes: 2 additions & 2 deletions dist/js/epoch.min.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions src/core/chart.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -354,3 +354,8 @@ class Epoch.Chart.Canvas extends Epoch.Chart.Base
super()
@canvas.style {'width': "#{@width}px", 'height': "#{@height}px"}
@canvas.attr { width: @getWidth(), height: @getHeight() }

# Purges QueryCSS cache and redraws the Canvas based chart.
redraw: ->
Epoch.QueryCSS.purge()
@draw()
24 changes: 24 additions & 0 deletions tests/unit/core/charts.coffee
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
sinon = require 'sinon'

describe 'Epoch.Chart', ->
[defaultWidth, defaultHeight] = [320, 240]

Expand Down Expand Up @@ -547,3 +549,25 @@ describe 'Epoch.Chart', ->
chart.option 'height', newHeight
assert.equal chart.canvas.attr('height'), pixelRatio * newHeight
assert.equal chart.canvas.height(), newHeight

describe 'redraw', ->
chart = null
drawSpy = null
purgeSpy = null

before ->
chart = new Epoch.Chart.Canvas()

beforeEach ->
drawSpy = sinon.spy chart, 'draw'
purgeSpy = sinon.spy Epoch.QueryCSS, 'purge'

afterEach ->
chart.draw.restore()
Epoch.QueryCSS.purge.restore()

it 'should purge QueryCSS cache and redraw the canvas based chart with new styles', ->
chart.redraw()

assert drawSpy.calledOnce
assert purgeSpy.calledOnce

0 comments on commit 76b30d6

Please sign in to comment.