| 1 |
define([ |
| 2 |
"dojo/_base/kernel", |
| 3 |
"dojo/_base/lang", |
| 4 |
"dojo/_base/array", |
| 5 |
"dojo/_base/declare", |
| 6 |
"dojo/_base/html", |
| 7 |
"dojo/dom", |
| 8 |
"dojo/dom-construct", |
| 9 |
"dojo/dom-class", |
| 10 |
"dojo/_base/window", |
| 11 |
"dijit/_Widget" |
| 12 |
], function(dojo, lang, arr, declare, html,dom,domConstruct,domClass, win, Widget){ |
| 13 |
|
| 14 |
return declare("dojox.geo.charting.widget.Legend",Widget, { |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
horizontal:true, |
| 28 |
legendBody:null, |
| 29 |
swatchSize:18, |
| 30 |
map:null, |
| 31 |
postCreate: function(){ |
| 32 |
if(!this.map){return;} |
| 33 |
this.series = this.map.series; |
| 34 |
if(!this.domNode.parentNode){ |
| 35 |
|
| 36 |
dom.byId(this.map.container).appendChild(this.domNode); |
| 37 |
} |
| 38 |
this.refresh(); |
| 39 |
}, |
| 40 |
buildRendering: function(){ |
| 41 |
this.domNode = domConstruct.create("table", |
| 42 |
{role: "group", "class": "dojoxLegendNode"}); |
| 43 |
this.legendBody = domConstruct.create("tbody", null, this.domNode); |
| 44 |
this.inherited(arguments); |
| 45 |
}, |
| 46 |
|
| 47 |
refresh: function(){ |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
while(this.legendBody.lastChild){ |
| 53 |
domConstruct.destroy(this.legendBody.lastChild); |
| 54 |
} |
| 55 |
|
| 56 |
if(this.horizontal){ |
| 57 |
domClass.add(this.domNode,"dojoxLegendHorizontal"); |
| 58 |
this._tr = win.doc.createElement("tr"); |
| 59 |
this.legendBody.appendChild(this._tr); |
| 60 |
} |
| 61 |
|
| 62 |
var s = this.series; |
| 63 |
if(s.length == 0){return;} |
| 64 |
|
| 65 |
arr.forEach(s,function(x){ |
| 66 |
this._addLabel(x.color, x.name); |
| 67 |
},this); |
| 68 |
}, |
| 69 |
_addLabel:function(color,label){ |
| 70 |
var icon = win.doc.createElement("td"); |
| 71 |
var text = win.doc.createElement("td"); |
| 72 |
var div = win.doc.createElement("div"); |
| 73 |
domClass.add(icon, "dojoxLegendIcon"); |
| 74 |
domClass.add(text, "dojoxLegendText"); |
| 75 |
div.style.width = this.swatchSize + "px"; |
| 76 |
div.style.height = this.swatchSize + "px"; |
| 77 |
icon.appendChild(div); |
| 78 |
|
| 79 |
if(this.horizontal){ |
| 80 |
this._tr.appendChild(icon); |
| 81 |
this._tr.appendChild(text); |
| 82 |
}else{ |
| 83 |
var tr = win.doc.createElement("tr"); |
| 84 |
this.legendBody.appendChild(tr); |
| 85 |
tr.appendChild(icon); |
| 86 |
tr.appendChild(text); |
| 87 |
} |
| 88 |
|
| 89 |
div.style.background = color; |
| 90 |
text.innerHTML = String(label); |
| 91 |
} |
| 92 |
}); |
| 93 |
}); |