Working with scales
In data visualization, we will always have to deal with mapping our dataset to a specific range of pixels. Let me give you an example. We have a dataset [0, 2, 4, 6, 8, 10]
that we want to display for mobile and desktop devices. On mobiles, we want to display the dataset with a total width of 480px
and on desktops with a width of 1024px
. In order to draw the dataset on these pixel ranges, we need to map it to these ranges. We can see this example in the following figure:
D3.js provides a very useful tool to map a dataset to a certain range of pixels: d3.scale
. In D3.js, we call the mapping function's scale, the slice of the dataset that we want to map the domain to, and the pixel range on which we want to map the dataset range. In the following figure, we can see a dataset, where only the positive values are mapped to the width of the axis:
In order to represent different data types with scales, we distinguish...