Tasks = (g, xScale) =>
g
.selectAll('.task')
.data(Data, d => d.name + +d.time)
.join('g')
.attr('class', 'task')
.each(function(d) {
let data = d;
let it = null;
if (d.activeDuration === 0 || onlySHAPES) {
it = d3
.select(this)
.selectAll('.task-shape')
.data([d], d => d.name + +d.time)
.join('path')
.attr('class', 'task-shape')
.attr(
'transform',
d =>
`translate(${xScale(
new Date(+d.time + +d.activeDuration / 2)
)},${yScale(d.name) + yScale.bandwidth() / 2}) scale(3)`
)
.attr("d", d => shape(d.name));
} else {
it = d3
.select(this)
.selectAll('.task-shape')
.data([d], d => d.name + +d.time)
.join('rect')
.attr('class', 'task-shape')
.attr('rx', d => 14)
.attr('ry', d => 14)
.attr(
'transform',
d =>
`translate(${xScale(d.time)},${yScale(d.name) +
yScale.bandwidth() / 4})`
)
.attr('height', d => yScale.bandwidth() / 2)
.attr(
'width',
d => xScale(new Date(+d.time + +d.activeDuration)) - xScale(d.time)
);
}
it.attr('fill', d =>
colorScale(Categories.indexOf(d.name) / Categories.length)
).on('mousemove', handleTaskHover);
})