Add doughnut chart for contribution composition #77

Merged
raucao merged 4 commits from feature/charts into master 2018-07-17 18:45:33 +00:00
4 changed files with 71 additions and 16 deletions
Showing only changes of commit 2befc91d90 - Show all commits
@@ -1,17 +1,58 @@
import Component from '@ember/component';
import { computed } from '@ember/object';
let categoryColors = {
community: "#fb6868",
design: "#fbe468",
dev: "#e068fb",
docs: "#97fb68",
ops: "#8f68fb",
}
export default Component.extend({
chartData: {
datasets: [{
data: [10, 20, 30]
}],
labels: [
'Red',
'Yellow',
'Blue'
]
},
contributions: null,
chartData: computed('contributions', function() {
let kredits = this.get('contributions')
.map(c => {
return { kind: c.kind, amount: c.amount }
}).reduce(function (kinds, c) {
if (c.kind in kinds) {
kinds[c.kind] = kinds[c.kind] + c.amount
} else {
kinds[c.kind] = c.amount;
}
galfert commented 2018-07-16 15:02:47 +00:00 (Migrated from github.com)
Review

I think the if/else block can be simplified to kinds[c.kind] = (kinds[c.kind] || 0) + c.amount;.

I think the `if/else` block can be simplified to `kinds[c.kind] = (kinds[c.kind] || 0) + c.amount;`.
raucao commented 2018-07-16 15:12:53 +00:00 (Migrated from github.com)
Review

Ooh, that's a good idea!

Ooh, that's a good idea!
return kinds;
}, {});
return {
datasets: [{
data: [
kredits['community'],
kredits['design'],
kredits['dev'],
kredits['ops'],
kredits['docs'],
],
borderColor: [
categoryColors.community,
categoryColors.design,
categoryColors.dev,
categoryColors.ops,
categoryColors.docs,
],
borderWidth: 1
}],
labels: [
'Community',
'Design',
'Development',
'Operations & Infrastructure',
'Documentation'
],
}
}),
chartOptions: {
legend: {
@@ -1,5 +1,7 @@
{{ember-chart type='doughnut'
data=chartData
options=chartOptions
width=200
height=200}}
<div class="chart">
{{ember-chart type='doughnut'
data=chartData
options=chartOptions
width=200
height=200}}
</div>
+12
View File
@@ -62,6 +62,18 @@ section {
}
}
&#contributions-by-type {
.chart {
width: 50%;
margin-left: auto;
margin-right: auto;
}
@include media($mobile) {
width: 90%;
}
}
&#proposals-open, &#proposals-closed {
.actions {
padding-top: 3rem;
+1 -1
View File
@@ -20,7 +20,7 @@
<h2>Contributions by type</h2>
</header>
<div class="content">
{{chart-contributions-by-type contributions=proposalsClosed}}
{{chart-contributions-by-type contributions=proposals}}
</div>
</section>
</div>