2 * @fileoverview Test cases for the callbacks.
4 * @author uemit.seren@gmail.com (Ümit Seren)
7 var CallbackTestCase
= TestCase("callback");
9 CallbackTestCase
.prototype.setUp
= function() {
10 document
.body
.innerHTML
= "<div id='graph'></div><div id='selection'></div>";
11 this.styleSheet
= document
.createElement("style");
12 this.styleSheet
.type
= "text/css";
13 document
.getElementsByTagName("head")[0].appendChild(this.styleSheet
);
16 CallbackTestCase
.prototype.tearDown
= function() {
19 var data
= "X,a\,b,c\n" +
27 * This tests that when the function idxToRow_ returns the proper row and the onHiglightCallback
28 * is properly called when the first series is hidden (setVisibility = false)
31 CallbackTestCase
.prototype.testHighlightCallbackIsCalled
= function() {
35 var highlightCallback
= function(e
, x
, pts
, row
) {
40 var graph
= document
.getElementById("graph");
41 var g
= new Dygraph(graph
, data
,
45 visibility
: [false, true, true],
46 highlightCallback
: highlightCallback
49 DygraphOps
.dispatchMouseMove(g
, 13, 10);
51 //check correct row is returned
52 assertEquals(3, h_row
);
53 //check there are only two points (because first series is hidden)
54 assertEquals(2, h_pts
.length
);
58 * Test the closest-series highlighting methods for normal and stacked modes.
59 * Also pass in line widths for plain and highlighted lines for easier visual
60 * confirmation that the highlighted line is drawn on top of the others.
62 var runClosestTest
= function(isStacked
, widthNormal
, widthHighlighted
) {
67 var graph
= document
.getElementById("graph");
68 var g
= new Dygraph(graph
, data
,
72 visibility
: [false, true, true],
73 stackedGraph
: isStacked
,
74 strokeWidth
: widthNormal
,
76 highlightCircleSize
: widthNormal
* 2,
77 highlightSeriesBackgroundFade
: 0.7,
78 highlightSeriesAnimate
: true,
80 highlightSeriesOpts
: {
81 strokeWidth
: widthHighlighted
,
82 highlightCircleSize
: widthHighlighted
* 2
86 var highlightCallback
= function(e
, x
, pts
, row
, set
) {
90 document
.getElementById('selection').innerHTML
='row=' + row
+ ', set=' + set
;
93 g
.updateOptions({highlightCallback
: highlightCallback
}, true);
96 DygraphOps
.dispatchMouseMove(g
, 11.45, 1.4);
97 assertEquals(1, h_row
);
98 assertEquals('c', h_series
);
100 //now move up in the same row
101 DygraphOps
.dispatchMouseMove(g
, 11.45, 1.5);
102 assertEquals(1, h_row
);
103 assertEquals('b', h_series
);
105 //and a bit to the right
106 DygraphOps
.dispatchMouseMove(g
, 11.55, 1.5);
107 assertEquals(2, h_row
);
108 assertEquals('c', h_series
);
110 DygraphOps
.dispatchMouseMove(g
, 11, 1.5);
111 assertEquals(1, h_row
);
112 assertEquals('c', h_series
);
114 //now move up in the same row
115 DygraphOps
.dispatchMouseMove(g
, 11, 2.5);
116 assertEquals(1, h_row
);
117 assertEquals('b', h_series
);
124 * Test basic closest-point highlighting.
126 CallbackTestCase
.prototype.testClosestPointCallback
= function() {
127 runClosestTest(false, 1, 3);
131 * Test setSelection() with series name
133 CallbackTestCase
.prototype.testSetSelection
= function() {
134 var g
= runClosestTest(false, 1, 3);
135 assertEquals(1, g
.attr_('strokeWidth', 'c'));
136 g
.setSelection(false, 'c');
137 assertEquals(3, g
.attr_('strokeWidth', 'c'));
141 * Test closest-point highlighting for stacked graph
143 CallbackTestCase
.prototype.testClosestPointStackedCallback
= function() {
144 runClosestTest(true, 1, 3);
148 * Closest-point highlighting with legend CSS - border around active series.
150 CallbackTestCase
.prototype.testClosestPointCallbackCss1
= function() {
151 var css
= "div.dygraph-legend > span { display: block; }\n" +
152 "div.dygraph-legend > span.highlight { border: 1px solid grey; }\n";
153 this.styleSheet
.innerHTML
= css
;
154 runClosestTest(false, 2, 4);
158 * Closest-point highlighting with legend CSS - show only closest series.
160 CallbackTestCase
.prototype.testClosestPointCallbackCss2
= function() {
161 var css
= "div.dygraph-legend > span { display: none; }\n" +
162 "div.dygraph-legend > span.highlight { display: inline; }\n";
163 this.styleSheet
.innerHTML
= css
;
164 runClosestTest(false, 10, 15);
165 // TODO(klausw): verify that the highlighted line is drawn on top?