SlideShare ist ein Scribd-Unternehmen logo
1 von 27
Downloaden Sie, um offline zu lesen
Washington DC 2013




      Visualizing MongoDB Objects
        in Concept and Practice
https://github.com/cvitter/ikanow.mongodc2013.presentation
Introduction

•  Do you have a MongoDB database full of BSON
   documents crying out for visual analysis?
Agenda

•  Visualizing Objects vs. Records
•  Getting Your Data from MongoDB
•  JSON 101
•  Free & Open Source Visualization Libraries
    –  Google Maps JavaScript API
    –  D3.js
•  Other Visualization Libraries You Should Know
•  Questions?
Objects vs. Records

•  Document oriented data stores support dynamic and
   complex schemas vs. the simple, static structures in
   RDBMs, e.g.:
Is There Really a Difference?

•  Yes and No

•  Yes
    •  Obviously, document oriented formats are different from
       record oriented formats;
    •  Few common visualizations tools designed for
       traditional record based formats support document
       based formats

•  No
    •  The basic visualizations are the same even if the data
       format feeding them are different
Getting your Data from MongoDB

•  mongoexport
   Export data from MongoDB as JSON or CSV
  > mongoexport --db dbname --collection collectionname 

    --out file.json!

•  MongoDB’s Simple REST Interface
   •  Read only access to data
   •  Start your server with the --rest option
   •  Simple queries:
     http://127.0.0.1:28017/databaseName/collectionName/!


•  Other options:
   •  DrowsyDromedary, MongoDB Rest, etc.
JSON 101

•  JSON (JavaScript Object Notation) documents
   are built using two types of common data structures:
   •  Name/value pairs (objects) and;
     { “string” : value }!
   •  Ordered lists of values (arrays).
     { “string” : [value, value, value] }!

•  JSON is a subset of the object literal notation
   of JavaScript so:
  var jsonObj = {"numbers" : [1, 2, 3] };!
  var numberOne = jsonObj.numbers[0];!
  var numberTwo = jsonObj.numbers[1];!

•  Converting the string representation of JSON is as easy as:
  var jsonObj = JSON.parse("{"numbers":[1,2,3]}");!
A Word About the Sample Code

•  All of the code used in this presentation is available online
   via GitHub at:
  https://github.com/cvitter/ikanow.mongodc2013.presentation

  "
•  The project includes code from the following Open Source
   Projects:
   •  Bootstrap: http://twitter.github.com/bootstrap/!
   •  JQuery: http://jquery.com/!
   •  D3.js: http://d3js.org/

      !
•  The data samples used are simple JSON files read in using
   JQuery’a .ajax method
Google Maps JavaScript API

•  Requirements:
    •  Get an API Key (its free*)
    •  Have an Internet Connection

•  Build a simple example that:
    1.  Creates a place holder DIV for the map object
    2.  Loads the map script
    3.  Initializes the map
    4.  Draws markers on the map




 * Up to 25,000 map loads per day for commercial applications.
Creating the Map

•  Use a DIV to create a placeholder for the map:
   <div id="map_canvas" style="height:450px; width:870px;"></div>!

•  Load the map script:
   function loadScript() {!
      var script = document.createElement("script");!
      script.type = "text/javascript";!
      script.src = "http://maps.googleapis.com/maps/api/js?

       !key=YOUR_API_KEY&sensor=TRUE_OR_FALSE&callback=initialize";!
      document.body.appendChild(script);!
   }!

•  Initialize the map:
    var mapOptions = {!
        !zoom: 11,!
        !center: new google.maps.LatLng( 38.8964, -77.0262 ),!
        !mapTypeId: google.maps.MapTypeId.ROADMAP!
    };!
    map = new google.maps.Map(document.getElementById('map_canvas'),   !
        !   !mapOptions);!
Drawing Markers on the Map

•  Sample documents:
  {...},!
  {!
      !search_field: "adams morgan",!
      !country: "United States",!
      !country_code: "US",!
      !region: "District of Columbia",!
      !latitude: "38.9213889",!
      !longitude: "-77.0425000”}!
  },!
  {...},!


•  Add markers to the map:
  for (var i=0; i < locations.length; i++) {!    !   !   !!
     !var marker = new google.maps.Marker({!
     !    !map: map,   !!
     !    !position: new google.maps.LatLng(!
     !    !   !locations[i].latitude , locations[i].longitude ),!
     !    !title: convertToTitleCase(locations[i].search_field)!
     !});!
  }!
The Finished Product
Creating Heat Maps

•  Requires the Visualization Library:
  script.src = "http://maps.googleapis.com/maps/api/js?

     !key=YOUR_API_KEY&sensor=TRUE_OR_FALSE&libraries=visualiza-on	
  
      	
  &callback=initialize";!


•  Create the Heat Map Data and Layer:
  var heatMapData = new Array();!
  for (var i=0; i < locations.length; i++) {!
       var newRecord = {location: new

          !google.maps.LatLng( locations[i].geoindex.lat ,

          !    !locations[i].geoindex.lon), weight: 1};!
       heatMapData.push(newRecord);!
  }!
     !    !!
  var heatmap = new google.maps.visualization.HeatmapLayer({!
       data: heatMapData,!
       dissipating: true,!
       radius: 10,!
       map: map!
  });!
The Finished Product
D3.js

•  D3.js (d3js.org) is:
    “a JavaScript library for manipulating documents based on
    data”

•  Convert data into visualizations in the following formats:
   HTML, CSS, SVG

•  Download the library or include it via:
  <script src="http://d3js.org/d3.v3.min.js"></script>!
The (Very) Basics

•  Select the DIV to write the SVG image to:
  var chart = d3.select("#d3_canvas").append("svg")!
      .attr("class", "chart")!
     !.attr("width", chartWidth)!
     !.attr("height", chartHeight);!

•  Draw the bars (rectangles):
  chart.selectAll("rect")!
       .data(inputData)!
     !.enter().append("rect")!
     !.attr("y", function(d, i) {return i * (lineHeight + 3); })!
     !.attr("width", function(d, i) 

     !    !{ return chartWidth * (d.chance_of_rain * 0.01); })!
     !.attr("height", function(d) return lineHeight; });!
Adding Rules

•  Making things scale on the chart:
  var x = d3.scale.linear()!
     !.domain([0, 100])!
     !.range([0, chartWidth]);!



•  Drawing the rules:
  chart.selectAll("line")!
      .data(x.ticks(10))!
     !.enter().append("line")!
     !.attr("x1", x)!
     !.attr("x2", x)!
     !.attr("y1", 0)!
     !.attr("y2", chartHeight)!
     !.style("stroke", "#ccc");!
Adding Text

•  Labeling the X and Y axes:
  chart.selectAll(".rule")!
     !.data(x.ticks(10))!
     !.enter().append("text")!
     !.attr("class", "rule")!
     !.attr("x", x)!
     !.attr("y", 0)!
     !.attr("dy", -3)!
     !.attr("text-anchor", "middle")!
     !.text(String);!
  !
  chart.selectAll("text")!
     !.data(inputData)!
     !.enter().append("text")!
     !.attr("x", 0)!
     !.attr("y", function(d, i) {

     !   !return i * (lineHeight + 3) + (lineHeight / 2); })!
     !.attr("dx", -3) // padding-right!
     !.attr("dy", ".35em") // vertical-align: middle!
     !.attr("text-anchor", "end") // text-align: right!
     !.text(function(d) { return d.date; });!
The Finished Product
Treemaps, Bubble Charts, and More

•  D3.js can accept an array of values, objects, or a function
   that returns an array of values

•  Some of the D3.js visualizations allow you to pass data in a
   wide variety of formats, others expect a specific format

•  The Treemap and Bubble Chart samples use a really
   simple JSON tree structure representing multi-level parent
   child relationships
Treemap
Treemaps Layout

•  D3.js features different layout packs that help you build
   complex charts including .treemap
•  In this example the layout pack is creating a properly sized
   div for each node in our JSON file as opposed to creating
   an SVG image
  var treemap = d3.layout.treemap()!
     !.size([width, height])!
     !.sticky(true)!
     !.value(function(d) { return d.size; });!
  !
  var node = div.datum(data).selectAll(".node")!
     !.data(treemap.nodes)!
     !.enter().append("div")!
     !.attr("class", "node")!
     !.call(position)!
     !.style("background", function(d) { 

     !    !return d.children ? color(d.name) : null; })!
       .text(function(d) { return d.children ? null : d.name; });!
Bubble Chart
Other D3js.org Examples
More Cool Visualization Libraries

•  NVD3 (nvd3.org)
  Re-usable charts and chart components for d3.js

•  Raphael JS (raphaeljs.com)
  JavaScript library designed to simplify working with vector graphics and
  build data visualizations

•  TimelineJS (timeline.verite.co)
  “Beautifully crafted timelines that are easy, and intuitive to use.”
Reminder: Get the Example Code

•  All of the sample code used in this presentation is available
   online via GitHub at:




            https://github.com/cvitter/
            ikanow.mongodc2013.presentation	
  
Thank You!

                  Craig	
  Vi4er	
  
                        	
  
                        	
  
                www.ikanow.com	
  
             developer.ikanow.com	
  
              cvi,er@ikanow.com	
  
                  @IkanowDev	
  
                        	
  
               github.com/ikanow/Infinit.e	
  

Weitere ähnliche Inhalte

Was ist angesagt?

Aggregation Framework MongoDB Days Munich
Aggregation Framework MongoDB Days MunichAggregation Framework MongoDB Days Munich
Aggregation Framework MongoDB Days MunichNorberto Leite
 
Introduction to d3js (and SVG)
Introduction to d3js (and SVG)Introduction to d3js (and SVG)
Introduction to d3js (and SVG)zahid-mian
 
MongoDB Aggregation Framework
MongoDB Aggregation FrameworkMongoDB Aggregation Framework
MongoDB Aggregation FrameworkTyler Brock
 
Aggregation Framework in MongoDB Overview Part-1
Aggregation Framework in MongoDB Overview Part-1Aggregation Framework in MongoDB Overview Part-1
Aggregation Framework in MongoDB Overview Part-1Anuj Jain
 
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
 
The Aggregation Framework
The Aggregation FrameworkThe Aggregation Framework
The Aggregation FrameworkMongoDB
 
MongoDB Aggregation Framework
MongoDB Aggregation FrameworkMongoDB Aggregation Framework
MongoDB Aggregation FrameworkCaserta
 
Tearing the Sofa Apart: CouchDB and CouchApps from a Beginner's Perspective
Tearing the Sofa Apart: CouchDB and CouchApps from a Beginner's PerspectiveTearing the Sofa Apart: CouchDB and CouchApps from a Beginner's Perspective
Tearing the Sofa Apart: CouchDB and CouchApps from a Beginner's PerspectiveSeh Hui Leong
 
Ajax tutorial
Ajax tutorialAjax tutorial
Ajax tutorialKat Roque
 
Aggregation Framework
Aggregation FrameworkAggregation Framework
Aggregation FrameworkMongoDB
 
1403 app dev series - session 5 - analytics
1403   app dev series - session 5 - analytics1403   app dev series - session 5 - analytics
1403 app dev series - session 5 - analyticsMongoDB
 
10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data Modeling10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data ModelingDATAVERSITY
 
Edição de Texto Rico com React e Draft.js
Edição de Texto Rico com React e Draft.jsEdição de Texto Rico com React e Draft.js
Edição de Texto Rico com React e Draft.jsGuilherme Vierno
 
An in-depth look at jQuery
An in-depth look at jQueryAn in-depth look at jQuery
An in-depth look at jQueryPaul Bakaus
 
Schema design
Schema designSchema design
Schema designchristkv
 
HTML5 after the hype - JFokus2015
HTML5 after the hype - JFokus2015HTML5 after the hype - JFokus2015
HTML5 after the hype - JFokus2015Christian Heilmann
 

Was ist angesagt? (20)

wtf is in Java/JDK/wtf7?
wtf is in Java/JDK/wtf7?wtf is in Java/JDK/wtf7?
wtf is in Java/JDK/wtf7?
 
Aggregation Framework MongoDB Days Munich
Aggregation Framework MongoDB Days MunichAggregation Framework MongoDB Days Munich
Aggregation Framework MongoDB Days Munich
 
Introduction to d3js (and SVG)
Introduction to d3js (and SVG)Introduction to d3js (and SVG)
Introduction to d3js (and SVG)
 
MongoDB Aggregation Framework
MongoDB Aggregation FrameworkMongoDB Aggregation Framework
MongoDB Aggregation Framework
 
Aggregation Framework in MongoDB Overview Part-1
Aggregation Framework in MongoDB Overview Part-1Aggregation Framework in MongoDB Overview Part-1
Aggregation Framework in MongoDB Overview Part-1
 
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...
 
The Aggregation Framework
The Aggregation FrameworkThe Aggregation Framework
The Aggregation Framework
 
MongoDB Aggregation Framework
MongoDB Aggregation FrameworkMongoDB Aggregation Framework
MongoDB Aggregation Framework
 
Polyglot Persistence
Polyglot PersistencePolyglot Persistence
Polyglot Persistence
 
Tearing the Sofa Apart: CouchDB and CouchApps from a Beginner's Perspective
Tearing the Sofa Apart: CouchDB and CouchApps from a Beginner's PerspectiveTearing the Sofa Apart: CouchDB and CouchApps from a Beginner's Perspective
Tearing the Sofa Apart: CouchDB and CouchApps from a Beginner's Perspective
 
Ajax tutorial
Ajax tutorialAjax tutorial
Ajax tutorial
 
Aggregation Framework
Aggregation FrameworkAggregation Framework
Aggregation Framework
 
SVGD3Angular2React
SVGD3Angular2ReactSVGD3Angular2React
SVGD3Angular2React
 
1403 app dev series - session 5 - analytics
1403   app dev series - session 5 - analytics1403   app dev series - session 5 - analytics
1403 app dev series - session 5 - analytics
 
Web2.0 with jQuery in English
Web2.0 with jQuery in EnglishWeb2.0 with jQuery in English
Web2.0 with jQuery in English
 
10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data Modeling10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data Modeling
 
Edição de Texto Rico com React e Draft.js
Edição de Texto Rico com React e Draft.jsEdição de Texto Rico com React e Draft.js
Edição de Texto Rico com React e Draft.js
 
An in-depth look at jQuery
An in-depth look at jQueryAn in-depth look at jQuery
An in-depth look at jQuery
 
Schema design
Schema designSchema design
Schema design
 
HTML5 after the hype - JFokus2015
HTML5 after the hype - JFokus2015HTML5 after the hype - JFokus2015
HTML5 after the hype - JFokus2015
 

Ähnlich wie Mongo db washington dc 2014

Intro to node.js - Ran Mizrahi (27/8/2014)
Intro to node.js - Ran Mizrahi (27/8/2014)Intro to node.js - Ran Mizrahi (27/8/2014)
Intro to node.js - Ran Mizrahi (27/8/2014)Ran Mizrahi
 
Intro to node.js - Ran Mizrahi (28/8/14)
Intro to node.js - Ran Mizrahi (28/8/14)Intro to node.js - Ran Mizrahi (28/8/14)
Intro to node.js - Ran Mizrahi (28/8/14)Ran Mizrahi
 
Crafting Evolvable Api Responses
Crafting Evolvable Api ResponsesCrafting Evolvable Api Responses
Crafting Evolvable Api Responsesdarrelmiller71
 
Practical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.jsPractical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.jsasync_io
 
Creating Dynamic Charts With JFreeChart
Creating Dynamic Charts With JFreeChartCreating Dynamic Charts With JFreeChart
Creating Dynamic Charts With JFreeChartDavid Keener
 
COMP 4026 Lecture 5 OpenFrameworks and Soli
COMP 4026 Lecture 5 OpenFrameworks and SoliCOMP 4026 Lecture 5 OpenFrameworks and Soli
COMP 4026 Lecture 5 OpenFrameworks and SoliMark Billinghurst
 
Hi performance table views with QuartzCore and CoreText
Hi performance table views with QuartzCore and CoreTextHi performance table views with QuartzCore and CoreText
Hi performance table views with QuartzCore and CoreTextMugunth Kumar
 
Solid and Sustainable Development in Scala
Solid and Sustainable Development in ScalaSolid and Sustainable Development in Scala
Solid and Sustainable Development in Scalascalaconfjp
 
The Fine Art of Schema Design in MongoDB: Dos and Don'ts
The Fine Art of Schema Design in MongoDB: Dos and Don'tsThe Fine Art of Schema Design in MongoDB: Dos and Don'ts
The Fine Art of Schema Design in MongoDB: Dos and Don'tsMatias Cascallares
 
Solid And Sustainable Development in Scala
Solid And Sustainable Development in ScalaSolid And Sustainable Development in Scala
Solid And Sustainable Development in ScalaKazuhiro Sera
 
Spring 3 - An Introduction
Spring 3 - An IntroductionSpring 3 - An Introduction
Spring 3 - An IntroductionThorsten Kamann
 
"Визуализация данных с помощью d3.js", Михаил Дунаев, MoscowJS 19
"Визуализация данных с помощью d3.js", Михаил Дунаев, MoscowJS 19"Визуализация данных с помощью d3.js", Михаил Дунаев, MoscowJS 19
"Визуализация данных с помощью d3.js", Михаил Дунаев, MoscowJS 19MoscowJS
 
About Best friends - HTML, CSS and JS
About Best friends - HTML, CSS and JSAbout Best friends - HTML, CSS and JS
About Best friends - HTML, CSS and JSNaga Harish M
 
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
 
JavaScript!
JavaScript!JavaScript!
JavaScript!RTigger
 

Ähnlich wie Mongo db washington dc 2014 (20)

Intro to node.js - Ran Mizrahi (27/8/2014)
Intro to node.js - Ran Mizrahi (27/8/2014)Intro to node.js - Ran Mizrahi (27/8/2014)
Intro to node.js - Ran Mizrahi (27/8/2014)
 
Intro to node.js - Ran Mizrahi (28/8/14)
Intro to node.js - Ran Mizrahi (28/8/14)Intro to node.js - Ran Mizrahi (28/8/14)
Intro to node.js - Ran Mizrahi (28/8/14)
 
Crafting Evolvable Api Responses
Crafting Evolvable Api ResponsesCrafting Evolvable Api Responses
Crafting Evolvable Api Responses
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
 
Couchbas for dummies
Couchbas for dummiesCouchbas for dummies
Couchbas for dummies
 
Practical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.jsPractical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.js
 
Creating Dynamic Charts With JFreeChart
Creating Dynamic Charts With JFreeChartCreating Dynamic Charts With JFreeChart
Creating Dynamic Charts With JFreeChart
 
D3 data visualization
D3 data visualizationD3 data visualization
D3 data visualization
 
COMP 4026 Lecture 5 OpenFrameworks and Soli
COMP 4026 Lecture 5 OpenFrameworks and SoliCOMP 4026 Lecture 5 OpenFrameworks and Soli
COMP 4026 Lecture 5 OpenFrameworks and Soli
 
Jquery fundamentals
Jquery fundamentalsJquery fundamentals
Jquery fundamentals
 
Hi performance table views with QuartzCore and CoreText
Hi performance table views with QuartzCore and CoreTextHi performance table views with QuartzCore and CoreText
Hi performance table views with QuartzCore and CoreText
 
Solid and Sustainable Development in Scala
Solid and Sustainable Development in ScalaSolid and Sustainable Development in Scala
Solid and Sustainable Development in Scala
 
The Fine Art of Schema Design in MongoDB: Dos and Don'ts
The Fine Art of Schema Design in MongoDB: Dos and Don'tsThe Fine Art of Schema Design in MongoDB: Dos and Don'ts
The Fine Art of Schema Design in MongoDB: Dos and Don'ts
 
Solid And Sustainable Development in Scala
Solid And Sustainable Development in ScalaSolid And Sustainable Development in Scala
Solid And Sustainable Development in Scala
 
Spring 3 - An Introduction
Spring 3 - An IntroductionSpring 3 - An Introduction
Spring 3 - An Introduction
 
"Визуализация данных с помощью d3.js", Михаил Дунаев, MoscowJS 19
"Визуализация данных с помощью d3.js", Михаил Дунаев, MoscowJS 19"Визуализация данных с помощью d3.js", Михаил Дунаев, MoscowJS 19
"Визуализация данных с помощью d3.js", Михаил Дунаев, MoscowJS 19
 
About Best friends - HTML, CSS and JS
About Best friends - HTML, CSS and JSAbout Best friends - HTML, CSS and JS
About Best friends - HTML, CSS and JS
 
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)
 
JavaScript!
JavaScript!JavaScript!
JavaScript!
 

Mehr von ikanow

Aliasing Use Cases - How to Use IKANOW to Crunch Big Data
Aliasing Use Cases - How to Use IKANOW to Crunch Big DataAliasing Use Cases - How to Use IKANOW to Crunch Big Data
Aliasing Use Cases - How to Use IKANOW to Crunch Big Dataikanow
 
Open Analytics: Building Effective Frameworks for Social Media Analysis
Open Analytics: Building Effective Frameworks for Social Media AnalysisOpen Analytics: Building Effective Frameworks for Social Media Analysis
Open Analytics: Building Effective Frameworks for Social Media Analysisikanow
 
Dr. Michael Valivullah, NASS/USDA - Cloud Computing
Dr. Michael Valivullah, NASS/USDA - Cloud ComputingDr. Michael Valivullah, NASS/USDA - Cloud Computing
Dr. Michael Valivullah, NASS/USDA - Cloud Computingikanow
 
Cloud computing with AWS
Cloud computing with AWS Cloud computing with AWS
Cloud computing with AWS ikanow
 
Building Effective Frameworks for Social Media Analysis
Building Effective Frameworks for Social Media AnalysisBuilding Effective Frameworks for Social Media Analysis
Building Effective Frameworks for Social Media Analysisikanow
 
Open Analytics DC June 2012 Presentation
Open Analytics DC June 2012 PresentationOpen Analytics DC June 2012 Presentation
Open Analytics DC June 2012 Presentationikanow
 
MongoDC - Ikanow April 2012 Meetup
MongoDC - Ikanow April 2012 MeetupMongoDC - Ikanow April 2012 Meetup
MongoDC - Ikanow April 2012 Meetupikanow
 
Open Analytics DC April 2012 Meetup
Open Analytics DC April 2012 MeetupOpen Analytics DC April 2012 Meetup
Open Analytics DC April 2012 Meetupikanow
 
Hadoop MapReduce - I'm Sold, Now What?
Hadoop MapReduce - I'm Sold, Now What?Hadoop MapReduce - I'm Sold, Now What?
Hadoop MapReduce - I'm Sold, Now What?ikanow
 
Agile intelligence through Open Analytics
Agile intelligence through Open AnalyticsAgile intelligence through Open Analytics
Agile intelligence through Open Analyticsikanow
 
Social Intelligence: Realizing Business Value in Big Data
Social Intelligence: Realizing Business Value in Big DataSocial Intelligence: Realizing Business Value in Big Data
Social Intelligence: Realizing Business Value in Big Dataikanow
 
How IKANOW uses MongoDB to help organizations solve really big problems
How IKANOW uses MongoDB to help organizations solve really big problemsHow IKANOW uses MongoDB to help organizations solve really big problems
How IKANOW uses MongoDB to help organizations solve really big problemsikanow
 
Value Mining: How Entity Extraction Informs Analysis
Value Mining: How Entity Extraction Informs AnalysisValue Mining: How Entity Extraction Informs Analysis
Value Mining: How Entity Extraction Informs Analysisikanow
 

Mehr von ikanow (13)

Aliasing Use Cases - How to Use IKANOW to Crunch Big Data
Aliasing Use Cases - How to Use IKANOW to Crunch Big DataAliasing Use Cases - How to Use IKANOW to Crunch Big Data
Aliasing Use Cases - How to Use IKANOW to Crunch Big Data
 
Open Analytics: Building Effective Frameworks for Social Media Analysis
Open Analytics: Building Effective Frameworks for Social Media AnalysisOpen Analytics: Building Effective Frameworks for Social Media Analysis
Open Analytics: Building Effective Frameworks for Social Media Analysis
 
Dr. Michael Valivullah, NASS/USDA - Cloud Computing
Dr. Michael Valivullah, NASS/USDA - Cloud ComputingDr. Michael Valivullah, NASS/USDA - Cloud Computing
Dr. Michael Valivullah, NASS/USDA - Cloud Computing
 
Cloud computing with AWS
Cloud computing with AWS Cloud computing with AWS
Cloud computing with AWS
 
Building Effective Frameworks for Social Media Analysis
Building Effective Frameworks for Social Media AnalysisBuilding Effective Frameworks for Social Media Analysis
Building Effective Frameworks for Social Media Analysis
 
Open Analytics DC June 2012 Presentation
Open Analytics DC June 2012 PresentationOpen Analytics DC June 2012 Presentation
Open Analytics DC June 2012 Presentation
 
MongoDC - Ikanow April 2012 Meetup
MongoDC - Ikanow April 2012 MeetupMongoDC - Ikanow April 2012 Meetup
MongoDC - Ikanow April 2012 Meetup
 
Open Analytics DC April 2012 Meetup
Open Analytics DC April 2012 MeetupOpen Analytics DC April 2012 Meetup
Open Analytics DC April 2012 Meetup
 
Hadoop MapReduce - I'm Sold, Now What?
Hadoop MapReduce - I'm Sold, Now What?Hadoop MapReduce - I'm Sold, Now What?
Hadoop MapReduce - I'm Sold, Now What?
 
Agile intelligence through Open Analytics
Agile intelligence through Open AnalyticsAgile intelligence through Open Analytics
Agile intelligence through Open Analytics
 
Social Intelligence: Realizing Business Value in Big Data
Social Intelligence: Realizing Business Value in Big DataSocial Intelligence: Realizing Business Value in Big Data
Social Intelligence: Realizing Business Value in Big Data
 
How IKANOW uses MongoDB to help organizations solve really big problems
How IKANOW uses MongoDB to help organizations solve really big problemsHow IKANOW uses MongoDB to help organizations solve really big problems
How IKANOW uses MongoDB to help organizations solve really big problems
 
Value Mining: How Entity Extraction Informs Analysis
Value Mining: How Entity Extraction Informs AnalysisValue Mining: How Entity Extraction Informs Analysis
Value Mining: How Entity Extraction Informs Analysis
 

Mongo db washington dc 2014

  • 1. Washington DC 2013 Visualizing MongoDB Objects in Concept and Practice https://github.com/cvitter/ikanow.mongodc2013.presentation
  • 2. Introduction •  Do you have a MongoDB database full of BSON documents crying out for visual analysis?
  • 3. Agenda •  Visualizing Objects vs. Records •  Getting Your Data from MongoDB •  JSON 101 •  Free & Open Source Visualization Libraries –  Google Maps JavaScript API –  D3.js •  Other Visualization Libraries You Should Know •  Questions?
  • 4. Objects vs. Records •  Document oriented data stores support dynamic and complex schemas vs. the simple, static structures in RDBMs, e.g.:
  • 5. Is There Really a Difference? •  Yes and No •  Yes •  Obviously, document oriented formats are different from record oriented formats; •  Few common visualizations tools designed for traditional record based formats support document based formats •  No •  The basic visualizations are the same even if the data format feeding them are different
  • 6. Getting your Data from MongoDB •  mongoexport Export data from MongoDB as JSON or CSV > mongoexport --db dbname --collection collectionname 
 --out file.json! •  MongoDB’s Simple REST Interface •  Read only access to data •  Start your server with the --rest option •  Simple queries: http://127.0.0.1:28017/databaseName/collectionName/! •  Other options: •  DrowsyDromedary, MongoDB Rest, etc.
  • 7. JSON 101 •  JSON (JavaScript Object Notation) documents are built using two types of common data structures: •  Name/value pairs (objects) and; { “string” : value }! •  Ordered lists of values (arrays). { “string” : [value, value, value] }! •  JSON is a subset of the object literal notation of JavaScript so: var jsonObj = {"numbers" : [1, 2, 3] };! var numberOne = jsonObj.numbers[0];! var numberTwo = jsonObj.numbers[1];! •  Converting the string representation of JSON is as easy as: var jsonObj = JSON.parse("{"numbers":[1,2,3]}");!
  • 8. A Word About the Sample Code •  All of the code used in this presentation is available online via GitHub at: https://github.com/cvitter/ikanow.mongodc2013.presentation
 " •  The project includes code from the following Open Source Projects: •  Bootstrap: http://twitter.github.com/bootstrap/! •  JQuery: http://jquery.com/! •  D3.js: http://d3js.org/
 ! •  The data samples used are simple JSON files read in using JQuery’a .ajax method
  • 9. Google Maps JavaScript API •  Requirements: •  Get an API Key (its free*) •  Have an Internet Connection •  Build a simple example that: 1.  Creates a place holder DIV for the map object 2.  Loads the map script 3.  Initializes the map 4.  Draws markers on the map * Up to 25,000 map loads per day for commercial applications.
  • 10. Creating the Map •  Use a DIV to create a placeholder for the map: <div id="map_canvas" style="height:450px; width:870px;"></div>! •  Load the map script: function loadScript() {! var script = document.createElement("script");! script.type = "text/javascript";! script.src = "http://maps.googleapis.com/maps/api/js?
 !key=YOUR_API_KEY&sensor=TRUE_OR_FALSE&callback=initialize";! document.body.appendChild(script);! }! •  Initialize the map: var mapOptions = {! !zoom: 11,! !center: new google.maps.LatLng( 38.8964, -77.0262 ),! !mapTypeId: google.maps.MapTypeId.ROADMAP! };! map = new google.maps.Map(document.getElementById('map_canvas'), ! ! !mapOptions);!
  • 11. Drawing Markers on the Map •  Sample documents: {...},! {! !search_field: "adams morgan",! !country: "United States",! !country_code: "US",! !region: "District of Columbia",! !latitude: "38.9213889",! !longitude: "-77.0425000”}! },! {...},! •  Add markers to the map: for (var i=0; i < locations.length; i++) {! ! ! !! !var marker = new google.maps.Marker({! ! !map: map, !! ! !position: new google.maps.LatLng(! ! ! !locations[i].latitude , locations[i].longitude ),! ! !title: convertToTitleCase(locations[i].search_field)! !});! }!
  • 13. Creating Heat Maps •  Requires the Visualization Library: script.src = "http://maps.googleapis.com/maps/api/js?
 !key=YOUR_API_KEY&sensor=TRUE_OR_FALSE&libraries=visualiza-on    &callback=initialize";! •  Create the Heat Map Data and Layer: var heatMapData = new Array();! for (var i=0; i < locations.length; i++) {! var newRecord = {location: new
 !google.maps.LatLng( locations[i].geoindex.lat ,
 ! !locations[i].geoindex.lon), weight: 1};! heatMapData.push(newRecord);! }! ! !! var heatmap = new google.maps.visualization.HeatmapLayer({! data: heatMapData,! dissipating: true,! radius: 10,! map: map! });!
  • 15. D3.js •  D3.js (d3js.org) is: “a JavaScript library for manipulating documents based on data” •  Convert data into visualizations in the following formats: HTML, CSS, SVG •  Download the library or include it via: <script src="http://d3js.org/d3.v3.min.js"></script>!
  • 16. The (Very) Basics •  Select the DIV to write the SVG image to: var chart = d3.select("#d3_canvas").append("svg")! .attr("class", "chart")! !.attr("width", chartWidth)! !.attr("height", chartHeight);! •  Draw the bars (rectangles): chart.selectAll("rect")! .data(inputData)! !.enter().append("rect")! !.attr("y", function(d, i) {return i * (lineHeight + 3); })! !.attr("width", function(d, i) 
 ! !{ return chartWidth * (d.chance_of_rain * 0.01); })! !.attr("height", function(d) return lineHeight; });!
  • 17. Adding Rules •  Making things scale on the chart: var x = d3.scale.linear()! !.domain([0, 100])! !.range([0, chartWidth]);! •  Drawing the rules: chart.selectAll("line")! .data(x.ticks(10))! !.enter().append("line")! !.attr("x1", x)! !.attr("x2", x)! !.attr("y1", 0)! !.attr("y2", chartHeight)! !.style("stroke", "#ccc");!
  • 18. Adding Text •  Labeling the X and Y axes: chart.selectAll(".rule")! !.data(x.ticks(10))! !.enter().append("text")! !.attr("class", "rule")! !.attr("x", x)! !.attr("y", 0)! !.attr("dy", -3)! !.attr("text-anchor", "middle")! !.text(String);! ! chart.selectAll("text")! !.data(inputData)! !.enter().append("text")! !.attr("x", 0)! !.attr("y", function(d, i) {
 ! !return i * (lineHeight + 3) + (lineHeight / 2); })! !.attr("dx", -3) // padding-right! !.attr("dy", ".35em") // vertical-align: middle! !.attr("text-anchor", "end") // text-align: right! !.text(function(d) { return d.date; });!
  • 20. Treemaps, Bubble Charts, and More •  D3.js can accept an array of values, objects, or a function that returns an array of values •  Some of the D3.js visualizations allow you to pass data in a wide variety of formats, others expect a specific format •  The Treemap and Bubble Chart samples use a really simple JSON tree structure representing multi-level parent child relationships
  • 22. Treemaps Layout •  D3.js features different layout packs that help you build complex charts including .treemap •  In this example the layout pack is creating a properly sized div for each node in our JSON file as opposed to creating an SVG image var treemap = d3.layout.treemap()! !.size([width, height])! !.sticky(true)! !.value(function(d) { return d.size; });! ! var node = div.datum(data).selectAll(".node")! !.data(treemap.nodes)! !.enter().append("div")! !.attr("class", "node")! !.call(position)! !.style("background", function(d) { 
 ! !return d.children ? color(d.name) : null; })! .text(function(d) { return d.children ? null : d.name; });!
  • 25. More Cool Visualization Libraries •  NVD3 (nvd3.org) Re-usable charts and chart components for d3.js •  Raphael JS (raphaeljs.com) JavaScript library designed to simplify working with vector graphics and build data visualizations •  TimelineJS (timeline.verite.co) “Beautifully crafted timelines that are easy, and intuitive to use.”
  • 26. Reminder: Get the Example Code •  All of the sample code used in this presentation is available online via GitHub at: https://github.com/cvitter/ ikanow.mongodc2013.presentation  
  • 27. Thank You! Craig  Vi4er       www.ikanow.com   developer.ikanow.com   cvi,er@ikanow.com   @IkanowDev     github.com/ikanow/Infinit.e