In the code below, I seek to insert 3 strings on screen one next to the other
To do so, I need to calculate the screen width of the labels that I have been already displayed, as highlighted in the attr("x",...)
line.
How do I refer to the previous elements during a selection in d3?
References: How to refer to the previous element, how to calculate width of text before displaying it
var labels = ['a label', 'another label', 'a third label']
var textItems = svg.append('g')
.selectAll('.my_labels_text')
.data(labels)
.enter()
.append("text")
.attr("class", "my_labels_text")
.attr("text-anchor", "left")
.attr("x", function (d, i) { return <cumulated width of labels previously displayed>})
.attr("y", 10) // arbitrary y value
.text(function(d) { return d })