4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-chart-axis-Gauge'>/**
19 </span> * @class Ext.chart.axis.Gauge
20 * @extends Ext.chart.axis.Abstract
22 * Gauge Axis is the axis to be used with a Gauge series. The Gauge axis
23 * displays numeric data from an interval defined by the `minimum`, `maximum` and
24 * `step` configuration properties. The placement of the numeric data can be changed
25 * by altering the `margin` option that is set to `10` by default.
27 * A possible configuration for this axis would look like:
38 Ext.define('Ext.chart.axis.Gauge', {
40 /* Begin Definitions */
42 extend: 'Ext.chart.axis.Abstract',
46 <span id='Ext-chart-axis-Gauge-cfg-minimum'> /**
47 </span> * @cfg {Number} minimum (required) the minimum value of the interval to be displayed in the axis.
50 <span id='Ext-chart-axis-Gauge-cfg-maximum'> /**
51 </span> * @cfg {Number} maximum (required) the maximum value of the interval to be displayed in the axis.
54 <span id='Ext-chart-axis-Gauge-cfg-steps'> /**
55 </span> * @cfg {Number} steps (required) the number of steps and tick marks to add to the interval.
58 <span id='Ext-chart-axis-Gauge-cfg-margin'> /**
59 </span> * @cfg {Number} margin (optional) the offset positioning of the tick marks and labels in pixels. Default's 10.
66 drawAxis: function(init) {
67 var chart = this.chart,
68 surface = chart.surface,
69 bbox = chart.chartBBox,
70 centerX = bbox.x + (bbox.width / 2),
71 centerY = bbox.y + bbox.height,
72 margin = this.margin || 10,
73 rho = Math.min(bbox.width, 2 * bbox.height) /2 + margin,
80 if (this.sprites && !chart.resizing) {
85 if (this.margin >= 0) {
88 for (i = 0; i <= steps; i++) {
89 sprite = surface.add({
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'],
97 sprite.setAttributes({
100 sprites.push(sprite);
103 sprites = this.sprites;
105 for (i = 0; i <= steps; i++) {
106 sprites[i].setAttributes({
107 path: ['M', centerX + (rho - margin) * cos(i / steps * pi - pi),
108 centerY + (rho - margin) * sin(i / steps * pi - pi),
109 'L', centerX + rho * cos(i / steps * pi - pi),
110 centerY + rho * sin(i / steps * pi - pi), 'Z'],
116 this.sprites = sprites;
123 drawTitle: function() {
126 surface = chart.surface,
127 bbox = chart.chartBBox,
128 labelSprite = me.titleSprite,
132 me.titleSprite = labelSprite = surface.add({
137 labelSprite.setAttributes(Ext.apply({
139 }, me.label || {}), true);
140 labelBBox = labelSprite.getBBox();
141 labelSprite.setAttributes({
142 x: bbox.x + (bbox.width / 2) - (labelBBox.width / 2),
143 y: bbox.y + bbox.height - (labelBBox.height / 2) - 4
147 <span id='Ext-chart-axis-Gauge-method-setTitle'> /**
148 </span> * Updates the {@link #title} of this axis.
149 * @param {String} title
151 setTitle: function(title) {
156 drawLabel: function() {
157 var chart = this.chart,
158 surface = chart.surface,
159 bbox = chart.chartBBox,
160 centerX = bbox.x + (bbox.width / 2),
161 centerY = bbox.y + bbox.height,
162 margin = this.margin || 10,
163 rho = Math.min(bbox.width, 2 * bbox.height) /2 + 2 * margin,
165 labelArray = [], label,
166 maxValue = this.maximum || 0,
167 steps = this.steps, i = 0,
172 labelConf = this.label,
173 renderer = labelConf.renderer || function(v) { return v; };
175 if (!this.labelArray) {
177 for (i = 0; i <= steps; i++) {
178 // TODO Adjust for height of text / 2 instead
179 adjY = (i === 0 || i === steps) ? 7 : 0;
180 label = surface.add({
182 text: renderer(round(i / steps * maxValue)),
183 x: centerX + rho * cos(i / steps * pi - pi),
184 y: centerY + rho * sin(i / steps * pi - pi) - adjY,
185 'text-anchor': 'middle',
190 label.setAttributes({
193 labelArray.push(label);
197 labelArray = this.labelArray;
199 for (i = 0; i <= steps; i++) {
200 // TODO Adjust for height of text / 2 instead
201 adjY = (i === 0 || i === steps) ? 7 : 0;
202 labelArray[i].setAttributes({
203 text: renderer(round(i / steps * maxValue)),
204 x: centerX + rho * cos(i / steps * pi - pi),
205 y: centerY + rho * sin(i / steps * pi - pi) - adjY
209 this.labelArray = labelArray;