Skip to content

Commit a995ceb

Browse files
committedApr 18, 2016
fixing bugs, adding options
1 parent 8b3ba26 commit a995ceb

File tree

4 files changed

+58
-31
lines changed

4 files changed

+58
-31
lines changed
 

‎public/lib/vectormap_controller.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@ var module = require('ui/modules').get('vectormap');
44

55
module.controller('VectormapController', function ($scope) {
66
$scope.$watch('esResponse', function (resp) {
7-
if (!resp) {
7+
if (!resp || !resp.aggregations) {
88
$scope.data = null;
99
return;
1010
}
1111

1212
var geoCodeAggId = _.first(_.pluck($scope.vis.aggs.bySchemaName['segment'], 'id'));
1313
var metricsAgg = _.first($scope.vis.aggs.bySchemaName['metric']);
14-
15-
var buckets = resp.aggregations[geoCodeAggId].buckets;
14+
var buckets = resp.aggregations[geoCodeAggId] && resp.aggregations[geoCodeAggId].buckets;
1615

1716
$scope.data = {};
1817

1918
buckets.forEach(function (bucket) {
20-
$scope.data[bucket.key.toUpperCase()] = metricsAgg.getValue(bucket);
19+
var prefix = $scope.vis.params.mapType === 'us_aea' ? 'US-' : '';
20+
$scope.data[prefix + bucket.key.toUpperCase()] = metricsAgg.getValue(bucket);
2121
});
2222
});
2323
});

‎public/lib/vectormap_directive.js

+29-25
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var _ = require('lodash');
22
var $ = require('jquery');
3+
var numeral = require('numeral');
34

45
// jvectormap - version 2.0.3
56
require('plugins/vectormap/lib/jvectormap/jquery-jvectormap.min');
@@ -10,7 +11,23 @@ var module = require('ui/modules').get('vectormap');
1011
module.directive('vectormap', function () {
1112
function link (scope, element) {
1213

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+
}
1431

1532
scope.$watch('data',function(){
1633
render();
@@ -29,51 +46,38 @@ module.directive('vectormap', function () {
2946
render();
3047
});
3148

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-
4049
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%'
4453
});
4554

4655
element.text('');
4756

57+
// Remove previously drawn vector map
4858
$('.jvectormap-zoomin, .jvectormap-zoomout, .jvectormap-label').remove();
49-
59+
5060
require(['plugins/vectormap/lib/jvectormap/maps/map.' + scope.options.mapType], function () {
5161
element.vectorMap({
5262
map: scope.options.mapType,
5363
regionStyle: { initial: { fill: '#8c8c8c' }},
54-
zoomOnScroll: false,
64+
zoomOnScroll: scope.options.zoomOnScroll,
5565
backgroundColor: null,
5666
series: {
5767
regions: [{
5868
values: scope.data,
59-
scale: scope.options.colors,
69+
scale: [scope.options.minColor, scope.options.maxColor],
6070
normalizeFunction: 'polynomial'
6171
}]
6272
},
63-
onRegionLabelShow: function(event, label, code) {
64-
element.children('.map-legend').show();
73+
onRegionTipShow: function(event, el, code) {
74+
if (!scope.data) { return; }
75+
6576
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)));
7078
}
7179
});
7280
});
73-
74-
element.prepend('<span class="map-legend"></span>');
75-
76-
$('.map-legend').hide();
7781
}
7882
}
7983

‎public/vectormap.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ function VectormapProvider(Private) {
1717
params: {
1818
defaults: {
1919
mapType: 'world_mill',
20-
colors: ['#A0E2E2', '#265656']
20+
minColor: '#A0E2E2',
21+
maxColor: '#265656',
22+
zoomOnScroll: false,
23+
tipNumberFormat: 'number'
2124
},
2225
editor: require('plugins/vectormap/vectormap_vis_params.html')
2326
},

‎public/vectormap_vis_params.html

+21-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div class="form-group">
22
<div class="form-group">
3-
<label>Map Type</label>
3+
<h3>Map Type</h3>
44
<select ng-model="vis.params.mapType" class="form-control">
55
<option value="world_mill" selected="selected">World</option>
66
<option value="africa_mill">Africa</option>
@@ -12,4 +12,24 @@
1212
<option value="us_aea">USA</option>
1313
</select>
1414
</div>
15+
16+
<!-- Color Scale -->
17+
<div class="form-group">
18+
<h3>Map Color Scale</h3>
19+
<label>Min Color: </label>
20+
<input type="text" ng-model="vis.params.minColor"><br>
21+
<label>Max Color: </label>
22+
<input type="text" ng-model="vis.params.maxColor">
23+
</div>
24+
25+
<!-- Tooltip Number Format Type -->
26+
<div class="form-group">
27+
<h3>Tooltip Number Format</h3>
28+
<select ng-model="vis.params.tipNumberFormat" class="form-control">
29+
<option value="number" selected="selected">number</option>
30+
<option value="bytes">bytes</option>
31+
<option value="currency">currency</option>
32+
<option value="percentage">percentage</option>
33+
</select>
34+
</div>
1535
</div>

0 commit comments

Comments
 (0)
Please sign in to comment.