1
1
var _ = require ( 'lodash' ) ;
2
2
var $ = require ( 'jquery' ) ;
3
+ var numeral = require ( 'numeral' ) ;
3
4
4
5
// jvectormap - version 2.0.3
5
6
require ( 'plugins/vectormap/lib/jvectormap/jquery-jvectormap.min' ) ;
@@ -10,7 +11,23 @@ var module = require('ui/modules').get('vectormap');
10
11
module . directive ( 'vectormap' , function ( ) {
11
12
function link ( scope , element ) {
12
13
13
- //element.html('<center><img src="img/load_big.gif"></center>');
14
+ function onSizeChange ( ) {
15
+ return {
16
+ width : element . parent ( ) . width ( ) ,
17
+ height : element . parent ( ) . height ( )
18
+ } ;
19
+ }
20
+
21
+ function displayFormat ( val ) {
22
+ var formats = {
23
+ number : '0[.]0a' ,
24
+ bytes : '0[.]0b' ,
25
+ currency : '$0[.]00a' ,
26
+ percentage : '0%'
27
+ }
28
+
29
+ return formats [ val ] || formats . number ;
30
+ }
14
31
15
32
scope . $watch ( 'data' , function ( ) {
16
33
render ( ) ;
@@ -29,51 +46,38 @@ module.directive('vectormap', function () {
29
46
render ( ) ;
30
47
} ) ;
31
48
32
- element . bind ( 'resize' , function ( ) {
33
- scope . $apply ( ) ;
34
- } ) ;
35
-
36
- function onSizeChange ( ) {
37
- return { width : element . parent ( ) . width ( ) , height : element . parent ( ) . height ( ) } ;
38
- }
39
-
40
49
function render ( ) {
41
- element . css ( {
42
- height : element . parent ( ) . height ( ) ,
43
- width : element . parent ( ) . width ( )
50
+ element . css ( {
51
+ height : element . parent ( ) . height ( ) ,
52
+ width : '100%'
44
53
} ) ;
45
54
46
55
element . text ( '' ) ;
47
56
57
+ // Remove previously drawn vector map
48
58
$ ( '.jvectormap-zoomin, .jvectormap-zoomout, .jvectormap-label' ) . remove ( ) ;
49
-
59
+
50
60
require ( [ 'plugins/vectormap/lib/jvectormap/maps/map.' + scope . options . mapType ] , function ( ) {
51
61
element . vectorMap ( {
52
62
map : scope . options . mapType ,
53
63
regionStyle : { initial : { fill : '#8c8c8c' } } ,
54
- zoomOnScroll : false ,
64
+ zoomOnScroll : scope . options . zoomOnScroll ,
55
65
backgroundColor : null ,
56
66
series : {
57
67
regions : [ {
58
68
values : scope . data ,
59
- scale : scope . options . colors ,
69
+ scale : [ scope . options . minColor , scope . options . maxColor ] ,
60
70
normalizeFunction : 'polynomial'
61
71
} ]
62
72
} ,
63
- onRegionLabelShow : function ( event , label , code ) {
64
- element . children ( '.map-legend' ) . show ( ) ;
73
+ onRegionTipShow : function ( event , el , code ) {
74
+ if ( ! scope . data ) { return ; }
75
+
65
76
var count = _ . isUndefined ( scope . data [ code ] ) ? 0 : scope . data [ code ] ;
66
- element . children ( '.map-legend' ) . text ( label . text ( ) + ": " + count ) ;
67
- } ,
68
- onRegionOut : function ( ) {
69
- $ ( '.map-legend' ) . hide ( ) ;
77
+ el . html ( el . html ( ) + ": " + numeral ( count ) . format ( displayFormat ( scope . options . tipNumberFormat ) ) ) ;
70
78
}
71
79
} ) ;
72
80
} ) ;
73
-
74
- element . prepend ( '<span class="map-legend"></span>' ) ;
75
-
76
- $ ( '.map-legend' ) . hide ( ) ;
77
81
}
78
82
}
79
83
0 commit comments