Skip to content
Snippets Groups Projects
Commit 578eb514 authored by Kevin Hill's avatar Kevin Hill
Browse files

Batch static chart generation works!

parent 65eb8b5c
No related branches found
No related tags found
No related merge requests found
.idea/
node_modules/
renders/
File moved
const _ = require('lodash');
const Nightmare = require('nightmare');
var gulp = require('gulp'),
glob = require('glob'),
gutil = require('gulp-util'),
bump = require('gulp-bump'),
jshint = require('gulp-jshint'),
uglify = require('gulp-uglify'),
streamify = require('gulp-streamify'),
notify = require('gulp-notify'),
gulpif = require('gulp-if'),
stylish = require('jshint-stylish'),
fs = require('fs'),
replace = require('gulp-replace'),
argv = require('yargs').array('browsers').argv,
source = require('vinyl-source-stream'),
Loading
Loading
@@ -15,18 +15,15 @@ browserify = require('browserify'),
babelify = require('babelify'),
stripify = require('stripify'),
bSync = require('browser-sync').create(),
exec = require('child_process').exec,
spawn = require('child_process').spawn,
execSync = require('child_process').execSync,
phantom = require('gulp-phantom'),
connect = require('gulp-connect-php'),
watchify = require('watchify'),
notifier = require('node-notifier');
 
var renderOutputDir = './phantomjs/renders';
const serverPort = 5000;
const renderOutputDir = process.cwd()+'/renders/';
 
function compile(prod, watch, sync) {
var bundler = browserify({
let bundler = browserify({
debug: true,
entries: ['./src/lava.entry.es6'],
cache: {},
Loading
Loading
@@ -68,7 +65,7 @@ function compile(prod, watch, sync) {
 
if (watch) {
bundler.on('update', function() {
var msg = 'lava.js re-bundling...';
const msg = 'lava.js re-bundling...';
 
gutil.log(gutil.colors.green(msg));
 
Loading
Loading
@@ -93,102 +90,74 @@ function compile(prod, watch, sync) {
}
 
function getChartTypes(callback) {
exec('php ../tests/Examples/chartTypes.php', function (error, stdout, stderr) {
console.log(stderr);
var charts = eval(stdout);
callback(charts);
glob('*.php', {
cwd: '../src/Charts/',
nomount: true
}, (err, chartTypes) => {
_.pullAll(chartTypes, [
'Chart.php',
'ChartBuilder.php',
'ChartFactory.php',
]);
callback(_.map(chartTypes, chartType => {
return chartType.slice(0, -4);
}));
});
}
 
function renderChart(type, callback) {
const phantom = './node_modules/.bin/phantomjs';
const renderScript = './phantomjs/render.js';
console.log('[' + type + '] Launching phantom.');
//return exec([phantom, renderScript, type].join(' '), callback);
return spawn(phantom, [renderScript, type]);
}
function phpServer(router, port, callback) {
function phpServer(router, callback) {
const base = '../tests/Examples/';
 
connect.server({
base: base,
port: port || 8080,
port: serverPort,
ini: base + 'php.ini',
router: base + router
}, callback || function(){});
}
function phpServerEnd(done) {
connect.closeServer(function() {
done();
});
}, callback);
}
 
gulp.task('default', ['build']);
gulp.task('default', ['dev']);
 
// compile(prod, watch, sync)
gulp.task('build', function() { return compile(false, false, false) });
gulp.task('watch', function() { return compile(false, true, false) });
gulp.task('sync', function() { return compile(false, true, true) });
gulp.task('release', function() { return compile(true, false, false) });
gulp.task('dev', function() { return compile(false, false, false) });
gulp.task('watch', function() { return compile(false, true, false) });
gulp.task('sync', function() { return compile(false, true, true) });
gulp.task('prod', function() { return compile(true, false, false) });
 
gulp.task('charts', function() {
getChartTypes(function (charts) {
getChartTypes(charts => {
console.log(charts);
});
});
 
gulp.task('demos', function() {
phpServer('demo.php', process.env.PORT || 6000);
});
gulp.task('render', done => {
const Nightmare = require('nightmare');
phpServer('renderer.php', 5000, () => {
const chart = 'PieChart';
const nightmare = Nightmare();
nightmare
.viewport(800, 600)
.on('did-finish-load', () => {
phpServer('renderer.php', () => {
getChartTypes(chartTypes => {
let renders = _.map(chartTypes, chartType => {
const nightmare = Nightmare();
gutil.log(gutil.colors.green('Rendering '+chartType));
return nightmare
.viewport(800, 600)
.goto('http://localhost:'+serverPort+'/'+chartType)
.wait(3000)
.screenshot(renderOutputDir+chartType+'.png')
.end()
.catch(err => {
console.log(err);
});
});
 
console.log('did-finish-load');
})
.goto('http://localhost:5000/'+chart)
.wait(2000)
.screenshot('./renders/'+chart+'.png')
.end(() => "some value")
//prints "some value"
.then(connect.closeServer)
.then((value) => console.log(value));
Promise.all(renders).then(connect.closeServer);
});
});
});
 
gulp.task('phantom', function() {
gulp.src("./phantomjs/render.js")
.pipe(phantom({
ext: json
}))
.pipe(gulp.dest("./data/"));
});
gulp.task('jshint', function (done) {
return gulp.src('./src/**/*.js')
.pipe(jshint())
.pipe(jshint.reporter(stylish));
});
gulp.task('bump', function (done) { //-v=1.2.3
var version = argv.v;
var minorVersion = version.slice(0, -2);
let version = argv.v;
let minorVersion = version.slice(0, -2);
 
gulp.src('./package.json')
.pipe(bump({version:argv.v}))
Loading
Loading
Loading
Loading
@@ -18,6 +18,7 @@
"babelify": "^7.3.0",
"browser-sync": "^2.18.12",
"browserify": "^14.4.0",
"glob": "^7.1.2",
"gulp": "^3.9.1",
"gulp-bump": "^0.3.0",
"gulp-connect-php": "^1.0.1",
Loading
Loading
/* jshint undef: true */
/* globals module, require, phantom, window */
"use strict";
var page = require('webpage').create();
var args = require('system').args;
var renderOutputDir = './javascript/phantomjs/renders';
var url = 'http://127.0.0.1:5000/';
var chart = args[1];
page.onConsoleMessage = function(msg) {
console.log(msg);
};
page.open(url + chart, function (status) {
if (status !== "success") {
console.log('Error loading page.');
} else {
console.log('Page loaded, waiting on chart to render.');
page.onCallback = function (data) {
page.render(renderOutputDir + '/' + chart + '.png');
console.log('Saved to disk.');
phantom.exit();
//console.log('CALLBACK: ' + JSON.stringify(data));
// Prints 'CALLBACK: { "hello": "world" }'
};
}
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment