//
// For more on phantomjs, visit www.phantomjs.org.
+var RunAllAutoTests = function(done_callback) {
+
var page = require('webpage').create();
// NOTE: Cannot include '#' or '?' in this URL.
console.log(' ' + failures[i] + ' failed.');
}
- if (num_failing == 0) {
- console.log('PASS');
- } else {
+ done_callback(num_failing, num_passing);
+});
+
+};
+
+// Load all "tests/" pages.
+var LoadAllManualTests = function(totally_done_callback) {
+
+var fs = require('fs');
+var tests = fs.list('tests');
+var pages = [];
+
+function make_barrier_closure(n, fn) {
+ var calls = 0;
+ return function() {
+ calls++;
+ if (calls == n) {
+ fn();
+ } else {
+ // console.log('' + calls + ' done, ' + (n - calls) + ' remain');
+ }
+ };
+}
+
+var tasks = [];
+for (var i = 0; i < tests.length; i++) {
+ if (tests[i].substr(-5) != '.html') continue;
+ tasks.push(tests[i]);
+}
+tasks = [ 'independent-series.html' ];
+
+var loaded_page = make_barrier_closure(tasks.length, function() {
+ // Wait 2 secs to allow JS errors to happen after page load.
+ setTimeout(function() {
+ var success = 0, failures = 0;
+ for (var i = 0; i < pages.length; i++) {
+ if (pages[i].success && !pages[i].hasErrors) {
+ success++;
+ } else {
+ failures++;
+ }
+ }
+ console.log('Successfully loaded ' + success + ' / ' +
+ (success + failures) + ' test pages.');
+ totally_done_callback(failures, success);
+ }, 2000);
+});
+
+
+for (var i = 0; i < tasks.length; i++) {
+ var url = 'file://' + fs.absolute('tests/' + tasks[i]);
+ pages.push(function(path, url) {
+ var page = require('webpage').create();
+ page.success = false;
+ page.hasErrors = false;
+ page.onError = function (msg, trace) {
+ console.log(path + ': ' + msg);
+ page.hasErrors = true;
+ trace.forEach(function(item) {
+ console.log(' ', item.file, ':', item.line);
+ });
+ };
+ page.onLoadFinished = function(status) {
+ if (status == 'success') {
+ page.success = true;
+ }
+ if (!page.done) loaded_page();
+ page.done = true;
+ };
+ page.open(url);
+ return page;
+ }(tasks[i], url));
+}
+
+};
+
+
+// First run all auto_tests.
+// If they all pass, load the manual tests.
+RunAllAutoTests(function(num_failing, num_passing) {
+ if (num_failing !== 0) {
console.log('FAIL');
+ phantom.exit();
}
-
+ console.log('PASS');
phantom.exit();
+
+ // This is not yet reliable enough to be useful:
+ /*
+ LoadAllManualTests(function(failing, passing) {
+ if (failing !== 0) {
+ console.log('FAIL');
+ } else {
+ console.log('PASS');
+ }
+ phantom.exit();
+ });
+ */
});
[9, [10, 50, 100]]
], {
customBars: true,
- errorBars: true
+ errorBars: true,
+ labels: ['X', 'Y']
}
);
</script>
document.getElementById("div_g1"),
data, {
dateWindow: [ Date.parse("2009/09/29 12:00:00"),
- Date.parse("2009/10/10 12:00:00") ]
+ Date.parse("2009/10/10 12:00:00") ],
+ labels: [ 'Date', 'Y1', 'Y2' ]
}
);
document.getElementById("div_g2"),
data, {
dateWindow: [ Date.parse("2009/10/01 12:00:00"),
- Date.parse("2009/10/08 12:00:00") ]
+ Date.parse("2009/10/08 12:00:00") ],
+ labels: [ 'Date', 'Y1', 'Y2' ]
}
);
</script>
},
{ fillGraph: true }
);
-
- var g3 = new Dygraph(
- document.getElementById("div_g3"),
- function() {
- var ret = "X,Y1,Y2\n";
- for (var i = 0; i < 100; i++) {
- ret += i + "," + i + ",10," +
- (i * (100-i) * 100/(50*50)) + ",5\n";
- }
- return ret;
- },
- {
- errorBars: true,
- fillGraph: true
- }
- );
</script>
</body>
</html>
var chart1 = new Dygraph.GVizChart(document.getElementById('dygraphs'))
.draw(data, { });
-
- data = createDataTable('datetime');
- var chart2 = new Dygraph.GVizChart(
- document.getElementById('dygraphs_datetime')).draw(data, {
- });
}
google.setOnLoadCallback(drawVisualization);
"8,8, \n" +
"10,10, \n"
, {
- labels: ["x", "A", "B" ],
connectSeparatedPoints: true,
drawPoints: true
}
suffixes[magnitude];
}
- var g = new Dygraph(document.getElementById("labelsKMB"), data, { labelsKMB: true });
- var g2 = new Dygraph(document.getElementById("labelsKMG2"), data, { labelsKMG2: true });
- var g3 = new Dygraph(document.getElementById("labelsKMG2yValueFormatter"), data,
- { labelsKMG2: true, yValueFormatter: formatValue });
+ var g = new Dygraph(document.getElementById("labelsKMB"), data, {
+ labelsKMB: true,
+ labels: ['Base', 'Power']
+ });
+ var g2 = new Dygraph(document.getElementById("labelsKMG2"), data, {
+ labelsKMG2: true,
+ labels: ['Base', 'Power']
+ });
+ var g3 = new Dygraph(document.getElementById("labelsKMG2yValueFormatter"), data, {
+ labelsKMG2: true,
+ yValueFormatter: formatValue,
+ labels: ['Base', 'Power']
+ });
</script>
</body>
</html>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
+ // Capture warnings, since these are what we want in this test.
+ Dygraph.prototype.warn = function(msg) {
+ console.log(msg);
+ };
+
google.load('visualization', '1');
function createDataTable(dateType) {
data.push(row);
}
- g = new Dygraph(graph, data);
+ var labels = ['X'];
+ if (data[0].length == 2) {
+ labels.push('Y');
+ } else {
+ for (var i = 0; i < data[0].length; i++) {
+ labels.push('Y' + (1 + i));
+ }
+ }
+
+ g = new Dygraph(graph, data, {
+ labels: labels
+ });
}
function preset() {