SlideShare a Scribd company logo
1 of 41
Download to read offline
Welcome!
“Networking”
There is a “networking table” near
the entrance to the lecture room,
where you can put your business
cards and prospects :-)
KAROL
DEPKA
– Woody Allen
“80% percent of success
is showing up.”
About the presentation
• As interactive as possible
• Questions welcome
• Feel free to interrupt at any time
• We can spend as much time as you want, on any slide
• I assume that the most active audience members are the most
interested and therefor should be able to control the
presentation flow
KAROL
DEPKA
A little poll
• On SVG:
• who has used SVG?
• who considers themselves proficient with SVG?
• who has plans to learn / use SVG?
• On D3
• who has used D3?
• who considers themselves proficient with D3?
• who has plans to learn / use D3?
H
ands
up
please!
KAROL
DEPKA
D3.js
DATA
DRIVEN
DOCUMENTS
KAROL
DEPKA
Data-to-Documents
DATA DOCUMENT
SVG
SCALABLE
VECTOR
GRAPHICS
KAROL
DEPKA
Why should you care about
D3 and why is it better?
• Interactive, unlike static images
• Open-source
• Good merits and Eye-candy
• Super flexible
KAROL
DEPKA
Why should you care about
SVG and why is it better?
• Web standard (unlike Flash)
• Runs in the browser without a plugin
(unlike Flash)
• Scales well
KAROL
DEPKA
Scaling & Resolutions
KAROL
DEPKA
Zoom in
The final product that we want to achieve
KAROL
DEPKA
The features that we want to achieve
• Physics-based automatic layout
• Drag-and-drop
• Automatic layout
• Zoom
• Pan
• Mouse-over highlight
KAROL
DEPKA
Our example is on GitHub
https://github.com/karol-depka/D3SVGTechnologyGraph
KAROL
DEPKA
https://bl.ocks.org/mbostock/4062045
Force layout
KAROL
DEPKA
D3 modules visualized in D3 :-D
KAROL
DEPKA
http://bl.ocks.org/alisd23/5762cc5912253c4febeb
Animated SVG
How do I animate SVG?
KAROL
DEPKA
Declaring nodes
// …
JavaScript: {

id: JavaScript,

body: "viewBox="0 0 256 256" v
"<path d="M67.311746,21
"</svg>n",

sizeMult: 1.2

},
KAROL
DEPKA
Declaring nodes, part 2
Inkscape: {id: Inkscape},

Illustrator: {id: Illustrator},

AffinityDesigner: {id: AffinityDesigner,
html: "Affinity<br/>Designer"},

// …
var nodesWebOnly = [

nodes.SVG,

// …

nodes.NodeJS,

nodes.JavaScript,

];
KAROL
DEPKA
Declaring links between nodes
var linksWebOnly = [

{source: HTML5, target: Angular2},

{source: Ionic, target: Angular2},

{source: HTML5, target: Angular2},

{source: D3, target: SVG},

{source: JavaScript, target: HTML5},

{source: JavaScript, target: TypeScript},

{source: JavaScript, target: jQuery},
// …

{source: Angular2, target: TypeScript},

{source: jQuery, target: HTML5},

{source: HTML5, target: CSS, thick: 10},

{source: SVG, target: HTML5, thick: 10,
distance: 1.5},

];
Setting up the D3 force
simulation
/* Base Example:
Force-Directed Graph:
https://bl.ocks.org/mbostock/4062045 */


var simulation = d3.forceSimulation()

// .force("gravity", 3)

.force("link",

d3.forceLink().id(function(d) { return d.id; })

.strength(function(d) {

return 3;

}))

.force("charge", d3.forceManyBody().strength(-1000))

.force("center", d3.forceCenter(width / 2, height / 2));

KAROL
DEPKA
Where to handle mouse events
Layer for drag&drop
and mouse-over
KAROL
DEPKA
Add drag&drop
https://github.com/d3/d3-drag
KAROL
DEPKA
Add drag&drop
function dragStarted(d) {

isDragging = true;

if (!d3.event.active) {

simulation.alphaTarget(0.3).restart();

}

d.fx = d.x;

d.fy = d.y;

}



function dragged(d) {

isDragging = true;

d.fx = d3.event.x;

d.fy = d3.event.y;

}



function dragEnded(d) {

isDragging = false;

unHighlightHover()



if (!d3.event.active) {

simulation.alphaTarget(0);

}

d.fx = null;

d.fy = null;

}
Add drag&drop
nodeCircleOverlay.call(

d3.drag()

.on("start", dragStarted)

.on("drag", dragged)

.on("end", dragEnded));
KAROL
DEPKA
Add SVG icons
perNodeMainGroup.append("g").html(function(d) {

var bodyText = d.body || "";

var size = d.sizeMult ? d.sizeMult * defaultSize

: defaultSize;



if (bodyText.trim().endsWith("</svg>")) {

const htmlContent = '<svg '

+ 'width="' + size + 'px" '

+ 'height="' + size + 'px" '

+ 'x="' + (-size/2) + '" '

+ 'y="' + (-size/2) + '" '

+ bodyText /* also contains </svg> */;

return htmlContent;

} else {

return "";

}

});
Add HTML foreignObject
perNodeMainGroup.append("foreignObject")

.attr("style", "pointer-events:none;")

.attr("width", foreignObjectW)

.attr("height", foreignObjectH)

.attr("height", foreignObjectH)

.attr("x", -foreignObjectW/2)

.attr("y", -foreignObjectH/2)

.style("font", "9px 'Helvetica Neue'")

.html(function(d) {

if ( d.body ) {

return ""; // has icon: no need for text

}

var bodyText = d.html || d.id;

return "<div style='display: table;" +

"text-align:center;" +

"height:100%; width:100%'>" +

"<p style='display: table-cell; " +

"vertical-align: middle'>" +

bodyText + "</p></div>";

});
ticked() function
function ticked() {

link

.attr("x1", function(d) { return d.source.x; })

.attr("y1", function(d) { return d.source.y; })

.attr("x2", function(d) { return d.target.x; })

.attr("y2", function(d) { return d.target.y; });



nodeG1.attr("transform", function(d) {

return "translate(" + d.x + "," + d.y + ")";

});

}
KAROL
DEPKA
Tested on browsers
• Chrome
• Firefox
• Safari
• Opera
• Edge
• Internet Explorer
Browsers, Browsers,
Browsers!
• Who here uses IE as their main browser?
• Who here uses IE as their main browser and is not
afraid to admit it?
• Who here uses Microsoft Edge as their main
browser?
H
ands
up
please!
https://github.com/eisman/neo4jd3
KAROL
DEPKA
Cool D3 Examples
https://bl.ocks.org/mbostock/
2990a882e007f8384b04827617752738
Cool D3 Examples
• http://bl.ocks.org/rkirsling/5001347 - directed graph
editor
KAROL
DEPKA
Gallery of
D3
Examples
URL:
Alternatives to SVG
• Font Awesome (only monochrome?)
• Canvas? (not scalable?)
• Adobe Flash? ;-)
• PDF
KAROL
DEPKA
A little poll - after the
presentation
• On SVG:
• who has plans to learn / use SVG?
• On D3
• who has plans to learn / use D3?
H
ands
up
please!
KAROL
DEPKA
Q
und
A
THANKS TO
Ewa, Rafa
Antonio, Guillermo, Abigail
Ania, Greg

More Related Content

What's hot

Unobtrusive javascript with jQuery
Unobtrusive javascript with jQueryUnobtrusive javascript with jQuery
Unobtrusive javascript with jQuery
Angel Ruiz
 

What's hot (20)

Write Less Do More
Write Less Do MoreWrite Less Do More
Write Less Do More
 
jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginners
 
jQuery Fundamentals
jQuery FundamentalsjQuery Fundamentals
jQuery Fundamentals
 
jQuery Presentation
jQuery PresentationjQuery Presentation
jQuery Presentation
 
jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009
 
Learning jQuery in 30 minutes
Learning jQuery in 30 minutesLearning jQuery in 30 minutes
Learning jQuery in 30 minutes
 
jQuery Essentials
jQuery EssentialsjQuery Essentials
jQuery Essentials
 
jQuery
jQueryjQuery
jQuery
 
jQuery Essentials
jQuery EssentialsjQuery Essentials
jQuery Essentials
 
jQuery from the very beginning
jQuery from the very beginningjQuery from the very beginning
jQuery from the very beginning
 
JavaScript and jQuery Basics
JavaScript and jQuery BasicsJavaScript and jQuery Basics
JavaScript and jQuery Basics
 
jQuery in 15 minutes
jQuery in 15 minutesjQuery in 15 minutes
jQuery in 15 minutes
 
Unobtrusive javascript with jQuery
Unobtrusive javascript with jQueryUnobtrusive javascript with jQuery
Unobtrusive javascript with jQuery
 
jQuery Features to Avoid
jQuery Features to AvoidjQuery Features to Avoid
jQuery Features to Avoid
 
Jquery Complete Presentation along with Javascript Basics
Jquery Complete Presentation along with Javascript BasicsJquery Complete Presentation along with Javascript Basics
Jquery Complete Presentation along with Javascript Basics
 
jQuery
jQueryjQuery
jQuery
 
SharePoint and jQuery Essentials
SharePoint and jQuery EssentialsSharePoint and jQuery Essentials
SharePoint and jQuery Essentials
 
J query b_dotnet_ug_meet_12_may_2012
J query b_dotnet_ug_meet_12_may_2012J query b_dotnet_ug_meet_12_may_2012
J query b_dotnet_ug_meet_12_may_2012
 
Learning jQuery made exciting in an interactive session by one of our team me...
Learning jQuery made exciting in an interactive session by one of our team me...Learning jQuery made exciting in an interactive session by one of our team me...
Learning jQuery made exciting in an interactive session by one of our team me...
 
Drupal Best Practices
Drupal Best PracticesDrupal Best Practices
Drupal Best Practices
 

Similar to D3.js and SVG

Илья Пухальский (EPAM Systems)
Илья Пухальский (EPAM Systems)Илья Пухальский (EPAM Systems)
Илья Пухальский (EPAM Systems)
Ontico
 
HTML5 and SVG
HTML5 and SVGHTML5 and SVG
HTML5 and SVG
yarcub
 

Similar to D3.js and SVG (20)

Accessibility Hacks Version 2
Accessibility Hacks Version 2Accessibility Hacks Version 2
Accessibility Hacks Version 2
 
Accessibility Hacks version 2
Accessibility Hacks version 2Accessibility Hacks version 2
Accessibility Hacks version 2
 
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)
 
Accessibility Hacks Wordcamp Manchester October 2018
Accessibility Hacks Wordcamp Manchester October 2018Accessibility Hacks Wordcamp Manchester October 2018
Accessibility Hacks Wordcamp Manchester October 2018
 
Sara Soueidan: Styling and Animating Scalable Vector Graphics with CSS [CSSCo...
Sara Soueidan: Styling and Animating Scalable Vector Graphics with CSS [CSSCo...Sara Soueidan: Styling and Animating Scalable Vector Graphics with CSS [CSSCo...
Sara Soueidan: Styling and Animating Scalable Vector Graphics with CSS [CSSCo...
 
Thats Not Flash?
Thats Not Flash?Thats Not Flash?
Thats Not Flash?
 
HTML5 - A Whirlwind tour
HTML5 - A Whirlwind tourHTML5 - A Whirlwind tour
HTML5 - A Whirlwind tour
 
Html5 more than just html5 v final
Html5  more than just html5 v finalHtml5  more than just html5 v final
Html5 more than just html5 v final
 
Илья Пухальский (EPAM Systems)
Илья Пухальский (EPAM Systems)Илья Пухальский (EPAM Systems)
Илья Пухальский (EPAM Systems)
 
SVGD3Angular2React
SVGD3Angular2ReactSVGD3Angular2React
SVGD3Angular2React
 
HTML5 and SVG
HTML5 and SVGHTML5 and SVG
HTML5 and SVG
 
Transforming public data into thematic maps (TDC2019 presentation)
Transforming public data into thematic maps (TDC2019 presentation)Transforming public data into thematic maps (TDC2019 presentation)
Transforming public data into thematic maps (TDC2019 presentation)
 
Make your own Print & Play card game using SVG and JavaScript
Make your own Print & Play card game using SVG and JavaScriptMake your own Print & Play card game using SVG and JavaScript
Make your own Print & Play card game using SVG and JavaScript
 
JavaONE 2012 Using Java with HTML5 and CSS3
JavaONE 2012 Using Java with HTML5 and CSS3JavaONE 2012 Using Java with HTML5 and CSS3
JavaONE 2012 Using Java with HTML5 and CSS3
 
Professional reports with SVG
Professional reports with SVGProfessional reports with SVG
Professional reports with SVG
 
Implementing Awesome: An HTML5/CSS3 Workshop
Implementing Awesome: An HTML5/CSS3 WorkshopImplementing Awesome: An HTML5/CSS3 Workshop
Implementing Awesome: An HTML5/CSS3 Workshop
 
About Best friends - HTML, CSS and JS
About Best friends - HTML, CSS and JSAbout Best friends - HTML, CSS and JS
About Best friends - HTML, CSS and JS
 
Top 10 HTML5 features
Top 10 HTML5 featuresTop 10 HTML5 features
Top 10 HTML5 features
 
Next generation Graphics: SVG
Next generation Graphics: SVGNext generation Graphics: SVG
Next generation Graphics: SVG
 

Recently uploaded

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
chiefasafspells
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
masabamasaba
 

Recently uploaded (20)

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 

D3.js and SVG

  • 2. “Networking” There is a “networking table” near the entrance to the lecture room, where you can put your business cards and prospects :-) KAROL DEPKA
  • 3.
  • 4. – Woody Allen “80% percent of success is showing up.”
  • 5. About the presentation • As interactive as possible • Questions welcome • Feel free to interrupt at any time • We can spend as much time as you want, on any slide • I assume that the most active audience members are the most interested and therefor should be able to control the presentation flow KAROL DEPKA
  • 6. A little poll • On SVG: • who has used SVG? • who considers themselves proficient with SVG? • who has plans to learn / use SVG? • On D3 • who has used D3? • who considers themselves proficient with D3? • who has plans to learn / use D3? H ands up please! KAROL DEPKA
  • 10. Why should you care about D3 and why is it better? • Interactive, unlike static images • Open-source • Good merits and Eye-candy • Super flexible KAROL DEPKA
  • 11. Why should you care about SVG and why is it better? • Web standard (unlike Flash) • Runs in the browser without a plugin (unlike Flash) • Scales well KAROL DEPKA
  • 14. The final product that we want to achieve KAROL DEPKA
  • 15. The features that we want to achieve • Physics-based automatic layout • Drag-and-drop • Automatic layout • Zoom • Pan • Mouse-over highlight KAROL DEPKA
  • 16. Our example is on GitHub https://github.com/karol-depka/D3SVGTechnologyGraph KAROL DEPKA
  • 18. D3 modules visualized in D3 :-D KAROL DEPKA http://bl.ocks.org/alisd23/5762cc5912253c4febeb
  • 19. Animated SVG How do I animate SVG? KAROL DEPKA
  • 20. Declaring nodes // … JavaScript: {
 id: JavaScript,
 body: "viewBox="0 0 256 256" v "<path d="M67.311746,21 "</svg>n",
 sizeMult: 1.2
 }, KAROL DEPKA
  • 21. Declaring nodes, part 2 Inkscape: {id: Inkscape},
 Illustrator: {id: Illustrator},
 AffinityDesigner: {id: AffinityDesigner, html: "Affinity<br/>Designer"},
 // … var nodesWebOnly = [
 nodes.SVG,
 // …
 nodes.NodeJS,
 nodes.JavaScript,
 ]; KAROL DEPKA
  • 22. Declaring links between nodes var linksWebOnly = [
 {source: HTML5, target: Angular2},
 {source: Ionic, target: Angular2},
 {source: HTML5, target: Angular2},
 {source: D3, target: SVG},
 {source: JavaScript, target: HTML5},
 {source: JavaScript, target: TypeScript},
 {source: JavaScript, target: jQuery}, // …
 {source: Angular2, target: TypeScript},
 {source: jQuery, target: HTML5},
 {source: HTML5, target: CSS, thick: 10},
 {source: SVG, target: HTML5, thick: 10, distance: 1.5},
 ];
  • 23. Setting up the D3 force simulation /* Base Example: Force-Directed Graph: https://bl.ocks.org/mbostock/4062045 */ 
 var simulation = d3.forceSimulation()
 // .force("gravity", 3)
 .force("link",
 d3.forceLink().id(function(d) { return d.id; })
 .strength(function(d) {
 return 3;
 }))
 .force("charge", d3.forceManyBody().strength(-1000))
 .force("center", d3.forceCenter(width / 2, height / 2));
 KAROL DEPKA
  • 24. Where to handle mouse events Layer for drag&drop and mouse-over KAROL DEPKA
  • 26. Add drag&drop function dragStarted(d) {
 isDragging = true;
 if (!d3.event.active) {
 simulation.alphaTarget(0.3).restart();
 }
 d.fx = d.x;
 d.fy = d.y;
 }
 
 function dragged(d) {
 isDragging = true;
 d.fx = d3.event.x;
 d.fy = d3.event.y;
 }
 
 function dragEnded(d) {
 isDragging = false;
 unHighlightHover()
 
 if (!d3.event.active) {
 simulation.alphaTarget(0);
 }
 d.fx = null;
 d.fy = null;
 }
  • 28. Add SVG icons perNodeMainGroup.append("g").html(function(d) {
 var bodyText = d.body || "";
 var size = d.sizeMult ? d.sizeMult * defaultSize
 : defaultSize;
 
 if (bodyText.trim().endsWith("</svg>")) {
 const htmlContent = '<svg '
 + 'width="' + size + 'px" '
 + 'height="' + size + 'px" '
 + 'x="' + (-size/2) + '" '
 + 'y="' + (-size/2) + '" '
 + bodyText /* also contains </svg> */;
 return htmlContent;
 } else {
 return "";
 }
 });
  • 29. Add HTML foreignObject perNodeMainGroup.append("foreignObject")
 .attr("style", "pointer-events:none;")
 .attr("width", foreignObjectW)
 .attr("height", foreignObjectH)
 .attr("height", foreignObjectH)
 .attr("x", -foreignObjectW/2)
 .attr("y", -foreignObjectH/2)
 .style("font", "9px 'Helvetica Neue'")
 .html(function(d) {
 if ( d.body ) {
 return ""; // has icon: no need for text
 }
 var bodyText = d.html || d.id;
 return "<div style='display: table;" +
 "text-align:center;" +
 "height:100%; width:100%'>" +
 "<p style='display: table-cell; " +
 "vertical-align: middle'>" +
 bodyText + "</p></div>";
 });
  • 30. ticked() function function ticked() {
 link
 .attr("x1", function(d) { return d.source.x; })
 .attr("y1", function(d) { return d.source.y; })
 .attr("x2", function(d) { return d.target.x; })
 .attr("y2", function(d) { return d.target.y; });
 
 nodeG1.attr("transform", function(d) {
 return "translate(" + d.x + "," + d.y + ")";
 });
 } KAROL DEPKA
  • 31. Tested on browsers • Chrome • Firefox • Safari • Opera • Edge • Internet Explorer
  • 32.
  • 33. Browsers, Browsers, Browsers! • Who here uses IE as their main browser? • Who here uses IE as their main browser and is not afraid to admit it? • Who here uses Microsoft Edge as their main browser? H ands up please!
  • 36. Cool D3 Examples • http://bl.ocks.org/rkirsling/5001347 - directed graph editor KAROL DEPKA
  • 38. Alternatives to SVG • Font Awesome (only monochrome?) • Canvas? (not scalable?) • Adobe Flash? ;-) • PDF KAROL DEPKA
  • 39. A little poll - after the presentation • On SVG: • who has plans to learn / use SVG? • On D3 • who has plans to learn / use D3? H ands up please! KAROL DEPKA
  • 41. THANKS TO Ewa, Rafa Antonio, Guillermo, Abigail Ania, Greg