/* Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved. Available via Academic Free License >= 2.1 OR the modified BSD license. see: http://dojotoolkit.org/license for details */ if(!dojo._hasResource["dojox.widget.gauge._Gauge"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. 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],{ // summary: // a gauge built using the dojox.gfx package. // // description: // using dojo.gfx (and thus either SVG or VML based on what is supported), this widget // builds a gauge component, used to display numerical data in a familiar format // // usage: // this widget is not to be used alone. it is meant to be subclassed, such as // dojox.widget.BarGauge or dojox.widget.AnalogGauge // width: Number // the width of the gauge (default is 300) width: 0, // height: Number // the height of the gauge (default is 200) height: 0, // background: Object // the color of the background. This must be an object of one of two forms: // {'color': 'color-name'} // OR // (for a gradient:) // {'type': 'linear', 'x1': 0, 'x2': 0, 'y1': 0, 'y2': 200, 'colors': [{offset: 0, color:'#C0C0C0'}, {offset: 1, color: '#E0E0E0'}] } background: null, // min: Number // minimum value displayed by gauge (default is lowest range value) min: 0, // max: Number // maximum value displayed by gauge (default is largest range value) max: 0, // image: String // background image for gauge (default is no image) image: null, // useRangeStyles: Number // indicates whether to use given css classes (dojoxGaugeRangeXX) // to determine the color (and other style attributes?) of the ranges // this value should be the number of dojoxGaugeRange classes that are // defined, starting at dojoxGaugeRange1 (0 indicates falling to default // hardcoded colors) useRangeStyles: 0, // useTooltip: Boolean // indicates whether tooltips should be displayed for ranges, indicators, etc. useTooltip: true, // majorTicks: Object // An object representing the tick marks that should be added to the gauge. Major tick marks have a text label // indicating the value. The object can have the following attributes (required are marked with a *): // offset: the distance from the 'center' of the gauge. Used differently for Analog vs. Bar // width: The width of the mark // length: The length of the mark // interval: The interval the ticks should be added on // color: The color of the mark and text // font: an object with any/all of the following parameters: // {family: "Helvetica", style: "italic", variant: 'small-caps', weight: 'bold', size: "18pt"} majorTicks: null, // minorTicks: Object // An object of the same format as majorTicks, indicating where the minor (label-less) marks should be placed // The font parameter is ignored if provided since minor tick marks have no text label. minorTicks: null, // _defaultIndicator: Objection // Should be overridden by any extending classes and used to indicate what the 'default' indicator is. // This object is used as the indicator when creating tick marks or when an anonmyous object is passed into // addIndicator. _defaultIndicator: null, // defaultColors: Array // Set of default colors to color ranges with. 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: Number // The minimum value of the gauge. Normally not set explicitly, as it will be determined by // the ranges that are added. min: null, // max: Number // The maximum value of the gauge. Normally not set explicitly, as it will be determined by // the ranges that are added. max: null, // surface: Object // The SVG/VML surface that the shapes are drawn on. Can be accessed/used by indicators to draw themselves surface: null, // hideValues: Boolean // indicates whether the text boxes showing the value of the indicator (as text // content) should be hidden or shown. Default is not hidden, aka shown. hideValues: false, // internal data gaugeContent: undefined, templateString: dojo.cache("dojox.widget.gauge", "_Gauge.html", "
\n\t
\n\t
\n\t
\n
\n"), _backgroundDefault: {color: '#E0E0E0'}, _rangeData: null, _indicatorData: null, _drag: null, _img: null, _overOverlay: false, _lastHover: '', startup: function(){ // handle settings from HTML by making sure all the options are // converted correctly to numbers and that we calculate defaults // for cx, cy and radius 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 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){ // summary: // This method is used to add an indicator to the bar graph. // description: // This method adds an indicator, such as a tick mark or needle, // to the bar graph. // indicator: // A dojox.widget.gauge._Indicator or an object with similar parameters // (value, color, offset, etc.). indicator._gauge = this; if(!indicator.declaredClass){// !== 'dojox.widget.gauge.Indicator'){ // We were passed a plain object, need to make an indicator out of it. 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){ // summary: // Removes the given indicator from the gauge by calling it's remove function // and removing it from the local cache. for(var i=0; i // dojo.require("dojox.widget.AnalogGauge"); // dojo.require("dijit.util.parser"); // // ... //
//
//
//
// low: Number // the low value of the range low: 0, // high: Numbe // the high value of the range high: 0, // hover: String // the text to put in the tooltip for the gauge hover: '', // color: Object // the color of the range. This must be an object of one of two forms: // {'color': 'color-name'} // OR // (for a gradient:) // {'type': 'linear', 'colors': [{offset: 0, color:'#C0C0C0'}, {offset: 1, color: '#E0E0E0'}] } color: null, // size: Number // for a circular gauge (such as an AnalogGauge), this dictates the size of the arc size: 0, startup: function(){ this.color = this.color.color || this.color; } }); dojo.declare("dojox.widget.gauge._Indicator",[dijit._Widget, dijit._Contained, dijit._Templated],{ // summary: // a indicator to be used in a gauge // // description: // an indicator widget, which has given properties. drawn by a gauge. // // usage: // // ... //
//
//
//
// value: Number // The value (on the gauge) that this indicator should be placed at value: 0, // type: String // The type of indicator to draw. Varies by gauge type. Some examples include // "line", "arrow", and "bar" type: '', // color: String // The color of the indicator. color: 'black', // label: String // The text label for the indicator. label: '', // font: Object // Generally in a format similar to: // {family: "Helvetica", weight: "bold", style: "italic", size: "18pt", rotated: true} font: {family: "sans-serif", size: "12px"}, // length: Number // The length of the indicator. In the above example, the radius of the AnalogGauge // is 125, but the length of the indicator is 135, meaning it would project beyond // the edge of the AnalogGauge length: 0, // width: Number // The width of the indicator. width: 0, // offset: Number // The offset of the indicator offset: 0, // hover: String // The string to put in the tooltip when this indicator is hovered over. hover: '', // front: boolean // Keep this indicator at the front front: false, // onDragMove: String // The function to call when this indicator is moved by dragging. //onDragMove: '', // easing: String|Object // indicates the easing function to be used when animating the of an indicator. easing: dojo._defaultEasing, // duration: Number // indicates how long an animation of the indicator should take duration: 1000, // hideValues: Boolean // indicates whether the text boxes showing the value of the indicator (as text // content) should be hidden or shown. Default is not hidden, aka shown. hideValue: false, // noChange: Boolean // indicates whether the indicator's value can be changed. Useful for // a static target indicator. Default is false (that the value can be changed). noChange: false, _gauge: null, // title: String // The title of the indicator, to be displayed next to it's input box for the text-representation. title: "", templateString: dojo.cache("dojox.widget.gauge", "_Indicator.html", "
\n\t\n\t\n
\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){ // summary: // A private function, handling the updating of the gauge 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){ // if re-drawing value, make sure target is still on top this._gauge.moveIndicatorToFront(this); } } }, update: function(value){ // summary: // Updates the value of the indicator, including moving/re-drawing at it's new location and // updating the text box if(!this.noChange){ this.valueNode.value = value; this._update(); } }, onDragMove: function(){ // summary: // Handles updating the text box and the hover text while dragging an indicator this.value = Math.floor(this.value); this.valueNode.value = this.value; this.hover = this.title+': '+this.value; }, draw: function(/* Boolean? */ dontAnimate){ // summary: // Performs the initial drawing of the indicator. // dontAnimate: // Indicates if the drawing should not be animated (rather than teh default, to animate) }, remove: function(){ // summary: // Removes the indicator's shapes from the gauge surface. for(var i=0; i