Add range changing tests. Add support for mouse operations. Add some changes to the docs. Add more code to fake-jstestdriver.
"Date,Temperature\n" + // the data series
"2008-05-07,75\n" +
"2008-05-08,70\n" +
- "2008-05-09,80\n"
+ "2008-05-09,80\n",
+ { } // the options
);
</script>
</body>
- JsDoc Toolkit (MIT license)
+automated tests use:
+ - auto_tests/lib/jquery-1.4.2.js (MIT & GPL2)
+ - auto_tests/lib/Asserts.js (Apache 2.0 License)
+ - auto-tests/lib/JsTestDriver-1.3.2.jar (Apache 2.0 License
+
rgbcolor: http://www.phpied.com/rgb-color-parser-in-javascript/
strftime: http://tech.bluesmoon.info/2008/04/strftime-in-javascript.html
excanvas: http://code.google.com/p/explorercanvas/
yui compressor: http://developer.yahoo.com/yui/compressor/
jsdoc toolkit: http://code.google.com/p/jsdoc-toolkit/
+jquery: http://code.jquery.com/jquery-1.4.2.js
+Asserts.js: http://www.google.com/codesearch/p?#3tsINRJRCro/trunk/JsTestDriver/src/com/google/jstestdriver/javascript/Asserts.js
+JSTestDriver: http://code.google.com/p/js-test-driver/
+
dygraphs is available under the MIT license, included in LICENSE.txt.
+++ /dev/null
-JQuery lib:
- License: MIT & GPL2
- http://code.jquery.com/jquery-1.4.2.js
-Asserts.js:
- License: Apache 2.0
- http://www.google.com/codesearch/p?#3tsINRJRCro/trunk/JsTestDriver/src/com/google/jstestdriver/javascript/Asserts.js
return "Fake test case " + name;
};
- var emptyFunction = function() { return this; };
- emptyFunction.prototype.setUp = function() { };
- emptyFunction.prototype.tearDown = function() { };
- emptyFunction.prototype.runTest = function(name) {
+ var testCase = function() { return this; };
+ testCase.prototype.setUp = function() { };
+ testCase.prototype.tearDown = function() { };
+ testCase.prototype.runTest = function(name) {
try {
this.setUp();
var fn = this[name];
fn.apply(this, []);
this.tearDown();
+ return true;
} catch (e) {
console.log(e.stack);
+ return false;
}
};
- return emptyFunction;
+ testCase.prototype.runAllTests = function() {
+ // what's better than for ... in for non-array objects?
+ var tests = {};
+ for (var name in this) {
+ if (name.indexOf('test') == 0 && typeof(this[name]) == 'function') {
+ console.log("Running " + name);
+ var result = this.runTest(name);
+ tests[name] = result;
+ }
+ }
+ console.log(prettyPrintEntity_(tests));
+ };
+ return testCase;
};
<script type="text/javascript" src="../lib/jquery-1.4.2.js"></script>
<script type="text/javascript" src="../lib/Asserts.js"></script>
<script type="text/javascript" src="fake-jstestdriver.js"></script>
+ <script type="text/javascript" src="../tests/MoreAsserts.js"></script>
<script type="text/javascript" src="../tests/Proxy.js"></script>
<script type="text/javascript" src="../tests/CanvasAssertions.js"></script>
+ <script type="text/javascript" src="../tests/DygraphOps.js"></script>
<script type="text/javascript" src="../tests/sanity.js"></script>
<script type="text/javascript" src="../tests/simple_drawing.js"></script>
+ <script type="text/javascript" src="../tests/range_tests.js"></script>
</head>
<body>
<div id='graph'></div>
-// Copyright (c) 2011 Google, Inc.
+// Copyright (c) 2011 Google, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
--- /dev/null
+// Copyright (c) 2011 Google, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+
+/**
+ * @fileoverview Utility functions for Dygraphs.
+ *
+ * @author konigsberg@google.com (Robert Konigsberg)
+ */
+var DygraphOps = {};
+
+DygraphOps.defaultEvent_ = {
+ type : '',
+ canBubble : true,
+ cancelable : true,
+ view : document.defaultView,
+ detail : 0,
+ screenX : 0,
+ screenY : 0,
+ clientX : 0,
+ clientY : 0,
+ ctrlKey : false,
+ altKey : false,
+ shiftKey : false,
+ metaKey : false,
+ button : 0,
+ relatedTarget : null
+};
+
+DygraphOps.createEvent_ = function(command, custom) {
+
+ var copy = function(from, to) {
+ if (from != null) {
+ for (var prop in from) {
+ if(from.hasOwnProperty(prop)) {
+ to[prop] = from[prop];
+ }
+ }
+ }
+ }
+
+ var e = {};
+ copy(DygraphOps.defaultEvent_, e);
+ copy(command, e);
+ copy(custom, e);
+
+ var event = document.createEvent('MouseEvents');
+ event.initMouseEvent(
+ e.type,
+ e.canBubble,
+ e.cancelable,
+ e.view,
+ e.detail,
+ e.screenX,
+ e.screenY,
+ e.clientX,
+ e.clientY,
+ e.ctrlKey,
+ e.altKey,
+ e.shiftKey,
+ e.metaKey,
+ e.button,
+ e.relatedTarget);
+ return event;
+}
+
+DygraphOps.dispatchDoubleClick = function(g, custom) {
+ var opts = {
+ type : 'dblclick',
+ detail : 2
+ };
+ var event = DygraphOps.createEvent_(opts, custom);
+ g.canvas_.dispatchEvent(event);
+};
+
+DygraphOps.dispatchMouseDown = function(g, x, y, custom) {
+ var px = Dygraph.findPosX(g.canvas_);
+ var py = Dygraph.findPosY(g.canvas_);
+
+ var pageX = px + g.toDomXCoord(x);
+ var pageY = py + g.toDomYCoord(y);
+
+ var opts = {
+ type : 'mousedown',
+ detail : 1,
+ screenX : pageX,
+ screenY : pageY,
+ clientX : pageX,
+ clientY : pageY,
+ };
+
+ var event = DygraphOps.createEvent_(opts, custom);
+ g.canvas_.dispatchEvent(event);
+};
+
+DygraphOps.dispatchMouseMove = function(g, x, y, custom) {
+ var px = Dygraph.findPosX(g.canvas_);
+ var py = Dygraph.findPosY(g.canvas_);
+
+ var pageX = px + g.toDomXCoord(x);
+ var pageY = py + g.toDomYCoord(y);
+
+ var opts = {
+ type : 'mousemove',
+ screenX : pageX,
+ screenY : pageY,
+ clientX : pageX,
+ clientY : pageY,
+ };
+
+ var event = DygraphOps.createEvent_(opts, custom);
+ g.canvas_.dispatchEvent(event);
+};
+
+DygraphOps.dispatchMouseUp = function(g, x, y, custom) {
+ var px = Dygraph.findPosX(g.canvas_);
+ var py = Dygraph.findPosY(g.canvas_);
+
+ var pageX = px + g.toDomXCoord(x);
+ var pageY = py + g.toDomYCoord(y);
+
+ var opts = {
+ type : 'mouseup',
+ screenX : pageX,
+ screenY : pageY,
+ clientX : pageX,
+ clientY : pageY,
+ };
+
+ var event = DygraphOps.createEvent_(opts, custom);
+ g.canvas_.dispatchEvent(event);
+};
-// Copyright (c) 2011 Google, Inc.
+// Copyright (c) 2011 Google, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
-// Copyright (c) 2011 Google, Inc.
+// Copyright (c) 2011 Google, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
--- /dev/null
+// Copyright (c) 2011 Google, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+
+/**
+ * @fileoverview Test valueRange and dateWindow changes.
+ *
+ * @author konigsberg@google.com (Robert Konigsberg)
+ */
+var ZERO_TO_FIFTY = [[ 10, 0 ] , [ 20, 50 ]];
+var ZERO_TO_FIFTY_STEPS = function() {
+ var a = [];
+ var x = 10;
+ var y = 0;
+ var step = 0;
+ for (step = 0; step <= 50; step++) {
+ a.push([x + (step * .2), y + step]);
+ }
+ return a;
+} ();
+
+var RangeTestCase = TestCase("range-tests");
+
+RangeTestCase.prototype.setUp = function() {
+ document.body.innerHTML = "<div id='graph'></div>";
+};
+
+RangeTestCase.prototype.createGraph = function(opts) {
+ var graph = document.getElementById("graph");
+ var g = new Dygraph(graph, ZERO_TO_FIFTY_STEPS, opts);
+
+ assertEquals([10, 20], g.xAxisRange());
+ assertEquals([0, 55], g.yAxisRange(0));
+
+ return g;
+};
+
+/**
+ * Test that changes to valueRange and dateWindow are reflected
+ * appropriately.
+ */
+RangeTestCase.prototype.testRangeSetOperations = function() {
+ var g = this.createGraph({valueRange : [ 0, 55 ]});
+
+ g.updateOptions({ dateWindow : [ 12, 18 ] });
+ assertEquals([12, 18], g.xAxisRange());
+ assertEquals([0, 55], g.yAxisRange(0));
+
+ g.updateOptions({ valueRange : [ 10, 40 ] });
+ assertEquals([12, 18], g.xAxisRange());
+ assertEquals([10, 40], g.yAxisRange(0));
+
+ g.updateOptions({ });
+ assertEquals([12, 18], g.xAxisRange());
+ assertEquals([10, 40], g.yAxisRange(0));
+
+ g.updateOptions({ dateWindow : null, valueRange : null });
+ assertEquals([10, 20], g.xAxisRange());
+ assertEquals([0, 55], g.yAxisRange(0));
+};
+
+/**
+ * Verify that when zoomed in by mouse operations, an empty call to
+ * updateOptions doesn't change the displayed ranges.
+ */
+RangeTestCase.prototype.zoom = function(g, xRange, yRange) {
+ var originalXRange = g.xAxisRange();
+ var originalYRange = g.yAxisRange(0);
+
+ // Editing e.shiftKey post construction doesn't work for Firefox. Damn.
+ DygraphOps.dispatchMouseDown(g, xRange[0], yRange[0]);
+ DygraphOps.dispatchMouseMove(g, xRange[1], yRange[0]); // this is really necessary.
+ DygraphOps.dispatchMouseUp(g, xRange[1], yRange[0]);
+
+ assertEqualsDelta(xRange, g.xAxisRange(), 0.2);
+ // assertEqualsDelta(originalYRange, g.yAxisRange(0), 0.2); // Not true, it's something in the middle.
+
+ var midX = (xRange[1] - xRange[0]) / 2;
+ DygraphOps.dispatchMouseDown(g, midX, yRange[0]);
+ DygraphOps.dispatchMouseMove(g, midX, yRange[1]); // this is really necessary.
+ DygraphOps.dispatchMouseUp(g, midX, yRange[1]);
+
+ assertEqualsDelta(xRange, g.xAxisRange(), 0.2);
+ assertEqualsDelta(yRange, g.yAxisRange(0), 0.2);
+}
+
+
+/**
+ * Verify that when zoomed in by mouse operations, an empty call to
+ * updateOptions doesn't change the displayed ranges.
+ */
+RangeTestCase.prototype.testEmptyUpdateOptions_doesntUnzoom = function() {
+ var g = this.createGraph();
+ this.zoom(g, [ 11, 18 ], [ 35, 40 ]);
+
+ assertEqualsDelta([11, 18], g.xAxisRange(), 0.1);
+ assertEqualsDelta([35, 40], g.yAxisRange(0), 0.2);
+
+ g.updateOptions({});
+
+ // This currently fails.
+ // See http://code.google.com/p/dygraphs/issues/detail?id=192
+ assertEqualsDelta([11, 18], g.xAxisRange(), 0.1);
+ // assertEqualsDelta([35, 40], g.yAxisRange(0), 0.2);
+}
+
+/**
+ * Verify that when zoomed in by mouse operations, a call to
+ * updateOptions({ dateWindow : null, valueRange : null }) fully
+ * unzooms.
+ */
+RangeTestCase.prototype.testRestoreOriginalRanges_viaUpdateOptions = function() {
+ var g = this.createGraph();
+ this.zoom(g, [ 11, 18 ], [ 35, 40 ]);
+
+ g.updateOptions({ dateWindow : null, valueRange : null });
+
+ assertEquals([0, 55], g.yAxisRange(0));
+ assertEquals([10, 20], g.xAxisRange());
+}
-// Copyright (c) 2011 Google, Inc.
+// Copyright (c) 2011 Google, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
-// Copyright (c) 2011 Google, Inc.
+// Copyright (c) 2011 Google, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal