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

Choropleth keep d3.geoAlbers the default projection but deprecate it #1382

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ language: node_js
node_js:
- '8'
script:
- 'if [ "${TRAVIS_PULL_REQUEST}" = "false" ]; then grunt ci; else grunt ci; fi'
- 'if [ "${TRAVIS_PULL_REQUEST}" = "false" ]; then grunt ci; else grunt ci-pull; fi'
env:
global:
- secure: Kt+5IJDJRVwr28xRnmR5YDsJceXDcDR21/JUBfk6DYFixPbIq7LCPnZUmiSZQs8akU95ucXwB5hsirUAdEhXdYKilec6go70lticVlZBLy8IdJ+Di1uPwMOeMHvalC2P0woIRJSMzP8u5E+e+5ASggTjsXID7/p1rE0jXtoOueQ=
Expand Down
36 changes: 25 additions & 11 deletions src/geo-choropleth-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ dc.geoChoroplethChart = function (parent, chartGroup) {
});

var _geoPath = d3.geoPath();
var _projectionFlag;
var _projection;

var _geoJsons = [];

Expand All @@ -50,13 +50,12 @@ dc.geoChoroplethChart = function (parent, chartGroup) {
regionG
.append('path')
.attr('fill', 'white')
.attr('d', _geoPath);
.attr('d', _getGeoPath());

regionG.append('title');

plotData(layerIndex);
}
_projectionFlag = false;
};

function plotData (layerIndex) {
Expand Down Expand Up @@ -168,11 +167,7 @@ dc.geoChoroplethChart = function (parent, chartGroup) {
_chart._doRedraw = function () {
for (var layerIndex = 0; layerIndex < _geoJsons.length; ++layerIndex) {
plotData(layerIndex);
if (_projectionFlag) {
_chart.svg().selectAll('g.' + geoJson(layerIndex).name + ' path').attr('d', _geoPath);
}
}
_projectionFlag = false;
};

/**
Expand Down Expand Up @@ -211,22 +206,41 @@ dc.geoChoroplethChart = function (parent, chartGroup) {
};

/**
* Set custom geo projection function. See the available
* Gets or sets a custom geo projection function. See the available
* {@link https://github.com/d3/d3-geo/blob/master/README.md#projections d3 geo projection functions}.
*
* Starting version 3.0 it has been deprecated to rely on the default projection being
* {@link https://github.com/d3/d3-geo/blob/master/README.md#geoAlbersUsa d3.geoAlbersUsa()}. Please
* set it explicitly. {@link https://bl.ocks.org/mbostock/5557726
* Considering that `null` is also a valid value for projection}, if you need
* projection to be `null` please set it explicitly to `null`.
* @method projection
* @memberof dc.geoChoroplethChart
* @instance
* @see {@link https://github.com/d3/d3-geo/blob/master/README.md#projections d3.projection}
* @see {@link https://github.com/d3/d3-geo-projection d3-geo-projection}
* @param {d3.projection} [projection=d3.geoAlbersUsa()]
* @returns {dc.geoChoroplethChart}
* @returns {d3.projection|dc.geoChoroplethChart}
*/
_chart.projection = function (projection) {
_geoPath.projection(projection);
_projectionFlag = true;
if (!arguments.length) {
return _projection;
}

_projection = projection;
return _chart;
};

var _getGeoPath = function () {
if (_projection === undefined) {
dc.logger.warn('choropleth projection default of geoAlbers is deprecated,' +
' in next version projection will need to be set explicitly');
return _geoPath.projection(d3.geoAlbersUsa());
}

return _geoPath.projection(_projection);
};

/**
* Returns all GeoJson layers currently registered with this chart. The returned array is a
* reference to this chart's internal data structure, so any modification to this array will also
Expand Down
7 changes: 6 additions & 1 deletion web/vc/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ <h2>US Venture Capital Landscape 2011</h2>
.overlayGeoJson(statesJson.features, "state", function (d) {
return d.properties.name;
})
.projection(d3.geoAlbersUsa())
// .projection(d3.geoAlbersUsa())
.valueAccessor(function(kv) {
console.log(kv);
return kv.value;
Expand Down Expand Up @@ -227,6 +227,11 @@ <h2>US Venture Capital Landscape 2011</h2>
});

dc.renderAll();

setTimeout(function () {
usChart.projection(d3.geoAlbers());
usChart.render();
}, 6000);
});
});
</script>
Expand Down