Top Banner
INTRODUCTION TO D3 _by Oleksii Prohonnyi
60

Introduction to D3.js

Feb 23, 2017

Download

Software

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Introduction to D3.js

INTRODUCTION TO D3

_by Oleksii Prohonnyi

Page 2: Introduction to D3.js
Page 3: Introduction to D3.js

DATA VISUALIZATION

Page 4: Introduction to D3.js

Overview Data visualization is the presentation of data in a pictorial

or graphical format.

Reasons to use:

helps people see things that were not obvious to them before;

patterns can be spotted quickly and easily;

conveys information in a universal manner;

answer questions like “What would happen if we made an adjustment to that area?”.

Page 5: Introduction to D3.js
Page 6: Introduction to D3.js
Page 7: Introduction to D3.js
Page 8: Introduction to D3.js
Page 9: Introduction to D3.js

Tools

Charts wizards (Libre Office, MS Office, Numbers)

Google Charts

Modest Maps (mapping tool)

Visual.ly

Tableau

RAW (from Density Design)

D3.js

Page 10: Introduction to D3.js

See more

www.storytellingwithdata.com

vizwiz.blogspot.com

www.visualisingdata.com

flowingdata.com

helpmeviz.com

plot.ly (collaboration online tool)

Page 11: Introduction to D3.js

D3 IS NOT A SILVER BULLET!

Page 12: Introduction to D3.js

ALTERNATIVES

Page 13: Introduction to D3.js

D3.js alternatives

Cytoscape.js

C3.js

Canvas.js

Datacopia

Panxpan

See more: alternativeto.net

Page 14: Introduction to D3.js

ABOUT D3

Page 15: Introduction to D3.js

Introduction

D3.js is a JavaScript library for manipulating documents based on data.

D3 - Data-Driven Documents

d3js.org

github.com/mbostock/d3

github.com/mbostock/d3/wiki/API-Reference

Page 16: Introduction to D3.js

BAD PARTS

Page 17: Introduction to D3.js

D3 is bad at

Being a chart library

Being Backward compatible

Rendering things for you

Abstracting basic graphic primitives

Source: ireneros.com

Page 18: Introduction to D3.js

GOOD PARTS

Page 19: Introduction to D3.js

D3 is good at

Providing a way to map data to documents.

Being a general purpose visualization library

Handling data transformation

Providing basic math & layout algorithms

Source: ireneros.com

Page 20: Introduction to D3.js

D3 VS JQUERY

Page 21: Introduction to D3.js

D3 is a little like jQuery (jQuery)

Page 22: Introduction to D3.js

D3 is a little like jQuery (D3)

Page 23: Introduction to D3.js

Source: bl.ocks.org

Page 24: Introduction to D3.js

PRE-CONDITIONS

Page 25: Introduction to D3.js

Index.html

Page 26: Introduction to D3.js

SELECTIONS

Page 27: Introduction to D3.js

Selections A selection is an array of elements pulled from the current

document. D3 uses CSS3 to select elements.

After selecting elements, you apply operators to them to do stuff. These operators can get or set attributes, styles, properties, HTML and text content.

d3.select(selector), d3.select(node)

d3.selectAll(selector), d3.selectAll(nodes)

See more: github.com/mbostock/d3/wiki/Selections

Page 28: Introduction to D3.js

Select element and style it a bit

Page 29: Introduction to D3.js

EXTERNAL DATA

Page 30: Introduction to D3.js

External data files d3.csv - request a comma-separated values (CSV) file.

d3.html - request an HTML document fragment.

d3.json - request a JSON blob.

d3.text - request a text file.

d3.tsv - request a tab-separated values (TSV) file.

d3.xhr - request a resource using XMLHttpRequest.

d3.xml - request an XML document fragment.

See more: github.com/mbostock/d3/wiki/Requests

Page 31: Introduction to D3.js

Create simple data file

Page 32: Introduction to D3.js

DATA JOINTS

Page 33: Introduction to D3.js

Data joints

The act of creating a mapping between data points and the objects representing them.

[1,2,3] -> µ £ ¥ [1,2,3] -> <div>1</div>

<div>2</div>

<div>3</div>

See more: github.com/mbostock/d3/wiki/Requests

Page 34: Introduction to D3.js

Fetch data from file

Page 35: Introduction to D3.js

SCALES

Page 36: Introduction to D3.js

What do scales should be used?

Source: ireneros.com

Page 38: Introduction to D3.js

Create scales for data

Page 39: Introduction to D3.js

DYNAMIC PROPERTIES

Page 40: Introduction to D3.js

What do dynamic properties do?

Styles, attributes, and other properties can be specified as functions of data in D3, not just simple constants.

Computed properties often refer to bound data. Data is specified as an array of values, and each value is passed as the first argument (d) to selection functions.

See more: d3js.org/#properties

Page 41: Introduction to D3.js

Set label position due to data

Page 42: Introduction to D3.js

Demo: <presentation-code-root>/index.html

Page 43: Introduction to D3.js

OTHER D3 FEATURES

Page 44: Introduction to D3.js

Layouts A layout encapsulates a strategy for laying out data elements

visually, relative to each other. Many layouts are built in to D3 itself:

Chord - produce a chord diagram from a matrix of relationships.

Partition - recursively partition a node tree into a sunburst or icicle.

Pie - compute the start and end angles for arcs in a pie or donut chart.

Tree - position a tree of nodes tidily.

etc.

See more: github.com/mbostock/d3/wiki/Layouts

Page 45: Introduction to D3.js

Transitions

A special type of selection where the operators apply smoothly over time rather than instantaneously.

May have per-element delays and durations, computed using functions of data similar to other operators.

Multiple transitions may operate on any selection sequentially or in parallel.

See more: github.com/mbostock/d3/wiki/Transitions

Page 46: Introduction to D3.js

Geography

Paths - display geographic shapes.

Projections - convert locations (latitude and longitude) to pixel coordinates.

Streams - streaming geometry transformations.

Page 48: Introduction to D3.js

MORE EXAMPLES

Page 50: Introduction to D3.js

Source: jasondavies.com

Page 52: Introduction to D3.js

ONE MORE THING

Page 53: Introduction to D3.js

How to select a chart type?

Main purpose of data visualization:

Comparison

Composition

Distribution

Relationship

See more: goo.gl/1jkVNk

Try by yourself: goo.gl/gl6Q4R

Page 54: Introduction to D3.js

Source: storytellingwithdata.com

Page 55: Introduction to D3.js

REFERENCES

Page 57: Introduction to D3.js

DIVE INTO D3

Page 58: Introduction to D3.js

LvivJS 2015 presentation:

D3.JS TIPS & TRICKS(export to svg, crossfilter, maps etc.)

See and download: goo.gl/SSzp5C

Page 59: Introduction to D3.js

THANK YOUFOR ATTENTION