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('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() {
[[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'));
*/
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() {
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 = 'X,Y\n10,2100';
-var ZERO_TO_FIFTY = 'X,Y\n10,0\n20,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");