123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767 |
- if(!dojo._hasResource["dojox.widget.gauge._Gauge"]){
- dojo._hasResource["dojox.widget.gauge._Gauge"] = true;
- dojo.provide("dojox.widget.gauge._Gauge");
- dojo.require("dijit._Widget");
- dojo.require("dijit._Templated");
- dojo.require("dijit._Container");
- dojo.require("dijit._Contained");
- dojo.require("dijit.Tooltip");
- dojo.require("dojo.fx.easing");
- dojo.require("dojox.gfx");
- dojo.experimental("dojox.widget.gauge._Gauge");
- dojo.declare("dojox.widget.gauge._Gauge",[dijit._Widget, dijit._Templated, dijit._Container],{
-
-
-
-
-
-
-
-
-
-
-
-
- width: 0,
-
-
- height: 0,
-
-
-
-
-
-
- background: null,
-
-
- min: 0,
-
-
- max: 0,
-
-
- image: null,
-
-
-
-
-
-
- useRangeStyles: 0,
-
-
- useTooltip: true,
-
-
-
-
-
-
-
-
-
-
-
- majorTicks: null,
-
-
-
-
- minorTicks: null,
-
-
-
-
- _defaultIndicator: null,
-
-
- defaultColors: [[0x00,0x54,0xAA,1],
- [0x44,0x77,0xBB,1],
- [0x66,0x99,0xCC,1],
- [0x99,0xBB,0xEE,1],
- [0x99,0xCC,0xFF,1],
- [0xCC,0xEE,0xFF,1],
- [0xDD,0xEE,0xFF,1]],
-
-
-
-
- min: null,
-
-
-
-
- max: null,
-
-
-
- surface: null,
-
-
-
- hideValues: false,
-
- gaugeContent: undefined,
- templateString: dojo.cache("dojox.widget.gauge", "_Gauge.html", "<div>\n\t<div class=\"dojoxGaugeContent\" dojoAttachPoint=\"gaugeContent\"></div>\n\t<div dojoAttachPoint=\"containerNode\"></div>\n\t<div dojoAttachPoint=\"mouseNode\"></div>\n</div>\n"),
- _backgroundDefault: {color: '#E0E0E0'},
- _rangeData: null,
- _indicatorData: null,
- _drag: null,
- _img: null,
- _overOverlay: false,
- _lastHover: '',
- startup: function(){
-
-
-
- if(this.image === null){
- this.image={};
- }
- this.connect(this.gaugeContent, 'onmousemove', this.handleMouseMove);
- this.connect(this.gaugeContent, 'onmouseover', this.handleMouseOver);
- this.connect(this.gaugeContent, 'onmouseout', this.handleMouseOut);
- this.connect(this.gaugeContent, 'onmouseup', this.handleMouseUp);
- if(!dojo.isArray(this.ranges)){ this.ranges = []; }
- if(!dojo.isArray(this.indicators)){ this.indicators = []; }
- var ranges = [], indicators = [];
- var i;
- if(this.hasChildren()){
- var children = this.getChildren();
- for(i=0; i<children.length; i++){
- if(/dojox\.widget\..*Indicator/.test(children[i].declaredClass)){
- indicators.push(children[i]);
-
- continue;
- }
- switch(children[i].declaredClass){
- case "dojox.widget.gauge.Range":
- ranges.push(children[i]);
- break;
- }
- }
- this.ranges = this.ranges.concat(ranges);
- this.indicators = this.indicators.concat(indicators);
- }
- if(!this.background){ this.background = this._backgroundDefault; }
- this.background = this.background.color || this.background;
- if(!this.surface){ this.createSurface(); }
- this.addRanges(this.ranges);
- if(this.minorTicks && this.minorTicks.interval){
- this.setMinorTicks(this.minorTicks);
- }
- if(this.majorTicks && this.majorTicks.interval){
- this.setMajorTicks(this.majorTicks);
- }
- for(i=0; i<this.indicators.length; i++){
- this.addIndicator(this.indicators[i]);
- }
- },
- _setTicks: function(/*Object*/ oldTicks, /*Object*/ newTicks, /*Boolean*/ label){
-
-
- var i;
- if(oldTicks && dojo.isArray(oldTicks._ticks)){
- for(i=0; i<oldTicks._ticks.length; i++){
- this.removeIndicator(oldTicks._ticks[i]);
- }
- }
- var t = {length: newTicks.length,
- offset: newTicks.offset,
- noChange: true};
- if(newTicks.color){ t.color = newTicks.color; }
- if(newTicks.font){ t.font = newTicks.font; }
- newTicks._ticks = [];
- for(i=this.min; i<=this.max; i+=newTicks.interval){
- t.value = i;
- if(label){t.label = ''+i;}
- newTicks._ticks.push(this.addIndicator(t));
- }
- return newTicks;
- },
-
- setMinorTicks: function(/*Object*/ ticks){
-
-
-
- this.minorTicks = this._setTicks(this.minorTicks, ticks, false);
- },
- setMajorTicks: function(/*Object*/ ticks){
-
-
-
- this.majorTicks = this._setTicks(this.majorTicks, ticks, true);
- },
- postCreate: function(){
- if(this.hideValues){
- dojo.style(this.containerNode, "display", "none");
- }
- dojo.style(this.mouseNode, 'width', '0');
- dojo.style(this.mouseNode, 'height', '0');
- dojo.style(this.mouseNode, 'position', 'absolute');
- dojo.style(this.mouseNode, 'z-index', '100');
- if(this.useTooltip){
- dijit.showTooltip('test',this.mouseNode, !this.isLeftToRight());
- dijit.hideTooltip(this.mouseNode);
- }
- },
- createSurface: function(){
-
-
- this.gaugeContent.style.width = this.width + 'px';
- this.gaugeContent.style.height = this.height + 'px';
- this.surface = dojox.gfx.createSurface(this.gaugeContent, this.width, this.height);
- this._background = this.surface.createRect({x: 0, y: 0, width: this.width, height: this.height });
- this._background.setFill(this.background);
- if(this.image.url){
- this._img = this.surface.createImage({width: this.image.width || this.width, height: this.image.height || this.height, src: this.image.url});
- if(this.image.overlay){
- this._img.getEventSource().setAttribute('overlay',true);
- }
- if(this.image.x || this.image.y){
- this._img.setTransform({dx: this.image.x || 0, dy: this.image.y || 0});
- }
- }
- },
- setBackground: function(background){
-
-
-
-
-
-
-
-
-
-
-
-
- if(!background){ background = this._backgroundDefault; }
- this.background = background.color || background;
- this._background.setFill(this.background);
- },
- addRange: function(/*Object*/range){
-
-
-
-
-
-
-
-
- this.addRanges([range]);
- },
- addRanges: function(/*Array*/ranges){
-
-
-
-
-
-
-
-
- if(!this._rangeData){
- this._rangeData = [];
- }
- var range;
- for(var i=0; i<ranges.length; i++){
- range = ranges[i];
- if((this.min === null) || (range.low < this.min)){this.min = range.low;}
- if((this.max === null) || (range.high > this.max)){this.max = range.high;}
- if(!range.color){
- var colorIndex = this._rangeData.length % this.defaultColors.length;
- if(dojox.gfx.svg && this.useRangeStyles > 0){
- colorIndex = (this._rangeData.length % this.useRangeStyles)+1;
- range.color = {style: "dojoxGaugeRange"+colorIndex};
- }else{
- colorIndex = this._rangeData.length % this.defaultColors.length;
- range.color = this.defaultColors[colorIndex];
- }
- }
- this._rangeData[this._rangeData.length] = range;
- }
- this.draw();
- },
- addIndicator: function(/*Object*/indicator){
-
-
-
-
-
-
-
-
- indicator._gauge = this;
- if(!indicator.declaredClass){
-
- indicator = new this._defaultIndicator(indicator);
- }
- if(!indicator.hideValue){
- this.containerNode.appendChild(indicator.domNode);
- }
- if(!this._indicatorData){this._indicatorData = [];}
- this._indicatorData[this._indicatorData.length] = indicator;
- indicator.draw();
- return indicator;
- },
- removeIndicator: function(/*Object*/indicator){
-
-
-
- for(var i=0; i<this._indicatorData.length; i++){
- if(this._indicatorData[i] === indicator){
- this._indicatorData.splice(i, 1);
- indicator.remove();
- break;
- }
- }
- },
- moveIndicatorToFront: function(/*Object*/indicator){
-
-
-
-
-
-
- if(indicator.shapes){
- for(var i=0; i<indicator.shapes.length; i++){
- indicator.shapes[i].moveToFront();
- }
- }
- },
- drawText: function(/*String*/txt, /*Number*/x, /*Number*/y, /*String?*/align, /*String?*/vAlign, /*String?*/color, /*Object?*/font){
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- var t = this.surface.createText({x: x, y: y, text: txt, align: align});
- t.setFill(color);
- t.setFont(font);
- return t;
- },
- removeText:function(/*String*/t){
-
-
-
-
- this.surface.rawNode.removeChild(t);
- },
- updateTooltip: function(/*String*/txt, /*Event*/ e){
-
-
-
-
- if(this._lastHover != txt){
- if(txt !== ''){
- dijit.hideTooltip(this.mouseNode);
- dijit.showTooltip(txt,this.mouseNode, !this.isLeftToRight());
- }else{
- dijit.hideTooltip(this.mouseNode);
- }
- this._lastHover = txt;
- }
- },
- handleMouseOver: function(/*Object*/event){
-
-
-
-
-
- var hover = event.target.getAttribute('hover');
- if(event.target.getAttribute('overlay')){
- this._overOverlay = true;
- var r = this.getRangeUnderMouse(event);
- if(r && r.hover){
- hover = r.hover;
- }
- }
- if(this.useTooltip && !this._drag){
- if(hover){
- this.updateTooltip(hover, event);
- }else{
- this.updateTooltip('', event);
- }
- }
- },
- handleMouseOut: function(/*Object*/event){
-
-
-
-
-
- if(event.target.getAttribute('overlay')){
- this._overOverlay = false;
- }
- if(this.useTooltip && this.mouseNode){
- dijit.hideTooltip(this.mouseNode);
- }
- },
- handleMouseDown: function(/*Object*/event){
-
-
-
-
-
-
- for(var i=0; i<this._indicatorData.length; i++){
- var shapes = this._indicatorData[i].shapes;
- for(var s=0; s<shapes.length; s++){
- if(shapes[s].getEventSource() == event.target){
- this._drag = this._indicatorData[i];
- s = shapes.length;
- i = this._indicatorData.length;
- }
- }
- }
- dojo.stopEvent(event);
- },
- handleMouseUp: function(/*Object*/event){
-
-
-
-
-
- this._drag = null;
- dojo.stopEvent(event);
- },
- handleMouseMove: function(/*Object*/event){
-
-
-
-
-
- if(event){
- dojo.style(this.mouseNode, 'left', event.pageX+1+'px');
- dojo.style(this.mouseNode, 'top', event.pageY+1+'px');
- }
- if(this._drag){
- this._dragIndicator(this, event);
- }else{
- if(this.useTooltip && this._overOverlay){
- var r = this.getRangeUnderMouse(event);
- if(r && r.hover){
- this.updateTooltip(r.hover, event);
- }else{
- this.updateTooltip('', event);
- }
- }
- }
- }
- });
- dojo.declare("dojox.widget.gauge.Range",[dijit._Widget, dijit._Contained],{
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- low: 0,
-
-
-
- high: 0,
-
-
-
- hover: '',
-
-
-
-
-
-
-
- color: null,
-
-
-
- size: 0,
- startup: function(){
- this.color = this.color.color || this.color;
- }
- });
- dojo.declare("dojox.widget.gauge._Indicator",[dijit._Widget, dijit._Contained, dijit._Templated],{
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- value: 0,
-
-
-
- type: '',
-
-
- color: 'black',
-
-
- label: '',
-
-
-
- font: {family: "sans-serif", size: "12px"},
-
-
-
-
- length: 0,
-
-
- width: 0,
-
-
- offset: 0,
-
-
- hover: '',
-
-
- front: false,
-
-
-
-
-
- easing: dojo._defaultEasing,
-
-
- duration: 1000,
-
-
-
- hideValue: false,
-
-
-
- noChange: false,
- _gauge: null,
-
-
-
- title: "",
- templateString: dojo.cache("dojox.widget.gauge", "_Indicator.html", "<div class=\"dojoxGaugeIndicatorDiv\">\n\t<label class=\"dojoxGaugeIndicatorLabel\" for=\"${title}\">${title}:</label>\n\t<input class=\"dojoxGaugeIndicatorInput\" name=\"${title}\" size=\"5\" value=\"${value}\" dojoAttachPoint=\"valueNode\" dojoAttachEvent=\"onchange:_update\"></input>\n</div>\n"),
- startup: function(){
- if(this.onDragMove){
- this.onDragMove = dojo.hitch(this.onDragMove);
- }
- },
- postCreate: function(){
- if(this.title === ""){
- dojo.style(this.domNode, "display", "none");
- }
- if(dojo.isString(this.easing)){
- this.easing = dojo.getObject(this.easing);
- }
- },
- _update: function(event){
-
-
- var value = this.valueNode.value;
- if(value === ''){
- this.value = null;
- }else{
- this.value = Number(value);
- this.hover = this.title+': '+value;
- }
- if(this._gauge){
- this.draw();
- this.valueNode.value = this.value;
- if((this.title == 'Target' || this.front) && this._gauge.moveIndicator){
-
- this._gauge.moveIndicatorToFront(this);
- }
- }
- },
- update: function(value){
-
-
-
- if(!this.noChange){
- this.valueNode.value = value;
- this._update();
- }
- },
- onDragMove: function(){
-
-
- this.value = Math.floor(this.value);
- this.valueNode.value = this.value;
- this.hover = this.title+': '+this.value;
- },
- draw: function(/* Boolean? */ dontAnimate){
-
-
-
-
- },
- remove: function(){
-
-
- for(var i=0; i<this.shapes.length; i++){
- this._gauge.surface.remove(this.shapes[i]);
- }
- if(this.text){
- this._gauge.surface.remove(this.text);
- }
- }
- });
- }
|