Forked from 0000marcell/components.pie-chart.js
Last active
January 24, 2018 08:47
-
-
Save abueloshika/f0451e839bf78f0fa5486f06caf56649 to your computer and use it in GitHub Desktop.
New Twiddle
This file contains hidden or 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
import Ember from 'ember'; | |
import Component from 'ember-component'; | |
import {arc, pie} from 'd3-shape'; | |
import { select } from 'd3-selection'; | |
import { scaleOrdinal, schemeCategory10 } from 'd3-scale'; | |
export default Component.extend({ | |
didInsertElement() { | |
this.pieChart(); | |
}, | |
pieChart() { | |
let margin = {top: 20, right: 100, bottom: 30, left: 40}, | |
svgWidth = window.innerWidth - (window.innerWidth/4), | |
width = window.innerWidth - (window.innerWidth/4), | |
height = (Math.min(width) / 2) + 100, | |
donutwidth = 75, | |
radius = Math.min(width, height) / 2, | |
marc = arc().outerRadius(radius - 10).innerRadius(10), | |
labelArc = arc().outerRadius(radius - 40) | |
.innerRadius(radius - 40), | |
color = scaleOrdinal(schemeCategory10), | |
data = [ | |
{ label: 'Abulia', count: 10 }, | |
{ label: 'Betelgeuse', count: 20 }, | |
{ label: 'Cantaloupe', count: 30 }, | |
{ label: 'Dijkstra', count: 40 } | |
], | |
mpie = pie().padAngle(0.01) | |
.value((d) => { return d.count; })(data), | |
svg = select(this.$('svg')[0]) | |
.attr("width", width) | |
.attr("height", height) | |
.append("g") | |
.attr("transform", "translate(" + width/2 + ", " + | |
height/2 + ")"); | |
let g = svg.selectAll("arc") | |
.data(mpie) | |
.enter().append("g") | |
.attr("class", "arc"); | |
g.append("path") | |
.attr("d", marc) | |
.style("fill", (d, i) => { return color(i); }) | |
.each((d) => { this.set('chartContext', d); }); | |
//Labels | |
g.append("text") | |
.attr("transform", (d) => { return "translate(" + | |
labelArc.centroid(d) + ")"; }) | |
.text((d) => { return d.data.label; }) | |
.attr("text-anchor", "middle") | |
.style("fill", "#FFF") | |
.each((d) => { this.set('chartContextLable', d); }); | |
}, | |
}); |
This file contains hidden or 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
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
}); |
This file contains hidden or 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
{ | |
"version": "0.13.0", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "2.16.2", | |
"ember-template-compiler": "2.16.2", | |
"ember-testing": "2.16.2" | |
}, | |
"addons": { | |
"ember-data": "2.16.3", | |
"ember-d3": "0.3.4" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment