Suppose I have the following D3 code:

```
var bar = chart.selectAll("g").data(data)
    .enter().append("g")
    .attr("width", function(d) {return calculateValue(d)+1})
    .attr("height", function(d) {return calculateValue(d)*2});

```

And let's suppose that the calculateValue() function is somewhat expensive. What is the best way to pre-calculate the value for each item in the data?

I have done something like this to pre-calculate the values:

```
var bar = chart.selectAll("g").data(data)
    .enter().append("g")
    .each(function(d) {d._preCalculated = calculateValue(d)})
    .attr("width", function(d) {return d._preCalculated+1})
    .attr("height", function(d) {return d._preCalculated*2});

```

But I don't like this approach because I don't want to mutate the data. I would rather use some external context or scope to accomplish this. Is it possible?