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

[ci skip] Chart JSON object no longer needs to define the class property. It...

[ci skip] Chart JSON object no longer needs to define the class property. It will be mapped from the chart type
parent 95ffef59
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
@@ -36,8 +36,6 @@ function rebundle(prod = false) {
} else {
log(red('Error'), err.message);
}
this.emit('end');
})
.pipe(source('lava.js'))
.pipe(gulpif(prod, streamify(uglify())))
Loading
Loading
Loading
Loading
@@ -8,7 +8,8 @@
* @license MIT
*/
import _forIn from 'lodash/forIn';
import { Renderable } from './Renderable';
import Renderable from './Renderable';
import VisualizationProps from './VisualizationProps';
import { stringToFunction } from './Utils';
 
/**
Loading
Loading
@@ -43,21 +44,22 @@ export default class Chart extends Renderable
super(json);
 
this.type = json.type;
this.class = json.class;
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);
 
let ChartClass = stringToFunction(this.class, window);
console.log(this.vizProps.class);
 
this.gchart = new ChartClass(this.element);
this.gchart = new google.visualization[this.vizProps.class](this.element);
 
if (this.formats) {
this.applyFormats();
Loading
Loading
@@ -65,10 +67,6 @@ export default class Chart extends Renderable
 
if (this.events) {
this._attachEvents();
// TODO: Idea... forward events to be listenable by the user, instead of having the user define them as a string callback.
// lava.get('MyCoolChart').on('ready', function(data) {
// console.log(this); // gChart
// });
}
 
this.draw();
Loading
Loading
@@ -79,6 +77,15 @@ 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
Loading
Loading
@@ -7,7 +7,7 @@
* @copyright (c) 2017, KHill Designs
* @license MIT
*/
import { Renderable } from './Renderable';
import Renderable from './Renderable';
 
/**
* Dashboard class
Loading
Loading
Loading
Loading
@@ -173,33 +173,22 @@ export default class LavaJs extends EventEmitter
this.store(this.createDashboard(json));
}
 
/**
* Public method for initializing google on the page.
*
* @public
*/
init() {
return this._loadGoogle().then(() => {
this.visualization = google.visualization;
});
}
/**
* Runs the Lava.js module
*
* @public
*/
run() {
// const $lava = this;
console.log('[lava.js] Running...');
console.log('[lava.js] Loading options:', this.options);
 
this._attachRedrawHandler();
 
this.init().then(() => {
this._loadGoogle().then(() => {
console.log('[lava.js] Google is ready.');
 
this.visualization = google.visualization;
_forIn(this._renderables, renderable => {
console.log(`[lava.js] Rendering ${renderable.uuid()}`);
 
Loading
Loading
Loading
Loading
@@ -30,7 +30,7 @@ import { ElementIdNotFound } from "./Errors";
* @copyright (c) 2017, KHill Designs
* @license MIT
*/
export class Renderable
export default class Renderable
{
/**
* Chart Class
Loading
Loading
@@ -81,7 +81,7 @@ export class Renderable
* @param {object} payload Json representation of a DataTable
*/
setData(payload) {
// If the payload is from JoinedDataTable::toJson(), then create
// If the payload is from the php class JoinedDataTable->toJson(), then create
// two new DataTables and join them with the defined options.
if (getType(payload.data) === 'Array') {
this.data = google.visualization.data.join(
Loading
Loading
@@ -104,12 +104,20 @@ export class Renderable
return;
}
 
// If a DataTable#toJson() payload is received, with formatted columns,
// If an Array is received, then attempt to use parse with arrayToDataTable.
if (getType(payload) === 'Array') {
this.data = google.visualization.arrayToDataTable(payload);
return;
}
// If a php DataTable->toJson() payload is received, with formatted columns,
// then payload.data will be defined, and used as the DataTable
if (getType(payload.data) === 'Object') {
payload = payload.data;
// TODO: handle formats better...
}
// TODO: handle formats better...
 
// If we reach here, then it must be standard JSON for creating a DataTable.
this.data = new google.visualization.DataTable(payload);
Loading
Loading
Loading
Loading
@@ -110,7 +110,7 @@ export default class VisualizationProps
*
* @return {string}
*/
getPackage() {
get package() {
return this.CHART_TYPE_PACKAGE_MAP[this.chartType];
}
 
Loading
Loading
@@ -119,7 +119,7 @@ export default class VisualizationProps
*
* @return {string}
*/
getClass() {
get class() {
return this.CHART_TYPE_CLASS_MAP[this.chartType];
}
 
Loading
Loading
@@ -128,7 +128,7 @@ export default class VisualizationProps
*
* @return {number}
*/
getVersion() {
get version() {
return this.CHART_TYPE_VERSION_MAP[this.chartType];
}
}
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