I have a stackblitz here - https://stackblitz.com/edit/chart-update-1-34uvdo?file=src/app/bar-chart.ts
It's a d3 chart in an angular app.
The bars have arrows to show the start and finish position of the bar.
I'd like to have each bar arrow compo in one g element - at the moment they are all in the same g element.
How can I craete a g element for each bar and arrow.
bar.enter()
.append("line")
.attr("x1", d => this.x(d.phase) + this.x.bandwidth() / 2)
.attr("y1", d => this.y(d.start) + ((d.start < d.finish) ? -5 : 5))
.attr("x2", d => this.x(d.phase) + this.x.bandwidth() / 2)
.attr("y2", d => this.y(d.finish) + ((d.start < d.finish) ? 5 : -5))
.attr("stroke", "black")
.attr("stroke-width", 3)
.attr("marker-end", "url(#arrow)")
.style('pointer-events', 'none');
Have a look again at the d3 general update pattern. It is one of those d3 concepts that will always be a little confusing, especially when applying it to anything except the simplest examples.
So by looking at the above pattern we can break it down as:
Updated stackblitz