viewof selection2 = {
const svg = d3.create('svg')
.attr('width', 1000)
.attr('height', visHeight + margin.top + margin.bottom);
const rowHeight = 20;
const fontSize = 15;
const rows = svg.selectAll('g')
.data(Provinces)
.join('g')
.attr('transform', (d, i) => `translate(755, ${i * rowHeight + 5})`);
rows.append('rect')
.attr('width', fontSize)
.attr('height', fontSize)
.attr('stroke-width', 2)
.attr('stroke', d => carColor(d))
.attr('fill', d => carColor(d))
.on('click', onclick);
rows.append('text')
.attr('font-size', fontSize)
.attr('x', rowHeight)
.attr('y', fontSize / 2)
.attr('font-family', 'sans-serif')
.attr('dominant-baseline', 'middle')
.text(d => d);
const selected = new Map(Provinces.map(d => [d, true]));
function onclick(event, d) {
const isSelected = selected.get(d);
const square = d3.select(this);
square.attr('fill', d => isSelected ? 'white' : carColor(d));
selected.set(d, !isSelected);
svg.property('value', selected).dispatch('input');
}
svg.property('value', selected).dispatch('input');
const g = svg.append('g')
.attr('transform', `translate(${margin.left}, ${margin.top})`);
g.append("g").call(xAxis, x, 'time');
g.append("g").call(yAxis, y, 'numconf');
g.selectAll('circle')
.data(data1.filter(d => selections.get(d.prname)))
.join('circle')
.attr('cx', d => x(d.date))
.attr('cy', d => y(d.numconf))
.attr('fill', d => carColor(d.prname))
.attr('opacity', 1)
.attr('r', 3);
return svg.node();
}