1 /** 2 * @class 3 * Base class for all gauges 4 */ 5 wso2vis.s.gauge.Gauge = function (canvas, ttle, desc) { 6 wso2vis.s.Subscriber.call(this); 7 /* @private */ 8 this.title(ttle) 9 .description(desc) 10 .divEl(canvas) 11 .tooltip(true) 12 //.legend(true) 13 //.marks(false) 14 .width(600) 15 .height(500) 16 //.titleFont("10px sans-serif") 17 //.labelFont("10px sans-serif") 18 //.legendX(0) 19 //.legendY(0) 20 .paddingTop(25) 21 .paddingLeft(10) 22 .paddingRight(60) 23 .paddingBottom(10); 24 25 /* @private */ 26 this.data = null; 27 //this.formattedData = null; 28 29 wso2vis.environment.gauges.push(this); 30 id = wso2vis.environment.gauges.length - 1; 31 this.getID = function() { 32 return id; 33 }; 34 }; 35 36 wso2vis.extend(wso2vis.s.gauge.Gauge, wso2vis.s.Subscriber); 37 38 wso2vis.s.gauge.Gauge.prototype 39 .property("title") 40 .property("description") 41 .property("divEl") 42 .property("msgDiv") 43 .property("tooltip") 44 //.property("legend") 45 .property("x") 46 .property("y") 47 .property("width") 48 .property("height") 49 .property("paddingTop") 50 .property("paddingLeft") 51 .property("paddingRight") 52 .property("paddingBottom") 53 .property("anchorTop") 54 .property("anchorLeft") 55 .property("anchorRight") 56 .property("anchorBottom") 57 //.property("legendX") 58 //.property("legendY") 59 .property("titleFont"); 60 //.property("labelFont") 61 //.property("marks"); 62 63 wso2vis.s.gauge.Gauge.prototype.pushData = function (d) { 64 if( this.validateData(d) ){ 65 this.data = d; 66 this.update(); 67 } else { 68 this.updateMessageDiv(this.messageInterceptFunction()); 69 } 70 }; 71 72 wso2vis.s.gauge.Gauge.prototype.validateData = function (d) { 73 //Check whether we have valid data or not. 74 if( d === null || d === undefined ) { 75 return false; 76 } 77 else { 78 return true; 79 } 80 }; 81 82 wso2vis.s.gauge.Gauge.prototype.update = function () { 83 }; 84 85 wso2vis.s.gauge.Gauge.prototype.updateMessageDiv = function (s) { 86 if( this.msgDiv() !== undefined ) { 87 var msgdiv = document.getElementById(this.msgDiv()); 88 if( msgdiv !== undefined ) { 89 msgdiv.innerHTML = s; 90 msgdiv.style.display = "block"; 91 } 92 } 93 }; 94 95 wso2vis.s.gauge.Gauge.prototype.messageInterceptFunction = function () { 96 return "Invalid Data"; 97 }; 98 99 wso2vis.s.gauge.Gauge.prototype.onClick = function () { 100 }; 101 102 wso2vis.s.gauge.Gauge.prototype.onTooltip = function (data) { 103 return ""; 104 }; 105 106 wso2vis.s.gauge.Gauge.prototype.onKey = function () { 107 }; 108 109 wso2vis.s.gauge.Gauge.prototype.traverseToDataField = function (object, dataFieldArray) { 110 var a = object; 111 try { //Try catch outside the loop TODO 112 for (var i = 0; i < dataFieldArray.length; i++) { 113 a = a[dataFieldArray[i]]; 114 } 115 } 116 catch (e) { 117 this.updateMessageDiv(this.messageInterceptFunction()); 118 } 119 return a; 120 }; 121 122 wso2vis.s.gauge.Gauge.prototype.getDataObject = function (dataObj, i) { 123 if( dataObj instanceof Array ) { 124 return dataObj[i]; 125 } 126 else { 127 return dataObj; 128 } 129 }; 130 131