2 * @class Ext.chart.axis.Gauge
3 * @extends Ext.chart.axis.Abstract
5 * Gauge Axis is the axis to be used with a Gauge series. The Gauge axis
6 * displays numeric data from an interval defined by the `minimum`, `maximum` and
7 * `step` configuration properties. The placement of the numeric data can be changed
8 * by altering the `margin` option that is set to `10` by default.
10 * A possible configuration for this axis would look like:
22 Ext.define('Ext.chart.axis.Gauge', {
24 /* Begin Definitions */
26 extend: 'Ext.chart.axis.Abstract',
31 * @cfg {Number} minimum (required) the minimum value of the interval to be displayed in the axis.
35 * @cfg {Number} maximum (required) the maximum value of the interval to be displayed in the axis.
39 * @cfg {Number} steps (required) the number of steps and tick marks to add to the interval.
43 * @cfg {Number} margin (optional) the offset positioning of the tick marks and labels in pixels. Default's 10.
50 drawAxis: function(init) {
51 var chart = this.chart,
52 surface = chart.surface,
53 bbox = chart.chartBBox,
54 centerX = bbox.x + (bbox.width / 2),
55 centerY = bbox.y + bbox.height,
56 margin = this.margin || 10,
57 rho = Math.min(bbox.width, 2 * bbox.height) /2 + margin,
64 if (this.sprites && !chart.resizing) {
69 if (this.margin >= 0) {
72 for (i = 0; i <= steps; i++) {
73 sprite = surface.add({
75 path: ['M', centerX + (rho - margin) * cos(i / steps * pi - pi),
76 centerY + (rho - margin) * sin(i / steps * pi - pi),
77 'L', centerX + rho * cos(i / steps * pi - pi),
78 centerY + rho * sin(i / steps * pi - pi), 'Z'],
81 sprite.setAttributes({
87 sprites = this.sprites;
89 for (i = 0; i <= steps; i++) {
90 sprites[i].setAttributes({
91 path: ['M', centerX + (rho - margin) * cos(i / steps * pi - pi),
92 centerY + (rho - margin) * sin(i / steps * pi - pi),
93 'L', centerX + rho * cos(i / steps * pi - pi),
94 centerY + rho * sin(i / steps * pi - pi), 'Z'],
100 this.sprites = sprites;
107 drawTitle: function() {
110 surface = chart.surface,
111 bbox = chart.chartBBox,
112 labelSprite = me.titleSprite,
116 me.titleSprite = labelSprite = surface.add({
121 labelSprite.setAttributes(Ext.apply({
123 }, me.label || {}), true);
124 labelBBox = labelSprite.getBBox();
125 labelSprite.setAttributes({
126 x: bbox.x + (bbox.width / 2) - (labelBBox.width / 2),
127 y: bbox.y + bbox.height - (labelBBox.height / 2) - 4
132 * Updates the {@link #title} of this axis.
133 * @param {String} title
135 setTitle: function(title) {
140 drawLabel: function() {
141 var chart = this.chart,
142 surface = chart.surface,
143 bbox = chart.chartBBox,
144 centerX = bbox.x + (bbox.width / 2),
145 centerY = bbox.y + bbox.height,
146 margin = this.margin || 10,
147 rho = Math.min(bbox.width, 2 * bbox.height) /2 + 2 * margin,
149 labelArray = [], label,
150 maxValue = this.maximum || 0,
151 steps = this.steps, i = 0,
156 labelConf = this.label,
157 renderer = labelConf.renderer || function(v) { return v; };
159 if (!this.labelArray) {
161 for (i = 0; i <= steps; i++) {
162 // TODO Adjust for height of text / 2 instead
163 adjY = (i === 0 || i === steps) ? 7 : 0;
164 label = surface.add({
166 text: renderer(round(i / steps * maxValue)),
167 x: centerX + rho * cos(i / steps * pi - pi),
168 y: centerY + rho * sin(i / steps * pi - pi) - adjY,
169 'text-anchor': 'middle',
174 label.setAttributes({
177 labelArray.push(label);
181 labelArray = this.labelArray;
183 for (i = 0; i <= steps; i++) {
184 // TODO Adjust for height of text / 2 instead
185 adjY = (i === 0 || i === steps) ? 7 : 0;
186 labelArray[i].setAttributes({
187 text: renderer(round(i / steps * maxValue)),
188 x: centerX + rho * cos(i / steps * pi - pi),
189 y: centerY + rho * sin(i / steps * pi - pi) - adjY
193 this.labelArray = labelArray;