0% found this document useful (0 votes)
15 views

Interactive Data Visualization for the Web 1st Edition Scott Murray - Read the ebook online or download it to own the full content

The document promotes instant ebook access through ebookgate.com, featuring various titles on data visualization and interactive computing. It includes links to multiple ebooks, such as 'Interactive Data Visualization for the Web' by Scott Murray and 'Learning IPython for Interactive Computing and Data Visualization' by Cyrille Rossant. The content emphasizes the availability of digital formats like PDF, ePub, and MOBI for immediate download.

Uploaded by

pendovagheli91
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Interactive Data Visualization for the Web 1st Edition Scott Murray - Read the ebook online or download it to own the full content

The document promotes instant ebook access through ebookgate.com, featuring various titles on data visualization and interactive computing. It includes links to multiple ebooks, such as 'Interactive Data Visualization for the Web' by Scott Murray and 'Learning IPython for Interactive Computing and Data Visualization' by Cyrille Rossant. The content emphasizes the availability of digital formats like PDF, ePub, and MOBI for immediate download.

Uploaded by

pendovagheli91
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 81

Instant Ebook Access, One Click Away – Begin at ebookgate.

com

Interactive Data Visualization for the Web 1st


Edition Scott Murray

https://ebookgate.com/product/interactive-data-
visualization-for-the-web-1st-edition-scott-murray/

OR CLICK BUTTON

DOWLOAD EBOOK

Get Instant Ebook Downloads – Browse at https://ebookgate.com


Click here to visit ebookgate.com and download ebook now
Instant digital products (PDF, ePub, MOBI) available
Download now and explore formats that suit you...

Learning IPython for Interactive Computing and Data


Visualization 2nd Edition Cyrille Rossant

https://ebookgate.com/product/learning-ipython-for-interactive-
computing-and-data-visualization-2nd-edition-cyrille-rossant/

ebookgate.com

Data Visualization with Flash Builder Designing RIA and


AIR Applications with Remote Data Sources Visualizing the
Web Cesare Rocchi
https://ebookgate.com/product/data-visualization-with-flash-builder-
designing-ria-and-air-applications-with-remote-data-sources-
visualizing-the-web-cesare-rocchi/
ebookgate.com

Everyday Data Visualization Desiree Abbott

https://ebookgate.com/product/everyday-data-visualization-desiree-
abbott/

ebookgate.com

Learning Qlikview Data Visualization 1st Edition Karl


Pover

https://ebookgate.com/product/learning-qlikview-data-
visualization-1st-edition-karl-pover/

ebookgate.com
Web Cartography Map Design for Interactive and Mobile
Devices 1st Edition Ian Muehlenhaus (Author)

https://ebookgate.com/product/web-cartography-map-design-for-
interactive-and-mobile-devices-1st-edition-ian-muehlenhaus-author/

ebookgate.com

Handbook of Statistics 24 Data Mining and Data


Visualization C.R. Rao

https://ebookgate.com/product/handbook-of-statistics-24-data-mining-
and-data-visualization-c-r-rao/

ebookgate.com

Social Data Visualization with HTML5 and JavaScript Timms

https://ebookgate.com/product/social-data-visualization-with-
html5-and-javascript-timms/

ebookgate.com

HTML5 Graphing and Data Visualization Cookbook 1st Edition


Ben Fhala

https://ebookgate.com/product/html5-graphing-and-data-visualization-
cookbook-1st-edition-ben-fhala/

ebookgate.com

HTML5 graphing and data visualization cookbook learn how


to create interactive HTML5 charts and graphs with canvas
JavaScript and open source tools Ben Fhala
https://ebookgate.com/product/html5-graphing-and-data-visualization-
cookbook-learn-how-to-create-interactive-html5-charts-and-graphs-with-
canvas-javascript-and-open-source-tools-ben-fhala/
ebookgate.com
Interactive Data Visualization
for the Web
Download from Wow! eBook <www.wowebook.com>

Scott Murray
Interactive Data Visualization for the Web
by Scott Murray
Copyright © 2013 Scott Murray. All rights reserved.
Printed in the United States of America.
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are
also available for most titles (http://my.safaribooksonline.com). For more information, contact our corporate/
institutional sales department: 800-998-9938 or corporate@oreilly.com.
Editor: Meghan Blanchette Indexer: Judith McConville
Production Editor: Melanie Yarbrough Cover Designer: Karen Montgomery
Copyeditor: Teresa Horton Interior Designer: David Futato
Proofreader: Linley Dolby Illustrator: Rebecca Demarest

March 2013: First Edition

Revision History for the First Edition:


2013-03-04: First release

2013-04-12: Second release

See http://oreilly.com/catalog/errata.csp?isbn=9781449339739 for release details.

Nutshell Handbook, the Nutshell Handbook logo, the cover image, and the O’Reilly logo are registered
trademarks of O’Reilly Media, Inc. Interactive Data Visualization for the Web, the cover image of a long-tail
bushtit, and related trade dress are trademarks of O’Reilly Media, Inc.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as
trademarks. Where those designations appear in this book, and O’Reilly Media, Inc., was aware of a trade‐
mark claim, the designations have been printed in caps or initial caps.
While every precaution has been taken in the preparation of this book, the publisher and author assume no
responsibility for errors or omissions, or for damages resulting from the use of the information contained
herein.

ISBN: 978-1-449-33973-9
[LSI]
Table of Contents

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
Download from Wow! eBook <www.wowebook.com>

viii | Table of Contents


Preface

This is a book about programming data visualizations for nonprogrammers. If you’re


an artist or graphic designer with visual skills but no prior experience working with data
or code, this book is for you. If you’re a journalist or researcher with lots of data but no
prior experience working with visuals or code, this book is for you, too.
This book will introduce you to D3, a JavaScript-based tool for loading data into a web
page and generating visuals from that data. I assume that you have little or no pro‐
gramming experience. Or, perhaps you have programmed before, but D3 and data vis‐
ualization are bringing you to JavaScript for the first time, and you’ve heard bad things
about it. Well, JavaScript is a little weird, but it’s not as bad as you’ve heard, and every‐
thing is going to be all right. Please sit down and make yourself comfortable.
This book began as a series of tutorials posted on my website. At the time (January 2012),
there wasn’t much information on D3 available that was accessible to beginners. Very
quickly, I was getting hundreds, then thousands of page views a day—evidence that
interest in the field generally (and D3 specifically) was growing like gangbusters. If
you’ve read the tutorials, portions of the book will feel familiar, but there is a lot of new
material here, including many more examples, sneaky tips, and warnings of things to
avoid. Also, the book contains 78 percent more bad jokes.
Data visualization is an interdisciplinary field, which is just one reason it’s impossible
to document the breadth of skills needed in a single book. Fortunately, because the field
is exploding in popularity, there are many new titles to choose from, each of which
complements this one.
On design process:

• Designing Data Visualizations: Intentional Communication from Data to Display


by Noah Iliinsky and Julie Steele. O’Reilly Media, 2011.
• Data Visualization: A Successful Design Process by Andy Kirk. Packt Publishing,
2012.

ix
On visual design principles and techniques:

• The Functional Art: An Introduction to Information Graphics and Visualization by


Alberto Cairo. New Riders, 2012.
• Information Dashboard Design: The Effective Visual Communication of Data by
Stephen Few. O’Reilly Media, 2006.

On the practicalities of working with data:

• Bad Data Handbook: Mapping the World of Data Problems by Q. Ethan McCallum.
O’Reilly Media, 2012.
• Data Analysis with Open Source Tools: A Hands-On Guide for Programmers and
Data Scientists by Philipp K. Janert. O’Reilly Media, 2010.
• Python for Data Analysis: Agile Tools for Real World Data by Wes McKinney.
O’Reilly Media, 2012.

Conventions Used in This Book


The following typographical conventions are used in this book:
Italic
Indicates new terms, URLs, email addresses, filenames, and file extensions.
Constant width
Used for program listings, as well as within paragraphs to refer to program elements
such as variable or function names, databases, data types, environment variables,
statements, and keywords.
Constant width bold
Shows commands or other text that should be typed literally by the user.
Constant width italic
Shows text that should be replaced with user-supplied values or by values deter‐
mined by context.

This icon signifies a tip, suggestion, or general note.

This icon indicates a warning or caution.

x | Preface
Using Code Examples
This book is here to help you get your job done. In general, if this book includes code
examples, you may use the code in this book in your programs and documentation. You
do not need to contact us for permission unless you’re reproducing a significant portion
of the code. For example, writing a program that uses several chunks of code from this
book does not require permission. Selling or distributing a CD-ROM of examples from
O’Reilly books does require permission. Answering a question by citing this book and
quoting example code does not require permission. Incorporating a significant amount
of example code from this book into your product’s documentation does require per‐
mission.
We appreciate, but do not require, attribution. An attribution usually includes the title,
author, publisher, and ISBN. For example: “Interactive Data Visualization for the Web
by Scott Murray (O’Reilly). Copyright 2013 Scott Murray, 978-1-449-33973-9.”
If you feel your use of code examples falls outside fair use or the permission given above,
feel free to contact us at permissions@oreilly.com.

Safari® Books Online


Safari Books Online is an on-demand digital library that delivers ex‐
pert content in both book and video form from the world’s leading
authors in technology and business.
Technology professionals, software developers, web designers, and business and crea‐
tive professionals use Safari Books Online as their primary resource for research, prob‐
lem solving, learning, and certification training.
Safari Books Online offers a range of product mixes and pricing programs for organi‐
zations, government agencies, and individuals. Subscribers have access to thousands of
books, training videos, and prepublication manuscripts in one fully searchable database
from publishers like O’Reilly Media, Prentice Hall Professional, Addison-Wesley Pro‐
fessional, Microsoft Press, Sams, Que, Peachpit Press, Focal Press, Cisco Press, John
Wiley & Sons, Syngress, Morgan Kaufmann, IBM Redbooks, Packt, Adobe Press, FT
Press, Apress, Manning, New Riders, McGraw-Hill, Jones & Bartlett, Course Technol‐
ogy, and dozens more. For more information about Safari Books Online, please visit us
online.

Preface | xi
How to Contact Us
Please address comments and questions concerning this book to the publisher:

O’Reilly Media, Inc.


1005 Gravenstein Highway North
Sebastopol, CA 95472
800-998-9938 (in the United States or Canada)
707-829-0515 (international or local)
707-829-0104 (fax)

We have a web page for this book, where we list errata, examples, and any additional
information. You can access this page at http://oreil.ly/interactive_data_visualiza
tion_web.
To comment or ask technical questions about this book, send email to bookques
tions@oreilly.com.
For more information about our books, courses, conferences, and news, see our website
at http://www.oreilly.com.
Find us on Facebook: http://facebook.com/oreilly
Follow us on Twitter: http://twitter.com/oreillymedia
Watch us on YouTube: http://www.youtube.com/oreillymedia

Acknowledgments
My name may be on the cover, but as an author, I feel as though I am merely funneling
the wisdom of hundreds of other brilliant minds onto the page.
First and foremost, I must thank my wife Nora, not least for being the first to say “Hey,
you should turn those tutorials into a book.” Without her support and encouragement,
this project never would have happened.
Thanks also to Rosten Woo, with whom I collaborated on my first D3 project, for
reaching out and giving me a reason to finally dig into this new tool. Thanks to Joe
Golike for several early D3 debugging sessions around that time, and to Jen Lowe and
Sha Hwang for their reviews and feedback on the initial tutorials.
I am extremely grateful to Casey Reas, Dan Shiffman, Joshua Noble, and Noah Iliinsky
—not just for offering advice on the book-creation process, but also for their ground‐
breaking work in the spheres of art, design, code, and data. Their careers have greatly
influenced my own.

xii | Preface
In that vein, I should also thank Jan Kubasiewicz at MassArt’s Dynamic Media Insti‐
tute. Back in 2007, Jan encouraged me to check out something called Processing, which
eventually led me to a whole new career in code-driven arts, data visualization, and now
this book.
It has been a pleasure working with my editor, Meghan Blanchette, and everyone else
on the team at O’Reilly. Thanks to Meghan and her crew for shepherding this project
all the way through, from concept to an actual, physical, chunk of paper with words and
strange diagrams printed on it.
Special thanks to Mike Bostock, Jen Lowe, Anna Powell-Smith, and Daisy Vincent for
agreeing to tech review the book and sending incredibly valuable feedback. The final
product is vastly improved, thanks to their input. That said, if you find an error or
confusing code example, it is because they begged me to rewrite it, and I steadfastly
refused.
Mike gets an extra-special thanks for developing D3 in the first place. Without this
elegant piece of software, the community of data visualization practitioners wouldn’t be
quite as vibrant, enthusiastic, and standards-compliant as it is today.
Speaking of community, many other people—including Jérôme Cukier, Lynn Cherny,
Jason Davies, Jeff Heer, Santiago Ortiz, Kim Rees, Moritz Stefaner, Jan Willem Tulp,
and others who I have forgotten to mention—on the D3 list and in nearby orbits have
also directly contributed to my thinking and process. Thank you for your support. I am
lucky to get to collaborate with so many talented people.

Preface | xiii
CHAPTER 1
Introduction

Why Data Visualization?


Our information age more often feels like an era of information overload. Excess
amounts of information are overwhelming; raw data becomes useful only when we apply
methods of deriving insight from it.
Fortunately, we humans are intensely visual creatures. Few of us can detect patterns
among rows of numbers, but even young children can interpret bar charts, extracting
meaning from those numbers’ visual representations. For that reason, data visualization
is a powerful exercise. Visualizing data is the fastest way to communicate it to others.
Of course, visualizations, like words, can be used to lie, mislead, or distort the truth. But
when practiced honestly and with care, the process of visualization can help us see the
world in a new way, revealing unexpected patterns and trends in the otherwise hidden
information around us. At its best, data visualization is expert storytelling.
More literally, visualization is a process of mapping information to visuals. We craft
rules that interpret data and express its values as visual properties. For example, the
humble bar chart in Figure 1-1 is generated from a very simple rule: larger values are
mapped as taller bars.

Figure 1-1. Data values mapped to visuals

1
More complex visualizations are generated from datasets more complex than the se‐
quence of numbers shown in Figure 1-1 and more complex sets of mapping rules.

Why Write Code?


Mapping data by hand can be satisfying, yet is slow and tedious. So we usually employ
the power of computation to speed things up. The increased speed enables us to work
with much larger datasets of thousands or millions of values; what would have taken
years of effort by hand can be mapped in a moment. Just as important, we can rapidly
experiment with alternate mappings, tweaking our rules and seeing their output re-
rendered immediately. This loop of write/render/evaluate is critical to the iterative pro‐
cess of refining a design.
Sets of mapping rules function as design systems. The human hand no longer executes
the visual output; the computer does. Our human role is to conceptualize, craft, and
write out the rules of the system, which is then finally executed by software.
Unfortunately, software (and computation generally) is extremely bad at understanding
what, exactly, people want. (To be fair, many humans are also not good at this challenging
task.) Because computers are binary systems, everything is either on or off, yes or no,
this or that, there or not there. Humans are mushier, softer creatures, and the computers
are not willing to meet us halfway—we must go to them. Hence the inevitable struggle
of learning to write software, in which we train ourselves to communicate in the very
limited and precise syntax that the computer can understand.
Yet we continue to write code because seeing our visual creations come to life is so
rewarding. We practice data visualization because it is exciting to see what has never
before been seen. It is like summoning a magical, visual genie out of an inscrutable data
bottle.

Why Interactive?
Static visualizations can offer only precomposed “views” of data, so multiple static views
are often needed to present a variety of perspectives on the same information. The
number of dimensions of data are limited, too, when all visual elements must be present
on the same surface at the same time. Representing multidimensional datasets fairly in
static images is notoriously difficult. A fixed image is ideal when alternate views are
neither needed nor desired, and required when publishing to a static medium, such as
print.
Dynamic, interactive visualizations can empower people to explore the data for them‐
selves. The basic functions of most interactive visualization tools have changed little
since 1996, when Ben Shneiderman of the University of Maryland first proposed a

2 | Chapter 1: Introduction
“Visual Information-Seeking Mantra”: overview first, zoom and filter, then details-on-
demand.
This design pattern is found in most interactive visualizations today. The combination
of functions is successful, because it makes the data accessible to different audiences,
from those who are merely browsing or exploring the dataset to those who approach
the visualization with a specific question in search of an answer. An interactive visual‐
ization that offers an overview of the data alongside tools for “drilling down” into the
details may successfully fulfill many roles at once, addressing the different concerns of
different audiences, from those new to the subject matter to those already deeply familiar
with the data.
Of course, interactivity can also encourage engagement with the data in ways that static
images cannot. With animated transitions and well-crafted interfaces, some visualiza‐
tions can make exploring data feel more like playing a game. Interactive visualization
can be a great medium for engaging an audience who might not otherwise care about
the topic or data at hand.

Why on the Web?


Visualizations aren’t truly visual unless they are seen. Getting your work out there for
others to see is critical, and publishing on the Web is the quickest way to reach a global
audience. Working with web-standard technologies means that your work can be seen
and experienced by anyone using a recent web browser, regardless of the operating
system (Windows, Mac, Linux) and device type (laptop, desktop, smartphone, tablet).
Best of all, everything covered in this book can be done with freely accessible tools, so
the only investment required is your time. And everything we’ll talk about uses open
source, web-standard technologies.
By avoiding proprietary software and plug-ins, you can ensure that your projects are
accessible on the widest possible range of devices, from typical desktop computers to
tablets and even phones. The more accessible your visualization, the greater your au‐
dience and your impact.

What This Book Is


This book is a practical introduction to merging three practices—data visualization,
interactive design, and web development—using D3, a powerful tool for custom, web-
based visualization.
These chapters grew out of my own process of learning how to use D3. Many people,
including myself, come to D3 with backgrounds in design, mapping, and data visuali‐
zation, but not programming and computer science.

Why on the Web? | 3


D3 has a bit of an unfair reputation for being hard to learn. D3 itself is not so complicated,
but it operates in the domain of the Web, and the Web is complicated. Using D3 com‐
fortably requires some prior knowledge of the web technologies with which it interacts,
such as HTML, CSS, JavaScript, and SVG. Many people (myself included) are self-taught
when it comes to web skills. This is great, because the barrier to entry is so low, but
problematic because it means we probably didn’t learn each of these technologies from
the ground up—more often, we just hack something together until it seems to work,
and call it a day. Yet successful use of D3 requires understanding some of these tech‐
nologies in a fundamental way.
Because D3 is written in JavaScript, learning to use D3 often means learning a lot about
JavaScript. For many datavis folks, D3 is their introduction to JavaScript (or even web
development generally). It’s hard enough to learn a new programming language, let
alone a new tool built on that language. D3 will enable you to do great things with
JavaScript that you never would have even attempted. The time you spend learning both
the language and the tool will provide an incredible payoff.
My goal is to reduce that learning time, so you can start creating awesome stuff sooner.
We’ll take a ground-up approach, starting with the fundamental concepts and gradually
adding complexity. I don’t intend to show you how to make specific kinds of visualiza‐
tions so much as to help you understand the workings of D3 well enough to take those
building blocks and generate designs of your own creation.

Who You Are


You may be an absolute beginner, someone new to datavis, web development, or both.
(Welcome!) Perhaps you are a journalist interested in new ways to communicate the
data you collect during reporting. Or maybe you’re a designer, comfortable drawing
static infographics but ready to make the leap to interactive projects on the Web. You
could be an artist, interested in generative, data-based art. Or a programmer, already
familiar with JavaScript and the Web, but excited to learn a new tool and pick up some
visual design experience along the way.
Whoever you are, I hope that you:

• Have heard of this new thing called the “World Wide Web”
• Are a bit familiar with HTML, the DOM, and CSS
• Might even have a little programming experience already
• Have heard of jQuery or written some JavaScript before
• Aren’t scared by unknown initialisms like CSV, SVG, or JSON
• Want to make useful, interactive visualizations

4 | Chapter 1: Introduction
If any of those things are unknown or unclear, don’t fear. You might just want to spend
more time with Chapter 3, which covers what you really need to know before diving
into D3.

What This Book Is Not


That said, this is definitely not a computer science textbook, and it is not intended to
teach the intricacies of any one web technology (HTML, CSS, JavaScript, SVG) in depth.
In that spirit, I might gloss over some technical points, grossly oversimplifying impor‐
tant concepts fundamental to computer science in ways that will make true software
engineers recoil. That’s fine, because I’m writing for artists and designers here, not en‐
gineers. We’ll cover the basics, and then you can dive into the more complex pieces once
you’re comfortable.
Download from Wow! eBook <www.wowebook.com>

I will deliberately not address every possible approach to a given problem, but will
typically present what I feel is the simplest solution, or, if not the simplest, then the most
understandable.
My goal is to teach you the fundamental concepts and methods of D3. As such, this
book is decidedly not organized around specific example projects. Everyone’s data and
design needs will be different. It’s up to you to integrate these concepts in the way best
suited to your particular project.

Using Sample Code


If you are a mad genius, then you can probably learn to use D3 without ever looking at
any sample code files, in which case you can skip the rest of this section.
If you’re still with me, you are probably still very bright but not mad, in which case you
should undertake this book with the full set of accompanying code samples in hand.
Before you go any further, please download the sample files from GitHub.
Normal people will want to click the ZIP link to download a compressed ZIP archive
with all the files. Hardcore geeksters will want to clone the repository using Git. If that
last sentence sounds like total gibberish, please use the first option.
Within the download, you’ll notice there is a folder for each chapter that has code to go
with it:
chapter_04
chapter_05
chapter_06
chapter_07
chapter_08

What This Book Is Not | 5


Files are organized by chapter, so in Chapter 9 when I reference 01_bar_chart.html,
know that you can find that file in the corresponding location: d3-book/chap‐
ter_9/01_bar_chart.html.
You are welcome to copy, adapt, modify, and reuse the example code in these tutorials
for any noncommercial purpose.

Thank You
Finally, this book has been handcrafted, carefully written, and pedagogically fine-tuned
for maximum effect. Thank you for reading it. I hope you learn a great deal, and even
have some fun along the way.

6 | Chapter 1: Introduction
CHAPTER 2
Introducing D3

D3—also referred to as D3 or d3.js—is a JavaScript library for creating data visualiza‐


tions. But that kind of undersells it.
The abbreviation D3 references the tool’s full name, Data-Driven Documents. The da‐
ta is provided by you, and the documents are web-based documents, meaning anything
that can be rendered by a web browser, such as HTML and SVG. D3 does the driving,
in the sense that it connects the data to the documents.
Of course, the name also functions as a clever allusion to the network of technologies
underlying the tool itself: the W3, or World Wide Web, or, today, simply “the Web.”
D3’s primary author is the brilliant Mike Bostock, although there are a few other dedi‐
cated contributors. The project is entirely open source and freely available on GitHub.
D3 is released under a BSD license, so you may use, modify, and adapt the code for
noncommercial or commercial use at no cost.
D3’s official home on the Web is d3js.org.

What It Does
Fundamentally, D3 is an elegant piece of software that facilitates generation and ma‐
nipulation of web documents with data. It does this by:

• Loading data into the browser’s memory


• Binding data to elements within the document, creating new elements as needed

7
• Transforming those elements by interpreting each element’s bound datum and set‐
ting its visual properties accordingly
• Transitioning elements between states in response to user input

Learning to use D3 is simply a process of learning the syntax used to tell it how you
want it to load and bind data, and transform and transition elements.
The transformation step is most important, as this is where the mapping happens. D3
provides a structure for applying these transformations, but, as we’ll see, you define the
mapping rules. Should larger values make taller bars or brighter circles? Will clusters
be sorted on the x-axis by age or category? What color palette is used to fill in countries
on your world map? All of the visual design decisions are up to you. You provide the
concept, you craft the rules, and D3 executes it—without telling you what to do. (Yes,
it’s like the opposite of Excel’s pushy “Chart Wizard.”)

What It Doesn’t Do
Here is a list of things D3 does not do:

• D3 doesn’t generate predefined or “canned” visualizations for you. This is on pur‐


pose. D3 is intended primarily for explanatory visualization work, as opposed to
exploratory visualizations. Exploratory tools help you discover significant, mean‐
ingful patterns in data. These are tools like Tableau and ggplot2, which help you
quickly generate multiple views on the same data set. That’s an essential step, but
different from generating an explanatory presentation of the data, a view of the data
that highlights what you’ve already discovered. Explanatory views are more con‐
strained and limited, but also focused, and designed to communicate only the im‐
portant points. D3 excels at this latter step, but is not ideal for the former. (For ideas
on other tools, see the section “Alternatives” on page 10 later in this chapter.)
• D3 doesn’t even try to support older browsers. This helps keep the D3 codebase
clean and free of hacks to support old versions of Internet Explorer, for example.
The philosophy is that by creating more compelling tools and refusing to support
older browsers, we encourage more people to upgrade (rather than forestall the
process, thereby requiring us to continue to support those browsers, and so on—a
vicious cycle). D3 wants us to move forward.
• D3’s core functionality doesn’t handle bitmap map tiles, such as those provided by
Google Maps or Cloudmade. D3 is great with anything vector—SVG images or
GeoJSON data—but wasn’t originally intended to work with traditional map tiles.
(Bitmap images are made up of pixels, so resizing them larger or smaller is difficult
without a loss in quality. Vector images are defined by points, lines, and curves—
mathematical equations, really—and can be scaled up or down without a loss in
quality.) This is starting to change, with the introduction of the d3.geo.tile plug-

8 | Chapter 2: Introducing D3
in. Prior to this plug-in, geomapping with D3 meant either going all-SVG and
avoiding tiles or using D3 to create SVG visuals on top of a base layer of map tiles
(which would be managed by another library, like Leaflet or Polymaps—see the
section “Alternatives” on page 10 later in this chapter). This question of how to in‐
tegrate bitmap tiles and vector graphics comes up a lot in the D3 community. As of
today, there is no super-simple and perfect answer, but I think you can expect to
see lots of work done in this area, and possibly the new tile-handling methods
integrated into the D3 core at some point in the future.
• D3 doesn’t hide your original data. Because D3 code is executed on the client side
(meaning, in the user’s web browser, as opposed to on the web server), the data you
want visualized must be sent to the client. If your data can’t be shared, then don’t
use D3. Alternatives include using proprietary tools (like Flash) or prerendering
visualizations as static images and sending those to the browser. (If you’re not in‐
terested in sharing your data, though, why would you bother visualizing it? The
purpose of visualization is to communicate the data, so you might sleep better at
night by choosing openness and transparency, rather than having nightmares about
data thieves.)

Origins and Context


The first web browsers rendered static pages; interactivity was limited to clicking links.
In 1996, Netscape introduced the first browser with JavaScript, a new scripting language
that could be interpreted by the browser while the page was being viewed.
This doesn’t sound as groundbreaking as it turned out to be, but this enabled web
browsers to evolve from merely passive browsers to dynamic frames for interactive,
networked experiences. This shift ultimately enabled every intrapage interaction we
have on the Web today. Without JavaScript, D3 would never exist, and web-based data
visualizations would be limited to prerendered, noninteractive GIFs. (Yuck. Thank you,
Netscape!)
Jump ahead to 2005, when Jeffrey Heer, Stuart Card, and James Landay introduced
prefuse, a toolkit for bringing data visualization to the Web. prefuse (spelled with all
lowercase letters) was written in Java, a compiled language, with programs that could
run in web browsers via a Java plug-in. (Note that Java is a completely different pro‐
gramming language than JavaScript, despite their similar names.)
prefuse was a breakthrough application—the first to make web-based visualization ac‐
cessible to less-than-expert programmers. Until prefuse came along, any datavis on the
Web was very much a custom affair.
Two years later, Jeff Heer introduced Flare, a similar toolkit, but written in ActionScript,
so its visualizations could be viewed on the Web through Adobe’s Flash Player. Flare,

Origins and Context | 9


like prefuse, relied on a browser plug-in. Flare was a huge improvement, but as web
browsers continued to evolve, it was clear that visualizations could be created with native
browser technology, no plug-ins required.
By 2009, Jeff Heer had moved to Stanford, where he was advising a graduate student
named Michael Bostock. Together, in Stanford’s Vis Group, they created Protovis, a
JavaScript-based visualization toolkit that relied exclusively on native browser technol‐
ogies. (If you have used Protovis, be sure to reference Mike’s introduction to D3 for
Protovis users.)
Protovis made generating visualizations simple, even for users without prior program‐
ming experience. Yet to achieve this, it created an abstract representation layer. The
designer could address this layer using Protovis syntax, but it wasn’t accessible through
standard methods, so debugging was difficult.
In 2011, Mike Bostock, Vadim Ogievetsky, and Jeff Heer officially announced D3, the
next evolution in web visualization tools. Unlike Protovis, D3 operates directly on the
web document itself. This means easier debugging, easier experimentation, and more
visual possibilities. The only downside to this approach is a potentially steeper learning
curve, but this book will make that as painless as possible. Plus, all the skills you gain
while learning about D3 will prove useful even beyond the realm of datavis.
If you’re familiar with any of these groundbreaking tools, you’ll appreciate that D3 de‐
scends from a prestigious lineage. And if you have any interest in the philosophy un‐
derlying D3’s elegant technical design, I highly recommend Mike, Vadim, and Jeff ’s
InfoVis paper, which clearly articulates the need for this kind of tool. The paper encap‐
sulates years’ worth of learning and insights made while developing visualization tools.

Alternatives
D3 might not be perfect for every project. Sometimes you just need a quick chart and
you don’t have time to code it from scratch. Or you might need to support older browsers
and can’t rely on recent technologies like SVG.
For those situations, it’s good to know what other tools are out there. Here is a brief,
noncomprehensive list of D3 alternatives, all of which use web-standard technologies
(mostly JavaScript) and are free to download and use.

Easy Charts
DataWrapper
A beautiful web service that lets you upload your data and quickly generate a chart
that you can republish elsewhere or embed on your site. This service was originally
intended for journalists, but it is helpful for everyone. DataWrapper displays in‐

10 | Chapter 2: Introducing D3
teractive charts in current browsers and static images for old ones. (Brilliant!) You
can also download all the code and run it on your own server instead of using theirs.
Flot
A plotting library for jQuery that uses the HTML canvas element and supports
older browsers, even all the way back to Internet Explorer 6. It supports limited
visual forms (lines, points, bars, areas), but it is easy to use.
Google Chart Tools
Having evolved from their earlier Image Charts API, Google’s Chart Tools can be
used to generate several standard chart types, with support for old versions of IE.
gRaphaël
A charting library based on Raphaël (see later in this chapter) that supports older
browsers, including IE6. It has more visual flexibility than Flot, and—some might
say—it is prettier.
Highcharts JS
A JavaScript-based charting library with several predesigned themes and chart
types. It uses SVG for modern browsers and falls back on VML for old versions of
IE, including IE6 and later. The tool is free only for noncommercial use.
JavaScript InfoVis Toolkit
The JIT provides several preset visualization styles for your data. It includes lots of
examples, but the documentation is pretty technical. The toolkit is great if you like
one of the preset styles, but browser support is unclear.
jqPlot
A plug-in for charting with jQuery. This supports very simple charts and is great if
you are okay with the predefined styles. jqPlot supports IE7 and newer.
jQuery Sparklines
A jQuery plug-in for generating sparklines, typically small bar, line, or area charts
used inline with text. Supports most browsers, even back to IE6.
Peity
A jQuery plug-in for very simple and very tiny bar, line, and pie charts that supports
only recent browsers. Did I mention that this makes only very tiny visualizations?
+10 cuteness points.
Timeline.js
A library specifically for generating interactive timelines. No coding is required;
just use the code generator. There is not much room for customization, but hey,
timelines are really hard to do well. Timeline.js supports only IE8 and newer.

Alternatives | 11
YUI Charts
The Charts module for the Yahoo! User Interface Library enables creation of simple
charts with a goal of wide browser support.

Graph Visualizations
A “graph” is just data with a networked structure (for example, B is connected to A, and
A is connected to C).
Arbor.js
A library for graph visualization using jQuery. Even if you never use this, you should
check out how the documentation is presented as a graph, using the tool itself. (It’s
so meta.) It uses the HTML canvas, so it works only in IE9 or current browsers,
although some workarounds are available.
Sigma.js
A very lightweight library for graph visualization. You have to visit this website,
move your mouse over the header graphic, and then play with the demos. Sigma.js
is beautiful and fast, and it also uses canvas.

Geomapping
I distinguish between mapping (all visualizations are maps) and geomapping (visuali‐
zations that include geographic data, or geodata, such as traditional maps). D3 has a lot
of geomapping functionality, but you should know about these other tools.
Kartograph
A JavaScript-and-Python combo for gorgeous, entirely vector-based mapping by
Gregor Aisch with must-see demos. Please go look at them now. I promise you’ve
never seen online maps this beautiful. Kartograph works with IE7 and newer.
Leaflet
A library for tiled maps, designed for smooth interaction on both desktop and
mobile devices. It includes some support for displaying data layers of SVG on top

12 | Chapter 2: Introducing D3
of the map tiles. (See Mike’s demo “Using D3 with Leaflet”.) Leaflet works with IE6
(barely) or IE7 (better!) and of course all current browsers.
Modest Maps
The granddaddy of tiled map libraries, Modest Maps has been succeeded by Poly‐
maps, but lots of people still love it, as it is lightweight and works with old versions
of IE and other browsers. Modest Maps has been adapted for ActionScript, Pro‐
cessing, Python, PHP, Cinder, openFrameworks…yeah, basically everything. File
this under “oldie, but goodie.”
Polymaps
A library for displaying tiled maps, with layers of data on top of the tiles. Polymaps
relies on SVG and thus works best with current browsers.

Almost from Scratch


These tools, like D3, provide methods of drawing visual forms, but without predesigned
visual templates. If you enjoy the creative freedom of starting from scratch, you might
enjoy these.
Processing.js
A native JavaScript implementation of Processing, the fantastic programming lan‐
guage for artists and designers new to programming. Processing is written in Java,
so exporting Processing sketches to the Web traditionally involved clunky Java
applets. Thanks to Processing.js, regular Processing code can run natively, in the
browser. It renders using canvas, so only modern browsers are supported.
Paper.js
A framework for rendering vector graphics to canvas. Also, its website is one of the
most beautiful on the Internet, and their demos are unbelievable. (Go play with
them now.)
Raphaël
Another library for drawing vector graphics, popular due to its friendly syntax and
support for older browsers.

Three-Dimensional
D3 is not the best at 3D, simply because web browsers are historically two-dimensional
beasts. But with increased support for WebGL, there are now more opportunities for
3D web experiences.
PhiloGL
A WebGL framework specifically for 3D visualization.

Alternatives | 13
Three.js
A library for generating any sort of 3D scene you could imagine, produced by
Google’s Data Arts team. You could spend all day exploring the mind-blowing de‐
mos on their site.

Tools Built with D3


When you want to use D3 without actually writing any D3 code, you can choose one of
the many tools built on top of D3!
Crossfilter
A library for working with large, multivariate datasets, written primarily by Mike
Bostock. This is useful for trying to squeeze your “big data” into a relatively small
web browser.
Cubism
A D3 plug-in for visualizing time series data, also written by Mike Bostock. (One
of my favorite demos.)
Dashku
An online tool for data dashboards and widgets updated in real time, by Paul Jensen.
dc.js
The “dc” is short for dimensional charting, as this library is optimized for exploring
large, multidimensional datasets.
NVD3
Reusable charts with D3. NVD3 offers lots of beautiful examples, with room for
visual customizations without requiring as much code as D3 alone.
Polychart.js
More reusable charts, with a range of chart types available. Polychart.js is free only
for noncommercial use.
Rickshaw
A toolkit for displaying time series data that is also very customizable.
Tributary
A great tool for experimenting with live coding using D3, by Ian Johnson.

14 | Chapter 2: Introducing D3
CHAPTER 3
Technology Fundamentals
Download from Wow! eBook <www.wowebook.com>

Solid familiarity with the following concepts will make your time with D3 a lot less
frustrating and a lot more rewarding. Consider this a brief refresher course on Web-
Making 101.

Beware! This is a pretty dense chapter, packed with years’ worth of web
development knowledge, and nothing in here is specific to D3. I rec‐
ommend skimming just the sections on information that is new to you,
and skipping the rest. You can always reference this chapter later as
questions arise.

The Web
If you’re brand new to making web pages, you will now have to think about things that
regular people blissfully disregard every day, such as this: How does the Web actually
work?
We think of the Web as a bunch of interlinked pages, but it’s really a collection of con‐
versations between web servers and web clients (browsers).
The following scene is a dramatization of a typical such conversation that happens
whenever you or anyone else clicks a link or types an address into your browser (mean‐
ing, this brief conversation is had about 88 zillion times every day):

CLIENT: I’d really like to know what’s going on over at somewebsite.com. I better call over
there to get the latest info. [Silent sound of Internet connection being established.]
SERVER: Hello, unknown web client! I am the server hosting somewebsite.com. What
page would you like?
CLIENT: This morning, I am interested in the page at somewebsite.com/news/.
SERVER: Of course, one moment.

15
Code is transmitted from SERVER to CLIENT.
CLIENT: I have received it. Thank you!
SERVER: You’re welcome! Would love to stay on the line and chat, but I have other
requests to process. Bye!

Clients contact servers with requests, and servers respond with data. But what is a server
and what is a client?
Web servers are Internet-connected computers running server software, so called be‐
cause they serve web documents as requested. Servers are typically always on and always
connected, but web developers often also run local servers, meaning they run on the
same computer that you’re working on. Local means here; remote means somewhere
else, on any computer but the one right in front of you.
There are lots of different server software packages, but Apache is the most common.
Web server software is not pretty, and no one ever wants to look at it.
In contrast, web browsers can be very pretty, and we spend a lot of time looking at them.
Regular people recognize names like Firefox, Safari, Chrome, and Internet Explorer, all
of which are browsers or web clients.
Every web page, in theory, can be identified by its URL (Uniform Resource Locator) or
URI (Uniform Resource Identifier). Most people don’t know what URL stands for, but
they recognize one when they see it. By obsolete convention, URLs commonly begin
with www, as in http://www.calmingmanatee.com, but with a properly configured serv‐
er, the www part is wholly unnecessary.
Complete URLs consist of four parts:

• An indication of the communication protocol, such as HTTP or HTTPS


• The domain name of the resource, such as calmingmanatee.com
• The port number, indicating over which port the connection to the server should
be attempted
• Any additional locating information, such as the path of the requested file, or any
query parameters

A complete URL, then, might look like this: http://alignedleft.com:80/tutorials/d3/.


Typically, the port number is excluded, as web browsers will try to connect over port 80
by default. So the preceding URL is functionally the same as the following: http://
alignedleft.com/tutorials/d3/
Note that the protocol is separated from the domain name by a colon and two forward
(regular) slashes. Why two slashes? No reason. The inventor of the Web regrets the error.

16 | Chapter 3: Technology Fundamentals


HTTP stands for Hypertext Transfer Protocol, and it’s the most common protocol for
transferring web content from server to client. The “S” on the end of HTTPS stands for
Secure. HTTPS connections are used whenever information should be encrypted in
transit, such as for online banking or e-commerce.
Let’s briefly step through the process of what happens when a person goes to visit a
website.

1. User runs the web browser of her choice, then types a URL into the address bar,
such as alignedleft.com/tutorials/d3/. Because she did not specify a protocol, HTTP
is assumed, and “http://” is prepended to the URL.
2. The browser then attempts to connect to the server behind alignedleft.com across
the network, via port 80, the default port for HTTP.
3. The server associated with alignedleft.com acknowledges the connection and is
taking requests. (“I’ll be here all night.”)
4. The browser sends a request for the page that lives at /tutorials/d3/.
5. The server sends back the HTML content for that page.
6. As the client browser receives the HTML, it discovers references to other files needed
to assemble and display the entire page, including CSS stylesheets and image files.
So it contacts the same server again, once per file, requesting the additional infor‐
mation.
7. The server responds, dispatching each file as needed.
8. Finally, all the web documents have been transferred over. Now the client performs
its most arduous task, which is to render the content. It first parses through the
HTML to understand the structure of the content. Then it reviews the CSS selectors,
applying any properties to matched elements. Finally, it plugs in any image files and
executes any JavaScript code.

Can you believe that all that happens every time you click a link? It’s a lot more com‐
plicated than most people realize, but it’s important to understand that client/server
conversations are fundamental to the Web.

HTML
Hypertext Markup Language is used to structure content for web browsers. HTML is
stored in plain text files with the .html suffix. A simple HTML document looks like this:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>

HTML | 17
<h1>Page Title</h1>
<p>This is a really interesting paragraph.</p>
</body>
</html>
HTML is a complex language with a rich history. This overview will address only the
current iteration of HTML (formerly known as HTML5) and will touch on only what
is immediately relevant for our practice with D3.

Content Plus Structure


The core function of HTML is to enable you to “mark up” content, thereby giving it
structure. Take, for example, this raw text:
Amazing Visualization Tool Cures All Ills A new open-source tool designed for
visualization of data turns out to have an unexpected, positive side effect:
it heals any ailments of the viewer. Leading scientists report that the tool,
called D3000, can cure even the following symptoms: fevers chills general
malaise It achieves this end with a patented, three-step process. Load in data.
Generate a visual representation. Activate magic healing function.
Reading between the lines, we can infer that this is a very exciting news story. But as
unstructured content, it is very hard to read. By adding structure, we can differentiate
between the headline, for example, and the body of the story.

Amazing Visualization Tool Cures All Ills


A new open-source tool designed for visualization of data turns out to have an unexpec‐
ted, positive side effect: it heals any ailments of the viewer. Leading scientists report that
the tool, called D3000, can cure even the following symptoms:

• fevers
• chills
• general malaise

It achieves this end with a patented, three-step process.

1. Load in data.
2. Generate a visual representation.
3. Activate magic healing function.

That has the same raw text content, but with a visual structure that makes the content
more accessible.
HTML is a tool for specifying semantic structure, or attaching hierarchy, relationships,
and meaning to content. (HTML doesn’t address the visual representation of a

18 | Chapter 3: Technology Fundamentals


document’s structure—that’s CSS’ job.) Here is our story with each chunk of content
replaced by a semantic description of what that content is.

Headline
Paragraph text

• Unordered list item


• Unordered list item
• Unordered list item

Paragraph text

1. Numbered list item


2. Numbered list item
3. Numbered list item

This is the kind of structure we specify with HTML markup.

Adding Structure with Elements


“Marking up” is the process of adding tags to create elements. HTML tags begin with <
and end with >, as in <p>, which is the tag indicating a paragraph of text. Tags usually
occur in pairs, in which case adding an opening and closing pair of tags creates a new
element in the document structure.
Closing tags are indicated with a slash that closes or ends the element, as in </p>. Thus,
a paragraph of text may be marked up like the following:
<p>This is a really interesting paragraph.</p>

Some elements can be nested. For example, here we use the em element to add emphasis.
<p>This is a <em>really</em> interesting paragraph.</p>

Nesting elements introduces hierarchy to the document. In this case, em is a child of p


because it is contained by p. (Conversely, p is em’s parent.)
When elements are nested, they cannot overlap closures of their parent elements, as
doing so would disrupt the hierarchy. For example:
<p>This could cause <em>unexpected</p>
<p>results</em>, and is best avoided.</p>

HTML | 19
Some tags never occur in pairs, such as the img element, which references an image file.
Although HTML no longer requires it, you will sometimes see such tags written in self-
closing fashion, with a trailing slash before the closing bracket:
<img src="photo.jpg" />
As of HTML5, the self-closing slash is optional, so the following code is equivalent to
the preceding code:
<img src="photo.jpg">

Common Elements
There are hundreds of different HTML elements. Here are some of the most common.
We’ll cover additional elements in later chapters. (Reference the excellent Mozilla De‐
veloper Network documentation for a complete listing.)
<!DOCTYPE html>
The standard document type declaration. Must be the first thing in the document.
html
Surrounds all HTML content in a document.
head
The document head contains all metadata about the document, such as its title
and any references to external stylesheets and scripts.
title
The title of the document. Browsers typically display this at the top of the browser
window and use this title when bookmarking a page.
body
Everything not in the head should go in the body. This is the primary visible content
of the page.
h1, h2, h3, h4
These let you specify headings of different levels. h1 is a top-level heading, h2 is
below that, and so on.
p
A paragraph!
ul, ol, li
Unordered lists are specified with ul, most often used for bulleted lists. Ordered
lists (ol) are often numbered. Both ul and ol should include li elements to specify
list items.
em
Indicates emphasis. Typically rendered in italics.

20 | Chapter 3: Technology Fundamentals


strong
Indicates additional emphasis. Typically rendered in boldface.
a
A link. Typically rendered as underlined, blue text, unless otherwise specified.
span
An arbitrary span of text, typically within a larger containing element like p.
div
An arbitrary division within the document. Used for grouping and containing re‐
lated elements.
Our earlier example could be given semantic structure by marking it up using some of
these element’s tags:
<h1>Amazing Visualization Tool Cures All Ills</h1>
<p>A new open-source tool designed for visualization of data turns out to have
an unexpected, positive side effect: it heals any ailments of the viewer.
Leading scientists report that the tool, called D3000, can cure even the
following symptoms:</p>
<ul>
<li>fevers</li>
<li>chills</li>
<li>general malaise</li>
</ul>
<p>It achieves this end with a patented, three-step process.</p>
<ol>
<li>Load in data.</li>
<li>Generate a visual representation.</li>
<li>Activate magic healing function.</li>
</ol>
When viewed in a web browser, that markup is rendered as shown in Figure 3-1.

HTML | 21
Figure 3-1. Typical default rendering of simple HTML

Notice that we specified only the semantic structure of the content; we didn’t specify
any visual properties, such as color, type size, indents, or line spacing. Without such
instructions, the browser falls back on its default styles, which, frankly, are not too
exciting.

Attributes
All HTML elements can be assigned attributes by including property/value pairs in the
opening tag.
<tagname property="value"></tagname>
The name of the property is followed by an equals sign, and the value is enclosed within
double quotation marks.
Different kinds of elements can be assigned different attributes. For example, the a link
tag can be given an href attribute, whose value specifies the URL for that link. (href is
short for “HTTP reference.”)
<a href="http://d3js.org/">The D3 website</a>

Some attributes can be assigned to any type of element, such as class and id.

Classes and IDs


Classes and IDs are extremely useful attributes, as they can be referenced later to identify
specific pieces of content. Your CSS and JavaScript code will rely heavily on classes and
IDs to identify elements. For example:

22 | Chapter 3: Technology Fundamentals


<p>Brilliant paragraph</p>
<p>Insightful paragraph</p>
<p class="awesome">Awe-inspiring paragraph</p>
These are three very uplifting paragraphs, but only one of them is truly awesome, as I’ve
indicated with class="awesome". The third paragraph becomes part of a class of awe‐
some elements, and it can be selected and manipulated along with other class members.
(We’ll get to that in a moment.)
Elements can be assigned multiple classes, simply by separating them with a space:
<p class="uplifting">Brilliant paragraph</p>
<p class="uplifting">Insightful paragraph</p>
<p class="uplifting awesome">Awe-inspiring paragraph</p>

Now, all three paragraphs are uplifting, but only the last one is both uplifting and
awesome.
IDs are used in much the same way, but there can be only one ID per element, and each
ID value can be used only once on the page. For example:
<div id="content">
<div id="visualization"></div>
<div id="button"></div>
</div>

IDs are useful when a single element has some special quality, like a div that functions
as a button or as a container for other content on the page.
As a general rule, if there will be only one such element on the page, you can use an
id. Otherwise, use a class.

Class and ID names cannot begin with numerals; they must begin with
alphabetic characters. So id="1" won’t work, but id="item1" will. The
browser will not give you any errors; your code simply won’t work, and
you will go crazy trying to figure out why.

Comments
As code grows in size and complexity, it is good practice to include comments. These
are friendly notes that you leave for yourself to remind you why you wrote the code the
way you did. If you are like me, you will revisit projects only weeks later and have lost
all recollections of it. Commenting is an easy way to reach out and provide guidance
and solace to your future (and very confused) self.
In HTML, comments are written in the following format:
<!-- Your comment here -->

Anything between the <!-- and --> will be ignored by the web browser.

HTML | 23
DOM
The term Document Object Model refers to the hierarchical structure of HTML. Each
pair of bracketed tags (or, in some cases, a single tag) is an element, and we refer to
elements’ relative relationships to each other in human terms: parent, child, sibling,
ancestor, and descendant. For example, in this HTML:
<html>
<body>
<h1>Breaking News</h1>
<p></p>
</body>
</html>

body is the parent element to both of its children, h1 and p (which are siblings to each
other). All elements on the page are descendants of html.
Web browsers parse the DOM to make sense of a page’s content. As coders building
visualizations, we care about the DOM, because our code must navigate its hierarchy
to apply styles and actions to its elements. We don’t want to make all the div elements
blue; we need to know how to select just the divs of the class sky and make them blue.

Developer Tools
In the olden days, the web development process went like this:

1. Write some code in a text editor.


2. Save the files.
3. Switch to a browser window.
4. Reload the page, and see if your code worked.
5. If it didn’t work, take a guess at what went wrong inside the magical black box of
the web browser, then go back to step 1.

Browsers were notoriously secretive about what went on inside the rendering engine,
which made debugging a total nightmare. (Seriously, in the late 1990s and early 2000s,
I literally had nightmares about this.) Fortunately, we live in a more enlightened age,
and every modern-day browser has built-in developer tools that expose the inner work‐
ings of the beast and enable us to poke around under the hood (to mix incompatible
metaphors).
All this is to say that developer tools are a big deal and you will rely on them heavily to
both test your code and, when something breaks, figure out what went wrong.
Let’s start with the simplest possible use of the developer tools: viewing the raw source
code of an HTML page (see Figure 3-2).

24 | Chapter 3: Technology Fundamentals


Every browser supports this, although different browsers hide this option in different
places. In Chrome 23.0, it’s under View→Developer→View Source. In Firefox 17.0, look
under Tools→Web Developer→Page Source. In Safari 6.0, it’s under Develop→Show
Page Source (although you must first set the “Develop” menu to display under Sa‐
fari→Preferences→Advanced). Going forward, I’m going to assume that you’re using
the newest version of whatever browser you choose.

Figure 3-2. Looking at the source code in a new window

That gets you the raw HTML, but if any D3 or JavaScript code has been executed, the
current DOM may be vastly different.
Fortunately, your browser’s developer tools enable you to see the current state of the
DOM. And, again, the developer tools are different in every browser. In Chrome, find
them under View→Developer→Developer Tools. In Firefox, try Tools→Web Developer.
In Safari, first enable the developer tools (in Safari→Preferences→Advanced). Then, in
the Develop menu, choose Show Web Inspector. In any browser, you can also use the
corresponding keyboard shortcut (as shown adjacent to the menu item) or right-click
and choose “inspect element” or something similar.
Until recently, Safari and Chrome shared the same developer tools, but with Safari 6.0,
Apple completely redesigned their dev tools, much to the dismay of many web-
developing Safari fans. (The new tools are very hard to navigate, and I don’t think I’m
the only one who feels that way.) Whichever browser you use might look a bit different
from my screenshots, but the functionality will be very similar.

Developer Tools | 25
Figure 3-3 shows the Elements tab of Chrome’s web inspector. Here we can see the
current state of the DOM. This is useful because your code will modify DOM elements
dynamically. In the web inspector, you can watch elements as they change.
Download from Wow! eBook <www.wowebook.com>

Figure 3-3. Chrome’s web inspector

If you look closely, you’ll already see some differences between the raw HTML and the
DOM, including the fact that Chrome generated the required html, head, and body
elements. (I was lazy and didn’t include them in my original HTML.)

26 | Chapter 3: Technology Fundamentals


One more thing: why am I focusing on Chrome, Firefox, and Safari? Why not Internet
Explorer, Opera, or the many other browsers out there? For one, it’s best to develop your
projects using a browser with the broadest support for web standards. Internet Explorer
made huge progress with versions 9 and 10, but Chrome, Firefox, and Safari are un‐
derstood to have the broadest standards support, and they are updated more frequently.
Second, you’re going to spend a lot of time using the developer tools, so you should
develop with a browser that has tools you enjoy using. I was pretty devoted to Safari
until the 6.0 update changed everything. Now I’m going back and forth between Chrome
and Firefox’s new dev tools. I recommend you try them all and decide what works best
for you.

Rendering and the Box Model


Rendering is the process by which browsers, after parsing the HTML and generating the
DOM, apply visual rules to the DOM contents and draw those pixels to the screen.
The most important thing to keep in mind when considering how browsers render
content is this: to a browser, everything is a box.
Paragraphs, divs, spans—all are boxes in the sense that they are two-dimensional rec‐
tangles, with properties that any rectangle can have, such as width, height, and positions
in space. Even if something looks curved or irregularly shaped, rest assured, to the
browser, it is merely another rectangular box.
You can see these boxes with the help of the web inspector. Just mouse over any element,
and the box associated with that element is highlighted in blue, as shown in Figure 3-4.

Rendering and the Box Model | 27


Figure 3-4. Inspector with element box highlighted

There’s a lot of information about the ul unordered list here. Note that the list’s total
dimensions (width and height) are shown in the yellow box at the element’s lower-left
corner. Also, the list’s position in the DOM hierarchy is indicated in the lower-left corner
of the inspector: html > body > ul.
The box for the ul expands to fill the width of the entire window because it is a block-
level element. (Note how under “Computed Style” is listed display: block.) This is in
contrast to inline elements, which rest in line with each other, not stacked on top of each
other like blocks. Common inline elements include strong, em, a, and span.
By default, block-level elements expand to fill their container elements and force any
subsequent sibling elements further down the page. Inline elements do not expand to
fill extra space, and happily exist side by side, next to their fellow inline neighbors.
(Discussion question: what kind of element would you rather be?)

28 | Chapter 3: Technology Fundamentals


CSS
Cascading Style Sheets are used to style the visual presentation of DOM elements. A
simple CSS stylesheet looks like the following:
body {
background-color: white;
color: black;
}
CSS styles consist of selectors and properties. Selectors are followed by properties, grou‐
ped in curly brackets. A property and its value are separated by a colon, and the line is
terminated with a semicolon, like the following:
selector {
property: value;
property: value;
property: value;
}
The same properties can be applied to multiple selectors at once by separating the se‐
lectors with a comma, as in the following:
selectorA,
selectorB,
selectorC {
property: value;
property: value;
property: value;
}

For example, you might want to specify that both p paragraphs and li list items should
use the same font size, line height, and color.
p,
li {
font-size: 12px;
line-height: 14px;
color: orange;
}
Collectively, this whole chunk of code (selectors and bracketed properties) is called a
CSS rule.

Selectors
D3 uses CSS-style selectors to identify elements on which to operate, so it’s important
to understand how to use them.
Selectors identify specific elements to which styles will be applied. There are several
different kinds of selectors. We’ll use only the simplest ones in this book.

CSS | 29
Discovering Diverse Content Through
Random Scribd Documents
Einsicht

Eine schneeweiße Pfauentaube saß mit dem Tauber auf dem


Dach. Sie glänzten in der Sonne und schnäbelten sich zärtlich.
»Das ist stark,« sagte das Truthuhn, das seinen Kopf ganz schief
halten mußte und dazu blinzeln um hinaufzusehen. Es wollte weiter
reden; aber da ging der Truthahn vorbei, kollerte und blähte sich,
und das Truthuhn warf sich platt auf die Erde, verliebt und demütig.
Es sah mit seinen blöden Augen zu dem stattlichen Tier empor, das
mit Rasseln und Trommeln dafür dankte und sich aufblies wie ein
Luftballon.
»Daß man einen Tauber anbeten kann!« kreischte das Truthuhn.
»Einen kleinen, unbedeutenden, farblosen Vogel, der keinem
Geschöpf Respekt einzuflößen imstande ist.« Es lag nun flach da,
wie ein breiter, bräunlicher Eierkuchen. Dem Truthahn schwoll der
rote Zierat an Kopf und Hals. Er wurde purpurrot.
»Daß er die Zärtlichkeit der Taube überhaupt für voll nimmt,«
kollerte er. »Daß er so wenig Einsicht hat und glaubt, was die Kleine
da oben girrt.« Er schüttelte sich. Das Truthuhn vor ihm wurde noch
flacher.
»Er ist ein Tauber,« sagte es verächtlich. »Kein Herrscher, kein
König unter seinesgleichen, kein ...« Es konnte nicht weiter, und
schnappte nach Luft. Sein bläuliches Köpflein bewegte sich vorwärts
und rückwärts. Es schloß die Augen und wartete, ob der Truthahn
seine Ergebenheit belohnen werde. Aber er rauschte weiter. Wie
dunkles Gold glänzte sein Gefieder. Er wußte, daß er der Stolz des
Hühnerhofes war.
Der große, weiße Hahn hatte dem Zwiegespräch zugehört. Er
schwieg. Stolz drehte er den gebogenen Hals, und gravitätisch ging
er seinen Hühnern voran durch den großen Hof. Eine der Hennen
sagte, daß sie sich wundere, daß der Truthahn sich mit der dummen
Dinde abgeben möge, die Verehrung und Zärtlichkeit heuchle. »Und
er glaubt das alles,« sagte ein braungesprenkeltes Huhn, und
trippelte zum Hahn. Der hob sich, schüttelte sich und krähte. Alle
Hühner sahen sich an.
»So wie du, kräht keiner,« sagte eines.
»Wer hat dein stolzes Auge?« fragte ein anderes, und gab der
Nachbarin einen Hieb, denn sie hatte ihm eine Mücke vor dem
Schnabel weggeschnappt.
»Wessen Schwanzfedern wölben sich wie die deinen?«
»Wer ist so weiß wie du?«
»Wer könnte uns beschützen, wie du es tust?« Der Hahn schwieg.
Er war klug. Aber er stolzierte durch den Hof, schlug mit den Flügeln
und krähte, daß alle Hähne der Nachbarschaft antworteten.
Der Enterich, der am Zaun in der Sonne lag, hatte mit seinen
beerenschwarzen Augen dem allem zugesehen. Er war aber zu faul,
um zu sagen, was er dachte. Er wippte nur mit dem Schwänzlein
und schnatterte ganz leise. Seine beiden Enten konnten sich nicht
genug wundern, daß der Hahn solche grobe Schmeicheleien glaube.
Sie sahen hinüber zum Hahn und schnatterten empört und
verächtlich. Dann begannen sie gleichzeitig den Enterich zärtlich zu
lausen. Er ließ es sich gefallen.
Warum auch nicht?
Eintagsfliegen

Ein paar leichtbeschwingte Fliegen summten um den schön


gezopften Misthaufen im Hühnerhof herum.
Eine von ihnen, eine behäbige, wie blaues Metall glänzende
Roßfliege setzte sich auf den hölzernen Zaun, der den Hof umschloß,
denn es war unter ihrer Würde, sich tiefer unten niederzulassen. Sie
hatte der Welt Großes geschenkt. Eine Entdeckung von
Ewigkeitswert war ihr gelungen: Sie hatte die Grenze der Erde
erreicht. Triumphierend sah sie sich um.
»Die ganze Welt ist nun unser,« sagte sie, und ein Schauer der
Ehrfurcht machte die zarten Flügel der andern erzittern.
»Unser, im wahren Sinn des Wortes,« sagte bewundernd eine
kleine, muntere Fliege. »Nach allen Richtungen haben wir sie
erforscht. Sie birgt kein Geheimnis mehr für uns.« Die tausend
Augen der Zuhörer richteten sich wieder auf die Roßfliege, die aber
unwillig surrte, denn sie liebte es nicht, wenn andere in der Mehrzahl
von ihrer Entdeckung redeten.
Die muntere Fliege kratzte sich etwas verlegen mit dem dünnen
Beinchen den Kopf.
»Ich sage wir, weil ich dadurch andeuten möchte, daß das
Universum teilnimmt an dem Großen, das in diesen Tagen geschah.
Und auch, weil wir andern es uns nicht nehmen lassen wollen, uns
als einen Teil des Ganzen zu fühlen, als einen Stein am Bauwerk der
Wissenschaft, als eine Staffel an der Leiter des Ruhms, deren
höchste Stufe unsere glorreiche Roßfliege – es verneigten sich alle
zum Zeichen des Respekts und schwirrten mit den Flügeln – erreicht
hat.«
Die Gefeierte sah bescheiden mit den tausend Facetten ihrer
Augen zum Himmel auf, mit der anderen Hälfte spiegelte sie im Kreis
herum, ob man ihr auch allseitig die gebührende Hochachtung
erweise.
Plötzlich flogen alle Anwesenden erschrocken auf, denn es nahte
sich ein großer, unbekannter Fliegenschwarm. Sie setzten sich aber
sogleich wieder, da die Herannahenden kamen, um dem
blauglänzenden Forscher Ehre zu erweisen.
Ein gegenseitiges, höfliches Flügelrauschen, Summen und Surren
erhob sich. Ein bewunderndes Auf- und Abwogen, ein Gratulieren,
bescheidenes Abwehren, interessiertes Fragen, bestimmtes, sicheres
Antworten. Eine grünschillernde Fliege sprach für die andern. Sie
wandte sich an die Roßfliege.
»Du hast es erreicht,« begann sie. »Ohnegleichen ist dein Ruhm.
Himmel und Erde sind dir kein Geheimnis mehr. Die Grenze der Welt
hast du erforscht. Unter die Unsterblichen bist du aufgenommen
worden.« Sie funkelte mit ihren geschliffenen Augen die Roßfliege
an, die zusehends dicker, größer, blauer und haariger wurde. Alles an
ihr wuchs und gleißte.
Sie surrte auf das korrekteste ihren Dank, nahm den Orden der
erlösten Paradiesfliegen entgegen, und geleitete darauf die
Deputation über den Misthaufen, durch den Hof, weit in den Garten
hinaus. –
»Die Blaue platzt noch vor Hochmut,« sagte eine Biene, die an ihr
vorüberflog. Sie kroch in eine rosafarbene Primel, blieb dort eine
Weile, und kam heraus, die Füßchen voll Blütenstaub. »Was hat man
davon, wenn man weiß, daß am Ende der Welt ein Berg ist, den
keiner überfliegen kann?« fragte sie.
»Nichts,« sagte verächtlich ein Schmetterling, der auf der Primel
saß. »Aber was hast du von deiner Arbeit?«
Verblüfft sah die Biene ihn an.
»Genug, meine ich. Die Welt bewundert uns und braucht uns.
Ohne uns schritte der dürrbeinige Hunger durch das Land. Ohne uns
stürbe, was Odem hat. Was ich davon habe? Dumme Frage: Wir sind
die Ernährer der Welt.« Zornig schnellte sie ihren Stachel gegen den
samtnen Schmetterling.
Er wiegte sich jetzt auf einer frühen Narzisse, die weiß wie er, ihr
goldenes Krönchen auf der Stirne, ihren zarten Duft verbreitete.
»Arbeitstiere ihr,« sagte er verächtlich. »Ihr braucht auf euren
Stand auch noch stolz zu sein. Grobes Volk, aller Schönheit bar. Wir
Schmetterlinge sind der Zweck der Schöpfung. Wir sind das Schöne.
Wir tragen den blauen Himmel, die bunten Blumen, die
durchsichtigen Steine und den Schimmer des Goldes auf unsern
Flügeln. Wir baden uns im flirrenden Sonnenstrahl und nähren uns
von glitzerndem Tau. Wir leben um zu genießen. Ohne uns wäre die
Welt öde, glanzlos, traurig.«
Er berührte den silberschimmernden Atlas der Narzisse mit den
zarten Flügeln. Die Biene flog mürrisch summend davon, dem Garten
zu, wo ihr Korb stand. Sie flog mit ihren beschwerten Füßen langsam
an der blauen Roßfliege vorüber, die eben heimkehrte in der Mitte
ihrer Anbeter.
»Faulenzer,« brummte die Biene.
In der Nacht kam ein Frost. Am Morgen lagen sie alle starr und
steif am Boden, die Fliegen, die Biene und der Schmetterling. Auf
dem Rücken lagen sie und streckten die Beine gen Himmel. – Über
ihnen lächelten die Sterne.
Der Gesangverein
Mitten in einem Steinbruch lag ein Tümpel, der von großen Blättern
beschattet war, und wo der Gesangverein »Froschenia« seine
Übungen abhielt. Jeden Donnerstag Abend.
Es war ein feiner Gesangverein, und nur feine Leute sangen mit.
Waren andere Elemente eingetreten, so wurden sie rechtzeitig
hinausgeekelt. Sämtliche Mitglieder hatten Grün als ihre Farbe
erwählt, und so erschienen bei den Übungen die Damen in grünen
Roben, die Herren in ebensolchen Fracks, mit weißen oder gelben
Piquéwesten*.
* Die Verpflichtung, nur grün gekleidet den Übungen beizuwohnen, hielt
auch Unbemittelte fern. Sie waren nicht erwünscht.

Es war kurz vor acht Uhr. Man fand sich immer ein paar Minuten
vor der Zeit ein, teils um des notwendigen, sehr beliebten Flirts
willen, teils um die ebenso berechtigte Medisance zu Wort kommen
zu lassen.
Nur die ganz jungen Fräuleins kamen naiv um des Singens willen,
sie schwärmten aber für den Kapellmeister. Daß er verheiratet war,
tat nichts zur Sache, da die Backfische gänzlich wunschlos
schwärmten.
Der Meister kam und bestieg sein Pult.
»O Gott!« sagten die ganz jungen Fräuleins und sahen sich
errötend an.
Die älteren Damen warfen sich bedeutungsvolle Blicke zu; denn
der Musiker hatte mit einer unter ihnen einen kurzen Gruß
getauscht. Man wußte, daß sie einander sehr genau kannten.
»Ekelhafter Patron,« näselte ein Student, »glaubt sich hier Hahn
im Korb.« Die Studenten waren wütend, weil sie von den
Backfischen nicht beachtet wurden; die hatten nur Augen für den
verehrten Meister.
Der Kapellmeister gab das Zeichen zum Beginn. Man übte aus
Carmen.
»Ich bitte die Bässe gefälligst beginnen zu wollen!« rief der
Dirigent. Alle erhoben sich, und: Mut in der Brust, siegesbewußt!
erscholl es unter den großen Blättern.
»Halt! Etwas mehr Feuer, muß ich bitten!« rief der Kapellmeister.
Also noch einmal: Mut in der Brust, siegesbewußt! Diesmal wurde
der Chor zu Ende gesungen.
»Meine Herren,« schrie der Musiker, »ich habe Sie singen lassen,
um einmal den vollen Eindruck eines derartigen Singsangs zu
bekommen! Meine Herren! Ist das gesungen? Das ist geleiert. Haben
Sie denn keine Ahnung, was das ist: Mut in der Brust? Hat denn
noch keiner von Ihnen Siegesbewußtsein empfunden! Mut ist – –«
Da patschte es im Wasser, ein roter Schnabel wurde sichtbar, und
ein paar lange Beine traten mitten zwischen die grünen Herren und
Damen.
Eine Sekunde lang war alles starr; dann sprangen, huschten,
schwammen und quiekten sie durcheinander und waren im Nu
verschwunden. Der Storch hatte das Nachsehen und schrie
höhnisch: »Jawohl! Mut in der Brust! Ihr seid mir die Rechten!«
Dann suchte er sich anderswo sein Nachtessen.
Es dauerte eine lange Weile, ehe sich einer der Herren Frösche
hervorwagte, dann ein zweiter und dritter. Endlich war die ganze
Gesellschaft wieder beisammen. Sie waren noch ganz aufgeregt von
dem Abenteuer. Der Dirigent begab sich an sein Pult, bedeutend
milder gestimmt, klopfte dreimal mit seinem Stab und rief: »Meine
Herren und Damen! Ich bitte um das Lied: Ein Veilchen auf der
Wiese stand!« Das Lied wurde mit Empfindung gesungen, und
mußte nur ein einziges Mal wiederholt werden.
Da aber der Meister beim Schluß des Liedes die Augen jedesmal
nach der vorerwähnten Dame verdrehte, begann ein Backfisch zu
kichern, andere fielen ein, es lachten die älteren Fräuleins, es
lachten die Damen, die Herren, zuletzt alle.
Wütend klopfte der Kapellmeister.
»Ich bitte die ungezogenen Backfische den Saal zu verlassen!«
schrie er.
»Was! Ungezogenen Backfische!« brüllten die Studenten, »das
lassen wir uns nicht gefallen!« Sie stürmten das Dirigentenpult,
packten den armen Musiker an den Beinen, und in hohem Bogen
flog er ins Wasser.
Die Übung war aus. Arm in Arm verließen die Studenten mit den
Backfischen das Lokal. Diese schwärmten nun für ihre Verteidiger,
die ihren Vorteil wahrnahmen. Hinter jedem Blatt saß ein Pärchen.
Die Damen waren vorsichtiger; sie trafen sich mit den
betreffenden Herren erst weit draußen und benutzten die Schatten
der Binsen.
Die älteren Herren aber zogen in den »Goldenen Frosch«, um den
heutigen Abend durchzusprechen. Die Stimmung war sehr animiert,
es wurde viel getrunken. Nach Mitternacht schwankte eine Reihe
grünbefrackter Gestalten nach Hause und sang: Mut in der Brust,
siegesbewußt! mit so viel Verve und Feuer, daß auch der
Kapellmeister zufrieden gewesen wäre!
Das kluge Huhn

Im Hühnerhof war große Gesellschaft. Von überall her waren die


Hühner und Enten eingeladen. Zu einem Gericht frischer Maikäfer
hieß es, in Wahrheit aber um die neue Nachbarin in Augenschein zu
nehmen. Es ging das Gerücht in der Gegend, daß sie eine
Andalusierin sei. Und das mußte wahr sein, denn tief schwarz war
das Gefieder, und blau die Bäcklein, wirklich blau. Andere Spanier,
Minorka zum Beispiel, hatte man ja auch schon gesehen, aber
Andalusier noch nie.
Die Fremde benahm sich wirklich nett. Sie begrüßte jede der
Hennen einzeln, und nur ganz kurz den Hahn.
Sie beantwortete sämtliche Fragen mit »Ja« oder »Nein«. Selber
fragte sie nichts.
Nur bei den Hennen, die Junge hatten, forschte sie eifrig, ob alle
die Kleinen gesund seien, und fügte hinzu, daß sie selten so hübsche
Jungen gesehen habe.
Diese weise Frage hatte sie von ihrer Großmutter.
»Kücken,« hatte die gesagt; »du gehst nun in die weite Welt. Klug
bist du nicht. Also gibt es für dich nur zweierlei zu beobachten:
Begegnet dir ein Hahn, so sei schweigsam, und begegnet dir ein
Huhn, so lobe seine Jungen. Beide werden deine Klugheit preisen.«
Die einzige Klugheit des spanischen Kückens war aber die, daß es
seiner Großmutter gehorchte. Und auch diese Klugheit verdankte es
nur seiner Dummheit. Es fiel ihm leichter zu gehorchen, als selbst zu
denken.
Der Rat des alten spanischen Huhnes bewährte sich.
»Es ist wirklich eine gescheite Henne,« sagten die mütterlichen
Hühner.
»Das ist sie,« bestätigte der Hahn und fügte anzüglich hinzu:
»Wenigstens gackelt sie nicht den ganzen Tag wie gewisse andre.
Sie muß klug sein.«
Nun war die Parole ausgegeben. Die kluge Spanierin wurde sie
überall genannt.
»Sie kann reizend zuhören,« sagten die guten, schwatzhaften
Hühner und merkten nie, daß die Fremde bei ihren Erzählungen die
Augen geschlossen hatte und träumte.
»Und so bescheiden ist sie,« sagte die alte Ente. Sie konnte es
nicht leiden, wenn ihr jemand widersprach, ganz besonders wenn es
junge Leute waren. Die Jungen hatten »Ja« zu antworten, und damit
basta.
Und »Ja« antwortete die Spanierin immer, warum hätte sie »Nein«
sagen sollen? Es war ihr ja ganz gleichgültig, was die Alte da
behauptete.
Der Hahn aber liebte seine schwarze Andalusierin sehr. Sie
bewunderte ihn schweigend. Mit kindlichen, runden Augen sah sie zu
ihm auf. Sie schwieg, wenn die anderen gackelten. Sie lief immer
dicht hinter dem Hahn und ging nie eigene Wege. Auch hatte sie nie
eine eigene Meinung.
Später hatte die Spanierin Junge. Reizende, schwarze, kleine
Geschöpfe. Sie hütete und fütterte sie und lief nie von ihrer Seite.
Das tut ein Huhn aus Instinkt, dazu braucht es keinen Verstand.
Als sie aufwuchsen, gab es freilich Hindernisse.
»Was muß ich tun, um in der Welt fortzukommen?« fragte einer
der jungen Gockel.
»Du mußt »ja« und »nein« sagen und die Kücken der Hennen
loben,« sagte das Huhn. »Das hat mich meine Großmutter gelehrt,
und ich bin gut damit ausgekommen.«
Das Huhn sah nicht, daß hinter dem Zaun eine schöne, bunte
Katze saß, mit feurigen, gelben Augen, die das Gockelchen
unverwandt anstarrte. Es lief auf sie zu. Die Katze packte es und
trug es im Maul davon.
»Was muß ich tun, um in der Welt fortzukommen?« fragte auch
eines der jungen Hühnchen.
»Du mußt dem Gockel gefallen, das hat schon meine Großmutter
mich gelehrt,« sagte das spanische Huhn und warnte das Hühnchen
nicht vor dem Habicht, der mit gierigen Augen über dem Hühnerhof
kreiste. Er schoß herab und packte das Hühnchen mit seinen
scharfen Krallen.
Auch die andern Kücken kamen gelaufen.
»Was ist das Schönste in der Welt?« fragten sie.
»Das Schlafen,« sagte die Andalusierin und schloß ihre Augen. Die
Kücken schlossen auch ihre Augen.
Sie sagten des ganze Leben »ja« und »nein«. Sie fraßen und
schliefen.
Als das spanische Huhn starb, hielt der Hahn die Grabrede. Er
nannte die Andalusierin die Klügste des Hühnerhofes.
»Des Hühnerhofes,« nickte klappernd der Storch und flog davon.
Der alte Schafbock

In der Schafherde lebte ein alter Bock. Er war nicht liebenswürdig


gewesen, als er jung war, und er glaubte nun das Recht zu haben,
noch viel weniger liebenswürdig zu sein, da er alt geworden. Um
seines Alters willen mußte die ganze Herde sich ihm beugen. Einzig
gegen die jungen Schäfchen war er freundlich, und die hätten es
lieber gehabt, wenn er weniger artig gewesen wäre. Dies fanden
auch die jungen Böcke. »Das Recht des Alters« nannte es der
Schafbock, wenn er an den Lämmern herumschnüffelte.
Er hatte aber noch andre Eigenschaften.
Meistens erzählte er lange, langweilige Geschichten, und vergaß
im Laufe der Erzählung das Ende. Er fing dann von vorne an und
erzählte die Geschichte noch einmal. Aber dann passierte es ihm
leicht, daß er die Pointe einer andern Erzählung dieser anfügte. Das
merkten aber nur die andern, er selbst nie.
Man sah es ihm immer an, wenn er erzählen wollte, er hatte dann
einen matten, in sich gekehrten Blick. Wer ihn bemerkte, nahm
Reißaus. Nur die ganz Jungen nicht, die sahen nie, was ihnen
drohte; noch nicht einmal merkten sie es, wenn der Alte sie zu sich
rief.
»Laßt euch einmal erzählen, wie zu meiner Zeit die Alten
behandelt wurden,« sagte er dann, und die Helden seiner
Geschichten wurden jedesmal tugendhafter, und die Böcklein, die
zuhörten, kamen sich jedesmal gemeiner vor, wenn sie sich mit den
Altersgenossen des alten Schafbockes verglichen. Aber wieder nur
die ganz Jungen.
Die andern kannten die Form, nach der die schönen, moralischen
Lügen geprägt wurden.
Der alte Bock hatte aber nicht nur Belehrendes zu erzählen. Stand
er unter den Schafen, so ging es nach einer andern Melodie, und
hatte er sich gar an die Jungen herangeschlichen, so hörte er
überhaupt mit Erzählen auf, und die Lämmlein mußten sich von ihm
lecken lassen, so sehr ihnen vor seinen kahlen Stellen im Pelz und
seinen roten Augen ekelte.
»Denkt, ich sei euer Großvater, meine Lämmchen,« sagte er. Aber
das dachten sie nicht und sprangen bei der ersten Gelegenheit
davon.
Der alte Schafbock hörte nicht mehr gut, deshalb mußte jedes
Wort, das in seiner Gegenwart gesprochen wurde, wiederholt
werden, auch das gleichgültigste.
»Das ist das Recht des Alters,« behauptete er auch da. Zudem
nahm er alles übel, und die Jungen mußten um Verzeihung bitten,
wenn sie es schon nicht böse gemeint hatten.
»Das ist die Pflicht der Jugend,« sagte er. Er hatte auch ein
schlechtes Gedächtnis und wiederholte fortwährend dasselbe. Wenn
den andern die Geduld ausging, und sie über ihn weg zusammen
redeten, wurde er wütend.
»Nie wäre so etwas zu meiner Zeit möglich gewesen,« schrie er.
»Die heutige Jugend ist entartet, der Respekt vor dem Alter ist tot!«
»Warum soll man eigentlich gerade vor dem Alter Respekt
haben?« fragte ein kräftiges Böcklein.
»Warum? Warum?« Der Alte schnappte nach Luft. Er erstickte fast
vor Zorn. Er schnaufte und nieste und schäumte und bespritzte die
Umstehenden. Aber als er fertig war, fand er doch keine Antwort.
»Darum!« mähte er endlich heiser. »Ich verlange Respekt von
euch, das ist mein Recht! Ihr habt zu schweigen, wenn ich rede, ihr
habt zuzuhören, wenn ich erzähle, ihr habt stillzuhalten, wenn ich
euch liebkose. Ihr habt mir nicht zu widersprechen, wenn ich etwas
behaupte, und ihr habt mich zu ehren und zu lieben und zu achten.«
Erschöpft schwieg er.
»Warum?« fragten sie wieder. »Wir wollen wissen warum!«
»Weil ich alt bin!« Der alte Schafbock ging seinem Stalle zu, um zu
schlafen.
»Wenn er freundlich wäre,« sagten die Schafe, »wir wollten ihm
gerne helfen und ihm dienen!«
»Wenn er würdevoll wäre,« sagten die jungen Böcklein, »wir
wollten ihm gerne gehorchen.«
»Wenn er weise wäre,« sagten die alten Schafe, »wir hörten
gerne seine Lehren. Aber er ist nur alt. Hat er darum ein Recht auf
unser aller Wohlbehagen?«
»Nein,« schrien alle, »er hat keines! Wir wollen ausziehen und uns
belehren über die Rechte des Alters.« Die ganze Schafherde ging
über Land.
Sie fanden ein altes Pferd auf der Weide. Still und ruhig graste es.
Sprangen unerfahrene, junge Pferde zu nahe an den Fluß, so hielt es
sie auf. Den Füllen wehrte es die Fliegen. Wollten die Pferde in
wildem Jagen ihre Glieder üben, so stand es beiseite, und freute sich
der tollen Sprünge und gedachte dabei der eigenen Jugend. Und die
jungen Pferde suchten die saftigsten Kräuter und führten das alte
Pferd dorthin. Sie rieben sich schmeichelnd an ihm und scherzten
mit ihm. Sie liebten es, denn es freute sich ihrer Jugend.
»Hat das alte Pferd von seinen Rechten gesprochen?« fragte der
Leiter der Schafherde.
»Kein Wort!« riefen alle. Darauf fanden sie einen rissigen, uralten
Baum. Hohl war sein Stamm, und dürre Äste ragten traurig zum
Himmel auf. Aber fröhlicher Efeu war am Stamme in die Höhe
geklettert und schmiegte sich schmeichelnd an die Eiche.
»Kann der Baum den Efeu zwingen, ihn zu schmücken, darum weil
er alt ist?« fragte der Leitbock die Herde.
»Niemals,« antworteten die Tiere.
Am Bache lag ein alter, grauer Stein. Er lag mitten im Flußbett und
störte den Lauf des Bächleins. Aber er hatte sich mit grünem Moos
bedeckt, er hatte seine scharfen Kanten und Ecken vom lustigen
Wässerlein abschleifen lassen und hörte freundlich auf sein Murmeln
und Plätschern, und freute sich des munteren Gefährten, der sein
Alter erheiterte.
»Warum kräuselt sich der Bach so gerne um den alten Stein?«
fragte der Bock die Herde.
»Weil der Alte ihn nicht hemmt!« rief die Herde.
»So brauchen wir nicht weiter zu ziehen,« sagte der Bock. »Wir
wissen nun, was wir wissen wollten.« Und sie zogen heimwärts bis
zu ihrer Weide, wo der alte Bock mürrisch an der Sonne lag und
schalt, daß man ihn so lange allein gelassen.
»Ich habe ein Recht, zu verlangen, daß man bei mir bleibe,« rief
er und stieß die Nahestehenden mit den Hörnern.
»Fort mit dir,« schrie nun die ganze Herde. »Du hast kein Recht
auf uns, nur weil du alt bist! Gehe zu Pferd, Baum und Stein und
lerne von ihnen, wie man sich Liebe erwirbt.« Und sie ließen den
Bock stehen und rannten leichtfüßig hinauf in die Berge, in die
Sonne, zu duftendem Tymian und Vergißmeinnicht.
Vom bescheidenen Hähnchen

»Frau Mutter, wir möchten uns ein wenig in der Welt umsehen,«
sagte das jüngste Hähnchen zu der Henne.
»Ja, das möchten wir,« sagte auch das älteste.
»Was heutzutage die Kinder nicht alles wollen!« Die Henne
schüttelte den Kopf. »So geht! Ihr werdet bald genug wieder da
sein. Und was ich sagen wollte: Seid ja recht bescheiden und drängt
euch nirgends vor. Das können die Erwachsenen nicht leiden.«
Die Hähnchen machten sich eilends davon und krähten heiser und
vergnügt in die Welt hinaus. Die Henne sah ihnen nach.
»Um den Ältesten ist mir nicht bange,« sagte sie zum Hahn, »aber
der Jüngste.«
»Jugend hat keine Tugend,« bedeutete sie der Hahn.
Die Hähnchen zogen über das Feld, und das jüngste wurde
hungrig.
»Hast du etwas zu essen?« fragte es seinen Bruder.
»Nein,« sagte der Älteste; »aber da kriecht eine fette Raupe.«
»Danke!« sagte das Jüngste, und fraß sie auf. Verblüfft sah der
andere zu.
»Eigentlich hätte sie mir gehört. Ich habe sie zuerst gesehen.«
»Aber ich habe sie zuerst gefressen,« sagte ruhig das Hähnchen.
Sie liefen weiter und liefen manchen Tag, und die Welt hatte
immer noch kein Ende. Es wurde ihnen fast unheimlich zumute.
»Ich wollte, ich wäre wieder daheim bei der Frau Mutter!« sagte
das Älteste.
»Das glaube ich!« lachte der Fuchs, der plötzlich vor ihnen stand.
»Welches von euch beiden möchte nun zuerst gefressen werden?«
»Bitte, Herr Fuchs, ich warte gerne,« sagte das jüngste Hähnchen
bescheiden.
Da packte der Fuchs den Ältesten und zerriß ihn. Das Jüngste aber
lief über das Feld heimwärts, so schnell es konnte. Es rannte und
flog und krähte, bis es endlich bei seiner Mutter war.
»Frau Mutter,« schrie es schon von weitem, »oh, wie recht haben
Sie gehabt. Bescheidenheit ist eine schöne Sache.«
»So,« sagte die Henne und sah ihren Jüngsten mißtrauisch an,
»und wo hast du denn deinen Bruder?«
»Den hat der Fuchs gefressen, Frau Mutter. Und hätte ich nicht
auf Sie gehört und mich unbescheiden vorgedrängt, so hätte die
Sache schief ablaufen können.«
Das neue Buch

Es war einmal ein alter Uhu, der nicht mehr auf die Jagd gehen
konnte, und sich von seinen Söhnen füttern lassen mußte. Da dachte
er, daß er ein Buch schreiben wolle, und zwar ein Buch, in dem man
sehen konnte, wie es in der Welt zugehe. Er wollte es drucken lassen
für die Schulkinder.
Er ließ seine drei Freunde kommen: Den Maulwurf, den Hahn und
die Schwalbe; die sollten ihm berichten, was sie von der Welt
wüßten.
Es waren Leute, die viel erfahren hatten, zudem wichen sie nie
von der Wahrheit ab, und dem Uhu lag besonders viel daran, daß in
dem Buch nur die reine Wahrheit gesagt würde.
Sie begaben sich zusammen an den Rand des nächsten Waldes,
um ungestört verhandeln zu können. Der Uhu saß im Stamm einer
alten, hohlen Eiche, der Hahn ging gravitätisch davor auf und ab und
der Maulwurf grub sich ein Loch, aus dem er nur den Kopf
herausstreckte. Die Schwalbe aber flog auf den untersten Zweig des
Baumes, unter dem sie beraten wollten.
Der Uhu nahm sein Notizbuch, spitzte seinen Bleistift, und bat den
Maulwurf anzufangen. Der setzte sich in Positur und begann:
»Die Welt ist dunkel.«
»Dunkel?« fragte die Schwalbe verwundert.
»Ja, dunkel,« antwortete der Maulwurf bestimmt. »Dunkel und
eng. Lange, schmale Gänge durchziehen sie, in denen man bequem
gehen kann. Man macht die Gänge selbst, und hat viel Arbeit damit.
Nahrung gibt es in Menge. Die Tiere besitzen alle einen schwarzen
samtnen Pelz.«
»Einen schwarzen Pelz!« rief der Hahn. »Was für ein Unsinn!«
»Jawohl, einen schwarzen Pelz! Es gibt auch Maulwürfe, die einen
weißen Pelz haben. Aber zum Glück sind sie sehr selten. Man
verachtet sie, weil sie nicht sind wie alle andern.«
Der Uhu schrieb alles, was der Maulwurf gesagt, in sein Notizbuch.
Zu einigen Mitteilungen machte er Bemerkungen. Er sagte aber
nichts, sondern fragte höflich den Maulwurf, ob er noch etwas
mitzuteilen habe.
»O ja,« sagte der Maulwurf, »die Hauptsache! In der Welt ist es
sehr langweilig. Ein Tag ist wie der andere, und man hat nur zwei
Zerstreuungen. Die eine ist das Essen. Die andere ist, daß man alle
anderen Tiere über die Achsel ansieht, die nicht in der Welt wohnen
und nicht leben wie die Maulwürfe. Und das ist die feinste Freude für
einen Maulwurf.«
Der Uhu notierte alles. Darauf bat er den Hahn, nun auch seine
Erfahrungen mitzuteilen.
»Die Welt,« begann der Hahn, »ist meistens eine lustige Sache.
Genug zu essen, genug zu trinken und Hühner, soviel man will!«
»Soviel man will!« stöhnte entsetzt der Maulwurf.
»Jawohl! Soviel man will! Die Welt ist viereckig und hat einen
Zaun aus Draht rings herum. Die Welt hat ein Licht am Himmel,
dann ist es warm. Manchmal fallen aber weiße Fetzen vom Himmel
und dann ist es kalt.«
»Weiße Fetzen?« fragte erstaunt die Schwalbe.
»Ja, und wenn die herabfallen, wird die ganze Welt weiß davon.
Kein Tier legt dann Eier. Es gibt in der Welt jemand, der einem alle
Tage Futter bringt. In der Welt haben die Tiere Federn und einen
roten Kamm.«
»Einen Kamm?« riefen Maulwurf und Schwalbe. »Das ist nicht
wahr.«
»So! Nicht wahr!« krähte heftig der Hahn. »Ich habe doch einen,
und unsere Kücken haben einen, wenn sie zur Welt kommen, meine
Hühner haben einen, und dann: nicht wahr! Jedes Wort ist wahr, das
ich sage! Ich habe alles selbst beobachtet, ich lebe mitten in der
Welt und betrachte sie von morgens bis abends.«
Der Uhu bat höflich den Hahn, sich nicht zu ärgern. Es zweifle
niemand an der Wahrheit seiner Behauptungen, nur nehme eben
nicht jedes denselben Standpunkt ein. Da gebe es dann leicht
Differenzen.
»Das Schönste in der Welt,« fuhr der Hahn besänftigt fort, »ist der
Misthaufen. Das ist eine wahre Fundgrube. Würmer, Käfer, Körner,
kurz alles, was man sich wünschen kann, ist vorhanden. Das ist eine
Lust, wenn alle da kratzen und scharren, picken und gackern, und
nie fühlt man sich so als Mann, als wenn man auf seinem Mist steht
inmitten seiner Hühner und stolz in die Welt hinauskräht.«
Ganz ergriffen hörte der Uhu zu. Zu der letzten Bemerkung des
Hahns machte er ein Kreuz, damit er sie besonders sorgfältig
ausarbeite.
Dann bat er die Schwalbe, nun auch ihre Beobachtungen und
Erlebnisse zum besten zu geben.
»Die Welt,« fing die Schwalbe an, »ist unendlich groß. Sie besteht
aus Meeren und Ländern, aus Bergen und Tälern. Das Schönste in
der Welt ist, wie ein Pfeil die Luft zu durchmessen, von einem Land
ins andere, Meere zu überfliegen und seine Brust dem Sturme
preiszugeben.«
»Ein gräßliches Vergnügen!« wimmerte der Maulwurf, und der
Hahn und der Uhu schüttelten ihre Köpfe. Der Uhu fragte nicht
weiter. Es kam ihm gar zu phantastisch vor, was die Schwalbe
erzählte, gar zu unwahrscheinlich und übertrieben. Jedenfalls würde
er sich in seinem Buch mehr an die beiden andern halten.
Der Uhu dankte den Dreien sehr für die nützlichen Mitteilungen,
und versprach jedem ein Exemplar des Buches, wenn es erscheinen
würde. Er sagte, daß die Ansichten der drei Freunde weit
auseinander gingen, daß aber, da alle drei ehrenwerte Leute seien,
an ihrem Worte nicht zu zweifeln sei. Er werde alles sorgfältig prüfen
und aus allen Darstellungen dasjenige nehmen, was ihm für die
Kinder das Passendste scheine.
Nach einigen Monaten kam das Buch für die Schulkinder heraus.
Lehrer Storch las in der Schule daraus vor. Es hieß da:
Die Welt ist dunkel. Oft ist eine Sonne da, doch scheint sie nicht
immer. Wenn sie scheint, sehen sie nicht alle.
In der Welt haben die Tiere einen Kamm, manchmal aber einen
schwarzen Pelz. Die Welt ist unendlich groß, und alles ist mit einem
Zaun umgeben. Sie ist viereckig.
Das Schönste in der Welt ist der Misthaufen. Einige fliegen darüber
weg und geben ihre Brust dem Sturme preis, die meisten aber
krähen und suchen Würmer.
In der Welt sind enge, dunkle Gänge und darinnen verachtet man
die andern Tiere. In der Welt ist es sehr langweilig, manchmal auch
lustig, besonders wenn man Hühner hat, soviel man will und genug
zu essen.
Viele Tiere sehen Flocken vom Himmel fallen, andere sehen sie
nie.
In der Welt bringt jemand den Tieren Futter ... usw.
Als der Storch fertig vorgelesen hatte, mußten die Kinder es
durchbuchstabieren, und dann mußten sie es auswendig lernen.
Der Uhu hatte es sich lange überlegt, welche der verschiedenen
Ansichten der Tiere er bringen wolle, denn sie stimmten ja durchaus
nicht überein. Er wollte keinen seiner Freunde ärgern, indem er
etwas wegließ, auch war ihm alles gleich wertvoll und schien ihm
unentbehrlich für sein Buch.
Zuletzt fand er einen Ausweg. Er machte Zettelchen, schrieb
sämtliche Beobachtungen von Maulwurf, Hahn und Schwalbe einzeln
darauf, warf sie dann in eine Schüssel, schüttelte sie tüchtig und fing
an zu ziehen. Den ersten Zettel, den er zog, gebrauchte er für das
Buch, den zweiten nicht, den dritten wieder für das Buch, den
vierten nicht, und so weiter, bis er den letzten gezogen hatte.
Das war gerecht und einfach und konnte ihm keinerlei
Unannehmlichkeiten zuziehen. Und so entstand das Buch.
Der Storch stattete dem Uhu einen Besuch ab und dankte ihm
begeistert im Namen der heranwachsenden Jugend für das
interessante Werk.
Die lieben Nachbarn

»Habt ihr es schon gehört, der Nachbar von nebenan will eine
Stadtmaus heiraten!« sagte eine Feldmaus zu ihren Besucherinnen.
Sie glättete ihr braunes Pelzlein und ringelte zierlich den Schwanz.
»Eine Stadtmaus? Doch nicht die Weiße mit den roten Augen, die
neulich hier auf Besuch war?«
»Gerade die!«
»Jetzt hört aber doch alles auf!« jammerte eine der drei, eine
fette braune Feldmaus. »Also die Weiße! Nun, der Nachbar kann sich
gratulieren!«
»Warum? Was wissen Sie von der weißen Maus?« schrien
aufgeregt die andern.
»Ich weiß nichts, und ich sage nichts; aber denken tue ich mein
Teil.«
»Woher wissen Sie es, Frau Feldmausin?« fragten die drei und
rückten näher zusammen.
»Das darf ich nicht sagen. Aber die Person, die es mir mitteilte, ist
zuverlässig, durchaus zuverlässig. Wenn das unser Nachbar wüßte!
Der würde sich schwer hüten, so eine zu heiraten.«
»Man sollte ihn warnen,« riefen alle; »das ist beinahe unsere
Pflicht!«
»Jawohl, es ist eigentlich unsere Pflicht!« Alle nickten mit den
Köpfen und sahen sich bedeutungsvoll an. Es glänzte
unternehmungslustig in den beerenschwarzen Äuglein. Und die vier
machten sich eilig auf, und gingen zum Nachbarn hinüber.
»Herr Nachbar, wir kommen in einer delikaten Angelegenheit.«
»Liebe Freundinnen, ihr kommt gewiß, um mir zu gratulieren. Es
ist ja kein Geheimnis mehr, gar nicht.« Die vier lächelten sauersüß
und wünschten Glück.
»Meine Braut ist reizend,« rief der Verliebte. Die vier nickten.
»Das ist sie, gewiß; dagegen ist nichts zu sagen.«
»Und tugendhaft,« betonte nochmals der Nachbar.
Die langen Schnurrbarthaare der Feldmäuse zitterten vor
Erwartung.
»Jetzt!« sagte leise die eine, und stieß ihre Nachbarin an, damit
sie reden solle.
»Herr Nachbar,« begann die Fette und räusperte sich, »es ist
leider unsere Pflicht, Ihnen mitzuteilen, daß Ihre Braut ...«
»Daß meine Braut?«
»Das Lob, tugendhaft zu sein, nicht ganz verdient.«
»So,« sagte der Nachbar, »was wissen Sie denn von ihr?« Die
fette Maus kam etwas aus der Fassung: Der Bräutigam blieb gar zu
gelassen.
»Sie ist ... sie hatte ... kurz, man hat sie mit einer braunen Maus
im Mondschein spazieren sehen!« Erleichtert setzte sich die
Feldmaus; es war eben keine Kleinigkeit, einem Bräutigam so etwas
zu sagen.
»So!« sagte der Nachbar.
»So! So, sagen Sie, Herr Nachbar? Und mit diesen Grundsätzen
wollen Sie in die Ehe treten? Bei so etwas bleiben Sie gelassen? Die
beiden haben sich nämlich auch geküßt!« Triumphierend sah die
Feldmaus im Kreise herum.
Der Nachbar lachte. Da erhoben sich alle vier würdevoll.
»Wir haben unsere Pflicht getan,« sagten sie. »Das Weitere ist
Ihre Sache!« Steif wandten sie sich zum Gehen, ihre Schwänzchen
fuhren aufgeregt hin und her. Sie waren schwer enttäuscht. »Wir
bedauern gestört zu haben!«
»Gar nicht, aber gar nicht!« rief der Nachbar. »Die große,
dunkelbraune Maus bin ich nämlich selber gewesen. Übrigens lade
ich Sie alle zur Hochzeit ein.«
Und er öffnete die Türe und machte eine tiefe Verbeugung ...
Welcome to Our Bookstore - The Ultimate Destination for Book Lovers
Are you passionate about books and eager to explore new worlds of
knowledge? At our website, we offer a vast collection of books that
cater to every interest and age group. From classic literature to
specialized publications, self-help books, and children’s stories, we
have it all! Each book is a gateway to new adventures, helping you
expand your knowledge and nourish your soul
Experience Convenient and Enjoyable Book Shopping Our website is more
than just an online bookstore—it’s a bridge connecting readers to the
timeless values of culture and wisdom. With a sleek and user-friendly
interface and a smart search system, you can find your favorite books
quickly and easily. Enjoy special promotions, fast home delivery, and
a seamless shopping experience that saves you time and enhances your
love for reading.
Let us accompany you on the journey of exploring knowledge and
personal growth!

ebookgate.com

You might also like