SlideShare una empresa de Scribd logo
1 de 15
Descargar para leer sin conexión
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

Más contenido relacionado

La actualidad más candente

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
 

La actualidad más candente (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
 

Destacado

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
 

Destacado (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
 

Similar 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
 

Similar 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

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 

Último (20)

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 

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