2 * @fileoverview Tests for the highlightSeriesBackgroundAlpha and
3 * highlightSeriesBackgroundColor options.
4 * @author sergeyslepian@gmail.com
7 import Dygraph from
'../../src/dygraph';
8 import * as utils from
'../../src/dygraph-utils';
9 import Util from
'./Util';
11 describe("highlight-series-background", function() {
15 var origRepeatAndCleanup
;
17 beforeEach(function() {
18 // A "fast" version of repeatAndCleanup
19 origRepeatAndCleanup
= utils
.repeatAndCleanup
;
20 // utils.repeatAndCleanup = function(repeatFn, maxFrames, framePeriodInMillis, cleanupFn) {
22 // if (maxFrames > 1) repeatFn(maxFrames - 1);
27 afterEach(function() {
28 utils
.repeatAndCleanup
= origRepeatAndCleanup
;
31 function setupGraph(highlightSeriesBackgroundAlpha
,
32 highlightSeriesBackgroundColor
) {
38 highlightSeriesOpts
: {
41 highlightCircleSize
: 1
45 if (highlightSeriesBackgroundAlpha
) utils
.update(opts
, {highlightSeriesBackgroundAlpha
});
46 if (highlightSeriesBackgroundColor
) utils
.update(opts
, {highlightSeriesBackgroundColor
});
49 for (var j
= 0; j
< 10; j
++) {
53 return new Dygraph('graph', data
, opts
);
56 it('testDefaultHighlight', function(done
) {
57 var graph
= setupGraph();
59 assert
.deepEqual(Util
.samplePixel(graph
.canvas_
, 100, 100), [0,0,0,0]);
61 graph
.setSelection(0, 'y', true);
63 // handle background color fade-in time
64 window
.setTimeout(() => {
65 assert
.deepEqual(Util
.samplePixel(graph
.canvas_
, 100, 100), [255,255,255,127]);
70 it('testNoHighlight', function(done
) {
71 var graph
= setupGraph(1);
73 assert
.deepEqual(Util
.samplePixel(graph
.canvas_
, 100, 100), [0,0,0,0]);
75 graph
.setSelection(0, 'y', true);
77 // handle background color fade-in time
78 window
.setTimeout(() => {
79 assert
.deepEqual(Util
.samplePixel(graph
.canvas_
, 100, 100), [0,0,0,0]);
84 it('testCustomHighlightColor', function(done
) {
85 var graph
= setupGraph(null, 'rgb(0,255,255)');
87 assert
.deepEqual(Util
.samplePixel(graph
.canvas_
, 100, 100), [0,0,0,0]);
89 graph
.setSelection(0, 'y', true);
91 // handle background color fade-in time
92 window
.setTimeout(() => {
93 assert
.deepEqual(Util
.samplePixel(graph
.canvas_
, 100, 100), [0,255,255,127]);
98 it('testCustomHighlightAlpha', function(done
) {
99 var graph
= setupGraph(0.3);
101 assert
.deepEqual(Util
.samplePixel(graph
.canvas_
, 100, 100), [0,0,0,0]);
103 graph
.setSelection(0, 'y', true);
105 // handle background color fade-in time
106 window
.setTimeout(() => {
107 assert
.deepEqual(Util
.samplePixel(graph
.canvas_
, 100, 100), [255,255,255,179]);
112 it('testCustomHighlightColorAndAlpha', function(done
) {
113 var graph
= setupGraph(0.7,'rgb(255,0,0)');
115 assert
.deepEqual(Util
.samplePixel(graph
.canvas_
, 100, 100), [0,0,0,0]);
117 graph
.setSelection(0, 'y', true);
119 // handle background color fade-in time
120 window
.setTimeout(() => {
121 assert
.deepEqual(Util
.samplePixel(graph
.canvas_
, 100, 100), [255,0,0,76]);
126 it('testGetSelectionZeroCanvasY', function () {
127 var graph
= document
.getElementById("graph");
129 function callback(g
, seriesName
, canvasContext
, cx
, cy
, color
, pointSize
, idx
) {
130 calls
.push(arguments
);
133 var g
= new Dygraph(document
.getElementById("graph"),
139 drawHighlightPointCallback
: callback
,
148 assert
.equal(args
[4], 0);