function leftVisualization() {
const initialValue = top5_company_dispatches;
const svg = d3.create('svg')
.attr('width', width2 + margin2.left + margin2.right)
.attr('height', height2 + margin2.top + margin2.bottom)
.property('value', initialValue);
svg.append("text")
.attr("x", width2 / 2)
.attr("y", 0)
.attr("text-anchor", "middle")
.attr("dominant-baseline", "hanging")
.attr("font-family", "sans-serif")
.attr("font-size", "16px")
.text("# Dispatched Trips over Time");
const xAxis = d3.axisBottom(time_scale);
const yAxis = d3.axisLeft(dispatched_trips);
svg.append("g")
.call(xAxis)
.attr("transform", `translate(0, ${height2-20})`)
.append("text")
.attr("x", width2 / 2)
.attr("y", 40)
.attr("fill", "black")
.attr("text-anchor", "middle")
.text("Year");
svg.append("g")
.call(yAxis)
.attr("transform", `translate(${margin2.left-10},0)`)
.append("text")
.attr("x", -20)
.attr("y", 10)
.attr("fill", "black")
.attr("text-anchor", "middle")
.text("# Dispatched Trips");
const radius = 3;
const dots = svg.selectAll('circle')
.data(top5_company_dispatches)
.join('circle')
.attr('cx', d => time_scale(d["timestamp"]))
.attr('cy', d => dispatched_trips(d["Total Dispatched Trips"]))
.attr('fill', d => colors(d["Base Name"]))
.attr('opacity', 1)
.attr('r', radius);
const brush = d3.brush()
.extent([[margin2.left, margin2.top], [width2, height2]])
.on('brush', onBrush)
.on('end', onEnd);
svg.append('g')
.call(brush);
function onBrush(event) {
const [[x1, y1], [x2, y2]] = event.selection;
function isBrushed(d) {
const cx = time_scale(d["timestamp"]);
const cy = dispatched_trips(d["Total Dispatched Trips"])
return cx >= x1 && cx <= x2 && cy >= y1 && cy <= y2;
}
dots.attr('fill', d => isBrushed(d) ? colors(d["Base Name"]):'gray');
svg.property('value', dispatched_trips.filter(isBrushed)).dispatch('input');
}
function onEnd(event) {
if (event.selection === null) {
dots.attr('fill', d => colors(d["Base Name"]))
svg.property('value', initialValue).dispatch('input');
}
}
return svg.node();
}