1
Introduction to D3
Ma Maneesh Agrawala
CS 448B: Visualization Fall 2020
1
D3 Notebooks
2
Introduction to D3 Ma Maneesh Agrawala CS 448B: Visualization - - PDF document
Introduction to D3 Ma Maneesh Agrawala CS 448B: Visualization Fall 2020 1 D3 Notebooks 2 1 Last Time: Interaction 3 Dynamic Queries 6 2 Query and results SELECT house FROM east bay WHERE price < 1,000,000 AND bedrooms > 2
1
2
3
6
7 [Ahlberg and Schneiderman 92]
9
17
http://www.babynamewizard.com/voyager
18
19
20
Based on Wattenberg’s [2001] idea for sketch-based queries of time-series data. 21
22
23
I Controls useful for both novices and experts I Quick way to explore data
I Simple queries I Lots of controls I Amount of data shown limited by screen space
24
I Note that even passive media elicit interactions
I Pick the right interaction technique
I Selection, Brushing & Linking, Dynamic Queries 25
26
Step 1: Pick domain & data Step 2: Pose questions Step 3: Profile data Iterate as needed
Interact with data Refine questions
Screenshots of most insightful views (10+) Include titles and captions for each view
27
1.
Implement timeboxes interface
2.
Submit the application and a short write-up on canvas Can work alone or in pairs
Create a small interactive dynamic query application similar to TimeSearcher, but for top 100 personalities
28
29
30
31
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> </head> <body> Hello, world! </body> </html>
32
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> </head> <body> Hello, world! </body> </html>
33
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <style> /* CSS */ </style> </head> <body> <svg width="960" height="500"> <circle cx='120' cy='150' r='60' style='fill: gold;'> <animate attributeName='r' from='2' to='80' begin='0' dur='3' repeatCount='indefinite' /> </circle> </svg> </body> </html>
36
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <style> /* CSS */ </style> </head> <body> <svg width="960" height="500"> <circle cx='120' cy='150' r='60' style='fill: gold;'> <animate attributeName='r' from='2' to='80' begin='0' dur='3' repeatCount='indefinite' /> </circle> </svg> </body> </html>
37
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <style> /* CSS */ </style> </head> <body> Hello, world! <script> console.log(“Hello, world!”); function add2(x) { return x + 2; } console.log("2 + 2 is " + add2(2)); </script> </body> </html>
38
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <style> /* CSS */ </style> </head> <body> Hello, world! <script> console.log(“Hello, world!”); function add2(x) { return x + 2; } console.log("2 + 2 is " + add2(2)); </script> </body> </html>
39
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <style> /* CSS */ </style> </head> <body> <script src="https://d3js.org/d3.v6.min.js"></script> <script>
// JavaScript code that handles the logic of adding SVG elements // that make up the visual building blocks of your data visualization
</script> </body> </html>
40
<html> <head> <title></title> </head> <body> <h1></h1> <div> <p></p> </div> </body> </html>
[Adapted from Victoria Kirst’s cs193x slides. ]
41
<html> <head> <title></title> </head> <body> <h1></h1> <div> <p></p> </div> </body> </html>
[Adapted from Victoria Kirst’s cs193x slides. ] html head body title h1 div p
42
<html> <head> <title></title> </head> <body> <h1></h1> <div> <svg></svg> </div> </body> </html>
[Adapted from Victoria Kirst’s cs193x slides. ]
html head body title h1 div svg
43
<html> … <svg width="960" height="500"> <circle cx="10" cy="10" r="5"></circle> <circle cx="20" cy="15" r="5"></circle> </svg>
44
<script> // select all SVG circle elements var circles = d3.selectAll("circle"); </script>
<html> … <svg width="960" height="500"> <circle cx="10" cy="10" r="5"></circle> <circle cx="20" cy="15" r="5"></circle> </svg>
45
<script> // select all SVG circle elements var circles = d3.selectAll("circle"); // set attributes and styles circles.attr("cx", 40); circles.attr("cy", 50); circles.attr("r", 24); circles.style("fill", "red"); </script>
<html> … <svg width="960" height="500"> <circle cx="10" cy="10" r="5"></circle> <circle cx="20" cy="15" r="5"></circle> </svg>
46
<script> // select all SVG circle elements var circles = d3.selectAll("circle"); // set attributes and styles circles.attr("cx", 40); circles.attr("cy", 50); circles.attr("r", 24); circles.style("fill", "red"); </script>
<html> … <svg width="960" height="500"> <circle cx="10" cy="10" r="5"></circle> <circle cx="20" cy="15" r="5"></circle> </svg>
47
<script> // select all SVG circle elements var circles = d3.select("circle"); // set attributes and styles circles.attr("cx", 40); circles.attr("cy", 50); circles.attr("r", 24); circles.style("fill", "red"); </script>
<html> … <svg width="960" height="500"> <circle cx="10" cy="10" r="5"></circle> <circle cx="20" cy="15" r="5"></circle> </svg>
49
<html> … <svg width="960" height="500"> <circle cx="10" cy="10" r="5"></circle> <circle cx="20" cy="15" r="5"></circle> </svg>
<script> // all together!! d3.select("circle") .attr("cx", 40) .attr("cy", 50) .attr("r", 24) .style("fill", "red"); </script>
50
51
not have a corresponding DOM element in the original selection
bound data value
a matching data value was not found
53
54
https://observablehq.com/@stanfordvis/lets-make-a-scatterplot
55