Skip to content

Commit d69243c

Browse files
committed
added margin to map so it aligns with other charts
1 parent d5614b8 commit d69243c

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/minicharts/d3fns/geo.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
var d3 = require('d3');
22
var _ = require('lodash');
3-
// var shared = require('./shared');
3+
var shared = require('./shared');
44
var debug = require('debug')('scout:minicharts:geo');
55
var mapStyle = require('./mapstyle');
66
// var async = require('async');
@@ -11,7 +11,7 @@ var format = require('util').format;
1111

1212
var SHIFTKEY = 16;
1313
var APIKEY = 'AIzaSyDrhE1qbcnNIh4sK3t7GEcbLRdCNKWjlt0';
14-
14+
// var APIKEY = 'AIzaSyDrhE1qbcnNIh4sZp47GEcbLRdCNKWjlt4'; // wrong one
1515
// function produceKey(text) {
1616
// var key = 'Error: Google map could not be loaded, disabling feature';
1717
// var res = xor(key, text);
@@ -57,14 +57,13 @@ var minicharts_d3fns_geo = function() {
5757
view: null
5858
};
5959

60-
// var margin = shared.margin;
60+
var margin = shared.margin;
6161

6262
function disableMapsFeature() {
6363
// disable both in feature flag (for this run) and localStorage
6464
app.setFeature('Google Map Minicharts', false);
6565
localStorage.disableGoogleMaps = true;
6666
delete window.google;
67-
debug('parent render', options.view.parent.render());
6867
options.view.parent.render();
6968
}
7069

@@ -211,6 +210,15 @@ var minicharts_d3fns_geo = function() {
211210
selection.each(function(data) {
212211
var el = d3.select(this);
213212

213+
var innerDiv = el.selectAll('div.map').data([null]);
214+
innerDiv.enter().append('div')
215+
.attr('class', 'map')
216+
.style({
217+
width: (width - margin.left - margin.right) + 'px',
218+
height: (height - margin.top - margin.bottom) + 'px',
219+
padding: margin.top + 'px ' + margin.right + 'px ' + margin.bottom + 'px ' + margin.left + 'px;'
220+
});
221+
214222
if (!window.google) {
215223
loadGoogleMaps(function(err) {
216224
if (err) {
@@ -255,7 +263,7 @@ var minicharts_d3fns_geo = function() {
255263

256264
if (!googleMap) {
257265
// Create the Google Map
258-
googleMap = new google.maps.Map(el.node(), {
266+
googleMap = new google.maps.Map(innerDiv.node(), {
259267
disableDefaultUI: true,
260268
// disableDoubleClickZoom: true,
261269
scrollwheel: true,
@@ -306,7 +314,7 @@ var minicharts_d3fns_geo = function() {
306314
}; // end overlay.draw
307315

308316
overlay.setMap(googleMap);
309-
el.on('mousedown', startSelection);
317+
innerDiv.on('mousedown', startSelection);
310318

311319
d3.select('body')
312320
.on('keydown', onKeyDown)
@@ -361,7 +369,6 @@ var minicharts_d3fns_geo = function() {
361369
}
362370
});
363371
} else {
364-
debug('toplevel location field. fitting map.');
365372
_.defer(function() {
366373
google.maps.event.trigger(googleMap, 'resize');
367374
googleMap.fitBounds(bounds);

0 commit comments

Comments
 (0)