From b617ba25a4500750fd4ffdc7ac12758c7e1b3823 Mon Sep 17 00:00:00 2001 From: Dan Vanderkam Date: Mon, 13 Apr 2015 13:47:33 -0400 Subject: [PATCH] Set this for drawCallback --- auto_tests/tests/callback.js | 14 +++++++++++++- src/dygraph.js | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/auto_tests/tests/callback.js b/auto_tests/tests/callback.js index d41d91e..b12ea64 100644 --- a/auto_tests/tests/callback.js +++ b/auto_tests/tests/callback.js @@ -686,7 +686,7 @@ it('testDrawPointCallback_idx', function() { /** * Test that the correct idx is returned for the point in the onHiglightCallback. - */ + */ it('testDrawHighlightPointCallback_idx', function() { var idxToCheck = null; @@ -712,4 +712,16 @@ it('testDrawHighlightPointCallback_idx', function() { assert.equal(5,idxToCheck); }); +/** + * Test that drawCallback is called with the correct value for `this`. + */ +it('should set this in drawCallback', function() { + var g = new Dygraph('graph', data, { + drawCallback: function(g, is_initial) { + assert.isTrue(is_initial); + assert.equal(g, this); + } + }); +}); + }); diff --git a/src/dygraph.js b/src/dygraph.js index 878a747..4f3ce77 100644 --- a/src/dygraph.js +++ b/src/dygraph.js @@ -2671,7 +2671,7 @@ Dygraph.prototype.renderGraph_ = function(is_initial_draw) { this.canvas_.getContext('2d').clearRect(0, 0, this.width_, this.height_); if (this.getFunctionOption("drawCallback") !== null) { - this.getFunctionOption("drawCallback")(this, is_initial_draw); + this.getFunctionOption("drawCallback").call(this, this, is_initial_draw); } if (is_initial_draw) { this.readyFired_ = true; -- 2.7.4