-
-
Notifications
You must be signed in to change notification settings - Fork 836
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from apertureless/feature/reactive_chart_data
WIP Feature/reactive chart data #11
- Loading branch information
Showing
12 changed files
with
224 additions
and
16 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
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
codecov: | ||
branch: master | ||
|
||
coverage: | ||
precision: 2 | ||
round: down | ||
range: "70...100" | ||
|
||
status: | ||
project: | ||
default: | ||
target: auto | ||
threshold: null | ||
branches: null | ||
|
||
patch: | ||
default: | ||
target: auto | ||
branches: null | ||
|
||
changes: | ||
default: | ||
branches: null | ||
|
||
ignore: | ||
- "tests/*" | ||
- "src/examples/*" | ||
- "src/mixins/*" | ||
|
||
|
||
comment: | ||
layout: "header, diff, changes, sunburst, uncovered, tree" | ||
branches: null | ||
behavior: default |
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
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
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import BarChart from '../BaseCharts/Bar' | ||
import reactiveData from '../mixins/reactiveData' | ||
|
||
export default BarChart.extend({ | ||
mixins: [reactiveData], | ||
data () { | ||
return { | ||
chartData: '' | ||
} | ||
}, | ||
created () { | ||
this.fillData() | ||
}, | ||
|
||
mounted () { | ||
this.renderChart(this.chartData) | ||
|
||
setInterval(() => { | ||
this.fillData() | ||
}, 5000) | ||
}, | ||
|
||
methods: { | ||
fillData () { | ||
this.chartData = { | ||
labels: ['January' + this.getRandomInt(), 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'], | ||
datasets: [ | ||
{ | ||
label: 'Data One', | ||
backgroundColor: '#f87979', | ||
data: [this.getRandomInt(), this.getRandomInt(), this.getRandomInt(), this.getRandomInt(), this.getRandomInt(), this.getRandomInt(), this.getRandomInt(), this.getRandomInt(), this.getRandomInt(), this.getRandomInt(), this.getRandomInt(), this.getRandomInt()] | ||
} | ||
] | ||
} | ||
}, | ||
|
||
getRandomInt () { | ||
return Math.floor(Math.random() * (50 - 5 + 1)) + 5 | ||
} | ||
} | ||
}) |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import BarChart from '../BaseCharts/Bar' | ||
import reactiveData from '../mixins/reactiveProp' | ||
|
||
export default BarChart.extend({ | ||
mixins: [reactiveData], | ||
|
||
mounted () { | ||
this.renderChart(this.chartData) | ||
} | ||
}) |
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
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
module.exports = { | ||
data () { | ||
return { | ||
chartData: null | ||
} | ||
}, | ||
watch: { | ||
'chartData': { | ||
handler (newData, oldData) { | ||
if (oldData) { | ||
let chart = this._chart | ||
|
||
let newDataLabels = newData.datasets.map((dataset) => { | ||
return dataset.label | ||
}) | ||
|
||
let oldDataLabels = oldData.datasets.map((dataset) => { | ||
return dataset.label | ||
}) | ||
|
||
if (JSON.stringify(newDataLabels) === JSON.stringify(oldDataLabels)) { | ||
this.forceUpdate(newData, chart) | ||
} else { | ||
this.forceRender() | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
methods: { | ||
forceUpdate (newData, chart) { | ||
newData.datasets.forEach((dataset, i) => { | ||
chart.data.datasets[i].data = dataset.data | ||
}) | ||
|
||
chart.data.labels = newData.labels | ||
chart.update() | ||
}, | ||
|
||
forceRender () { | ||
this.renderChart(this.chartData, this.options) | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module.exports = { | ||
props: { | ||
chartData: { | ||
required: true | ||
} | ||
}, | ||
|
||
watch: { | ||
'chartData': { | ||
handler (newData, oldData) { | ||
if (oldData) { | ||
let chart = this._chart | ||
|
||
let newDataLabels = newData.datasets.map((dataset) => { | ||
return dataset.label | ||
}) | ||
|
||
let oldDataLabels = oldData.datasets.map((dataset) => { | ||
return dataset.label | ||
}) | ||
|
||
if (JSON.stringify(newDataLabels) === JSON.stringify(oldDataLabels)) { | ||
newData.datasets.forEach((dataset, i) => { | ||
chart.data.datasets[i].data = dataset.data | ||
}) | ||
chart.data.labels = newData.labels | ||
chart.update() | ||
} else { | ||
this.renderChart(this.chartData, this.options) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
}, | ||
"globals": { | ||
"expect": true, | ||
"jasmine": true, | ||
"sinon": true | ||
} | ||
} |
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
Empty file.