Book Image

Mastering D3.js

Book Image

Mastering D3.js

Overview of this book

Table of Contents (19 chapters)
Mastering D3.js
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating reusable charts


A chart is a visual representation of a dataset. As datasets grow in complexity and number of elements, we might want to encapsulate the chart in a reusable piece of code to share it and use it in other projects. The success of the reusability of the chart depends on the choices made during the design process.

We will follow the proposal given in the article Towards Reusable Charts by Mike Bostock with some modifications. Charts created with this model will have the following attributes:

  • Configurable: The chart appearance and behavior can be modified without having to change the code of the chart. The chart should expose an API that allows customization.

  • Repeatable: A chart can be rendered in a selection that contains several elements, displaying independent visualizations in each node. The update process and the variables associated to the data items must be independent as well.

  • Composable: A consequence of the previous attributes is that a chart can have inner...