1 //@class wso2vis.s.chart.protovis.Sunburst : wso2vis.s.chart.Chart
  2 
  3 //Constructor
  4 wso2vis.s.chart.protovis.Sunburst = function(canvas, chartTitle, chartDesc) {
  5     wso2vis.s.chart.Chart.call(this, canvas, chartTitle, chartDesc);
  6 
  7     this.labelLength(12)
  8         .thickness(30);
  9 
 10     /* @private */
 11     this.vis = null;
 12     this.sunburst = null;
 13     this.wedge = null;
 14 
 15     this.flare = {
 16       analytics: {
 17         cluster: {
 18           AgglomerativeCluster: 3938,
 19           CommunityStructure: 3812,
 20           HierarchicalCluster: 6714,
 21           MergeEdge: 743
 22         },
 23         graph: {
 24           BetweennessCentrality: 3534,
 25           LinkDistance: 5731,
 26           MaxFlowMinCut: 7840,
 27           ShortestPaths: 5914,
 28           SpanningTree: 3416
 29         },
 30         optimization: {
 31           AspectRatioBanker: 7074
 32         }
 33       }
 34     };
 35 }
 36 
 37 // this makes c.protovis.Sunburst.prototype inherits from wso2vis.s.chart.Chart
 38 wso2vis.extend(wso2vis.s.chart.protovis.Sunburst, wso2vis.s.chart.Chart);
 39 
 40 wso2vis.s.chart.protovis.Sunburst.prototype
 41     .property("dataField")
 42     .property("dataValue")
 43     .property("dataLabel")
 44     .property("labelLength")
 45     .property("thickness");
 46 
 47 //Public function load
 48 //Loads the chart inside the given HTML element
 49 wso2vis.s.chart.protovis.Sunburst.prototype.load = function (w) {
 50     if ( w !== undefined ) {
 51         this.width(w);
 52     }
 53     /*if ( h !== undefined ) { //not using height for the Wedge
 54         this.height(h);
 55     }*/
 56     var r = this.width() / 2.5;
 57 
 58     var thisObject = this;
 59 
 60     //this.sunburst = pv.Layout.sunburst(this.data).size(Number);
 61     
 62     this.vis = new pv.Panel()
 63         //.def("i", -1)
 64         .canvas(function() { return thisObject.divEl(); })
 65         .width(function() { return thisObject.width(); })
 66         .height(function() { return thisObject.height(); });
 67     
 68     this.wedge = this.vis.add(pv.Wedge)
 69         .extend(pv.Layout.sunburst(this.formattedData).size(function(n) { return parseInt(n); }))
 70         .fillStyle(pv.Colors.category10()
 71               .by(function(n) { return n.children ? n.keys : n.keys.slice(0, -1); }))
 72         .strokeStyle("#222")
 73           .lineWidth(1)
 74           //.visible(function(n) { return n.depth < 3; })
 75           .title(function(n) { return /*thisObject.traverseToDataField(thisObject.data, n.keys)*/ n.keys.join(".") + ": " + n.size; });
 76         //.anchor("center").add(pv.Label)
 77           //.visible(function(n) { return n.angle * n.depth > .05; })
 78           //.text(function(n) { return n.keys[n.keys.length - 1]; });
 79 
 80      this.vis.add(pv.Label)
 81         .left(this.width() / 2)
 82         .visible(function() { return !(thisObject.title() === ""); })
 83         .top(16)
 84         .textAlign("center")
 85         .text(function() { return thisObject.title(); })
 86         .font(function() { return thisObject.titleFont(); });
 87 };
 88 
 89 /**
 90 * @private
 91 */
 92 wso2vis.s.chart.protovis.Sunburst.prototype.titleSpacing = function () {
 93     if(this.title() === "") {
 94         return 1;
 95     }
 96     else {
 97         return 0.9;
 98     }
 99 };
100 
101 /**
102 * @private
103 */
104 wso2vis.s.chart.protovis.Sunburst.prototype.populateData = function (thisObject) {
105 
106     rec(this.data);
107     //console.log(this.data);
108     this.formattedData = this.data;
109 
110     function rec(d) {
111         for( i in d ) {
112             if( typeof(d[i]) == "string" && isNaN(d[i]) ) {
113                 d[i] = 0;
114             }
115             rec(d[i]);
116         }
117     }
118 };
119 
120 wso2vis.s.chart.protovis.Sunburst.prototype.getData = function (thisObject) {
121 
122     return thisObject.formattedData;
123 };
124 
125 wso2vis.s.chart.protovis.Sunburst.prototype.update = function () {
126 
127     this.populateData(this);
128     this.wedge.extend(pv.Layout.sunburst(this.formattedData).size(function(n) { return parseInt(n); })); 
129     //this.sunburst.size(Number);//console.log(JSON.stringify(this.data));
130     this.vis.render();
131     if(this.tooltip() === true) {
132         tooltip.init();
133     }
134 };
135 
136 wso2vis.s.chart.protovis.Sunburst.prototype.getDataLable = function (i) {
137 
138     if (this.data !== null){
139 
140         var rootObj = this.traverseToDataField(this.data, this.dataField());
141         if( rootObj instanceof Array ) {
142             return  this.traverseToDataField(rootObj[i], this.dataLabel());
143         }
144         else {
145             return  this.traverseToDataField(rootObj, this.dataLabel());
146         }
147     }
148     
149     return i;
150 };
151 
152