pyk 0.2.6 → 0.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/app/assets/javascripts/lib/chardinjs.min.js +2 -0
- data/app/assets/javascripts/lib/crossfilter.js +1383 -1
- data/app/assets/javascripts/lib/{d3.js → d3.v3.js} +0 -0
- data/app/assets/javascripts/lib/dc.js +3492 -757
- data/app/assets/javascripts/lib/jquery.gridster.js +2 -3621
- data/app/assets/javascripts/lib/markermanager.js +2 -980
- data/app/assets/javascripts/lib/underscore.js +1276 -0
- data/app/assets/javascripts/nvd3/lib/colorbrewer.js +302 -0
- data/app/assets/javascripts/nvd3/lib/crossfilter.js +1180 -0
- data/app/assets/javascripts/nvd3/lib/crossfilter.min.js +1 -0
- data/app/assets/javascripts/nvd3/lib/d3.v2.js +7033 -0
- data/app/assets/javascripts/nvd3/lib/d3.v2.min.js +4 -0
- data/app/assets/javascripts/nvd3/lib/d3.v3.js +8436 -0
- data/app/assets/javascripts/nvd3/lib/fisheye.js +86 -0
- data/app/assets/javascripts/nvd3/lib/hive.js +80 -0
- data/app/assets/javascripts/nvd3/lib/horizon.js +192 -0
- data/app/assets/javascripts/nvd3/lib/sankey.js +292 -0
- data/app/assets/javascripts/nvd3/nv.d3.js +14312 -0
- data/app/assets/javascripts/nvd3/nv.d3.min.js +6 -0
- data/app/assets/javascripts/nvd3/src/core.js +122 -0
- data/app/assets/javascripts/nvd3/src/interactiveLayer.js +251 -0
- data/app/assets/javascripts/nvd3/src/models/axis.js +405 -0
- data/app/assets/javascripts/nvd3/src/models/backup/bullet.js +250 -0
- data/app/assets/javascripts/nvd3/src/models/backup/bulletChart.js +349 -0
- data/app/assets/javascripts/nvd3/src/models/boilerplate.js +104 -0
- data/app/assets/javascripts/nvd3/src/models/bullet.js +385 -0
- data/app/assets/javascripts/nvd3/src/models/bulletChart.js +343 -0
- data/app/assets/javascripts/nvd3/src/models/cumulativeLineChart.js +782 -0
- data/app/assets/javascripts/nvd3/src/models/discreteBar.js +349 -0
- data/app/assets/javascripts/nvd3/src/models/discreteBarChart.js +333 -0
- data/app/assets/javascripts/nvd3/src/models/distribution.js +148 -0
- data/app/assets/javascripts/nvd3/src/models/historicalBar.js +331 -0
- data/app/assets/javascripts/nvd3/src/models/historicalBarChart.js +419 -0
- data/app/assets/javascripts/nvd3/src/models/indentedTree.js +337 -0
- data/app/assets/javascripts/nvd3/src/models/legend.js +270 -0
- data/app/assets/javascripts/nvd3/src/models/line.js +284 -0
- data/app/assets/javascripts/nvd3/src/models/lineChart.js +465 -0
- data/app/assets/javascripts/nvd3/src/models/linePlusBarChart.js +433 -0
- data/app/assets/javascripts/nvd3/src/models/linePlusBarWithFocusChart.js +658 -0
- data/app/assets/javascripts/nvd3/src/models/lineWithFisheye.js +200 -0
- data/app/assets/javascripts/nvd3/src/models/lineWithFisheyeChart.js +297 -0
- data/app/assets/javascripts/nvd3/src/models/lineWithFocusChart.js +574 -0
- data/app/assets/javascripts/nvd3/src/models/multiBar.js +461 -0
- data/app/assets/javascripts/nvd3/src/models/multiBarChart.js +524 -0
- data/app/assets/javascripts/nvd3/src/models/multiBarHorizontal.js +424 -0
- data/app/assets/javascripts/nvd3/src/models/multiBarHorizontalChart.js +434 -0
- data/app/assets/javascripts/nvd3/src/models/multiBarTimeSeries.js +384 -0
- data/app/assets/javascripts/nvd3/src/models/multiBarTimeSeriesChart.js +405 -0
- data/app/assets/javascripts/nvd3/src/models/multiChart.js +452 -0
- data/app/assets/javascripts/nvd3/src/models/ohlcBar.js +380 -0
- data/app/assets/javascripts/nvd3/src/models/parallelCoordinates.js +239 -0
- data/app/assets/javascripts/nvd3/src/models/pie.js +398 -0
- data/app/assets/javascripts/nvd3/src/models/pieChart.js +292 -0
- data/app/assets/javascripts/nvd3/src/models/scatter.js +674 -0
- data/app/assets/javascripts/nvd3/src/models/scatterChart.js +628 -0
- data/app/assets/javascripts/nvd3/src/models/scatterPlusLineChart.js +620 -0
- data/app/assets/javascripts/nvd3/src/models/sparkline.js +194 -0
- data/app/assets/javascripts/nvd3/src/models/sparklinePlus.js +295 -0
- data/app/assets/javascripts/nvd3/src/models/stackedArea.js +368 -0
- data/app/assets/javascripts/nvd3/src/models/stackedAreaChart.js +629 -0
- data/app/assets/javascripts/nvd3/src/tooltip.js +490 -0
- data/app/assets/javascripts/nvd3/src/utils.js +152 -0
- data/app/assets/javascripts/pyk.js +1 -0
- data/app/assets/stylesheets/lib/chardinjs.css +82 -0
- data/app/assets/stylesheets/nvd3/nv.d3.css +769 -0
- data/app/assets/stylesheets/pyk.css.scss +1 -0
- metadata +61 -2
@@ -0,0 +1,239 @@
|
|
1
|
+
|
2
|
+
//Code adapted from Jason Davies' "Parallel Coordinates"
|
3
|
+
// http://bl.ocks.org/jasondavies/1341281
|
4
|
+
|
5
|
+
nv.models.parallelCoordinates = function() {
|
6
|
+
"use strict";
|
7
|
+
//============================================================
|
8
|
+
// Public Variables with Default Settings
|
9
|
+
//------------------------------------------------------------
|
10
|
+
|
11
|
+
|
12
|
+
var margin = {top: 30, right: 10, bottom: 10, left: 10}
|
13
|
+
, width = 960
|
14
|
+
, height = 500
|
15
|
+
, x = d3.scale.ordinal()
|
16
|
+
, y = {}
|
17
|
+
, dimensions = []
|
18
|
+
, color = nv.utils.getColor(d3.scale.category20c().range())
|
19
|
+
, axisLabel = function(d) { return d; }
|
20
|
+
, filters = []
|
21
|
+
, active = []
|
22
|
+
, dispatch = d3.dispatch('brush')
|
23
|
+
;
|
24
|
+
|
25
|
+
//============================================================
|
26
|
+
|
27
|
+
|
28
|
+
//============================================================
|
29
|
+
// Private Variables
|
30
|
+
//------------------------------------------------------------
|
31
|
+
|
32
|
+
|
33
|
+
//============================================================
|
34
|
+
|
35
|
+
|
36
|
+
function chart(selection) {
|
37
|
+
selection.each(function(data) {
|
38
|
+
var availableWidth = width - margin.left - margin.right,
|
39
|
+
availableHeight = height - margin.top - margin.bottom,
|
40
|
+
container = d3.select(this);
|
41
|
+
|
42
|
+
active = data; //set all active before first brush call
|
43
|
+
|
44
|
+
chart.update = function() { }; //This is a placeholder until this chart is made resizeable
|
45
|
+
|
46
|
+
//------------------------------------------------------------
|
47
|
+
// Setup Scales
|
48
|
+
|
49
|
+
x
|
50
|
+
.rangePoints([0, availableWidth], 1)
|
51
|
+
.domain(dimensions);
|
52
|
+
|
53
|
+
// Extract the list of dimensions and create a scale for each.
|
54
|
+
dimensions.forEach(function(d) {
|
55
|
+
y[d] = d3.scale.linear()
|
56
|
+
.domain(d3.extent(data, function(p) { return +p[d]; }))
|
57
|
+
.range([availableHeight, 0]);
|
58
|
+
|
59
|
+
y[d].brush = d3.svg.brush().y(y[d]).on('brush', brush);
|
60
|
+
|
61
|
+
return d != 'name';
|
62
|
+
})
|
63
|
+
|
64
|
+
|
65
|
+
//------------------------------------------------------------
|
66
|
+
|
67
|
+
|
68
|
+
//------------------------------------------------------------
|
69
|
+
// Setup containers and skeleton of chart
|
70
|
+
|
71
|
+
var wrap = container.selectAll('g.nv-wrap.nv-parallelCoordinates').data([data]);
|
72
|
+
var wrapEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-parallelCoordinates');
|
73
|
+
var gEnter = wrapEnter.append('g');
|
74
|
+
var g = wrap.select('g')
|
75
|
+
|
76
|
+
gEnter.append('g').attr('class', 'nv-parallelCoordinatesWrap');
|
77
|
+
|
78
|
+
wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')');
|
79
|
+
|
80
|
+
//------------------------------------------------------------
|
81
|
+
|
82
|
+
|
83
|
+
var line = d3.svg.line(),
|
84
|
+
axis = d3.svg.axis().orient('left'),
|
85
|
+
background,
|
86
|
+
foreground;
|
87
|
+
|
88
|
+
|
89
|
+
// Add grey background lines for context.
|
90
|
+
background = gEnter.append('g')
|
91
|
+
.attr('class', 'background')
|
92
|
+
.selectAll('path')
|
93
|
+
.data(data)
|
94
|
+
.enter().append('path')
|
95
|
+
.attr('d', path)
|
96
|
+
;
|
97
|
+
|
98
|
+
// Add blue foreground lines for focus.
|
99
|
+
foreground = gEnter.append('g')
|
100
|
+
.attr('class', 'foreground')
|
101
|
+
.selectAll('path')
|
102
|
+
.data(data)
|
103
|
+
.enter().append('path')
|
104
|
+
.attr('d', path)
|
105
|
+
;
|
106
|
+
|
107
|
+
// Add a group element for each dimension.
|
108
|
+
var dimension = g.selectAll('.dimension')
|
109
|
+
.data(dimensions)
|
110
|
+
.enter().append('g')
|
111
|
+
.attr('class', 'dimension')
|
112
|
+
.attr('transform', function(d) { return 'translate(' + x(d) + ',0)'; });
|
113
|
+
|
114
|
+
// Add an axis and title.
|
115
|
+
dimension.append('g')
|
116
|
+
.attr('class', 'axis')
|
117
|
+
.each(function(d) { d3.select(this).call(axis.scale(y[d])); })
|
118
|
+
.append('text')
|
119
|
+
.attr('text-anchor', 'middle')
|
120
|
+
.attr('y', -9)
|
121
|
+
.text(String);
|
122
|
+
|
123
|
+
// Add and store a brush for each axis.
|
124
|
+
dimension.append('g')
|
125
|
+
.attr('class', 'brush')
|
126
|
+
.each(function(d) { d3.select(this).call(y[d].brush); })
|
127
|
+
.selectAll('rect')
|
128
|
+
.attr('x', -8)
|
129
|
+
.attr('width', 16);
|
130
|
+
|
131
|
+
|
132
|
+
// Returns the path for a given data point.
|
133
|
+
function path(d) {
|
134
|
+
return line(dimensions.map(function(p) { return [x(p), y[p](d[p])]; }));
|
135
|
+
}
|
136
|
+
|
137
|
+
// Handles a brush event, toggling the display of foreground lines.
|
138
|
+
function brush() {
|
139
|
+
var actives = dimensions.filter(function(p) { return !y[p].brush.empty(); }),
|
140
|
+
extents = actives.map(function(p) { return y[p].brush.extent(); });
|
141
|
+
|
142
|
+
filters = []; //erase current filters
|
143
|
+
actives.forEach(function(d,i) {
|
144
|
+
filters[i] = {
|
145
|
+
dimension: d,
|
146
|
+
extent: extents[i]
|
147
|
+
}
|
148
|
+
});
|
149
|
+
|
150
|
+
active = []; //erase current active list
|
151
|
+
foreground.style('display', function(d) {
|
152
|
+
var isActive = actives.every(function(p, i) {
|
153
|
+
return extents[i][0] <= d[p] && d[p] <= extents[i][1];
|
154
|
+
});
|
155
|
+
if (isActive) active.push(d);
|
156
|
+
return isActive ? null : 'none';
|
157
|
+
});
|
158
|
+
|
159
|
+
dispatch.brush({
|
160
|
+
filters: filters,
|
161
|
+
active: active
|
162
|
+
});
|
163
|
+
|
164
|
+
}
|
165
|
+
|
166
|
+
|
167
|
+
|
168
|
+
});
|
169
|
+
|
170
|
+
return chart;
|
171
|
+
}
|
172
|
+
|
173
|
+
|
174
|
+
//============================================================
|
175
|
+
// Expose Public Variables
|
176
|
+
//------------------------------------------------------------
|
177
|
+
|
178
|
+
|
179
|
+
chart.dispatch = dispatch;
|
180
|
+
chart.options = nv.utils.optionsFunc.bind(chart);
|
181
|
+
|
182
|
+
chart.margin = function(_) {
|
183
|
+
if (!arguments.length) return margin;
|
184
|
+
margin.top = typeof _.top != 'undefined' ? _.top : margin.top;
|
185
|
+
margin.right = typeof _.right != 'undefined' ? _.right : margin.right;
|
186
|
+
margin.bottom = typeof _.bottom != 'undefined' ? _.bottom : margin.bottom;
|
187
|
+
margin.left = typeof _.left != 'undefined' ? _.left : margin.left;
|
188
|
+
return chart;
|
189
|
+
};
|
190
|
+
|
191
|
+
chart.width = function(_) {
|
192
|
+
if (!arguments.length) return width;
|
193
|
+
width = _;
|
194
|
+
return chart;
|
195
|
+
};
|
196
|
+
|
197
|
+
chart.height = function(_) {
|
198
|
+
if (!arguments.length) return height;
|
199
|
+
height = _;
|
200
|
+
return chart;
|
201
|
+
};
|
202
|
+
|
203
|
+
chart.color = function(_) {
|
204
|
+
if (!arguments.length) return color;
|
205
|
+
color = nv.utils.getColor(_)
|
206
|
+
return chart;
|
207
|
+
};
|
208
|
+
|
209
|
+
chart.xScale = function(_) {
|
210
|
+
if (!arguments.length) return x;
|
211
|
+
x = _;
|
212
|
+
return chart;
|
213
|
+
};
|
214
|
+
|
215
|
+
chart.yScale = function(_) {
|
216
|
+
if (!arguments.length) return y;
|
217
|
+
y = _;
|
218
|
+
return chart;
|
219
|
+
};
|
220
|
+
|
221
|
+
chart.dimensions = function(_) {
|
222
|
+
if (!arguments.length) return dimensions;
|
223
|
+
dimensions = _;
|
224
|
+
return chart;
|
225
|
+
};
|
226
|
+
|
227
|
+
chart.filters = function() {
|
228
|
+
return filters;
|
229
|
+
};
|
230
|
+
|
231
|
+
chart.active = function() {
|
232
|
+
return active;
|
233
|
+
};
|
234
|
+
|
235
|
+
//============================================================
|
236
|
+
|
237
|
+
|
238
|
+
return chart;
|
239
|
+
}
|
@@ -0,0 +1,398 @@
|
|
1
|
+
nv.models.pie = function() {
|
2
|
+
"use strict";
|
3
|
+
//============================================================
|
4
|
+
// Public Variables with Default Settings
|
5
|
+
//------------------------------------------------------------
|
6
|
+
|
7
|
+
var margin = {top: 0, right: 0, bottom: 0, left: 0}
|
8
|
+
, width = 500
|
9
|
+
, height = 500
|
10
|
+
, getX = function(d) { return d.x }
|
11
|
+
, getY = function(d) { return d.y }
|
12
|
+
, getDescription = function(d) { return d.description }
|
13
|
+
, id = Math.floor(Math.random() * 10000) //Create semi-unique ID in case user doesn't select one
|
14
|
+
, color = nv.utils.defaultColor()
|
15
|
+
, valueFormat = d3.format(',.2f')
|
16
|
+
, showLabels = true
|
17
|
+
, pieLabelsOutside = true
|
18
|
+
, donutLabelsOutside = false
|
19
|
+
, labelType = "key"
|
20
|
+
, labelThreshold = .02 //if slice percentage is under this, don't show label
|
21
|
+
, donut = false
|
22
|
+
, labelSunbeamLayout = false
|
23
|
+
, startAngle = false
|
24
|
+
, endAngle = false
|
25
|
+
, donutRatio = 0.5
|
26
|
+
, dispatch = d3.dispatch('chartClick', 'elementClick', 'elementDblClick', 'elementMouseover', 'elementMouseout')
|
27
|
+
;
|
28
|
+
|
29
|
+
//============================================================
|
30
|
+
|
31
|
+
|
32
|
+
function chart(selection) {
|
33
|
+
selection.each(function(data) {
|
34
|
+
var availableWidth = width - margin.left - margin.right,
|
35
|
+
availableHeight = height - margin.top - margin.bottom,
|
36
|
+
radius = Math.min(availableWidth, availableHeight) / 2,
|
37
|
+
arcRadius = radius-(radius / 5),
|
38
|
+
container = d3.select(this);
|
39
|
+
|
40
|
+
|
41
|
+
//------------------------------------------------------------
|
42
|
+
// Setup containers and skeleton of chart
|
43
|
+
|
44
|
+
//var wrap = container.selectAll('.nv-wrap.nv-pie').data([data]);
|
45
|
+
var wrap = container.selectAll('.nv-wrap.nv-pie').data(data);
|
46
|
+
var wrapEnter = wrap.enter().append('g').attr('class','nvd3 nv-wrap nv-pie nv-chart-' + id);
|
47
|
+
var gEnter = wrapEnter.append('g');
|
48
|
+
var g = wrap.select('g');
|
49
|
+
|
50
|
+
gEnter.append('g').attr('class', 'nv-pie');
|
51
|
+
|
52
|
+
wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')');
|
53
|
+
g.select('.nv-pie').attr('transform', 'translate(' + availableWidth / 2 + ',' + availableHeight / 2 + ')');
|
54
|
+
|
55
|
+
//------------------------------------------------------------
|
56
|
+
|
57
|
+
|
58
|
+
container
|
59
|
+
.on('click', function(d,i) {
|
60
|
+
dispatch.chartClick({
|
61
|
+
data: d,
|
62
|
+
index: i,
|
63
|
+
pos: d3.event,
|
64
|
+
id: id
|
65
|
+
});
|
66
|
+
});
|
67
|
+
|
68
|
+
|
69
|
+
var arc = d3.svg.arc()
|
70
|
+
.outerRadius(arcRadius);
|
71
|
+
|
72
|
+
if (startAngle) arc.startAngle(startAngle)
|
73
|
+
if (endAngle) arc.endAngle(endAngle);
|
74
|
+
if (donut) arc.innerRadius(radius * donutRatio);
|
75
|
+
|
76
|
+
// Setup the Pie chart and choose the data element
|
77
|
+
var pie = d3.layout.pie()
|
78
|
+
.sort(null)
|
79
|
+
.value(function(d) { return d.disabled ? 0 : getY(d) });
|
80
|
+
|
81
|
+
var slices = wrap.select('.nv-pie').selectAll('.nv-slice')
|
82
|
+
.data(pie);
|
83
|
+
|
84
|
+
slices.exit().remove();
|
85
|
+
|
86
|
+
var ae = slices.enter().append('g')
|
87
|
+
.attr('class', 'nv-slice')
|
88
|
+
.on('mouseover', function(d,i){
|
89
|
+
d3.select(this).classed('hover', true);
|
90
|
+
dispatch.elementMouseover({
|
91
|
+
label: getX(d.data),
|
92
|
+
value: getY(d.data),
|
93
|
+
point: d.data,
|
94
|
+
pointIndex: i,
|
95
|
+
pos: [d3.event.pageX, d3.event.pageY],
|
96
|
+
id: id
|
97
|
+
});
|
98
|
+
})
|
99
|
+
.on('mouseout', function(d,i){
|
100
|
+
d3.select(this).classed('hover', false);
|
101
|
+
dispatch.elementMouseout({
|
102
|
+
label: getX(d.data),
|
103
|
+
value: getY(d.data),
|
104
|
+
point: d.data,
|
105
|
+
index: i,
|
106
|
+
id: id
|
107
|
+
});
|
108
|
+
})
|
109
|
+
.on('click', function(d,i) {
|
110
|
+
dispatch.elementClick({
|
111
|
+
label: getX(d.data),
|
112
|
+
value: getY(d.data),
|
113
|
+
point: d.data,
|
114
|
+
index: i,
|
115
|
+
pos: d3.event,
|
116
|
+
id: id
|
117
|
+
});
|
118
|
+
d3.event.stopPropagation();
|
119
|
+
})
|
120
|
+
.on('dblclick', function(d,i) {
|
121
|
+
dispatch.elementDblClick({
|
122
|
+
label: getX(d.data),
|
123
|
+
value: getY(d.data),
|
124
|
+
point: d.data,
|
125
|
+
index: i,
|
126
|
+
pos: d3.event,
|
127
|
+
id: id
|
128
|
+
});
|
129
|
+
d3.event.stopPropagation();
|
130
|
+
});
|
131
|
+
|
132
|
+
slices
|
133
|
+
.attr('fill', function(d,i) { return color(d, i); })
|
134
|
+
.attr('stroke', function(d,i) { return color(d, i); });
|
135
|
+
|
136
|
+
var paths = ae.append('path')
|
137
|
+
.each(function(d) { this._current = d; });
|
138
|
+
//.attr('d', arc);
|
139
|
+
|
140
|
+
d3.transition(slices.select('path'))
|
141
|
+
.attr('d', arc)
|
142
|
+
.attrTween('d', arcTween);
|
143
|
+
|
144
|
+
if (showLabels) {
|
145
|
+
// This does the normal label
|
146
|
+
var labelsArc = d3.svg.arc().innerRadius(0);
|
147
|
+
|
148
|
+
if (pieLabelsOutside){ labelsArc = arc; }
|
149
|
+
|
150
|
+
if (donutLabelsOutside) { labelsArc = d3.svg.arc().outerRadius(arc.outerRadius()); }
|
151
|
+
|
152
|
+
ae.append("g").classed("nv-label", true)
|
153
|
+
.each(function(d, i) {
|
154
|
+
var group = d3.select(this);
|
155
|
+
|
156
|
+
group
|
157
|
+
.attr('transform', function(d) {
|
158
|
+
if (labelSunbeamLayout) {
|
159
|
+
d.outerRadius = arcRadius + 10; // Set Outer Coordinate
|
160
|
+
d.innerRadius = arcRadius + 15; // Set Inner Coordinate
|
161
|
+
var rotateAngle = (d.startAngle + d.endAngle) / 2 * (180 / Math.PI);
|
162
|
+
if ((d.startAngle+d.endAngle)/2 < Math.PI) {
|
163
|
+
rotateAngle -= 90;
|
164
|
+
} else {
|
165
|
+
rotateAngle += 90;
|
166
|
+
}
|
167
|
+
return 'translate(' + labelsArc.centroid(d) + ') rotate(' + rotateAngle + ')';
|
168
|
+
} else {
|
169
|
+
d.outerRadius = radius + 10; // Set Outer Coordinate
|
170
|
+
d.innerRadius = radius + 15; // Set Inner Coordinate
|
171
|
+
return 'translate(' + labelsArc.centroid(d) + ')'
|
172
|
+
}
|
173
|
+
});
|
174
|
+
|
175
|
+
group.append('rect')
|
176
|
+
.style('stroke', '#fff')
|
177
|
+
.style('fill', '#fff')
|
178
|
+
.attr("rx", 3)
|
179
|
+
.attr("ry", 3);
|
180
|
+
|
181
|
+
group.append('text')
|
182
|
+
.style('text-anchor', labelSunbeamLayout ? ((d.startAngle + d.endAngle) / 2 < Math.PI ? 'start' : 'end') : 'middle') //center the text on it's origin or begin/end if orthogonal aligned
|
183
|
+
.style('fill', '#000')
|
184
|
+
|
185
|
+
|
186
|
+
});
|
187
|
+
|
188
|
+
slices.select(".nv-label").transition()
|
189
|
+
.attr('transform', function(d) {
|
190
|
+
if (labelSunbeamLayout) {
|
191
|
+
d.outerRadius = arcRadius + 10; // Set Outer Coordinate
|
192
|
+
d.innerRadius = arcRadius + 15; // Set Inner Coordinate
|
193
|
+
var rotateAngle = (d.startAngle + d.endAngle) / 2 * (180 / Math.PI);
|
194
|
+
if ((d.startAngle+d.endAngle)/2 < Math.PI) {
|
195
|
+
rotateAngle -= 90;
|
196
|
+
} else {
|
197
|
+
rotateAngle += 90;
|
198
|
+
}
|
199
|
+
return 'translate(' + labelsArc.centroid(d) + ') rotate(' + rotateAngle + ')';
|
200
|
+
} else {
|
201
|
+
d.outerRadius = radius + 10; // Set Outer Coordinate
|
202
|
+
d.innerRadius = radius + 15; // Set Inner Coordinate
|
203
|
+
return 'translate(' + labelsArc.centroid(d) + ')'
|
204
|
+
}
|
205
|
+
});
|
206
|
+
|
207
|
+
slices.each(function(d, i) {
|
208
|
+
var slice = d3.select(this);
|
209
|
+
|
210
|
+
slice
|
211
|
+
.select(".nv-label text")
|
212
|
+
.style('text-anchor', labelSunbeamLayout ? ((d.startAngle + d.endAngle) / 2 < Math.PI ? 'start' : 'end') : 'middle') //center the text on it's origin or begin/end if orthogonal aligned
|
213
|
+
.text(function(d, i) {
|
214
|
+
var percent = (d.endAngle - d.startAngle) / (2 * Math.PI);
|
215
|
+
var labelTypes = {
|
216
|
+
"key" : getX(d.data),
|
217
|
+
"value": getY(d.data),
|
218
|
+
"percent": d3.format('%')(percent)
|
219
|
+
};
|
220
|
+
return (d.value && percent > labelThreshold) ? labelTypes[labelType] : '';
|
221
|
+
});
|
222
|
+
|
223
|
+
var textBox = slice.select('text').node().getBBox();
|
224
|
+
slice.select(".nv-label rect")
|
225
|
+
.attr("width", textBox.width + 10)
|
226
|
+
.attr("height", textBox.height + 10)
|
227
|
+
.attr("transform", function() {
|
228
|
+
return "translate(" + [textBox.x - 5, textBox.y - 5] + ")";
|
229
|
+
});
|
230
|
+
});
|
231
|
+
}
|
232
|
+
|
233
|
+
|
234
|
+
// Computes the angle of an arc, converting from radians to degrees.
|
235
|
+
function angle(d) {
|
236
|
+
var a = (d.startAngle + d.endAngle) * 90 / Math.PI - 90;
|
237
|
+
return a > 90 ? a - 180 : a;
|
238
|
+
}
|
239
|
+
|
240
|
+
function arcTween(a) {
|
241
|
+
a.endAngle = isNaN(a.endAngle) ? 0 : a.endAngle;
|
242
|
+
a.startAngle = isNaN(a.startAngle) ? 0 : a.startAngle;
|
243
|
+
if (!donut) a.innerRadius = 0;
|
244
|
+
var i = d3.interpolate(this._current, a);
|
245
|
+
this._current = i(0);
|
246
|
+
return function(t) {
|
247
|
+
return arc(i(t));
|
248
|
+
};
|
249
|
+
}
|
250
|
+
|
251
|
+
function tweenPie(b) {
|
252
|
+
b.innerRadius = 0;
|
253
|
+
var i = d3.interpolate({startAngle: 0, endAngle: 0}, b);
|
254
|
+
return function(t) {
|
255
|
+
return arc(i(t));
|
256
|
+
};
|
257
|
+
}
|
258
|
+
|
259
|
+
});
|
260
|
+
|
261
|
+
return chart;
|
262
|
+
}
|
263
|
+
|
264
|
+
|
265
|
+
//============================================================
|
266
|
+
// Expose Public Variables
|
267
|
+
//------------------------------------------------------------
|
268
|
+
|
269
|
+
chart.dispatch = dispatch;
|
270
|
+
chart.options = nv.utils.optionsFunc.bind(chart);
|
271
|
+
|
272
|
+
chart.margin = function(_) {
|
273
|
+
if (!arguments.length) return margin;
|
274
|
+
margin.top = typeof _.top != 'undefined' ? _.top : margin.top;
|
275
|
+
margin.right = typeof _.right != 'undefined' ? _.right : margin.right;
|
276
|
+
margin.bottom = typeof _.bottom != 'undefined' ? _.bottom : margin.bottom;
|
277
|
+
margin.left = typeof _.left != 'undefined' ? _.left : margin.left;
|
278
|
+
return chart;
|
279
|
+
};
|
280
|
+
|
281
|
+
chart.width = function(_) {
|
282
|
+
if (!arguments.length) return width;
|
283
|
+
width = _;
|
284
|
+
return chart;
|
285
|
+
};
|
286
|
+
|
287
|
+
chart.height = function(_) {
|
288
|
+
if (!arguments.length) return height;
|
289
|
+
height = _;
|
290
|
+
return chart;
|
291
|
+
};
|
292
|
+
|
293
|
+
chart.values = function(_) {
|
294
|
+
nv.log("pie.values() is no longer supported.");
|
295
|
+
return chart;
|
296
|
+
};
|
297
|
+
|
298
|
+
chart.x = function(_) {
|
299
|
+
if (!arguments.length) return getX;
|
300
|
+
getX = _;
|
301
|
+
return chart;
|
302
|
+
};
|
303
|
+
|
304
|
+
chart.y = function(_) {
|
305
|
+
if (!arguments.length) return getY;
|
306
|
+
getY = d3.functor(_);
|
307
|
+
return chart;
|
308
|
+
};
|
309
|
+
|
310
|
+
chart.description = function(_) {
|
311
|
+
if (!arguments.length) return getDescription;
|
312
|
+
getDescription = _;
|
313
|
+
return chart;
|
314
|
+
};
|
315
|
+
|
316
|
+
chart.showLabels = function(_) {
|
317
|
+
if (!arguments.length) return showLabels;
|
318
|
+
showLabels = _;
|
319
|
+
return chart;
|
320
|
+
};
|
321
|
+
|
322
|
+
chart.labelSunbeamLayout = function(_) {
|
323
|
+
if (!arguments.length) return labelSunbeamLayout;
|
324
|
+
labelSunbeamLayout = _;
|
325
|
+
return chart;
|
326
|
+
};
|
327
|
+
|
328
|
+
chart.donutLabelsOutside = function(_) {
|
329
|
+
if (!arguments.length) return donutLabelsOutside;
|
330
|
+
donutLabelsOutside = _;
|
331
|
+
return chart;
|
332
|
+
};
|
333
|
+
|
334
|
+
chart.pieLabelsOutside = function(_) {
|
335
|
+
if (!arguments.length) return pieLabelsOutside;
|
336
|
+
pieLabelsOutside = _;
|
337
|
+
return chart;
|
338
|
+
};
|
339
|
+
|
340
|
+
chart.labelType = function(_) {
|
341
|
+
if (!arguments.length) return labelType;
|
342
|
+
labelType = _;
|
343
|
+
labelType = labelType || "key";
|
344
|
+
return chart;
|
345
|
+
};
|
346
|
+
|
347
|
+
chart.donut = function(_) {
|
348
|
+
if (!arguments.length) return donut;
|
349
|
+
donut = _;
|
350
|
+
return chart;
|
351
|
+
};
|
352
|
+
|
353
|
+
chart.donutRatio = function(_) {
|
354
|
+
if (!arguments.length) return donutRatio;
|
355
|
+
donutRatio = _;
|
356
|
+
return chart;
|
357
|
+
};
|
358
|
+
|
359
|
+
chart.startAngle = function(_) {
|
360
|
+
if (!arguments.length) return startAngle;
|
361
|
+
startAngle = _;
|
362
|
+
return chart;
|
363
|
+
};
|
364
|
+
|
365
|
+
chart.endAngle = function(_) {
|
366
|
+
if (!arguments.length) return endAngle;
|
367
|
+
endAngle = _;
|
368
|
+
return chart;
|
369
|
+
};
|
370
|
+
|
371
|
+
chart.id = function(_) {
|
372
|
+
if (!arguments.length) return id;
|
373
|
+
id = _;
|
374
|
+
return chart;
|
375
|
+
};
|
376
|
+
|
377
|
+
chart.color = function(_) {
|
378
|
+
if (!arguments.length) return color;
|
379
|
+
color = nv.utils.getColor(_);
|
380
|
+
return chart;
|
381
|
+
};
|
382
|
+
|
383
|
+
chart.valueFormat = function(_) {
|
384
|
+
if (!arguments.length) return valueFormat;
|
385
|
+
valueFormat = _;
|
386
|
+
return chart;
|
387
|
+
};
|
388
|
+
|
389
|
+
chart.labelThreshold = function(_) {
|
390
|
+
if (!arguments.length) return labelThreshold;
|
391
|
+
labelThreshold = _;
|
392
|
+
return chart;
|
393
|
+
};
|
394
|
+
//============================================================
|
395
|
+
|
396
|
+
|
397
|
+
return chart;
|
398
|
+
}
|