Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds fillColor support to updateChoropleth #240

Merged
merged 1 commit into from
Nov 9, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions src/js/datamaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

//save off default references
var d3 = window.d3, topojson = window.topojson;

var defaultOptions = {
scope: 'world',
responsive: false,
Expand Down Expand Up @@ -99,7 +99,7 @@
d3.select(this.options.element).style({'position': 'relative', 'padding-bottom': (this.options.aspectRatio*100) + '%'});
d3.select(this.options.element).select('svg').style({'position': 'absolute', 'width': '100%', 'height': '100%'});
d3.select(this.options.element).select('svg').select('g').selectAll('path').style('vector-effect', 'non-scaling-stroke');

}

return this.svg;
Expand All @@ -111,7 +111,7 @@
var height = options.height || element.offsetHeight;
var projection, path;
var svg = this.svg;

if ( options && typeof options.scope === 'undefined') {
options.scope = 'world';
}
Expand Down Expand Up @@ -202,7 +202,7 @@
if ( datum && datum.fillKey ) {
fillColor = fillData[ val(datum.fillKey, {data: colorCodeData[d.id], geography: d}) ];
}

if ( typeof fillColor === 'undefined' ) {
fillColor = val(datum && datum.fillColor, fillData.defaultFill, {data: colorCodeData[d.id], geography: d});
}
Expand Down Expand Up @@ -263,7 +263,7 @@
d3.selectAll('.datamaps-hoverover').style('display', 'none');
});
}

function moveToFront() {
this.parentNode.appendChild(this);
}
Expand Down Expand Up @@ -310,7 +310,7 @@
this.svg.insert("path", '.datamaps-subunits')
.datum(graticule)
.attr("class", "datamaps-graticule")
.attr("d", this.path);
.attr("d", this.path);
}

function handleArcs (layer, data, options) {
Expand Down Expand Up @@ -471,14 +471,14 @@
})
.attr('r', function(datum) {
// if animation enabled start with radius 0, otherwise use full size.
return options.animate ? 0 : val(datum.radius, options.radius, datum);
return options.animate ? 0 : val(datum.radius, options.radius, datum);
})
.attr('data-info', function(d) {
return JSON.stringify(d);
})
.attr('filter', function (datum) {
var filterKey = filterData[ val(datum.filterKey, options.filterKey, datum) ];

if (filterKey) {
return filterKey;
}
Expand All @@ -495,7 +495,7 @@
.style('fill', function ( datum ) {
var fillColor = fillData[ val(datum.fillKey, options.fillKey, datum) ];
return fillColor || fillData.defaultFill;
})
})
.on('mouseover', function ( datum ) {
var $this = d3.select(this);

Expand Down Expand Up @@ -648,7 +648,7 @@
var tmpData = {};
for(var i = 0; i < data.length; i++) {
tmpData[data[i].id] = data[i];
}
}
data = tmpData;
}
Datamaps.prototype.updateChoropleth.call(self, data);
Expand Down Expand Up @@ -965,6 +965,9 @@
else if ( typeof subunitData.color === "string" ) {
color = subunitData.color;
}
else if ( typeof subunitData.fillColor === "string" ) {
color = subunitData.fillColor;
}
else {
color = this.options.fills[ subunitData.fillKey ];
}
Expand Down