Data Visualization (DSC 530/CIS 568)dkoop/dsc530-2019sp/lectures/lecture08.pdf · D3.js is a...

20
Data Visualization (DSC 530/CIS 568) D3 and Marks & Channels Dr. David Koop D. Koop, DSC 530, Spring 2019

Transcript of Data Visualization (DSC 530/CIS 568)dkoop/dsc530-2019sp/lectures/lecture08.pdf · D3.js is a...

Page 1: Data Visualization (DSC 530/CIS 568)dkoop/dsc530-2019sp/lectures/lecture08.pdf · D3.js is a JavaScript library for manipulating documents based on data. D3 helps you bring data to

Data Visualization (DSC 530/CIS 568)

D3 and Marks & Channels

Dr. David Koop

D. Koop, DSC 530, Spring 2019

Page 2: Data Visualization (DSC 530/CIS 568)dkoop/dsc530-2019sp/lectures/lecture08.pdf · D3.js is a JavaScript library for manipulating documents based on data. D3 helps you bring data to

Tasks

�2

[Munzner (ill. Maguire), 2014]D. Koop, DSC 530, Spring 2019

Trends

Actions

Analyze

Search

Query

Why?

All Data

Outliers Features

Attributes

One ManyDistribution Dependency Correlation Similarity

Network Data

Spatial DataShape

Topology

Paths

Extremes

ConsumePresent EnjoyDiscover

ProduceAnnotate Record Derive

Identify Compare Summarize

tag

Target known Target unknown

Location knownLocation unknown

Lookup

Locate

Browse

Explore

Targets

Why?

How?

What?

Page 3: Data Visualization (DSC 530/CIS 568)dkoop/dsc530-2019sp/lectures/lecture08.pdf · D3.js is a JavaScript library for manipulating documents based on data. D3 helps you bring data to

Memorability

�3

HIGH QUALITY DESCRIPTION

LOW QUALITY

DESCRIPTION

MEMORABLE

FORGETTABLE[M. Borkin et al., InfoVis 2015]

D. Koop, DSC 530, Spring 2019

Page 4: Data Visualization (DSC 530/CIS 568)dkoop/dsc530-2019sp/lectures/lecture08.pdf · D3.js is a JavaScript library for manipulating documents based on data. D3 helps you bring data to

Memorability of Visualizations• S. Few: "Visualizations don’t need to be designed for memorability

– they need to be designed for comprehension. For most visualizations, the comprehension that they provide need only last until the decision that it informs is made. Usually, that is only a matter of seconds."

• B. Jones (paraphrased): People make decisions using visualizations but this isn't instantaneous like robots or algorithms; they often chew on a decision for a while

• R. Kosara: there are cases where people benefit from remembering a visualization (e.g. health-related visualization)

• Are there tradeoffs between the characteristics?

�4D. Koop, DSC 530, Spring 2019

Page 5: Data Visualization (DSC 530/CIS 568)dkoop/dsc530-2019sp/lectures/lecture08.pdf · D3.js is a JavaScript library for manipulating documents based on data. D3 helps you bring data to

Visualization for Production: Derived Data

�5

[Munzner (ill. Maguire), 2014]D. Koop, DSC 530, Spring 2019

Original Data

exports

imports

Derived Data

trade balance = exports − imports

trade balance

Page 6: Data Visualization (DSC 530/CIS 568)dkoop/dsc530-2019sp/lectures/lecture08.pdf · D3.js is a JavaScript library for manipulating documents based on data. D3 helps you bring data to

Visualization for Production• Generate new material • Annotate:

- Add more to a visualization - Usually associated with text, but can be graphical

• Record: - Persist visualizations for historical record - Provenance (graphical histories): how did I get here?

• Derive (Transform): - Create new data - Create derived attributes (e.g. mathematical operations,

aggregation)

�6D. Koop, DSC 530, Spring 2019

Page 7: Data Visualization (DSC 530/CIS 568)dkoop/dsc530-2019sp/lectures/lecture08.pdf · D3.js is a JavaScript library for manipulating documents based on data. D3 helps you bring data to

Actions: Search

• What does a user know? • Lookup: check bearings • Locate: find on a map • Browse: what’s nearby • Explore: where to go (patterns)

�7

[Munzner (ill. Maguire), 2014]D. Koop, DSC 530, Spring 2019

Analyze

Search

Query

ConsumePresent EnjoyDiscover

ProduceAnnotate Record Derive

Identify Compare Summarize

tag

Target known Target unknown

Location known

Location unknown

Lookup

Locate

Browse

Explore

Actions

Page 8: Data Visualization (DSC 530/CIS 568)dkoop/dsc530-2019sp/lectures/lecture08.pdf · D3.js is a JavaScript library for manipulating documents based on data. D3 helps you bring data to

Query

• Number of targets: One, Some (Often 2), or All • Identify: characteristics or references • Compare: similarities and differences • Summarize: overview of everything

�8

[Munzner (ill. Maguire), 2014]D. Koop, DSC 530, Spring 2019

Analyze

Search

Query

ConsumePresent EnjoyDiscover

ProduceAnnotate Record Derive

Identify Compare Summarize

tag

Target known Target unknown

Location known

Location unknown

Lookup

Locate

Browse

Explore

Actions

Page 9: Data Visualization (DSC 530/CIS 568)dkoop/dsc530-2019sp/lectures/lecture08.pdf · D3.js is a JavaScript library for manipulating documents based on data. D3 helps you bring data to

Assignment 2• Create a stacked bar chart using three different tools: Tableau,

Vega-Lite, and D3 • Due Monday, Feb. 25

�9D. Koop, DSC 530, Spring 2019

Page 10: Data Visualization (DSC 530/CIS 568)dkoop/dsc530-2019sp/lectures/lecture08.pdf · D3.js is a JavaScript library for manipulating documents based on data. D3 helps you bring data to

d3.js

�10

Overview Examples Documentation Source

Data-Driven Documents

D3.js is a JavaScript library for manipulating documents based on data. D3 helps you bring data tolife using HTML, SVG, and CSS. D3’s emphasis on web standards gives you the full capabilities ofmodern browsers without tying yourself to a proprietary framework, combining powerful visualizationcomponents and a data-driven approach to DOM manipulation.

See more examples.

D. Koop, DSC 530, Spring 2019

Page 11: Data Visualization (DSC 530/CIS 568)dkoop/dsc530-2019sp/lectures/lecture08.pdf · D3.js is a JavaScript library for manipulating documents based on data. D3 helps you bring data to

Data-Driven Documents (D3)• JavaScript Library • http://d3js.org/ • Original Authors: Mike Bostock, Vadim Ogievestky, and Jeff Heer • Open Source • Focus on Web standards, customization, and usability • Grew from work on Protovis: more standard, more interactive • By nature, a low-level library; you have control over all elements

and styles if you wish • A top project on GitHub (over 80,000 stars as of 2/8/2017) • Lots of impressive examples

- Bostock was a New York Times Graphics Editor - http://bost.ocks.org/mike/

�11D. Koop, DSC 530, Spring 2019

Page 12: Data Visualization (DSC 530/CIS 568)dkoop/dsc530-2019sp/lectures/lecture08.pdf · D3.js is a JavaScript library for manipulating documents based on data. D3 helps you bring data to

D3 Key Features• Supports data as a core piece of Web elements

- Loading data - Dealing with changing data (joins, enter/update/exit) - Correspondence between data and DOM elements

• Selections (similar to CSS) that allow greater manipulation • Method Chaining • Integrated layout algorithms, axes calculations, etc. • Focus on interaction support

- Straightforward support for transitions - Event handling support for user-initiated changes

�12D. Koop, DSC 530, Spring 2019

Page 13: Data Visualization (DSC 530/CIS 568)dkoop/dsc530-2019sp/lectures/lecture08.pdf · D3.js is a JavaScript library for manipulating documents based on data. D3 helps you bring data to

D3 Introduction• Ogievetsky has put together a nice set of interactive examples that

show off the major features of D3 • http://dakoop.github.io/IntroD3/

- (Updated from original for D3 v5 with new joins) • https://beta.observablehq.com/@dakoop/d3-intro • Other references:

- Murrary’s book on Interactive Data Visualization for the Web - The D3 website: d3js.org - Ros's Slides on v4: https://iros.github.io/d3-v4-whats-new/

�13D. Koop, DSC 530, Spring 2019

Page 14: Data Visualization (DSC 530/CIS 568)dkoop/dsc530-2019sp/lectures/lecture08.pdf · D3.js is a JavaScript library for manipulating documents based on data. D3 helps you bring data to

D3 Data Joins• Two groups: data and visual elements • Three parts of the join between them: enter, update, and exit • enter: s.enter(), update: s, exit: s.exit()

�14D. Koop, DSC 530, Spring 2019

Data Visual Elements

Enter Update Exit

Page 15: Data Visualization (DSC 530/CIS 568)dkoop/dsc530-2019sp/lectures/lecture08.pdf · D3.js is a JavaScript library for manipulating documents based on data. D3 helps you bring data to

Merge vs. Join• Merge creates a new selection that includes the items from both

selections - If you want to update all elements (including those just added via

enter), use merge! - Useful when enter+update have similar transitions

• Join allows you to modify different parts of the selection in a single statement - Also will create the final selection - Does enter+append and exit+remove automatically - Pass functions to modify the enter, update, and exit parts of the

selection - Examples: https://beta.observablehq.com/@d3/selection-join

�15D. Koop, DSC 530, Spring 2019

Page 16: Data Visualization (DSC 530/CIS 568)dkoop/dsc530-2019sp/lectures/lecture08.pdf · D3.js is a JavaScript library for manipulating documents based on data. D3 helps you bring data to

Transitions• Nested transitions (those that "hang off" of a parent transition)

follow immediately after the parent transition

�16D. Koop, DSC 530, Spring 2019

Page 17: Data Visualization (DSC 530/CIS 568)dkoop/dsc530-2019sp/lectures/lecture08.pdf · D3.js is a JavaScript library for manipulating documents based on data. D3 helps you bring data to

Data In Tableau

• Categorical data = Dimension • Quantitative data = Measures

�17D. Koop, DSC 530, Spring 2019

Attributes

Attribute Types

Ordering Direction

Categorical Ordered

Ordinal Quantitative

Sequential Diverging Cyclic

Page 18: Data Visualization (DSC 530/CIS 568)dkoop/dsc530-2019sp/lectures/lecture08.pdf · D3.js is a JavaScript library for manipulating documents based on data. D3 helps you bring data to

Toward Reusable Charts• D3 does not provide "standard" charts • E.g. there is no barchart method • What is a standard chart?

- "Should you expose the underlying scales and axes, or encapsulate them with chart-specific representations?"

- "Should your chart support interaction and animation automatically?"

- "Should the user be able to reach into your chart and tweak some aspect of its behavior?"

�18

[Towards Reusable Charts, M. Bostock, 2012]D. Koop, DSC 530, Spring 2019

Page 19: Data Visualization (DSC 530/CIS 568)dkoop/dsc530-2019sp/lectures/lecture08.pdf · D3.js is a JavaScript library for manipulating documents based on data. D3 helps you bring data to

Visual Encoding• How should we visualize this data?

�19D. Koop, DSC 530, Spring 2019

Name Region Population Life Expectancy Income

China East Asia & Pacific 1335029250 73.28 7226.07

India South Asia 1140340245 64.01 2731

United States America 306509345 79.43 41256.08

Indonesia East Asia & Pacific 228721000 71.17 3818.08

Brazil America 193806549 72.68 9569.78

Pakistan South Asia 176191165 66.84 2603

Bangladesh South Asia 156645463 66.56 1492

Nigeria Sub-Saharan Africa 141535316 48.17 2158.98

Japan East Asia & Pacific 127383472 82.98 29680.68

Mexico America 111209909 76.47 11250.37

Philippines East Asia & Pacific 94285619 72.1 3203.97

Vietnam East Asia & Pacific 86970762 74.7 2679.34

Germany Europe & Central Asia 82338100 80.08 31191.15

Ethiopia Sub-Saharan Africa 79996293 55.69 812.16

Turkey Europe & Central Asia 72626967 72.06 8040.78

Page 20: Data Visualization (DSC 530/CIS 568)dkoop/dsc530-2019sp/lectures/lecture08.pdf · D3.js is a JavaScript library for manipulating documents based on data. D3 helps you bring data to

Potential Solution

�20

Share ! " #Bubbles $

Color

Select

Size

Zoom20152015

30

40

50

60

70

80

year

s

Life

exp

ecta

ncy ▼

1800 1900 2000

World Regions

Search...

Afghanistan

Albania

Algeria

Andorra

Angola

Antigua and Barbuda

Argentina

Armenia

Australia

Austria

Azerbaijan

Bahamas

Bahrain

Bangladesh

Barbados

Belarus

Population, total

100100%%

OPTIONS EXPAND PRESENT

English ▼ FACTS TEACH ABOUT ►HOW TO USE

[Gapminder, Wealth & Health of Nations]D. Koop, DSC 530, Spring 2019