1 /** 2 * @class 3 * Base class for all charts 4 */ 5 wso2vis.s.chart.Chart = 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.charts.push(this); 30 id = wso2vis.environment.charts.length - 1; 31 this.getID = function() { 32 return id; 33 }; 34 }; 35 36 wso2vis.extend(wso2vis.s.chart.Chart, wso2vis.s.Subscriber); 37 38 wso2vis.s.chart.Chart.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.chart.Chart.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.chart.Chart.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.chart.Chart.prototype.update = function () { 83 }; 84 85 wso2vis.s.chart.Chart.prototype.updateMessageDiv = function (s) { 86 87 if( this.msgDiv() !== undefined ) { 88 var msgdiv = document.getElementById(this.msgDiv()); 89 if( msgdiv !== undefined ) { 90 msgdiv.innerHTML = s; 91 msgdiv.style.display = "block"; 92 } 93 } 94 }; 95 96 wso2vis.s.chart.Chart.prototype.messageInterceptFunction = function () { 97 98 return "Invalid Data"; 99 }; 100 101 wso2vis.s.chart.Chart.prototype.onClick = function () { 102 }; 103 104 wso2vis.s.chart.Chart.prototype.onTooltip = function (data) { 105 return ""; 106 }; 107 108 wso2vis.s.chart.Chart.prototype.onKey = function () { 109 }; 110 111 wso2vis.s.chart.Chart.prototype.traverseToDataField = function (object, dataFieldArray) { 112 var a = object; 113 try { //Try catch outside the loop TODO 114 for (var i = 0; i < dataFieldArray.length; i++) { 115 a = a[dataFieldArray[i]]; 116 } 117 } 118 catch (e) { 119 this.updateMessageDiv(this.messageInterceptFunction()); 120 } 121 return a; 122 }; 123 124 wso2vis.s.chart.Chart.prototype.getDataObject = function (dataObj, i) { 125 if( dataObj instanceof Array ) { 126 return dataObj[i]; 127 } 128 else { 129 return dataObj; 130 } 131 }; 132 133