Util.formatDate = function(dateMillis) {
return Dygraph.dateString_(dateMillis).slice(0, 10); // 10 == "YYYY/MM/DD".length
};
+
+/**
+ * Capture console.{log,warn,error} statements into obj.
+ * obj will look like {log:[], warn:[], error:[]}
+ * This returns a function which will restore the original console.
+ */
+Util.captureConsole = function(obj) {
+ obj.log = [];
+ obj.warn = [];
+ obj.error = [];
+ var orig = [console.log, console.warn, console.error];
+ console.log = function(text) { obj.log.push(text); };
+ console.warn = function(text) { obj.warn.push(text); };
+ console.error = function(text) { obj.error.push(text); };
+
+ return function() {
+ console.log = orig[0];
+ console.warn = orig[1];
+ console.error = orig[2];
+ };
+};
it('testDeprecatedDeprecatedXAxisTimeLabelFormatter', function() {
var opts = {
width: 480,
- height: 320
+ 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");
it('testXAxisTimeLabelFormatter', function() {
var opts = {
width: 480,
- height: 320
+ 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");
* Verify that log scale axis range is properly specified.
*/
it('testLogScale', function() {
- var g = new Dygraph("graph", [[0, 5], [1, 1000]], { logscale : true });
+ var g = new Dygraph("graph",
+ [[0, 5], [1, 1000]], {
+ logscale: true,
+ labels: ['X', 'Y']
+ });
var nonEmptyLabels = Util.getYLabels().filter(function(x) { return x.length > 0; });
assert.deepEqual(["5","10","20","50","100","200","500","1000"], nonEmptyLabels);
* Verify that include zero range is properly specified.
*/
it('testIncludeZero', function() {
- var g = new Dygraph("graph", [[0, 500], [1, 1000]], { includeZero : true });
+ var g = new Dygraph("graph",
+ [[0, 500], [1, 1000]], {
+ includeZero: true,
+ labels: ['X', 'Y1']
+ });
assert.deepEqual(['0','200','400','600','800','1000'], Util.getYLabels());
g.updateOptions({ includeZero : false });
var assertFontSize = function(selector, expected) {
Util.assertStyleOfChildren(selector, "font-size", expected);
}
-
+
assertFontSize(document.querySelectorAll(".dygraph-axis-label-x"), "14px");
- assertFontSize(document.querySelectorAll(".dygraph-axis-label-y") , "14px");
+ assertFontSize(document.querySelectorAll(".dygraph-axis-label-y"), "14px");
- g.updateOptions({ axisLabelFontSize : 8});
+ g.updateOptions({axisLabelFontSize : 8});
assertFontSize(document.querySelectorAll(".dygraph-axis-label-x"), "8px");
assertFontSize(document.querySelectorAll(".dygraph-axis-label-y"), "8px");
g.updateOptions({
axisLabelFontSize : null,
- axes : {
- x : { axisLabelFontSize : 5 },
+ axes: {
+ x: { axisLabelFontSize : 5 },
}
});
assertFontSize(document.querySelectorAll(".dygraph-axis-label-y"), "14px");
g.updateOptions({
- axes : {
- y : { axisLabelFontSize : 20 },
+ axes: {
+ y: { axisLabelFontSize : 20 },
}
});
assertFontSize(document.querySelectorAll(".dygraph-axis-label-y"), "20px");
g.updateOptions({
- series : {
- Y2 : { axis : "y2" } // copy y2 series to y2 axis.
+ series: {
+ Y2: { axis : "y2" } // copy y2 series to y2 axis.
},
- axes : {
- y2 : { axisLabelFontSize : 12 },
+ axes: {
+ y2: { axisLabelFontSize : 12 },
}
});
};
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
+ var g = new Dygraph(graph, testdata, {
+ drawHighlightPointCallback: drawHighlightPointCallback,
+ labels: ['X', 'Y']
});
assert.isNull(idxToCheck);
width: 500, height: 350,
customBars: true,
errorBars: true,
- axes : {
- x : {
+ axes: {
+ x: {
drawGrid: false,
drawAxis: false,
},
- y : {
+ y: {
drawGrid: false,
drawAxis: false,
}
},
valueRange: [0, 120],
fillAlpha: 0.15,
- colors: [ '#00FF00' ]
+ colors: ['#00FF00'],
+ labels: ['X', 'Y']
});
var sampler = new PixelSampler(g);
},
fillAlpha: 1.0,
logscale: true,
- colors: [ '#00FF00' ]
+ colors: ['#00FF00'],
+ labels: ['X', 'Y']
});
// The following assertions describe the sides of the custom bars, which are
],
{
drawPoints: true,
- drawPointCallback : drawPointCallback,
- customBars: true
+ drawPointCallback: drawPointCallback,
+ customBars: true,
+ labels: ['X', 'Y']
});
// Normally all three points would be drawn.
}
},
customBars: true,
- errorBars: true
+ errorBars: true,
+ labels: ['X', 'Y']
};
var data = [
[1, [10, 10, 100]],
[1,0],
[2,1],
[3,0]];
+var BASE_OPTS = {labels: ['X', 'Y']};
it('testCsv', function() {
var data = dataString;
it('testArray', function() {
var data = dataArray;
var graph = document.getElementById("graph");
- var g = new Dygraph(graph, data, {});
+ var g = new Dygraph(graph, data, BASE_OPTS);
assertData(g);
});
it('testFunctionReturnsCsv', function() {
- var string = dataString;
- var data = function() { return string; };
+ var data = function() { return dataString; };
var graph = document.getElementById("graph");
var g = new Dygraph(graph, data, {});
- // assertData(g);
- console.log("x");
+ assertData(g);
});
it('testFunctionDefinesArray', function() {
var data = function() { return array; }
var graph = document.getElementById("graph");
- var g = new Dygraph(graph, data, {});
+ var g = new Dygraph(graph, data, BASE_OPTS);
assertData(g);
});
"23,0\n";
var data2 =
- [[1, 10],
- [2, 20],
- [3, 30],
- [4, 40],
- [5, 120],
- [6, 50],
- [7, 70],
- [8, 90],
- [9, 50]];
+ "X,Y\n" +
+ "1,10\n" +
+ "2,20\n" +
+ "3,30\n" +
+ "4,40\n" +
+ "5,120\n" +
+ "6,50\n" +
+ "7,70\n" +
+ "8,90\n" +
+ "9,50\n";
function getXLabels() {
var x_labels = document.getElementsByClassName("dygraph-axis-label-x");
* A sanity test to ensure pointClickCallback is called.
*/
it('testPointClickCallback', function() {
- var clicked;
- var g = new Dygraph(document.getElementById("graph"), data2, {
- pointClickCallback : function(event, point) {
+ var clicked = null;
+ var g = new Dygraph('graph', data2, {
+ pointClickCallback: function(event, point) {
clicked = point;
}
});
clickAt(g, 4, 40);
+ assert.isNotNull(clicked);
assert.equal(4, clicked.xval);
assert.equal(40, clicked.yval);
});
[[1, 10, 11],
[2, 11, null],
[3, 12, 13]],
- { colors: ['red', 'blue']});
+ {
+ colors: ['red', 'blue'],
+ labels: ['X', 'Y1', 'Y2']
+ });
var htx = g.hidden_ctx_;
assert.equal(2, CanvasAssertions.numLinesDrawn(htx, '#ff0000'));
assert.equal(0, CanvasAssertions.numLinesDrawn(htx, '#0000ff'));
[2, null],
[3, 13],
[4, 14]],
- { colors: ['blue']});
+ { colors: ['blue'], labels: ['X', 'Y']});
var htx = g.hidden_ctx_;
assert.equal(2, CanvasAssertions.numLinesDrawn(htx, '#0000ff'));
[2, null],
[3, 13],
[4, 14]],
- { colors: ['blue'], connectSeparatedPoints: true});
+ {
+ colors: ['blue'],
+ connectSeparatedPoints: true,
+ labels: ['X', 'Y']
+ });
var htx = g.hidden_ctx_;
var num_lines = 0;
{
connectSeparatedPoints: true,
drawPoints: true,
- colors: ['red', 'blue']
+ colors: ['red', 'blue'],
+ labels: ['X', 'Y1', 'Y2']
}
);
data,
{
errorBars: true,
- colors: ['red']
+ colors: ['red'],
+ labels: ['X', 'Y']
}
);
connectSeparatedPoints: true,
drawPoints: true,
errorBars: true,
- colors: ['red']
+ colors: ['red'],
+ labels: ['X', 'Y']
}
);
data,
{
customBars: true,
- colors: ['red']
+ colors: ['red'],
+ labels: ['X', 'Y']
}
);
connectSeparatedPoints: true,
drawPoints: true,
customBars: true,
- colors: ['red']
+ colors: ['red'],
+ labels: ['X', 'Y']
}
);
{
connectSeparatedPoints: true,
drawPoints: true,
- colors: ['red','blue']
+ colors: ['red','blue'],
+ labels: ['X', 'Y1', 'Y2']
}
);
g.updateOptions({ dateWindow : [ 2.5, 4.5 ] });
*/
describe("pathological-cases", function() {
+var restoreConsole;
+var logs = {};
beforeEach(function() {
document.body.innerHTML = "<div id='graph'></div>";
+ restoreConsole = Util.captureConsole(logs);
});
afterEach(function() {
+ restoreConsole();
});
it('testZeroPoint', function() {
opts.labels = ['X', 'A', 'B', 'C'].slice(0, cols);
var g = new Dygraph(gdiv, data, opts);
+
+ if (dataName == 'empty') {
+ assert.deepEqual(logs, {
+ log: [], warn: [],
+ error: ["Can't plot empty data set"]
+ });
+ logs.error = []; // reset
+ } else {
+ assert.deepEqual(logs, {log: [], warn: [], error: []});
+ }
}
}
}
*/
describe("range-selector", function() {
+var restoreConsole;
+var logs = {};
beforeEach(function() {
document.body.innerHTML = "<div id='graph'></div>";
+ restoreConsole = Util.captureConsole(logs);
});
afterEach(function() {
+ restoreConsole();
});
it('testRangeSelector', function() {
var g = new Dygraph(graph, data, opts);
assertGraphExistence(g, graph);
assert.isFalse(g.getOption('animatedZooms'));
+ assert.deepEqual(logs, {
+ log: [], error: [],
+ warn: ["Animated zooms and range selector are not compatible; disabling animatedZooms."]
+ });
});
it('testRangeSelectorWithAnimatedZoomsOption2', function() {
g.updateOptions({showRangeSelector: true});
assertGraphExistence(g, graph);
assert.isFalse(g.getOption('animatedZooms'));
+ assert.deepEqual(logs, {
+ log: [], error: [],
+ warn: ["Animated zooms and range selector are not compatible; disabling animatedZooms."]
+ });
});
it('testRangeSelectorInteraction', function() {
if (data === undefined) data = ZERO_TO_FIFTY_STEPS;
if (expectRangeX === undefined) expectRangeX = [10, 20];
if (expectRangeY === undefined) expectRangeY = [0, 55];
- var graph = document.getElementById("graph");
- var g = new Dygraph(graph, data, opts);
+ if (!opts) opts = {};
+ opts['labels'] = ['X', 'Y'];
+ var g = new Dygraph('graph', data, opts);
assertDeepCloseTo(expectRangeX, g.xAxisRange(), 0.01);
assertDeepCloseTo(expectRangeY, g.yAxisRange(0), 0.01);
* Verify that log scale axis range is properly specified.
*/
it('testLogScaleExcludesZero', function() {
- var g = new Dygraph("graph", FIVE_TO_ONE_THOUSAND, { logscale : true });
+ var g = new Dygraph("graph", FIVE_TO_ONE_THOUSAND, {
+ logscale: true,
+ labels: ['X', 'Y']
+ });
assert.deepEqual([10, 1099], g.yAxisRange(0));
g.updateOptions({ logscale : false });
* Verify that includeZero range is properly specified.
*/
it('testIncludeZeroIncludesZero', function() {
- var g = new Dygraph("graph", [[0, 500], [500, 1000]], { includeZero : true });
+ var g = new Dygraph("graph", [[0, 500], [500, 1000]], {
+ includeZero: true,
+ labels: ['X', 'Y']
+ });
assert.deepEqual([0, 1100], g.yAxisRange(0));
g.updateOptions({ includeZero : false });
* Verify that very large Y ranges don't break things.
*/
it('testHugeRange', function() {
- var g = new Dygraph("graph", [[0, -1e120], [1, 1e230]], { includeZero : true });
+ var g = new Dygraph("graph", [[0, -1e120], [1, 1e230]], {
+ includeZero: true,
+ labels: ['X', 'Y']
+ });
assert.closeTo(1, -1e229 / g.yAxisRange(0)[0], 0.001);
assert.closeTo(1, 1.1e230 / g.yAxisRange(0)[1], 0.001);
});
it('testRollShortFractions', function() {
var opts = {
customBars: true,
- labels: ['x', 'A']
+ labels: ['x', 'A', 'B']
};
var data1 = [ [1, 10, [1, 20]] ];
var data2 = [ [1, 10, [1, 20]],
*
* @author konigsberg@google.com (Robert Konigsberg)
*/
-var DEAD_SIMPLE_DATA = [[ 10, 2100 ]];
-var ZERO_TO_FIFTY = [[ 10, 0 ] , [ 20, 50 ]];
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>";
});
var graph = document.getElementById("graph");
var g = new Dygraph(graph,
"X,A,B,C\n" +
- "1,1,null,null\n" +
- "2,null,2,null\n" +
- "3,null,null,3\n",
+ "1,1,,\n" +
+ "2,,2,\n" +
+ "3,,,3\n",
{
dataHandler: dataHandler
}
*
* @author konigsberg@google.com (Robert Konigsberg)
*/
-var ZERO_TO_FIFTY = [[ 10, 0 ] , [ 20, 50 ]];
describe("simple-drawing", function() {
+var ZERO_TO_FIFTY = 'X,Y\n10,0\n20,50';
+
var _origFunc = Dygraph.getContext;
beforeEach(function() {
document.body.innerHTML = "<div id='graph'></div>";
it('testDrawSimpleRangePlusOne', function() {
var opts = {
- axes : {
- x : {
+ axes: {
+ x: {
drawGrid: false,
- drawAxis: false,
+ drawAxis: false
},
- y : {
+ y: {
drawGrid: false,
- drawAxis: false,
+ drawAxis: false
}
},
- valueRange: [0,51] }
+ valueRange: [0,51]
+ };
var graph = document.getElementById("graph");
var g = new Dygraph(graph, ZERO_TO_FIFTY, opts);
series: {
'Y1': {strokePattern: [25, 7, 7, 7]},
},
- colors: ['#ff0000']
+ colors: ['#ff0000'],
+ labels: ['X', 'Y']
};
var graph = document.getElementById("graph");
*/
it('testDrawThickLine', function() {
var opts = {
- axes : {
- x : {
+ axes: {
+ x: {
drawGrid: false,
- drawAxis: false,
+ drawAxis: false
},
- y : {
+ y: {
drawGrid: false,
- drawAxis: false,
+ drawAxis: false
}
},
strokeWidth: 15,
- colors: ['#ff0000']
+ colors: ['#ff0000'],
+ labels: ['X', 'Y']
};
var graph = document.getElementById("graph");
it('testInterpolation', function() {
var opts = {
colors: ['#ff0000', '#00ff00', '#0000ff'],
- stackedGraph: true
+ stackedGraph: true,
+ labels: ['X', 'Y1', 'Y2', 'Y3', 'Y4']
};
// The last series is all-NaN, it ought to be treated as all zero
it('testInterpolationOptions', function() {
var opts = {
colors: ['#ff0000', '#00ff00', '#0000ff'],
- stackedGraph: true
+ stackedGraph: true,
+ labels: ['X', 'Y1', 'Y2', 'Y3']
};
var data = [
colors: ['#ff0000', '#00ff00', '#0000ff'],
stackedGraph: true,
series: {
- "Y1": {
- axis: 'y',
- },
- "Y2": {
- axis: 'y',
- },
- "Y3": {
- axis: 'y2',
- },
- "Y4": {
- axis: 'y2',
- }
- }
+ 'Y1': {
+ axis: 'y',
+ },
+ 'Y2': {
+ axis: 'y',
+ },
+ 'Y3': {
+ axis: 'y2',
+ },
+ 'Y4': {
+ axis: 'y2',
+ }
+ },
+ labels: ['X', 'Y1', 'Y2', 'Y3', 'Y4']
};
// The last series is all-NaN, it ought to be treated as all zero
it('testPlainChart', function() {
var opts = {
- axes : {
- x : {
+ axes: {
+ x: {
drawAxis : false,
- drawGrid : false,
+ drawGrid : false
},
- y : {
+ y: {
drawAxis : false,
- drawGrid : false,
+ drawGrid : false
}
},
rightGap: 0,
dateWindow: [0, 100],
width: 400,
height: 400,
- colors: ['#ff0000']
+ colors: ['#ff0000'],
+ labels: ['X', 'Y']
}
var graph = document.getElementById("graph");
it('testChartWithAxes', function() {
var opts = {
- axes : {
- x : {
+ axes: {
+ x: {
drawGrid: false,
drawAxis: true,
},
- y : {
+ y: {
drawGrid: false,
drawAxis: true,
axisLabelWidth: 100
dateWindow: [0, 100],
width: 500,
height: 450,
- colors: ['#ff0000']
+ colors: ['#ff0000'],
+ labels: ['X', 'Y']
}
var graph = document.getElementById("graph");
it('testChartWithAxesAndLabels', function() {
var opts = {
- axes : {
- x : {
+ axes: {
+ x: {
drawGrid: false,
drawAxis: true,
},
- y : {
+ y: {
drawGrid: false,
drawAxis: true,
axisLabelWidth: 100
- }
+ },
},
xAxisHeight: 50,
axisTickSize: 0,
xlabel: 'This is the x-axis',
xLabelHeight: 25,
title: 'This is the title of the chart',
- titleHeight: 25
+ titleHeight: 25,
+ labels: ['X', 'Y']
}
var graph = document.getElementById("graph");
valueRange: [0, 100],
dateWindow: [0, 100],
width: 500,
- height: 500
+ height: 500,
+ labels: ['X', 'Y']
}
var graph = document.getElementById("graph");
valueRange: [0, 100],
dateWindow: [0, 100],
width: 500,
- height: 500
+ height: 500,
+ labels: ['X', 'Y']
}
var graph = document.getElementById("graph");
drawAxis: false,
logscale: true
}
- }
+ },
+ labels: ['X', 'Y']
}
var graph = document.getElementById("graph");
drawGrid: false,
drawAxis: false
}
- }
+ },
+ labels: ['X', 'Y']
}
var graph = document.getElementById("graph");
var opts = {
width: 480,
height: 320,
- valueRange: [-2, 2]
+ valueRange: [-2, 2],
+ labels: ['X', 'Y']
};
var graph = document.getElementById("graph");
"obvious-closure-library": "^20140401.0.2",
"parse-data-uri": "^0.2.0",
"phantomjs": "^1.9.7-8",
+ "pre-commit": "^1.0.6",
"source-map": "^0.4.2",
"uglify-js": "^2"
},
"scripts": {
- "test": "make test"
- }
+ "test": "make test",
+ "tests-ok": "./scripts/check-no-only.sh"
+ },
+ "pre-commit": [
+ "tests-ok"
+ ]
}
--- /dev/null
+#!/bin/bash
+# Checks that no ".only" has made it into tests. This should never be commited,
+# since it will disable the vast majority of tests.
+
+if grep -R '\.only(' auto_tests/tests; then
+ echo 'Remove .only from tests before committing.'
+ exit 1
+fi
+
+exit 0