From b5481aea020c5fa66baef26508671591527bd3df Mon Sep 17 00:00:00 2001 From: Dan Vanderkam Date: Fri, 8 Feb 2013 20:23:37 -0500 Subject: [PATCH] auto_test for stacked annotations --- auto_tests/tests/annotations.js | 35 +++++++++++++++++++++++++++++++++++ dygraph-layout.js | 3 ++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/auto_tests/tests/annotations.js b/auto_tests/tests/annotations.js index 857dd60..76a56d2 100644 --- a/auto_tests/tests/annotations.js +++ b/auto_tests/tests/annotations.js @@ -205,3 +205,38 @@ 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); +}; diff --git a/dygraph-layout.js b/dygraph-layout.js index b99896b..2b3d137 100644 --- a/dygraph-layout.js +++ b/dygraph-layout.js @@ -130,7 +130,8 @@ DygraphLayout.prototype.setAnnotations = function(ann) { var parse = this.attr_('xValueParser') || function(x) { return x; }; for (var i = 0; i < ann.length; i++) { var a = {}; - if (!ann[i].xval && !ann[i].x) { + if (!ann[i].xval && ann[i].x === undefined) { + console.log(ann[i]); this.dygraph_.error("Annotations must have an 'x' property"); return; } -- 2.7.4