source: Dev/trunk/src/client/dojox/dgauges/CircularGauge.js @ 532

Last change on this file since 532 was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

  • Property svn:executable set to *
File size: 1.9 KB
Line 
1define(["dojo/_base/declare", "dojo/dom-geometry", "dojox/gfx", "./GaugeBase"], function(declare, domGeom, gfx, GaugeBase){
2        return declare("dojox.dgauges.CircularGauge", GaugeBase, {
3                // summary:
4                //              The base class for circular gauges.
5                //              You can create custom circular or semi-circular gauges by extending this class.
6                //              See dojox.dgauges.components.default.CircularLinearGauge.js for an example of circular gauge.
7               
8                _transformProperties: null,
9               
10                refreshRendering: function(){
11                        if(this._widgetBox.w <= 0 || this._widgetBox.h <= 0){
12                                return;
13                        }
14                       
15                        for(var key in this._elementsIndex){
16                                this._elementsRenderers[key] = this._elementsIndex[key].refreshRendering();
17                        }
18                       
19                        // Maximize the drawing area and center the gauge
20                        var bb = this._computeBoundingBox(this._gfxGroup);
21                       
22                        var naturalRatio = (bb.x + bb.width) / (bb.y + bb.height);
23                        var widgetWidth = this._widgetBox.w;
24                        var widgetHeight = this._widgetBox.h;
25                        var widgetRatio = this._widgetBox.w / this._widgetBox.h;
26                       
27                        var xpos = 0;
28                        var ypos = 0;
29                        var h = 0;
30                        var w = 0;
31                        if(naturalRatio > widgetRatio){
32                                w = widgetWidth;
33                                h = w / naturalRatio;
34                                ypos = (widgetHeight - h) / 2;
35                        }else{
36                                h = widgetHeight;
37                                w = h * naturalRatio;
38                                xpos = (widgetWidth - w) / 2;
39                        }
40                        var scaleFactor = Math.max(w / (bb.x + bb.width), h / (bb.y + bb.height));
41                        this._transformProperties = {scale:scaleFactor, tx:xpos, ty:ypos};
42                        this._gfxGroup.setTransform([gfx.matrix.scale(scaleFactor), gfx.matrix.translate(xpos / scaleFactor, ypos / scaleFactor)]);
43                },
44               
45                _gaugeToPage: function(px, py){
46                        // summary:
47                        //              Internal method.
48                        // tags:
49                        //              private
50                        if(this._transformProperties){
51                                var np = domGeom.position(this.domNode, true);
52                                return {x: np.x + px * this._transformProperties.scale + this._transformProperties.tx, y: np.y + py * this._transformProperties.scale + this._transformProperties.ty};
53                        }else{
54                                return null;
55                        }
56                }
57        });
58});
Note: See TracBrowser for help on using the repository browser.