{
const margin = {
top: 0,
bottom: 0,
left: -100,
right: 0,
}
const height = 500
const svg = d3.create("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
const g = svg.append("g")
.attr("width", width)
.attr("height", height)
.attr("transform", `translate(${margin.left}, ${margin.top} )`)
const rScale = d3.scaleRadial(
d3.extent(averageRidershipByStation.map(d => d.average)),
[1, 7]
)
const curve = d3.line()
.x(d => d[0])
.y(d => d[1])
.curve(d3.curveNatural)
g.append("g")
.selectAll("path")
.data(selangor.features)
.join("path")
.attr("d", geoGenerator)
.attr("fill", "black")
.attr("stroke", "white")
const kjPath = curve(
stops
.filter(stop => stop.stop_id.includes("KJ"))
.sort()
.reverse()
.map(stop => projection([stop.stop_lon, stop.stop_lat]))
)
const agPath = curve(
stops
.filter(stop => stop.stop_id.includes("AG"))
.sort()
.reverse()
.map(stop => projection([stop.stop_lon, stop.stop_lat]))
)
const spPath = curve(
stops
.filter(stop => stop.stop_id.includes("SP"))
.sort()
.reverse()
.map(stop => projection([stop.stop_lon, stop.stop_lat]))
)
g.append("g")
.append("path")
.attr("d", kjPath)
.attr("fill", "none")
.attr("stroke", "red")
.attr("stroke-opacity", 0.5)
g.append("g")
.append("path")
.attr("d", agPath)
.attr("fill", "none")
.attr("stroke", "orange")
.attr("stroke-opacity", 0.5)
g.append("g")
.append("path")
.attr("d", spPath)
.attr("fill", "none")
.attr("stroke", "yellow")
.attr("stroke-opacity", 0.5)
g.append("g")
.selectAll("circle")
.data(averageRidershipByStation)
.join("circle")
.attr("cx", d => projection([d.longitude, d.latitude])[0])
.attr("cy", d => projection([d.longitude, d.latitude])[1])
.attr("r", d => rScale(d.average))
.attr("fill", d => getLineColor(d.line))
.attr("fill-opacity", 0.5)
.attr("stroke", d => getLineColor(d.line))
.attr("stroke-opacity", 1)
return svg.node()
}