X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=auto_tests%2Ftests%2Fcallback.js;h=a26b7e7b085f8e496f2dea2c16c60f2027f5c928;hb=a937d03183e33deea11a8d020cb1265c266e7f41;hp=aad0dad4bed0a04fa4d4972342504b681c101329;hpb=2a02e5dde7f3727c1735761b84ca41c0f241dcaf;p=dygraphs.git diff --git a/auto_tests/tests/callback.js b/auto_tests/tests/callback.js index aad0dad..a26b7e7 100644 --- a/auto_tests/tests/callback.js +++ b/auto_tests/tests/callback.js @@ -167,7 +167,7 @@ var runClosestTest = function(isStacked, widthNormal, widthHighlighted) { strokeWidth: widthNormal, strokeBorderWidth: 2, highlightCircleSize: widthNormal * 2, - highlightSeriesBackgroundFade: 0.7, + highlightSeriesBackgroundAlpha: 0.3, highlightSeriesOpts: { strokeWidth: widthHighlighted, @@ -244,6 +244,7 @@ CallbackTestCase.prototype.testClosestPointCallbackCss1 = function() { "div.dygraph-legend > span.highlight { border: 1px solid grey; }\n"; this.styleSheet.innerHTML = css; runClosestTest(false, 2, 4); + this.styleSheet.innerHTML = ''; } /** @@ -254,5 +255,55 @@ CallbackTestCase.prototype.testClosestPointCallbackCss2 = function() { "div.dygraph-legend > span.highlight { display: inline; }\n"; this.styleSheet.innerHTML = css; runClosestTest(false, 10, 15); + this.styleSheet.innerHTML = ''; // TODO(klausw): verify that the highlighted line is drawn on top? } + +/** + * This tests that closest point searches work for data containing NaNs. + * + * It's intended to catch a regression where a NaN Y value confuses the + * closest-point algorithm, treating it as closer as any previous point. + */ +CallbackTestCase.prototype.testNaNData = function() { + var dataNaN = [ + [10, -1, 1, 2], + [11, 0, 3, 1], + [12, 1, 4, NaN], + [13, 0, 2, 3], + [14, -1, 1, 4]]; + + var h_row; + var h_pts; + + var highlightCallback = function(e, x, pts, row) { + h_row = row; + h_pts = pts; + }; + + var graph = document.getElementById("graph"); + var g = new Dygraph(graph, dataNaN, + { + width: 600, + height: 400, + labels: ['x', 'a', 'b', 'c'], + visibility: [false, true, true], + highlightCallback: highlightCallback + }); + + DygraphOps.dispatchMouseMove(g, 10.1, 0.9); + //check correct row is returned + assertEquals(0, h_row); + + // Explicitly test closest point algorithms + var dom = g.toDomCoords(10.1, 0.9); + assertEquals(0, g.findClosestRow(dom[0])); + + var res = g.findClosestPoint(dom[0], dom[1]); + assertEquals(0, res.row); + assertEquals('b', res.seriesName); + + res = g.findStackedPoint(dom[0], dom[1]); + assertEquals(0, res.row); + assertEquals('c', res.seriesName); +};