TennisVisuals / updating-radar-chart

Updating Radar Chart Visualization with extensive configuration options
MIT License
13 stars 7 forks source link

Potential for removing redundant code? #6

Closed PeterVermont closed 8 years ago

PeterVermont commented 8 years ago

Thanks for sharing this. I appreciate the very clear spacing of the update, enter, and exit selections.

I am new-ish to d3 so this may be off-base but my reading says that anything processed in the enter section is automatically appended to the update selection.

This means that is you move your update selection code below your enter selection code you should be able to remove all code that is in both the enter and update selections.

I see this in many d3 examples and would guess it is one of the most common mistakes and, like any duplicated code, is an opportunity for inadvertent bugs as the 'duplicate' code sections can diverge.

Hope I am on the right track!

TennisVisuals commented 8 years ago

Hi Peter ~

Thanks for your comment. You are absolutely correct.

There was a method to the madness, however, though I pushed the code out there before I had worked through it entirely!

The code in the update section occurs after the enter() and then upon each update.
The update sections each begin with a .transition() statement.

The idea was that an initial value would be set in the enter() section and then a transition would be made to the values in the update section. So, there is the potential that they would not be equivalent. In fact, when there is a transition delay the radar chart is seen to fly in from the upper left. This is because I didn't tidy everything up and add proper values for the .enter() section to center the chart before any other transitions begin!

I will probably leave the code as it is until I rewrite it completely for D3v4. I've made many improvements to my standard template as I've continued to learn about D3.

Regards, Charles