chart = {
const svg = d3
.create("svg")
.attr('width', width)
.attr('height', height);
data.forEach(function(value, key) {
let dotsActive = svg
.selectAll(`.active-dot[user=${value.get('active')[0].id}]`)
.data(getOffsets(value.get('active')))
.enter()
.append('circle')
.attr('r', 3)
.attr('class', 'active-dot')
.attr('user', d => {
return d.id;
})
.attr('cx', d => {
return xScale(d.time);
})
.attr('cy', d => {
return yScale(d.delta);
})
.style('fill', activeColor);
let dotsSedentary = svg
.selectAll(`.sedentary-dot[user=${value.get('active')[0].id}]`)
.data(getOffsets(value.get('sedentary')))
.enter()
.append('circle')
.attr('r', 3)
.attr('class', 'sedentary-dot')
.attr('user', d => {
return d.id;
})
.attr('cx', d => {
return xScale(d.time);
})
.attr('cy', d => {
return yScale(d.delta);
})
.style('fill', sedentaryColor);
svg
.append('path')
.datum(getOffsets(value.get('sedentary')))
.attr('class', 'sedentary-line')
.attr('user', d => {
return d.id;
})
.attr('d', line)
.style('fill', 'none')
.style('stroke', sedentaryColor);
svg
.append('path')
.datum(getOffsets(value.get('active')))
.attr('class', 'active-line')
.attr('user', d => {
return d.id;
})
.attr('d', line)
.style('fill', 'none')
.style('stroke', activeColor);
});
let yAxis = svg
.append("g")
.attr('id', 'y-axis')
.call(yAxisGenerator)
.call(g => g.select(".domain").remove());
let xAxis = svg
.append("g")
.attr('id', 'x-axis')
.call(xAxisGenerator)
.call(g => g.select(".domain").remove());
return svg.node();
}