X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=auto_tests%2Ftests%2Fcallback.js;h=1e008156306a9ab30b6aa5e7e8458ce18761fa9f;hb=056763ed22ccc5bdebc73355841052d0d6815a1f;hp=b10cf1652bad6dc1d5602f9070128ec571728fc5;hpb=3123ca57f71d145bb5bcc4a2f754d3dff3225346;p=dygraphs.git diff --git a/auto_tests/tests/callback.js b/auto_tests/tests/callback.js index b10cf16..1e00815 100644 --- a/auto_tests/tests/callback.js +++ b/auto_tests/tests/callback.js @@ -4,12 +4,22 @@ * @author uemit.seren@gmail.com (Ümit Seren) */ +import Dygraph from '../../src/dygraph'; +import * as utils from '../../src/dygraph-utils'; +import Util from './Util'; +import DygraphOps from './DygraphOps'; + describe("callback", function() { +cleanupAfterEach(); + var xhr, styleSheet; +var graph; beforeEach(function() { - document.body.innerHTML = "
"; + var container = document.getElementById('graph'); + container.innerHTML = "
"; + graph = container.querySelector('#inner-graph'); xhr = XMLHttpRequest; styleSheet = document.createElement("style"); styleSheet.type = "text/css"; @@ -42,7 +52,6 @@ it('testHighlightCallbackIsCalled', function() { h_pts = pts; }; - var graph = document.getElementById("graph"); var g = new Dygraph(graph, data, { width: 100, @@ -71,7 +80,6 @@ it('testDrawPointCallback_disabled', function() { called = true; }; - var graph = document.getElementById("graph"); var g = new Dygraph(graph, data, { drawPointCallback: callback, }); @@ -91,7 +99,6 @@ it('testDrawPointCallback_enabled', function() { called = true; }; - var graph = document.getElementById("graph"); var g = new Dygraph(graph, data, { drawPoints: true, drawPointCallback: callback @@ -114,7 +121,6 @@ it('testDrawPointCallback_pointSize', function() { count++; }; - var graph = document.getElementById("graph"); var g = new Dygraph(graph, data, { drawPoints: true, drawPointCallback: callback @@ -144,10 +150,9 @@ it('testDrawPointCallback_isolated', function() { assert.equal(g, this); var dx = g.toDataXCoord(cx); xvalues.push(dx); - Dygraph.Circles.DEFAULT.apply(this, arguments); + utils.Circles.DEFAULT.apply(this, arguments); }; - var graph = document.getElementById("graph"); var testdata = [[10, 2], [11, 3], [12, NaN], [13, 2], [14, NaN], [15, 3]]; var graphOpts = { labels: ['X', 'Y'], @@ -188,7 +193,6 @@ it('testDrawHighlightPointCallbackIsCalled', function() { called = true; }; - var graph = document.getElementById("graph"); var g = new Dygraph(graph, data, { width: 100, @@ -211,7 +215,6 @@ var runClosestTest = function(isStacked, widthNormal, widthHighlighted) { var h_pts; var h_series; - var graph = document.getElementById("graph"); var g = new Dygraph(graph, data, { width: 600, @@ -359,7 +362,6 @@ it('testNaNData', function() { h_pts = pts; }; - var graph = document.getElementById("graph"); var g = new Dygraph(graph, dataNaN, { width: 600, @@ -412,7 +414,6 @@ it('testNaNDataStack', function() { h_pts = pts; }; - var graph = document.getElementById("graph"); var g = new Dygraph(graph, dataNaN, { width: 600, @@ -478,7 +479,6 @@ it('testGapHighlight', function() { h_pts = pts; }; - var graph = document.getElementById("graph"); var g = new Dygraph(graph, dataGap, { width: 400, height: 300, @@ -521,7 +521,6 @@ it('testFailedResponse', function() { throw "should not reach here"; }; - var graph = document.getElementById("graph"); graph.style.border = "2px solid black"; var g = new Dygraph(graph, "data.csv", { // fake name width: 400, @@ -551,7 +550,6 @@ it('testHighlightCallbackRow', function() { highlightRow = row; }; - var graph = document.getElementById("graph"); var g = new Dygraph(graph, "X,Y,Z\n" + "0,1,2\n" + // 0 @@ -602,7 +600,6 @@ it('testUnderlayCallback_noSeries', function() { yMax = g.yAxisRange(0)[1]; }; - var graph = document.getElementById("graph"); var g = new Dygraph(graph, "\n", { underlayCallback: callback }); @@ -625,7 +622,6 @@ it('testUnderlayCallback_yAxisRange', function() { yMax = g.yAxisRange(0)[1]; }; - var graph = document.getElementById("graph"); var g = new Dygraph(graph, "\n", { valueRange: [0,10], underlayCallback: callback @@ -645,10 +641,9 @@ it('testDrawPointCallback_idx', function() { var callback = function(g, seriesName, canvasContext, cx, cy, color, pointSizeParam,idx) { assert.equal(g, this); indices.push(idx); - Dygraph.Circles.DEFAULT.apply(this, arguments); + utils.Circles.DEFAULT.apply(this, arguments); }; - var graph = document.getElementById("graph"); var testdata = [[10, 2], [11, 3], [12, NaN], [13, 2], [14, NaN], [15, 3]]; var graphOpts = { @@ -686,7 +681,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; @@ -695,10 +690,9 @@ it('testDrawHighlightPointCallback_idx', function() { idxToCheck = idx; }; var testdata = [[1, 2], [2, 3], [3, NaN], [4, 2], [5, NaN], [6, 3]]; - var graph = document.getElementById("graph"); - var g = new Dygraph(graph, testdata, - { - drawHighlightPointCallback : drawHighlightPointCallback + var g = new Dygraph(graph, testdata, { + drawHighlightPointCallback: drawHighlightPointCallback, + labels: ['X', 'Y'] }); assert.isNull(idxToCheck); @@ -712,4 +706,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); + } + }); +}); + });