SlideShare une entreprise Scribd logo
1  sur  19
D3.js
A picture is worth a thousand words
Why data visualization?
<- Because of that
But what do we GET?
{
“id” : 6,
“wall_id” : 55,
“resource_id” : 42,
“project_id” : 3,
“hours” : 3,
“intervals” : [
{
“start_date” : “2016-05-06” ,
“end_date” : “2016-05-08” ,
“booking_id” : 6
} ,
{
“start_date” : “2016-05-19” ,
“end_date” : “2016-05-19” ,
} ,
{
“start_date” : “2016-05-21” ,
“end_date” : “2016-05-24” ,
“booking_id” : 6
} ,
{
“start_date” : “2016-06-01” ,
“end_date” : “2016-10-25” ,
“booking_id” : 6
}
The two paths
The imperative one
For each of the element do…
Change width to 100px and then…
Rotate if rotate===true…
...
Then debug
The declarative one
I want the elements to be there
(I want an animation for the elements
that are not there)
I don’t give a …
how it all happens
D3 is...
Declarative approach
Data-oriented
Lots of built-in stuff
Basics of D3 - selection
JS
var selection = d3.select('#root')
.selectAll('span');
HTML
<div id="root">
</div>
● Looks a bit empty
Basics of D3 - enter, update, exit
JS
var updateSelection = d3.select('#root')
.selectAll('span');
.data([
'Lorem',
'Ipsum'
]);
updateSelection.enter().append('span');
updateSelection.text(el => el);
updateSelection.exit().remove();
HTML
<div id="root">
<span>Lorem</span>
<span>Ipsum</span>
</div>
Enter Exit
Data Elements
Update
Basics of D3 - complete render function
let render = function(data) {
let selection = d3.select('#root').selectAll('span');
let updateSelection = selection.data(data);
updateSelection.enter().append('span');
updateSelection.text(d => d);
updateSelection.exit().remove();
};
Components (codepen)
let spanComponent = function(selection) {
let updateSelection = selection.selectAll('span').data(data =>
data.lorem);
updateSelection.enter().append('span');
updateSelection.text(d => d + ' ');
updateSelection.exit().remove();
};
let render = function(data) {
let selection = d3.select('#root').selectAll('div');
let updateSelection = selection.data(data);
updateSelection.enter().append('div');
updateSelection.call(spanComponent);
updateSelection.exit().remove();
};
render([{lorem: ['foo', 'bar']}, {lorem: ['ipsum', 'dolor']}]);
Transitions (codepen)
let spanComponent = function(selection) {
let updateSelection = selection.selectAll('span').data(data =>
data.lorem);
updateSelection.enter().append('span')
.style('opacity', 0)
.transition()
.delay((d, i) => i * 400)
.duration(500)
.style('opacity', 1);
updateSelection
.text(d => d + ' ');
updateSelection.exit().remove();
};
Scales
let myLinearScale = d3.scale
.linear()
.domain([0, 10])
.range([0, 800]);
let x = myLinearScale(5);
console.log(x); // prints 400
Scales (2)
let myTimeScale = d3.time
.scale()
.domain([new Date('2016-01-01'), new Date('2017-01-01')])
.range([0, 800]);
let anyDate = new Date('2016-05-10');
let x = myTimeScale(anyDate);
myTimeScale.invert(x); // equals anyDate
SVG, Axes (codepen)
let svg = d3.select('#root').append('svg')
.attr("width", 300)
.attr("height", 300);
let x = d3.scale.linear()
.range([0, 300]);
let xAxis = d3.svg.axis()
.ticks(4)
.scale(x);
svg.append("g")
.attr("transform", "translate(0,100)")
.call(xAxis);
let line = d3.svg.line()
.x(d => d.x)
.y(d => d.y)
.interpolate('monotone');
svg.data([[ {x: x(0.1), y: 60}, {x: x(0.3), y: 20},
{x: x(0.5), y: 30}, {x: x(0.7), y: 10},
{x: x(0.9), y: 80} ]]);
svg.append("path")
.attr('fill', 'none')
.attr('stroke', '#000')
.attr("d", line);
Layouts
And much more
A lot of examples here: https://bl.ocks.org/mbostock
Thank you for your attention!
Tymoteusz Bleja
Junior Frontend Developer @ Apptension

Contenu connexe

Tendances

Making Games in JavaScript
Making Games in JavaScriptMaking Games in JavaScript
Making Games in JavaScriptSam Cartwright
 
The Ring programming language version 1.7 book - Part 48 of 196
The Ring programming language version 1.7 book - Part 48 of 196The Ring programming language version 1.7 book - Part 48 of 196
The Ring programming language version 1.7 book - Part 48 of 196Mahmoud Samir Fayed
 
The Ring programming language version 1.5 book - Part 8 of 31
The Ring programming language version 1.5 book - Part 8 of 31The Ring programming language version 1.5 book - Part 8 of 31
The Ring programming language version 1.5 book - Part 8 of 31Mahmoud Samir Fayed
 
The Ring programming language version 1.7 book - Part 63 of 196
The Ring programming language version 1.7 book - Part 63 of 196The Ring programming language version 1.7 book - Part 63 of 196
The Ring programming language version 1.7 book - Part 63 of 196Mahmoud Samir Fayed
 
Google Analytics + R. Praktyczne przykłady.
Google Analytics + R. Praktyczne przykłady.Google Analytics + R. Praktyczne przykłady.
Google Analytics + R. Praktyczne przykłady.Michal Brys
 
D3 svg & angular
D3 svg & angularD3 svg & angular
D3 svg & angular500Tech
 
Exploring Canvas
Exploring CanvasExploring Canvas
Exploring CanvasKevin Hoyt
 
The Ring programming language version 1.9 book - Part 53 of 210
The Ring programming language version 1.9 book - Part 53 of 210The Ring programming language version 1.9 book - Part 53 of 210
The Ring programming language version 1.9 book - Part 53 of 210Mahmoud Samir Fayed
 
The Ring programming language version 1.4.1 book - Part 13 of 31
The Ring programming language version 1.4.1 book - Part 13 of 31The Ring programming language version 1.4.1 book - Part 13 of 31
The Ring programming language version 1.4.1 book - Part 13 of 31Mahmoud Samir Fayed
 
Михаил Матросов, Повседневный С++: boost и STL
Михаил Матросов, Повседневный С++: boost и STLМихаил Матросов, Повседневный С++: boost и STL
Михаил Матросов, Повседневный С++: boost и STLSergey Platonov
 
Javascript Without Javascript
Javascript Without JavascriptJavascript Without Javascript
Javascript Without JavascriptPatrick Kettner
 
Ass day2 1_checkerboard...copy in cpp
Ass day2 1_checkerboard...copy in cppAss day2 1_checkerboard...copy in cpp
Ass day2 1_checkerboard...copy in cppRobi Parvez
 
[JS EXPERIENCE 2018] Jogos em JavaScript com WebGL - Juliana Negreiros, Codem...
[JS EXPERIENCE 2018] Jogos em JavaScript com WebGL - Juliana Negreiros, Codem...[JS EXPERIENCE 2018] Jogos em JavaScript com WebGL - Juliana Negreiros, Codem...
[JS EXPERIENCE 2018] Jogos em JavaScript com WebGL - Juliana Negreiros, Codem...iMasters
 
The Ring programming language version 1.5.3 book - Part 70 of 184
The Ring programming language version 1.5.3 book - Part 70 of 184The Ring programming language version 1.5.3 book - Part 70 of 184
The Ring programming language version 1.5.3 book - Part 70 of 184Mahmoud Samir Fayed
 

Tendances (20)

Scrollytelling
ScrollytellingScrollytelling
Scrollytelling
 
Making Games in JavaScript
Making Games in JavaScriptMaking Games in JavaScript
Making Games in JavaScript
 
The Ring programming language version 1.7 book - Part 48 of 196
The Ring programming language version 1.7 book - Part 48 of 196The Ring programming language version 1.7 book - Part 48 of 196
The Ring programming language version 1.7 book - Part 48 of 196
 
The Ring programming language version 1.5 book - Part 8 of 31
The Ring programming language version 1.5 book - Part 8 of 31The Ring programming language version 1.5 book - Part 8 of 31
The Ring programming language version 1.5 book - Part 8 of 31
 
D3.js workshop
D3.js workshopD3.js workshop
D3.js workshop
 
The Ring programming language version 1.7 book - Part 63 of 196
The Ring programming language version 1.7 book - Part 63 of 196The Ring programming language version 1.7 book - Part 63 of 196
The Ring programming language version 1.7 book - Part 63 of 196
 
Google Analytics + R. Praktyczne przykłady.
Google Analytics + R. Praktyczne przykłady.Google Analytics + R. Praktyczne przykłady.
Google Analytics + R. Praktyczne przykłady.
 
D3 svg & angular
D3 svg & angularD3 svg & angular
D3 svg & angular
 
MongoDB With Style
MongoDB With StyleMongoDB With Style
MongoDB With Style
 
Exploring Canvas
Exploring CanvasExploring Canvas
Exploring Canvas
 
MongoDB Oplog入門
MongoDB Oplog入門MongoDB Oplog入門
MongoDB Oplog入門
 
D3
D3D3
D3
 
The Ring programming language version 1.9 book - Part 53 of 210
The Ring programming language version 1.9 book - Part 53 of 210The Ring programming language version 1.9 book - Part 53 of 210
The Ring programming language version 1.9 book - Part 53 of 210
 
course js day 3
course js day 3course js day 3
course js day 3
 
The Ring programming language version 1.4.1 book - Part 13 of 31
The Ring programming language version 1.4.1 book - Part 13 of 31The Ring programming language version 1.4.1 book - Part 13 of 31
The Ring programming language version 1.4.1 book - Part 13 of 31
 
Михаил Матросов, Повседневный С++: boost и STL
Михаил Матросов, Повседневный С++: boost и STLМихаил Матросов, Повседневный С++: boost и STL
Михаил Матросов, Повседневный С++: boost и STL
 
Javascript Without Javascript
Javascript Without JavascriptJavascript Without Javascript
Javascript Without Javascript
 
Ass day2 1_checkerboard...copy in cpp
Ass day2 1_checkerboard...copy in cppAss day2 1_checkerboard...copy in cpp
Ass day2 1_checkerboard...copy in cpp
 
[JS EXPERIENCE 2018] Jogos em JavaScript com WebGL - Juliana Negreiros, Codem...
[JS EXPERIENCE 2018] Jogos em JavaScript com WebGL - Juliana Negreiros, Codem...[JS EXPERIENCE 2018] Jogos em JavaScript com WebGL - Juliana Negreiros, Codem...
[JS EXPERIENCE 2018] Jogos em JavaScript com WebGL - Juliana Negreiros, Codem...
 
The Ring programming language version 1.5.3 book - Part 70 of 184
The Ring programming language version 1.5.3 book - Part 70 of 184The Ring programming language version 1.5.3 book - Part 70 of 184
The Ring programming language version 1.5.3 book - Part 70 of 184
 

En vedette

Explore Data Distributions Using D3.js
Explore Data Distributions Using D3.jsExplore Data Distributions Using D3.js
Explore Data Distributions Using D3.jsSalesforce Developers
 
Testerzy na orbicie
Testerzy na orbicieTesterzy na orbicie
Testerzy na orbicieApptension
 
Narzędzia frontend developera A.D. 2015
Narzędzia frontend developera A.D. 2015Narzędzia frontend developera A.D. 2015
Narzędzia frontend developera A.D. 2015psmolenski
 
Universal Javascript in React
Universal Javascript in ReactUniversal Javascript in React
Universal Javascript in ReactApptension
 
D3 Basic Tutorial
D3 Basic TutorialD3 Basic Tutorial
D3 Basic TutorialTao Jiang
 
Team Happiness - O szczęściu w zespole
Team Happiness - O szczęściu w zespoleTeam Happiness - O szczęściu w zespole
Team Happiness - O szczęściu w zespoleApptension
 
AngularJS - podstawy
AngularJS - podstawyAngularJS - podstawy
AngularJS - podstawyApptension
 

En vedette (10)

Explore Data Distributions Using D3.js
Explore Data Distributions Using D3.jsExplore Data Distributions Using D3.js
Explore Data Distributions Using D3.js
 
Testerzy na orbicie
Testerzy na orbicieTesterzy na orbicie
Testerzy na orbicie
 
Narzędzia frontend developera A.D. 2015
Narzędzia frontend developera A.D. 2015Narzędzia frontend developera A.D. 2015
Narzędzia frontend developera A.D. 2015
 
Universal Javascript in React
Universal Javascript in ReactUniversal Javascript in React
Universal Javascript in React
 
D3 Basic Tutorial
D3 Basic TutorialD3 Basic Tutorial
D3 Basic Tutorial
 
D3.js mindblow
D3.js mindblowD3.js mindblow
D3.js mindblow
 
Team Happiness - O szczęściu w zespole
Team Happiness - O szczęściu w zespoleTeam Happiness - O szczęściu w zespole
Team Happiness - O szczęściu w zespole
 
D3 js
D3 jsD3 js
D3 js
 
White Space
White SpaceWhite Space
White Space
 
AngularJS - podstawy
AngularJS - podstawyAngularJS - podstawy
AngularJS - podstawy
 

Similaire à D3.js - A picture is worth a thousand words

Learn D3.js in 90 minutes
Learn D3.js in 90 minutesLearn D3.js in 90 minutes
Learn D3.js in 90 minutesJos Dirksen
 
Big Data for each one of us
Big Data for each one of usBig Data for each one of us
Big Data for each one of usOSCON Byrum
 
SVCC 2013 D3.js Presentation (10/05/2013)
SVCC 2013 D3.js Presentation (10/05/2013)SVCC 2013 D3.js Presentation (10/05/2013)
SVCC 2013 D3.js Presentation (10/05/2013)Oswald Campesato
 
Dynamic Data Visualization With Chartkick
Dynamic Data Visualization With ChartkickDynamic Data Visualization With Chartkick
Dynamic Data Visualization With ChartkickDax Murray
 
Visualization of Big Data in Web Apps
Visualization of Big Data in Web AppsVisualization of Big Data in Web Apps
Visualization of Big Data in Web AppsEPAM
 
Better d3 charts with tdd
Better d3 charts with tddBetter d3 charts with tdd
Better d3 charts with tddMarcos Iglesias
 
SenchaCon 2016: Add Magic to Your Ext JS Apps with D3 Visualizations - Vitaly...
SenchaCon 2016: Add Magic to Your Ext JS Apps with D3 Visualizations - Vitaly...SenchaCon 2016: Add Magic to Your Ext JS Apps with D3 Visualizations - Vitaly...
SenchaCon 2016: Add Magic to Your Ext JS Apps with D3 Visualizations - Vitaly...Sencha
 
What's Coming Next in Sencha Frameworks
What's Coming Next in Sencha FrameworksWhat's Coming Next in Sencha Frameworks
What's Coming Next in Sencha FrameworksGrgur Grisogono
 
Michael Hackstein - NoSQL meets Microservices - NoSQL matters Dublin 2015
Michael Hackstein - NoSQL meets Microservices - NoSQL matters Dublin 2015Michael Hackstein - NoSQL meets Microservices - NoSQL matters Dublin 2015
Michael Hackstein - NoSQL meets Microservices - NoSQL matters Dublin 2015NoSQLmatters
 
Create Graph and Grid Using D3 Library
Create Graph and Grid Using D3 LibraryCreate Graph and Grid Using D3 Library
Create Graph and Grid Using D3 LibraryYanliang Bao (Beryl)
 
Running Intelligent Applications inside a Database: Deep Learning with Python...
Running Intelligent Applications inside a Database: Deep Learning with Python...Running Intelligent Applications inside a Database: Deep Learning with Python...
Running Intelligent Applications inside a Database: Deep Learning with Python...Miguel González-Fierro
 

Similaire à D3.js - A picture is worth a thousand words (20)

Learn D3.js in 90 minutes
Learn D3.js in 90 minutesLearn D3.js in 90 minutes
Learn D3.js in 90 minutes
 
Big Data for each one of us
Big Data for each one of usBig Data for each one of us
Big Data for each one of us
 
Svcc 2013-d3
Svcc 2013-d3Svcc 2013-d3
Svcc 2013-d3
 
SVCC 2013 D3.js Presentation (10/05/2013)
SVCC 2013 D3.js Presentation (10/05/2013)SVCC 2013 D3.js Presentation (10/05/2013)
SVCC 2013 D3.js Presentation (10/05/2013)
 
Dynamic Data Visualization With Chartkick
Dynamic Data Visualization With ChartkickDynamic Data Visualization With Chartkick
Dynamic Data Visualization With Chartkick
 
JQuery Flot
JQuery FlotJQuery Flot
JQuery Flot
 
Visualization of Big Data in Web Apps
Visualization of Big Data in Web AppsVisualization of Big Data in Web Apps
Visualization of Big Data in Web Apps
 
HTML5 - Pedro Rosa
HTML5 - Pedro RosaHTML5 - Pedro Rosa
HTML5 - Pedro Rosa
 
Intro to HTML5
Intro to HTML5Intro to HTML5
Intro to HTML5
 
JavaScript Refactoring
JavaScript RefactoringJavaScript Refactoring
JavaScript Refactoring
 
SVGD3Angular2React
SVGD3Angular2ReactSVGD3Angular2React
SVGD3Angular2React
 
Better d3 charts with tdd
Better d3 charts with tddBetter d3 charts with tdd
Better d3 charts with tdd
 
WebXR if X = how?
WebXR if X = how?WebXR if X = how?
WebXR if X = how?
 
SenchaCon 2016: Add Magic to Your Ext JS Apps with D3 Visualizations - Vitaly...
SenchaCon 2016: Add Magic to Your Ext JS Apps with D3 Visualizations - Vitaly...SenchaCon 2016: Add Magic to Your Ext JS Apps with D3 Visualizations - Vitaly...
SenchaCon 2016: Add Magic to Your Ext JS Apps with D3 Visualizations - Vitaly...
 
What's Coming Next in Sencha Frameworks
What's Coming Next in Sencha FrameworksWhat's Coming Next in Sencha Frameworks
What's Coming Next in Sencha Frameworks
 
Fact, Fiction, and FP
Fact, Fiction, and FPFact, Fiction, and FP
Fact, Fiction, and FP
 
Michael Hackstein - NoSQL meets Microservices - NoSQL matters Dublin 2015
Michael Hackstein - NoSQL meets Microservices - NoSQL matters Dublin 2015Michael Hackstein - NoSQL meets Microservices - NoSQL matters Dublin 2015
Michael Hackstein - NoSQL meets Microservices - NoSQL matters Dublin 2015
 
NoSQL meets Microservices
NoSQL meets MicroservicesNoSQL meets Microservices
NoSQL meets Microservices
 
Create Graph and Grid Using D3 Library
Create Graph and Grid Using D3 LibraryCreate Graph and Grid Using D3 Library
Create Graph and Grid Using D3 Library
 
Running Intelligent Applications inside a Database: Deep Learning with Python...
Running Intelligent Applications inside a Database: Deep Learning with Python...Running Intelligent Applications inside a Database: Deep Learning with Python...
Running Intelligent Applications inside a Database: Deep Learning with Python...
 

Dernier

Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 

Dernier (20)

Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 

D3.js - A picture is worth a thousand words

  • 1. D3.js A picture is worth a thousand words
  • 2. Why data visualization? <- Because of that
  • 3. But what do we GET? { “id” : 6, “wall_id” : 55, “resource_id” : 42, “project_id” : 3, “hours” : 3, “intervals” : [ { “start_date” : “2016-05-06” , “end_date” : “2016-05-08” , “booking_id” : 6 } , { “start_date” : “2016-05-19” , “end_date” : “2016-05-19” , } , { “start_date” : “2016-05-21” , “end_date” : “2016-05-24” , “booking_id” : 6 } , { “start_date” : “2016-06-01” , “end_date” : “2016-10-25” , “booking_id” : 6 }
  • 5. The imperative one For each of the element do… Change width to 100px and then… Rotate if rotate===true… ... Then debug
  • 6. The declarative one I want the elements to be there (I want an animation for the elements that are not there) I don’t give a … how it all happens
  • 8. Basics of D3 - selection JS var selection = d3.select('#root') .selectAll('span'); HTML <div id="root"> </div> ● Looks a bit empty
  • 9. Basics of D3 - enter, update, exit JS var updateSelection = d3.select('#root') .selectAll('span'); .data([ 'Lorem', 'Ipsum' ]); updateSelection.enter().append('span'); updateSelection.text(el => el); updateSelection.exit().remove(); HTML <div id="root"> <span>Lorem</span> <span>Ipsum</span> </div>
  • 11. Basics of D3 - complete render function let render = function(data) { let selection = d3.select('#root').selectAll('span'); let updateSelection = selection.data(data); updateSelection.enter().append('span'); updateSelection.text(d => d); updateSelection.exit().remove(); };
  • 12. Components (codepen) let spanComponent = function(selection) { let updateSelection = selection.selectAll('span').data(data => data.lorem); updateSelection.enter().append('span'); updateSelection.text(d => d + ' '); updateSelection.exit().remove(); }; let render = function(data) { let selection = d3.select('#root').selectAll('div'); let updateSelection = selection.data(data); updateSelection.enter().append('div'); updateSelection.call(spanComponent); updateSelection.exit().remove(); }; render([{lorem: ['foo', 'bar']}, {lorem: ['ipsum', 'dolor']}]);
  • 13. Transitions (codepen) let spanComponent = function(selection) { let updateSelection = selection.selectAll('span').data(data => data.lorem); updateSelection.enter().append('span') .style('opacity', 0) .transition() .delay((d, i) => i * 400) .duration(500) .style('opacity', 1); updateSelection .text(d => d + ' '); updateSelection.exit().remove(); };
  • 14. Scales let myLinearScale = d3.scale .linear() .domain([0, 10]) .range([0, 800]); let x = myLinearScale(5); console.log(x); // prints 400
  • 15. Scales (2) let myTimeScale = d3.time .scale() .domain([new Date('2016-01-01'), new Date('2017-01-01')]) .range([0, 800]); let anyDate = new Date('2016-05-10'); let x = myTimeScale(anyDate); myTimeScale.invert(x); // equals anyDate
  • 16. SVG, Axes (codepen) let svg = d3.select('#root').append('svg') .attr("width", 300) .attr("height", 300); let x = d3.scale.linear() .range([0, 300]); let xAxis = d3.svg.axis() .ticks(4) .scale(x); svg.append("g") .attr("transform", "translate(0,100)") .call(xAxis); let line = d3.svg.line() .x(d => d.x) .y(d => d.y) .interpolate('monotone'); svg.data([[ {x: x(0.1), y: 60}, {x: x(0.3), y: 20}, {x: x(0.5), y: 30}, {x: x(0.7), y: 10}, {x: x(0.9), y: 80} ]]); svg.append("path") .attr('fill', 'none') .attr('stroke', '#000') .attr("d", line);
  • 18. And much more A lot of examples here: https://bl.ocks.org/mbostock
  • 19. Thank you for your attention! Tymoteusz Bleja Junior Frontend Developer @ Apptension