Skip to content

Commit

Permalink
Merge pull request #41 from markmarkoh/update-choropleth
Browse files Browse the repository at this point in the history
allowing for the updating of colors after drawing
  • Loading branch information
markmarkoh committed Jan 21, 2014
2 parents c785ae6 + ff9a78e commit 32b6fce
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 199 deletions.
25 changes: 24 additions & 1 deletion dist/datamaps.all.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/datamaps.all.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/datamaps.none.min.js

Large diffs are not rendered by default.

25 changes: 24 additions & 1 deletion dist/datamaps.usa.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
function addContainer( element ) {
this.svg = d3.select( element ).append('svg')
.attr('width', element.offsetWidth)
.attr('class', 'datamap')
.attr('height', element.offsetHeight);

return this.svg;
Expand Down Expand Up @@ -80,7 +81,7 @@
function addStyleBlock() {
if ( d3.select('.datamaps-style-block').empty() ) {
d3.select('head').attr('class', 'datamaps-style-block').append('style')
.html('path {stroke: #FFFFFF; stroke-width: 1px;} .datamaps-legend dt, .datamaps-legend dd { float: left; margin: 0 3px 0 0;} .datamaps-legend dd {width: 20px; margin-right: 6px; border-radius: 3px;} .datamaps-legend {padding-bottom: 20px; z-index: 1001; position: absolute; left: 4px; font-size: 12px; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;} .datamaps-hoverover {display: none; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; } .hoverinfo {padding: 4px; border-radius: 1px; background-color: #FFF; box-shadow: 1px 1px 5px #CCC; font-size: 12px; border: 1px solid #CCC; } .hoverinfo hr {border:1px dotted #CCC; }');
.html('.datamap path {stroke: #FFFFFF; stroke-width: 1px;} .datamaps-legend dt, .datamaps-legend dd { float: left; margin: 0 3px 0 0;} .datamaps-legend dd {width: 20px; margin-right: 6px; border-radius: 3px;} .datamaps-legend {padding-bottom: 20px; z-index: 1001; position: absolute; left: 4px; font-size: 12px; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;} .datamaps-hoverover {display: none; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; } .hoverinfo {padding: 4px; border-radius: 1px; background-color: #FFF; box-shadow: 1px 1px 5px #CCC; font-size: 12px; border: 1px solid #CCC; } .hoverinfo hr {border:1px dotted #CCC; }');
}
}

Expand Down Expand Up @@ -513,6 +514,28 @@
.attr('class', className || '');
};

Datamap.prototype.updateChoropleth = function(data) {
var svg = this.svg;
for ( var subunit in data ) {
if ( data.hasOwnProperty(subunit) ) {
var color;
if ( typeof data[subunit] === "string" ) {
color = data[subunit];
}
else if ( typeof data[subunit].color === "string" ) {
color = data[subunit].color;
}
else {
color = this.options.fills[ data[subunit].fillKey ];
}
svg
.selectAll('.' + subunit)
.transition()
.style('fill', color);
}
}
};

Datamap.prototype.updatePopup = function (element, d, options) {
var self = this;
element.on('mousemove', null);
Expand Down
4 changes: 2 additions & 2 deletions dist/datamaps.usa.min.js

Large diffs are not rendered by default.

25 changes: 24 additions & 1 deletion dist/datamaps.world.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/datamaps.world.min.js

Large diffs are not rendered by default.

25 changes: 24 additions & 1 deletion src/js/datamaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
function addContainer( element ) {
this.svg = d3.select( element ).append('svg')
.attr('width', element.offsetWidth)
.attr('class', 'datamap')
.attr('height', element.offsetHeight);

return this.svg;
Expand Down Expand Up @@ -80,7 +81,7 @@
function addStyleBlock() {
if ( d3.select('.datamaps-style-block').empty() ) {
d3.select('head').attr('class', 'datamaps-style-block').append('style')
.html('path {stroke: #FFFFFF; stroke-width: 1px;} .datamaps-legend dt, .datamaps-legend dd { float: left; margin: 0 3px 0 0;} .datamaps-legend dd {width: 20px; margin-right: 6px; border-radius: 3px;} .datamaps-legend {padding-bottom: 20px; z-index: 1001; position: absolute; left: 4px; font-size: 12px; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;} .datamaps-hoverover {display: none; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; } .hoverinfo {padding: 4px; border-radius: 1px; background-color: #FFF; box-shadow: 1px 1px 5px #CCC; font-size: 12px; border: 1px solid #CCC; } .hoverinfo hr {border:1px dotted #CCC; }');
.html('.datamap path {stroke: #FFFFFF; stroke-width: 1px;} .datamaps-legend dt, .datamaps-legend dd { float: left; margin: 0 3px 0 0;} .datamaps-legend dd {width: 20px; margin-right: 6px; border-radius: 3px;} .datamaps-legend {padding-bottom: 20px; z-index: 1001; position: absolute; left: 4px; font-size: 12px; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;} .datamaps-hoverover {display: none; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; } .hoverinfo {padding: 4px; border-radius: 1px; background-color: #FFF; box-shadow: 1px 1px 5px #CCC; font-size: 12px; border: 1px solid #CCC; } .hoverinfo hr {border:1px dotted #CCC; }');
}
}

Expand Down Expand Up @@ -513,6 +514,28 @@
.attr('class', className || '');
};

Datamap.prototype.updateChoropleth = function(data) {
var svg = this.svg;
for ( var subunit in data ) {
if ( data.hasOwnProperty(subunit) ) {
var color;
if ( typeof data[subunit] === "string" ) {
color = data[subunit];
}
else if ( typeof data[subunit].color === "string" ) {
color = data[subunit].color;
}
else {
color = this.options.fills[ data[subunit].fillKey ];
}
svg
.selectAll('.' + subunit)
.transition()
.style('fill', color);
}
}
};

Datamap.prototype.updatePopup = function (element, d, options) {
var self = this;
element.on('mousemove', null);
Expand Down
Loading

0 comments on commit 32b6fce

Please sign in to comment.