LAB 03: VISUALIZATION WITH D3 September 30, 2015 SDS 235 Visual Analytics.

Slides:



Advertisements
Similar presentations
CT-376 jQuery Most popular javascript library today Latest version:
Advertisements

Chapter 16 Dynamic HTML and Animation The Web Warrior Guide to Web Design Technologies.
Web Page Behavior IS 373—Web Standards Todd Will.
Dynamic Web Pages Bert Wachsmuth. Review  Internet, IP addresses, ports, client-server, http, smtp  HTML, XHTML, XML  Style Sheets, external, internal,
High Performance Faceted Interfaces Using S2S Eric Rozell, Tetherless World Constellation.
Chapter 9 Introduction to the Document Object Model (DOM) JavaScript, Third Edition.
XP Tutorial 1 New Perspectives on JavaScript, Comprehensive1 Introducing JavaScript Hiding Addresses from Spammers.
1 Chapter 20 — Creating Web Projects Microsoft Visual Basic.NET, Introduction to Programming.
1 Using jQuery JavaScript & jQuery the missing manual (Second Edition)
Web Design Basic Concepts.
2. Introduction to the Visual Studio.NET IDE 2. Introduction to the Visual Studio.NET IDE Ch2 – Deitel’s Book.
Agenda What is AJAX? What is jQuery? Demonstration/Tutorial Resources Q&A.
JQuery CS 268. What is jQuery? From their web site:
Web 2.0: Concepts and Applications 2 Publishing Online.
CGS3066: Web Programming and Design Summer 2014 Instructor Mir Anamul Hasan.
1 CS 3870/CS 5870 Static and Dynamic Web Pages ASP.NET and IIS.
JavaScript & jQuery the missing manual Chapter 11
Building a UI with Zen Pat McGibbon –Sales Engineer.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 2 - HelloWorld Application: Introduction to.
SEG3210 DHTML Tutorial. DHTML DHTML is a combination of technologies used to create dynamic and interactive Web sites. –HTML - For creating text and image.
CSS/Photoshop Layouts – Quiz #7 Lecture Code:
Review IDIA 619 Spring 2013 Bridget M. Blodgett. HTML A basic HTML document looks like this: Sample page Sample page This is a simple sample. HTML user.
HTML5 – The Power of HTML5 – The Power of Thomas Lewis HTML5 Principal Technical Evangelist Microsoft | asimplepixel.tumblr.com.
SEG3210 DHTML Tutorial. DHTML DHTML is a combination of technologies used to create dynamic and interactive Web sites. –HTML - For creating text and image.
PUBLISHING ONLINE Chapter 2. Overview Blogs and wikis are two Web 2.0 tools that allow users to publish content online Blogs function as online journals.
Getting Started with Canvas IDIA Spring 2013 Bridget M. Blodgett.
2. Introduction to the Visual Studio.NET IDE. Chapter Outline Overview of the Visual Studio.NET IDE Overview of the Visual Studio.NET IDE Menu Bar and.
MIS 425 Lecture 3 – HTML 5 and CSS Instructor: Martin Neuhard
JavaScript, Fourth Edition
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
Tutorial 10 Programming with JavaScript
Introduction to Programming the WWW I CMSC Summer 2003 Lecture 7.
Session: 1. © Aptech Ltd. 2Introduction to the Web / Session 1  Explain the evolution of HTML  Explain the page structure used by HTML  List the drawbacks.
C#.NETASP.NETJavaPHPJavaScript PerlPythonOthersLiverpool FCMotorsports.
A Quick Introduction to d3.js & Reusable Charts Adam Pere Olin College, November 11 th 2014
Introduction to Programming the WWW I CMSC Winter 2003 Lecture 10.
Chapter 16: Ajax-Enabled Rich Internet Applications with XML and JSON TP2543 Web Programming Mohammad Faidzul Nasrudin.
Web Technologies Lecture 3 Web forms. HTML5 forms A component of a webpage that has form controls – Text fields – Buttons – Checkboxes – Range controls.
Data-Driven Document BY SIMA MEHRI. Voronoi Diagram
Data Visualization Fall What D3 is? Fall 2015Data Visualization2 JavaScript library for manipulating documents based on data Data-Driven Documents.
D3 Practicum CS 4460 – Information Visualization Megha Sandesh Prepared under advisement by Dr.Fames Foley.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
AJAX and REST. Slide 2 What is AJAX? It’s an acronym for Asynchronous JavaScript and XML Although requests need not be asynchronous It’s not really a.
JavaScript Introduction and Background. 2 Web languages Three formal languages HTML JavaScript CSS Three different tasks Document description Client-side.
Introduction to JavaScript MIS 3502, Spring 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 2/2/2016.
Please thank our sponsors?. SharePoint Data Visualization Using D3, SVG, jQuery and REST.
1 Using jQuery JavaScript & jQuery the missing manual (Second Edition)
11 jQuery Web Service Client. 22 Objectives You will be able to Use JSON (JavaScript Object Notation) for communcations between browser and server methods.
CSCI 3100 Tutorial 5 JavaScript & Ajax Jichuan Zeng Department of Computer Science and Engineering The Chinese University of Hong.
Developing Online Tools To Support The Visualization Of Ocean Data For Educational Applications Poster #1767 Michael Mills, S. Lichtenwalner,
Join the Community
Programming Web Pages with JavaScript
Lab 03: Visualization with d3
AJAX and REST.
Lab 02: Visualization with Tableau
Environmental Sensing Monitoring and Analyzing Water Temperatures
Lab 04: Interactive Visualization W/ d3
Introduction to D3.js and Bar Chart in D3.js
D3.js Tutorial (Hands on Session)
MIS JavaScript and API Workshop (Part 3)
Introduction to AJAX and JSON
Thank you Sponsors.
D3.js Tutorial (Hands on Session)
Introduction to AJAX and JSON
Ajax and JSON Jeremy Shafer Department of MIS Fox School of Business
Web Client Side Technologies Raneem Qaddoura
Ajax and JSON Jeremy Shafer Department of MIS Fox School of Business
Lab 1: D3 Setup John Fallon
Presentation transcript:

LAB 03: VISUALIZATION WITH D3 September 30, 2015 SDS 235 Visual Analytics

Announcements / Questions NYTimes recruiting event tonight at 5:30pm in the Lazarus Center, featuring Tessa Taylor, CS ’12 Free pizza! Questions that have come up re: homework: Solution will be posted at the end of this week Request for additional web-scraping demo; will work on scheduling Next homework assignment will be posted on Monday New online poll regarding lab structure

Outline Introduction to D3 Lab – Building a Bar Chart with D3 - Using HTML - Using SVG - Using external data, with bells & whistles Discussion (time permitting) Lab modeled on ““Let’s Make a Bar Chart” tutorial series by Mike Bostock,

D3.js JavaScript library designed to make web-based visualization easier Data transformation, rather than new representation Visualization problems reduced to constructing and updating a DOM DOM responds to changes in underlying data (stream or interaction) Much of what follows comes from Mike Bostock's VIZBI 2012 workshop

Why use D3? Uses existing web standards (HTML and SVG) SVG has visual primitives: rect, circle, text, path, etc. Low point of entry Future-proofing Compatibility with existing tools (like CSS and debuggers) Use what you already know! Use the browser's JavaScript console to debug interactively Can build really powerful data-to-visual transformations

Selections Selections of elements are D3’s atomic operand (much like jQuery) d3.selectAll("circle")// return all elements with // the circle tag Can select by any facet: #foo // foo //.foo // [foo=bar] // foo bar // Result is an array of elements that match description

Selection Example // Select all elements var circle = d3.selectAll("circle"); // Set some attributes and styles circle.attr("cx", 20); // Center x value = 20 circle.attr("cy", 12); // Center y value = 12 circle.attr("r", 24); // radius = 24px circle.style("fill", "red");

Selection Example Method chaining allows shorter (and more readable) code. // Select all elements // and set some attributes and styles d3.selectAll("circle").attr("cx", 20).attr("cy", 12).attr("r", 24).style("fill", "red");

Selection.append To build dynamic visualizations, we need to be able to add new elements as well var h1 = d3.selectAll("section").style("background", "steelblue").append("h1").text("Hello!"); Use caution with method chaining: append returns a new selection!

Mapping Data to Elements Data are arrays Could be numbers: var data = [1, 1, 2, 3, 5, 8]; Or objects: var data = [ {x: 10.0, y: 9.14}, {x: 8.0, y: 8.14}, {x: 13.0, y: 8.74} ]; D3 provides a pattern for managing the mapping from data to elements: enter(), update(), exit()

Thinking with joins (in 60 seconds).enter() figures out what’s changed in the dataset.update() assigns data items to visual elements.exit() cleans up things no longer being displayed

D3 Example svg.selectAll("circle").data(data).enter().append("circle").attr("cx", x).attr("cy", y).attr("r", 2.5); The first line may be surprising: why select elements that don’t exist yet? => You’re telling D3 that you want circles to correspond to data elements

D3 Example (Breakdown) var circle = svg.selectAll("circle").data(data); // Data method computes the join, // defining enter() and exit() // Appending to the enter selection // creates the missing elements circle.enter().append("circle").attr("cx", x(d) { return d.x; // New elements are bound to }) // data, so we can compute.attr("cy", y(d) { // attributes using accessor return d.y; // functions }).attr("r", 2.5);

Working with External Data CSV: d3.csv() JSON: d3.json() Database integration? Just need a (simple) web server Data loaded asynchronously (browser won't stall) Because everything is returned as an array, JavaScript's built in array functions work: array.{filter,map,sort,…} D3 also some additional data-transform methods; explore the API d3.{nest,keys,values,…} Up next: mapping from data space to visual space using scales

Ordinal Scales Map a discrete domain to a discrete range Essentially an explicit mapping var x = d3.scale.ordinal().domain(["A", "B", "C", "D"]).range([0, 10, 20, 30]); x("B"); // 10 Often used to assign categorical colors d3.scale.category20() // pre-assigned range w/ // 20 color categories

Quantitative Scales Map a continuous (numeric) domain to a continuous range var x = d3.scale.linear() // Others include sqrt(), pow().domain([12, 24]) // log(), etc..range([0, 720]); x(16); // 240 Typically, domains are derived from data:.domain([0, d3.max(numbers)]) or.domain(d3.extent(numbers)) // To compute min/max // simultaneously Sometimes, you may need a compound (“polylinear”) scale: the domain and range can have more than two values!

Line (and Area) Generators Can use scales to generate lines and regions var x = d3.scale.linear(), y = d3.scale.linear(); var line = d3.svg.line() // Line generator.x(function(d) { return x(d.x); }).y(function(d) { return y(d.y); }); svg.append("path") // Pass data to the line generator.datum(objects).attr("class", "line").attr("d", line);

Let’s play!

Discussion What are some of D3’s strengths? Weaknesses? How does it compare with Tableau?

Upcoming Demos / Assignments Next class: Dealing with Big Data Guest speaker: Rajmonda Caceres, MIT “Data Mappings” Assignment 1 due tonight at 5:59pm