Skip to content

Instantly share code, notes, and snippets.

@0000marcell
Last active September 2, 2019 14:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save 0000marcell/a658207aa8800816329f95b4e1b4860f to your computer and use it in GitHub Desktop.
Save 0000marcell/a658207aa8800816329f95b4e1b4860f to your computer and use it in GitHub Desktop.
New Twiddle
import Ember from 'ember';
import Component from 'ember-component';
import {arc, pie} from 'd3-shape';
import { select } from 'd3-selection';
import { scaleOrdinal } from 'd3-scale';
export default Component.extend({
didInsertElement() {
this.pieChart();
},
pieChart() {
let width = 500,
height = 500,
radius = Math.min(width, height) / 2,
marc = arc().outerRadius(radius - 10).innerRadius(0),
labelArc = arc().outerRadius(radius - 40)
.innerRadius(radius - 40),
color = scaleOrdinal().range(['#A60F2B', '#648C85',
'#B3F2C9', '#528C18', '#C3F25C']),
data = [
{ label: 'Abulia', count: 10 },
{ label: 'Betelgeuse', count: 20 },
{ label: 'Cantaloupe', count: 30 },
{ label: 'Dijkstra', count: 40 }
],
mpie = pie()
.value((d) => { return d.count; })(data),
svg = select("#pie-chart")
.append("svg")
.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); })
.style("stroke", "#222")
.each((d) => { this.set('chartContext', d); });
//Labels
g.append("text")
.attr("transform", (d) => { return "translate(" +
labelArc.centroid(d) + ")"; })
.text((d) => { return d.data.color; })
.attr("text-anchor", "middle")
.style("fill", "#FFF")
.each((d) => { this.set('chartContextLable', d); });
},
});
import Ember from 'ember';
export default Ember.Controller.extend({
});
<br>
<br>
{{pie-chart}}
<br>
<br>
{
"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