SlideShare uma empresa Scribd logo
1 de 15
Baixar para ler offline
d3 is cool
                     maps data to DOM




Sunday, 7 April 13
# jQuery-esque API
            d3
               .select("body")
               .append("p")
               .text("New paragraph!")
               .attr("class", "yep")
               .style("height", "10px")




Sunday, 7 April 13
data = []
            for num in [0..25]
              data.push Math.random() * 30

            d3.select("#bar") # get a wrapper element
              .selectAll("div") # get an array
              .data(data) # get a data-bound array
              .enter() # creates new nodes
              .append("div") # adds to DOM
              .style("height", (d)-> d * 5 + "px")




Sunday, 7 April 13
maps data to DOM




Sunday, 7 April 13
svg is cool
                     DOM for vector graphics & text




Sunday, 7 April 13
<svg height="200" width="700">
              <rect x="0" y="0" width="500" height="50">
              <circle cx="10" cy="100" r="50" fill="red">
              <text x="250" y="50">Easy-peasy</text>
              <path d="M 100 100 L 300 100 L 200 300 z" stroke-width="3">
              <image>
              <font> # fek yeah
            </svg>




Sunday, 7 April 13
svg = d3.select("body")
              .append("svg")
              .attr("width", w)
              .attr("height", h)
            circles = svg.selectAll()
              .data(dataset)
              .enter()
              .append("circle")
              .attr("cx", (d, i)-> i * 22)
              .attr("cy", 50)
              .attr("r", (d)-> d / 2)
              .attr("fill", (d)-> "rgb(" + Math.floor(d * 6) + ",0,150)")




Sunday, 7 April 13
data = [
              [5, 20],
              ...
              [220, 88]
            ]
            svg = getSVG()
            svg.selectAll()
               .data(data)
               .enter()
               .append("circle")
               .attr("cx", (d)-> d[0])
               .attr("cy", (d)-> d[1])
               .attr("r", 4)




Sunday, 7 April 13
# scales - d3's best feature
            # functions that map an input range to an output range
            xScale = d3.time.scale()
              .domain([xMin, xMax])
              .range([0, w]);

            yScale = d3.scale.linear()
              .domain([yMin, yMax])
              .range([h, 0]);
              # y output reversed because elements are positioned top/left




Sunday, 7 April 13
readings = [{
              read_at: '2013-03-27T00:04:00Z'
              wind_speed: 28,
              gust: 34,
              wind_direction: 287.3
            }...]

            xPoint = (reading)-> xScale(new Date(reading.read_at))
            yPointBySpeed = (reading)-> yScale(reading.wind_speed)
            yPointByGust = (reading)-> yScale(reading.gust)

            speedLine = d3.svg.line()
              .x(xPoint)
              .y(yPointBySpeed)

            # dark blue line
            svg.append("svg:path")
              .attr("d", speedLine(readings))
              .attr("stroke-width", 2)
              .attr("stroke", "#04C8FF")
              .attr("fill", "none")

Sunday, 7 April 13
speeds = []
            gusts = []
            for reading in data
              x = xPoint reading
              speeds.push [x, yPointBySpeed(reading)]
              gusts.push [x, yPointByGust(reading)]

            # light blue area
            # array of speed(x,y) followed by array of gust(x,y) reversed
            svg.selectAll("path.area")
              .data([speeds.concat(gusts.reverse())])
              .enter()
              .append("path")
              .attr("fill", "#04C8FF")
              .attr("fill-opacity", .2)
              .attr("d", d3.svg.area())




Sunday, 7 April 13
# arrow heads
            arrowTransform = (reading)->
              "translate(#{xPoint(reading)}, #{yPointBySpeed(reading)}),
               rotate(#{reading.wind_direction})"

            svg.selectAll("polygon")
              .data(data)
              .enter()
              .append("polygon")
              .attr("transform", arrowTransform)
              .attr("points", "0,-7.8 -5.1,7.8 0,5.4 5.1,7.8")
              .attr("stroke-width", 1)
              .attr("stroke", "#fff")
              .attr("fill", "#04C8FF")




Sunday, 7 April 13
yPointBySwellPeriod = (reading)->
              yScale(reading.swell_period)

            swellLine = d3.svg.line()
              .x(xPoint)
              .y(yPointBySwellPeriod)
              .interpolate("cardinal")
              # Many ways for svg paths to be drawn around the points

            svg.append("svg:path")
              .attr("d", swellLine(data))
              .attr("stroke-width", 2)
              .attr("stroke", "#28d7bd")
              .attr("fill", "none")




Sunday, 7 April 13
Lots of things I’m yet to play with..

                                      Transitions
                                Events - mouse, touches
                                          Ajax
                                         Colors
                                          Axes
                                   Other scale types
                                     Other shapes
                                    Time Intervals

                Cluster, Force, Hierarchy, Histogram, Pack, Partition, Pie,
                Stack, Tree, Treemap, Geography, Projections, Zoom etc..


Sunday, 7 April 13
d3 is cool
                                  Thanks!

                     http://alignedleft.com/tutorials/d3/

                              @markbrown4




Sunday, 7 April 13

Mais conteúdo relacionado

Mais procurados

Advanced Data Visualization Examples with R-Part II
Advanced Data Visualization Examples with R-Part IIAdvanced Data Visualization Examples with R-Part II
Advanced Data Visualization Examples with R-Part IIDr. Volkan OBAN
 
Effector: we need to go deeper
Effector: we need to go deeperEffector: we need to go deeper
Effector: we need to go deeperVictor Didenko
 
Html5 canvas
Html5 canvasHtml5 canvas
Html5 canvasGary Yeh
 
Drawing with the HTML5 Canvas
Drawing with the HTML5 CanvasDrawing with the HTML5 Canvas
Drawing with the HTML5 CanvasHenry Osborne
 
ARTDM 170, Week 13: Text Elements + Arrays
ARTDM 170, Week 13: Text Elements + ArraysARTDM 170, Week 13: Text Elements + Arrays
ARTDM 170, Week 13: Text Elements + ArraysGilbert Guerrero
 
Advanced Data Visualization in R- Somes Examples.
Advanced Data Visualization in R- Somes Examples.Advanced Data Visualization in R- Somes Examples.
Advanced Data Visualization in R- Somes Examples.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
 
λ | Lenses
λ | Lensesλ | Lenses
λ | LensesOpen-IT
 
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
 
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
 
Pointer Events in Canvas
Pointer Events in CanvasPointer Events in Canvas
Pointer Events in Canvasdeanhudson
 
Expand/Collapse animation on Android
Expand/Collapse animation on AndroidExpand/Collapse animation on Android
Expand/Collapse animation on AndroidPavlo Dudka
 
Will it Blend? - ScalaSyd February 2015
Will it Blend? - ScalaSyd February 2015Will it Blend? - ScalaSyd February 2015
Will it Blend? - ScalaSyd February 2015Filippo Vitale
 

Mais procurados (20)

Functional programming in scala
Functional programming in scalaFunctional programming in scala
Functional programming in scala
 
Advanced Data Visualization Examples with R-Part II
Advanced Data Visualization Examples with R-Part IIAdvanced Data Visualization Examples with R-Part II
Advanced Data Visualization Examples with R-Part II
 
Effector: we need to go deeper
Effector: we need to go deeperEffector: we need to go deeper
Effector: we need to go deeper
 
Introduction to D3
Introduction to D3 Introduction to D3
Introduction to D3
 
Intro to HTML5 Canvas
Intro to HTML5 CanvasIntro to HTML5 Canvas
Intro to HTML5 Canvas
 
Html5 canvas
Html5 canvasHtml5 canvas
Html5 canvas
 
Fuzzy Data Leaks
Fuzzy Data LeaksFuzzy Data Leaks
Fuzzy Data Leaks
 
Drawing with the HTML5 Canvas
Drawing with the HTML5 CanvasDrawing with the HTML5 Canvas
Drawing with the HTML5 Canvas
 
Ml all programs
Ml all programsMl all programs
Ml all programs
 
ARTDM 170, Week 13: Text Elements + Arrays
ARTDM 170, Week 13: Text Elements + ArraysARTDM 170, Week 13: Text Elements + Arrays
ARTDM 170, Week 13: Text Elements + Arrays
 
Supstat nyc subway
Supstat nyc subwaySupstat nyc subway
Supstat nyc subway
 
Advanced Data Visualization in R- Somes Examples.
Advanced Data Visualization in R- Somes Examples.Advanced Data Visualization in R- Somes Examples.
Advanced Data Visualization in R- Somes Examples.
 
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
 
Beyond Scala Lens
Beyond Scala LensBeyond Scala Lens
Beyond Scala Lens
 
λ | Lenses
λ | Lensesλ | Lenses
λ | Lenses
 
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
 
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
 
Pointer Events in Canvas
Pointer Events in CanvasPointer Events in Canvas
Pointer Events in Canvas
 
Expand/Collapse animation on Android
Expand/Collapse animation on AndroidExpand/Collapse animation on Android
Expand/Collapse animation on Android
 
Will it Blend? - ScalaSyd February 2015
Will it Blend? - ScalaSyd February 2015Will it Blend? - ScalaSyd February 2015
Will it Blend? - ScalaSyd February 2015
 

Destaque

7 tips for great presentations
7 tips for great presentations7 tips for great presentations
7 tips for great presentationsEnglish Teaching
 
Bhagavat Gita Simplified[1]
Bhagavat Gita Simplified[1]Bhagavat Gita Simplified[1]
Bhagavat Gita Simplified[1]Sekar S
 
FM&amp;Property Summit Oct2011
FM&amp;Property Summit Oct2011FM&amp;Property Summit Oct2011
FM&amp;Property Summit Oct2011pcarder
 
Why Does God Exist
Why Does God ExistWhy Does God Exist
Why Does God ExistBlooper
 
Lychnari 2005 01 Zigeuners
Lychnari 2005 01 ZigeunersLychnari 2005 01 Zigeuners
Lychnari 2005 01 Zigeunerszefanjahoogers
 
Don\'t Sprint the Marathon
Don\'t Sprint the MarathonDon\'t Sprint the Marathon
Don\'t Sprint the MarathonSekar S
 

Destaque (9)

7 tips for great presentations
7 tips for great presentations7 tips for great presentations
7 tips for great presentations
 
Bhagavat Gita Simplified[1]
Bhagavat Gita Simplified[1]Bhagavat Gita Simplified[1]
Bhagavat Gita Simplified[1]
 
Project
ProjectProject
Project
 
FM&amp;Property Summit Oct2011
FM&amp;Property Summit Oct2011FM&amp;Property Summit Oct2011
FM&amp;Property Summit Oct2011
 
Why Does God Exist
Why Does God ExistWhy Does God Exist
Why Does God Exist
 
Lychnari 2005 01 Zigeuners
Lychnari 2005 01 ZigeunersLychnari 2005 01 Zigeuners
Lychnari 2005 01 Zigeuners
 
Don\'t Sprint the Marathon
Don\'t Sprint the MarathonDon\'t Sprint the Marathon
Don\'t Sprint the Marathon
 
Fixtures
FixturesFixtures
Fixtures
 
Child Development
Child DevelopmentChild Development
Child Development
 

Semelhante a d3 is cool

D3.js 30-minute intro
D3.js   30-minute introD3.js   30-minute intro
D3.js 30-minute introFelipe
 
Better d3 charts with tdd
Better d3 charts with tddBetter d3 charts with tdd
Better d3 charts with tddMarcos Iglesias
 
D3 svg & angular
D3 svg & angularD3 svg & angular
D3 svg & angular500Tech
 
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
 
An overview of Python 2.7
An overview of Python 2.7An overview of Python 2.7
An overview of Python 2.7decoupled
 
Useful javascript
Useful javascriptUseful javascript
Useful javascriptLei Kang
 
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
 
Chapter3_Visualizations2.pdf
Chapter3_Visualizations2.pdfChapter3_Visualizations2.pdf
Chapter3_Visualizations2.pdfMekiyaShigute1
 
07. Java Array, Set and Maps
07.  Java Array, Set and Maps07.  Java Array, Set and Maps
07. Java Array, Set and MapsIntro C# Book
 
imager package in R and examples..
imager package in R and examples..imager package in R and examples..
imager package in R and examples..Dr. Volkan OBAN
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with ClojureDmitry Buzdin
 

Semelhante a d3 is cool (20)

Scrollytelling
ScrollytellingScrollytelling
Scrollytelling
 
SVGo workshop
SVGo workshopSVGo workshop
SVGo workshop
 
D3.js 30-minute intro
D3.js   30-minute introD3.js   30-minute intro
D3.js 30-minute intro
 
Introduction to R
Introduction to RIntroduction to R
Introduction to R
 
Better d3 charts with tdd
Better d3 charts with tddBetter d3 charts with tdd
Better d3 charts with tdd
 
D3 svg & angular
D3 svg & angularD3 svg & angular
D3 svg & angular
 
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...
 
An overview of Python 2.7
An overview of Python 2.7An overview of Python 2.7
An overview of Python 2.7
 
A tour of Python
A tour of PythonA tour of Python
A tour of Python
 
Useful javascript
Useful javascriptUseful javascript
Useful javascript
 
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)
 
Joclad 2010 d
Joclad 2010 dJoclad 2010 d
Joclad 2010 d
 
Chapter3_Visualizations2.pdf
Chapter3_Visualizations2.pdfChapter3_Visualizations2.pdf
Chapter3_Visualizations2.pdf
 
JQuery Flot
JQuery FlotJQuery Flot
JQuery Flot
 
07. Java Array, Set and Maps
07.  Java Array, Set and Maps07.  Java Array, Set and Maps
07. Java Array, Set and Maps
 
imager package in R and examples..
imager package in R and examples..imager package in R and examples..
imager package in R and examples..
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
 
Ggplot2 v3
Ggplot2 v3Ggplot2 v3
Ggplot2 v3
 
D3
D3D3
D3
 

Último

Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
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
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusZilliz
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
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
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...apidays
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
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
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
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
 

Último (20)

Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
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...
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
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, ...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
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
 

d3 is cool

  • 1. d3 is cool maps data to DOM Sunday, 7 April 13
  • 2. # jQuery-esque API d3 .select("body") .append("p") .text("New paragraph!") .attr("class", "yep") .style("height", "10px") Sunday, 7 April 13
  • 3. data = [] for num in [0..25] data.push Math.random() * 30 d3.select("#bar") # get a wrapper element .selectAll("div") # get an array .data(data) # get a data-bound array .enter() # creates new nodes .append("div") # adds to DOM .style("height", (d)-> d * 5 + "px") Sunday, 7 April 13
  • 4. maps data to DOM Sunday, 7 April 13
  • 5. svg is cool DOM for vector graphics & text Sunday, 7 April 13
  • 6. <svg height="200" width="700"> <rect x="0" y="0" width="500" height="50"> <circle cx="10" cy="100" r="50" fill="red"> <text x="250" y="50">Easy-peasy</text> <path d="M 100 100 L 300 100 L 200 300 z" stroke-width="3"> <image> <font> # fek yeah </svg> Sunday, 7 April 13
  • 7. svg = d3.select("body") .append("svg") .attr("width", w) .attr("height", h) circles = svg.selectAll() .data(dataset) .enter() .append("circle") .attr("cx", (d, i)-> i * 22) .attr("cy", 50) .attr("r", (d)-> d / 2) .attr("fill", (d)-> "rgb(" + Math.floor(d * 6) + ",0,150)") Sunday, 7 April 13
  • 8. data = [ [5, 20], ... [220, 88] ] svg = getSVG() svg.selectAll() .data(data) .enter() .append("circle") .attr("cx", (d)-> d[0]) .attr("cy", (d)-> d[1]) .attr("r", 4) Sunday, 7 April 13
  • 9. # scales - d3's best feature # functions that map an input range to an output range xScale = d3.time.scale() .domain([xMin, xMax]) .range([0, w]); yScale = d3.scale.linear() .domain([yMin, yMax]) .range([h, 0]); # y output reversed because elements are positioned top/left Sunday, 7 April 13
  • 10. readings = [{ read_at: '2013-03-27T00:04:00Z' wind_speed: 28, gust: 34, wind_direction: 287.3 }...] xPoint = (reading)-> xScale(new Date(reading.read_at)) yPointBySpeed = (reading)-> yScale(reading.wind_speed) yPointByGust = (reading)-> yScale(reading.gust) speedLine = d3.svg.line() .x(xPoint) .y(yPointBySpeed) # dark blue line svg.append("svg:path") .attr("d", speedLine(readings)) .attr("stroke-width", 2) .attr("stroke", "#04C8FF") .attr("fill", "none") Sunday, 7 April 13
  • 11. speeds = [] gusts = [] for reading in data x = xPoint reading speeds.push [x, yPointBySpeed(reading)] gusts.push [x, yPointByGust(reading)] # light blue area # array of speed(x,y) followed by array of gust(x,y) reversed svg.selectAll("path.area") .data([speeds.concat(gusts.reverse())]) .enter() .append("path") .attr("fill", "#04C8FF") .attr("fill-opacity", .2) .attr("d", d3.svg.area()) Sunday, 7 April 13
  • 12. # arrow heads arrowTransform = (reading)-> "translate(#{xPoint(reading)}, #{yPointBySpeed(reading)}), rotate(#{reading.wind_direction})" svg.selectAll("polygon") .data(data) .enter() .append("polygon") .attr("transform", arrowTransform) .attr("points", "0,-7.8 -5.1,7.8 0,5.4 5.1,7.8") .attr("stroke-width", 1) .attr("stroke", "#fff") .attr("fill", "#04C8FF") Sunday, 7 April 13
  • 13. yPointBySwellPeriod = (reading)-> yScale(reading.swell_period) swellLine = d3.svg.line() .x(xPoint) .y(yPointBySwellPeriod) .interpolate("cardinal") # Many ways for svg paths to be drawn around the points svg.append("svg:path") .attr("d", swellLine(data)) .attr("stroke-width", 2) .attr("stroke", "#28d7bd") .attr("fill", "none") Sunday, 7 April 13
  • 14. Lots of things I’m yet to play with.. Transitions Events - mouse, touches Ajax Colors Axes Other scale types Other shapes Time Intervals Cluster, Force, Hierarchy, Histogram, Pack, Partition, Pie, Stack, Tree, Treemap, Geography, Projections, Zoom etc.. Sunday, 7 April 13
  • 15. d3 is cool Thanks! http://alignedleft.com/tutorials/d3/ @markbrown4 Sunday, 7 April 13