appendix B Selecting a scale

 

This appendix aims at helping you select the right D3 scales for your data visualization projects. For further information, refer to the documentation of the d3-scale module (https://d3js.org/d3-scale).

Scales are simply functions. The values they accept as an input are part of what we call the domain (the spectrum of possible input values from the data), while the values they return as an output are part of the range (the spectrum of possible output values). The domain and the range can be made of continuous or discrete values. Continuous values can exist anywhere within a predetermined spectrum, such as a floating-point number between 0 and 100 or a date between June 2020 and January 2021. On the other hand, discrete values have a predetermined set of values, for instance, a collection of t-shirts available in the sizes XS, S, M, L, and XL or a group of colors such as blue, green, yellow, and red.

There are four scale families, introduced in chapter 3. The difference between them is the type of values (continuous or discrete) they accept as input and output. To get started, pick a family from the following list, and go to the indicated section:

  • Continuous input, continuous output: section B.1
  • Continuous input, discrete output: section B.2
  • Discrete input, continuous output: section B.3
  • Discrete input, discrete output: section B.4

B.1 Continuous input, continuous output

B.1.1 Continuous scales

B.1.2 Sequential scales

B.1.3 Diverging scales

B.2 Continuous input, discrete output

B.3 Discrete input, continuous output

B.4 Discrete input, discrete output

sitemap