Friday, 1 July 2022

Reusable d3 charts with optional functionality

I encapsulated d3 charts into function as suggested best practice from creator in blog Towards Reusable Charts. Is it possible to create optional functionalities on top of this chart, so calling specific function would trigger it, otherwise it would be omitted.

Working JSFiddle example (base working example from Rob Moore's blog)

In JS line 56 I added a function which I'd like to create and then conditionally call in line 67.

My current way of doing it, is creating a boolean and setting it to false and then calling function with argument true. Problem of doing it this way is that the code gets too many conditionals and edge cases.

P.S. this question is not meant to be a discussion how to correctly apply axis to the chart. This is just an example.



from Reusable d3 charts with optional functionality

No comments:

Post a Comment