rveciana - using-rollup-with-d3-composite-projections

Using rollup with d3-composite-projections

Open raw page in new tab

This example is part of this blog entry and shows how to use rollup to create a custom bundle with the library d3-composite-projections.

To use this example, just download the files from the gist

git clone https://gist.github.com/0e73c92391def44331d2069755edc199.git

and then:

npm install
npm run build

I took the information from this post by Richa Vyas.

<!DOCTYPE html>
<meta charset="utf-8">
<style>

.states {
  fill: #ccc;
  stroke: #fff;
}
</style>
<body>
<script src="d3.min.js"></script>

<script>
var width = 960,
    height = 500;

var projection = d3.geoConicConformalSpain();
var path = d3.geoPath()
    .projection(projection);

var svg = d3.select("body").append("svg")
    .attr("width", width)
    .attr("height", height);

    var t = d3.transition();
d3.json("provincias.json", function(error, spain) {
  var spain = d3.feature(spain, spain.objects.provincias);
  svg.selectAll(".region")
      .data(spain.features)
      .enter()
      .append("path")
      .attr("class", "region")
      .attr("d", path)
      .style("fill", "#aca")
      .style("stroke", "#000")
      .style("stroke-width", "0.5px")
      .on("mouseover", function(d,i) {
        d3.select(this).interrupt();
        d3.select(this)
          .transition(t)
          .style("fill", "red");
        })
      .on("mouseout", function(d,i) {
        d3.select(this).interrupt();
        d3.select(this)
          .transition(t)
          .style("fill", "#aca");
        });;

  svg
    .append("path")
      .style("fill","none")
      .style("stroke","#f00")
      .attr("d", projection.getCompositionBorders());

});

</script>