]>
git.proxmox.com Git - sencha-touch.git/blob - src/src/chart/series/Pie.js
2 * @class Ext.chart.series.Pie
3 * @extends Ext.chart.series.Polar
5 * Creates a Pie Chart. A Pie Chart is a useful visualization technique to display quantitative information for different
6 * categories that also have a meaning as a whole.
7 * As with all other series, the Pie Series must be appended in the *series* Chart array configuration. See the Chart
8 * documentation for more information. A typical configuration object for the pie series could be:
11 * var chart = new Ext.chart.PolarChart({
13 * interactions: ['rotate'],
14 * colors: ['#115fa6', '#94ae0a', '#a61120', '#ff8809', '#ffd13e'],
16 * fields: ['name', 'data1', 'data2', 'data3', 'data4', 'data5'],
18 * {name: 'metric one', data1: 10, data2: 12, data3: 14, data4: 8, data5: 13},
19 * {name: 'metric two', data1: 7, data2: 8, data3: 16, data4: 10, data5: 3},
20 * {name: 'metric three', data1: 5, data2: 2, data3: 14, data4: 12, data5: 7},
21 * {name: 'metric four', data1: 2, data2: 14, data3: 6, data4: 1, data5: 23},
22 * {name: 'metric five', data1: 27, data2: 38, data3: 36, data4: 13, data5: 33}
35 * Ext.Viewport.setLayout('fit');
36 * Ext.Viewport.add(chart);
38 * In this configuration we set `pie` as the type for the series, set an object with specific style properties for highlighting options
39 * (triggered when hovering elements). We also set true to `showInLegend` so all the pie slices can be represented by a legend item.
40 * We set `data1` as the value of the field to determine the angle span for each pie slice. We also set a label configuration object
41 * where we set the field name of the store field to be rendered as text for the label. The labels will also be displayed rotated.
42 * We set `contrast` to `true` to flip the color of the label if it is to similar to the background color. Finally, we set the font family
43 * and size through the `font` parameter.
46 Ext
.define('Ext.chart.series.Pie', {
47 extend
: 'Ext.chart.series.Polar',
49 'Ext.chart.series.sprite.PieSlice'
53 seriesType
: 'pieslice',
57 * @cfg {String} labelField
58 * @deprecated Use {@link Ext.chart.series.Pie#label} instead.
59 * The store record field name to be used for the pie slice labels.
64 * @cfg {Number} donut Specifies the radius of the donut hole, as a percentage of the chart's radius.
65 * Defaults to 0 (no donut hole).
71 * @deprecated Use xField directly
76 * @cfg {Number} rotation The starting angle of the pie slices.
81 * @cfg {Number} [totalAngle=2*PI] The total angle of the pie series.
83 totalAngle
: Math
.PI
* 2,
86 * @cfg {Array} hidden Determines which pie slices are hidden.
91 * @cfg {Number} Allows adjustment of the radius by a spefic perfentage.
102 setField: function (f
) {
103 return this.setXField(f
);
106 getField: function () {
107 return this.getXField();
110 applyRadius : function (radius
) {
111 return radius
* this.getRadiusFactor() * 0.01;
114 updateLabelData: function () {
116 store
= me
.getStore(),
117 items
= store
.getData().items
,
118 sprites
= me
.getSprites(),
119 labelField
= me
.getLabel().getTemplate().getField(),
120 hidden
= me
.getHidden(),
121 i
, ln
, labels
, sprite
;
122 if (sprites
.length
> 0 && labelField
) {
124 for (i
= 0, ln
= items
.length
; i
< ln
; i
++) {
125 labels
.push(items
[i
].get(labelField
));
127 for (i
= 0, ln
= sprites
.length
; i
< ln
; i
++) {
129 sprite
.setAttributes({label
: labels
[i
]});
130 sprite
.putMarker('labels', {hidden
: hidden
[i
]}, sprite
.attr
.attributeId
);
135 coordinateX: function () {
137 store
= me
.getStore(),
138 items
= store
.getData().items
,
139 length
= items
.length
,
140 field
= me
.getXField(),
142 hidden
= me
.getHidden(),
145 totalAngle
= me
.getTotalAngle(),
146 sprites
= me
.getSprites();
152 for (i
= 0; i
< length
; i
++) {
153 value
= Math
.abs(Number(items
[i
].get(field
))) || 0;
158 if (i
>= hidden
.length
) {
164 sum
= totalAngle
/ sum
;
166 for (i
= 0; i
< length
; i
++) {
167 sprites
[i
].setAttributes({
168 startAngle
: lastAngle
,
169 endAngle
: lastAngle
= (sum
? summation
[i
] * sum
: 0),
173 for (; i
< me
.sprites
.length
; i
++) {
174 sprites
[i
].setAttributes({
175 startAngle
: totalAngle
,
176 endAngle
: totalAngle
,
180 me
.getChart().refreshLegendStore();
183 updateCenter: function (center
) {
185 translationX
: center
[0] + this.getOffsetX(),
186 translationY
: center
[1] + this.getOffsetY()
188 this.doUpdateStyles();
191 updateRadius: function (radius
) {
193 startRho
: radius
* this.getDonut() * 0.01, // Percentage
196 this.doUpdateStyles();
199 updateDonut: function (donut
) {
200 var radius
= this.getRadius();
202 startRho
: radius
* donut
* 0.01, // Percentage
205 this.doUpdateStyles();
208 updateRotation: function (rotation
) {
210 rotationRads
: rotation
212 this.doUpdateStyles();
215 updateTotalAngle: function (totalAngle
) {
219 getSprites: function () {
221 chart
= me
.getChart(),
222 store
= me
.getStore();
223 if (!chart
|| !store
) {
228 var items
= store
.getData().items
,
229 length
= items
.length
,
230 animation
= chart
&& chart
.getAnimate(),
231 sprites
= me
.sprites
, sprite
,
232 spriteIndex
= 0, rendererData
,
233 i
, spriteCreated
= false,
234 label
= me
.getLabel(),
235 labelTpl
= label
.getTemplate();
239 field
: me
.getField(),
243 for (i
= 0; i
< length
; i
++) {
246 sprite
= me
.createSprite();
247 if (me
.getHighlightCfg()) {
248 sprite
.config
.highlightCfg
= me
.getHighlightCfg();
249 sprite
.addModifier('highlight', true);
251 if (labelTpl
.getField()) {
252 labelTpl
.setAttributes({
253 labelOverflowPadding
: me
.getLabelOverflowPadding()
255 labelTpl
.fx
.setCustomDuration({'callout': 200});
256 sprite
.bindMarker('labels', label
);
258 sprite
.setAttributes(me
.getStyleByIndex(i
));
259 sprite
.rendererData
= rendererData
;
260 sprite
.rendererIndex
= spriteIndex
++;
261 spriteCreated
= true;
263 sprite
.fx
.setConfig(animation
);
271 normalizeAngle: function (angle
) {
272 var pi2
= Math
.PI
* 2;
276 return (angle
% pi2
+ pi2
) % pi2
;
279 betweenAngle: function (x
, a
, b
) {
280 var normalize
= this.normalizeAngle
;
287 return x
>= a
&& x
< b
;
291 * Returns the pie slice for a given angle
292 * @param {Number} angle The angle to search for the slice
293 * @return {Object} An object containing the reocord, sprite, scope etc.
295 getItemForAngle: function (angle
) {
297 sprites
= me
.getSprites(),
300 angle
%= Math
.PI
* 2;
303 angle
+= Math
.PI
* 2;
307 var store
= me
.getStore(),
308 items
= store
.getData().items
,
309 hidden
= me
.getHidden(),
311 ln
= store
.getCount();
313 for (; i
< ln
; i
++) {
315 // Fortunately, the id of items equals the index of it in instances list.
316 attr
= sprites
[i
].attr
;
318 if (attr
.startAngle
<= angle
&& attr
.endAngle
>= angle
) {
324 field
: me
.getXField()
334 getItemForPoint: function (x
, y
) {
336 sprites
= me
.getSprites();
338 var center
= me
.getCenter(),
339 offsetX
= me
.getOffsetX(),
340 offsetY
= me
.getOffsetY(),
341 originalX
= x
- center
[0] + offsetX
,
342 originalY
= y
- center
[1] + offsetY
,
343 store
= me
.getStore(),
344 donut
= me
.getDonut(),
345 items
= store
.getData().items
,
346 direction
= Math
.atan2(originalY
, originalX
) - me
.getRotation(),
347 donutLimit
= Math
.sqrt(originalX
* originalX
+ originalY
* originalY
),
348 endRadius
= me
.getRadius(),
349 startRadius
= donut
/ 100 * endRadius
,
350 hidden
= me
.getHidden(),
353 for (i
= 0, ln
= items
.length
; i
< ln
; i
++) {
355 // Fortunately, the id of items equals the index of it in instances list.
356 attr
= sprites
[i
].attr
;
357 if (startRadius
+ attr
.margin
<= donutLimit
&& donutLimit
+ attr
.margin
<= endRadius
) {
358 if (this.betweenAngle(direction
, attr
.startAngle
, attr
.endAngle
)) {
364 field
: this.getXField()
374 provideLegendInfo: function (target
) {
375 var store
= this.getStore();
377 var items
= store
.getData().items
,
378 labelField
= this.getLabel().getTemplate().getField(),
379 field
= this.getField(),
380 hidden
= this.getHidden();
381 for (var i
= 0; i
< items
.length
; i
++) {
383 name
: labelField
? String(items
[i
].get(labelField
)) : field
+ ' ' + i
,
384 mark
: this.getStyleByIndex(i
).fillStyle
|| this.getStyleByIndex(i
).strokeStyle
|| 'black',
386 series
: this.getId(),