SlideShare uma empresa Scribd logo
1 de 17
Baixar para ler offline
Having fun with graphs
An introduction to d3.js

Michael Hackstein
@mchacki

August 13, 2013

1 / 15
d3.js

Short Description
Take javascript objects or a JSON file
Create SVGs out of them
Synchronize objects and SVG
API quite similar to jQuery
⇒ “The jQuery for SVG”

2 / 15
Examples

3 / 15
Examples

3 / 15
Examples

3 / 15
Simple Setup

var nodes = [{ id : 0 , x : 100 , y : 80} , ...];
var edges = [{ id : 0 ,
source : nodes [0] ,
target : nodes [1]
} , ...];
var svg = d3 . select ( " body " )
. append ( " svg " )
. attr ( " width " , 960)
. attr ( " height " , 500) ;
draw ( svg , nodes , edges ) ;

4 / 15
The draw function
var draw = function ( svg , nodes , edges )
var d3Edge = svg . selectAll ( " . link " )
. data ( edges )
. enter () . append ( " line " )
. attr ( " class " , " link " )
. attr ( " x1 " , function ( d ) { return
. attr ( " y1 " , function ( d ) { return
. attr ( " x2 " , function ( d ) { return
. attr ( " y2 " , function ( d ) { return

{

d . source . x ;
d . source . y ;
d . target . x ;
d . target . y ;

})
})
})
}) ;

var d3Node = svg . selectAll ( " . node " )
. data ( nodes )
. enter () . append ( " circle " )
. attr ( " r " , 25)
. attr ( " cx " , function ( d ) { return d . x })
. attr ( " cy " , function ( d ) { return d . y })
. style ( " fill " , " red " ) ;
};

5 / 15
Tree Layout Datastructure

var treeData = {
id : 1 ,
children : [
{ id : 2} ,
{
id : 3 ,
children : [
{ id : 4} ,{ id : 5} ,{ id : 6}
]
},
]
};

6 / 15
Tree Layout

var tree = d3 . layout . tree ()
. size ([ width , height ]) ;
var nodes = tree . nodes ( treeData ) ;
var edges = tree . links ( nodes ) ;
draw ( svg , nodes , edges ) ;

7 / 15
on

lsi

on

pu
re

re
pu
l si

←

→

Force-Based Layout Idea

←

→

→ attraction ←

Figure : Forces in Force-Directed Layout

Attention
Runtime: O(n2 ) ⇒ Only small number of nodes

8 / 15
Force-Based Layout Setup

var force = d3 . layout . force ()
. charge ( -120)
. linkDistance (30)
. size ([ width , height ])
. nodes ( nodes )
. links ( edges )
. start () ;
draw ( svg , nodes , edges ) ;

9 / 15
Force-Based Layout Update Position

force . on ( " tick " , function ()
svg . selectAll ( " . edge " )
. attr ( " x1 " , function ( d )
. attr ( " y1 " , function ( d )
. attr ( " x2 " , function ( d )
. attr ( " y2 " , function ( d )

{
{ return
{ return
{ return
{ return

d . source . x ;})
d . source . y ;})
d . target . x ;})
d . target . y ;}) ;

svg . selectAll ( " . node " )
. attr ( " cx " , function ( d ) { return d . x ; })
. attr ( " cy " , function ( d ) { return d . y ; }) ;
}) ;

10 / 15
Adding User-Interaction

Similar to jQuery.
Add in the draw function:
d3Node . on ( " click " , function ( d ) {
alert ( " Clicked on Node with ID : " + d . id ) ;
})
. on ( " mouseover " , function ( d ) {
d3 . select ( this ) . style ( " fill " , " green " ) ;
})
. on ( " mouseout " , function ( d ) {
d3 . select ( this ) . style ( " fill " , " red " ) ;
}) ;

11 / 15
Difficulties

Often details are important
Show everything always is not useful
Many nodes
Layout-algorithms get slow
Not enough pixels for nodes

12 / 15
Fisheye-Distortion

Figure : Fish-Eye Distortion

Mouse-pointer is the focus
Magnifies close objects
Minifies far away objects

13 / 15
Group Nodes to smaller parts

Figure : Group similar nodes

Group nodes (f.e. by similar attributes)
Layout each group separately
Treat each group as one large node
Then layout group-nodes

14 / 15
A complete GUI for a Graph-Database

DEMO

15 / 15

Mais conteúdo relacionado

Mais procurados

d3jsではじめるデータビジュアライゼーション入門
d3jsではじめるデータビジュアライゼーション入門d3jsではじめるデータビジュアライゼーション入門
d3jsではじめるデータビジュアライゼーション入門Kohei Kadowaki
 
D3.js - A picture is worth a thousand words
D3.js - A picture is worth a thousand wordsD3.js - A picture is worth a thousand words
D3.js - A picture is worth a thousand wordsApptension
 
Зависимые типы в GHC 8. Максим Талдыкин
Зависимые типы в GHC 8. Максим ТалдыкинЗависимые типы в GHC 8. Максим Талдыкин
Зависимые типы в GHC 8. Максим ТалдыкинЮрий Сыровецкий
 
Exploring Canvas
Exploring CanvasExploring Canvas
Exploring CanvasKevin Hoyt
 
Human-powered Javascript Compression for Fun and Gummy Bears
Human-powered Javascript Compression for Fun and Gummy BearsHuman-powered Javascript Compression for Fun and Gummy Bears
Human-powered Javascript Compression for Fun and Gummy BearsRui Lopes
 
Cocos2dを使ったゲーム作成の事例
Cocos2dを使ったゲーム作成の事例Cocos2dを使ったゲーム作成の事例
Cocos2dを使ったゲーム作成の事例Yuichi Higuchi
 
ggtimeseries-->ggplot2 extensions
ggtimeseries-->ggplot2 extensions ggtimeseries-->ggplot2 extensions
ggtimeseries-->ggplot2 extensions Dr. Volkan OBAN
 
Fun with D3.js: Data Visualization Eye Candy with Streaming JSON
Fun with D3.js: Data Visualization Eye Candy with Streaming JSONFun with D3.js: Data Visualization Eye Candy with Streaming JSON
Fun with D3.js: Data Visualization Eye Candy with Streaming JSONTomomi Imura
 
Gems of GameplayKit. UA Mobile 2017.
Gems of GameplayKit. UA Mobile 2017.Gems of GameplayKit. UA Mobile 2017.
Gems of GameplayKit. UA Mobile 2017.UA Mobile
 
Paperjs presentation
Paperjs presentationPaperjs presentation
Paperjs presentationsharp-blade
 
Making Games in JavaScript
Making Games in JavaScriptMaking Games in JavaScript
Making Games in JavaScriptSam Cartwright
 
Introduction to programming class 13
Introduction to programming   class 13Introduction to programming   class 13
Introduction to programming class 13Paul Brebner
 
Computer graphics lab assignment
Computer graphics lab assignmentComputer graphics lab assignment
Computer graphics lab assignmentAbdullah Al Shiam
 

Mais procurados (20)

Scrollytelling
ScrollytellingScrollytelling
Scrollytelling
 
d3jsではじめるデータビジュアライゼーション入門
d3jsではじめるデータビジュアライゼーション入門d3jsではじめるデータビジュアライゼーション入門
d3jsではじめるデータビジュアライゼーション入門
 
D3.js - A picture is worth a thousand words
D3.js - A picture is worth a thousand wordsD3.js - A picture is worth a thousand words
D3.js - A picture is worth a thousand words
 
HTML5 Canvas
HTML5 CanvasHTML5 Canvas
HTML5 Canvas
 
Supstat nyc subway
Supstat nyc subwaySupstat nyc subway
Supstat nyc subway
 
Зависимые типы в GHC 8. Максим Талдыкин
Зависимые типы в GHC 8. Максим ТалдыкинЗависимые типы в GHC 8. Максим Талдыкин
Зависимые типы в GHC 8. Максим Талдыкин
 
Exploring Canvas
Exploring CanvasExploring Canvas
Exploring Canvas
 
Human-powered Javascript Compression for Fun and Gummy Bears
Human-powered Javascript Compression for Fun and Gummy BearsHuman-powered Javascript Compression for Fun and Gummy Bears
Human-powered Javascript Compression for Fun and Gummy Bears
 
Cocos2dを使ったゲーム作成の事例
Cocos2dを使ったゲーム作成の事例Cocos2dを使ったゲーム作成の事例
Cocos2dを使ったゲーム作成の事例
 
ggtimeseries-->ggplot2 extensions
ggtimeseries-->ggplot2 extensions ggtimeseries-->ggplot2 extensions
ggtimeseries-->ggplot2 extensions
 
Real life XNA
Real life XNAReal life XNA
Real life XNA
 
Fun with D3.js: Data Visualization Eye Candy with Streaming JSON
Fun with D3.js: Data Visualization Eye Candy with Streaming JSONFun with D3.js: Data Visualization Eye Candy with Streaming JSON
Fun with D3.js: Data Visualization Eye Candy with Streaming JSON
 
Gems of GameplayKit. UA Mobile 2017.
Gems of GameplayKit. UA Mobile 2017.Gems of GameplayKit. UA Mobile 2017.
Gems of GameplayKit. UA Mobile 2017.
 
My favorite slides
My favorite slidesMy favorite slides
My favorite slides
 
Scala.io
Scala.ioScala.io
Scala.io
 
Paperjs presentation
Paperjs presentationPaperjs presentation
Paperjs presentation
 
Making Games in JavaScript
Making Games in JavaScriptMaking Games in JavaScript
Making Games in JavaScript
 
Introduction to D3
Introduction to D3 Introduction to D3
Introduction to D3
 
Introduction to programming class 13
Introduction to programming   class 13Introduction to programming   class 13
Introduction to programming class 13
 
Computer graphics lab assignment
Computer graphics lab assignmentComputer graphics lab assignment
Computer graphics lab assignment
 

Semelhante a Having fun with graphs, a short introduction to D3.js

Introduction to d3js (and SVG)
Introduction to d3js (and SVG)Introduction to d3js (and SVG)
Introduction to d3js (and SVG)zahid-mian
 
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
 
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
 
D3 svg & angular
D3 svg & angularD3 svg & angular
D3 svg & angular500Tech
 
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
 
D3.js 30-minute intro
D3.js   30-minute introD3.js   30-minute intro
D3.js 30-minute introFelipe
 
Visual Exploration of Large Data sets with D3, crossfilter and dc.js
Visual Exploration of Large Data sets with D3, crossfilter and dc.jsVisual Exploration of Large Data sets with D3, crossfilter and dc.js
Visual Exploration of Large Data sets with D3, crossfilter and dc.jsFlorian Georg
 
Dynamic Data Visualization With Chartkick
Dynamic Data Visualization With ChartkickDynamic Data Visualization With Chartkick
Dynamic Data Visualization With ChartkickDax Murray
 
The Web map stack on Django
The Web map stack on DjangoThe Web map stack on Django
The Web map stack on DjangoPaul Smith
 
D3js learning tips
D3js learning tipsD3js learning tips
D3js learning tipsLearningTech
 
Micro and moblile: Java on the Raspberry Pi
Micro and moblile: Java on the Raspberry PiMicro and moblile: Java on the Raspberry Pi
Micro and moblile: Java on the Raspberry PiPance Cavkovski
 
Learn D3.js in 90 minutes
Learn D3.js in 90 minutesLearn D3.js in 90 minutes
Learn D3.js in 90 minutesJos Dirksen
 
SVGo: a Go Library for SVG generation
SVGo: a Go Library for SVG generationSVGo: a Go Library for SVG generation
SVGo: a Go Library for SVG generationAnthony Starks
 

Semelhante a Having fun with graphs, a short introduction to D3.js (20)

Introduction to d3js (and SVG)
Introduction to d3js (and SVG)Introduction to d3js (and SVG)
Introduction to d3js (and SVG)
 
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)
 
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
 
D3 svg & angular
D3 svg & angularD3 svg & angular
D3 svg & angular
 
Better d3 charts with tdd
Better d3 charts with tddBetter d3 charts with tdd
Better d3 charts with tdd
 
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...
 
D3.js 30-minute intro
D3.js   30-minute introD3.js   30-minute intro
D3.js 30-minute intro
 
SVGD3Angular2React
SVGD3Angular2ReactSVGD3Angular2React
SVGD3Angular2React
 
Visual Exploration of Large Data sets with D3, crossfilter and dc.js
Visual Exploration of Large Data sets with D3, crossfilter and dc.jsVisual Exploration of Large Data sets with D3, crossfilter and dc.js
Visual Exploration of Large Data sets with D3, crossfilter and dc.js
 
Dynamic Data Visualization With Chartkick
Dynamic Data Visualization With ChartkickDynamic Data Visualization With Chartkick
Dynamic Data Visualization With Chartkick
 
The Web map stack on Django
The Web map stack on DjangoThe Web map stack on Django
The Web map stack on Django
 
D3js learning tips
D3js learning tipsD3js learning tips
D3js learning tips
 
D3 data visualization
D3 data visualizationD3 data visualization
D3 data visualization
 
Micro and moblile: Java on the Raspberry Pi
Micro and moblile: Java on the Raspberry PiMicro and moblile: Java on the Raspberry Pi
Micro and moblile: Java on the Raspberry Pi
 
JQuery Flot
JQuery FlotJQuery Flot
JQuery Flot
 
Learn D3.js in 90 minutes
Learn D3.js in 90 minutesLearn D3.js in 90 minutes
Learn D3.js in 90 minutes
 
SVGo: a Go Library for SVG generation
SVGo: a Go Library for SVG generationSVGo: a Go Library for SVG generation
SVGo: a Go Library for SVG generation
 
D3
D3D3
D3
 
SVGo workshop
SVGo workshopSVGo workshop
SVGo workshop
 

Último

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 

Último (20)

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 

Having fun with graphs, a short introduction to D3.js

  • 1. Having fun with graphs An introduction to d3.js Michael Hackstein @mchacki August 13, 2013 1 / 15
  • 2. d3.js Short Description Take javascript objects or a JSON file Create SVGs out of them Synchronize objects and SVG API quite similar to jQuery ⇒ “The jQuery for SVG” 2 / 15
  • 6. Simple Setup var nodes = [{ id : 0 , x : 100 , y : 80} , ...]; var edges = [{ id : 0 , source : nodes [0] , target : nodes [1] } , ...]; var svg = d3 . select ( " body " ) . append ( " svg " ) . attr ( " width " , 960) . attr ( " height " , 500) ; draw ( svg , nodes , edges ) ; 4 / 15
  • 7. The draw function var draw = function ( svg , nodes , edges ) var d3Edge = svg . selectAll ( " . link " ) . data ( edges ) . enter () . append ( " line " ) . attr ( " class " , " link " ) . attr ( " x1 " , function ( d ) { return . attr ( " y1 " , function ( d ) { return . attr ( " x2 " , function ( d ) { return . attr ( " y2 " , function ( d ) { return { d . source . x ; d . source . y ; d . target . x ; d . target . y ; }) }) }) }) ; var d3Node = svg . selectAll ( " . node " ) . data ( nodes ) . enter () . append ( " circle " ) . attr ( " r " , 25) . attr ( " cx " , function ( d ) { return d . x }) . attr ( " cy " , function ( d ) { return d . y }) . style ( " fill " , " red " ) ; }; 5 / 15
  • 8. Tree Layout Datastructure var treeData = { id : 1 , children : [ { id : 2} , { id : 3 , children : [ { id : 4} ,{ id : 5} ,{ id : 6} ] }, ] }; 6 / 15
  • 9. Tree Layout var tree = d3 . layout . tree () . size ([ width , height ]) ; var nodes = tree . nodes ( treeData ) ; var edges = tree . links ( nodes ) ; draw ( svg , nodes , edges ) ; 7 / 15
  • 10. on lsi on pu re re pu l si ← → Force-Based Layout Idea ← → → attraction ← Figure : Forces in Force-Directed Layout Attention Runtime: O(n2 ) ⇒ Only small number of nodes 8 / 15
  • 11. Force-Based Layout Setup var force = d3 . layout . force () . charge ( -120) . linkDistance (30) . size ([ width , height ]) . nodes ( nodes ) . links ( edges ) . start () ; draw ( svg , nodes , edges ) ; 9 / 15
  • 12. Force-Based Layout Update Position force . on ( " tick " , function () svg . selectAll ( " . edge " ) . attr ( " x1 " , function ( d ) . attr ( " y1 " , function ( d ) . attr ( " x2 " , function ( d ) . attr ( " y2 " , function ( d ) { { return { return { return { return d . source . x ;}) d . source . y ;}) d . target . x ;}) d . target . y ;}) ; svg . selectAll ( " . node " ) . attr ( " cx " , function ( d ) { return d . x ; }) . attr ( " cy " , function ( d ) { return d . y ; }) ; }) ; 10 / 15
  • 13. Adding User-Interaction Similar to jQuery. Add in the draw function: d3Node . on ( " click " , function ( d ) { alert ( " Clicked on Node with ID : " + d . id ) ; }) . on ( " mouseover " , function ( d ) { d3 . select ( this ) . style ( " fill " , " green " ) ; }) . on ( " mouseout " , function ( d ) { d3 . select ( this ) . style ( " fill " , " red " ) ; }) ; 11 / 15
  • 14. Difficulties Often details are important Show everything always is not useful Many nodes Layout-algorithms get slow Not enough pixels for nodes 12 / 15
  • 15. Fisheye-Distortion Figure : Fish-Eye Distortion Mouse-pointer is the focus Magnifies close objects Minifies far away objects 13 / 15
  • 16. Group Nodes to smaller parts Figure : Group similar nodes Group nodes (f.e. by similar attributes) Layout each group separately Treat each group as one large node Then layout group-nodes 14 / 15
  • 17. A complete GUI for a Graph-Database DEMO 15 / 15