D3.js vs Vue.js examples
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.3 KiB

7 years ago
<!--
7 years ago
It would be great if you color the map by population using data from index.vue
7 years ago
Based on:
http://bl.ocks.org/rveciana/a2a1c21ca1c71cd3ec116cc911e5fce9
7 years ago
http://bl.ocks.org/mapsam/6083585
7 years ago
Links:
-->
<template>
<svg width="500" height="300"></svg>
</template>
<script>
const d3 = require('d3');
7 years ago
const topojson = require('topojson')
7 years ago
export default {
mounted: function() {
7 years ago
var v = this;
7 years ago
var svg = d3.select(this.$el);
var width = +svg.attr('width');
var height = +svg.attr('height');
var projection = d3.geoAlbersUsa();
7 years ago
var path = d3.geoPath().projection(projection);
d3.json("static/data/us.json", function(error, us) {
var g = svg.append('g');
g
.selectAll('.state')
.data(topojson.feature(us, us.objects.usStates).features)
.enter()
.append("path")
.attr("class", "state")
.attr("d", path)
.on('mouseover', function(d) {
v.$emit('stateSelected', d.properties.STATE_ABBR)
})
.on('mouseout', function(d) {
v.$emit('stateDeselected', d.properties.STATE_ABBR)
})
g.attr('transform', 'scale(0.57)')
7 years ago
});
}
// TODO: fire events
}
</script>
7 years ago
<style>
.state {
fill: #ccc;
stroke: #fff;
}
.state:hover {
fill: steelblue;
}
</style>