1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
/**
* Represents map legend.
* @constructor
* @param {Object} params Configuration parameters.
* @param {String} params.cssClass Additional CSS class to apply to legend element.
* @param {Boolean} params.vertical If <code>true</code> legend will be rendered as vertical.
* @param {String} params.title Legend title.
* @param {Function} params.labelRender Method to convert series values to legend labels.
*/
jvm.Legend = function(params) {
this.params = params || {};
this.map = this.params.map;
this.series = this.params.series;
this.body = jvm.$('<div/>');
this.body.addClass('jvectormap-legend');
if (this.params.cssClass) {
this.body.addClass(this.params.cssClass);
}
if (params.vertical) {
this.map.legendCntVertical.append( this.body );
} else {
this.map.legendCntHorizontal.append( this.body );
}
this.render();
}
jvm.Legend.prototype.render = function(){
var ticks = this.series.scale.getTicks(),
i,
inner = jvm.$('<div/>').addClass('jvectormap-legend-inner'),
tick,
sample,
label;
this.body.html('');
if (this.params.title) {
this.body.append(
jvm.$('<div/>').addClass('jvectormap-legend-title').html(this.params.title)
);
}
this.body.append(inner);
for (i = 0; i < ticks.length; i++) {
tick = jvm.$('<div/>').addClass('jvectormap-legend-tick');
sample = jvm.$('<div/>').addClass('jvectormap-legend-tick-sample');
switch (this.series.params.attribute) {
case 'fill':
if (jvm.isImageUrl(ticks[i].value)) {
sample.css('background', 'url('+ticks[i].value+')');
} else {
sample.css('background', ticks[i].value);
}
break;
case 'stroke':
sample.css('background', ticks[i].value);
break;
case 'image':
sample.css('background', 'url('+ticks[i].value+') no-repeat center center');
break;
case 'r':
jvm.$('<div/>').css({
'border-radius': ticks[i].value,
border: this.map.params.markerStyle.initial['stroke-width']+'px '+
this.map.params.markerStyle.initial['stroke']+' solid',
width: ticks[i].value * 2 + 'px',
height: ticks[i].value * 2 + 'px',
background: this.map.params.markerStyle.initial['fill']
}).appendTo(sample);
break;
}
tick.append( sample );
label = ticks[i].label;
if (this.params.labelRender) {
label = this.params.labelRender(label);
}
tick.append( jvm.$('<div>'+label+' </div>').addClass('jvectormap-legend-tick-text') );
inner.append(tick);
}
inner.append( jvm.$('<div/>').css('clear', 'both') );
}
|