1 <!DOCTYPE html><html><head><title>Sencha Documentation Project</title><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../prettify.css" type="text/css"><link rel="stylesheet" href="../prettify_sa.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script></head><body onload="prettyPrint()"><pre class="prettyprint"><pre><span id='Ext-chart.series.Gauge'>/**
2 </span> * @class Ext.chart.series.Gauge
3 * @extends Ext.chart.series.Series
5 * Creates a Gauge Chart. Gauge Charts are used to show progress in a certain variable. There are two ways of using the Gauge chart.
6 * One is setting a store element into the Gauge and selecting the field to be used from that store. Another one is instanciating the
7 * visualization and using the `setValue` method to adjust the value you want.
9 * A chart/series configuration for the Gauge visualization could look like this:
26 * colorSet: ['#F49D10', '#ddd']
30 * In this configuration we create a special Gauge axis to be used with the gauge visualization (describing half-circle markers), and also we're
31 * setting a maximum, minimum and steps configuration options into the axis. The Gauge series configuration contains the store field to be bound to
32 * the visual display and the color set to be used with the visualization.
36 Ext.define('Ext.chart.series.Gauge', {
38 /* Begin Definitions */
40 extend: 'Ext.chart.series.Series',
44 type: "gauge",
45 alias: 'series.gauge',
49 <span id='Ext-chart.series.Gauge-cfg-highlightDuration'> /**
50 </span> * @cfg {Number} highlightDuration
51 * The duration for the pie slice highlight effect.
53 highlightDuration: 150,
55 <span id='Ext-chart.series.Gauge-cfg-angleField'> /**
56 </span> * @cfg {String} angleField
57 * The store record field name to be used for the pie angles.
58 * The values bound to this field name must be positive real numbers.
59 * This parameter is required.
63 <span id='Ext-chart.series.Gauge-cfg-needle'> /**
64 </span> * @cfg {Boolean} needle
65 * Use the Gauge Series as an area series or add a needle to it. Default's false.
69 <span id='Ext-chart.series.Gauge-cfg-donut'> /**
70 </span> * @cfg {Boolean|Number} donut
71 * Use the entire disk or just a fraction of it for the gauge. Default's false.
75 <span id='Ext-chart.series.Gauge-cfg-showInLegend'> /**
76 </span> * @cfg {Boolean} showInLegend
77 * Whether to add the pie chart elements as legend items. Default's false.
81 <span id='Ext-chart.series.Gauge-cfg-style'> /**
82 </span> * @cfg {Object} style
83 * An object containing styles for overriding series styles from Theming.
87 constructor: function(config) {
88 this.callParent(arguments);
91 surface = chart.surface,
93 shadow = chart.shadow, i, l, cfg;
94 Ext.apply(me, config, {
96 "stroke-width": 6,
97 "stroke-opacity": 1,
98 stroke: 'rgb(200, 200, 200)',
105 "stroke-width": 4,
106 "stroke-opacity": 1,
107 stroke: 'rgb(150, 150, 150)',
114 "stroke-width": 2,
115 "stroke-opacity": 1,
116 stroke: 'rgb(100, 100, 100)',
123 me.group = surface.getGroup(me.seriesId);
125 for (i = 0, l = me.shadowAttributes.length; i < l; i++) {
126 me.shadowGroups.push(surface.getGroup(me.seriesId + '-shadows' + i));
129 surface.customAttributes.segment = function(opt) {
130 return me.getSegment(opt);
134 //@private updates some onbefore render parameters.
135 initialize: function() {
137 store = me.chart.substore || me.chart.store;
138 //Add yFields to be used in Legend.js
140 if (me.label.field) {
141 store.each(function(rec) {
142 me.yField.push(rec.get(me.label.field));
147 // @private returns an object with properties for a Slice
148 getSegment: function(opt) {
156 x1 = 0, x2 = 0, x3 = 0, x4 = 0,
157 y1 = 0, y2 = 0, y3 = 0, y4 = 0,
159 r = opt.endRho - opt.startRho,
160 startAngle = opt.startAngle,
161 endAngle = opt.endAngle,
162 midAngle = (startAngle + endAngle) / 2 * rad,
163 margin = opt.margin || 0,
164 flag = abs(endAngle - startAngle) > 180,
165 a1 = Math.min(startAngle, endAngle) * rad,
166 a2 = Math.max(startAngle, endAngle) * rad,
169 x += margin * cos(midAngle);
170 y += margin * sin(midAngle);
172 x1 = x + opt.startRho * cos(a1);
173 y1 = y + opt.startRho * sin(a1);
175 x2 = x + opt.endRho * cos(a1);
176 y2 = y + opt.endRho * sin(a1);
178 x3 = x + opt.startRho * cos(a2);
179 y3 = y + opt.startRho * sin(a2);
181 x4 = x + opt.endRho * cos(a2);
182 y4 = y + opt.endRho * sin(a2);
184 if (abs(x1 - x3) <= delta && abs(y1 - y3) <= delta) {
187 //Solves mysterious clipping bug with IE
191 ["M", x1, y1],
192 ["L", x2, y2],
193 ["A", opt.endRho, opt.endRho, 0, +flag, 1, x4, y4],
199 ["M", x1, y1],
200 ["L", x2, y2],
201 ["A", opt.endRho, opt.endRho, 0, +flag, 1, x4, y4],
202 ["L", x3, y3],
203 ["A", opt.startRho, opt.startRho, 0, +flag, 0, x1, y1],
209 // @private utility function to calculate the middle point of a pie slice.
210 calcMiddle: function(item) {
216 startAngle = slice.startAngle,
217 endAngle = slice.endAngle,
218 radius = Math.max(('rho' in slice) ? slice.rho: me.radius, me.label.minMargin),
220 a1 = Math.min(startAngle, endAngle) * rad,
221 a2 = Math.max(startAngle, endAngle) * rad,
222 midAngle = -(a1 + (a2 - a1) / 2),
223 xm = x + (item.endRho + item.startRho) / 2 * Math.cos(midAngle),
224 ym = y - (item.endRho + item.startRho) / 2 * Math.sin(midAngle);
232 <span id='Ext-chart.series.Gauge-method-drawSeries'> /**
233 </span> * Draws the series for the current chart.
235 drawSeries: function() {
238 store = chart.substore || chart.store,
240 animate = me.chart.animate,
241 axis = me.chart.axes.get(0),
242 minimum = axis && axis.minimum || me.minimum || 0,
243 maximum = axis && axis.maximum || me.maximum || 0,
244 field = me.angleField || me.field || me.xField,
245 surface = chart.surface,
246 chartBBox = chart.chartBBox,
251 seriesStyle = me.seriesStyle,
252 seriesLabelStyle = me.seriesLabelStyle,
253 colorArrayStyle = me.colorArrayStyle,
254 colorArrayLength = colorArrayStyle && colorArrayStyle.length || 0,
255 gutterX = chart.maxGutter[0],
256 gutterY = chart.maxGutter[1],
259 rendererAttributes, centerX, centerY, slice, slices, sprite, value,
260 item, ln, record, i, j, startAngle, endAngle, middleAngle, sliceLength, path,
261 p, spriteOptions, bbox, splitAngle, sliceA, sliceB;
263 Ext.apply(seriesStyle, me.style || {});
268 //override theme colors
270 colorArrayStyle = me.colorSet;
271 colorArrayLength = colorArrayStyle.length;
274 //if not store or store is empty then there's nothing to draw
275 if (!store || !store.getCount()) {
279 centerX = me.centerX = chartBBox.x + (chartBBox.width / 2);
280 centerY = me.centerY = chartBBox.y + chartBBox.height;
281 me.radius = Math.min(centerX - chartBBox.x, centerY - chartBBox.y);
282 me.slices = slices = [];
283 me.items = items = [];
286 record = store.getAt(0);
287 me.value = record.get(field);
299 splitAngle = -180 * (1 - (value - minimum) / (maximum - minimum));
302 splitAngle = -180 * (1 - (value - minimum) / (maximum - minimum));
307 endAngle: splitAngle,
312 value: me.maximum - value,
313 startAngle: splitAngle,
317 slices.push(sliceA, sliceB);
320 //do pie slices after.
321 for (i = 0, ln = slices.length; i < ln; i++) {
323 sprite = group.getAt(i);
324 //set pie slice properties
325 rendererAttributes = Ext.apply({
327 startAngle: slice.startAngle,
328 endAngle: slice.endAngle,
331 startRho: slice.rho * +donut / 100,
334 }, Ext.apply(seriesStyle, colorArrayStyle && { fill: colorArrayStyle[i % colorArrayLength] } || {}));
337 rendererAttributes.segment, {
344 // Create a new sprite if needed (no height)
346 spriteOptions = Ext.apply({
347 type: "path",
349 }, Ext.apply(seriesStyle, colorArrayStyle && { fill: colorArrayStyle[i % colorArrayLength] } || {}));
350 sprite = surface.add(Ext.apply(spriteOptions, rendererAttributes));
352 slice.sprite = slice.sprite || [];
353 item.sprite = sprite;
354 slice.sprite.push(sprite);
356 rendererAttributes = me.renderer(sprite, record, rendererAttributes, i, store);
357 sprite._to = rendererAttributes;
358 me.onAnimate(sprite, {
359 to: rendererAttributes
362 rendererAttributes = me.renderer(sprite, record, Ext.apply(rendererAttributes, {
365 sprite.setAttributes(rendererAttributes, true);
370 splitAngle = splitAngle * Math.PI / 180;
372 if (!me.needleSprite) {
373 me.needleSprite = me.chart.surface.add({
375 path: ['M', centerX + (me.radius * +donut / 100) * cos(splitAngle),
376 centerY + -Math.abs((me.radius * +donut / 100) * sin(splitAngle)),
377 'L', centerX + me.radius * cos(splitAngle),
378 centerY + -Math.abs(me.radius * sin(splitAngle))],
384 me.onAnimate(me.needleSprite, {
386 path: ['M', centerX + (me.radius * +donut / 100) * cos(splitAngle),
387 centerY + -Math.abs((me.radius * +donut / 100) * sin(splitAngle)),
388 'L', centerX + me.radius * cos(splitAngle),
389 centerY + -Math.abs(me.radius * sin(splitAngle))]
393 me.needleSprite.setAttributes({
395 path: ['M', centerX + (me.radius * +donut / 100) * cos(splitAngle),
396 centerY + -Math.abs((me.radius * +donut / 100) * sin(splitAngle)),
397 'L', centerX + me.radius * cos(splitAngle),
398 centerY + -Math.abs(me.radius * sin(splitAngle))]
402 me.needleSprite.setAttributes({
410 <span id='Ext-chart.series.Gauge-method-setValue'> /**
411 </span> * Sets the Gauge chart to the current specified value.
413 setValue: function (value) {
418 // @private callback for when creating a label sprite.
419 onCreateLabel: function(storeItem, item, i, display) {},
421 // @private callback for when placing a label sprite.
422 onPlaceLabel: function(label, storeItem, item, i, display, animate, index) {},
424 // @private callback for when placing a callout.
425 onPlaceCallout: function() {},
427 // @private handles sprite animation for the series.
428 onAnimate: function(sprite, attr) {
430 return this.callParent(arguments);
433 isItemInPoint: function(x, y, item, i) {
437 // @private shows all elements in the series.
438 showAll: function() {
439 if (!isNaN(this._index)) {
440 this.__excludes[this._index] = false;
445 <span id='Ext-chart.series.Gauge-method-getLegendColor'> /**
446 </span> * Returns the color of the series (to be displayed as color for the series legend item).
447 * @param item {Object} Info about the item; same format as returned by #getItemForPoint
449 getLegendColor: function(index) {
451 return me.colorArrayStyle[index % me.colorArrayStyle.length];
455 </pre></pre></body></html>