--- /dev/null
+<html>
+<head>
+ <meta charset="utf-8">
+ <title>dygraphs tests</title>
+ <link rel="stylesheet" href="../node_modules/mocha/mocha.css" />
+</head>
+<body>
+ <div id="graph"></div>
+ <div id="mocha"></div>
+
+ <!-- Polyfills for PhantomJS -->
+ <script src="../node_modules/babel/node_modules/babel-core/browser-polyfill.js"></script>
+
+ <!-- Mocha -->
+ <script src="../node_modules/mocha/mocha.js"></script>
+ <script src="../node_modules/chai/chai.js"></script>
+ <script>
+ var expect = chai.expect;
+ var assert = chai.assert;
+ function cleanupAfterEach() {
+ // Clean up the DOM before each test.
+ // This makes debugging easier than cleaning up after each test, since the
+ // DOM stays on the screen after a failure.
+ beforeEach(function() {
+ var graph = document.getElementById('graph');
+ graph.innerHTML = '';
+ graph.setAttribute('style', '');
+ });
+ }
+ function useProxyCanvas(utils, Proxy) {
+ var _origFunc = utils.getContext;
+ beforeEach(function() {
+ utils.getContext = function(canvas) {
+ return new Proxy(_origFunc(canvas));
+ }
+ });
+
+ afterEach(function() {
+ utils.getContext = _origFunc;
+ });
+ }
+ </script>
+ <script>mocha.setup('bdd')</script>
+
+ <!-- Test data -->
+ <script src="data/data.js"></script>
+
+ <!-- Bundled tests -->
+ <script src="../dist/tests.js"></script>
+
+ <script>
+ mocha.checkLeaks();
+ if (window.mochaPhantomJS) {
+ mochaPhantomJS.run();
+ } else {
+ mocha.run();
+ }
+ </script>
+</body>
+</html>
}
return true;
};
+
+export default CanvasAssertions;
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
+import * as utils from '../../src/dygraph-utils';
/**
* @fileoverview Utility functions for Dygraphs.
* type, screenX, screenY, clientX, clientY.
*/
DygraphOps.createOptsForPoint_ = function(g, type, x, y) {
- var pos = Dygraph.findPos(g.canvas_);
+ var pos = utils.findPos(g.canvas_);
var pageX = pos.x + x;
var pageY = pos.y + y;
custom);
};
+
+export default DygraphOps;
};
/**
+ * Convenience wrapper around colorAtPixel if you only care about RGB (not A).
+ * @param {number} x The screen x-coordinate at which to sample.
+ * @param {number} y The screen y-coordinate at which to sample.
+ * @return {Array.<number>} a 3D array: [R, G, B]. All three values
+ * are in [0, 255]. A pixel which has never been touched will be [0,0,0].
+ */
+PixelSampler.prototype.rgbAtPixel = function(x, y) {
+ return this.colorAtPixel(x, y).slice(0, 3);
+};
+
+/**
* The method samples a color using data coordinates (not screen coordinates).
* This will round your data coordinates to the nearest screen pixel before
* sampling.
var dom_xy = this.dygraph_.toDomCoords(x, y);
return this.colorAtPixel(Math.round(dom_xy[0]), Math.round(dom_xy[1]));
};
+
+export default PixelSampler;
Proxy.reset = function(proxy) {
proxy.calls__ = [];
}
+
+export default Proxy;
*
* @author konigsberg@google.com (Robert Konigsberg)
*/
+
+import * as utils from '../../src/dygraph-utils';
+
var Util = {};
/**
/**
* Sample a pixel from the canvas.
* Returns an [r, g, b, a] tuple where each values is in [0, 255].
+ * This is _very_ slow! If you want to sample many pixels, use PixelSampler.
*/
Util.samplePixel = function(canvas, x, y) {
var ctx = canvas.getContext("2d"); // bypasses Proxy if applied.
- // TODO(danvk): Any performance issues with this?
var imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
- var scale = Dygraph.getContextPixelRatio(ctx);
+ var scale = utils.getContextPixelRatio(ctx);
var i = 4 * (x * scale + imageData.width * y * scale);
var d = imageData.data;
* @return {string} The date formatted as YYYY-MM-DD.
*/
Util.formatDate = function(dateMillis) {
- return Dygraph.dateString_(dateMillis).slice(0, 10); // 10 == "YYYY/MM/DD".length
+ return utils.dateString_(dateMillis).slice(0, 10); // 10 == "YYYY/MM/DD".length
};
/**
console.error = orig[2];
};
};
+
+export default Util;
*
* @author danvk@google.com (Dan Vanderkam)
*/
-describe("annotations", function() {
-beforeEach(function() {
- document.body.innerHTML = "<div id='graph'></div>";
-});
+import Dygraph from '../../src/dygraph';
+import Util from './Util';
-afterEach(function() {
-});
+describe("annotations", function() {
+
+cleanupAfterEach();
it('testAnnotationsDrawn', function() {
var opts = {
+++ /dev/null
-/**
- * @fileoverview Test cases for how axis labels are chosen and formatted,
- * specializing on the deprecated xLabelFormatter, etc.
- *
- * @author dan@dygraphs.com (Dan Vanderkam)
- */
-describe("axis-labels-deprecated", function() {
-
-beforeEach(function() {
- document.body.innerHTML = "<div id='graph'></div>";
-});
-
-afterEach(function() {
-});
-
-it('testDeprecatedDeprecatedXAxisTimeLabelFormatter', function() {
- var opts = {
- width: 480,
- height: 320,
- labels: ['X', 'Y1']
- };
- var data = [[5.0,0],[5.1,1],[5.2,2],[5.3,3],[5.4,4],[5.5,5],[5.6,6],[5.7,7],[5.8,8],[5.9,9]];
- var graph = document.getElementById("graph");
- var g = new Dygraph(graph, data, opts);
- g.updateOptions({
- axes : {
- x : {
- axisLabelFormatter: function (totalMinutes) {
- var hours = Math.floor( totalMinutes / 60);
- var minutes = Math.floor((totalMinutes - (hours * 60)));
- var seconds = Math.round((totalMinutes * 60) - (hours * 3600) - (minutes * 60));
-
- if (hours < 10) hours = "0" + hours;
- if (minutes < 10) minutes = "0" + minutes;
- if (seconds < 10) seconds = "0" + seconds;
-
- return hours + ':' + minutes + ':' + seconds;
- }
- }
- }
- });
-
- assert.deepEqual(["00:05:00","00:05:12","00:05:24","00:05:36","00:05:48"], Util.getXLabels());
-
- // The legend does not use the xAxisLabelFormatter:
- g.setSelection(1);
- assert.equal('5.1: Y1: 1', Util.getLegend());
-});
-
-it('testDeprecatedAxisLabelFormatter', function() {
- var opts = {
- width: 480,
- height: 320,
- axes : {
- x : {
- axisLabelFormatter: function(x, granularity, opts, dg) {
- assert.equal('number', typeof(x));
- assert.equal('number', typeof(granularity));
- assert.equal('function', typeof(opts));
- assert.equal('[Dygraph graph]', dg.toString());
- return 'x' + x;
- }
- },
- y : {
- axisLabelFormatter: function(y, granularity, opts, dg) {
- assert.equal('number', typeof(y));
- assert.equal('number', typeof(granularity));
- assert.equal('function', typeof(opts));
- assert.equal('[Dygraph graph]', dg.toString());
- return 'y' + y;
- }
- }
- },
- labels: ['x', 'y']
- };
- var data = [];
- for (var i = 0; i < 10; i++) {
- data.push([i, 2 * i]);
- }
- var graph = document.getElementById("graph");
- var g = new Dygraph(graph, data, opts);
-
- assert.deepEqual(['x0','x2','x4','x6','x8'], Util.getXLabels());
- assert.deepEqual(["y0","y5","y10","y15"], Util.getYLabels());
-
- g.setSelection(2);
- assert.equal("2: y: 4", Util.getLegend());
-});
-
-it('testDeprecatedDateAxisLabelFormatter', function() {
- var opts = {
- width: 480,
- height: 320,
- axes : {
- x : {
- axisLabelFormatter: function(x, granularity, opts, dg) {
- assert.isTrue(Dygraph.isDateLike(x));
- assert.equal('number', typeof(granularity));
- assert.equal('function', typeof(opts));
- assert.equal('[Dygraph graph]', dg.toString());
- return 'x' + Util.formatDate(x);
- },
- pixelsPerLabel: 60
- },
- y : {
- axisLabelFormatter: function(y, granularity, opts, dg) {
- assert.equal('number', typeof(y));
- assert.equal('number', typeof(granularity));
- assert.equal('function', typeof(opts));
- assert.equal('[Dygraph graph]', dg.toString());
- return 'y' + y;
- }
- }
- },
- labels: ['x', 'y']
- };
- var data = [];
- for (var i = 1; i < 10; i++) {
- data.push([new Date("2011/01/0" + i), 2 * i]);
- }
- var graph = document.getElementById("graph");
- var g = new Dygraph(graph, data, opts);
-
- assert.deepEqual(["x2011/01/02","x2011/01/04","x2011/01/06","x2011/01/08"], Util.getXLabels());
- assert.deepEqual(["y5","y10","y15"], Util.getYLabels());
-
- g.setSelection(0);
- assert.equal("2011/01/01: y: 2", Util.getLegend());
-});
-
-// This test verifies that when a valueFormatter is set (but not an
-// axisLabelFormatter), then the valueFormatter is used to format the axis
-// labels.
-it('testDeprecatedValueFormatter', function() {
- var opts = {
- width: 480,
- height: 320,
- axes : {
- x : {
- valueFormatter: function(x, opts, series_name, dg) {
- assert.equal('number', typeof(x));
- assert.equal('function', typeof(opts));
- assert.equal('string', typeof(series_name));
- assert.equal('[Dygraph graph]', dg.toString());
- return 'x' + x;
- }
- },
- y : {
- valueFormatter: function(y, opts, series_name, dg) {
- assert.equal('number', typeof(y));
- assert.equal('function', typeof(opts));
- assert.equal('string', typeof(series_name));
- assert.equal('[Dygraph graph]', dg.toString());
- return 'y' + y;
- }
- }
- },
- labels: ['x', 'y']
- };
- var data = [];
- for (var i = 0; i < 10; i++) {
- data.push([i, 2 * i]);
- }
- var graph = document.getElementById("graph");
- var g = new Dygraph(graph, data, opts);
-
- // the valueFormatter options do not affect the ticks.
- assert.deepEqual(['0','2','4','6','8'], Util.getXLabels());
- assert.deepEqual(["0","5","10","15"], Util.getYLabels());
-
- // they do affect the legend, however.
- g.setSelection(2);
- assert.equal("x2: y: y4", Util.getLegend());
-});
-
-it('testDeprecatedDateValueFormatter', function() {
- var opts = {
- width: 480,
- height: 320,
- axes : {
- x : {
- valueFormatter: function(x, opts, series_name, dg) {
- assert.equal('number', typeof(x));
- assert.equal('function', typeof(opts));
- assert.equal('string', typeof(series_name));
- assert.equal('[Dygraph graph]', dg.toString());
- return 'x' + Util.formatDate(x);
- },
- pixelsPerLabel: 60
- },
- y : {
- valueFormatter: function(y, opts, series_name, dg) {
- assert.equal('number', typeof(y));
- assert.equal('function', typeof(opts));
- assert.equal('string', typeof(series_name));
- assert.equal('[Dygraph graph]', dg.toString());
- return 'y' + y;
- }
- }
- },
- labels: ['x', 'y']
- };
-
- var data = [];
- for (var i = 1; i < 10; i++) {
- data.push([new Date("2011/01/0" + i), 2 * i]);
- }
- var graph = document.getElementById("graph");
- var g = new Dygraph(graph, data, opts);
-
- // valueFormatters do not affect ticks.
- assert.deepEqual(["02 Jan","04 Jan","06 Jan","08 Jan"], Util.getXLabels());
- assert.deepEqual(["5","10","15"], Util.getYLabels());
-
- // the valueFormatter options also affect the legend.
- g.setSelection(2);
- assert.equal('x2011/01/03: y: y6', Util.getLegend());
-});
-
-// This test verifies that when both a valueFormatter and an axisLabelFormatter
-// are specified, the axisLabelFormatter takes precedence.
-it('testDeprecatedAxisLabelFormatterPrecedence', function() {
- var opts = {
- width: 480,
- height: 320,
- axes : {
- x : {
- valueFormatter: function(x) {
- return 'xvf' + x;
- },
- axisLabelFormatter: function(x, granularity) {
- return 'x' + x;
- },
- },
- y : {
- valueFormatter: function(y) {
- return 'yvf' + y;
- },
- axisLabelFormatter: function(y) {
- return 'y' + y;
- },
- }
- },
- labels: ['x', 'y']
- };
- var data = [];
- for (var i = 0; i < 10; i++) {
- data.push([i, 2 * i]);
- }
- var graph = document.getElementById("graph");
- var g = new Dygraph(graph, data, opts);
-
- assert.deepEqual(['x0','x2','x4','x6','x8'], Util.getXLabels());
- assert.deepEqual(["y0","y5","y10","y15"], Util.getYLabels());
-
- g.setSelection(9);
- assert.equal("xvf9: y: yvf18", Util.getLegend());
-});
-
-// This is the same as the previous test, except that options are added
-// one-by-one.
-it('testDeprecatedAxisLabelFormatterIncremental', function() {
- var opts = {
- width: 480,
- height: 320,
- labels: ['x', 'y']
- };
- var data = [];
- for (var i = 0; i < 10; i++) {
- data.push([i, 2 * i]);
- }
- var graph = document.getElementById("graph");
- var g = new Dygraph(graph, data, opts);
- g.updateOptions({
- axes : {
- x : {
- valueFormatter: function(x) {
- return 'xvf' + x;
- }
- }
- }
- });
- g.updateOptions({
- axes : {
- y : {
- valueFormatter: function(y) {
- return 'yvf' + y;
- }
- }
- }
- });
- g.updateOptions({
- axes : {
- x : {
- axisLabelFormatter: function(x) {
- return 'x' + x;
- }
- }
- }
- });
- g.updateOptions({
- axes : {
- y : {
- axisLabelFormatter: function(y) {
- return 'y' + y;
- }
- }
- }
- });
-
- assert.deepEqual(["x0","x2","x4","x6","x8"], Util.getXLabels());
- assert.deepEqual(["y0","y5","y10","y15"], Util.getYLabels());
-
- g.setSelection(9);
- assert.equal("xvf9: y: yvf18", Util.getLegend());
-});
-
-});
*
* @author dan@dygraphs.com (Dan Vanderkam)
*/
-describe("axis-labels", function() {
-beforeEach(function() {
- document.body.innerHTML = "<div id='graph'></div>";
-});
+import Dygraph from '../../src/dygraph';
+import * as utils from '../../src/dygraph-utils';
+import DEFAULT_ATTRS from '../../src/dygraph-default-attrs';
+import Util from './Util';
+import {assertDeepCloseTo} from './custom_asserts';
-afterEach(function() {
-});
+describe("axis-labels", function() {
+
+cleanupAfterEach();
var simpleData =
"X,Y,Y2\n" +
x : {
pixelsPerLabel: 60,
axisLabelFormatter : function(x, granularity, opts, dg) {
- assert.isTrue(Dygraph.isDateLike(x));
+ assert.isTrue(utils.isDateLike(x));
assert.equal('number', typeof(granularity));
assert.equal('function', typeof(opts));
assert.equal('[Dygraph graph]', dg.toString());
var g = new Dygraph(graph, simpleData, {});
// Be sure we're dealing with a 14-point default.
- assert.equal(14, Dygraph.DEFAULT_ATTRS.axisLabelFontSize);
+ assert.equal(14, DEFAULT_ATTRS.axisLabelFontSize);
var assertFontSize = function(selector, expected) {
Util.assertStyleOfChildren(selector, "font-size", expected);
};
// Be sure we're dealing with a 14-point default.
- assert.equal(14, Dygraph.DEFAULT_ATTRS.axisLabelFontSize);
+ assert.equal(14, DEFAULT_ATTRS.axisLabelFontSize);
assertFontSize(document.querySelectorAll(".dygraph-axis-label-x"), "14px");
assertFontSize(document.querySelectorAll(".dygraph-axis-label-y"), "14px");
var g = new Dygraph(graph, simpleData, {});
// Be sure we're dealing with a black default.
- assert.equal("black", Dygraph.DEFAULT_ATTRS.axisLabelColor);
+ assert.equal("black", DEFAULT_ATTRS.axisLabelColor);
var assertColor = function(selector, expected) {
Util.assertStyleOfChildren(selector, "color", expected);
}
// Be sure we're dealing with a 14-point default.
- assert.equal(14, Dygraph.DEFAULT_ATTRS.axisLabelFontSize);
+ assert.equal(14, DEFAULT_ATTRS.axisLabelFontSize);
assertColor(document.querySelectorAll(".dygraph-axis-label-x"), "rgb(0, 0, 0)");
assertColor(document.querySelectorAll(".dygraph-axis-label-y"), "rgb(0, 0, 0)");
* @author uemit.seren@gmail.com (Ãœmit Seren)
*/
+import Dygraph from '../../src/dygraph';
+import * as utils from '../../src/dygraph-utils';
+import Util from './Util';
+import DygraphOps from './DygraphOps';
+
describe("callback", function() {
+cleanupAfterEach();
+
var xhr, styleSheet;
+var graph;
beforeEach(function() {
- document.body.innerHTML = "<div id='graph'></div><div id='selection'></div>";
+ var container = document.getElementById('graph');
+ container.innerHTML = "<div id='inner-graph'></div><div id='selection'></div>";
+ graph = container.querySelector('#inner-graph');
xhr = XMLHttpRequest;
styleSheet = document.createElement("style");
styleSheet.type = "text/css";
h_pts = pts;
};
- var graph = document.getElementById("graph");
var g = new Dygraph(graph, data,
{
width: 100,
called = true;
};
- var graph = document.getElementById("graph");
var g = new Dygraph(graph, data, {
drawPointCallback: callback,
});
called = true;
};
- var graph = document.getElementById("graph");
var g = new Dygraph(graph, data, {
drawPoints: true,
drawPointCallback: callback
count++;
};
- var graph = document.getElementById("graph");
var g = new Dygraph(graph, data, {
drawPoints: true,
drawPointCallback: callback
assert.equal(g, this);
var dx = g.toDataXCoord(cx);
xvalues.push(dx);
- Dygraph.Circles.DEFAULT.apply(this, arguments);
+ utils.Circles.DEFAULT.apply(this, arguments);
};
- var graph = document.getElementById("graph");
var testdata = [[10, 2], [11, 3], [12, NaN], [13, 2], [14, NaN], [15, 3]];
var graphOpts = {
labels: ['X', 'Y'],
called = true;
};
- var graph = document.getElementById("graph");
var g = new Dygraph(graph, data,
{
width: 100,
var h_pts;
var h_series;
- var graph = document.getElementById("graph");
var g = new Dygraph(graph, data,
{
width: 600,
h_pts = pts;
};
- var graph = document.getElementById("graph");
var g = new Dygraph(graph, dataNaN,
{
width: 600,
h_pts = pts;
};
- var graph = document.getElementById("graph");
var g = new Dygraph(graph, dataNaN,
{
width: 600,
h_pts = pts;
};
- var graph = document.getElementById("graph");
var g = new Dygraph(graph, dataGap, {
width: 400,
height: 300,
throw "should not reach here";
};
- var graph = document.getElementById("graph");
graph.style.border = "2px solid black";
var g = new Dygraph(graph, "data.csv", { // fake name
width: 400,
highlightRow = row;
};
- var graph = document.getElementById("graph");
var g = new Dygraph(graph,
"X,Y,Z\n" +
"0,1,2\n" + // 0
yMax = g.yAxisRange(0)[1];
};
- var graph = document.getElementById("graph");
var g = new Dygraph(graph, "\n", {
underlayCallback: callback
});
yMax = g.yAxisRange(0)[1];
};
- var graph = document.getElementById("graph");
var g = new Dygraph(graph, "\n", {
valueRange: [0,10],
underlayCallback: callback
var callback = function(g, seriesName, canvasContext, cx, cy, color, pointSizeParam,idx) {
assert.equal(g, this);
indices.push(idx);
- Dygraph.Circles.DEFAULT.apply(this, arguments);
+ utils.Circles.DEFAULT.apply(this, arguments);
};
- var graph = document.getElementById("graph");
var testdata = [[10, 2], [11, 3], [12, NaN], [13, 2], [14, NaN], [15, 3]];
var graphOpts = {
idxToCheck = idx;
};
var testdata = [[1, 2], [2, 3], [3, NaN], [4, 2], [5, NaN], [6, 3]];
- var graph = document.getElementById("graph");
var g = new Dygraph(graph, testdata, {
drawHighlightPointCallback: drawHighlightPointCallback,
labels: ['X', 'Y']
*
* @author julian.eichstaedt@ch.sauter-bc.com (Fr. Sauter AG)
*/
+
+import Dygraph from '../../src/dygraph';
+import * as utils from '../../src/dygraph-utils';
+import CanvasAssertions from './CanvasAssertions';
+import Proxy from './Proxy';
+
describe("connect-separated-points", function() {
-beforeEach(function() {
- document.body.innerHTML = "<div id='graph'></div>";
-});
+cleanupAfterEach();
-var origFunc = Dygraph.getContext;
+var origFunc = utils.getContext;
beforeEach(function() {
- document.body.innerHTML = "<div id='graph'></div>";
- Dygraph.getContext = function(canvas) {
+ utils.getContext = function(canvas) {
return new Proxy(origFunc(canvas));
};
});
* @fileoverview Regression test based on some strange customBars data.
* @author danvk@google.com (Dan Vanderkam)
*/
+
+import Dygraph from '../../src/dygraph';
+
describe("css", function() {
+cleanupAfterEach();
+
var data = "X,Y,Z\n1,2,3\n4,5,6\n";
var styleSheet;
beforeEach(function() {
- document.body.innerHTML = "<div id='graph'></div>";
styleSheet = document.createElement("style");
styleSheet.type = "text/css";
document.getElementsByTagName("head")[0].appendChild(styleSheet);
});
afterEach(function() {
+ styleSheet.innerHTML = '';
});
// Verifies that an unstyled, unsized dygraph gets a default size.
// Verifies that a CSS percentage size works.
it('testPercentageSize', function() {
- document.body.innerHTML =
+ var testdiv = document.getElementById("graph");
+ testdiv.innerHTML =
'<div style="width: 600px; height: 400px;">' +
- '<div id="graph"></div></div>';
+ '<div id="inner-graph"></div></div>';
var opts = {
};
- var graph = document.getElementById("graph");
+ var graph = document.getElementById("inner-graph");
graph.style.width = '50%';
graph.style.height = '50%';
// An invisible chart div shouldn't produce an error.
it('testInvisibleChart', function() {
- document.body.innerHTML =
+ graph.innerHTML =
'<div style="display:none;">' +
- '<div id="graph" style="width: 640px; height: 480px;"></div>' +
+ '<div id="inner-graph" style="width: 640px; height: 480px;"></div>' +
'</div>';
- var graph = document.getElementById("graph");
- new Dygraph(graph, data, {});
+ new Dygraph('inner-graph', data, {});
});
// An invisible chart div shouldn't produce an error.
it('testInvisibleChartDate', function() {
- document.body.innerHTML =
+ graph.innerHTML =
'<div style="display:none;">' +
- '<div id="graph" style="width: 640px; height: 480px;"></div>' +
+ '<div id="inner-graph" style="width: 640px; height: 480px;"></div>' +
'</div>';
- var graph = document.getElementById("graph");
- new Dygraph(graph,
+ new Dygraph('inner-graph',
"Date,Y\n" +
"2010/01/01,100\n" +
"2010/02/01,200\n" +
// An invisible chart div that becomes visible.
it('testInvisibleThenVisibleChart', function() {
- document.body.innerHTML =
+ var testdiv = document.getElementById("graph");
+ testdiv.innerHTML =
'<div id="x" style="display:none;">' +
- '<div id="graph" style="width: 640px; height: 480px;"></div>' +
+ '<div id="inner-graph" style="width: 640px; height: 480px;"></div>' +
'</div>';
- var graph = document.getElementById("graph");
+ var graph = document.getElementById("inner-graph");
var g = new Dygraph(graph,
"Date,Y\n" +
"2010/01/01,100\n" +
* @fileoverview Assertions that chai doesn't provide out of the box.
*/
-var assertDeepCloseTo = function(actualArray, expectedArray, epsilon) {
+export function assertDeepCloseTo(actualArray, expectedArray, epsilon) {
assert.isArray(actualArray);
assert.isArray(expectedArray);
for (var i = 0; i < actualArray.length; i++) {
* @fileoverview Regression test based on some strange customBars data.
* @author danvk@google.com (Dan Vanderkam)
*/
+import Dygraph from '../../src/dygraph';
+import * as utils from '../../src/dygraph-utils';
+import CanvasAssertions from './CanvasAssertions';
+import PixelSampler from './PixelSampler';
+import Proxy from './Proxy';
+
describe("custom-bars", function() {
-var _origFunc = Dygraph.getContext;
+cleanupAfterEach();
+
+var _origFunc = utils.getContext;
beforeEach(function() {
- document.body.innerHTML = "<div id='graph'></div>";
- Dygraph.getContext = function(canvas) {
+ utils.getContext = function(canvas) {
return new Proxy(_origFunc(canvas));
}
});
afterEach(function() {
- Dygraph.getContext = _origFunc;
+ utils.getContext = _origFunc;
});
// This test used to reliably produce an infinite loop.
*
* @author danvdk@gmail.com (Dan Vanderkam)
*/
+import Dygraph from '../../src/dygraph';
describe("data-api", function() {
+cleanupAfterEach();
+
var opts, graphDiv;
beforeEach(function() {
- document.body.innerHTML = "<div id='graph'></div>";
opts = {
width: 480,
height: 320
graphDiv = document.getElementById("graph");
});
-afterEach(function() {
-});
-
it('testBasicAccessors', function() {
var g = new Dygraph(graphDiv, temperature_data, opts);
*
* @author dan@dygraphs.com (Dan Vanderkam)
*/
-describe("date-formats", function() {
-beforeEach(function() {
-});
+import * as utils from '../../src/dygraph-utils';
-afterEach(function() {
-});
+describe("date-formats", function() {
it('testISO8601', function() {
// Format: YYYY-MM-DDTHH:MM:SS.ddddddZ
// Firefox <4 does not support this format:
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date/parse
if (navigator.userAgent.indexOf("Firefox/3.5") == -1) {
- assert.equal(946816496789, Dygraph.dateParser("2000-01-02T12:34:56.789012Z"));
+ assert.equal(946816496789, utils.dateParser("2000-01-02T12:34:56.789012Z"));
}
});
zp(d.getDate()) + ' ' +
zp(d.getHours()) + ':' +
zp(d.getMinutes());
- assert.equal(Date.UTC(2000, 1, 2), Dygraph.dateParser(str));
+ assert.equal(Date.UTC(2000, 1, 2), utils.dateParser(str));
});
});
* @author danvdk@gmail.com (Dan Vanderkam)
*/
+import * as DygraphTickers from '../../src/dygraph-tickers';
+import DEFAULT_ATTRS from '../../src/dygraph-default-attrs';
+
describe("date-ticker-tests", function() {
-beforeEach(function() {
- document.body.innerHTML = "<div id='graph'></div>";
-});
+cleanupAfterEach();
var createOptionsViewForAxis = function(axis, dict) {
return function (x) {
if (dict && dict.hasOwnProperty(x)) {
return dict[x];
}
- if (Dygraph.DEFAULT_ATTRS.axes[axis].hasOwnProperty(x)) {
- return Dygraph.DEFAULT_ATTRS.axes[axis][x];
+ if (DEFAULT_ATTRS.axes[axis].hasOwnProperty(x)) {
+ return DEFAULT_ATTRS.axes[axis][x];
}
- if (Dygraph.DEFAULT_ATTRS.hasOwnProperty(x)) {
- return Dygraph.DEFAULT_ATTRS[x];
+ if (DEFAULT_ATTRS.hasOwnProperty(x)) {
+ return DEFAULT_ATTRS[x];
}
if (x == 'axisLabelFormatter') return null;
throw "mysterious " + axis + "-axis option: " + x;
var opts = {labelsUTC: true};
var options = createOptionsViewForAxis('x', opts);
- var ticks = Dygraph.dateTicker(-1797534000000, 1255579200000, 800, options);
+ var ticks = DygraphTickers.dateTicker(-1797534000000, 1255579200000, 800, options);
var expected_ticks = [
{"v":-1577923200000,"label":"1920"},
{"v":-1262304000000,"label":"1930"},
var start = Date.UTC(1999, 11, 31, 14, 0, 0);
var end = Date.UTC(2000, 0, 1, 12, 0, 0);
- var granularity = Dygraph.TWO_HOURLY;
- ticks = Dygraph.getDateAxis(start, end, granularity, options);
+ var granularity = DygraphTickers.Granularity.TWO_HOURLY;
+ ticks = DygraphTickers.getDateAxis(start, end, granularity, options);
changeNbspToSpace(ticks);
expected_ticks = [ // months of the year are zero-based.
{v: Date.UTC(1999, 11, 31, 14, 0, 0), label: '14:00'},
// In these tests, those spurious ticks are removed to test new behavior.
var ticker = function() {
- var ticks = Dygraph.dateTicker.apply(null, arguments);
+ var ticks = DygraphTickers.dateTicker.apply(null, arguments);
changeNbspToSpace(ticks);
return ticks;
};
/**
* @fileoverview Test cases for DygraphOptions.
*/
+
+import Dygraph from '../../src/dygraph';
+import DygraphOptions from '../../src/dygraph-options';
+
describe("dygraph-options-tests", function() {
+cleanupAfterEach();
+
var graph;
beforeEach(function() {
- document.body.innerHTML = "<div id='graph'></div>";
graph = document.getElementById("graph");
});
-afterEach(function() {
-});
-
/*
* Pathalogical test to ensure getSeriesNames works
*/
*
* @author danvk@google.com (Dan Vanderkam)
*/
-describe("error-bars", function() {
-beforeEach(function() {
- document.body.innerHTML = "<div id='graph'></div>";
-});
+import Dygraph from '../../src/dygraph';
+import * as utils from '../../src/dygraph-utils';
+import Util from './Util';
+import Proxy from './Proxy';
+import CanvasAssertions from './CanvasAssertions';
-var _origFunc = Dygraph.getContext;
-beforeEach(function() {
- document.body.innerHTML = "<div id='graph'></div>";
- Dygraph.getContext = function(canvas) {
- return new Proxy(_origFunc(canvas));
- }
-});
+describe("error-bars", function() {
-afterEach(function() {
- Dygraph.getContext = _origFunc;
-});
+cleanupAfterEach();
+useProxyCanvas(utils, Proxy);
it('testErrorBarsDrawn', function() {
var opts = {
*
* @author danvdk@gmail.com (Dan Vanderkam)
*/
-describe("fast-canvas-proxy", function() {
-beforeEach(function() {
-});
+import DygraphCanvasRenderer from '../../src/dygraph-canvas';
+import Proxy from './Proxy';
-afterEach(function() {
-});
+describe("fast-canvas-proxy", function() {
var fakeCanvasContext = {
moveTo: function() {},
*
* @author benoitboivin.pro@gmail.com (Benoit Boivin)
*/
+import Dygraph from '../../src/dygraph';
+import * as utils from '../../src/dygraph-utils';
+import CanvasAssertions from './CanvasAssertions';
+import Proxy from './Proxy';
+
describe("fill-step-plot", function() {
-beforeEach(function() {
- document.body.innerHTML = "<div id='graph'></div>";
-});
+cleanupAfterEach();
-var origFunc = Dygraph.getContext;
+var origFunc = utils.getContext;
beforeEach(function() {
- document.body.innerHTML = "<div id='graph'></div>";
- Dygraph.getContext = function(canvas) {
+ utils.getContext = function(canvas) {
return new Proxy(origFunc(canvas));
};
});
afterEach(function() {
- Dygraph.getContext = origFunc;
+ utils.getContext = origFunc;
});
*
* @author konigsberg@google.com (Robert Konigsberg)
*/
-describe("formats", function() {
-beforeEach(function() {
- document.body.innerHTML = "<div id='graph'></div>";
-});
+import Dygraph from '../../src/dygraph';
-afterEach(function() {
-});
+describe("formats", function() {
+
+cleanupAfterEach();
var dataString =
"X,Y\n" +
*
* @author david.eberlein@ch.sauter-bc.com (Fr. Sauter AG)
*/
-describe("grid-per-axis", function() {
-beforeEach(function() {
- document.body.innerHTML = "<div id='graph'></div>";
-});
+import Dygraph from '../../src/dygraph';
+import * as utils from '../../src/dygraph-utils';
-var origFunc = Dygraph.getContext;
+import Proxy from './Proxy';
+import CanvasAssertions from './CanvasAssertions';
+import Util from './Util';
+import PixelSampler from './PixelSampler';
-beforeEach(function() {
- document.body.innerHTML = "<div id='graph'></div>";
- Dygraph.getContext = function(canvas) {
- return new Proxy(origFunc(canvas));
- };
-});
+describe("grid-per-axis", function() {
-afterEach(function() {
- Dygraph.getContext = origFunc;
-});
+cleanupAfterEach();
+useProxyCanvas(utils, Proxy);
it('testIndependentGrids', function() {
var opts = {
}
var x, y;
x = halfUp(g.plotter_.area.x);
+ var sampler = new PixelSampler(g);
// Step through y(0) and y2(1) axis
for ( var axis = 0; axis < 2; axis++) {
// Step through all gridlines of the axis
for ( var i = 0; i < gridlines[axis].length; i++) {
y = halfDown(g.toDomYCoord(gridlines[axis][i], axis));
// Check the grid colors.
- assert.deepEqual(gridColors[axis], Util.samplePixel(g.hidden_, x, y),
+ assert.deepEqual(gridColors[axis], sampler.colorAtPixel(x, y),
"Unexpected grid color found at pixel: x: " + x + "y: " + y);
}
}
});
+
it('testPerAxisGridWidth', function() {
var opts = {
width : 480,
}
var x, y;
x = halfUp(g.plotter_.area.x + 10);
+
+ var sampler = new PixelSampler(g);
// Step through y(0) and y2(1) axis
for ( var axis = 0; axis < 2; axis++) {
// Step through all gridlines of the axis
// Ignore the alpha value
// FIXME(pholden): this test fails with a context pixel ratio of 2.
- var drawnPixeldown2 = Util.samplePixel(g.hidden_, x, y - 2).slice(0, 3);
- var drawnPixeldown1 = Util.samplePixel(g.hidden_, x, y - 1).slice(0, 3);
- var drawnPixel = Util.samplePixel(g.hidden_, x, y).slice(0, 3);
- var drawnPixelup1 = Util.samplePixel(g.hidden_, x, y + 1).slice(0, 3);
- var drawnPixelup2 = Util.samplePixel(g.hidden_, x, y + 2).slice(0, 3);
+ var drawnPixeldown2 = sampler.rgbAtPixel(x, y - 2);
+ var drawnPixeldown1 = sampler.rgbAtPixel(x, y - 1);
+ var drawnPixel = sampler.rgbAtPixel(x, y);
+ var drawnPixelup1 = sampler.rgbAtPixel(x, y + 1);
+ var drawnPixelup2 = sampler.rgbAtPixel(x, y + 2);
// Check the grid width.
switch (axis) {
case 0: // y with 2 pixels width
y = halfDown(g.plotter_.area.y) + 10;
for ( var i = 0; i < xGridlines.length; i++) {
x = halfUp(g.toDomXCoord(xGridlines[i]));
- assert.deepEqual(emptyColor, Util.samplePixel(g.hidden_, x - 4, y).slice(0, 3),
+ assert.deepEqual(emptyColor, sampler.rgbAtPixel(x - 4, y),
"Unexpected x-grid color found at pixel: x: " + x + "y: " + y);
- assert.deepEqual(gridColor, Util.samplePixel(g.hidden_, x - 3, y).slice(0, 3),
+ assert.deepEqual(gridColor, sampler.rgbAtPixel(x - 3, y),
"Unexpected x-grid color found at pixel: x: " + x + "y: " + y);
- assert.deepEqual(gridColor, Util.samplePixel(g.hidden_, x - 2, y).slice(0, 3),
+ assert.deepEqual(gridColor, sampler.rgbAtPixel(x - 2, y),
"Unexpected x-grid color found at pixel: x: " + x + "y: " + y);
- assert.deepEqual(gridColor, Util.samplePixel(g.hidden_, x - 1, y).slice(0, 3),
+ assert.deepEqual(gridColor, sampler.rgbAtPixel(x - 1, y),
"Unexpected x-grid color found at pixel: x: " + x + "y: " + y);
- assert.deepEqual(gridColor, Util.samplePixel(g.hidden_, x, y).slice(0, 3),
+ assert.deepEqual(gridColor, sampler.rgbAtPixel(x, y),
"Unexpected x-grid color found at pixel: x: " + x + "y: " + y);
- assert.deepEqual(gridColor, Util.samplePixel(g.hidden_, x + 1, y).slice(0, 3),
+ assert.deepEqual(gridColor, sampler.rgbAtPixel(x + 1, y),
"Unexpected x-grid color found at pixel: x: " + x + "y: " + y);
- assert.deepEqual(emptyColor, Util.samplePixel(g.hidden_, x + 2, y).slice(0, 3),
+ assert.deepEqual(emptyColor, sampler.rgbAtPixel(x + 2, y),
"Unexpected x-grid color found at pixel: x: " + x + "y: " + y);
}
});
it('testGridLinePattern', function() {
var opts = {
- width : 120,
+ width : 480,
height : 320,
errorBars : false,
labels : [ "X", "Left", "Right" ],
return Math.round(y) - 1;
}
var x, y;
+ var sampler = new PixelSampler(g);
// Step through all gridlines of the axis
for (var i = 0; i < yGridlines.length; i++) {
y = halfDown(g.toDomYCoord(yGridlines[i], 0));
// avoid checking the edge pixels since they differ depending on the OS.
var pixelpos = x % 10;
if(pixelpos < 1 || pixelpos > 8) continue;
+
+ // XXX: check what this looks like at master
// Ignore alpha
- var drawnPixel = Util.samplePixel(g.hidden_, x, y).slice(0,3);
+ var drawnPixel = sampler.rgbAtPixel(x, y);
var pattern = (Math.floor((x) / 10)) % 2;
switch (pattern) {
case 0: // fill
* Unit tests for GViz data table support.
*/
-describe('gviz', function() {
+import Dygraph from '../../src/dygraph';
- beforeEach(function() {
- document.body.innerHTML = "<div id='graph'></div>";
- });
+import Util from './Util';
- afterEach(function() {
- });
+describe('gviz', function() {
+
+ cleanupAfterEach();
// This is a fake version of the gviz DataTable API, which can only be
// sourced using the google js loader.
*
* @author danvdk@gmail.com (Dan Vanderkam)
*/
+
+import Dygraph from '../../src/dygraph';
+
describe("hidpi", function() {
+cleanupAfterEach();
+
var savePixelRatio;
beforeEach(function() {
savePixelRatio = window.devicePixelRatio;
window.devicePixelRatio = 2;
-
- document.body.innerHTML = "<div id='graph'></div>";
});
afterEach(function() {
*
* @author konigsberg@google.com (Robert Konigsbrg)
*/
-describe("interaction-model", function() {
-beforeEach(function() {
- document.body.innerHTML = "<div id='graph'></div>";
-});
+import Dygraph from '../../src/dygraph';
+import DygraphInteraction from '../../src/dygraph-interaction-model';
+import DygraphOps from './DygraphOps';
-afterEach(function() {
-});
+describe("interaction-model", function() {
+
+cleanupAfterEach();
var data1 = "X,Y\n" +
"20,-1\n" +
function customDown(event, g, context) {
context.initializeMouseDown(event, g, context);
- Dygraph.startPan(event, g, context);
+ DygraphInteraction.startPan(event, g, context);
}
function customMove(event, g, context) {
- Dygraph.movePan(event, g, context);
+ DygraphInteraction.movePan(event, g, context);
}
function customUp(event, g, context) {
- Dygraph.endPan(event, g, context);
+ DygraphInteraction.endPan(event, g, context);
}
var opts = {
width: 100,
height : 100,
clickCallback : clickCallback,
- interactionModel : Dygraph.Interaction.nonInteractiveModel_
+ interactionModel : DygraphInteraction.nonInteractiveModel_
};
var graph = document.getElementById("graph");
*
* @author konigsberg@google.com (Robert Konigsberg)
*/
+
+import Dygraph from '../../src/dygraph';
+import * as utils from '../../src/dygraph-utils';
+import Proxy from './Proxy';
+import CanvasAssertions from './CanvasAssertions';
+import Util from './Util';
+
var ZERO_TO_FIFTY = [[ 10, 0 ] , [ 20, 50 ]];
describe("missing-points", function() {
-var _origFunc = Dygraph.getContext;
-beforeEach(function() {
- document.body.innerHTML = "<div id='graph'></div>";
- Dygraph.getContext = function(canvas) {
- return new Proxy(_origFunc(canvas));
- }
-});
-
-afterEach(function() {
- Dygraph.getContext = _origFunc;
-});
+cleanupAfterEach();
+useProxyCanvas(utils, Proxy);
it('testSeparatedPointsDontDraw', function() {
var graph = document.getElementById("graph");
*
* @author dan@dygraphs.com (Dan Vanderkam)
*/
-describe("multi-csv", function() {
-beforeEach(function() {
- document.body.innerHTML = "<div id='graph'></div>";
-});
+import Dygraph from '../../src/dygraph';
-afterEach(function() {
-});
+describe("multi-csv", function() {
+
+cleanupAfterEach();
function getXLabels() {
var x_labels = document.getElementsByClassName("dygraph-axis-label-x");
* @author danvdk@gmail.com (Dan Vanderkam)
*/
+import Dygraph from '../../src/dygraph';
+import * as utils from '../../src/dygraph-utils';
+import Util from './Util';
+
describe("multiple-axes-tests", function() {
-beforeEach(function() {
- document.body.innerHTML = "<div id='graph'></div>";
-});
+cleanupAfterEach();
var getData = function() {
var data = [];
var results = { y : {}, y2 : {}};
var firstCallback = function(g, seriesName, ctx, canvasx, canvasy, color, radius) {
results.y[seriesName] = 1;
- Dygraph.Circles.DEFAULT(g, seriesName, ctx, canvasx, canvasy, color, radius);
+ utils.Circles.DEFAULT(g, seriesName, ctx, canvasx, canvasy, color, radius);
};
var secondCallback = function(g, seriesName, ctx, canvasx, canvasy, color, radius) {
results.y2[seriesName] = 1;
- Dygraph.Circles.DEFAULT(g, seriesName, ctx, canvasx, canvasy, color, radius);
+ utils.Circles.DEFAULT(g, seriesName, ctx, canvasx, canvasy, color, radius);
};
var g = new Dygraph(
*
* @author danvk@google.com (Dan Vanderkam)
*/
-describe("no-hours", function() {
-beforeEach(function() {
- document.body.innerHTML = "<div id='graph'></div>";
-});
+import Dygraph from '../../src/dygraph';
+import Util from './Util';
-afterEach(function() {
-});
+describe("no-hours", function() {
+
+cleanupAfterEach();
it('testNoHours', function() {
var opts = {
* @author danvdk@gmail.com (Dan Vanderkam)
*/
+import Dygraph from '../../src/dygraph';
+import * as DygraphTickers from '../../src/dygraph-tickers';
+import DEFAULT_ATTRS from '../../src/dygraph-default-attrs';
+
describe("numeric-ticker-tests", function() {
-beforeEach(function() {
- document.body.innerHTML = "<div id='graph'></div>";
-});
+cleanupAfterEach();
var createOptionsViewForAxis = function(axis, dict) {
return function (x) {
if (dict && dict.hasOwnProperty(x)) {
return dict[x];
}
- if (Dygraph.DEFAULT_ATTRS.axes[axis].hasOwnProperty(x)) {
- return Dygraph.DEFAULT_ATTRS.axes[axis][x];
+ if (DEFAULT_ATTRS.axes[axis].hasOwnProperty(x)) {
+ return DEFAULT_ATTRS.axes[axis][x];
}
- if (Dygraph.DEFAULT_ATTRS.hasOwnProperty(x)) {
- return Dygraph.DEFAULT_ATTRS[x];
+ if (DEFAULT_ATTRS.hasOwnProperty(x)) {
+ return DEFAULT_ATTRS[x];
}
if (x == 'axisLabelFormatter') return null;
throw "mysterious " + axis + "-axis option: " + x;
var opts = {"logscale":null,"labelsKMG2":false,"labelsKMB":false};
var options = createOptionsViewForAxis('y', opts);
- var ticks = Dygraph.numericTicks(-0.4, 4.4, 320, options);
+ var ticks = DygraphTickers.numericTicks(-0.4, 4.4, 320, options);
var expected_ticks = [
{"v":-0.5,"label":"-0.5"},
{"v":0,"label":"0"},
{"v":4.5,"label":"4.5"}];
assert.deepEqual(expected_ticks, ticks);
- ticks = Dygraph.numericTicks(1, 84, 540, options);
+ ticks = DygraphTickers.numericTicks(1, 84, 540, options);
var expected_ticks = [
{"v":0,"label":"0"},
{"v":5,"label":"5"},
*
* @author danvk@google.com (Dan Vanderkam)
*/
-describe("parser", function() {
-beforeEach(function() {
- document.body.innerHTML = "<div id='graph'></div>";
-});
+import Dygraph from '../../src/dygraph';
+import * as utils from '../../src/dygraph-utils';
-afterEach(function() {
-});
+describe("parser", function() {
+
+cleanupAfterEach();
it('testDetectLineDelimiter', function() {
var data = "X,Y\r" +
"2,1\r" +
"3,0\r"
;
- assert.equal("\r", Dygraph.detectLineDelimiter(data));
+ assert.equal("\r", utils.detectLineDelimiter(data));
data = "X,Y\n" +
"0,-1\n" +
"2,1\n" +
"3,0\n"
;
- assert.equal("\n", Dygraph.detectLineDelimiter(data));
+ assert.equal("\n", utils.detectLineDelimiter(data));
data = "X,Y\n\r" +
"0,-1\n\r" +
"2,1\n\r" +
"3,0\n\r"
;
- assert.equal("\n\r", Dygraph.detectLineDelimiter(data));
+ assert.equal("\n\r", utils.detectLineDelimiter(data));
});
it('testParseDosNewlines', function() {
*
* @author dan@dygraphs.com (Dan Vanderkam)
*/
+
+import Dygraph from '../../src/dygraph';
+import Util from './Util';
+
describe("pathological-cases", function() {
+cleanupAfterEach();
+
var restoreConsole;
var logs = {};
beforeEach(function() {
- document.body.innerHTML = "<div id='graph'></div>";
restoreConsole = Util.captureConsole(logs);
});
restoreConsole();
});
+var graph = document.getElementById("graph");
+
it('testZeroPoint', function() {
var opts = {
width: 480,
};
var data = "X,Y\n";
- var graph = document.getElementById("graph");
var g = new Dygraph(graph, data, opts);
});
var data = "X,Y\n" +
"1,2\n";
- var graph = document.getElementById("graph");
var g = new Dygraph(graph, data, opts);
});
var h = document.createElement('h3');
h.appendChild(document.createTextNode(baseName + ' ' + variantName));
- document.body.appendChild(h);
+ graph.appendChild(h);
for (var dataName in dataSets) {
var data = dataSets[dataName];
var gdiv = document.createElement('div');
gdiv.style.display = 'inline-block';
box.appendChild(gdiv);
- document.body.appendChild(box);
+ graph.appendChild(box);
var cols = data && data[0] ? data[0].length : 0;
opts.labels = ['X', 'A', 'B', 'C'].slice(0, cols);
var data = "X,Y\n" +
"1,2\n";
- var graph = document.getElementById("graph");
var g = new Dygraph(graph, data, opts);
});
*
* @author konigsberg@google.com (Robert Konigsberg)
*/
+
+import Dygraph from '../../src/dygraph';
+import * as utils from '../../src/dygraph-utils';
+
+import Util from './Util';
+import CanvasAssertions from './CanvasAssertions';
+import Proxy from './Proxy';
+
describe("per-axis", function() {
-var _origGetContext = Dygraph.getContext;
+cleanupAfterEach();
+useProxyCanvas(utils, Proxy);
var xAxisLineColor = "#00ffff";
var yAxisLineColor = "#ffff00";
var g, graph;
beforeEach(function() {
- document.body.innerHTML = "<div id='graph'></div>";
- Dygraph.getContext = function(canvas) {
- return new Proxy(_origGetContext(canvas));
- }
-
var opts = {
axes : {
x : {
g = new Dygraph(graph, data, opts);
});
-afterEach(function() {
- Dygraph.getContext = _origGetContext;
-});
-
it('testDrawXAxis', function() {
g.updateOptions({ axes : { x : { drawAxis: true }} });
assert.isTrue(graph.getElementsByClassName('dygraph-axis-label-x').length > 0);
*
* @author danvk@google.com (Dan Vanderkam)
*/
-describe("per-series", function() {
-beforeEach(function() {
- document.body.innerHTML = "<div id='graph'></div>";
-});
+import Dygraph from '../../src/dygraph';
-afterEach(function() {
-});
+import PixelSampler from './PixelSampler';
+
+describe("per-series", function() {
+
+cleanupAfterEach();
it('testPerSeriesFill', function() {
var opts = {
*
* @author konigsberg@google.com (Robert Konigsberg)
*/
+
+import Dygraph from '../../src/dygraph';
+import DygraphOps from './DygraphOps';
+
describe("plugins", function() {
+cleanupAfterEach();
+
var data;
beforeEach(function() {
- document.body.innerHTML = "<div id='graph'></div>";
-
data = "X,Y1,Y2\n" +
"0,1,2\n" +
"1,2,1\n" +
;
});
-afterEach(function() {
-});
-
it('testWillDrawChart', function() {
var draw = 0;
+import Dygraph from '../../src/dygraph';
+import LegendPlugin from '../../src/plugins/legend';
+import Util from './Util';
+
describe("plugins-legend", function() {
-beforeEach(function() {
- document.body.innerHTML = "<div id='graph'></div><div id='label'></div>";
-});
+var graph;
-afterEach(function() {
+cleanupAfterEach();
+beforeEach(function() {
+ var testDiv = document.getElementById('graph');
+ testDiv.innerHTML = "<div id='inner-graph'></div><div id='label'></div>";
+ graph = document.getElementById('inner-graph');
});
it('testLegendEscape', function() {
"3,0\n"
;
- var graph = document.getElementById("graph");
var g = new Dygraph(graph, data, opts);
- var legendPlugin = new Dygraph.Plugins.Legend();
+ var legendPlugin = new LegendPlugin();
legendPlugin.activate(g);
var e = {
selectedX: 'selectedX',
it('should let labelsDiv be a string', function() {
var labelsDiv = document.getElementById('label');
- var g = new Dygraph('graph', 'X,Y\n1,2\n', {labelsDiv: 'label'});
+ var g = new Dygraph(graph, 'X,Y\n1,2\n', {labelsDiv: 'label'});
null
g.setSelection(0);
assert.equal('1: Y: 2', Util.nbspToSpace(labelsDiv.textContent));
it('should let labelsDiv be an Element', function() {
var labelsDiv = document.getElementById('label');
- var g = new Dygraph('graph', 'X,Y\n1,2\n', { labelsDiv: labelsDiv });
+ var g = new Dygraph(graph, 'X,Y\n1,2\n', { labelsDiv: labelsDiv });
assert.isNull(labelsDiv.getAttribute('class')); // dygraph-legend not added.
g.setSelection(0);
assert.equal('1: Y: 2', Util.nbspToSpace(labelsDiv.textContent));
});
it('should render dashed patterns', function() {
- var g = new Dygraph('graph', 'X,Y\n1,2\n', {
+ var g = new Dygraph(graph, 'X,Y\n1,2\n', {
strokePattern: [5, 5],
color: 'red',
legend: 'always'
* @fileoverview Regression tests for range selector.
* @author paul.eric.felix@gmail.com (Paul Felix)
*/
+
+import Dygraph from '../../src/dygraph';
+import * as utils from '../../src/dygraph-utils';
+import RangeSelectorPlugin from '../../src/plugins/range-selector';
+
+import Util from './Util';
+import DygraphOps from './DygraphOps';
+import CanvasAssertions from './CanvasAssertions';
+import Proxy from './Proxy';
+
describe("range-selector", function() {
+cleanupAfterEach();
+
var restoreConsole;
var logs = {};
beforeEach(function() {
- document.body.innerHTML = "<div id='graph'></div>";
restoreConsole = Util.captureConsole(logs);
});
it('testMiniPlotDrawn', function() {
// Install Proxy to track canvas calls.
- var origFunc = Dygraph.getContext;
+ var origFunc = utils.getContext;
var miniHtx;
- Dygraph.getContext = function(canvas) {
+ utils.getContext = function(canvas) {
if (canvas.className != 'dygraph-rangesel-bgcanvas') {
return origFunc(canvas);
}
assert.isNotNull(miniHtx);
assert.isTrue(0 < CanvasAssertions.numLinesDrawn(miniHtx, '#ff0000'));
- Dygraph.getContext = origFunc;
+ utils.getContext = origFunc;
});
// Tests data computation for the mini plot with a single series.
var graph = document.getElementById("graph");
var g = new Dygraph(graph, data, opts);
- var rangeSelector = g.getPluginInstance_(Dygraph.Plugins.RangeSelector);
+ var rangeSelector = g.getPluginInstance_(RangeSelectorPlugin);
assert.isNotNull(rangeSelector);
var combinedSeries = rangeSelector.computeCombinedSeriesAndLimits_();
var graph = document.getElementById("graph");
var g = new Dygraph(graph, data, opts);
- var rangeSelector = g.getPluginInstance_(Dygraph.Plugins.RangeSelector);
+ var rangeSelector = g.getPluginInstance_(RangeSelectorPlugin);
assert.isNotNull(rangeSelector);
var combinedSeries = rangeSelector.computeCombinedSeriesAndLimits_();
var graph = document.getElementById("graph");
var g = new Dygraph(graph, data, opts);
- var rangeSelector = g.getPluginInstance_(Dygraph.Plugins.RangeSelector);
+ var rangeSelector = g.getPluginInstance_(RangeSelectorPlugin);
assert.isNotNull(rangeSelector);
var combinedSeries = rangeSelector.computeCombinedSeriesAndLimits_();
var graph = document.getElementById("graph");
var g = new Dygraph(graph, data, opts);
- var rangeSelector = g.getPluginInstance_(Dygraph.Plugins.RangeSelector);
+ var rangeSelector = g.getPluginInstance_(RangeSelectorPlugin);
assert.isNotNull(rangeSelector);
var combinedSeries = rangeSelector.computeCombinedSeriesAndLimits_();
var graph = document.getElementById("graph");
var g = new Dygraph(graph, data, opts);
- var rangeSelector = g.getPluginInstance_(Dygraph.Plugins.RangeSelector);
+ var rangeSelector = g.getPluginInstance_(RangeSelectorPlugin);
assert.isNotNull(rangeSelector);
var combinedSeries = rangeSelector.computeCombinedSeriesAndLimits_();
var graph = document.getElementById("graph");
var g = new Dygraph(graph, data, opts);
- var rangeSelector = g.getPluginInstance_(Dygraph.Plugins.RangeSelector);
+ var rangeSelector = g.getPluginInstance_(RangeSelectorPlugin);
assert.isNotNull(rangeSelector);
var combinedSeries = rangeSelector.computeCombinedSeriesAndLimits_();
*
* @author konigsberg@google.com (Robert Konigsberg)
*/
+
+import Dygraph from '../../src/dygraph';
+
+import DygraphOps from './DygraphOps';
+import {assertDeepCloseTo} from './custom_asserts';
+
var ZERO_TO_FIFTY = [[ 10, 0 ] , [ 20, 50 ]];
var ZERO_TO_FIFTY_STEPS = (function() {
var a = [];
describe("range-tests", function() {
-beforeEach(function() {
- document.body.innerHTML = "<div id='graph'></div>";
-});
+cleanupAfterEach();
var createGraph = function(opts, data, expectRangeX, expectRangeY) {
if (data === undefined) data = ZERO_TO_FIFTY_STEPS;
*
* @author konigsberg@google.com (Robert Konigsberg)
*/
+
+import Dygraph from '../../src/dygraph';
+
+import DygraphOps from './DygraphOps';
+import Util from './Util';
+
describe("resize", function() {
+cleanupAfterEach();
+
var data =
"X,Y\n" +
"1,100\n" +
"5,300\n" +
"6,100\n";
-beforeEach(function() {
- document.body.innerHTML = "<div id='graph'></div>";
-});
-
-afterEach(function() {
-});
-
it('testResizeMaintainsMouseOperations', function() {
- document.body.innerHTML =
- '<div id="graph" style="width: 640px; height: 480px;"></div>' +
- '</div>';
- var graph = document.getElementById("graph");
+ var graph = document.getElementById('graph');
+ graph.setAttribute('style', 'width: 640px; height: 480px;');
var callbackCount = 0;
var callback = function() {
strum(g, 300, 640);
assert.equal(6, callbackCount);
- document.getElementById("graph").style.width = "500px";
+ graph.style.width = "500px";
g.resize();
callbackCount = 0;
*
* @author danvk@google.com (Dan Vanderkam)
*/
-describe("rolling-average", function() {
-beforeEach(function() {
- document.body.innerHTML = "<div id='graph'></div>";
-});
+import Dygraph from '../../src/dygraph';
-afterEach(function() {
-});
+import Util from './Util';
+
+describe("rolling-average", function() {
+
+cleanupAfterEach();
it('testRollingAverage', function() {
var opts = {
* @author konigsberg@google.com (Robert Konigsberg)
*/
+import Dygraph from '../../src/dygraph';
+
describe("dygraphs-sanity", function() {
var DEAD_SIMPLE_DATA = 'X,Y\n10,2100';
var ZERO_TO_FIFTY = 'X,Y\n10,0\n20,50';
-beforeEach(function() {
- document.body.innerHTML = "<div id='graph'></div>";
-});
+cleanupAfterEach();
/**
* The sanity test of sanity tests.
*
* @author danvk@google.com (Dan Vanderkam)
*/
-describe("scientific-notation", function() {
-beforeEach(function() {
- document.body.innerHTML = "<div id='graph'></div>";
-});
+import Dygraph from '../../src/dygraph';
+import {assertDeepCloseTo} from './custom_asserts';
-afterEach(function() {
-});
+describe("scientific-notation", function() {
+
+cleanupAfterEach();
function getXValues(g) {
var xs = [];
*
* @author konigsberg@google.com (Robert Konigsbrg)
*/
+
+import Dygraph from '../../src/dygraph';
+import DygraphOps from './DygraphOps';
+
describe("scrolling-div", function() {
var point, g;
"non proident, sunt in culpa qui officia deserunt mollit anim id est\n" +
"laborum.</p>";
- document.body.innerHTML =
+ var testDiv = document.getElementById('graph');
+ testDiv.innerHTML =
"<div id='scroller' style='overflow: scroll; height: 450px; width: 800px;'>" +
- "<div id='graph'></div>" +
+ "<div id='graph-inner'></div>" +
"<div style='height:100px; background-color:green;'>" + LOREM_IPSUM + " </div>" +
"<div style='height:100px; background-color:red;'>" + LOREM_IPSUM + "</div>" +
"</div>";
+ // The old test runner had an 8px margin on the body
+ // The Mocha test runner does not. We set it on the test div to keep the
+ // coordinates the same.
+ testDiv.style.margin = '8px';
+
var data = [
[ 10, 1 ],
[ 20, 3 ],
[ 70, 4 ],
[ 80, 6 ] ];
- var graph = document.getElementById("graph");
+ var graph = document.getElementById("graph-inner");
point = null;
g = new Dygraph(graph, data,
return scrollbarWidth;
};
-afterEach(function() {
-});
-
/**
* This tests that when the nested div is unscrolled, things work normally.
*/
* @author danvk@google.com (Dan Vanderkam)
*/
+import Dygraph from '../../src/dygraph';
+import DefaultHandler from '../../src/datahandler/default';
+
describe("selection", function() {
-beforeEach(function() {
- document.body.innerHTML = "<div id='graph'></div>";
-});
+cleanupAfterEach();
it('testSetGetSelection', function() {
var graph = document.getElementById("graph");
it('testSetGetSelectionMissingPoints', function() {
var dataHandler = function() {};
- dataHandler.prototype = new Dygraph.DataHandlers.DefaultHandler();
+ dataHandler.prototype = new DefaultHandler();
dataHandler.prototype.seriesToPoints = function(series, setName, boundaryIdStart) {
var val = null;
if (setName == 'A') {
* @author konigsberg@google.com (Robert Konigsberg)
*/
-describe("simple-drawing", function() {
+import Dygraph from '../../src/dygraph';
+import * as utils from '../../src/dygraph-utils';
-var ZERO_TO_FIFTY = 'X,Y\n10,0\n20,50';
+import CanvasAssertions from './CanvasAssertions';
+import Proxy from './Proxy';
+import PixelSampler from './PixelSampler';
-var _origFunc = Dygraph.getContext;
-beforeEach(function() {
- document.body.innerHTML = "<div id='graph'></div>";
- Dygraph.getContext = function(canvas) {
- return new Proxy(_origFunc(canvas));
- }
-});
+describe("simple-drawing", function() {
-afterEach(function() {
- Dygraph.getContext = _origFunc;
-});
+cleanupAfterEach();
+useProxyCanvas(utils, Proxy);
+
+var ZERO_TO_FIFTY = 'X,Y\n10,0\n20,50';
it('testDrawSimpleRangePlusOne', function() {
var opts = {
*
* @author danvdk@gmail.com (Dan Vanderkam)
*/
+
+import Dygraph from '../../src/dygraph';
+import '../../src/extras/smooth-plotter'; // defines Dygraph.smoothPlotter
+
describe("smooth-plotter", function() {
+var smoothPlotter = Dygraph.smoothPlotter;
var getControlPoints = smoothPlotter._getControlPoints;
beforeEach(function() {
*
* @author dan@dygraphs.com (Dan Vanderkam)
*/
-describe("stacked", function() {
-var _origGetContext = Dygraph.getContext;
+import Dygraph from '../../src/dygraph';
+import * as utils from '../../src/dygraph-utils';
-beforeEach(function() {
- document.body.innerHTML = "<div id='graph'></div>";
- Dygraph.getContext = function(canvas) {
- return new Proxy(_origGetContext(canvas));
- }
-});
+import Proxy from './Proxy';
+import CanvasAssertions from './CanvasAssertions';
+import Util from './Util';
-afterEach(function() {
- Dygraph.getContext = _origGetContext;
-});
+describe("stacked", function() {
+
+cleanupAfterEach();
+useProxyCanvas(utils, Proxy);
it('testCorrectColors', function() {
var opts = {
*
* @author julian.eichstaedt@ch.sauter-bc.com (Fr. Sauter AG)
*/
-describe("step-plot-per-series", function() {
-beforeEach(function() {
- document.body.innerHTML = "<div id='graph'></div>";
-});
+import Dygraph from '../../src/dygraph';
+import * as utils from '../../src/dygraph-utils';
-var origFunc = Dygraph.getContext;
+import Proxy from './Proxy';
+import CanvasAssertions from './CanvasAssertions';
-beforeEach(function() {
- document.body.innerHTML = "<div id='graph'></div>";
- Dygraph.getContext = function(canvas) {
- return new Proxy(origFunc(canvas));
- };
-});
+describe("step-plot-per-series", function() {
-afterEach(function() {
- Dygraph.getContext = origFunc;
-});
+cleanupAfterEach();
+useProxyCanvas(utils, Proxy);
it('testMixedModeStepAndLineFilled', function() {
var opts = {
*
* @author nyx@nyx.cz (Marek Janda)
*/
+
+import Dygraph from '../../src/dygraph';
+import '../../src/extras/synchronizer'; // Sets Dygraph.synchronize
+
+import DygraphOps from './DygraphOps';
+
describe("synchronize", function() {
var gs;
var originalCallbackCalled;
"12,1,4,2\n" +
"13,0,2,3\n";
var h_row, h_pts;
+ var graph = document.getElementById('graph');
beforeEach(function() {
- document.body.innerHTML = "<div id='graph1'></div><div id='graph2'></div>";
+ graph.innerHTML = "<div id='graph1'></div><div id='graph2'></div>";
originalCallbackCalled = false;
h_row = 0, h_pts = [];
gs = [];
*
* @author danvk@google.com (Dan Vanderkam)
*/
+import Dygraph from '../../src/dygraph';
+import * as utils from '../../src/dygraph-utils';
-describe("to-dom-coords", function() {
+import Proxy from './Proxy';
+import CanvasAssertions from './CanvasAssertions';
+import {assertDeepCloseTo} from './custom_asserts';
-var origFunc = Dygraph.getContext;
-beforeEach(function() {
- document.body.innerHTML = "<div id='graph'></div>";
- Dygraph.getContext = function(canvas) {
- return new Proxy(origFunc(canvas));
- }
-});
+describe("to-dom-coords", function() {
-afterEach(function() {
- Dygraph.getContext = origFunc;
-});
+cleanupAfterEach();
+useProxyCanvas(utils, Proxy);
// Checks that toDomCoords and toDataCoords are inverses of one another.
var checkForInverses = function(g) {
*
* @author gmadrid@gmail.com (George Madrid)
*/
+
+import Dygraph from '../../src/dygraph';
+import {Granularity, getDateAxis} from '../../src/dygraph-tickers';
+import * as utils from '../../src/dygraph-utils';
+import DEFAULT_ATTRS from '../../src/dygraph-default-attrs';
+
describe("two-digit-years", function() {
it('testTwoDigitYears', function() {
start.setFullYear(9);
end.setFullYear(11);
- var ticks = Dygraph.getDateAxis(start, end, Dygraph.QUARTERLY, function(x) {
- return Dygraph.DEFAULT_ATTRS.axes['x'][x];
+ var ticks = getDateAxis(start, end, Granularity.QUARTERLY, function(x) {
+ return DEFAULT_ATTRS.axes['x'][x];
});
// This breaks in Firefox & Safari:
* @fileoverview Tests for the updateOptions function.
* @author antrob@google.com (Anthony Robledo)
*/
+
+import Dygraph from '../../src/dygraph';
+
describe("update-options", function() {
+
+cleanupAfterEach();
var opts = {
width: 480,
"2011-04-04,9,5\n" +
"2011-05-05,8,3\n";
-beforeEach(function() {
- document.body.innerHTML = "<div id='graph'></div><div id='labels'></div>";
-});
-
-afterEach(function() {
-});
-
/*
* Tweaks the dygraph so it sets g._testDrawCalled to true when internal method
* drawGraph_ is called. Call unWrapDrawGraph when done with this.
*
* @author dan@dygraphs.com (Dan Vanderkam)
*/
-describe("update-while-panning", function() {
-beforeEach(function() {
- document.body.innerHTML = "<div id='graph'></div>";
-});
+import Dygraph from '../../src/dygraph';
+import DygraphOps from './DygraphOps';
-afterEach(function() {
-});
+describe("update-while-panning", function() {
+
+cleanupAfterEach();
// This tests the following sequence:
// 1. Begin dragging a chart (x-panning)
* @author danvdk@gmail.com (Dan Vanderkam)
*/
+import * as utils from '../../src/dygraph-utils';
+
describe("utils-tests", function() {
it('testUpdate', function() {
assert.deepEqual({x: 1, y: 2}, a['c']);
assert.deepEqual({f: 10, g: 20}, a['d']);
- Dygraph.update(a, { c: { x: 2 } });
+ utils.update(a, { c: { x: 2 } });
assert.deepEqual({x: 2}, a['c']);
- Dygraph.update(a, { d: null });
+ utils.update(a, { d: null });
assert.equal(null, a['d']);
- Dygraph.update(a, { a: 10, b: [1, 2] });
+ utils.update(a, { a: 10, b: [1, 2] });
assert.equal(10, a['a']);
assert.deepEqual([1, 2], a['b']);
assert.deepEqual({x: 2}, a['c']);
assert.deepEqual({x: 1, y: 2}, a['c']);
assert.deepEqual({f: 10, g: 20}, a['d']);
- Dygraph.updateDeep(a, { c: { x: 2 } });
+ utils.updateDeep(a, { c: { x: 2 } });
assert.deepEqual({x: 2, y: 2}, a['c']);
- Dygraph.updateDeep(a, { d: null });
+ utils.updateDeep(a, { d: null });
assert.equal(null, a['d']);
- Dygraph.updateDeep(a, { a: 10, b: [1, 2] });
+ utils.updateDeep(a, { a: 10, b: [1, 2] });
assert.equal(10, a['a']);
assert.deepEqual([1, 2], a['b']);
assert.deepEqual({x: 2, y: 2}, a['c']);
};
var b = {};
- Dygraph.updateDeep(b, a);
+ utils.updateDeep(b, a);
b.a = 2;
assert.equal(1, a.a);
it('testIterator_nopredicate', function() {
var array = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'];
- var iter = Dygraph.createIterator(array, 1, 4);
+ var iter = utils.createIterator(array, 1, 4);
assert.isTrue(iter.hasNext);
assert.equal('b', iter.peek);
assert.equal('b', iter.next());
it('testIterator_predicate', function() {
var array = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'];
- var iter = Dygraph.createIterator(array, 1, 4,
+ var iter = utils.createIterator(array, 1, 4,
function(array, idx) { return array[idx] !== 'd' });
assert.isTrue(iter.hasNext);
assert.equal('b', iter.peek);
it('testIterator_empty', function() {
var array = [];
- var iter = Dygraph.createIterator([], 0, 0);
+ var iter = utils.createIterator([], 0, 0);
assert.isFalse(iter.hasNext);
});
it('testIterator_outOfRange', function() {
var array = ['a', 'b', 'c'];
- var iter = Dygraph.createIterator(array, 1, 4,
+ var iter = utils.createIterator(array, 1, 4,
function(array, idx) { return array[idx] !== 'd' });
assert.isTrue(iter.hasNext);
assert.equal('b', iter.peek);
// with invalid boundaries.
it('testIterator_whole_array', function() {
var array = ['a', 'b', 'c'];
- var iter = Dygraph.createIterator(array, 0, array.length,
+ var iter = utils.createIterator(array, 0, array.length,
function(array, idx) {
if (idx < 0 || idx >= array.length) {
throw "err";
it('testIterator_no_args', function() {
var array = ['a', 'b', 'c'];
- var iter = Dygraph.createIterator(array);
+ var iter = utils.createIterator(array);
assert.isTrue(iter.hasNext);
assert.equal('a', iter.next());
assert.isTrue(iter.hasNext);
});
it('testToRGB', function() {
- assert.deepEqual({r: 255, g: 200, b: 150}, Dygraph.toRGB_('rgb(255,200,150)'));
- assert.deepEqual({r: 255, g: 200, b: 150}, Dygraph.toRGB_('#FFC896'));
- assert.deepEqual({r: 255, g: 0, b: 0}, Dygraph.toRGB_('red'));
+ assert.deepEqual({r: 255, g: 200, b: 150}, utils.toRGB_('rgb(255,200,150)'));
+ assert.deepEqual({r: 255, g: 200, b: 150}, utils.toRGB_('#FFC896'));
+ assert.deepEqual({r: 255, g: 0, b: 0}, utils.toRGB_('red'));
assert.deepEqual({r: 255, g: 200, b: 150, a: 0.6},
- Dygraph.toRGB_('rgba(255, 200, 150, 0.6)'));
+ utils.toRGB_('rgba(255, 200, 150, 0.6)'));
});
it('testIsPixelChangingOptionList', function() {
- var isPx = Dygraph.isPixelChangingOptionList;
+ var isPx = utils.isPixelChangingOptionList;
assert.isTrue(isPx([], { axes: { y: { digitsAfterDecimal: 3 }}}));
assert.isFalse(isPx([], { axes: { y: { axisLineColor: 'blue' }}}));
});
* @author sergeyslepian@gmail.com
*/
-describe("visibility", function() {
+import Dygraph from '../../src/dygraph';
+import Util from './Util';
-beforeEach(function() {
- document.body.innerHTML = "<div id='graph'></div>";
-});
+describe("visibility", function() {
-afterEach(function() {
-});
+cleanupAfterEach();
/**
* Does a bunch of the shared busywork of setting up a graph and changing its visibility.
"devDependencies": {
"babelify": "^6.3.0",
"browserify": "^11.2.0",
+ "chai": "^3.3.0",
"closure-compiler": "^0.2.6",
"coveralls": "^2.11.2",
"gulp": "^3.8.10",
* @author David Eberlein (david.eberlein@ch.sauter-bc.com)
*/
-(function() {
-
/*global Dygraph:false */
"use strict";
+import BarsHandler from './bars';
+
/**
* @constructor
* @extends Dygraph.DataHandlers.BarsHandler
*/
-Dygraph.DataHandlers.CustomBarsHandler = function() {
+var CustomBarsHandler = function() {
};
-var CustomBarsHandler = Dygraph.DataHandlers.CustomBarsHandler;
-CustomBarsHandler.prototype = new Dygraph.DataHandlers.BarsHandler();
+CustomBarsHandler.prototype = new BarsHandler();
/** @inheritDoc */
CustomBarsHandler.prototype.extractSeries = function(rawData, i, options) {
return rollingData;
};
-})();
+export default CustomBarsHandler;
* @author David Eberlein (david.eberlein@ch.sauter-bc.com)
*/
-(function() {
-
/*global Dygraph:false */
"use strict";
+import BarsHandler from './bars';
+
/**
* @constructor
- * @extends Dygraph.DataHandlers.BarsHandler
+ * @extends BarsHandler
*/
-Dygraph.DataHandlers.ErrorBarsHandler = function() {
+var ErrorBarsHandler = function() {
};
-var ErrorBarsHandler = Dygraph.DataHandlers.ErrorBarsHandler;
-ErrorBarsHandler.prototype = new Dygraph.DataHandlers.BarsHandler();
+ErrorBarsHandler.prototype = new BarsHandler();
/** @inheritDoc */
ErrorBarsHandler.prototype.extractSeries = function(rawData, i, options) {
return rollingData;
};
-})();
+export default ErrorBarsHandler;
* @author David Eberlein (david.eberlein@ch.sauter-bc.com)
*/
-(function() {
-
/*global Dygraph:false */
"use strict";
+import BarsHandler from './bars';
+
/**
* @constructor
* @extends Dygraph.DataHandlers.BarsHandler
*/
-Dygraph.DataHandlers.FractionsBarsHandler = function() {
+var FractionsBarsHandler = function() {
};
-var FractionsBarsHandler = Dygraph.DataHandlers.FractionsBarsHandler;
-FractionsBarsHandler.prototype = new Dygraph.DataHandlers.BarsHandler();
+FractionsBarsHandler.prototype = new BarsHandler();
/** @inheritDoc */
FractionsBarsHandler.prototype.extractSeries = function(rawData, i, options) {
return rollingData;
};
-})();
+export default FractionsBarsHandler;
* @author David Eberlein (david.eberlein@ch.sauter-bc.com)
*/
-(function() {
-
/*global Dygraph:false */
/*global DygraphLayout:false */
"use strict";
+import DygraphDataHandler from './datahandler';
+import DygraphLayout from '../dygraph-layout';
+
/**
* @constructor
* @extends {Dygraph.DataHandler}
*/
-Dygraph.DataHandlers.BarsHandler = function() {
- Dygraph.DataHandler.call(this);
+var BarsHandler = function() {
+ DygraphDataHandler.call(this);
};
-Dygraph.DataHandlers.BarsHandler.prototype = new Dygraph.DataHandler();
-
-// alias for the rest of the implementation
-var BarsHandler = Dygraph.DataHandlers.BarsHandler;
+BarsHandler.prototype = new DygraphDataHandler();
// TODO(danvk): figure out why the jsdoc has to be copy/pasted from superclass.
// (I get closure compiler errors if this isn't here.)
var point = points[i];
point.y_top = NaN;
point.y_bottom = NaN;
- point.yval_minus = Dygraph.DataHandler.parseFloat(item[2][0]);
- point.yval_plus = Dygraph.DataHandler.parseFloat(item[2][1]);
+ point.yval_minus = DygraphDataHandler.parseFloat(item[2][0]);
+ point.yval_plus = DygraphDataHandler.parseFloat(item[2][1]);
}
};
}
};
-})();
+export default BarsHandler;
* @author David Eberlein (david.eberlein@ch.sauter-bc.com)
*/
-(function() {
-
/*global Dygraph:false */
"use strict";
+import DygraphDataHandler from './datahandler';
+import DefaultHandler from './default';
+
/**
- * @extends Dygraph.DataHandlers.DefaultHandler
+ * @extends DefaultHandler
* @constructor
*/
-Dygraph.DataHandlers.DefaultFractionHandler = function() {
+var DefaultFractionHandler = function() {
};
-var DefaultFractionHandler = Dygraph.DataHandlers.DefaultFractionHandler;
-DefaultFractionHandler.prototype = new Dygraph.DataHandlers.DefaultHandler();
+DefaultFractionHandler.prototype = new DefaultHandler();
DefaultFractionHandler.prototype.extractSeries = function(rawData, i, options) {
// TODO(danvk): pre-allocate series here.
return rollingData;
};
-})();
+export default DefaultFractionHandler;
"use strict";
import * as utils from './dygraph-utils';
+import Dygraph from './dygraph';
/**
var ctx = e.drawingContext;
ctx.save();
if (stroking) {
- ctx.installPattern(strokePattern);
+ if (ctx.setLineDash) ctx.setLineDash(strokePattern);
}
var pointsOnLine = DygraphCanvasRenderer._drawSeries(
e, pointsOnLine, drawPointCallback, color, pointSize);
if (stroking) {
- ctx.uninstallPattern();
+ if (ctx.setLineDash) ctx.setLineDash([]);
}
ctx.restore();
* - http://dygraphs.com/tests/annotation-gviz.html
*/
-(function() {
/*global Dygraph:false */
"use strict";
+import Dygraph from './dygraph';
+
/**
* A wrapper around Dygraph that implements the gviz API.
* @param {!HTMLDivElement} container The DOM object the visualization should
* live in.
* @constructor
*/
-Dygraph.GVizChart = function(container) {
+var GVizChart = function(container) {
this.container = container;
};
* @param {GVizDataTable} data
* @param {Object.<*>} options
*/
-Dygraph.GVizChart.prototype.draw = function(data, options) {
+GVizChart.prototype.draw = function(data, options) {
// Clear out any existing dygraph.
// TODO(danvk): would it make more sense to simply redraw using the current
// date_graph object?
* @param {Array.<{row:number}>} selection_array array of the selected cells
* @public
*/
-Dygraph.GVizChart.prototype.setSelection = function(selection_array) {
+GVizChart.prototype.setSelection = function(selection_array) {
var row = false;
if (selection_array.length) {
row = selection_array[0].row;
* @return {Array.<{row:number,column:number}>} array of the selected cells
* @public
*/
-Dygraph.GVizChart.prototype.getSelection = function() {
+GVizChart.prototype.getSelection = function() {
var selection = [];
var row = this.date_graph.getSelection();
return selection;
};
-})();
+export default GVizChart;
* This is a list of human-friendly values at which to show tick marks on a log
* scale. It is k * 10^n, where k=1..9 and n=-39..+39, so:
* ..., 1, 2, 3, 4, 5, ..., 9, 10, 20, 30, ..., 90, 100, 200, 300, ...
- * NOTE: this assumes that Dygraph.LOG_SCALE = 10.
+ * NOTE: this assumes that utils.LOG_SCALE = 10.
* @type {Array.<number>}
*/
var PREFERRED_LOG_TICK_VALUES = (function() {
* @private
*/
export function hmsString_(hh, mm, ss) {
- var zeropad = Dygraph.zeropad;
var ret = zeropad(hh) + ":" + zeropad(mm);
if (ss) {
ret += ":" + zeropad(ss);
var r = [];
for (var i = 0; i < o.length; i++) {
if (isArrayLike(o[i])) {
- r.push(Dygraph.clone(o[i]));
+ r.push(clone(o[i]));
} else {
r.push(o[i]);
}
(function loop() {
if (frameNumber >= maxFrames) return;
- Dygraph.requestAnimFrame.call(window, function() {
+ requestAnimFrame.call(window, function() {
// Determine which frame to draw based on the delay so far. Will skip
// frames if necessary.
var currentTime = new Date().getTime();
import * as DygraphTickers from './dygraph-tickers';
import * as utils from './dygraph-utils';
import DEFAULT_ATTRS from './dygraph-default-attrs';
-import DygraphDataHandler from './datahandler/datahandler';
+
import DefaultHandler from './datahandler/default';
+import ErrorBarsHandler from './datahandler/bars-error';
+import CustomBarsHandler from './datahandler/bars-custom';
+import DefaultFractionHandler from './datahandler/default-fractions';
+import FractionsBarsHandler from './datahandler/bars-fractions';
import AnnotationsPlugin from './plugins/annotations';
import AxesPlugin from './plugins/axes';
import LegendPlugin from './plugins/legend';
import RangeSelectorPlugin from './plugins/range-selector';
+import GVizChart from './dygraph-gviz';
+
/*global DygraphLayout:false, DygraphCanvasRenderer:false, DygraphOptions:false, G_vmlCanvasManager:false,ActiveXObject:false */
"use strict";
//
// Use both sides as the exponent in 10^exp and we're done.
// x = 10 ^ (log(xRange[0]) + (pct * (log(xRange[1]) - log(xRange[0])))
- var logr0 = Dygraph.log10(xRange[0]);
- var logr1 = Dygraph.log10(xRange[1]);
+ var logr0 = utils.log10(xRange[0]);
+ var logr1 = utils.log10(xRange[1]);
var exponent = logr0 + (pct * (logr1 - logr0));
- var value = Math.pow(Dygraph.LOG_SCALE, exponent);
+ var value = Math.pow(utils.LOG_SCALE, exponent);
return value;
}
};
//
// Use both sides as the exponent in 10^exp and we're done.
// y = 10 ^ (log(yRange[1]) - (pct * (log(yRange[1]) - log(yRange[0]))));
- var logr0 = Dygraph.log10(yRange[0]);
- var logr1 = Dygraph.log10(yRange[1]);
+ var logr0 = utils.log10(yRange[0]);
+ var logr1 = utils.log10(yRange[1]);
var exponent = logr1 - (pct * (logr1 - logr0));
- var value = Math.pow(Dygraph.LOG_SCALE, exponent);
+ var value = Math.pow(utils.LOG_SCALE, exponent);
return value;
}
};
var pct;
var logscale = this.attributes_.getForAxis("logscale", axis);
if (logscale) {
- var logr0 = Dygraph.log10(yRange[0]);
- var logr1 = Dygraph.log10(yRange[1]);
- pct = (logr1 - Dygraph.log10(y)) / (logr1 - logr0);
+ var logr0 = utils.log10(yRange[0]);
+ var logr1 = utils.log10(yRange[1]);
+ pct = (logr1 - utils.log10(y)) / (logr1 - logr0);
} else {
// yRange[1] - y is unit distance from the bottom.
// yRange[1] - yRange[0] is the scale of the range.
var pct;
var logscale = this.attributes_.getForAxis("logscale", 'x') ;
if (logscale === true) { // logscale can be null so we test for true explicitly.
- var logr0 = Dygraph.log10(xRange[0]);
- var logr1 = Dygraph.log10(xRange[1]);
- pct = (Dygraph.log10(x) - logr0) / (logr1 - logr0);
+ var logr0 = utils.log10(xRange[0]);
+ var logr1 = utils.log10(xRange[1]);
+ pct = (utils.log10(x) - logr0) / (logr1 - logr0);
} else {
// x - xRange[0] is unit distance from the left.
// xRange[1] - xRange[0] is the scale of the range.
this.removeTrackedEvents_();
// remove mouse event handlers (This may not be necessary anymore)
- Dygraph.removeEvent(window, 'mouseout', this.mouseOutHandler_);
- Dygraph.removeEvent(this.mouseEventElement_, 'mousemove', this.mouseMoveHandler_);
+ utils.removeEvent(window, 'mouseout', this.mouseOutHandler_);
+ utils.removeEvent(this.mouseEventElement_, 'mousemove', this.mouseMoveHandler_);
// remove window handlers
- Dygraph.removeEvent(window,'resize', this.resizeHandler_);
+ utils.removeEvent(window,'resize', this.resizeHandler_);
this.resizeHandler_ = null;
removeRecursive(this.maindiv_);
// alternate colors for high contrast.
var idx = i % 2 ? (half + (i + 1)/ 2) : Math.ceil((i + 1) / 2);
var hue = (1.0 * idx / (1 + num));
- colorStr = Dygraph.hsvToRGB(hue, sat, val);
+ colorStr = utils.hsvToRGB(hue, sat, val);
}
}
this.colors_.push(colorStr);
var points = this.layout_.points[setIdx];
for (var i = 0; i < points.length; ++i) {
point = points[i];
- if (!Dygraph.isValidPoint(point)) continue;
+ if (!utils.isValidPoint(point)) continue;
dx = point.canvasx - domX;
dy = point.canvasy - domY;
dist = dx * dx + dy * dy;
var points = this.layout_.points[setIdx];
if (rowIdx >= points.length) continue;
var p1 = points[rowIdx];
- if (!Dygraph.isValidPoint(p1)) continue;
+ if (!utils.isValidPoint(p1)) continue;
var py = p1.canvasy;
if (domX > p1.canvasx && rowIdx + 1 < points.length) {
// interpolate series Y value using next point
var p2 = points[rowIdx + 1];
- if (Dygraph.isValidPoint(p2)) {
+ if (utils.isValidPoint(p2)) {
var dx = p2.canvasx - p1.canvasx;
if (dx > 0) {
var r = (domX - p1.canvasx) / dx;
} else if (domX < p1.canvasx && rowIdx > 0) {
// interpolate series Y value using previous point
var p0 = points[rowIdx - 1];
- if (Dygraph.isValidPoint(p0)) {
+ if (utils.isValidPoint(p0)) {
var dx = p1.canvasx - p0.canvasx;
if (dx > 0) {
var r = (p1.canvasx - domX) / dx;
handlerClass = this.attr_('dataHandler');
} else if (this.fractions_) {
if (this.getBooleanOption('errorBars')) {
- handlerClass = DygraphDataHandlers.FractionsBarsHandler;
+ handlerClass = FractionsBarsHandler;
} else {
- handlerClass = DygraphDataHandlers.DefaultFractionHandler;
+ handlerClass = DefaultFractionHandler;
}
} else if (this.getBooleanOption('customBars')) {
- handlerClass = DygraphDataHandlers.CustomBarsHandler;
+ handlerClass = CustomBarsHandler;
} else if (this.getBooleanOption('errorBars')) {
- handlerClass = DygraphDataHandlers.ErrorBarsHandler;
+ handlerClass = ErrorBarsHandler;
} else {
handlerClass = DefaultHandler;
}
GridPlugin
];
+Dygraph.GVizChart = GVizChart;
+
export default Dygraph;
-var smoothPlotter = (function() {
+(function() {
"use strict";
+var Dygraph;
+if (window.Dygraph) {
+ Dygraph = window.Dygraph;
+} else if (typeof(module) !== 'undefined') {
+ Dygraph = require('../dygraph');
+}
+
/**
* Given three sequential points, p0, p1 and p2, find the left and right
* control points for p1.
smoothPlotter.smoothing = 1/3;
smoothPlotter._getControlPoints = getControlPoints; // for testing
-return smoothPlotter;
+// older versions exported a global.
+// This will be removed in the future.
+// The preferred way to access smoothPlotter is via Dygraph.smoothPlotter.
+window.smoothPlotter = smoothPlotter;
+Dygraph.smoothPlotter = smoothPlotter;
})();
/* global Dygraph:false */
'use strict';
-Dygraph.synchronize = function(/* dygraphs..., opts */) {
+var Dygraph;
+if (window.Dygraph) {
+ Dygraph = window.Dygraph;
+} else if (typeof(module) !== 'undefined') {
+ Dygraph = require('../dygraph');
+}
+
+var synchronize = function(/* dygraphs..., opts */) {
if (arguments.length === 0) {
throw 'Invalid invocation of Dygraph.synchronize(). Need >= 1 argument.';
}
}
}
+Dygraph.synchronize = synchronize;
+
})();
for (i = 0; i < ticks.length; i++) {
var axis = ticks[i][0];
if(drawGrid[axis]) {
+ ctx.save();
if (stroking[axis]) {
- ctx.installPattern(strokePattern[axis]);
+ if (ctx.setLineDash) ctx.setLineDash(strokePattern[axis]);
}
ctx.strokeStyle = strokeStyles[axis];
ctx.lineWidth = lineWidths[axis];
ctx.beginPath();
ctx.moveTo(x, y);
ctx.lineTo(x + area.w, y);
- ctx.closePath();
ctx.stroke();
- if (stroking[axis]) {
- ctx.uninstallPattern();
- }
+ ctx.restore();
}
}
ctx.restore();
var strokePattern = g.getOptionForAxis('gridLinePattern', 'x');
var stroking = strokePattern && (strokePattern.length >= 2);
if (stroking) {
- ctx.installPattern(strokePattern);
+ if (ctx.setLineDash) ctx.setLineDash(strokePattern);
}
ctx.strokeStyle = g.getOptionForAxis('gridLineColor', 'x');
ctx.lineWidth = g.getOptionForAxis('gridLineWidth', 'x');
ctx.stroke();
}
if (stroking) {
- ctx.uninstallPattern();
+ if (ctx.setLineDash) ctx.setLineDash([]);
}
ctx.restore();
}
*
* @constructor
*/
-var legend = function() {
+var Legend = function() {
this.legend_div_ = null;
this.is_generated_div_ = false; // do we own this div, or was it user-specified?
};
-legend.prototype.toString = function() {
+Legend.prototype.toString = function() {
return "Legend Plugin";
};
* @param {Dygraph} g Graph instance.
* @return {object.<string, function(ev)>} Mapping of event names to callbacks.
*/
-legend.prototype.activate = function(g) {
+Legend.prototype.activate = function(g) {
var div;
var divWidth = g.getOption('labelsDivWidth');
"overflow": "hidden"};
// TODO(danvk): get rid of labelsDivStyles? CSS is better.
- Dygraph.update(messagestyle, g.getOption('labelsDivStyles'));
+ utils.update(messagestyle, g.getOption('labelsDivStyles'));
div = document.createElement("div");
div.className = "dygraph-legend";
for (var name in messagestyle) {
return str.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
};
-legend.prototype.select = function(e) {
+Legend.prototype.select = function(e) {
var xValue = e.selectedX;
var points = e.selectedPoints;
var row = e.selectedRow;
this.legend_div_.style.top = topLegend + "px";
}
- var html = legend.generateLegendHTML(e.dygraph, xValue, points, this.one_em_width_, row);
+ var html = Legend.generateLegendHTML(e.dygraph, xValue, points, this.one_em_width_, row);
this.legend_div_.innerHTML = html;
this.legend_div_.style.display = '';
};
-legend.prototype.deselect = function(e) {
+Legend.prototype.deselect = function(e) {
var legendMode = e.dygraph.getOption('legend');
if (legendMode !== 'always') {
this.legend_div_.style.display = "none";
var oneEmWidth = calculateEmWidthInDiv(this.legend_div_);
this.one_em_width_ = oneEmWidth;
- var html = legend.generateLegendHTML(e.dygraph, undefined, undefined, oneEmWidth, null);
+ var html = Legend.generateLegendHTML(e.dygraph, undefined, undefined, oneEmWidth, null);
this.legend_div_.innerHTML = html;
};
-legend.prototype.didDrawChart = function(e) {
+Legend.prototype.didDrawChart = function(e) {
this.deselect(e);
};
* - its top edge is flush with the top edge of the charting area
* @private
*/
-legend.prototype.predraw = function(e) {
+Legend.prototype.predraw = function(e) {
// Don't touch a user-specified labelsDiv.
if (!this.is_generated_div_) return;
* Called when dygraph.destroy() is called.
* You should null out any references and detach any DOM elements.
*/
-legend.prototype.destroy = function() {
+Legend.prototype.destroy = function() {
this.legend_div_ = null;
};
* 'always'}) and with dashed lines.
* @param {number} row The selected row index.
*/
-legend.generateLegendHTML = function(g, x, sel_points, oneEmWidth, row) {
+Legend.generateLegendHTML = function(g, x, sel_points, oneEmWidth, row) {
// TODO(danvk): deprecate this option in place of {legend: 'never'}
if (g.getOption('showLabelsOnHighlight') !== true) return '';
return dash;
};
-export default legend;
+export default Legend;
<html>
<head>
- <script src="../dashed-canvas.js"></script>
+ <script src="../src/polyfills/dashed-canvas.js"></script>
</head>
<body>
<p>You should see solid black and blue lines with a dashed red line in between
ctx.stroke();
// Draw a dashed line segment.
-ctx.installPattern([10, 10]);
+// ctx.installPattern([10, 10]);
+ctx.setLineDash([10, 10]);
ctx.strokeStyle = 'red';
ctx.beginPath();
ctx.moveTo(100, 50);
ctx2.lineTo(600, 50);
ctx2.stroke();
-ctx.uninstallPattern();
+// ctx.uninstallPattern();
+ctx.setLineDash([]);
// Now that we've uninstalled the pattern, should be normal again.
ctx.strokeStyle = 'blue';
--- /dev/null
+watchify \
+ -v -t babelify \
+ --debug \
+ -o dist/tests.js \
+ auto_tests/tests/sanity.js \
+ auto_tests/tests/pathological_cases.js \
+ auto_tests/tests/axis_labels.js \
+ auto_tests/tests/annotations.js \
+ auto_tests/tests/callback.js \
+ auto_tests/tests/connect_separated_points.js \
+ auto_tests/tests/fill_step_plot.js \
+ auto_tests/tests/custom_bars.js \
+ auto_tests/tests/css.js \
+ auto_tests/tests/data_api.js \
+ auto_tests/tests/date_formats.js \
+ auto_tests/tests/date_ticker.js \
+ auto_tests/tests/error_bars.js \
+ auto_tests/tests/dygraph-options-tests.js \
+ auto_tests/tests/fast_canvas_proxy.js \
+ auto_tests/tests/formats.js \
+ auto_tests/tests/hidpi.js \
+ auto_tests/tests/interaction_model.js \
+ auto_tests/tests/missing_points.js \
+ auto_tests/tests/multi_csv.js \
+
+
+cat <<END
+auto_tests/tests/multiple_axes.js \
+auto_tests/tests/no_hours.js \
+auto_tests/tests/numeric_ticker.js \
+auto_tests/tests/parser.js \
+auto_tests/tests/per_axis.js \
+auto_tests/tests/per_series.js \
+auto_tests/tests/plugins.js \
+auto_tests/tests/plugins_legend.js \
+auto_tests/tests/range_selector.js \
+auto_tests/tests/range_tests.js \
+auto_tests/tests/resize.js \
+auto_tests/tests/rolling_average.js \
+auto_tests/tests/scientific_notation.js \
+auto_tests/tests/scrolling_div.js \
+auto_tests/tests/selection.js \
+auto_tests/tests/simple_drawing.js \
+auto_tests/tests/smooth_plotter.js \
+auto_tests/tests/stacked.js \
+auto_tests/tests/step_plot_per_series.js \
+auto_tests/tests/synchronize.js \
+auto_tests/tests/to_dom_coords.js \
+auto_tests/tests/two_digit_years.js \
+auto_tests/tests/update_options.js \
+auto_tests/tests/update_while_panning.js \
+auto_tests/tests/utils_test.js \
+auto_tests/tests/axis_labels-deprecated.js \
+auto_tests/tests/visibility.js
+auto_tests/tests/gviz.js \
+END > /dev/null
+
+
+# These ones are going to be hard
+cat <<END
+# There are differences between how installPattern and setLineDash work:
+auto_tests/tests/grid_per_axis.js
+END > /dev/null