Skip to content

Commit

Permalink
adding reset option to updateChoropleth
Browse files Browse the repository at this point in the history
  • Loading branch information
markmarkoh committed Jan 29, 2016
1 parent ea021da commit c45c73a
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 8 deletions.
13 changes: 12 additions & 1 deletion dist/datamaps.all.js
Original file line number Diff line number Diff line change
Expand Up @@ -12436,8 +12436,19 @@
.attr('class', className || '');
};

Datamap.prototype.updateChoropleth = function(data) {
Datamap.prototype.updateChoropleth = function(data, options) {
var svg = this.svg;
var that = this;

// when options.reset = true, reset all the fill colors to the defaultFill and kill all data-info
if ( options && options.reset === true ) {
svg.selectAll('.datamaps-subunit')
.attr('data-info', function() {
return "{}"
})
.transition().style('fill', this.options.fills.defaultFill)
}

for ( var subunit in data ) {
if ( data.hasOwnProperty(subunit) ) {
var color;
Expand Down
2 changes: 1 addition & 1 deletion 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.

13 changes: 12 additions & 1 deletion dist/datamaps.usa.js
Original file line number Diff line number Diff line change
Expand Up @@ -975,8 +975,19 @@
.attr('class', className || '');
};

Datamap.prototype.updateChoropleth = function(data) {
Datamap.prototype.updateChoropleth = function(data, options) {
var svg = this.svg;
var that = this;

// when options.reset = true, reset all the fill colors to the defaultFill and kill all data-info
if ( options && options.reset === true ) {
svg.selectAll('.datamaps-subunit')
.attr('data-info', function() {
return "{}"
})
.transition().style('fill', this.options.fills.defaultFill)
}

for ( var subunit in data ) {
if ( data.hasOwnProperty(subunit) ) {
var color;
Expand Down
2 changes: 1 addition & 1 deletion dist/datamaps.usa.min.js

Large diffs are not rendered by default.

13 changes: 12 additions & 1 deletion dist/datamaps.world.js
Original file line number Diff line number Diff line change
Expand Up @@ -12436,8 +12436,19 @@
.attr('class', className || '');
};

Datamap.prototype.updateChoropleth = function(data) {
Datamap.prototype.updateChoropleth = function(data, options) {
var svg = this.svg;
var that = this;

// when options.reset = true, reset all the fill colors to the defaultFill and kill all data-info
if ( options && options.reset === true ) {
svg.selectAll('.datamaps-subunit')
.attr('data-info', function() {
return "{}"
})
.transition().style('fill', this.options.fills.defaultFill)
}

for ( var subunit in data ) {
if ( data.hasOwnProperty(subunit) ) {
var color;
Expand Down
2 changes: 1 addition & 1 deletion dist/datamaps.world.min.js

Large diffs are not rendered by default.

70 changes: 70 additions & 0 deletions src/examples/update-choropleth-reset.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<!DOCTYPE html>
<html>
<head>
<style>
.active { fill: blue !important;}
/*.datamaps-key dt, .datamaps-key dd {float: none !important;}
.datamaps-key {right: -50px; top: 0;}*/
</style>
</head>
<body>

<div id="container1" style="border:1px dotted blue; width: 700px; height: 475px; position: relative;"></div>
<script src="/src/js/components/d3/d3.min.js"></script>
<script src="/src/js/components/topojson/topojson.js"></script>
<!-- <script src="/src/js/json2.js"></script> -->
<script src="/src/rel/datamaps.usa.js"></script>
<script>

var election = new Datamap({
scope: 'usa',
element: document.getElementById('container1'),
geographyConfig: {
//popupOnHover: false,
//highlightOnHover: false,
borderColor: '#444',
borderWidth: 0.5
},
bubblesConfig: {
animate: false,
popupTemplate: function(geography, data) {
return '<div class="hoverinfo">Some From New: data about ' + data.centered + '</div>'
},
fillOpacity: 0.2
},
fills: {
'Visited': '#306596',
'neato': '#0fa0fa',
'Trouble': '#bada55',
defaultFill: '#dddddd'
},
data: {
NY: {
fillKey: 'neato',
numbeers: 555
}
}
});

window.setTimeout(function() {
election.updateChoropleth({
NY: 'blue',
NJ: 'blue',
TX: {
fillKey: 'Trouble',
numbers: 555
},
FL: {
fillColor: 'blue'
}
})
}, 1500)

window.setTimeout(function() {
//election.updateChoropleth({CA: 'blue'}, {reset: true})

}, 2000)

</script>
</body>
</html>
13 changes: 12 additions & 1 deletion src/js/datamaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -975,8 +975,19 @@
.attr('class', className || '');
};

Datamap.prototype.updateChoropleth = function(data) {
Datamap.prototype.updateChoropleth = function(data, options) {
var svg = this.svg;
var that = this;

// when options.reset = true, reset all the fill colors to the defaultFill and kill all data-info
if ( options && options.reset === true ) {
svg.selectAll('.datamaps-subunit')
.attr('data-info', function() {
return "{}"
})
.transition().style('fill', this.options.fills.defaultFill)
}

for ( var subunit in data ) {
if ( data.hasOwnProperty(subunit) ) {
var color;
Expand Down

0 comments on commit c45c73a

Please sign in to comment.