Debian Codegraph @

dojox/geo/charting/widget/Legend.js

raw symbols SCIP
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 // summary:
16 // A legend widget displaying association between colors and Feature value ranges.
17 //
18 // description:
19 // This widget basically is a table comprising (icon,string) pairs, describing the color scheme
20 // used for the map and its associated text descriptions.
21 //
22
23 // example:
24 // | var legend = new dojox.geo.charting.widget.Legend({
25 // | map: map
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 // compatibility with older version : add to map domNode if not already attached to a parentNode.
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 // summary:
49 // Refreshes this legend contents when Map series has changed.
50
51 // cleanup
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 });