Skip to content

Commit

Permalink
Feature/merge options #5 (#6)
Browse files Browse the repository at this point in the history
* ➕ Add dependency lodash

* ✨ Add helper function to merge chartOptions

* Change Charts to merge options

* And renamed options data to defaultOptions
  • Loading branch information
apertureless authored Aug 21, 2016
1 parent df7b6ec commit 5258ab1
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 28 deletions.
21 changes: 11 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,16 @@
"babel-plugin-transform-runtime": "^6.0.0",
"babel-preset-es2015": "^6.0.0",
"babel-preset-stage-2": "^6.0.0",
"chai": "^3.5.0",
"chromedriver": "^2.21.2",
"connect-history-api-fallback": "^1.1.0",
"cross-spawn": "^2.1.5",
"css-loader": "^0.23.0",
"eslint": "^2.10.2",
"eslint-config-standard": "^5.1.0",
"eslint-friendly-formatter": "^2.0.5",
"eslint-loader": "^1.3.0",
"eslint-plugin-html": "^1.3.0",
"eslint-config-standard": "^5.1.0",
"eslint-plugin-promise": "^1.0.8",
"eslint-plugin-standard": "^1.3.2",
"eventsource-polyfill": "^0.9.6",
Expand All @@ -50,6 +53,8 @@
"function-bind": "^1.0.2",
"html-webpack-plugin": "^2.8.1",
"http-proxy-middleware": "^0.12.0",
"inject-loader": "^2.0.1",
"isparta-loader": "^2.0.0",
"json-loader": "^0.5.4",
"karma": "^0.13.15",
"karma-coverage": "^0.5.5",
Expand All @@ -59,20 +64,16 @@
"karma-sourcemap-loader": "^0.3.7",
"karma-spec-reporter": "0.0.24",
"karma-webpack": "^1.7.0",
"lodash": "^4.15.0",
"lolex": "^1.4.0",
"mocha": "^2.4.5",
"chai": "^3.5.0",
"sinon": "^1.17.3",
"sinon-chai": "^2.8.0",
"inject-loader": "^2.0.1",
"isparta-loader": "^2.0.0",
"phantomjs-prebuilt": "^2.1.3",
"chromedriver": "^2.21.2",
"cross-spawn": "^2.1.5",
"nightwatch": "^0.8.18",
"selenium-server": "2.53.0",
"ora": "^0.2.0",
"phantomjs-prebuilt": "^2.1.3",
"selenium-server": "2.53.0",
"shelljs": "^0.6.0",
"sinon": "^1.17.3",
"sinon-chai": "^2.8.0",
"url-loader": "^0.5.7",
"vue-hot-reload-api": "^1.2.0",
"vue-html-loader": "^1.0.0",
Expand Down
9 changes: 6 additions & 3 deletions src/BaseCharts/Bar.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Vue from 'vue'
import Chart from 'chart.js'
import { mergeOptions } from '../helpers/options'

export default Vue.extend({
template: `
Expand All @@ -21,7 +22,7 @@ export default Vue.extend({

data () {
return {
options: {
defaultOptions: {
scales: {
yAxes: [{
ticks: {
Expand All @@ -44,12 +45,14 @@ export default Vue.extend({
},

methods: {
render (data, options = this.options) {
render (data, options) {
let chartOptions = mergeOptions(this.defaultOptions, options)

this._chart = new Chart(
this.$els.canvas.getContext('2d'), {
type: 'bar',
data: data,
options: options
options: chartOptions
}
)
this._chart.generateLegend()
Expand Down
9 changes: 6 additions & 3 deletions src/BaseCharts/Doughnut.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Vue from 'vue'
import Chart from 'chart.js'
import { mergeOptions } from '../helpers/options'

export default Vue.extend({
template: `
Expand All @@ -21,18 +22,20 @@ export default Vue.extend({

data () {
return {
options: {
defaultOptions: {
}
}
},

methods: {
render (data, options = this.options) {
render (data, options) {
let chartOptions = mergeOptions(this.defaultOptions, options)

this._chart = new Chart(
this.$els.canvas.getContext('2d'), {
type: 'doughnut',
data: data,
options: options
options: chartOptions
}
)
this._chart.generateLegend()
Expand Down
9 changes: 6 additions & 3 deletions src/BaseCharts/Line.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Vue from 'vue'
import Chart from 'chart.js'
import { mergeOptions } from '../helpers/options'

export default Vue.extend({
template: `
Expand All @@ -21,7 +22,7 @@ export default Vue.extend({

data () {
return {
options: {
defaultOptions: {
scales: {
yAxes: [{
ticks: {
Expand All @@ -42,12 +43,14 @@ export default Vue.extend({
},

methods: {
render (data, options = this.options) {
render (data, options) {
let chartOptions = mergeOptions(this.defaultOptions, options)

this._chart = new Chart(
this.$els.canvas.getContext('2d'), {
type: 'line',
data: data,
options: options
options: chartOptions
}
)
this._chart.generateLegend()
Expand Down
9 changes: 6 additions & 3 deletions src/BaseCharts/Pie.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Vue from 'vue'
import Chart from 'chart.js'
import { mergeOptions } from '../helpers/options'

export default Vue.extend({
template: `
Expand All @@ -21,18 +22,20 @@ export default Vue.extend({

data () {
return {
options: {
defaultOptions: {
}
}
},

methods: {
render (data, options = this.options) {
render (data, options) {
let chartOptions = mergeOptions(this.defaultOptions, options)

this._chart = new Chart(
this.$els.canvas.getContext('2d'), {
type: 'pie',
data: data,
options: options
options: chartOptions
}
)
this._chart.generateLegend()
Expand Down
9 changes: 6 additions & 3 deletions src/BaseCharts/PolarArea.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Vue from 'vue'
import Chart from 'chart.js'
import { mergeOptions } from '../helpers/options'

export default Vue.extend({
template: `
Expand All @@ -21,18 +22,20 @@ export default Vue.extend({

data () {
return {
options: {
defaultOptions: {
}
}
},

methods: {
render (data, options = this.options) {
render (data, options) {
let chartOptions = mergeOptions(this.defaultOptions, options)

this._chart = new Chart(
this.$els.canvas.getContext('2d'), {
type: 'polarArea',
data: data,
options: options
options: chartOptions
}
)
this._chart.generateLegend()
Expand Down
9 changes: 6 additions & 3 deletions src/BaseCharts/Radar.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Vue from 'vue'
import Chart from 'chart.js'
import { mergeOptions } from '../helpers/options'

export default Vue.extend({
template: `
Expand All @@ -21,18 +22,20 @@ export default Vue.extend({

data () {
return {
options: {
defaultOptions: {
}
}
},

methods: {
render (data, options = this.options) {
render (data, options) {
let chartOptions = mergeOptions(this.defaultOptions, options)

this._chart = new Chart(
this.$els.canvas.getContext('2d'), {
type: 'radar',
data: data,
options: options
options: chartOptions
}
)
this._chart.generateLegend()
Expand Down
5 changes: 5 additions & 0 deletions src/helpers/options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import merge from 'lodash/fp/merge'

export function mergeOptions (obj, src) {
return merge(obj, src)
}

0 comments on commit 5258ab1

Please sign in to comment.