class: center, middle, title-slide .contextLL[d3-Unconf | 2017 | David Richards] # Hierarchical Datasets ### When? What? How? --- .context[hierarchical data] # Our Goal? By the end of this session,
you should have a
solid understanding,
and a comfort with,
hierarchical datasets. -- ### We will learn: -- 1. *When* do they matter? -- 2. *What* are they? -- 3. *How* do we work with them?
-- ... & some d3 visuals
-- (Today we focus on the data. We'll apply it to visuals, but that'll be light.) --- class: center, middle ## When do they matter? --- .context[hierarchical data] # When do they matter?
Smart data structures and dumb code works a lot better
than the other way around.
.author[—Eric S. Raymond (The Cathedral and the Bazaar)]
-- Bad programmers worry about the code.
Good programmers worry about data structures and their relationships.
.author[—Linus Torvalds]
-- “Data! Data! Data!" he cried impatiently.
"I can't make bricks without clay.”
.author[—Sherlock Holmes]
-- .center[**They matter now....**] --- name: natural-hierarchies .context[when it matters] # Natural hierarchies Some data is naturally hierarchical: --- template: natural-hierarchies * Country ⇢ State ⇢ City ⇢ Street ⇢ House ``` json { "continent": "North America", "countries": [ { "country": "Canada" }, { "country": "Mexico" }, { "country": "United States", "states": [ { "state": "California" }, { "state": "Indiana", "cities": [ { "city": "Fishers" }, { "city": "Carmel" }, { "city": "Indianapolis" } ] } ] } ] } ``` --- template: natural-hierarchies .context[when it matters] * Country ⇢ State ⇢ City ⇢ Street ⇢ House * CEO ⇢ EVP ⇢ SVP ⇢ VP ⇢ DIR ⇢ MGR -- * Folder ⇢ Subfolder ⇢ File -- * Dictionary ⇢ Letter ⇢ Word ⇢ Part-of-speech ⇢ Definitions ⇢ Examples
.right[
] --- .context[when it matters] # Natural hierarchies --
Other examples of naturally occurring hierarchies?
--- .context[when it matters] # Natural hierarchies
Other examples of naturally occurring hierarchies?
Paper & Pencil exercise:
Draw a picture of a dataset that you want to work with that is hierarchical.
.right[(taxonomies & hierarchies are a natural fit)] --- .context[when it matters] # d3 examples
--- class: center, middle ## What are they? --- .context[what are they] # Model your data with Legos _How do we make this “real” for participants? Label blocks? Or use colors for data types?_ --- .context[what are they] # Hierarchy vs. Tabular
Hierarchical
Tabular
Relationships are intrinsic
Relationships formed at run-time
smaller data
larger data
a couple of layers of one-to-many relationships
many-to-many relationships
gateway to sunbursts, trees, treemaps, circle packs, and who knows what else
--- .context[what are they] # Hierarchical data = JSON Arrays + JSON Objects ## JSON Array `[ "Listen", "Learn", "Grow" ]` 1. an ordered list of values, seperated by commas 2. it can store strings, numbers, booleans, objects, other arrays, or a combination 3. surrounded by [ and ] (square brackets)
-- ## JSON Object `{ "name": "John", "age": 30, "motto": [ "Listen", "Learn", "Grow" ] }` 1. a list of key/value pairs * each pair is seperated a comma * keys and values are separated by a colon 2. each key is a string; each value is a strings, numbers, booleans, objects, other arrays 3. surrounded by { and } (curly braces) --- .context[what are they] # --- class: center, middle ## How do we work with them? --- .context[how to work with them] # Read the docs ([d3-hierarchy](https://github.com/d3/d3-hierarchy "d3 hierarchy api documentation")) We're moving from concept to code. `stratify` --- class: center, middle ## Some d3 visuals --- .context[examples] # Zip through some examples * Simple Treemap * Same script, but more data * Same script, create original hierarchy from tabular * Same script, create more data hierarchy from tabular --- .contextLL[slides created with remark.js] # Thanks!