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
) {
42 var graph
= document
.getElementById("graph");
43 var g
= new Dygraph(graph
, data
,
47 visibility
: [false, true, true],
48 highlightCallback
: highlightCallback
51 DygraphOps
.dispatchMouseMove(g
, 13, 10);
53 //check correct row is returned
54 assertEquals(3, h_row
);
55 //check there are only two points (because first series is hidden)
56 assertEquals(2, h_pts
.length
);
59 var runClosestTest
= function(isStacked
, widthNormal
, widthHighlighted
) {
64 var graph
= document
.getElementById("graph");
65 var g
= new Dygraph(graph
, data
,
69 visibility
: [false, true, true],
70 stackedGraph
: isStacked
,
71 strokeWidth
: widthNormal
,
73 highlightCircleSize
: widthNormal
* 2,
74 highlightSeriesBackgroundFade
: 0.7,
75 highlightSeriesAnimate
: true,
77 highlightSeriesOpts
: {
78 strokeWidth
: widthHighlighted
,
79 highlightCircleSize
: widthHighlighted
* 2
83 var highlightCallback
= function(e
, x
, pts
, row
, set
) {
87 document
.getElementById('selection').innerHTML
='row=' + row
+ ', set=' + set
;
90 g
.updateOptions({highlightCallback
: highlightCallback
}, true);
93 DygraphOps
.dispatchMouseMove(g
, 11.45, 1.4);
94 assertEquals(1, h_row
);
95 assertEquals('c', h_series
);
97 //now move up in the same row
98 DygraphOps
.dispatchMouseMove(g
, 11.45, 1.5);
99 assertEquals(1, h_row
);
100 assertEquals('b', h_series
);
102 //and a bit to the right
103 DygraphOps
.dispatchMouseMove(g
, 11.55, 1.5);
104 assertEquals(2, h_row
);
105 assertEquals('c', h_series
);
107 DygraphOps
.dispatchMouseMove(g
, 11, 1.5);
108 assertEquals(1, h_row
);
109 assertEquals('c', h_series
);
111 //now move up in the same row
112 DygraphOps
.dispatchMouseMove(g
, 11, 2.5);
113 assertEquals(1, h_row
);
114 assertEquals('b', h_series
);
121 * Test basic closest-point highlighting.
123 CallbackTestCase
.prototype.testClosestPointCallback
= function() {
124 runClosestTest(false, 1, 3);
128 * Test setSelection() with series name
130 CallbackTestCase
.prototype.testSetSelection
= function() {
131 var g
= runClosestTest(false, 1, 3);
132 assertEquals(1, g
.attr_('strokeWidth', 'c'));
133 g
.setSelection(false, 'c');
134 assertEquals(3, g
.attr_('strokeWidth', 'c'));
138 * Test closest-point highlighting for stacked graph
140 CallbackTestCase
.prototype.testClosestPointStackedCallback
= function() {
141 runClosestTest(true, 1, 3);
145 * Closest-point highlighting with legend CSS - border around active series.
147 CallbackTestCase
.prototype.testClosestPointCallbackCss1
= function() {
148 var css
= "div.dygraph-legend > span { display: block; }\n" +
149 "div.dygraph-legend > span.highlight { border: 1px solid grey; }\n";
150 this.styleSheet
.innerHTML
= css
;
151 runClosestTest(false, 2, 4);
155 * Closest-point highlighting with legend CSS - show only closest series.
157 CallbackTestCase
.prototype.testClosestPointCallbackCss2
= function() {
158 var css
= "div.dygraph-legend > span { display: none; }\n" +
159 "div.dygraph-legend > span.highlight { display: inline; }\n";
160 this.styleSheet
.innerHTML
= css
;
161 runClosestTest(false, 10, 15);
162 // TODO(klausw): verify that the highlighted line is drawn on top?