map = {
const width = 900
const R = 5
const curve = d3.line().curve(d3.curveBumpX);
const settings = [["Northeast", [-77.189941,40.245992, 2] ], ["Southwest", [-60,40.245992, 2] ], ["Northwest", [-60,40.245992, 2] ] ]
const zoom = d3.zoom()
.scaleExtent([1, 8])
.on('zoom', zoomed)
function clicked(e, d) {
const center = projection([-77.189941,40.245992])
e.stopPropagation();
svg.transition().duration(750).call(
zoom.transform,
d3.zoomIdentity
.translate(width / 2, height / 2)
.scale(2)
.translate(-center[0], -center[1]),
d3.pointer(e, svg.node())
);
}
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height])
const heightScale = d3.scaleLinear().domain([0, 10000]).range([2, 15])
const arcGenerator = d3.arc()
.outerRadius(d => heightScale(d.base))
.innerRadius(0)
.startAngle(-Math.PI / 2)
.endAngle(Math.PI / 2);
const defs = svg.append('defs')
defs
.append('marker')
.attr('id', 'arrow')
.attr('orient', 'auto')
.attr('markerHeight', 25)
.attr('markerWidth', 25)
.attr('viewBox', "0 0 12 12")
.attr('refX', 6)
.attr('refY', 6)
.append('path')
.attr('d', "M2,2 L10,6 L2,10 L6,6 L2,2")
.attr('fill', '#B84E58')
defs.selectAll('gradients')
.data(connections)
.join('linearGradient')
.attr("id", (d, i) => `gradient${i}`)
.attr('x1', d => d.lon > d.match.lon ? 1 : 0)
.attr('x2', d => d.lon > d.match.lon ? 0 : 1)
.selectAll('stops')
.data(d => [{offset: 0, color: 'steelblue'},
{offset: .7, color: '#B84E58'}])
.join('stop')
.attr('offset', s => s.offset)
.attr('stop-color', s => s.color )
const g = svg.append("g")
g.append("path")
.datum(topojson.merge(us, us.objects.lower48.geometries))
.attr("fill", "#ddd")
.attr("d", d3.geoPath())
.on('click', clicked);
g.append("path")
.datum(topojson.mesh(us, us.objects.lower48, (a, b) => a !== b))
.attr("fill", "none")
.attr("stroke", "white")
.attr("stroke-linejoin", "round")
.attr("d", d3.geoPath())
g.selectAll('circle')
.data(connections)
.join('path')
.attr('transform', d => `translate(${projection([d.lon, d.lat])[0]},${projection([d.lon, d.lat])[1]} )`)
.attr('d', d => arcGenerator(d))
.attr('fill', 'steelblue')
.attr('stroke', 'white')
g.selectAll('line')
.data(connections)
.join('path')
.attr('d', d => curve([projection([d.lon, d.lat]), projection([d.match.lon, d.match.lat]) ] ))
.attr('stroke',(d, i) => `url(#gradient${i})`)
.attr('stroke-width', 1)
.attr('opacity', .7)
.attr('fill', 'none')
.attr('marker-end', 'url(#arrow)')
.on('mouseover', function(d, obj){
d3.select(this).attr('stroke-width', 3).attr('opacity', 1)
mutable chosenResort = `${obj.name} will have as long of a season as ${obj.match.name}`
})
.on('mouseout', function(){d3.select(this).attr('stroke-width', 1).attr('opacity', .7) })
g.call(zoom)
function zoomed(e) {
g.attr('transform', e.transform)
}
return svg.node()
}