SlideShare a Scribd company logo
D3 Data
Visualization
USE CASES
Nation’s Report Card.gov
Shapes: Natural Earth
Projection: Albers USA
GlobalChange.gov
Shapes: custom
agilebpa.forumone.com
BUILDING
BLOCKS
Scalable Vector Graphics (SVG)
Scalable Vector Graphics (SVG) is an XML-based
vector image format for two-dimensional graphics
with support for interactivity and animation.
SVG Highlights
● DOM API
● Defines vector-based graphics for the Web
● Supports CSS styling
● Element Grouping
● Hyperlinks
● Accessible alternative content
● Path elements for arbitrary drawing
SVG support by browser
Source: Can I use...
Common SVG Elements
svg
- Container element
circle, rect, line, ...
- Various shape elements
path
- Arbitrary drawing paths
- ‘d’ attribute for path data
g
- Used for grouping
a
- Links of course
text
- Textual content
SVG Attributes
fill
- color of the inside of an element
stroke
- color of the border of an element
stroke-width
- width of the border
stroke-dasharray
- customizable dashes for lines
<html>
<body>
<h1>My first SVG</h1>
<svg width="600" height="600">
</svg>
</body>
</html>
My first SVG
<html>
<body>
<h1>My first SVG</h1>
<svg width="600" height="600">
<rect width="300" height="200">
</svg>
</body>
</html>
My first SVG
<html>
<body>
<h1>My first SVG</h1>
<svg width="600" height="600">
<rect width="300" height="200" fill="red"
stroke="black" stroke-width="4">
</svg>
</body>
</html>
My first SVG
<html>
<body>
<h1>My first SVG</h1>
<svg width="600" height="600">
<rect width="300" height="200" fill="red"
stroke="black" stroke-width="4">
<circle r="80" fill="purple" />
</svg>
</body>
</html>
My first SVG
<html>
<body>
<h1>My first SVG</h1>
<svg width="600" height="600">
<rect width="300" height="200" fill="red"
stroke="black" stroke-width="4" x="10" y="10" />
<circle r="80" fill="purple" cx="100" cy="100" />
</svg>
</body>
</html>
My first SVG
<html>
<body>
<h1>My first SVG</h1>
<svg width="600" height="600">
<rect width="300" height="200" fill="red"
stroke="black" stroke-width="4" x="10" y="10" />
<circle r="80" fill="purple" cx="100" cy="100" />
<text x="70" y="80" fill="white">I love SVG!
</text>
</svg>
</body>
</html>
My first SVG
SVG Path
● M = moveto
● L = lineto
● H = horizontal lineto
● V = vertical lineto
● C = curveto
● S = smooth curveto
● Q = quadratic Bézier curve
● T = smooth quadratic Bézier curveto
● A = elliptical Arc
● Z = closepath
<html>
<body>
<h1>My first SVG</h1>
<svg width="600" height="600">
<path d="M150 0 L75 200 L225 200 Z" />
</svg>
</body>
</html>
My first SVG
SVG + CSS
<html>
<body>
<style>
svg path {
fill:red;
stroke-width:4;
stroke:black;
}
</style>
<h1>My first SVG</h1>
<svg width="600" height="600">
<path d="M150 0 L75 200 L225 200 Z" />
</svg>
</body>
</html>
My first SVG
SVG + CSS + D3
What is D3?
D3.js is a JavaScript library for
manipulating documents based on data.
- D3js.org
D3js is the glue between data and SVG.
Why should I use it?
● Cross Browser Compatibility
● Easy to learn API
● Good documentation and examples
● Expansive library of data visualizations
● Out-of-the-box functions:
○ XHR data loading
○ Geo data conversion
D3 Selections
d3.select(selector: string)
- query one element
d3.selectAll(selector: string)
- query multiple elements
Example: SVG Element
var svg = d3.select(‘body’)
.append(‘svg’)
.attr(‘width’, 960)
.attr(‘height’, 500);
Adding Attributes
append("circle")
.attr(‘cx’, 50)
.attr(‘cy’, 50)
.attr(‘r’, 40);
<div id="viz"/>
<script>
//Create a sized SVG surface within viz:
var vizsvg = d3.select("#viz")
.append("svg")
.attr("width", 600)
.attr("height", 600);
//Add to the svg surface a circle
var circle =
vizsvg.append("circle")
.attr("fill", "red")
.attr("r", 40)
.attr("cx", 50)
.attr("cy", 50);
</script>
Bring in the Data
Data Joins
update = selection.data(data)
Bind array of data to selection.
update.enter()
Iterates over data points that don’t have associated nodes.
update.exit()
Data nodes without matching data trigger this.
…
var dataset = [ 5, 10, 15, 20, 25 ];
var circles = svg.selectAll("circle")
.data(dataset)
.enter()
.append("circle")
.attr("r", function(d) {
return d;
})
.attr("cx", function(d, i) {
// i is the current data node index
return (i * 50) + 25;
})
.attr("cy", h/2)
.attr("fill","red");
DRUPAL &
D3 MODULE
Common Integration Methods
Views with
Basic D3
Module
Libraries
Views with
Custom D3
Module
Libraries
Custom D3
WITHOUT
D3 Module
Why use the D3 module?
D3 Module Features
● Simple API
● Out-of-the-box basic visualizations
● Custom library support
● Simplified data binding through Views integration and
custom library
Views with Basic D3 Libraries
Select the Views Format
Add Your Fields
Select a D3 Library and Configure Data
Configure D3 Library Display
Views with Custom D3 Libraries
Custom D3 Library Files
● d3.myLibrary (folder at sites/SITE/libraries)
○ d3.myLibrary.libraries.info (contains info and
dependencies)
○ myLibrary.css (contains custom CSS)
○ myLibrary.js (contains custom D3 js)
○ views-setting.php (contains views info)
d3.myViz.libraries.info
name = My Vis
description = My Vis custom D3 display
files[js][] = myvis.js
files[js][] = nv.d3.min.js
files[css][] = myvis.css
version = 0.1
dependencies[] = d3.extend
dependencies[] = d3.tooltip
views[version] = 3.0
views[fields][rows][__data_type] = 2dnnv
views[fields][rows][x_label][label] = X label
views[fields][rows][x_label][type] = string
views[fields][rows][x_label][description] = The label that
appears on the X axis.
views[fields][rows][value] = { __repeated: TRUE, __cardinality: 0,
label: Numeric value, type: integer, description: The numeric
value that will be used to plot each dot (circle) on the line }
views[fields][legend][__cardinality] = 0
views[fields][legend][__data_type] = 1dn
views[fields][legend][label] = Line label
views[fields][legend][description] = The meaning of each
different line.
views[fields][legend][type] = string
views[settings] = views-settings.php
● Same as out the box D3 module
custom library info file with some
exceptions
myViz.js
(function($) {
Drupal.d3.myvis = function (select, settings) {
// Get the name of the DIV ID to place the visualization in
var div = (settings.id) ? settings.id : 'visualization';
// Get the height/width from the views settings
var height = (settings.height) ? settings.height : '400';
var width = (settings.width) ? settings.width : '600';
// Get the rows of content
var rows = settings.rows;
// Shift the yLabel names from the rows array
var yLabels = rows.map(function(d) { return d.shift(); });
// Get key names for content grouping
var key = settings.legend;
...
● Load data and configuration from
views into JS variables for later use
myViz.js (cont.)
…
var troopData = [];
// Force rows array into data structure noted above
for (var i in rows) {
var row = rows[i];
var items = [];
for (var j in row) {
var item = row[j];
items.push({
"label" : key[j],
"value" : item
});
}
troopData.push({
"key" : yLabels[i],
"values" : items
});
}
...
● Rearrange data structure to match the
following structure:
"key": "Dragon",
"color": "#E80CC8",
"values": [
{
"label" : "Cost" ,
"value" : 5
},
{
"label" : "Strength" ,
"value" : 5
}
]
myViz.js (cont.)
…
// Render the NVD3 Multi-Bar Horizontal Chart in the proper DIV
element
var chart;
nv.addGraph(function() {
chart = nv.models.multiBarHorizontalChart()
.x(function(d) { return d.label })
.y(function(d) { return d.value })
.margin({top: 30, right: 20, bottom: 50, left: 175})
.showValues(false) //Hide bar values
.showControls(false) //Hide group toggle option
.showYAxis(false); // Do not show yaxis values
d3.select('#' + div).append("svg") // Append SVG to views div
.attr("width",width) // Set SVG width and height
.attr("height",height)
.datum(troopData) // Inject Data
.call(chart); // Inject the chart call
nv.utils.windowResize(chart.update); // ensure proper sizing of
window
return chart;
});
}
})(jQuery);
● Create an NVD3 Multi-Bar-Horizontal-
Chart data visualization with the data
variables set previously
● Create an SVG element inside the
Views content DIV
● NVD3 chart will be injected into the
SVG element
Resulting Custom Data Visualization
Custom D3 WITHOUT D3 Module
D3 Fully Custom
1. Get data in a structured format (JSON, CSV, Array, etc.)
a. Views works best unless using outside data
2. Create custom D3js Drupal library
3. Create custom Drupal module/hook to invoke library where
needed
a. Commonly injected into the content of blocks, panes
and custom pages
4. Additional theming if needed
Keenan Holloway
Senior Developer
kholloway@forumone.com
www.forumone.com
THANK YOU!

More Related Content

What's hot

Web Mining & Text Mining
Web Mining & Text MiningWeb Mining & Text Mining
Web Mining & Text Mining
Hemant Sharma
 
Page layout with css
Page layout with cssPage layout with css
Page layout with css
Er. Nawaraj Bhandari
 
Introduction to Data Mining and Data Warehousing
Introduction to Data Mining and Data WarehousingIntroduction to Data Mining and Data Warehousing
Introduction to Data Mining and Data Warehousing
Kamal Acharya
 
Presentation on html, css
Presentation on html, cssPresentation on html, css
Presentation on html, css
Aamir Sohail
 
Data mining
Data miningData mining
Data mining
Hoang Nguyen
 
Css3
Css3Css3
CSS Dasar #3 : Penempatan CSS
CSS Dasar #3 : Penempatan CSSCSS Dasar #3 : Penempatan CSS
CSS Dasar #3 : Penempatan CSS
Sandhika Galih
 
PHP MVC
PHP MVCPHP MVC
Css floats
Css floatsCss floats
Css floats
Webtech Learning
 
Cascading style sheet
Cascading style sheetCascading style sheet
Cascading style sheet
Michael Jhon
 
Css box-model
Css box-modelCss box-model
Css box-model
Webtech Learning
 
The Basics of MongoDB
The Basics of MongoDBThe Basics of MongoDB
The Basics of MongoDB
valuebound
 
HTML Dasar : #1 Pendahuluan
HTML Dasar : #1 PendahuluanHTML Dasar : #1 Pendahuluan
HTML Dasar : #1 Pendahuluan
Sandhika Galih
 
Web usage-mining
Web usage-miningWeb usage-mining
Web usage-mining
Samik Bhattacharjee
 
Introduction to css
Introduction to cssIntroduction to css
Introduction to css
Evolution Network
 
C Programming Project
C Programming ProjectC Programming Project
C Programming Project
Vijayananda Mohire
 
XPath for web scraping
XPath for web scrapingXPath for web scraping
XPath for web scraping
Scrapinghub
 
MongoDB presentation
MongoDB presentationMongoDB presentation
MongoDB presentation
Hyphen Call
 
Big Data Ecosystem
Big Data EcosystemBig Data Ecosystem
Big Data Ecosystem
Lucian Neghina
 

What's hot (20)

Web Mining & Text Mining
Web Mining & Text MiningWeb Mining & Text Mining
Web Mining & Text Mining
 
Page layout with css
Page layout with cssPage layout with css
Page layout with css
 
Introduction to Data Mining and Data Warehousing
Introduction to Data Mining and Data WarehousingIntroduction to Data Mining and Data Warehousing
Introduction to Data Mining and Data Warehousing
 
Presentation on html, css
Presentation on html, cssPresentation on html, css
Presentation on html, css
 
Data mining
Data miningData mining
Data mining
 
Css3
Css3Css3
Css3
 
CSS Dasar #3 : Penempatan CSS
CSS Dasar #3 : Penempatan CSSCSS Dasar #3 : Penempatan CSS
CSS Dasar #3 : Penempatan CSS
 
PHP MVC
PHP MVCPHP MVC
PHP MVC
 
Css floats
Css floatsCss floats
Css floats
 
Cascading style sheet
Cascading style sheetCascading style sheet
Cascading style sheet
 
Css box-model
Css box-modelCss box-model
Css box-model
 
The Basics of MongoDB
The Basics of MongoDBThe Basics of MongoDB
The Basics of MongoDB
 
HTML Dasar : #1 Pendahuluan
HTML Dasar : #1 PendahuluanHTML Dasar : #1 Pendahuluan
HTML Dasar : #1 Pendahuluan
 
Web usage-mining
Web usage-miningWeb usage-mining
Web usage-mining
 
Introduction to css
Introduction to cssIntroduction to css
Introduction to css
 
CSS
CSSCSS
CSS
 
C Programming Project
C Programming ProjectC Programming Project
C Programming Project
 
XPath for web scraping
XPath for web scrapingXPath for web scraping
XPath for web scraping
 
MongoDB presentation
MongoDB presentationMongoDB presentation
MongoDB presentation
 
Big Data Ecosystem
Big Data EcosystemBig Data Ecosystem
Big Data Ecosystem
 

Similar to D3 data visualization

D3.js 30-minute intro
D3.js   30-minute introD3.js   30-minute intro
D3.js 30-minute intro
Felipe
 
SVGD3Angular2React
SVGD3Angular2ReactSVGD3Angular2React
SVGD3Angular2React
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 Apps
EPAM
 
D3js learning tips
D3js learning tipsD3js learning tips
D3js learning tips
LearningTech
 
SVG - Scalable Vector Graphics
SVG - Scalable Vector GraphicsSVG - Scalable Vector Graphics
SVG - Scalable Vector Graphics
Shweta Sadawarte
 
Accessibility on SVG and SEO
Accessibility on SVG and SEOAccessibility on SVG and SEO
Accessibility on SVG and SEO
Reinaldo Ferraz
 
Accessibility on SVG and SEO
Accessibility on SVG and SEOAccessibility on SVG and SEO
Accessibility on SVG and SEO
Centro Web
 
Dreamforce 2014 - Introduction to d3.js
Dreamforce 2014 - Introduction to d3.jsDreamforce 2014 - Introduction to d3.js
Dreamforce 2014 - Introduction to d3.js
ramanathanp82
 
Data Visualizations with D3
Data Visualizations with D3Data Visualizations with D3
Data Visualizations with D3Doug Domeny
 
D3
D3D3
Mongo db washington dc 2014
Mongo db washington dc 2014Mongo db washington dc 2014
Mongo db washington dc 2014ikanow
 
Svcc 2013-d3
Svcc 2013-d3Svcc 2013-d3
Svcc 2013-d3
Oswald Campesato
 
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
 
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
 
Advanced D3 Charting
Advanced D3 ChartingAdvanced D3 Charting
Advanced D3 Charting
dcryan
 
Introduction to d3js (and SVG)
Introduction to d3js (and SVG)Introduction to d3js (and SVG)
Introduction to d3js (and SVG)
zahid-mian
 
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...
Guillaume Kossi
 
Utahjs D3
Utahjs D3Utahjs D3
Utahjs D3
knomedia
 

Similar to D3 data visualization (20)

D3.js 30-minute intro
D3.js   30-minute introD3.js   30-minute intro
D3.js 30-minute intro
 
SVGD3Angular2React
SVGD3Angular2ReactSVGD3Angular2React
SVGD3Angular2React
 
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
 
D3js learning tips
D3js learning tipsD3js learning tips
D3js learning tips
 
SVG - Scalable Vector Graphics
SVG - Scalable Vector GraphicsSVG - Scalable Vector Graphics
SVG - Scalable Vector Graphics
 
Accessibility on SVG and SEO
Accessibility on SVG and SEOAccessibility on SVG and SEO
Accessibility on SVG and SEO
 
Accessibility on SVG and SEO
Accessibility on SVG and SEOAccessibility on SVG and SEO
Accessibility on SVG and SEO
 
Dreamforce 2014 - Introduction to d3.js
Dreamforce 2014 - Introduction to d3.jsDreamforce 2014 - Introduction to d3.js
Dreamforce 2014 - Introduction to d3.js
 
Html5
Html5Html5
Html5
 
Data Visualizations with D3
Data Visualizations with D3Data Visualizations with D3
Data Visualizations with D3
 
D3
D3D3
D3
 
The D3 Toolbox
The D3 ToolboxThe D3 Toolbox
The D3 Toolbox
 
Mongo db washington dc 2014
Mongo db washington dc 2014Mongo db washington dc 2014
Mongo db washington dc 2014
 
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)
 
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...
 
Advanced D3 Charting
Advanced D3 ChartingAdvanced D3 Charting
Advanced D3 Charting
 
Introduction to d3js (and SVG)
Introduction to d3js (and SVG)Introduction to d3js (and SVG)
Introduction to d3js (and SVG)
 
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...
 
Utahjs D3
Utahjs D3Utahjs D3
Utahjs D3
 

Recently uploaded

UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
Fwdays
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Bhaskar Mitra
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 

Recently uploaded (20)

UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 

D3 data visualization

  • 3. Nation’s Report Card.gov Shapes: Natural Earth Projection: Albers USA
  • 8. Scalable Vector Graphics (SVG) is an XML-based vector image format for two-dimensional graphics with support for interactivity and animation.
  • 9. SVG Highlights ● DOM API ● Defines vector-based graphics for the Web ● Supports CSS styling ● Element Grouping ● Hyperlinks ● Accessible alternative content ● Path elements for arbitrary drawing
  • 10. SVG support by browser Source: Can I use...
  • 11. Common SVG Elements svg - Container element circle, rect, line, ... - Various shape elements path - Arbitrary drawing paths - ‘d’ attribute for path data g - Used for grouping a - Links of course text - Textual content
  • 12. SVG Attributes fill - color of the inside of an element stroke - color of the border of an element stroke-width - width of the border stroke-dasharray - customizable dashes for lines
  • 13. <html> <body> <h1>My first SVG</h1> <svg width="600" height="600"> </svg> </body> </html> My first SVG
  • 14. <html> <body> <h1>My first SVG</h1> <svg width="600" height="600"> <rect width="300" height="200"> </svg> </body> </html> My first SVG
  • 15. <html> <body> <h1>My first SVG</h1> <svg width="600" height="600"> <rect width="300" height="200" fill="red" stroke="black" stroke-width="4"> </svg> </body> </html> My first SVG
  • 16. <html> <body> <h1>My first SVG</h1> <svg width="600" height="600"> <rect width="300" height="200" fill="red" stroke="black" stroke-width="4"> <circle r="80" fill="purple" /> </svg> </body> </html> My first SVG
  • 17. <html> <body> <h1>My first SVG</h1> <svg width="600" height="600"> <rect width="300" height="200" fill="red" stroke="black" stroke-width="4" x="10" y="10" /> <circle r="80" fill="purple" cx="100" cy="100" /> </svg> </body> </html> My first SVG
  • 18. <html> <body> <h1>My first SVG</h1> <svg width="600" height="600"> <rect width="300" height="200" fill="red" stroke="black" stroke-width="4" x="10" y="10" /> <circle r="80" fill="purple" cx="100" cy="100" /> <text x="70" y="80" fill="white">I love SVG! </text> </svg> </body> </html> My first SVG
  • 19. SVG Path ● M = moveto ● L = lineto ● H = horizontal lineto ● V = vertical lineto ● C = curveto ● S = smooth curveto ● Q = quadratic Bézier curve ● T = smooth quadratic Bézier curveto ● A = elliptical Arc ● Z = closepath
  • 20. <html> <body> <h1>My first SVG</h1> <svg width="600" height="600"> <path d="M150 0 L75 200 L225 200 Z" /> </svg> </body> </html> My first SVG
  • 22. <html> <body> <style> svg path { fill:red; stroke-width:4; stroke:black; } </style> <h1>My first SVG</h1> <svg width="600" height="600"> <path d="M150 0 L75 200 L225 200 Z" /> </svg> </body> </html> My first SVG
  • 23. SVG + CSS + D3
  • 24. What is D3? D3.js is a JavaScript library for manipulating documents based on data. - D3js.org D3js is the glue between data and SVG.
  • 25. Why should I use it? ● Cross Browser Compatibility ● Easy to learn API ● Good documentation and examples ● Expansive library of data visualizations ● Out-of-the-box functions: ○ XHR data loading ○ Geo data conversion
  • 26. D3 Selections d3.select(selector: string) - query one element d3.selectAll(selector: string) - query multiple elements
  • 27. Example: SVG Element var svg = d3.select(‘body’) .append(‘svg’) .attr(‘width’, 960) .attr(‘height’, 500);
  • 29. <div id="viz"/> <script> //Create a sized SVG surface within viz: var vizsvg = d3.select("#viz") .append("svg") .attr("width", 600) .attr("height", 600); //Add to the svg surface a circle var circle = vizsvg.append("circle") .attr("fill", "red") .attr("r", 40) .attr("cx", 50) .attr("cy", 50); </script>
  • 30. Bring in the Data
  • 31. Data Joins update = selection.data(data) Bind array of data to selection. update.enter() Iterates over data points that don’t have associated nodes. update.exit() Data nodes without matching data trigger this.
  • 32. … var dataset = [ 5, 10, 15, 20, 25 ]; var circles = svg.selectAll("circle") .data(dataset) .enter() .append("circle") .attr("r", function(d) { return d; }) .attr("cx", function(d, i) { // i is the current data node index return (i * 50) + 25; }) .attr("cy", h/2) .attr("fill","red");
  • 33.
  • 35. Common Integration Methods Views with Basic D3 Module Libraries Views with Custom D3 Module Libraries Custom D3 WITHOUT D3 Module
  • 36. Why use the D3 module?
  • 37. D3 Module Features ● Simple API ● Out-of-the-box basic visualizations ● Custom library support ● Simplified data binding through Views integration and custom library
  • 38. Views with Basic D3 Libraries
  • 39.
  • 42. Select a D3 Library and Configure Data
  • 44.
  • 45. Views with Custom D3 Libraries
  • 46. Custom D3 Library Files ● d3.myLibrary (folder at sites/SITE/libraries) ○ d3.myLibrary.libraries.info (contains info and dependencies) ○ myLibrary.css (contains custom CSS) ○ myLibrary.js (contains custom D3 js) ○ views-setting.php (contains views info)
  • 47. d3.myViz.libraries.info name = My Vis description = My Vis custom D3 display files[js][] = myvis.js files[js][] = nv.d3.min.js files[css][] = myvis.css version = 0.1 dependencies[] = d3.extend dependencies[] = d3.tooltip views[version] = 3.0 views[fields][rows][__data_type] = 2dnnv views[fields][rows][x_label][label] = X label views[fields][rows][x_label][type] = string views[fields][rows][x_label][description] = The label that appears on the X axis. views[fields][rows][value] = { __repeated: TRUE, __cardinality: 0, label: Numeric value, type: integer, description: The numeric value that will be used to plot each dot (circle) on the line } views[fields][legend][__cardinality] = 0 views[fields][legend][__data_type] = 1dn views[fields][legend][label] = Line label views[fields][legend][description] = The meaning of each different line. views[fields][legend][type] = string views[settings] = views-settings.php ● Same as out the box D3 module custom library info file with some exceptions
  • 48. myViz.js (function($) { Drupal.d3.myvis = function (select, settings) { // Get the name of the DIV ID to place the visualization in var div = (settings.id) ? settings.id : 'visualization'; // Get the height/width from the views settings var height = (settings.height) ? settings.height : '400'; var width = (settings.width) ? settings.width : '600'; // Get the rows of content var rows = settings.rows; // Shift the yLabel names from the rows array var yLabels = rows.map(function(d) { return d.shift(); }); // Get key names for content grouping var key = settings.legend; ... ● Load data and configuration from views into JS variables for later use
  • 49. myViz.js (cont.) … var troopData = []; // Force rows array into data structure noted above for (var i in rows) { var row = rows[i]; var items = []; for (var j in row) { var item = row[j]; items.push({ "label" : key[j], "value" : item }); } troopData.push({ "key" : yLabels[i], "values" : items }); } ... ● Rearrange data structure to match the following structure: "key": "Dragon", "color": "#E80CC8", "values": [ { "label" : "Cost" , "value" : 5 }, { "label" : "Strength" , "value" : 5 } ]
  • 50. myViz.js (cont.) … // Render the NVD3 Multi-Bar Horizontal Chart in the proper DIV element var chart; nv.addGraph(function() { chart = nv.models.multiBarHorizontalChart() .x(function(d) { return d.label }) .y(function(d) { return d.value }) .margin({top: 30, right: 20, bottom: 50, left: 175}) .showValues(false) //Hide bar values .showControls(false) //Hide group toggle option .showYAxis(false); // Do not show yaxis values d3.select('#' + div).append("svg") // Append SVG to views div .attr("width",width) // Set SVG width and height .attr("height",height) .datum(troopData) // Inject Data .call(chart); // Inject the chart call nv.utils.windowResize(chart.update); // ensure proper sizing of window return chart; }); } })(jQuery); ● Create an NVD3 Multi-Bar-Horizontal- Chart data visualization with the data variables set previously ● Create an SVG element inside the Views content DIV ● NVD3 chart will be injected into the SVG element
  • 51. Resulting Custom Data Visualization
  • 52. Custom D3 WITHOUT D3 Module
  • 53. D3 Fully Custom 1. Get data in a structured format (JSON, CSV, Array, etc.) a. Views works best unless using outside data 2. Create custom D3js Drupal library 3. Create custom Drupal module/hook to invoke library where needed a. Commonly injected into the content of blocks, panes and custom pages 4. Additional theming if needed