0% found this document useful (0 votes)
15 views52 pages

D3.js in Action: Data visualization with JavaScript 2nd Edition Elijah Meeks download

D3.js in Action, Second Edition by Elijah Meeks is a comprehensive guide to data visualization using JavaScript and the D3.js library. The book covers fundamental concepts, data-driven design, and advanced techniques for creating interactive visualizations. It includes practical examples, project architecture, and insights into real-world applications of D3.js.

Uploaded by

bsgehioa3549
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 views52 pages

D3.js in Action: Data visualization with JavaScript 2nd Edition Elijah Meeks download

D3.js in Action, Second Edition by Elijah Meeks is a comprehensive guide to data visualization using JavaScript and the D3.js library. The book covers fundamental concepts, data-driven design, and advanced techniques for creating interactive visualizations. It includes practical examples, project architecture, and insights into real-world applications of D3.js.

Uploaded by

bsgehioa3549
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/ 52

D3.

js in Action: Data visualization with


JavaScript 2nd Edition Elijah Meeks download

https://textbookfull.com/product/d3-js-in-action-data-
visualization-with-javascript-2nd-edition-elijah-meeks/

Download full version ebook from https://textbookfull.com


We believe these products will be a great fit for you. Click
the link to download now, or visit textbookfull.com
to discover even more!

D3 js in Action Data visualization with JavaScript


Second Edition Elijah Meeks

https://textbookfull.com/product/d3-js-in-action-data-
visualization-with-javascript-second-edition-elijah-meeks/

Data Visualization with d3 js 1st Edition Teller Swizec

https://textbookfull.com/product/data-visualization-
with-d3-js-1st-edition-teller-swizec/

Learning d3 js Data Visualization Ændrew Rininsland

https://textbookfull.com/product/learning-d3-js-data-
visualization-aendrew-rininsland/

Fullstack D3 and Data Visualization Build Beautiful


Data Visualizations and Dashboards with D3 Amelia
Wattenberger

https://textbookfull.com/product/fullstack-d3-and-data-
visualization-build-beautiful-data-visualizations-and-dashboards-
with-d3-amelia-wattenberger/
Data Visualization with D3 4 x Cookbook Nick Zhu

https://textbookfull.com/product/data-visualization-
with-d3-4-x-cookbook-nick-zhu/

Interactive Data Visualization for the Web An


Introduction to Designing with D3 2nd Edition Scott
Murray

https://textbookfull.com/product/interactive-data-visualization-
for-the-web-an-introduction-to-designing-with-d3-2nd-edition-
scott-murray/

Source Code Analytics With Roslyn and JavaScript Data


Visualization Mukherjee

https://textbookfull.com/product/source-code-analytics-with-
roslyn-and-javascript-data-visualization-mukherjee/

Interactive Data Visualization for the Web An


Introduction to Designing with D3 1st Edition Murray

https://textbookfull.com/product/interactive-data-visualization-
for-the-web-an-introduction-to-designing-with-d3-1st-edition-
murray/

Pro D3.js: Use D3.js to Create Maintainable, Modular,


and Testable Charts Marcos Iglesias

https://textbookfull.com/product/pro-d3-js-use-d3-js-to-create-
maintainable-modular-and-testable-charts-marcos-iglesias/
Elijah Meeks

Data visualization with JavaScript

SECOND EDITION

MANNING
Praise for the First Edition

Quickly gets you coding amazing visualizations.


—Ntino Krampis, PhD
City University of New York

A remarkable exploration of the world of dataviz possibilities with D3.


—Arun Noronha
Directworks

One of the most comprehensive books about data visualization I have ever read.
—Andrea Mostosi
The Fool s.r.l.

This book is required reading for anyone looking to get using D3. A mandatory
introduction to a very complex and powerful library.
—Stephen Wakely
Thomson Reuters

Excellent guide which handholds the reader for fast-tracking D3.js expertise effectively.
—Prashanth Babu
NTT DATA

A remarkable exploration into the world of data viz possibilities with D3.
—Arun Noronha
Directworks

I found this book to be inspiring!


—M.B., Amazon reader

A must-have book.
—Arif Shaikh
Sony Pictures Entertainment
D3.js in Action
Second Edition
DATA VISUALIZATION WITH JAVASCRIPT

ELIJAH MEEKS

MANNING
SHELTER ISLAND
For online information and ordering of this and other Manning books, please visit
www.manning.com. The publisher offers discounts on this book when ordered in quantity.
For more information, please contact
Special Sales Department
Manning Publications Co.
20 Baldwin Road
PO Box 761
Shelter Island, NY 11964
Email: [email protected]

©2018 by Manning Publications Co. All rights reserved.

No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in


any form or by means electronic, mechanical, photocopying, or otherwise, without prior written
permission of the publisher.

Many of the designations used by manufacturers and sellers to distinguish their products are
claimed as trademarks. Where those designations appear in the book, and Manning
Publications was aware of a trademark claim, the designations have been printed in initial caps
or all caps.

Recognizing the importance of preserving what has been written, it is Manning’s policy to have
the books we publish printed on acid-free paper, and we exert our best efforts to that end.
Recognizing also our responsibility to conserve the resources of our planet, Manning books
are printed on paper that is at least 15 percent recycled and processed without the use of
elemental chlorine.

Manning Publications Co. Development editor: Susanna Kline


20 Baldwin Road Technical development editor: James Womack
PO Box 761 Project editors: Kevin Sullivan and Janet Vail
Shelter Island, NY 11964 Copyeditor: Katie Petito
Proofreader: Corbin Collins
Technical proofreader: Jon Borgman
Typesetter: Dottie Marsico
Cover designer: Marija Tudor

ISBN 9781617294488
Printed in Canada
1 2 3 4 5 6 7 8 9 10 – TC – 22 21 20 19 18 17
contents
preface xi
acknowledgments xiii
about this book xiv
about the cover illustration xvii

PART 1 D3.JS FUNDAMENTALS ....................................... 1

1 An introduction to D3.js 3
1.1 What is D3.js? 4
1.2 How D3 works 4
Data visualization is more than charts 4 D3 is about selecting

and binding 9 D3 is about deriving the appearance of web page


elements from bound data 10 Web page elements can now be


divs, countries, and flowcharts 11


1.3 The power of HTML5 11
The DOM 12 Coding in the console 16 SVG 17
■ ■

CSS 24 JavaScript 28 ES2015 and Node 33


■ ■

1.4 Data standards 34


Tabular data 34 Nested data 35 Network data
■ ■
35
Geographic data 36 Raw data 37 Objects 37
■ ■

1.5 Infoviz standards expressed in D3 38

v
1.6 Your first D3 app 39
Hello world with divs 40 Hello World with circles

41
A conversation with D3 42
1.7 Summary 44
Why learn D3? 45

2 Information visualization data flow 47


2.1 Working with data 48
Loading data 49 Formatting data

52 ■
Further modifying
data 54 Measuring data 59

2.2 Data-binding 60
Selections and binding 60 Accessing data with inline

functions 63 Integrating scales 65


2.3 Data presentation style, attributes, and content 68


Visualization from loaded data 68 ■
Setting channels 70
Enter, update, merge, and exit 72
2.4 Summary 77

3 Data-driven design and interaction 78


3.1 Project architecture 79
Data 79 Resources

80 ■
Images 80 ■
Style sheets 80
External libraries 81
3.2 Interactive style and DOM 83
Events 83 Graphical transitions 85 DOM
■ ■

manipulation 87 Using color wisely 90


3.3 Pregenerated content 97


Images 97 ■
HTML fragments 98 ■
Pregenerated SVG 100
3.4 Summary 106
3.5 D3.js in the real world 107
Bocoup for Measurement Lab 107

4 Chart components 109


4.1 General charting principles 110
Generators 111 ■
Components 111 ■
Layouts 112
4.2 Creating an axis 112
Plotting data 112 ■
Styling axes 115
4.3 Complex graphical objects 117
CONTENTS vii

4.4 Line charts and interpolations 126


Drawing a line from points 127 Drawing many lines with ■

multiple generators 130 Exploring line interpolation 131


4.5 Complex accessor functions 132


4.6 Using third-party D3 modules to create legends 139
4.7 Summary 141

5 Layouts 143
5.1 Histograms 144
Drawing a histogram 144 ■
Interactivity 146 ■
Drawing
violin plots 147
5.2 Pie charts 149
Drawing the pie layout 150 ■
Creating a ring chart 151
Transitioning 152
5.3 Stack layout 154
5.4 Plugins to add new layouts 158
Sankey diagram 158 ■
Word clouds 165
5.5 Summary 170
5.6 D3.js in the real world 171
Adam Pearce ■
Graphics Editor, New York Times 171

PART 2 COMPLEX DATA VISUALIZATION ......................173

6 Hierarchical visualization 175


6.1 Hierarchical patterns 176
6.2 Working with hierarchical data 178
Hierarchical JSON and hierarchical objects 179
D3.nest 179 D3.stratify 180

6.3 Pack layouts 180


Drawing the circle pack 181 ■
When to use circle packing 184
6.4 Trees 184
Drawing a dendrogram 184 Radial tree diagrams 190 ■

d3.cluster vs d3.tree 192 When to use dendrograms 192


6.5 Partition 192


Drawing an icicle chart 192 Sunburst: radial icicle chart

194
Flame graph 196 When to use the partition layout 196

viii CONTENTS

6.6 Treemaps 197


Building 197 Filtering 198
■ ■
Radial treemap 200
When to use treemaps 200
6.7 Summary 201
6.8 D3.js in the real world 202
Nadieh Bremer ■
Data Visualization Consultant 202

7 Network visualization 204


7.1 Static network diagrams 205
Network data 206 ■
Adjacency matrix 209
Arc diagram 214
7.2 Force-directed layout 218
Playing with forces 219 Creating a force-directed network

diagram 221 SVG markers 223 Network measures 225


■ ■

Force layout settings 227 Updating the network 228


Removing and adding nodes and links 231 Manually ■

positioning nodes 235 Optimization 236


7.3 Summary 237


7.4 D3.js in the real world 238
Shirley Wu ■
Data Visualization Consultant 238

8 Geospatial information visualization 240


8.1 Basic mapmaking 242
Finding data 243 Drawing points on a map 248

Projections and areas 249 Interactivity 251 ■

8.2 Better mapping 253


Graticule 253 ■
Zoom 253
8.3 Advanced mapping 257
Creating and rotating globes 258 ■
Satellite projection 261
8.4 TopoJSON data and functionality 262
TopoJSON the file format 262 Rendering TopoJSON ■
262
Merging 264 Neighbors 266

8.5 Further reading for web mapping 267


Tile mapping 267 Transform zoom 267 Canvas
■ ■

drawing 268 Raster reprojection 268 Hexbins 268


■ ■

Voronoi diagrams 268 Cartograms 268 ■


CONTENTS ix

8.6 Summary 269


8.7 D3 in the real world 270
Philippe Rivière ■
journalist/programmer 270

PART 3 ADVANCED TECHNIQUES ................................273

9 Interactive applications with React and D3 275


9.1 One data source, many perspectives 276
9.2 Getting started with React 279
Why React, why not X? 279 ■
react-create-app: setting up
your application 280 ■
JSX 281
9.3 Traditional D3 rendering with React 282
9.4 React for element creation, D3 as the visualization
kernel 284
9.5 Data dashboard basics 286
9.6 Dashboard upgrades 292
Responsiveness 293 ■
Legends 294 ■
Cross-highlighting 295
9.7 Brushing 298
Creating the brush 298 ■
Understanding brush events 304
9.8 Show me the numbers 304
9.9 Summary 306
9.10 D3 in the real world 307
Elijah Meeks ■
Senior Data Visualization Engineer 307

10 Writing layouts and components 309


10.1 Creating a layout 310
Designing your layout 310 Implementing your layout 311

Testing your layout 312 Extending your layout 313


10.2 Writing your own components 318


10.3 Loading sample data 318
10.4 Linking components to scales 321
10.5 Adding component labels 326
10.6 Summary 328
10.7 D3.js in the real world 329
Susie Lu ■
Senior Data Visualization Engineer 329
x CONTENTS

11 Mixed mode rendering 330


11.1 Built-in canvas rendering with d3-shape generators 332
11.2 Big geodata 335
Creating random geodata 335 Drawing geodata with

canvas 339 Mixed mode rendering techniques 340


11.3 Big network data 345


11.4 Optimizing xy data selection with quadtrees 350
Generating random xy data 350 ■
xy brushing 351
11.5 More optimization techniques 355
Avoid general opacity 355 ■
Avoid general selections 355
Precalculate positions 356
11.6 Summary 356
11.7 D3 in the real world 358
Christophe Viau 358

index 360
preface
When I wrote the first edition of D3.js in Action, I did it mostly as a way to learn the
library. I knew D3 well enough to do cool things with it, but like many people, I didn’t
know the breadth and depth of it, nor did I really understand the structure of layouts
and generators and its other aspects. I agreed to write the book as a sort of graduate
school in D3, to become an expert in the library, and to become better at data visual-
ization more generally. I came at the second edition from a different perspective. I
knew D3 as well as most anyone could, and the changes from V3 to V4, while signifi-
cant, were straightforward enough to explain. But in the last two and a half years, I’ve
been a professional software developer, and I better understand where D3 sits in an
ecosystem of applications and libraries. This time I didn’t set out to write a book to
learn D3; this time I set out to write a book to teach people how to use D3, not only on
its own but in reference to other libraries and to JavaScript.
One of the things I want to teach now is how to create impactful data visualization
using D3 rather than pushing your limits on how to generate the most complex charts.
That doesn’t mean I don’t get into the ambitious data visualization methods that D3
allows—I still explore how to create network data visualization and geospatial maps
with D3—but it does mean the code and the text better reflect the needs of people
who want to learn how to make effective data visualization more than they want to
learn how to use D3.
That’s why the second edition has sections on D3.js in the real world written by
experts who’ve used D3 for analysis, storytelling, and journalism. That’s also why I
pulled out the extraneous bits from the first edition that showed you how to use D3
like JQuery, and replaced those with more in-depth analysis of how to create hierar-
chical data visualization and how to integrate D3 with popular frameworks.

xi
xii PREFACE

The code is much cleaner in the second edition, which is as much a result of my
own experience as it is a result of the advances in JavaScript in the last couple years.
Because I’ve grown more professional in my practice doesn’t mean I’ve grown less
ambitious in how I use D3 and how I think people should use D3. This is still a long
book, and it has to be because it’s an exhaustive look at the ins and outs of an import-
ant library in an exciting and fast-growing field.
acknowledgments
I’d like to thank my wife, Hajra, who always inspires me.
I’d also like to thank Manning Publications for a new opportunity to approach this
topic. Everyone says you don’t make much money off technical books, but the success
of the first edition of D3.js in Action was instrumental in advancing my career. Getting a
chance to revisit my old code and my old text and update it for the new version of the
library and the changes in the industry has been a boon. In the process, I was lucky
enough to work with the same editor, Susanna Kline, who has been as sharp and
insightful as she was before, and any success of this edition is in large part due to her.
I’d also like to thank the rest of the team at Manning who made this process as smooth
as it could possibly be.
The following reviewers provided feedback on the manuscript at various stages of
its development, and I thank them for their time and effort: Jonathan Rioux, Claudio
Rodriguez, Felipe Vildoso-Castillo, Rohit Sharma, Scott McKissock, Iain Shigeoka,
George Gaines, Michael Haller, Giancarlo Massari, Prashanth Babu, Piotr Kopszak,
and Nat Luengnaruemitchai. Thanks also to technical editor James Womack and
technical proofreader Jon Borgman for making me better at code and gently cor-
recting me over and over again.
Last, I’d like to thank Netflix, for its great culture, for the coworkers who have
pushed me and made me better at the practical and professional aspects of software
development, and specifically for letting me take off for a month to rewrite this book.

xiii
about this book
People come to data visualization, and D3 particularly, from three different areas. The
first is traditional JavaScript development, where they assume D3 is a charting library
or, less commonly, a mapping library. The second is more traditional software devel-
opment, such as Java, where D3 is part of the transition into frontend or node develop-
ment. The last area is a trajectory that involves statistical analysis using R, Python, or
desktop apps.
For all these folks, D3 represents a transition into two major new areas: web develop-
ment and data visualization. I touch on aspects of both that may give readers more
grounding in what I expect to be new and strange fields. Someone who’s intimately
familiar with JavaScript may find that many of these subjects are already well understood,
and others who know data visualization may well feel the same way about several of the
general principles, such as graphical primitives.
Although I do provide an introduction to D3, the focus of this book is on a more
exhaustive explanation of key principles of the library. Whether you’re getting started
with D3 or looking to develop more advanced skills, this book provides you with the tools
you need to create whatever data visualization you can think of.

Roadmap
This book is split into three parts. The first three chapters focus on the fundamen-
tals of D3 and data visualization generally. You’ll see data-binding, loading data, and
creating graphical elements from data in a variety of different ways. It also deals
with scales, color, and other important aspects of data visualization. Some of the
core technologies used by D3, such as JavaScript, CSS, and SVG, are explained through-
out these chapters.

xiv
ABOUT THIS BOOK xv

The next four chapters use D3 in the ways we typically think of. Chapter 4 teaches
you how to create simple graphics from data, such as line charts, axes, and boxplots.
Chapter 5 gives an in-depth exploration of various traditional data visualization lay-
outs such as pie charts, violin plots, and histograms as well as more exotic charts such
as Sankey diagrams and word clouds. Chapter 6 is devoted to hierarchical data visual-
izations such as treemaps and dendrograms, suitable for nested data such as organiza-
tional charts or economic sectors of the stock market. Chapter 7 focuses on network
data visualization, which might seem exotic, but is being used more and more in a
variety of domains. Chapter 8 dives into the rich mapping capabilities in D3, and
includes using TopoJSON to do interesting geodata manipulation in the browser.
The last three chapters cover topics that can be considered deep dives into D3.
Chapter 9 focuses on integrating D3 into another framework, in this case the popular
React library. Chapter 10 teaches you about creating your own D3 layouts and compo-
nents. Chapter 11 is all about optimizing data visualization for large datasets. Even if
you don’t think you’ll ever use D3 in these ways, each of these chapters still touches on
key aspects of using D3.

How to use this book


If you’re getting started with D3, I suggest going through chapters 1 through 4 in order.
Each chapter builds on its predecessor and establishes the basic principles not only of D3
but also of data visualization. After that, it depends on what you plan to use D3 for. If
your data is mostly geographic, then you can jump to chapter 8. If your data is mostly
network data, you can jump to chapter 7. If you’re doing traditional data visualization,
then I suggest going to chapters 5 and 6 and then on to chapter 9 to start thinking about
dashboards, which are a key component of traditional data visualization.
If you’ve been using D3 for a while and want to improve your skills, I suggest skim-
ming the first three chapters. The parts that I think might be of particular interest are
in chapter 3, and deal with color and loading external resources such as SVG icons or
HTML content. You might also want to review generators and components in chap-
ter 4 to fill in any gaps you might have dealing with these common, but often under-
examined, parts of D3. After that, it depends on what you see as your strengths and
goals for using D3. If you want to maximize traditional data visualization, look at
chapters 5 and 6 to see the layouts, and then look at chapter 9 for dashboards in a
modern JavaScript development environment. If you’re familiar with most of the
content there, look at chapter 11 for optimization techniques you might want to
bring into your data visualization, or look at chapter 10 and think about how you
might use the D3 tricks you know to build new layouts or reusable components.
Much of the value of this book comes in chapters 7 and 8, which go into great
detail about using D3 for two major areas of data visualization: networks and maps.
Along those lines, the use of HTML5 canvas in chapter 11 is an area that even experi-
enced D3 developers might not be familiar with.
xvi ABOUT THIS BOOK

Regardless of your level of experience with D3, I recommend you spend time with
chapter 10, which deals with the structure of layouts and components while showing
you how to build your own. Beginning to build modular, reusable components and
layouts will allow you to create not only effective data visualization, but also an effec-
tive career in visualizing data.

Code conventions
Initial code examples in chapters are complete, with later code examples that extend
an initial example only showing the code that has changed. It’s best to use the source
code and online examples alongside the text. The line lengths of some of the exam-
ples exceed the page width, and in cases like these, the ➥ marker is used to indicate
that a line has been wrapped for formatting.
All source code in listings or in text is in a fixed-width font like this to separate it
from ordinary text. Code annotations accompany many of the listings, highlighting
important concepts.

Source code downloads


The source code for the examples in this book is available for download from www.manning
.com/books/d3js-in-action-second-edition and is also online at https://github.com/
emeeks/d3_in_action_2.

Software requirements
D3.js requires a browser to run, and you should have a local web server installed on
your computer to host your code. The environment I develop in is macOS, so several
of the screenshots or commands may not apply in a Windows environment.

Book forum
Purchase of D3.js in Action, Second Edition includes free access to a private web forum
run by Manning Publications where you can make comments about the book, ask
technical questions, and receive help from the author and from other users. To access
the forum, go to https://forums.manning.com/forums/d3js-in-action-second-edition.
You can also learn more about Manning’s forums and the rules of conduct at
https://forums.manning.com/forums/about.
Manning’s commitment to our readers is to provide a venue where a meaningful
dialogue between individual readers and between readers and the author can take
place. It’s not a commitment to any specific amount of participation on the part of the
author, whose contribution to the forum remains voluntary (and unpaid). We suggest
you try asking the author some challenging questions lest his interest stray! The forum
and the archives of previous discussions will be accessible from the publisher’s website
as long as the book is in print.
about the cover illustration
The figure on the cover of D3.js in Action, Second Edition is captioned “Habit of a Moor-
ish Pilgrim Returning from Mecca in 1586.” The illustration is taken from Thomas Jef-
ferys’ A Collection of the Dresses of Different Nations, Ancient and Modern (four volumes),
London, published between 1757 and 1772. The title page states that these are hand-
colored copperplate engravings, heightened with gum arabic. Thomas Jefferys (1719–
1771) was called “Geographer to King George III.” He was an English cartographer
who was the leading map supplier of his day. He engraved and printed maps for gov-
ernment and other official bodies and produced a wide range of commercial maps
and atlases, especially of North America. His work as a mapmaker sparked an interest
in local dress customs of the lands he surveyed and mapped, an interest that’s bril-
liantly displayed in this four-volume collection.
Fascination with faraway lands and travel for pleasure were relatively new phenom-
ena in the late eighteenth century, and collections such as this one were popular,
introducing both the tourist as well as the armchair traveler to the inhabitants of
other countries. The diversity of the drawings in Jefferys’ volumes speaks vividly of the
uniqueness and individuality of the world’s nations some 200 years ago. Dress codes
have changed since then, and the diversity by region and country, so rich at the time,
has faded away. It’s now often hard to tell the inhabitant of one continent from
another. Perhaps, trying to view it optimistically, we’ve traded a cultural and visual
diversity for a more varied personal life, or a more varied and interesting intellectual
and technical life.
At a time when it’s hard to tell one computer book from another, Manning cele-
brates the inventiveness and initiative of the computer business with book covers
based on the rich diversity of regional life of two centuries ago, brought back to life by
Jeffreys’ pictures.

xvii
Part 1

D3.js fundamentals

T he first three chapters introduce you to the fundamental aspects of D3 and


get you started with creating graphical elements in SVG using data. Chapter 1
lays out how D3 relates to the DOM, HTML, CSS, and JavaScript, and provides a
few examples of how to use D3 to create elements on a web page. Chapter 2
focuses on loading, measuring, processing, and transforming your data in prepa-
ration for data visualization using the various functions D3 includes for data
manipulation. Chapter 3 turns toward design and explains how you can use D3
color functions for more effective data visualization, as well as load external ele-
ments such as HTML for modal dialogs or icons in raster and vector formats.
Chapter 4 deals with the fundamental usage of D3.js to create individual chart
components with an emphasis on generating scatterplots and line charts. Chap-
ter 5 shows off the basic data visualization layouts that you’ll need to create com-
mon data visualization products such as pie charts and bar charts. In all, part 1
shows you how to load, process, and visually represent data in SVG without rely-
ing on built-in layouts or components, which is critical for visualizing data.
This chapter covers
An introduction to D3.js

 The basics of HTML, CSS, and the Document


Object Model (DOM)
The principles of Scalable Vector Graphics (SVG)
1
 Node and ES2015 functionality
 Data-binding and selections with D3
 Different data types and their data visualization
methods

D3 is behind nearly all the most innovative and exciting information visualization
on the web today. D3 stands for data-driven documents. It’s a brand name, but also a
class of applications that have been offered on the web in one form or another for
years. In my career, I’ve made many things that could be considered data-driven
documents. These include everything from one-off dynamic maps or social net-
work diagrams to robust visual explorations of time and place. You’ll be using D3
whether you’re building data visualization prototypes for research or big data dash-
boards at the top tech companies.

3
4 CHAPTER 1 An introduction to D3.js

1.1 What is D3.js?


D3.js was created to fill a pressing need for web-accessible, sophisticated data visualiza-
tion. Let’s say your company has used Business Intelligence tools for a while, but they
don’t show you the kind of patterns in the data that your team needs. You need to
build a custom dashboard that shows exactly how your customers are behaving, tai-
lored for your specific domain. That dashboard needs to be fast, interactive, and
shareable around the organization. You’re going to use D3 for that.
D3.js’s creator, Mike Bostock, originally created D3 to take advantage of emerging
web standards, which, as he puts it, “avoids proprietary representation and affords
extraordinary flexibility, exposing the full capabilities of web standards such as CSS3,
HTML5, and SVG” (http://d3js.org). D3.js version 4, the latest iteration of this popular
library, continues this trend by modularizing the various pieces of D3 to make it more
useful in modern application development.
D3 provides developers with the ability to create rich interactive and animated con-
tent based on data and tie that content to existing web page elements. It gives you the
tools to create high-performance data dashboards and sophisticated data visualiza-
tion, and to dynamically update traditional web content.
You might have already experimented with D3 and found that it isn’t easy to get
into. Maybe that’s because you expected it to be a simple charting library. A case in
point is the pie chart layout, which you’ll see in chapter 5. D3 doesn’t have one single
function to create a pie chart. Rather, it has a function that processes your dataset with
the necessary angles so that if you pass the dataset to D3’s arc function, you get the
drawing code necessary to represent those angles. And you need to use yet another
function to create the paths necessary for that code. It’s a much longer process than
using dedicated charting libraries, but the explicit manner in which D3 deals with
data and graphics is also its strength. Although other charting libraries conveniently
allow you to make line graphs and pie charts, they quickly break down when you want
to make something different than that. Not D3, which allows you to build whatever
data-driven graphics and interactivity you can imagine.

1.2 How D3 works


Let’s look at the principles of data visualization, as well as how D3 works in general. In
figure 1.1 you see a rough map of how you might start with data and use D3 to process
and represent that data, as well as add interactivity and optimize the data visualization
you’ve created. In this chapter, we’ll start by establishing the principles of how D3
selections and data-binding work and learning how D3 interacts with SVG and HTML
in the DOM. Then we’ll look at data types that you’ll commonly encounter. Finally,
we’ll use D3 to create simple DOM and SVG elements.

1.2.1 Data visualization is more than charts


You may think of data visualization as limited to pie charts, line charts, and the variety
of charting methods popularized by Edward Tufte and deployed in research. It’s
much more than that. One of the core strengths of D3.js is that it allows for the
How D3 works 5

Data Load data


01101011 (chapters 2 and 3)
00011101
11011010
01010101
10110101 Process data
10101111 (chapter 2)

Generate Bind data


a dataset (chapter 2)
(chapter 11)

Charts

Design Basic Hierarchical Networks Maps


(chapter 3) charting layouts (chapter 7) (chapter 8)
(chapters 2–5) (chapter 6)

Interactivity basics
(chapter 2)

Interactivity

Mouse events Brush filtering MVC dashboard Extending D3


(chapters 2–12) (chapters 9 and 11) (chapter 9) (chapter 10)

Zoom
(chapters 5 and 7)
Optimization
(chapter 11)

Figure 1.1 A map of how to approach data visualization with D3.js that highlights the approach in this
book. Start at the top with data and then follow the path depending on the type of data and the needs
you’re addressing.

creation of vector graphics for traditional charting, but also the creation of geospatial
and network visualizations, as well as rich animation and interactivity. This broad-
based approach to data visualization, where a map or a network graph or a table is
another kind of representation of data, is the core of the D3.js library’s appeal for
application development.
6 CHAPTER 1 An introduction to D3.js

Figures 1.2 through 1.8 show


data visualization pieces that I’ve
created with D3. They include
maps and networks, along with
more traditional pie charts and
completely custom data visual- Figure 1.2 D3 can be
ization layouts based on the spe- used for simple charts,
such as this donut chart
cific needs of my clients.
(explained in chapter 5).

Figure 1.3 D3 can also be


used to create web maps (see
chapter 8), such as this map
showing the ethnic makeup of
major metropolitan areas in the
United States.

Figure 1.4 Maps in D3 aren’t limited to


traditional Mercator web maps. They can be
interactive globes, like this map of undersea
communication cables, or other, more
unorthodox maps (see chapter 8).
How D3 works 7

Figure 1.5 D3 also provides robust


capacities to create interactive
network visualizations (see chapter 7).
Here you see the social and
coauthorship network of
archaeologists working at the same
dig for nearly 25 years.

Figure 1.6 D3 includes a library of common data visualization layouts, such as the dendrogram (explained in
chapter 6), that let you represent data, such as this word tree.
Another Random Scribd Document
with Unrelated Content
the two contraries; which is done by the will. Now, God, as we know,
causes all things through his understanding, for his understanding is
his being; and, therefore, his science, as united with his will, must
be the cause of all things."[184]
It might be here objected that if, for the reason just alleged,
archetypal ideas are not to be considered a distinct principle of
creation, then neither can omnipotence be considered as a distinct
principle; for as archetypal ideas do not principiate anything unless
through free volition, so, also, omnipotence principiates nothing but
in consequence of the same volition; and, therefore, if archetypal
ideas on this account are not a distinct principle of things, on the
same account omnipotence cannot be taken as a distinct principle.
To this we answer that the assumed parity has no legs to stand on.
That archetypal ideas are not a distinct principle of creation was
proved above, not simply by arguing that they cannot principiate
anything independently of free volition, but by showing that it is not
from them, but from the volition alone, that the real principiation of
things begins. Now, this proof applies to ideas, but not to
omnipotence. In fact, ideas, even in God, must be conceived as
having a certain priority with respect to volitions; for it is true, even
in God, that nothing is willed which is not foreknown—nihil est
volitum, quin præcognitum. If, therefore, God's ideas were a distinct
principle of creation, there would be something in God, prior to his
will, which would entail the existence of created beings; which is
impossible to admit so long as we maintain that God's will must
remain free in its extrinsic operations. We cannot, therefore, admit,
without absurdity, that the archetypal ideas constitute a distinct
principle of things. But, as to divine omnipotence, no such absurdity
is to be feared; for God's omnipotence has no priority with respect to
God's will; and thus the above argument cannot be used to prove
that omnipotence is not a distinct principle of creation.
We conclude that the extrinsic principles, to which the first origin of
contingent beings is to be traced, are not fewer, and not more, than
three. Our Catholic readers will be satisfied, we hope, that this
conclusion has been fairly established on what they know to be
secure foundations. Infidels, of course, will object; for they will think
that the whole of our discussion has been based on hypothetical
grounds. In fact, we have supposed that there are "primitive"
beings, that they are "contingent," that they need "a creator," and
that the creator must be an "infinite being," a god. If a Comtist or a
materialist happens to read the preceding pages, he will surely say
that we have built nothing but a cob-house. But we do not care
much what may be objected by such a class of frivolous and
unreasonable philosophers. We know that their favorite theories
have been a hundred times exploded, and their futile objections a
hundred times answered. When a foe is defeated, what is the use of
prolonging the contest? And when noonday light is dazzling the
world, what need is there of lighting candles? Let them, therefore,
only open their eyes, if they really want light. There is no scarcity of
good philosophical works, which, if consulted by them in a spirit of
candor, will afford them all the light that a man can reasonably
desire for the full attainment of truth.
Yet the solidity of the ground on which we have taken our stand may
be established in a very few words.
That there are contingent beings is quite certain; for nothing which
necessarily exists is liable to change or modification. But all that
surrounds us in this world is liable to change and modification;
therefore, nothing that surrounds us in this world necessarily exists.
Accordingly, all that we see in this world exists contingently.
That contingent beings are either primitive or made up of primitive
beings is, again, a well-known fact; for all being which is not
primitive is a compound, and can be traced to its first physical
components—that is, to the first elements of its composition. But the
first elements of composition cannot possibly be made up of other
elements, and accordingly must be primitive beings. Therefore,
primitive beings exist everywhere, at least (if nowhere else) in all the
compounds of which they are the first physical components.
That every primitive contingent being must have had its origin from
without is a plain truth; for that which has no origin from without
must have the adequate reason of its existence from within; and,
therefore, it carries in its essence the necessity of its existence. But
evidently contingent and changeable beings do not carry within their
essence the necessity of their existence; therefore, contingent
beings must have had their origin from without.
That every such being must have come out of nothing is not less
evident; for a primitive being cannot possibly come out of pre-
existent beings as its material principles. It must, therefore, be
produced either out of God's substance or out of nothing. But not
out of God's substance, for divine substance is not susceptible of
contingent forms; therefore, out of nothing—that is, by creation
properly.
Lastly, that the Creator is an eternal, infinite being can be easily
proved, independently of many other arguments, by the following
general theorem, to which modern philosophers are invited to pay
close attention. The theorem is this: All efficient cause is infinitely
more perfect, and of an infinitely better nature, than any of its
effects. If this proposition be true, it immediately follows that the
Creator of the universe is infinitely more perfect than the whole
universe, and has a nature infinitely better, nobler, and higher than
that of any contingent being, and therefore is a necessary and
independent being, the supreme being—God. Let us, then,
demonstrate our theorem.
It is a known and incontrovertible truth that every efficient cause
eminently contains in itself (that is, possesses in an eminent degree)
all the perfection which it can efficiently communicate to any number
of effects; and it can be proved, moreover, that the efficiency of a
cause is never exhausted, and not even weakened, by its exertions,
however long continued and indefinitely multiplied. The earth, after
having for centuries exerted its attractive power and caused the fall
of innumerable bodies, has preserved to this day the same power
whole and undiminished, and is still acting, with its primitive energy,
on any number of bodies, just as it did at the time of its creation.
Our soul is not exhausted or weakened by its operations; but, after
having made any number of judgments, reasonings, or any other
mental actions, still retains the whole energy and perfection of its
faculties without waste, effeteness, or decay. A molecule of oxygen,
after having for ages, either free in the air or confined in water or in
other compounds, produced such a number of effects as bewilders
and beats all power of imagination, retains yet its efficient causality
as entire and unimpaired as if it were of quite recent creation. These
facts show that the efficient cause suffers no loss whatever by the
exertion of its power, and therefore is fully equal to the production of
an endless multitude of effects.
Some may say that this conclusion cannot be universal, as we see
that natural forces are very often exhausted by exertion. We answer
that, when natural forces are said to be exhausted, the efficient
powers from which those forces result remain as intact and as active
as before. We say, indeed, that a man or a horse is exhausted by
fatigue; that our brain, after hours of mental work, needs rest to
recover its lost energy, and many other such things; but, in all such
cases, what we call exhaustion is not a diminution of efficient power
in the agents from the concurrence of which the natural forces
result, but either the actual disappearance (by respiration,
perspiration, etc.) of a number of those agents, or a perturbance of
the arrangements and conditions necessary for their united
conspiration towards the production of a determinate effect. Natural
force, in the sense of the objection, is a combination of agents and
of efficient powers, which produce their effect by many concurrent
actions giving a different resultant under different conditions; and as
any given effect proximately depends on the resultant of such
actions, the same powers, though unaltered in themselves, must,
under different conditions, give rise to different effects. Take a car
and four horses. If the horses act all in the same direction, the car
will move easily enough; but if two of the horses act in one
direction, and two in the other, the result will be very different. Yet
the powers applied to the car are in both cases the same. Again,
take an army of fifty thousand men facing the enemy. If the men are
well arranged so as to present a good line of battle, the action of the
army will be strong; but if the men are disorderly scattered, the
action will be weak, though the men are the same and their powers
and exertions undiminished. Now, all bodies and all complex causes
are in the same case; which is evident from the fact that with all of
them a favorable change of conditions, all other things remaining the
same, is always attended by an increase of the effect. Therefore, the
so-called exhaustion of natural forces is not a diminution of the
efficient powers of which they are the result, but a state of things in
which the same active powers are exerted in a different manner, or
have to perform a different work, according to the different
conditions to which they are actually subjected. We therefore repeat
that efficient causes suffer no loss whatever by the exertion of their
efficient powers, and that consequently they are fully equal to the
production of an infinite multitude of effects; and since every
efficient cause, as we have premised, must contain within itself, in
an eminent manner, the whole perfection which it can communicate
to its effects, we are forced to conclude that the nature of every
efficient cause infinitely transcends in perfection the nature of its
effects.
The theorem could be further confirmed by considering that all the
acts produced by efficient causes of the natural order, either spiritual
or material, are mere accidents, whereas the causes themselves are
substances; and it is manifest that the nature of substance infinitely
transcends the nature of accident.
It might be confirmed, again, by another very simple consideration.
The efficient cause does not communicate any portion of itself to its
effect.[185] In fact, efficient causation is production; and production
is not a transfusion, translocation, or emanation of a pre-existing
thing, but the origination of a new entity which had no previous
formal existence. It follows that the efficient cause, while producing
an effect, retains its entire entity, and therefore is never exhausted.
Thus a syllogism is not a portion of the mind that makes it; and the
making of it leaves intact the substance and the faculty from which it
proceeds. Thus, also, the actual momentum of a falling body is not a
portion of the terrestrial power by which it is produced; the power
remains whole and undiminished in the substance of the earth, as
already remarked, always ready to produce any number of changes,
and always unchanged in itself. This is the reason why every efficient
cause infinitely transcends the nature of its effects.
Our theorem is, then, demonstrated both by facts and by intrinsic
reasons. We are confident that all honest philosophers, no matter
how much their intellectual vision may have been distorted by false
doctrines, will see their way to the right conclusion, and confess the
absolute necessity of an independent, self-existent, infinite Creator,
from whom all beauty, goodness, and perfection proceed, and to
whom all creatures—philosophers not excepted—owe allegiance,
honor, and glory.
TO BE CONTINUED.

FOOTNOTES:

[181] Entered according to Act of Congress, in the year 1874, by Rev. I. T. Hecker,
in the Office of the Librarian of Congress, at Washington, D. C.
[182] This argument could be employed against all other forms of pantheism; but
we must abstain at present from the discussion of particular systems, as we
cannot deal fairly with them within the narrow compass of a single article.
As for self-existent matter, we need only say that nothing which can receive new
determinations is self-existent; and since matter receives new determinations,
therefore matter is not self-existent. Hence the conception of eternal and
uncreated matter cannot be styled a philosophical opinion, but only a dream of
unreflecting or uneducated minds.
[183] The Aristotelic meaning of the word privation will be easily understood from
the following example: If a cylindrical piece of wax be made to assume a spherical
form, the sphericity will be educed, as the schools say, from the cylindrical wax,
not inasmuch as it is cylindrical, but inasmuch as it is non-spherical. Such a non-
sphericity is a privation, which is more than a negation, as it implies not only the
absence of sphericity, but also the presence of its contrary—that is, of the
cylindrical form. Privation is usually defined carentia formæ in subjecto apto. It is
a principle per accidens.
[184] We give the original text: Sic enim scientia Dei se habet ad omnes res
creatas, sicut scientia artificis se habet ad artificiata. Scientia autem artificis est
causa artificiatorum, eo quod artifex operatur per suum intellectum. Unde oportet
quod forma intellectus sit principium operationis, sicut calor est principium
calefactionis. Sed considerandum est, quod forma naturalis, in quantum est forma
manens in eo cui dat esse, non nominat principium actionis, sed secundum quod
habet inclinationem ad effectum. Et similiter forma intelligibilis non nominat
principium actionis secundum quod est tantum in intelligente, nisi adjungatur ei
inclinatio ad effectum, quæ est per voluntatem. Quum enim forma intelligibilis ad
opposita se habeat (quum eadem sit scientia oppositorum) non produceret
determinatum effectum, nisi determinaretur ad unum per appetitum, ut dicitur in
9. Metaph. Manifestum est autem quod Deus per intellectum suum causat res,
quum suum esse sit suum intelligere; unde necesse est quod sua scientia sit
causa rerum secundum quod habet voluntatem conjunctam (p. 1, q. 14, a. 8).
[185] Parents, however, communicate a portion of their substance to their
offspring. The reason is that parents are not only the efficient, but also the
material, cause of their offspring. As material causes, they supply the matter of
which the fœtus will be formed; but, as efficient causes, they only put the
conditions required by nature for the organization of this matter. The position of
such conditions is an accidental action as well as the subsequent organization.
Therefore, parents, as efficient causes, produce nothing but accidental acts. The
matter of which the fœtus is formed is, of course, all pre-existing.
DANTE'S PURGATORIO.
CANTO TWELFTH.
Paired, like two oxen treading under yoke,
That burdened soul and I as far had gone
As the loved Tutor let. But when he spoke
These words: "Now leave him! We must travel on,
For here 'tis good with spread of sail and stroke
Of oar, to push his boat as each best may;"
I made myself, as walking needs, erect,
But only in body; just it is to say
My thoughts were bowed, my spirit was deject.
Still I was moving, and with willing feet
Followed my Master; both began to show
How light we were, when thus he said: "'Tis meet
That, walking here, thou bend thine eyes below,
So to observe, and make the moments fleet,
Over what kind of bed thy footsteps go."

Even as, that so their memory may survive,


Our earthly tombs, above the buried, bear
The graven form of what they were alive;
Whence oft one weeps afresh the image there,
Pricked by remembrance,—which doth only give
To souls compassionate a sting of pain—
So I saw figured o'er, but with more skill
In the resemblance, all the narrow plain
Which formed our pathway, jutting from the hill.

Him[186] there I marked, on one side, noblest made


Of all God's creatures, stricken down from heaven
Like lightning! Opposite, there was displayed
Briareus, cast from where he late had striven,
Smit by celestial thunderbolts, and laid
Heavy on earth and in the frost of death.
I saw Thymbræus, Pallas too, and Mars,
Still armed, around their sire, with bated breath
Viewing the giants, their torn limbs and scars!
Ni dI t f t f hi tt
Nimrod I saw, at foot of his great tower,
As if bewildered, gazing on the tribes
That showed with him such haughtiness of power
In Shinar's plain, as Genesis describes.

O Niobe! with what eyes, full of woe,


Mid thy slain children, upon each hand seven,
I saw thee carved upon the road! And, O
Saul! in Gilboa, that no more from heaven
Felt rain or dew, how dead on thine own sword
Didst thou appear! Thee, mad Arachne, there
I saw, half spider! fumbling the deplored
Shreds of that work which wrought for thee despair
O Rehoboam! there no more in threat
Stands thy fierce figure; smit with fear he flies,
Whirled in a chariot, none pursuing yet:
Showed also that hard pavement to mine eyes
How young Alcmæon made his mother sell
With life the luckless ornament she wore
How, in the temple, on Sennacherib fell
The sons, and left his corpse there on the floor.
The cruel carnage and the wreck it showed
Which Tomyris made, when she to Cyrus cried:
Blood thou didst thirst for! now I give thee blood;
And showed th' Assyrians flying far and wide
In utter rout, with Holofernes dead,
And all the slaughter that befell beside,
And the grim carcase by the bloody bed.
Troy next I saw, an ashy, caverned waste:
O Ilion! how vile the work showed thee
Which there is graven,—how utterly abased!
What master of pencil or of stile[187] was he
Who so those traits and figures could have traced
That subtlest wit had been amazed thereby?
Alive the living seemed, and dead the dead!
Who saw the truth no better saw than I,
Whil b dI t ll d th t d
While bowed I went, all underneath my tread.

Now swell with pride, and on with lofty stalk,


Children of Eve! nor bend your visage aught
So to behold the sinful way ye walk.
More of the mountain than my busied thought
Had been aware of we had rounded now,
And much more of his course the sun had spent;
When he, who still went first with watchful brow,
Exclaimed: "Look up!—to accomplish our ascent
Time no more suffers to proceed so slow.
See yonder angel hastening on his way
To come towards us! and from her service, lo!
The sixth returning handmaid of the day.
Give to thy mien the grace of reverence, then,
That he may joy to marshal us above.
Think thus: this day will never dawn again."
I had so often felt his words reprove
My slowness, warning me to lose no time,
That on this point I read his dark words right.
With sparkling face, as glows at rosy prime
The tremulous morning star, and robed in white,
That being of beauty moved towards us, and said,
Opening his arms and then his pinions wide,
"Come, here the steps are!—easy to the tread
And close at hand: now upward ye may glide."
But very few obey this Angel's call:
O human race! born high on wings to soar,
Why at a little breath do ye so fall?
He brought us where the rock a pass revealed
Hewn out, his pinions on my forehead beat
And with his promise my safe-going sealed.

As, to the right, in climbing to the seat


Of the fair church[188] that looketh lordly down
Over the bridge that bears the name this day
Of b h ll l d [189]
Of Rubaconte, on the well-ruled town,[189]
The sharp ascent is broken by a way
Of stairs constructed in the old time, ere
Fraud was in measure and in ledger found;
Thus the steep bank is graduated there
Which falls abruptly from the other round:
On either side the tall rock grazes though.
As we turned thitherward, were voices heard,
Beati pauperes spiritu! singing so
As might not be exprest by any word.
Ah! these approaches—how unlike to Hell's!
With chant of anthems one makes entrance here;
Down there with agony's ferocious yells.

Now, as we climb, the sacred stairs appear


More easy than the plain had seemed before:
Wherefore I thus began: "O Master! say,
What heavy load is tak'n from me? No more
I feel that weariness upon my way."
"When every P, upon thy temples traced,
Almost obliterate now," he answered me,
"Shall be, like this one, totally erased,
So by right will thy feet shall vanquished be,
That they not only no fatigue shall know,
But ev'n with pleasure shall be forward sped."
Then did I like as men do when they go
Unweeting what they carry on their head,
Till signs from some one their suspicion waking,
The assistant hand its own assurance tries,
And seeks and findeth, such discovery making
As may not be afforded by the eyes.
Spreading my right-hand fingers, I could find
Six[190] letters only of the seven which he
Who bore the keys had on my forehead signed:
Observing which, my Master smiled on me.
FOOTNOTES:

[186] Lucifer.
[187] Stile here means a sculptor's tool, and not a writer's style.
[188] This is the well-known church of S. Miniato, which every boy who has been
to Florence must well remember.
[189] Florence, in irony.
[190] The Angel, sitting at the gate of Purgatory, had described (as the readers of
the Ninth Canto may remember, v. 112) the letter P seven times with the point of
his sword on the forehead of Dante, in sign of the seven deadly sins,—Peccata—
one of which, and Dante's worst, the sin of pride, now vanishes from his soul as
the letter fades from his forehead.
THE EPIPHANY.
Let us, then, also follow the Magi; let us separate ourselves from our
barbarian customs, and make our distance therefrom great, that we
may see Christ, since they too, had they not been far from their own
country, would have missed seeing him. Let us depart from the
things of earth. For so the wise men, while they were in Persia, saw
but the star; but after they had departed from Persia, they beheld
the Sun of Righteousness. Or rather, they would not have seen so
much as the star, unless they had readily risen up from thence. Let
us, then, also rise up; though all men be troubled, let us run to the
house of the young Child; though kings, though nations, though
tyrants, interrupt this our path, let not our desire pass away; for so
shall we thoroughly repel all the dangers that beset us; since these
too, except they had seen the young Child, would not have escaped
their danger from the king. Before seeing the young Child, fears and
dangers and troubles pressed upon them from every side; but after
the adoration, it is calm and security; and no longer a star, but an
angel, receives them, having become priests from the act of
adoration; for we see that they offered gifts also.
Do thou, therefore, likewise leave the Jewish people, the troubled
city, the blood-thirsty tyrant, the pomps of the world, and hasten to
Bethlehem, where is the house of the Spiritual Bread;[191] for
though thou be a shepherd, and come hither, thou wilt behold the
young Child in an inn; though thou be a king, and approach not
here, thy purple robe will profit thee nothing; though thou be one of
the wise men, this will be no hindrance to thee; only let thy coming
be to honor and adore, not to spurn, the Son of God; only do this
with trembling and with joy, for it is possible for both of these to
concur in one.
But take heed that thou be not like Herod, and say, That I may come
and worship him, and, when thou art come, be minded to slay him.
For him do they resemble who partake of the mysteries unworthily;
it being said that such an one shall be guilty of the Body and Blood
of the Lord. Yes; for they have in themselves the tyrant who is
grieved at Christ's Kingdom—him that is more wicked than Herod of
old—even Mammon. For he would fain have the dominion, and
sends them that are his own to worship in appearance, but slaying
while they worship. Let us fear, then, lest at any time, while we have
the appearance of suppliants and worshippers, we should indeed
show forth the contrary.—S. John Chrysostom.

FOOTNOTES:

[191] Bethlehem signifies in Hebrew "the house of bread."


GRAPES AND THORNS.
BY THE AUTHOR OF "THE HOUSE OF YORKE."

CHAPTER VIII.
SUMMER FRIENDS.

F. Chevreuse did not allow himself a long indulgence in his own


sorrows. Before half an hour had elapsed, he was stepping through
the portal of the city jail, all private grief set aside and lost sight of in
the errand that had brought him.
Sensitive as he was, the gloom and dampness inseparable from a
prison would have chilled him, but that pity for him who was
suffering from them so unjustly, as he believed, startled his heart
into intenser action, and sent an antagonistic glow through his
frame, as though by force of love alone he would have warmed the
stones and chased away those depressing shadows.
A few swift steps along the stone corridor brought him to the cell
assigned to Mr. Schöninger. Looking with eagerness, yet shrinkingly
too, through the grating, while the jailer unlocked the door, he saw
the prisoner standing there with folded arms and head erect,
regarding him coldly and without the faintest sign of recognition.
The place was not so dim but he must have seen perfectly who his
visitor was; yet a man of stone could not have stood more unmoved.
The jailer was not long unlocking the door, yet, brief as the time
was, it sufficed to work a change in the priest. It was with him as
with the fountain which tosses its warm waters into a chilly
atmosphere: the spray retains its form, but not its temperature. "I
am shocked at this, Mr. Schöninger!" he exclaimed, hastening into
the cell. "I will do anything to relieve you! Only tell me what to do."
The words, the gesture, the emphasis, all were as he had meant;
but a something in the whole manner, which tells when the heart
outleaps the word and the gesture, was lost. It was possible to think
the cordiality of his address affected.
Mr. Schöninger bowed lowly, without unfolding his arms or softening
the expression of his face. "I thank you for your offers of service,"
he said; "but they are unnecessary. I have employed counsel, and
what the law can do for me will be done. Meantime, it is not for you
and me to clasp hands."
His look conveyed not only pride, but disdain. He seemed less the
accused than the accuser.
"Whose hand, then, will you clasp?" the priest exclaimed, impatient
at what seemed to him an unreasonable scruple. "You are a stranger
here, and can be sure of no one. I am the very person whose good-
will will be most valuable to you."
It was only the embarrassment resulting from an unexpected rebuff
which could have made F. Chevreuse appeal to the motive of self-
interest. To tell a proud and bitter, perhaps a guilty, man that he
stands in his own light, is only to make him blacken yet more his
immovable shadow. But as a man sometimes relaxes the severity of
his manner at the same time that he increases the firmness of his
resolution, Mr. Schöninger unbent so far as to offer his visitor a seat.
"Please excuse the roughness," he said, indicating a rude bench.
"The furniture is not of my choosing." And seated himself on the
bed, there being no other place.
F. Chevreuse remained standing. The mocking courtesy was more
chilling than coldness.
"I followed an impulse of kindness in coming to you," he said,
looking down to hide how much he was hurt. "I did not stop to ask
myself what was conventional, or wise, or politic. My heart prompted
me to fly to the rescue, and I took no other counsel."
There was no reply. Mr. Schöninger's eyes were fixed with an intent
and searching gaze on the priest, and a faint color began to creep
up over his cold face. As F. Chevreuse raised his eyes and met that
gaze, the faint color deepened to a sudden red; for the priest's
glance was dimmed by tears of wounded feeling he had striven to
hide.
"You distrust me!" he said reproachfully; "and I do not deserve it. I
would serve you, if I could. I would be your friend, if you would let
me."
It was Mr. Schöninger's turn to drop his eyes. To look in that face
unmoved was impossible. The reproach, the pain, the tenderness of
it had shot like an arrow through his heart, steeled as it was. But his
habit of self-control was proof against surprise. After the blush had
left his face, there was no sign visible of the struggle that was going
on within. He seemed to be merely considering a question. After a
moment, he looked up.
"You seem to think me innocent of this charge?" he remarked calmly.
F. Chevreuse was silent with astonishment.
"You probably do think so," Mr. Schöninger went on, in the same
tone. "But whatever your opinion may be, you do not know. Crimes
are committed from various motives and under various
circumstances. Some are almost accidental. Neither is crime
committed by the low and rude alone, nor by the bad alone. There is
nothing in the character or circumstances of any man which would
render it impossible that he should ever be guilty of a crime. I
repeat, then, that you cannot be sure of my innocence; and, till it is
proved, there can be no intercourse between us. I am willing to give
you credit for a charitable impulse; but I do not want charity. I want
justice!" His eyes flashed out, and his face began to redden again.
Mr. Schöninger had not become cool by spending a night in jail.
F. Chevreuse did not stir, though he was in fact dismissed. Mr.
Schöninger, seeing that his visitor did not sit, rose, and stood waiting
to bow him out.
"I cannot go away and leave you so, in such a place!" the priest
exclaimed after a moment, during which he seemed to have made
an inner effort to go. "It is monstrous! Cannot you see that it is so?
Why, last night we were like friends; and I insist that there is no
reason why we should not be friends to-day."
"What! Even if I should be guilty?" asked the prisoner in a low voice.
F. Chevreuse made a gesture of impatience, and was about to utter
a still more impatient protest, when he met a look so cold, yet so
thrilling with a significance he could not interpret, that he drew back
involuntarily.
The Jew's face darkened. "Your convictions are, apparently, not so
deep as you had supposed, sir," he said freezingly. "I am afraid you
would find yourself disappointed as to the extent of confidence you
would be able to repose in me. The sober second thought is best.
Our paths are separate."
For the first time something like anger showed momentarily in the
priest's face, and gave a certain sternness to the first words he
spoke; but it was over in an instant. "You are quite right, sir!" he
said. "It is impossible for me to go with you, unless I am met with
entire frankness and confidence. If you choose that our paths shall
be separate, I will not force myself on you; but we need not be
antagonistic. Farewell!"
He turned and groped in the door-way for the passage-step, his own
shadow being added to those which already wrapped the place in an
obscurity almost like night. He saw the jailer in the long corridor
before him, waiting to lock the door, and he had just found where to
set his foot, when he felt a warm touch on his hand that still held by
the stone door-way inside the cell. The touch was slight, but it was a
caress, either a kiss or the quick pressure of a soft palm. He had
hardly time to be fully aware of it before he stood in the corridor,
and the jailer was locking the door behind him.
He stopped, and looked through the grating, but could not see the
prisoner. Only a narrow line of black, like the sleeve of a coat,
seemed to show that Mr. Schöninger had thrown himself on to his
bed. The priest put his face close to the bars, and whispered, "God
bless you!"
The line of black moved quickly with a start, but there was no reply.
Pale and dispirited, F. Chevreuse left the prison, and took his way
slowly to Mrs. Gerald's. He would rather not have gone then, but he
had promised. He wondered a little within himself, indeed, why he
felt such reluctance to see persons who had always been faithful and
sympathizing friends to him, and why he would rather, were the
choice left to him, have gone to Mrs. Ferrier, or, still better, to
Annette.
As soon as the true reason occurred to him, he put it aside, and
refused to think on the subject.
Mrs. Gerald was evidently on the watch for him; for as soon as he
approached the house, she came to the door to meet him. The color
was wavering in her face, her blue eyes were suffused with tears,
and looked the sympathy her lips did not speak. But the sympathy
was all for him—for the terrible wound torn open again, for the new
wound added, perhaps, of a misplaced confidence. No look seemed
to glance past him and inquire for the one he had left behind.
Honora sat by a fire in the sitting-room, leaning close to the blaze,
with a shawl drawn about her shoulders, and seemed to shiver even
then. There was a frosty paleness in her face as she rose to meet
their visitor, as though the blood had all flowed back to her heart,
and stopped there, and the hand she gave him was cold. But an
eager, questioning glance slipped from her eyes, swift and shrinking,
that went beyond him and asked for news of the prisoner.
"Well," said F. Chevreuse, glancing from one to the other, "there is
nothing to tell."
Honora sank into her chair again, and waited mutely, looking into
the fire.
"Nothing of any consequence, that is," he continued, folding his
hands together on the back of a chair, and looking down at them. "I
went to the jail; but Mr. Schöninger has so quixotic a sense of
propriety that he will not allow me to do anything for him. It was in
vain for me to urge the matter; he absolutely sent me away."
"He was quite right in that," Mrs. Gerald remarked coldly.
Honora's eyes were again eagerly searching the priest's face, but
Mrs. Gerald was in turn looking away from him.
"And why was he right, madam?" demanded F. Chevreuse.
She did not look up to answer, and her expression was of that
stubborn reserve which some good people assume when they
cannot say anything friendly, and are determined not to be
uncharitable. "I may be wrong," she said, carefully choosing her
words, "but it does not seem to me that you are the person of whom
he should take advice now. Pardon me, F. Chevreuse! I do not mean
to criticise you nor dictate to you, of course. But I am glad that you
are to have nothing to do with this. You should be spared the pain."
He was too sore-hearted to argue the point; and he knew, moreover,
that argument would be thrown away. He was well aware that the
most of his friends thought his generosity sometimes exaggerated,
and were more likely to check than to encourage him. When he
went out of the beaten track, he had never found sympathy
anywhere but with the one whose loss he felt more and more every
day, unless it might be with Annette Ferrier and her mother.
"It seems that I am not to have anything to do with it," he said;
"though I fail to see why I should not. Let that pass, however. I pity
the poor fellow from my heart, though his detention will be a short
one, since the trial, they tell me, is to come on immediately. It is a
miserable condition, being shut up in that place, and loaded with
such an outrageous accusation. I do not wonder it made him bitter
and distrustful of me."
Mrs. Gerald lifted her eyes quickly, and gave F. Chevreuse a glance
that recalled to his mind that look from which he had shrunk in the
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

textbookfull.com

You might also like