├── .gitignore ├── D3.Rproj ├── D3template.html ├── DataBindwithKeys.html ├── EDAV1.html ├── EDAV1Notes.md ├── EDAV2.html ├── EDAV2Notes.md ├── EDAV2Notes.pdf ├── EDAV3.html ├── EDAV3Notes.md ├── EDAV4Notes.md ├── EDAV4Sol.html ├── EDAV5Notes.md ├── EDAV5_1.html ├── EDAV5_2.html ├── EDAV5_3.html ├── EDAV5_4_scaleBand.html ├── EDAV5_5_scaleLinear.html ├── EDAV5_Solutions.md ├── EDAV6Lect-Axes.pdf ├── EDAV6Lect-Scales.pdf ├── EDAV6Notes.md ├── EDAV6_1_margins.html ├── EDAV6_2_yaxis.html ├── EDAV7Notes.md ├── EDAV7_1_axes.html ├── EDAV7_2_transitions.html ├── EDAV7_3_obj_constancy.html ├── EDAV8Notes.md ├── EDAV8_1_linegen.html ├── EDAV8_2_linechart.html ├── EDAV8_3_readfile.html ├── EDAV9Notes.md ├── EventListener.html ├── ExerciseSolutions.md ├── HorizontalBarChart.html ├── Interactivity.pdf ├── Layouts.pdf ├── LineCharts.pdf ├── ObjectConstancy.pdf ├── R ├── EDAV2Notes.Rmd ├── EDAV3Notes.Rmd └── EDAV3Notes.html ├── README.md ├── ReadingFiles.pdf ├── ScaleBand.html ├── SixBlueCircles.html ├── Test2SampleQuestions.md ├── Test2SampleSolutions.md ├── Tips4D3debugging.md ├── Transitions.pdf ├── UpdateEnterExit.pdf ├── cartogramfinal.png ├── docs ├── BestFittingLine.md ├── Boxplot.html ├── Boxplot.md ├── CorrelationCoefficient.md ├── D3template.html ├── DataBindwithKeys.html ├── DataBindwithKeys.md ├── EDAV1.html ├── EDAV2.html ├── EDAV3.html ├── EDAV4Sol.html ├── EDAV5_1.html ├── EDAV5_2.html ├── EDAV5_3.html ├── EDAV5_4_scaleBand.html ├── EDAV5_5_scaleLinear.html ├── EDAV6_1_margins.html ├── EDAV6_2_yaxis.html ├── EDAV7_1_axes.html ├── EDAV7_2_transitions.html ├── EDAV7_3_obj_constancy.html ├── EDAV8_1_linegen.html ├── EDAV8_2_linechart.html ├── EDAV8_3_readfile.html ├── EventListener.html ├── EventListener.md ├── HorizontalBarChart.html ├── HorizontalBarChart.md ├── MultipleTransitions.html ├── PSet2Q4.html ├── ScaleBand.html ├── SixBlueCircles.html ├── SixBlueCircles.md ├── index.md ├── line.html ├── porosity.csv └── read.md ├── line.html ├── porosity.csv └── visna.png /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | .Ruserdata 5 | *copy* 6 | *Lect* 7 | Untitled.* 8 | -------------------------------------------------------------------------------- /D3.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: knitr 13 | LaTeX: XeLaTeX 14 | 15 | AutoAppendNewline: Yes 16 | StripTrailingWhitespace: Yes 17 | -------------------------------------------------------------------------------- /D3template.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 |paragraph
22 | 23 | 30 | 31 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /EDAV1Notes.md: -------------------------------------------------------------------------------- 1 | EDAV1.html: Overview 2 | ================ 3 | 4 | ### Part A: Chrome Developer Tools, `d3.select()` 5 | 6 | 1. Open a *downloaded version* of EDAV1.html. You can download the file: 7 | 8 | 1. from the Courseworks Files folder 9 | 10 | 2. from this repo by clicking [here](https://raw.githubusercontent.com/jtr13/D3/master/EDAV1.html) and then File, Save Page As... 11 | 12 | 3. by downloading a ZIP of the whole repo by clicking [here](https://github.com/jtr13/D3/archive/master.zip) 13 | 14 | 2. Click View, Developer, Developer Tools, then the Elements tab. 15 | 16 | 3. Hover the mouse over various elements in the ` ... ` section. 17 | 18 | 4. Click the Console tab. Type `d3.select("circle").attr("cx", "200");` at the prompt (`>`), press enter and see what happens. 19 | 20 | 5. Now try some of the following and/or experiment on your own with changing attributes of the circle: 21 | 22 | ``` javascript 23 | d3.select("circle").attr("cx", "300"); 24 | 25 | d3.select("circle").attr("cx", "400"); 26 | 27 | d3.select("circle").attr("cx", "500"); 28 | 29 | d3.select("circle").attr("cx", "600"); 30 | 31 | d3.select("circle").attr("cx", "100"); 32 | 33 | d3.select("circle").attr("r", "30"); 34 | 35 | d3.select("circle").attr("r", "130"); 36 | 37 | d3.select("circle").attr("r", "3"); 38 | 39 | d3.select("circle").attr("r", "30"); 40 | 41 | d3.select("circle").attr("fill", "red"); 42 | 43 | d3.select("circle").attr("fill", "aliceblue"); 44 | 45 | d3.select("circle").attr("fill", "lightseagreen"); 46 | ``` 47 | 48 | 6. Refresh the page. What happened? 49 | 50 | 7. Go to Elements. Look at the value of the `y1` attribute of the SVG `paragraph
30 | 31 | 38 | 39 | 42 | 43 | 44 | 45 | 46 | ``` 47 | 48 | Sections 49 | ======== 50 | 51 | HTML 52 |55 | HEAD 56 | 57 | 1. Title 58 | 59 | 2. Link to D3 60 | 61 | 3. CSS (styles) 62 | 63 | | 64 |65 | BODY 66 | 67 | 1. HTML (text) 68 | 69 | 2. SVG (graphics) 70 | 71 | 3. D3 / JavaScript (dynamic content) 72 | 73 | | 74 |
paragraph
84 | ``` 85 | 86 |93 | paragraph 94 |
95 | 96 |This paragraph has a class.
114 | ``` 115 | 116 |117 | This paragraph has a class. 118 |
119 | 120 | CSS rules enable styling *and* selecting. 121 | 122 | *IDVW* pp. 30-35 123 | 124 | ## SVG 125 | 126 | 127 | ``` html 128 | 135 | ``` 136 | 137 | *IDVW* pp. 52-61 138 | 139 | ## JavaScript 140 | 141 | 142 | *IDVW* pp. 36-52 143 | 144 | Be generally familiar with arrays, objects, functions 145 | 146 | Be aware that ES6 does things differently (not covered in *IDVW*) 147 | 148 | Arrow functions `d => d.value` 149 | 150 | Template Literals 151 | 152 | ``` js 153 | let a = 3; 154 | let b = 4; 155 | console.log(`This is an equation: ${a} + ${b} = ${a + b}`); 156 | ``` 157 | 158 | instead of: 159 | 160 | ``` js 161 | console.log("This is an equation: " + a + " + " + b + " = " + (a + b)); 162 | ``` 163 | 164 | This is an equation: 3 + 4 = 7 165 | 166 | ## Breaking it down 167 | 168 | 169 | ``` js 170 | d3.select("circle").transition().duration(2000) 171 | .attr("r", "50"); 172 | ``` 173 | 174 | 1. Chaining (IDVW, Chapter 5, pp. 70-72) 175 | 176 | 2. Selections (IDVW, Chapter 5, pp. 79-80) 177 | 178 | 3. Modifying elements (IDVW, Chapter 6, 90-93 & elsewhere) 179 | 180 | ## Chaining methods 181 | 182 | ``` html 183 |184 | Watch me turn red and shrink.
185 | ``` 186 | 187 |188 | Watch me turn red and shrink. 189 |
190 | D3: 191 | 192 | ``` js 193 | d3.select("#id2").transition().duration(3000) 194 | .style("font-size", "24px").style("color", "red"); 195 | ``` 196 | 197 | ## Chaining methods: two transitions 198 | 199 | 200 | ``` html 201 |Watch me turn red, 202 | then shrink.
203 | ``` 204 | 205 |206 | Watch me turn red, then shrink. 207 |
208 | D3: 209 | 210 | ``` js 211 | d3.select("#id3") 212 | .transition().duration(3000).style("color", "red") 213 | .transition().duration(3000).style("font-size", "24px"); 214 | ``` 215 | 216 | ## Selecting by tag 217 | 218 | 219 | Select the first one: 220 | 221 | ``` js 222 | d3.select("circle"); 223 | ``` 224 | 225 | Select all: 226 | 227 | ``` js 228 | d3.selectAll("circle"); 229 | ``` 230 | 231 | ``` js 232 | d3.selectAll("p"); 233 | ``` 234 | 235 | ## Class and ID attributes 236 | 237 | 238 | ``` html 239 |This paragraph has a class.
240 | 241 |This paragraph has an id.
242 | ``` 243 | 244 |245 | This paragraph has a class. 246 |
247 |248 | This paragraph has an id. 249 |
250 | 251 | ## Selecting by ID 252 | 253 | 254 | ``` html 255 |Watch me grow.
256 | ``` 257 | 258 |259 | Watch me grow. 260 |
261 | ``` js 262 | d3.select("#id1").transition().duration(3000) 263 | .style("font-size", "72px"); 264 | ``` 265 | 266 | ## Selecting by class 267 | 268 | 269 | 272 | D3: 273 | 274 | ``` js 275 | d3.selectAll("rect.trio").transition().duration(3000) 276 | .attr("y", "150").attr("fill", "orange"); 277 | ``` 278 | 279 | # PRACTICE 280 | 281 | 282 | Download and open [SixBlueCircles.html](SixBlueCircles.html) 283 | 284 | 1. Move all the circles to the right. 285 | 286 | 2. Move them back to the left *and* change their color. 287 | 288 | 3. Add an id to one circle, and then move only that circle to the right. 289 | 290 | 4. Move all the circles to the middle of the screen, *then* move them all to the same location. 291 | 292 | ## Modifying elements 293 | 294 | 295 | 1. Attributes 296 | 297 | 2. Styles 298 | 299 | 3. Text 300 | 301 |Paragraph
310 | ``` 311 | 312 | ``` js 313 | d3.select("p").attr("id", "p1"); 314 | ``` 315 | 316 | ``` html 317 |Paragraph
318 | ``` 319 | 320 | ## Attributes 321 | 322 | 323 | ### SVG 324 | 325 | ``` svg 326 |It's not easy being green
344 | ``` 345 | 346 | ``` js 347 | d3.select("#id5").style("color", "red"); 348 | ``` 349 | 350 | ``` html 351 |It's not easy being green
352 | ``` 353 | 354 | ## Styles 355 | 356 | 357 | ### Rough timeline of HTML / CSS history: 358 | 359 | ### Early 90s: 360 | 361 | ``` html 362 |This method of 378 | styling was deprecated in 1998--but it still works :-) .
379 | ``` 380 | 381 |382 | This method of styling was deprecated in 1998--but it still works :-) . 383 |
384 | 385 | HTML tag history 386 | 387 |This is a paragraph.
476 | ``` 477 | 478 | ``` js 479 | d3.select("#id4").style("color", "red"); 480 | ``` 481 | 482 | But since style is an attribute, this would also work: 483 | 484 | ``` js 485 | d3.select("#id4").attr("style", "color: red;"); 486 | ``` 487 | 488 | The change to the DOM is the same in either case: 489 | 490 | ``` html 491 |This is a paragraph.
492 | ``` 493 | 494 | Modifying HTML text 495 | =================== 496 | 497 | ``` html 498 |Manhatten
499 | ``` 500 | 501 |502 | Manhatten 503 |
504 | 505 | Hover to execute this code (and fix the typo): 506 | 507 | ``` js 508 | d3.select("#typo").text("Manhattan"); 509 | ``` 510 | 511 | Modifying SVG text 512 | ================== 513 | 514 | ``` svg 515 | 521 | ``` 522 | 523 |524 | svg 525 |
526 | 530 | Hover to execute this code (and fix the typo): 531 | 532 | ``` js 533 | d3.select("#svgtypo").text("Web scraping is fun."); 534 | ``` 535 | 536 | Moving (and modifying) SVG text 537 | =============================== 538 | 539 | ``` svg 540 | 546 | ``` 547 | 548 |549 | svg 550 |
551 | 555 | ### Hover to execute this code: 556 | 557 | ``` js 558 | d3.select("#moveleft").attr("x", "20").text("Thanks, now I'm happy!"); 559 | ``` 560 | 561 | Modifying elements 562 | ================== 563 | 564 | Summary: 565 | 566 | ``` js 567 | d3.select("p").attr("id", "myid"); 568 | 569 | d3.select("h1").style("color", "red"); 570 | 571 | d3.select("text").text("Changing some svg text."); 572 | ``` 573 | 574 | Modifying elements heads-up 575 | =========================== 576 | 577 | ### Text color 578 | 579 | ### HTML 580 | 581 | ``` js 582 | d3.select("p").style("color", "red"); 583 | ``` 584 | 585 | ### SVG 586 | 587 | ``` js 588 | d3.select("text").style("fill", "red"); 589 | ``` 590 | 591 | Modifying elements heads-up 592 | =========================== 593 | 594 | ### SVG styles vs. attributes 595 | 596 | ``` js 597 | d3.select("circle").style("fill", "red"); 598 | ``` 599 | 600 | ``` html 601 |