diff --git a/app/components/chart-contributions-by-type/component.js b/app/components/chart-contributions-by-type/component.js index b78af88..ea3eed0 100644 --- a/app/components/chart-contributions-by-type/component.js +++ b/app/components/chart-contributions-by-type/component.js @@ -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; + } + 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: { diff --git a/app/components/chart-contributions-by-type/template.hbs b/app/components/chart-contributions-by-type/template.hbs index 1807721..9157ff7 100644 --- a/app/components/chart-contributions-by-type/template.hbs +++ b/app/components/chart-contributions-by-type/template.hbs @@ -1,5 +1,7 @@ -{{ember-chart type='doughnut' - data=chartData - options=chartOptions - width=200 - height=200}} \ No newline at end of file +
+ {{ember-chart type='doughnut' + data=chartData + options=chartOptions + width=200 + height=200}} +
\ No newline at end of file diff --git a/app/styles/app.scss b/app/styles/app.scss index 7d5bef5..26e101e 100644 --- a/app/styles/app.scss +++ b/app/styles/app.scss @@ -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; diff --git a/app/templates/index.hbs b/app/templates/index.hbs index 6d7177c..f39e9f2 100644 --- a/app/templates/index.hbs +++ b/app/templates/index.hbs @@ -20,7 +20,7 @@

Contributions by type

- {{chart-contributions-by-type contributions=proposalsClosed}} + {{chart-contributions-by-type contributions=proposals}}