Skip to Content
D3 for the Impatient
book

D3 for the Impatient

by Philipp K. Janert
May 2019
Intermediate to advanced
256 pages
6h 5m
English
O'Reilly Media, Inc.
Content preview from D3 for the Impatient

Chapter 10. Utilities: Arrays, Statistics, and Timestamps

D3 includes some ancillary features that mostly augment JavaScript’s built-in functionality. In this chapter, I’ll introduce two topics because they are so common and commonly useful: operations on arrays, including basic descriptive statistics for strictly numerical arrays, and support for working with dates and timestamps.

Structural Array Manipulations

D3 includes some functions that change the structure of arrays (of arbitrary types). Table 10-1 summarizes some of the most useful of these functions and those that are used elsewhere in this book.

Table 10-1. D3 functions to create and manipulate JavaScript arrays
Function Description

d3.range(start, stop, step)

Returns an array of uniformly spaced numbers, between start (inclusive) and stop (exclusive), obtained by repeatedly adding step to start. The step size need not be an integer and may be negative. If only a single argument is supplied, it is interpreted as stop; in this case start defaults to 0 and step defaults to 1. If two arguments are supplied, they are interpreted as start and stop; step again defaults to 1.

d3.shuffle( array, low, high )

Performs an in-place random shuffle on a subarray, bounded by array indices low (inclusive) and high (exclusive). If the bounds are omitted, the entire array is shuffled. Returns the array.

d3.cross(a, b, reducer)

Returns the Cartesian product of the arrays a and b as a one-dimensional array. The reducer

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

D3.js Quick Start Guide

D3.js Quick Start Guide

Matthew Huntington

Publisher Resources

ISBN: 9781492046783Errata Page