X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=auto_tests%2Ftests%2Fannotations.js;h=d0a2f7ffbfecc57f12858a6b649cdfd1fc732fe7;hb=d569e3a08324168e501e6ba1402273acdae554f9;hp=857dd607b92e591750a674bc8ea4385d1a3c004d;hpb=e6b0b7c295a1c3838817744e4548c52bbbdf051f;p=dygraphs.git diff --git a/auto_tests/tests/annotations.js b/auto_tests/tests/annotations.js index 857dd60..d0a2f7f 100644 --- a/auto_tests/tests/annotations.js +++ b/auto_tests/tests/annotations.js @@ -205,3 +205,68 @@ AnnotationsTestCase.prototype.testAnnotationsDrawnInDrawCallback = function() { assertEquals([true, false], calls); }; + + +// Test that annotations on the same point are stacked. +// Regression test for http://code.google.com/p/dygraphs/issues/detail?id=256 +AnnotationsTestCase.prototype.testAnnotationsStacked = function() { + var data = 'X,Y1,Y2\n' + + '0,1,2\n' + + '1,2,3\n'; + var graph = document.getElementById("graph"); + var annotations = [ + { + series: 'Y1', + x: 0, + shortText: '1', + attachAtBottom: true + }, + { + series: 'Y2', + x: 0, + shortText: '2', + attachAtBottom: true + } + ]; + var g = new Dygraph(graph, data, { + width: 480, + height: 320 + }); + g.setAnnotations(annotations); + + var annEls = document.getElementsByClassName('dygraphDefaultAnnotation'); + assertEquals(2, annEls.length); + + assertEquals(annEls[0].offsetLeft, annEls[1].offsetLeft); + assert(annEls[1].offsetTop < annEls[0].offsetTop - 10); +}; + + +// Test the .ready() method, which is most often used with setAnnotations(). +AnnotationsTestCase.prototype.testReady = function() { + var data = 'X,Y1,Y2\n' + + '0,1,2\n' + + '1,2,3\n'; + var mockXhr = Util.overrideXMLHttpRequest(data); + + var graph = document.getElementById("graph"); + var g = new Dygraph(graph, "data.csv", { + width: 480, + height: 320 + }); + + var ready_calls = 0; + g.ready(function() { ready_calls++; }); + + assertEquals(0, ready_calls); + mockXhr.respond(); + assertEquals(1, ready_calls); + + // Make sure that ready isn't called on redraws. + g.updateOptions({}); + assertEquals(1, ready_calls); + + // Or data changes. + g.updateOptions({file: data}); + assertEquals(1, ready_calls); +};