X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=auto_tests%2Ftests%2Fplugins_legend.js;h=5f67591590842147a44e861de51a1f9657b72198;hb=902091b8b33555845682681f64048f7ed1811c27;hp=26daf926e012c2688e98e4076368c42918f3558b;hpb=ce31caf22475e3e1fd6d9fea192d61ff4fcd7fac;p=dygraphs.git diff --git a/auto_tests/tests/plugins_legend.js b/auto_tests/tests/plugins_legend.js index 26daf92..5f67591 100644 --- a/auto_tests/tests/plugins_legend.js +++ b/auto_tests/tests/plugins_legend.js @@ -76,4 +76,67 @@ it('should render dashed patterns', function() { 'rgb(255, 0, 0)'); }); +it('should use a legendFormatter', function() { + var calls = []; + var g = new Dygraph(graph, 'X,Y\n1,2\n', { + color: 'red', + legend: 'always', + legendFormatter: function(data) { + calls.push(data); + // Note: can't check against `g` because it's not defined yet. + assert(this.toString().indexOf('Dygraph') >= 0); + return ''; + } + }); + + assert(calls.length == 1); // legend for no selected points + g.setSelection(0); + assert(calls.length == 2); // legend with selected points + g.clearSelection(); + assert(calls.length == 3); + + assert.equal(calls[0].x, undefined); + assert.equal(calls[1].x, 1); + assert.equal(calls[1].xHTML, '1'); + assert.equal(calls[2].x, undefined); + + assert.equal(calls[0].series.length, 1); + assert.equal(calls[1].series.length, 1); + assert.equal(calls[2].series.length, 1); + + assert.equal(calls[0].series[0].y, undefined); + assert.equal(calls[1].series[0].label, 'Y'); + assert.equal(calls[1].series[0].labelHTML, 'Y'); + assert.equal(calls[1].series[0].y, 2); + assert.equal(calls[1].series[0].yHTML, '2'); + assert.equal(calls[1].series[0].isVisible, true); + assert.equal(calls[2].series[0].y, undefined); +}); + +it('should include point drawn where canvas-y is 0', function () { + var graph = document.getElementById("graph"); + var calls = [] + function callback(data) { + calls.push(data); + }; + + var g = new Dygraph(document.getElementById("graph"), + "X,Y\n" + + "1,5\n" + + "1,10\n" + + "1,12\n", + { + legendFormatter: callback, + axes: { + y: { + valueRange: [0, 10] + } + } + }); + g.setSelection(1); + var data = calls[1]; + assert.isTrue(data.series[0].isVisible); + assert.notEqual(data.series[0].yHTML, ''); +}); + });