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

lava.js works as a standalone!

parent 26e66cc2
No related branches found
No related tags found
No related merge requests found
Source diff could not be displayed: it is too large. Options to address this: view the blob.
Loading
Loading
@@ -19,7 +19,11 @@ let bundler = browserify({
debug: true,
entries: ['./src/lava.entry.es6'],
cache: {},
packageCache: {}
packageCache: {},
transform: [
'browserify-versionify',
['babelify', {presets: ['es2015'] }]
]
});
 
function rebundle(prod = false) {
Loading
Loading
@@ -42,8 +46,8 @@ function rebundle(prod = false) {
}
 
export default function compile(prod, watch, sync) {
bundler.transform(babelify, {presets: ['es2015'] });
bundler.transform(versionify);
// bundler.transform(babelify, {presets: ['es2015'] });
// bundler.transform(versionify);
 
if (prod) {
bundler.transform('stripify');
Loading
Loading
Loading
Loading
@@ -32,33 +32,6 @@ gulp.task('prod', () => { compile(true, false, false) });
gulp.task('watch', () => { compile(false, true, false) });
gulp.task('sync', () => { compile(false, true, true) });
 
gulp.task('lavajs', () => {
let lavajs = browserify({
debug : true,
entries : ['./src/lava.browser.es6'],
cache : {},
packageCache: {}
});
lavajs
.transform('babelify', {presets: ['es2015'] })
.transform('browserify-versionify')
.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);
}
})
.pipe(source('lava.js'))
// .pipe(gulpif(prod, streamify(uglify())))
.pipe(gulp.dest('dist'));
});
/**
* Render a specific chart.
*
Loading
Loading
import LavaJs from './lava/Lava.es6';
window.lava = new LavaJs();
Loading
Loading
@@ -8,17 +8,23 @@ import { domLoaded } from './lava/Utils.es6';
* Assign the Lava.js module to the window and
* let $lava be an alias to the module.
*/
let $lava = window.lava = new LavaJs();
window.lava = new LavaJs();
 
/**
* Once the DOM has loaded...
* If Lava.js was loaded from Lavacharts, the __OPTIONS__
* placeholder will be a JSON object of options that
* were set server-side.
*/
domLoaded().then(() => {
if (typeof __OPTIONS__ !== 'undefined') {
$lava.options = __OPTIONS__;
}
if (typeof __OPTIONS__ !== 'undefined') {
window.lava.options = __OPTIONS__;
}
 
if ($lava.options.auto_run === true) {
$lava.run(window);
}
});
/**
* If Lava.js was set to auto_run then once the DOM
* is ready, rendering will begin.
*/
if (window.lava.options.auto_run === true) {
domLoaded().then(() => {
window.lava.run();
});
}
Loading
Loading
@@ -82,6 +82,13 @@ export default class LavaJs extends EventEmitter
*/
this.options = newOptions || defaultOptions;
 
/**
* Reference to the google.visualization object.
*
* @type {google.visualization}
*/
this.visualization = null;
/**
* Array of visualization packages for charts and dashboards.
*
Loading
Loading
@@ -172,7 +179,9 @@ export default class LavaJs extends EventEmitter
* @public
*/
init() {
return this._loadGoogle();
return this._loadGoogle().then(() => {
this.visualization = google.visualization;
});
}
 
/**
Loading
Loading
@@ -181,47 +190,27 @@ export default class LavaJs extends EventEmitter
* @public
*/
run() {
const $lava = this;
if ($lava.options.responsive === true) {
let debounced = null;
addEvent(window, 'resize', () => {
let redraw = $lava.redrawAll.bind($lava);
clearTimeout(debounced);
debounced = setTimeout(() => {
console.log('[lava.js] Window re-sized, redrawing...');
redraw();
}, $lava.options.debounce_timeout);
});
}
// const $lava = this;
 
console.log('[lava.js] Running...');
console.log('[lava.js] Loading options:', this.options);
 
$lava.init().then(() => {
console.log('[lava.js] Google is ready.');
this._attachRedrawHandler();
 
/**
* Convenience map for google.visualization to be accessible
* via lava.visualization
*/
this.visualization = google.visualization;
this.init().then(() => {
console.log('[lava.js] Google is ready.');
 
_forIn($lava._renderables, renderable => {
_forIn(this._renderables, renderable => {
console.log(`[lava.js] Rendering ${renderable.uuid()}`);
 
renderable.render();
});
 
console.log('[lava.js] Firing "ready" event.');
$lava.emit('ready');
this.emit('ready');
 
console.log('[lava.js] Executing lava.ready(callback)');
$lava._readyCallback();
this._readyCallback();
});
}
 
Loading
Loading
@@ -398,6 +387,30 @@ export default class LavaJs extends EventEmitter
this._packages = this._packages.concat(packages);
}
 
/**
* Attach a listener to the window resize event for redrawing the charts.
*
* @private
*/
_attachRedrawHandler() {
if (this.options.responsive === true) {
let debounced = null;
addEvent(window, 'resize', () => {
// let redraw = this.redrawAll().bind(this);
clearTimeout(debounced);
debounced = setTimeout(() => {
console.log('[lava.js] Window re-sized, redrawing...');
// redraw();
this.redrawAll()
}, this.options.debounce_timeout);
});
}
}
/**
* Load the Google Static Loader and resolve the promise when ready.
*
Loading
Loading
const defaultOptions = {
"auto_run" : true,
"auto_run" : false,
"locale" : "en",
"timezone" : "America/Los_Angeles",
"datetime_format" : "",
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