SlideShare a Scribd company logo
1 of 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

More Related Content

What's hot

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
 

What's hot (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
 

Viewers also liked

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
 

Viewers also liked (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
 

Similar to 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
 

Similar to 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
 
NoSQL meets Microservices
NoSQL meets MicroservicesNoSQL meets Microservices
NoSQL meets Microservices
 
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
 
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...
 

Recently uploaded

DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 

Recently uploaded (20)

DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 

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