资源说明:d3的快速入门资料。纯英文版
Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix
1. Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Why Data Visualization? 1
Why Write Code? 2
Why Interactive? 2
Why on the Web? 3
What This Book Is 3
Who You Are 4
What This Book Is Not 5
Using Sample Code 5
Thank You 6
2. Introducing D3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
What It Does 7
What It Doesn’t Do 8
Origins and Context 9
Alternatives 10
Easy Charts 10
Graph Visualizations 12
Geomapping 12
Almost from Scratch 13
Three-Dimensional 13
Tools Built with D3 14
3. Technology Fundamentals. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
The Web 15
HTML 17
Content Plus Structure 18
iii
Adding Structure with Elements 19
Common Elements 20
Attributes 22
Classes and IDs 22
Comments 23
DOM 24
Developer Tools 24
Rendering and the Box Model 27
CSS 29
Selectors 29
Properties and Values 31
Comments 31
Referencing Styles 31
Inheritance, Cascading, and Specificity 33
JavaScript 35
Hello, Console 35
Variables 35
Other Variable Types 36
Arrays 36
Objects 37
Objects and Arrays 38
Mathematical Operators 40
Comparison Operators 41
Control Structures 41
Functions 43
Comments 44
Referencing Scripts 44
JavaScript Gotchas 45
SVG 49
The SVG Element 50
Simple Shapes 50
Styling SVG Elements 53
Layering and Drawing Order 54
Transparency 55
A Note on Compatibility 57
4. Setup. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
Downloading D3 59
Referencing D3 60
Setting Up a Web Server 61
Terminal with Python 61
MAMP, WAMP, and LAMP 62
iv | Table of Contents
Diving In 62
5. Data. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
Generating Page Elements 63
Chaining Methods 65
One Link at a Time 66
The Hand-off 67
Going Chainless 67
Binding Data 67
In a Bind 67
Data 68
Please Make Your Selection 72
Bound and Determined 73
Using Your Data 76
High-Functioning 77
Data Wants to Be Held 78
Beyond Text 79
6. Drawing with Data. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Drawing divs 81
Setting Attributes 82
A Note on Classes 83
Back to the Bars 83
Setting Styles 84
The Power of data() 85
Random Data 87
Drawing SVGs 89
Create the SVG 89
Data-Driven Shapes 90
Pretty Colors, Oooh! 92
Making a Bar Chart 92
The Old Chart 93
The New Chart 93
Color 98
Labels 101
Making a Scatterplot 103
The Data 103
The Scatterplot 104
Size 105
Labels 106
Table of Contents | v
Next Steps 107
7. Scales. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
Apples and Pixels 109
Domains and Ranges 110
Normalization 111
Creating a Scale 111
Scaling the Scatterplot 112
d3.min() and d3.max() 112
Setting Up Dynamic Scales 114
Incorporating Scaled Values 114
Refining the Plot 115
Other Methods 119
Other Scales 119
8. Axes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
Introducing Axes 121
Setting Up an Axis 122
Cleaning It Up 123
Check for Ticks 126
Y Not? 127
Final Touches 128
Formatting Tick Labels 130
9. Updates, Transitions, and Motion. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
Modernizing the Bar Chart 133
Ordinal Scales, Explained 134
Round Bands Are All the Range These Days 136
Referencing the Ordinal Scale 136
Other Updates 137
Updating Data 137
Interaction via Event Listeners 138
Changing the Data 139
Updating the Visuals 139
Transitions 142
duration(), or How Long Is This Going to Take? 143
ease()-y Does It 144
Please Do Not delay() 145
Randomizing the Data 147
Updating Scales 150
Updating Axes 152
each() Transition Starts and Ends 153
vi | Table of Contents
Other Kinds of Data Updates 161
Adding Values (and Elements) 161
Removing Values (and Elements) 166
Data Joins with Keys 169
Add and Remove: Combo Platter 174
Recap 176
10. Interactivity. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
Binding Event Listeners 177
Introducing Behaviors 178
Hover to Highlight 179
Grouping SVG Elements 184
Click to Sort 185
Tooltips 188
Default Browser Tooltips 189
SVG Element Tooltips 190
HTML div Tooltips 192
Consideration for Touch Devices 195
Moving Forward 195
11. Layouts. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
Pie Layout 198
Stack Layout 202
Force Layout 206
12. Geomapping. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
JSON, Meet GeoJSON 213
Paths 215
Projections 216
Choropleth 219
Adding Points 222
Acquiring and Parsing Geodata 226
Find Shapefiles 226
Choose a Resolution 226
Simplify the Shapes 228
Convert to GeoJSON 228
13. Exporting. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
Bitmaps 233
PDF 234
Table of Contents | vii
SVG 235
A. Appendix: Further Study. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241
Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245
本源码包内暂不包含可直接显示的源代码文件,请下载源码包。