| 1 | // Copyright 2011 Google Inc. All Rights Reserved. |
| 2 | |
| 3 | /** |
| 4 | * @fileoverview Regression test based on an optimization w/ |
| 5 | * unforeseen consequences. |
| 6 | * @author danvk@google.com (Dan Vanderkam) |
| 7 | */ |
| 8 | |
| 9 | import Dygraph from '../../src/dygraph'; |
| 10 | import DefaultHandler from '../../src/datahandler/default'; |
| 11 | |
| 12 | describe("selection", function() { |
| 13 | |
| 14 | cleanupAfterEach(); |
| 15 | |
| 16 | it('testSetGetSelection', function() { |
| 17 | var graph = document.getElementById("graph"); |
| 18 | var g = new Dygraph(graph, |
| 19 | "X,Y\n" + |
| 20 | "1,1\n" + |
| 21 | "50,50\n" + |
| 22 | "100,100\n" |
| 23 | ); |
| 24 | |
| 25 | g.setSelection(0); |
| 26 | assert.equal(0, g.getSelection()); |
| 27 | g.setSelection(1); |
| 28 | assert.equal(1, g.getSelection()); |
| 29 | g.setSelection(2); |
| 30 | assert.equal(2, g.getSelection()); |
| 31 | }); |
| 32 | |
| 33 | it('testSetGetSelectionDense', function() { |
| 34 | var graph = document.getElementById("graph"); |
| 35 | var g = new Dygraph(graph, |
| 36 | "X,Y\n" + |
| 37 | "1,1\n" + |
| 38 | "50,50\n" + |
| 39 | "50.0001,50.0001\n" + |
| 40 | "100,100\n" |
| 41 | ); |
| 42 | |
| 43 | g.setSelection(0); |
| 44 | assert.equal(0, g.getSelection()); |
| 45 | g.setSelection(1); |
| 46 | assert.equal(1, g.getSelection()); |
| 47 | g.setSelection(2); |
| 48 | assert.equal(2, g.getSelection()); |
| 49 | g.setSelection(3); |
| 50 | assert.equal(3, g.getSelection()); |
| 51 | }); |
| 52 | |
| 53 | it('testSetGetSelectionMissingPoints', function() { |
| 54 | var dataHandler = function() {}; |
| 55 | dataHandler.prototype = new DefaultHandler(); |
| 56 | dataHandler.prototype.seriesToPoints = function(series, setName, boundaryIdStart) { |
| 57 | var val = null; |
| 58 | if (setName == 'A') { |
| 59 | val = 1; |
| 60 | } else if (setName == 'B') { |
| 61 | val = 2; |
| 62 | } else if (setName == 'C') { |
| 63 | val = 3; |
| 64 | } |
| 65 | return [{ |
| 66 | x: NaN, |
| 67 | y: NaN, |
| 68 | xval: val, |
| 69 | yval: val, |
| 70 | name: setName, |
| 71 | idx: val - 1 |
| 72 | }]; |
| 73 | }; |
| 74 | var graph = document.getElementById("graph"); |
| 75 | var g = new Dygraph(graph, |
| 76 | "X,A,B,C\n" + |
| 77 | "1,1,,\n" + |
| 78 | "2,,2,\n" + |
| 79 | "3,,,3\n", |
| 80 | { |
| 81 | dataHandler: dataHandler |
| 82 | } |
| 83 | ); |
| 84 | |
| 85 | g.setSelection(0); |
| 86 | assert.equal(0, g.getSelection()); |
| 87 | g.setSelection(1); |
| 88 | assert.equal(1, g.getSelection()); |
| 89 | g.setSelection(2); |
| 90 | assert.equal(2, g.getSelection()); |
| 91 | }); |
| 92 | |
| 93 | }); |