X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=auto_tests%2Ftests%2Fhighlight_series_background.js;fp=auto_tests%2Ftests%2Fhighlight_series_background.js;h=d2a09f0b329fd7c36cf448f60faad3a60353fc4d;hb=b6126069a9e468e80a27edf7bdf20ef0ae20b4fb;hp=0000000000000000000000000000000000000000;hpb=5a57a74cdb1f2a15441e154a6cf4a8985ab7a37a;p=dygraphs.git diff --git a/auto_tests/tests/highlight_series_background.js b/auto_tests/tests/highlight_series_background.js new file mode 100644 index 0000000..d2a09f0 --- /dev/null +++ b/auto_tests/tests/highlight_series_background.js @@ -0,0 +1,125 @@ +/** + * @fileoverview Tests for the highlightSeriesBackgroundAlpha and + * highlightSeriesBackgroundColor options. + * @author sergeyslepian@gmail.com + */ + +import Dygraph from '../../src/dygraph'; +import * as utils from '../../src/dygraph-utils'; +import Util from './Util'; + +describe("highlight-series-background", function() { + + cleanupAfterEach(); + + var origRepeatAndCleanup; + + beforeEach(function() { + // A "fast" version of repeatAndCleanup + origRepeatAndCleanup = utils.repeatAndCleanup; + // utils.repeatAndCleanup = function(repeatFn, maxFrames, framePeriodInMillis, cleanupFn) { + // repeatFn(0); + // if (maxFrames > 1) repeatFn(maxFrames - 1); + // cleanupFn(); + // }; + }); + + afterEach(function() { + utils.repeatAndCleanup = origRepeatAndCleanup; + }); + + function setupGraph(highlightSeriesBackgroundAlpha, + highlightSeriesBackgroundColor) { + var opts = { + width: 480, + height: 320, + labels: ['x', 'y'], + legend: 'always', + highlightSeriesOpts: { + strokeWidth: 1, + strokeBorderWidth: 1, + highlightCircleSize: 1 + } + }; + + if (highlightSeriesBackgroundAlpha) utils.update(opts, {highlightSeriesBackgroundAlpha}); + if (highlightSeriesBackgroundColor) utils.update(opts, {highlightSeriesBackgroundColor}); + + var data = []; + for (var j = 0; j < 10; j++) { + data.push([j, 0]); + } + + return new Dygraph('graph', data, opts); + } + + it('testDefaultHighlight', function(done) { + var graph = setupGraph(); + + assert.deepEqual(Util.samplePixel(graph.canvas_, 100, 100), [0,0,0,0]); + + graph.setSelection(0, 'y', true); + + // handle background color fade-in time + window.setTimeout(() => { + assert.deepEqual(Util.samplePixel(graph.canvas_, 100, 100), [255,255,255,127]); + done(); + }, 500); + }); + + it('testNoHighlight', function(done) { + var graph = setupGraph(1); + + assert.deepEqual(Util.samplePixel(graph.canvas_, 100, 100), [0,0,0,0]); + + graph.setSelection(0, 'y', true); + + // handle background color fade-in time + window.setTimeout(() => { + assert.deepEqual(Util.samplePixel(graph.canvas_, 100, 100), [0,0,0,0]); + done(); + }, 500); + }); + + it('testCustomHighlightColor', function(done) { + var graph = setupGraph(null, 'rgb(0,255,255)'); + + assert.deepEqual(Util.samplePixel(graph.canvas_, 100, 100), [0,0,0,0]); + + graph.setSelection(0, 'y', true); + + // handle background color fade-in time + window.setTimeout(() => { + assert.deepEqual(Util.samplePixel(graph.canvas_, 100, 100), [0,255,255,127]); + done(); + }, 500); + }); + + it('testCustomHighlightAlpha', function(done) { + var graph = setupGraph(0.3); + + assert.deepEqual(Util.samplePixel(graph.canvas_, 100, 100), [0,0,0,0]); + + graph.setSelection(0, 'y', true); + + // handle background color fade-in time + window.setTimeout(() => { + assert.deepEqual(Util.samplePixel(graph.canvas_, 100, 100), [255,255,255,179]); + done(); + }, 500); + }); + + it('testCustomHighlightColorAndAlpha', function(done) { + var graph = setupGraph(0.7,'rgb(255,0,0)'); + + assert.deepEqual(Util.samplePixel(graph.canvas_, 100, 100), [0,0,0,0]); + + graph.setSelection(0, 'y', true); + + // handle background color fade-in time + window.setTimeout(() => { + assert.deepEqual(Util.samplePixel(graph.canvas_, 100, 100), [255,0,0,76]); + done(); + }, 500); + }); +});