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

optimizing imports and adding VizProps to Renderable class

parent af6823ee
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
@@ -7,10 +7,10 @@ import uglify from 'gulp-uglify';
import babelify from 'babelify';
import watchify from 'watchify';
import streamify from 'gulp-streamify';
import { dest } from 'gulp';
import { log } from 'gulp-util';
import { red, green } from 'chalk';
import { create as createBrowserSync } from 'browser-sync';
import {dest} from 'gulp';
import {log} from 'gulp-util';
import {green, red} from 'chalk';
import {create as createBrowserSync} from 'browser-sync';
 
const browserSync = createBrowserSync();
 
Loading
Loading
Loading
Loading
@@ -9,8 +9,6 @@
*/
import _forIn from 'lodash/forIn';
import Renderable from './Renderable';
import VisualizationProps from './VisualizationProps';
import { stringToFunction } from './Utils';
 
/**
* Chart class used for storing all the needed configuration for rendering.
Loading
Loading
@@ -43,23 +41,18 @@ export default class Chart extends Renderable
constructor (json) {
super(json);
 
this.type = json.type;
this.formats = json.formats;
 
this.events = typeof json.events === 'object' ? json.events : null;
this.pngOutput = typeof json.pngOutput === 'undefined' ? false : Boolean(json.pngOutput);
 
this.vizProps = new VisualizationProps(this.type);
/**
* Any dependency on window.google must be in the render scope.
*/
this.render = () => {
this.setData(json.datatable);
 
console.log(this.vizProps.class);
this.gchart = new google.visualization[this.vizProps.class](this.element);
this.gchart = new google.visualization[this.class](this.element);
 
if (this.formats) {
this.applyFormats();
Loading
Loading
@@ -77,15 +70,6 @@ export default class Chart extends Renderable
};
}
 
/**
* Get the type of package needed to render the chart.
*
* @return {string}
*/
get package() {
return this.vizProps.package;
}
/**
* Draws the chart as a PNG instead of the standard SVG
*
Loading
Loading
@@ -138,7 +122,7 @@ export default class Chart extends Renderable
func = callback[1];
}
 
console.log(`[lava.js] The "${$chart.uuid()}::${event}" event will be handled by "${func}" in the context`, context);
console.log(`[lava.js] The "${$chart.uuid}::${event}" event will be handled by "${func}" in the context`, context);
 
/**
* Set the context of "this" within the user provided callback to the
Loading
Loading
Loading
Loading
@@ -26,9 +26,10 @@ import Renderable from './Renderable';
export default class Dashboard extends Renderable
{
constructor(json) {
json.type = 'Dashboard';
super(json);
 
this.type = 'Dashboard';
this.bindings = json.bindings;
 
/**
Loading
Loading
Loading
Loading
@@ -6,12 +6,12 @@
* @copyright (c) 2017, KHill Designs
* @license MIT
*/
class LavaError extends Error
class LavaJsError extends Error
{
constructor (message) {
super();
 
this.name = 'LavaError';
this.name = 'LavaJsError';
this.message = (message || '');
};
}
Loading
Loading
@@ -22,7 +22,7 @@ class LavaError extends Error
* thrown when when anything but a function is given as a callback
* @type {function}
*/
export class InvalidCallback extends LavaError
export class InvalidCallback extends LavaJsError
{
constructor (callback) {
super(`[lava.js] "${typeof callback}" is not a valid callback.`);
Loading
Loading
@@ -38,7 +38,7 @@ export class InvalidCallback extends LavaError
*
* @type {function}
*/
export class InvalidLabel extends LavaError
export class InvalidLabel extends LavaJsError
{
constructor (label) {
super(`[lava.js] "${typeof label}" is not a valid label.`);
Loading
Loading
@@ -53,7 +53,7 @@ export class InvalidLabel extends LavaError
*
* @type {function}
*/
export class ElementIdNotFound extends LavaError
export class ElementIdNotFound extends LavaJsError
{
constructor (elemId) {
super(`[lava.js] DOM node where id="${elemId}" was not found.`);
Loading
Loading
/* jshint browser:true */
/* globals google:true */
/**
* lava.js module
*
Loading
Loading
@@ -14,9 +13,8 @@ import EventEmitter from 'events';
import Chart from './Chart';
import Dashboard from './Dashboard';
import defaultOptions from './Options';
import { noop, addEvent } from './Utils';
import { InvalidCallback, RenderableNotFound } from './Errors'
import {addEvent, noop} from './Utils';
import {InvalidCallback, RenderableNotFound} from './Errors'
 
/**
* @property {string} VERSION
Loading
Loading
@@ -190,7 +188,7 @@ export default class LavaJs extends EventEmitter
this.visualization = google.visualization;
 
_forIn(this._renderables, renderable => {
console.log(`[lava.js] Rendering ${renderable.uuid()}`);
console.log(`[lava.js] Rendering ${renderable.uuid}`);
 
renderable.render();
});
Loading
Loading
@@ -209,7 +207,7 @@ export default class LavaJs extends EventEmitter
* @param {Renderable} renderable
*/
store(renderable) {
console.log(`[lava.js] Storing ${renderable.uuid()}`);
console.log(`[lava.js] Storing ${renderable.uuid}`);
 
this._renderables[renderable.label] = renderable;
}
Loading
Loading
@@ -344,7 +342,7 @@ export default class LavaJs extends EventEmitter
}
 
for (let renderable of this._renderables) {
console.log(`[lava.js] Redrawing ${renderable.uuid()}`);
console.log(`[lava.js] Redrawing ${renderable.uuid}`);
 
let redraw = renderable.draw.bind(renderable);
 
Loading
Loading
Loading
Loading
@@ -18,8 +18,9 @@
* @property {Function} uuid - Creates identification string for the chart.
* @property {Object} _errors - Collection of errors to be thrown.
*/
import { getType } from "./Utils"
import { ElementIdNotFound } from "./Errors";
import {getType} from "./Utils"
import {ElementIdNotFound} from "./Errors";
import VisualizationProps from './VisualizationProps';
 
/**
* Chart module
Loading
Loading
@@ -43,6 +44,7 @@ export default class Renderable
*/
constructor(json) {
this.gchart = null;
this.type = json.type;
this.label = json.label;
this.options = json.options;
this.elementId = json.elementId;
Loading
Loading
@@ -52,6 +54,18 @@ export default class Renderable
if (! this.element) {
throw new ElementIdNotFound(this.elementId);
}
this._vizProps = new VisualizationProps(this.type);
}
/**
* The google.visualization class needed for rendering.
*
* @return {string}
*/
get class()
{
return this._vizProps.class
}
 
/**
Loading
Loading
@@ -59,7 +73,7 @@ export default class Renderable
*
* @return {string}
*/
uuid() {
get uuid() {
return this.type+'::'+this.label;
}
 
Loading
Loading
/* jshint undef: true, unused: true */
/* globals document */
 
/**
Loading
Loading
@@ -65,25 +64,3 @@ export function addEvent(target, type, callback, eventReturn)
target["on" + type] = callback;
}
}
/**
* Get a function a by its' namespaced string name with context.
*
* Credit to Jason Bunting
*
* @link https://stackoverflow.com/users/1790/jason-bunting
* @link https://stackoverflow.com/a/359910
* @param {string} functionName
* @param {object} context
* @private
*/
export function stringToFunction(functionName, context) {
let namespaces = functionName.split('.');
let func = namespaces.pop();
for (let i = 0; i < namespaces.length; i++) {
context = context[namespaces[i]];
}
return context[func];
}
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