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

Merge branch 'nightmare'

parents 511597e8 c590d1b2
No related branches found
No related tags found
No related merge requests found
Showing
with 6726 additions and 9026 deletions
Loading
Loading
@@ -9,7 +9,7 @@ javascript/karma/ export-ignore
.gitignore export-ignore
.travis.yml export-ignore
.codeclimate.yml export-ignore
gulpfile.js export-ignore
gulpfile.babel.js export-ignore
package.json export-ignore
phpunit.xml
javascript/lava.spec.js export-ignore
Loading
Loading
Loading
Loading
@@ -2,9 +2,6 @@ vendor/
build/
.idea/
 
javascript/node_modules/
javascript/phantomjs/renders/
composer.phar
 
*.log
Loading
Loading
.idea/
node_modules/
renders/*.png
File moved
Source diff could not be displayed: it is too large. Options to address this: view the blob.
import args from 'yargs';
import gulpif from 'gulp-if';
import source from 'vinyl-source-stream';
import notifier from 'node-notifier';
import browserify from 'browserify';
import uglify from 'gulp-uglify';
import babelify from 'babelify';
// import stripify from 'stripify';
import watchify from 'watchify';
import streamify from 'gulp-streamify';
import versionify from 'browserify-versionify';
import { dest } from 'gulp';
import { log } from 'gulp-util';
import { red, green } from 'chalk';
import { create } from 'browser-sync';
const browserSync = create();
export default function compile(prod, watch, sync) {
let bundler = browserify({
debug: true,
entries: ['./src/lava.entry.es6'],
cache: {},
packageCache: {}
});
bundler.transform(babelify, { presets: ['es2015'] });
bundler.transform(versionify);
if (watch) {
bundler = watchify(bundler);
if (sync) {
browserSync.init({
proxy: "localhost:" + args.port || 8000
});
}
}
if (prod) {
bundler.transform('stripify');
}
function rebundle() {
return bundler.bundle()
.on('error', err => {
if (err instanceof SyntaxError) {
log(red('Syntax Error'));
log(err.message);
// log(err.filename+":"+err.loc.line);
log(err.codeFrame);
} else {
log(red('Error'), err.message);
}
this.emit('end');
})
.pipe(source('lava.js'))
.pipe(gulpif(prod, streamify(uglify())))
.pipe(dest('dist'));
}
if (watch) {
bundler.on('update', () => {
const msg = 'lava.js re-bundling...';
log(green(msg));
notifier.notify({
title: 'Browserify',
message:msg
});
rebundle();
});
bundler.on('log', msg => {
log(green(msg));
if (sync) {
browserSync.reload();
}
});
}
return rebundle();
}
import { map } from 'lodash';
import { cwd } from 'process';
import { resolve } from 'path';
import { sync as globSync } from 'glob';
export default function getChartTypes() {
let chartTypes = globSync('*.php', {
cwd: resolve(cwd(), '../src/Charts/'),
nomount: true,
ignore: [
'Chart.php',
'ChartBuilder.php',
'ChartFactory.php',
]
});
return map(chartTypes, chartType => {
return chartType.slice(0, -4);
});
}
import PortFinder from 'portfinder';
import PhpServer from 'gulp-connect-php';
import { cwd } from 'process';
import { resolve } from 'path';
function _createServer(port) {
const base = resolve(cwd(), '../tests/Examples');
const server = new PhpServer();
return new Promise(resolve => {
server.server({
base: base,
port: port,
ini: base + '/php.ini',
router: base + '/renderer.php'
});
resolve(server);
});
}
export default function getPhpServer() {
return PortFinder
.getPortPromise()
.then(_createServer)
.catch(err => {
console.log(err);
});
}
import Nightmare from 'nightmare';
import getPhpServer from './PhpServer';
import { cwd } from 'process';
import { resolve } from 'path';
function _getNightmare(timeout) {
return new Nightmare({
gotoTimeout: timeout,
waitTimeout: timeout,
loadTimeout: timeout,
executionTimeout: timeout
});
}
export default function renderChart(chartType) {
return getPhpServer()
.then(server => {
let chartUrl = 'http://localhost:' + server.port + '/' + chartType;
let renderDir = resolve(cwd(), 'renders');
let chartImg = renderDir + '/' + chartType + '.png';
console.log('Nightmare opening ' + chartUrl);
return _getNightmare(5000)
.viewport(800, 600)
.goto(chartUrl)
.wait(3000)
.screenshot(chartImg)
.end(() => {
console.log('Saved screenshot to ' + chartImg);
server.closeServer();
});
});
}
/* jshint node:true */
import gulp from 'gulp';
import yargs from 'yargs';
import bump from 'gulp-bump';
import replace from 'gulp-replace';
import compile from './gulp-functions/Compile';
import renderChart from './gulp-functions/Renderer';
import getChartTypes from './gulp-functions/GetChartTypes';
import { cpus } from 'os'
import { map } from 'bluebird';
gulp.task('default', ['dev']);
/**
* Lava.js compilation tasks.
*
* The compile method accepts three boolean flags for the following signature:
* compile(prod, watch, sync)
*/
gulp.task('dev', () => { compile(false, false, false) });
gulp.task('prod', () => { compile(true, false, false) });
gulp.task('watch', () => { compile(false, true, false) });
gulp.task('sync', () => { compile(false, true, true) });
/**
* Render a specific chart.
*
* Specify the type as the php class name
*
* Syntax:
* gulp render --type [ AreaChart | LineChart | GeoChart | etc... ]
*/
gulp.task('render', done => {
const chartTypes = getChartTypes();
const args = yargs
.fail(msg => {
throw new Error(msg);
})
.alias('t', 'type')
.describe('t', 'choose the type of chart to render')
.choices('t', chartTypes)
.wrap(70)
.help('help')
.argv;
renderChart(args.t)
.then(() => {
done();
})
.catch(err => {
console.log(err);
});
});
/**
* Render all of the available charts.
*
* The renders will be ran in batches equal to the number of processors.
*
* Syntax:
* gulp renderAll
*/
gulp.task('renderAll', done => {
let batchSize = cpus().length;
console.log('Rendering charts in batches of '+batchSize);
map(getChartTypes(), chartType => {
return renderChart(chartType);
}, {concurrency: batchSize})
.then(() => {
done();
})
.catch(err => {
console.log(err);
});
});
/**
* Get all available chart types
*
* Syntax:
* gulp charts
*/
gulp.task('charts', done => {
console.log('Available charts for rendering:');
console.log(getChartTypes().join(', '));
done();
});
/**
* Render all of the available charts.
*
* Syntax:
* gulp version -v 4.0.0
*/
// gulp.task('version', done => {
// let version = args.v;
// let minorVersion = version.slice(0, -2);
//
// gulp.src('./package.json')
// .pipe(bump({version:args.v}))
// .pipe(gulp.dest('./'));
//
// gulp.src(['./README.md', './.travis.yml'])
// .pipe(replace(/(["=\/-])[0-9]+\.[0-9]+/g, '$1'+minorVersion))
// .pipe(gulp.dest('./'));
//
// done();
// });
var gulp = require('gulp'),
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'),
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';
function compile(prod, watch, sync) {
var bundler = browserify({
debug: true,
entries: ['./src/lava.entry.es6'],
cache: {},
packageCache: {}
})
.transform(babelify, { presets: ['es2015'] });
if (watch) {
bundler = watchify(bundler);
if (sync) {
bSync.init({
proxy: "localhost:8000"
});
}
}
if (prod) {
bundler.transform('stripify');
}
function rebundle() {
return bundler.bundle()
.on('error', function(err){
if (err instanceof SyntaxError) {
gutil.log(gutil.colors.red('Syntax Error'));
console.log(err.message);
// console.log(err.filename+":"+err.loc.line);
console.log(err.codeFrame);
} else {
gutil.log(gutil.colors.red('Error'), err.message);
}
this.emit('end');
})
.pipe(source('lava.js'))
.pipe(gulpif(prod, streamify(uglify())))
.pipe(gulp.dest('dist'));
}
if (watch) {
bundler.on('update', function() {
var msg = 'lava.js re-bundling...';
gutil.log(gutil.colors.green(msg));
notifier.notify({
title: 'Browserify',
message:msg
});
rebundle();
});
bundler.on('log', function (msg) {
gutil.log(gutil.colors.green(msg));
if (sync) {
bSync.reload();
}
});
}
return rebundle();
}
function getChartTypes(callback) {
exec('php ../tests/Examples/chartTypes.php', function (error, stdout, stderr) {
console.log(stderr);
var charts = eval(stdout);
callback(charts);
});
}
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) {
const base = '../tests/Examples/';
connect.server({
base: base,
port: port || 8080,
ini: base + 'php.ini',
router: base + router
}, callback || function(){});
}
function phpServerEnd(done) {
connect.closeServer(function() {
done();
});
}
gulp.task('default', ['build']);
// 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('charts', function() {
getChartTypes(function (charts) {
console.log(charts);
});
});
gulp.task('demos', function() {
phpServer('demo.php', process.env.PORT || 6000);
});
gulp.task('render', function (done) {
phpServer('renderer.php', 5000, function() {
var chart = 'PieChart';
var renderer = renderChart(chart);
renderer.stdout.on('data', function (data) {
console.log('['+chart+'] ' + data);
});
renderer.on('close', function (code) {
const chartPath = renderOutputDir+'/'+chart+'.png';
if (fs.existsSync(chartPath)) {
execSync('convert ' + chartPath + ' -trim +repage ' + chartPath);
console.log('[' + chart + '] Successfully Cropped.');
} else {
console.log('[' + chart + '] ' + chartPath + ' not found.');
}
phpServerEnd(done);
});
});
});
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);
gulp.src('./package.json')
.pipe(bump({version:argv.v}))
.pipe(gulp.dest('./'));
gulp.src(['./README.md', './.travis.yml'])
.pipe(replace(/("|=|\/|-)[0-9]+\.[0-9]+/g, '$1'+minorVersion))
.pipe(gulp.dest('./'));
});
/* jshint node:true */
module.exports = function (config) {
config.set({
frameworks: ['jasmine','sinon'],
Loading
Loading
Source diff could not be displayed: it is too large. Options to address this: view the blob.
Loading
Loading
@@ -10,21 +10,24 @@
"node": "0.12.*"
},
"dependencies": {
"babel-register": "^6.24.1",
"lodash": "^4.17.4"
},
"devDependencies": {
"@angular/core": "^4.2.4",
"babel-preset-es2015": "^6.24.1",
"babelify": "^7.3.0",
"bluebird": "^3.5.0",
"browser-sync": "^2.18.12",
"browserify": "^14.4.0",
"browserify-versionify": "^1.0.6",
"glob": "^7.1.2",
"gulp": "^3.9.1",
"gulp-bump": "^0.3.0",
"gulp-connect-php": "0.0.8",
"gulp-connect-php": "^1.0.1",
"gulp-if": "^2.0.0",
"gulp-jshint": "^1.10.0",
"gulp-notify": "^3.0.0",
"gulp-phantom": "0.0.6",
"gulp-rename": "^1.2.2",
"gulp-replace": "^0.5.4",
"gulp-spawn": "^0.3.0",
Loading
Loading
@@ -38,8 +41,10 @@
"karma": "^0.13.0",
"karma-jasmine": "^0.3.5",
"karma-sinon": "^1.0.4",
"nightmare": "^2.10.0",
"node-notifier": "^5.1.2",
"node-resemble-js": "^0.2.0",
"portfinder": "^1.0.13",
"rxjs": "^5.1.0",
"sinon": "^1.17.3",
"stripify": "^4.0.0",
Loading
Loading
@@ -56,6 +61,7 @@
"url": "https://github.com/kevinkhill/lavacharts/issues"
},
"scripts": {
"gulp": "./node_modules/.bin/gulp",
"test": "./node_modules/.bin/karma start --singleRun",
"jsdoc": "./node_modules/.bin/jsdoc -d build/jsdoc --package package.json javascript/src/lava/Lava.js"
}
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" }'
};
}
});
Loading
Loading
@@ -36,7 +36,7 @@ export class LavaJs extends EventEmitter
* @type {string}
* @public
*/
this.VERSION = '4.0.0';
this.VERSION = '__VERSION__';
 
/**
* Version of the Google charts API to load.
Loading
Loading
This diff is collapsed.
This diff is collapsed.
Loading
Loading
@@ -14,14 +14,15 @@ if (preg_match('/\.(?:png|jpg|jpeg|gif)$/', $_SERVER["REQUEST_URI"])) {
$height = floor($width*(6/19));
 
$title = 'My' . ((strpos($chartType, 'To') > 0) ? 'Dashboard' : $chartType);
$id = strtolower($title);
 
if (strpos($chartType, 'Chart') > 0) {
require_once(__DIR__ . '/Charts/' . $chartType . '.php');
$id = $lava->fetch($chartType, $title)->getElementId();
} else {
require_once(__DIR__ . '/Dashboards/' . $chartType . '.php');
$id = $lava->fetch('Dashboard', $title)->getElementId();
}
$lava->get($title)->setElementId($id);
}
}
?>
Loading
Loading
@@ -46,11 +47,7 @@ if (preg_match('/\.(?:png|jpg|jpeg|gif)$/', $_SERVER["REQUEST_URI"])) {
<? } ?>
</div>
<?php
if (strpos($chartType, 'Chart') > 0) {
echo $lava->render($chartType, $title);
} else {
echo $lava->render('Dashboard', $title);
}
echo $lava->renderAll();
?>
<script type="text/javascript">
lava.ready(function() {
Loading
Loading
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