-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8e31bc3
commit c1a6c87
Showing
3 changed files
with
150 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,92 +1,91 @@ | ||
/** | ||
All credit to ahmadsoe for this excellent emblem-highcharts addon | ||
This is a direct fork of his work, just expanded and cleaned up for more universal use in ember-cli apps | ||
https://github.com/ahmadsoe/ember-highcharts | ||
All credit to ahmadsoe for this excellent emblem-highcharts addon | ||
This is a direct fork of his work, just expanded and cleaned up for more universal use in ember-cli apps | ||
https://github.com/ahmadsoe/ember-highcharts | ||
**/ | ||
|
||
import Ember from 'ember'; | ||
import { setDefaultHighChartOptions } from '../utils/option-loader'; | ||
|
||
const { | ||
computed, | ||
get, | ||
set, | ||
merge, | ||
on, | ||
observer, | ||
run | ||
computed, | ||
get, | ||
set, | ||
merge, | ||
on, | ||
observer, | ||
run | ||
} = Ember; | ||
|
||
export default Ember.Component.extend({ | ||
classNames: ['highcharts-wrapper'], | ||
content: undefined, | ||
mode: undefined, | ||
chartOptions: undefined, | ||
chart: null, | ||
theme: undefined, | ||
callback: undefined, | ||
|
||
buildOptions: computed('chartOptions', '[email protected]', function() { | ||
let chartOptions = Ember.$.extend(true, {}, get(this, 'theme'), get(this, 'chartOptions')); | ||
let chartContent = get(this, 'content.length') ? get(this, 'content') : [{ | ||
id : 'noData', | ||
data : 0, | ||
color : '#aaaaaa' | ||
}]; | ||
|
||
let defaults = { series: chartContent }; | ||
|
||
return merge(defaults, chartOptions); | ||
}), | ||
|
||
contentDidChange: observer('[email protected]', function() { | ||
if (!(get(this, 'content') && get(this, 'chart'))) { | ||
return; | ||
} | ||
|
||
let chart = get(this, 'chart'); | ||
let noData = chart.get('noData'); | ||
|
||
if (noData != null) { | ||
noData.remove(); | ||
} | ||
|
||
return get(this, 'content').forEach((series, idx) => { | ||
if (chart.series[idx]) { | ||
return chart.series[idx].setData(series.data); | ||
} else { | ||
return chart.addSeries(series); | ||
} | ||
}); | ||
}), | ||
|
||
drawAfterRender() { | ||
run.scheduleOnce('afterRender', this, 'draw'); | ||
}, | ||
|
||
draw() { | ||
let completeChartOptions = [ get(this, 'buildOptions'), get(this, 'callback') ]; | ||
let mode = get(this, 'mode'); | ||
|
||
if (typeof mode === 'string' && !!mode) { | ||
completeChartOptions.unshift(mode); | ||
} | ||
|
||
let $element = this.$(); | ||
window.console.log(completeChartOptions); | ||
let chart = $element.highcharts.apply($element, completeChartOptions).highcharts(); | ||
|
||
set(this, 'chart', chart); | ||
}, | ||
|
||
_renderChart: on('didInsertElement', function() { | ||
this.drawAfterRender(); | ||
setDefaultHighChartOptions(this.container); | ||
}), | ||
|
||
_destroyChart: on('willDestroyElement', function() { | ||
this._super(); | ||
get(this, 'chart').destroy(); | ||
}) | ||
classNames: ['highcharts-wrapper'], | ||
content: undefined, | ||
mode: undefined, | ||
chartOptions: undefined, | ||
chart: null, | ||
theme: undefined, | ||
callback: undefined, | ||
|
||
buildOptions: computed('chartOptions', '[email protected]', function() { | ||
let chartOptions = Ember.$.extend(true, {}, get(this, 'theme'), get(this, 'chartOptions')); | ||
let chartContent = get(this, 'content.length') ? get(this, 'content') : [{ | ||
id : 'noData', | ||
data : 0, | ||
color : '#aaaaaa' | ||
}]; | ||
|
||
let defaults = { series: chartContent }; | ||
|
||
return merge(defaults, chartOptions); | ||
}), | ||
|
||
contentDidChange: observer('[email protected]', function() { | ||
if (!(get(this, 'content') && get(this, 'chart'))) { | ||
return; | ||
} | ||
|
||
let chart = get(this, 'chart'); | ||
let noData = chart.get('noData'); | ||
|
||
if (noData != null) { | ||
noData.remove(); | ||
} | ||
|
||
return get(this, 'content').forEach((series, idx) => { | ||
if (chart.series[idx]) { | ||
return chart.series[idx].setData(series.data); | ||
} else { | ||
return chart.addSeries(series); | ||
} | ||
}); | ||
}), | ||
|
||
drawAfterRender() { | ||
run.scheduleOnce('afterRender', this, 'draw'); | ||
}, | ||
|
||
draw() { | ||
let completeChartOptions = [ get(this, 'buildOptions'), get(this, 'callback') ]; | ||
let mode = get(this, 'mode'); | ||
|
||
if (typeof mode === 'string' && !!mode) { | ||
completeChartOptions.unshift(mode); | ||
} | ||
|
||
let $element = this.$(); | ||
let chart = $element.highcharts.apply($element, completeChartOptions).highcharts(); | ||
|
||
set(this, 'chart', chart); | ||
}, | ||
|
||
_renderChart: on('didInsertElement', function() { | ||
this.drawAfterRender(); | ||
setDefaultHighChartOptions(this.container); | ||
}), | ||
|
||
_destroyChart: on('willDestroyElement', function() { | ||
this._super(); | ||
get(this, 'chart').destroy(); | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,18 @@ | ||
'use strict'; | ||
|
||
/* | ||
This blueprint is run automatically via ember install:addon ember-cli-highcharts | ||
Runs afterInstall hook to addBowerPackage dependency to our project for highcharts-release | ||
Reference: http://johnotander.com/ember/2014/12/14/creating-an-emberjs-addon-with-the-ember-cli/ | ||
This blueprint is run automatically via ember install:addon ember-cli-highcharts | ||
Runs afterInstall hook to addBowerPackage dependency to our project for highcharts-release | ||
Reference: http://johnotander.com/ember/2014/12/14/creating-an-emberjs-addon-with-the-ember-cli/ | ||
*/ | ||
module.exports = { | ||
normalizeEntityName: function() { | ||
//tbh, not sure why I need this, but it's here | ||
}, | ||
normalizeEntityName: function() { | ||
//tbh, not sure why I need this, but it's here | ||
}, | ||
|
||
afterInstall: function(options) { | ||
//add Bower Package for highcharts-release | ||
//@todo: highstock, highmaps? | ||
return this.addBowerPackageToProject('highcharts-release'); | ||
} | ||
afterInstall: function(options) { | ||
//add Bower Package for highcharts-release | ||
return this.addBowerPackageToProject('highcharts-release'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,66 @@ | ||
/* jshin t node: true */ | ||
/* jshin t node: true */ | ||
'use strict'; | ||
|
||
var path = require('path'); | ||
|
||
module.exports = { | ||
name: 'ember-cli-highcharts', | ||
blueprintsPath: function() { | ||
return path.join(__dirname, 'blueprints'); | ||
}, | ||
name: 'ember-cli-highcharts', | ||
blueprintsPath: function() { | ||
return path.join(__dirname, 'blueprints'); | ||
}, | ||
|
||
included: function(app) { | ||
this._super.included(app); | ||
var _highcharts = app.options.highcharts || { | ||
include: true, | ||
modules: { | ||
/* //Don't need to specify these defaults since they are false | ||
'broken-axis': false, | ||
'data': false, | ||
'canvas-tools': false, | ||
'drilldown': false, | ||
'exporting': false, | ||
'funnel': false, | ||
'heatmap': false, | ||
'no-data-to-display': false, | ||
'solid-gauge': false, | ||
'treemap': false | ||
*/ | ||
}, | ||
adapters: { | ||
/* //Don't need to specify false defaults | ||
'standalone-framework': false | ||
*/ | ||
} | ||
}; | ||
//highcharts + modules | ||
if(_highcharts.include) { | ||
this.app.import(app.bowerDirectory + '/highcharts-release/highcharts.js'); | ||
if(_highcharts.modules) { | ||
for(var module in _highcharts.modules) { | ||
var includeModule = _highcharts.modules[module]; | ||
if(includeModule) { | ||
this.app.import(app.bowerDirectory + '/highcharts-release/modules/' + module + '.js'); | ||
} | ||
} | ||
} | ||
if(_highcharts.adapters) { | ||
for(var adapter in _highcharts.adapter) { | ||
var includeAdapter = _highcharts.adapters[adapter]; | ||
if(includeAdapter) { | ||
this.app.import(app.bowerDirectory + '/highcharts-release/adapters/' + adapter + '.js'); | ||
} | ||
} | ||
} | ||
} | ||
//include shim | ||
this.app.import('vendor/ember-cli-highcharts/shim.js', { | ||
type: 'vendor', | ||
exports: { 'highcharts': ['default'] } | ||
}); | ||
} | ||
included: function(app) { | ||
this._super.included(app); | ||
var _highcharts = app.options.highcharts || { | ||
include: true, | ||
modules: { | ||
/* //Don't need to specify these defaults since they are false | ||
'broken-axis': false, | ||
'data': false, | ||
'canvas-tools': false, | ||
'drilldown': false, | ||
'exporting': false, | ||
'funnel': false, | ||
'heatmap': false, | ||
'no-data-to-display': false, | ||
'solid-gauge': false, | ||
'treemap': false | ||
*/ | ||
}, | ||
adapters: { | ||
/* //Don't need to specify false defaults | ||
'standalone-framework': false | ||
*/ | ||
} | ||
}; | ||
|
||
//highcharts + modules | ||
if(_highcharts.include) { | ||
this.app.import(app.bowerDirectory + '/highcharts-release/highcharts.js'); | ||
if(_highcharts.modules) { | ||
for(var module in _highcharts.modules) { | ||
var includeModule = _highcharts.modules[module]; | ||
if(includeModule) { | ||
this.app.import(app.bowerDirectory + '/highcharts-release/modules/' + module + '.js'); | ||
} | ||
} | ||
} | ||
if(_highcharts.adapters) { | ||
for(var adapter in _highcharts.adapter) { | ||
var includeAdapter = _highcharts.adapters[adapter]; | ||
if(includeAdapter) { | ||
this.app.import(app.bowerDirectory + '/highcharts-release/adapters/' + adapter + '.js'); | ||
} | ||
} | ||
} | ||
} | ||
//include shim | ||
this.app.import('vendor/ember-cli-highcharts/shim.js', { | ||
type: 'vendor', | ||
exports: { 'highcharts': ['default'] } | ||
}); | ||
} | ||
}; |