Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
D3.js 4.x Data Visualization

You're reading from   D3.js 4.x Data Visualization Learn to visualize your data with JavaScript

Arrow left icon
Product type Paperback
Published in Apr 2017
Publisher Packt
ISBN-13 9781787120358
Length 308 pages
Edition 3rd Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Aendrew Rininsland Aendrew Rininsland
Author Profile Icon Aendrew Rininsland
Aendrew Rininsland
Swizec Teller Swizec Teller
Author Profile Icon Swizec Teller
Swizec Teller
Arrow right icon
View More author details
Toc

Table of Contents (11) Chapters Close

Preface 1. Getting Started with D3, ES2017, and Node.js 2. A Primer on DOM, SVG, and CSS FREE CHAPTER 3. Shape Primitives of D3 4. Making Data Useful 5. Defining the User Experience - Animation and Interaction 6. Hierarchical Layouts of D3 7. The Other Layouts 8. D3 on the Server with Canvas, Koa 2, and Node.js 9. Having Confidence in Your Visualizations 10. Designing Good Data Visualizations

Scales


We've already used scales many times -- we had a chant, if you remember; what was that again?

SURPRISE POP QUIZ:

INPUT!: [ ] DOMAIN! [ ] NOT DOMAIN!
OUTPUT!: [ ] RANGE! [ ] NOT RANGE!

If you got INPUT! = DOMAIN! and OUTPUT! = RANGE!, you are totally correct!

The reason we use scales is to avoid math. This makes our code shorter, easier to understand, and more robust, as mistakes in high school mathematics are some of the hardest bugs to track down.

To reiterate a point I've hopefully been hammering home since Chapter 1, Getting Started with D3, ES2017, and Node.js, a function's domains are those values that are defined (the input), and the range are those values it returns. The following figure is borrowed from Wikipedia:

Here, X is the domain, Y is the range, and the arrows are the functions. We need a bunch of code to implement this manually:

   let shape_color = shape => { 
     if (shape == 'triangle') { 
       return 'red'; 
     } else if (shape == 'line') { 
       return 'yellow...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image