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