-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathc3Pie.enthral.js
More file actions
64 lines (60 loc) · 1.67 KB
/
c3Pie.enthral.js
File metadata and controls
64 lines (60 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
define(['enthral', 'd3/v3', 'c3', 'css!c3/styles'], function (enthral, d3, c3) {
"use strict";
var C3PieEnthral = function(config) {
var header = document.createElement('h1'),
graphContainer = document.createElement('div');
config.container.appendChild(graphContainer);
header.style.marginTop = "20px";
header.style.fontFamily = "sans-serif";
header.style.fontSize = "16px";
header.style.textAlign = "center";
header.style.fontWeight = "500";
this.render = function(props) {
// Set up the header.
header.innerText = props.title;
if (props.title && header.parentNode !== config.container) {
config.container.prepend(header);
} else if (!props.title && header.parentNode === config.container) {
config.container.remove(header);
}
// Set up the graph.
var columns = props.segments.map(function (s) {
return [s.label, s.value]
});
var chart = c3.generate({
bindto: graphContainer,
data: {
columns: columns,
type : (props.donut) ? 'donut' : 'pie'
},
pie: {
label: {
format: function (value, ratio, id) {
return d3.format(props.format)(value);
}
}
},
tooltip: {
format: {
value: d3.format(props.format)
}
},
legend: props.legend
});
}
};
C3PieEnthral.enthralPropTypes = {/*
title: PropTypes.string,
donut: PropTypes.boolean,
legend: PropTypes.shape({
position: PropTypes.oneOf(['bottom', 'right']),
show: PropTypes.boolean
}),
format: PropTypes.oneOf(['$', '%']),
segments: PropTypes.arrayOf(PropTypes.shape({
label: PropTypes.string.isRequired,
value: PropTypes.number.isRequired,
})).isRequired
*/};
return C3PieEnthral;
});