Full Download D3 Data Driven Documents Pocket Primer 1st Edition Oswald Campesato PDF

Download as pdf or txt
Download as pdf or txt
You are on page 1of 59

Full download test bank at ebookmeta.

com

D3 Data Driven Documents Pocket Primer 1st Edition


Oswald Campesato

For dowload this book click LINK or Button below

https://ebookmeta.com/product/d3-data-driven-
documents-pocket-primer-1st-edition-oswald-
campesato/

OR CLICK BUTTON

DOWLOAD EBOOK

Download More ebooks from https://ebookmeta.com


More products digital (pdf, epub, mobi) instant
download maybe you interests ...

Data Science Fundamentals Pocket Primer 1st Edition


Oswald Campesato

https://ebookmeta.com/product/data-science-fundamentals-pocket-
primer-1st-edition-oswald-campesato/

Bash for Data Scientists 1st Edition Oswald Campesato

https://ebookmeta.com/product/bash-for-data-scientists-1st-
edition-oswald-campesato/

Data Structures in Java 1st Edition Oswald Campesato

https://ebookmeta.com/product/data-structures-in-java-1st-
edition-oswald-campesato/

Python for Programmers 1st Edition Oswald Campesato

https://ebookmeta.com/product/python-for-programmers-1st-edition-
oswald-campesato/
Natural Language Processing Fundamentals for Developers
1st Edition Oswald Campesato

https://ebookmeta.com/product/natural-language-processing-
fundamentals-for-developers-1st-edition-oswald-campesato/

Data Architecture A Primer for the Data Scientist A


Primer for the Data Scientist 2nd Edition W.H. Inmon

https://ebookmeta.com/product/data-architecture-a-primer-for-the-
data-scientist-a-primer-for-the-data-scientist-2nd-edition-w-h-
inmon/

Data-Driven Model-Free Controllers 1st Edition Precup

https://ebookmeta.com/product/data-driven-model-free-
controllers-1st-edition-precup/

Integrating D3.js with React: Learn to Bring Data


Visualization to Life 1st Edition Elad Elrom

https://ebookmeta.com/product/integrating-d3-js-with-react-learn-
to-bring-data-visualization-to-life-1st-edition-elad-elrom/

Data Architecture A Primer for the Data Scientist 2nd


Edition W.H. Inmon

https://ebookmeta.com/product/data-architecture-a-primer-for-the-
data-scientist-2nd-edition-w-h-inmon/
D3
Pocket Primer
LICENSE, DISCLAIMER OF LIABILITY, AND
LIMITED WARRANTY
By purchasing or using this book and disc (the “Work”), you agree that this license
grants permission to use the contents contained herein, including the disc, but
does not give you the right of ownership to any of the textual content in the book
/ disc or ownership to any of the information or products contained in it. This
license does not permit uploading of the Work onto the Internet or on a network
(of any kind) without the written consent of the Publisher. Duplication or
dissemination of any text, code, simulations, images, etc. contained herein is
limited to and subject to licensing terms for the respective products, and
permission must be obtained from the Publisher or the owner of the content, etc.,
in order to reproduce or network any portion of the textual material (in any media)
that is contained in the Work.

MERCURY LEARNING AND INFORMATION (“MLI” or “the Publisher”) and anyone involved in
the creation, writing, or production of the companion disc, accompanying
algorithms, code, or computer programs (“the software”), and any accompanying
Web site or software of the Work, cannot and do not warrant the performance or
results that might be obtained by using the contents of the Work. The author,
developers, and the Publisher have used their best efforts to insure the accuracy
and functionality of the textual material and/or programs contained in this
package; we, however, make no warranty of any kind, express or implied,
regarding the performance of these contents or programs. The Work is sold “as is”
without warranty (except for defective materials used in manufacturing the book
or due to faulty workmanship).

The author, developers, and the publisher of any accompanying content, and
anyone involved in the composition, production, and manufacturing of this work
will not be liable for damages of any kind arising out of the use of (or the inability
to use) the algorithms, source code, computer programs, or textual material
contained in this publication. This includes, but is not limited to, loss of revenue or
profit, or other incidental, physical, or consequential damages arising out of the
use of this Work.

The sole remedy in the event of a claim of any kind is expressly limited to
replacement of the book and/or disc, and only at the discretion of the Publisher.
The use of “implied warranty” and certain “exclusions” vary from state to state,
and might not apply to the purchaser of this product.
D3
Pocket Primer

Oswald Campesato

MERCURY LEARNING AND INFORMATION


Dulles, Virginia
Boston, Massachusetts
New Delhi
Copyright ©2016 by MERCURY LEARNING AND INFORMATION LLC. All rights reserved.
This publication, portions of it, or any accompanying software may not be
reproduced in any way, stored in a retrieval system of any type, or transmitted by
any means, media, electronic display or mechanical display, including, but not
limited to, photocopy, recording, Internet postings, or scanning, without prior
permission in writing from the publisher.
Publisher: David Pallai
MERCURY LEARNING AND INFORMATION
22841 Quicksilver Drive
Dulles, VA 20166
[email protected]
www.merclearning.com
1-800-232-0223
O. Campesato. D3 Pocket Primer.
ISBN: 978-1-938549-65-6
The publisher recognizes and respects all marks used by companies,
manufacturers, and developers as a means to distinguish their products. All brand
names and product names mentioned in this book are trademarks or service
marks of their respective companies. Any omission or misuse (of any kind) of
service marks or trademarks, etc. is not an attempt to infringe on the property of
others.
Library of Congress Control Number: 2014937375
151617321 Printed in the United States of America
This book is printed on acid-free paper.
Our titles are available for adoption, license, or bulk purchase by institutions,
corporations, etc.
For additional information, please contact the Customer Service Dept. at (800)
232-0223 (toll free). Digital versions of our titles are available at:
www.authorcloudware.com and other e-vendors.
The sole obligation of MERCURY LEARNING AND INFORMATION to the purchaser is to
replace the book and/or disc, based on defective materials or faulty workmanship,
but not based on the operation or functionality of the product.
I’d like to dedicate this book to my parents – may
this bring joy and happiness into their lives.
CONTENTS

Preface
Chapter 1: Introduction to D3
What is D3?
D3 on Mobile Devices
D3 Boilerplate
Method Chaining in D3
The D3 Methods select() and selectAll()
Specifying UTF-8 in HTML5 Web Pages with D3
Creating New HTML Elements
The Most Common Idiom in D3
Binding Data to Document-Object-Model Elements
Generating Text Strings
Creating Simple Two-Dimensional Shapes
Bezier Curves and Text
Two-Dimensional Transforms
A Digression: Scaling Arrays of Numbers to Different Ranges
Tweening in D3
Formatting Numbers
Working with Gradients
Linear Gradients
Radial Gradients
Adding HTML <div> Elements with Gradient Effects
Working with Portable Network Graphics Files
D3 Application Programing Interface Reference
Additional Code Samples on the CD
Summary
Chapter 2: Arrays, Mouse Events, and Animation Effects
Finding the Maximum and Minimum Values in an Array
Working with Multidimensional Arrays
Two-Dimensional Arrays and Scatter Charts
D3 Data Scaling Functions
Other D3.js Scaling Functions
D3 Path Data Generator
What About this, $this, and $(this)?
D3 and Mouse Events
Mouse Events and Randomly Located Two-Dimensional Shapes
A “Follow the Mouse” Example
A Drag-and-Drop Example
Animation Effects with D3
Easing Functions in D3
Zoom, Pan, and Rescale Effects with D3
Handling Keyboard Events with D3
Additional Code Samples on the CD
Summary
Chapter 3: Working with Bar Charts in D3
A Simple Horizontal Bar Chart
Rendering Horizontal and Vertical Axes with Labels
A Scaled Vertical Bar Chart with Labeled Axes
Using Date and Time Stamps to Label Axes
D3 Bar Charts with Unicode Characters
Bar Charts with Three-Dimensional Effects
Bar Charts with Filter Effects and Tooltips
Additional Filter Effects
Updating Bar Charts
Dynamically Adding and Removing Data From Bar Charts
Scrolling Animation Effects with Bar Charts
Additional Code Samples on the CD
Summary
Chapter 4: Other Chart Types and Data Formats
Rendering A Line Graph
Rendering Multiple Nonlinear Graphs
Scatter Charts with Axes and Mouse Events
Selecting Equal Data Points in Scatter Charts
Rendering Pie Charts
A Histogram with Animation Effects
Working with Other Data Formats and Data Files
The XMLHttpRequest Request Object
The jQuery .ajax() Method
Useful D3 Methods for CSV Files
CSV: Synchronous Versus Nonsynchronous D3 Methods
Line Graphs with CSV Data and Mouse Events
Bar Charts with Three-Dimensional Effects from Comma-Separated-Value Files
Additional Code Samples on the CD
Summary
Chapter 5: SVG Essentials
Overview of SVG
Basic Two-Dimensional Shapes in SVG
SVG Gradients and the <path> Element
SVG <polygon> Element
Bezier Curves and Transforms
SVG Filters and Shadow Effects
Rendering Text Along an SVG <path> Element
SVG Transforms
The SVG <clipPath> Element
Other SVG Features
SVG Animation
Creating Three-Dimensional Effects in SVG
SVG and HTML
SVG and JavaScript
CSS3 and SVG
CSS3 and SVG Bar Charts
Similarities and Differences Between SVG And CSS3
SVG and XSLT (Extensible Stylesheet Language Transformations)
Additional Code Samples on the CD
Summary
Chapter 6: Introduction to CSS3 Graphics and Animation
CSS3 Support and Browser-Specific Prefixes for CSS3
Quick Overview of CSS3 Features
CSS3 Pseudoclasses, Attribute Selection, and Relational Symbols
CSS3 Pseudoclasses
CSS3 Attribute Selection
CSS3 Shadow Effects and Rounded Corners
Specifying Colors with Red/Green/Blue Triples and Hue/Saturation/Lightness
Representations
CSS3 and Text Shadow Effects
CSS3 and Box Shadow Effects
CSS3 and Rounded Corners
CSS3 Gradients
Linear Gradients
Radial Gradients
CSS3 Two-Dimensional Transforms
Rotate Transforms
CSS3 Three-Dimensional Animation Effects
CSS3 Media Queries
CSS3 and SVG
Additional Code Samples on the CD
Summary
Chapter 7: D3 with CSS3, SVG, and HTML5 Canvas
D3 Code Samples with HTML5 Canvas
Updated CSS3 Stylesheets for this Chapter
D3 and CSS3 Effects
D3 and CSS3 Animation Effects
D3 and HTML5 Canvas
D3 and SVG
Bubble Charts with JSON Data
Additional Code Samples on the CD
Summary
Chapter 8: D3 with Ajax, HTML5 WebSockets, and NodeJS
D3 and Ajax Requests
D3 with PHP Data
D3 with MySQL Data
D3 Bar Charts with a WebSocket Server
D3 and NodeJS (Optional)
Inserting an <svg> Element in an HTML Web Page
Rendering SVG Graphics with D3 and NodeJS (Optional)
Additional Code Samples on the CD
Summary
Chapter 9: Miscellaneous D3 Application Programming
Interfaces and Other Toolkits
Maps in D3 (Choropleth)
Adding Tooltips to a United States Map
D3 and Google Maps
GeoJSON and D3 TopoJSON
Other Maps
The D3 Force Layout
Using D3 Force with CSS Instead of SVG
D3 Trees
Voronoi Diagrams
Toolkits That are D3 Extensions
The ChartBuilder Extension
The CrossFilter Extension
The dc.js Extension
Rickshaw
D3 and Other Toolkits
D3 Plugins
DVL(Dynamic Visualization LEGO) for Data Visualization
Vega: A Visualization Grammar
NVD3
DexChart: Reusable Charts
R Programming with D3-Based Toolkits
Additional D3 APIs
The D3 Brushes API
D3 and HTML5 Web Audio
What About D3 for Three-Dimensional Graphics and Animation?
Other D3 Resources
Additional Code Samples on the CD
Summary
Chapter 10: HTML5 Mobile Applications on Android and iOS
HTML5/CSS3 and Android Applications
SVG and Android Applications
HTML5 Canvas and Android Applications
Android and HTML5 Canvas Multiline Graphs
What is PhoneGap?
How Does PhoneGap Work?
Software Dependencies for PhoneGap 3.0
Creating Android Hybrid Applications with PhoneGap 3.0
Creating iOS Hybrid Applications with PhoneGap 3.0
Requirements for Deploying Mobile Apps to iOS Devices
Rendering a CSS3 Cube on iOS Using PhoneGap
D3 and Android Applications
D3 and iOS Applications
Developing D3-Based Mobile Applications for Google Glass
How does Google Glass Work?
Supported HTML5 Tags
Unsupported HTML5 Tags
Deploying Android Applications to Google Glass
Displaying Google Glass in an Emulator
Other Useful Links for Google Glass
Other Google Glass Code Samples
Additional Code Samples on the CD
Summary
Index
On The CD
Appendix A: Overview of SVG
Appendix B: Introduction to Android
Appendix C: HTML5 and JavaScript Toolkits
Appendix D: Rendering 2D Shapes in HTLM5 Canvas
PREFACE

WHAT IS THE PRIMARY VALUE PROPOSITION FOR


THIS BOOK?

T his book endeavors to provide you with as much up-to-date


information as possible that can be reasonably included in a
book of this size. There are many unique features of this
book, including two chapters that are dedicated to CSS3 (with 2D/3D
graphics and animation and how to leverage SVG in CSS selectors)
and SVG (with custom code samples), and also an Appendix for
HTML5 Canvas. There are two additional chapters that are unique to
this D3 book: one chapter is devoted to hybrid mobile applications
with D3 (deployed to Android tablets Nexus 7 2 and Asus Prime and
an iPad3) with version of PhoneGap 3.0 (currently the latest
release), and another chapter contains integrated code samples with
CSS3, HTML5 Canvas, and SVG.
Other unique features of this book include code samples that
show you how to render 3D shapes (including 3D bar charts with
animation), create multiple animation effects, and how to create SVG
filters for your HTML Web pages. Moreover, you will see code
samples that show you how to work with Unicode, CSV files, Ajax,
HTML5 WebSockets, and an example involving NodeJS. Finally, the
author has written multiple open source projects (links are provided
toward the end of this Preface) containing literally thousands of code
samples so that you can explore the capabilities of CSS3, SVG,
HTML5 Canvas, and jQuery combined with CSS3.

THE TARGET AUDIENCE


This book is intended to reach an international audience of
readers with highly diverse backgrounds in various age groups.
While many readers know how to read English, their native language
is not always English (which could be their second, third, or even
fourth language). Consequently, this book uses standard English
rather than colloquial expressions that might be confusing to those
readers. As you know, many people learn by different types of
imitation, which includes reading, writing, or hearing new material
(yes, some basic videos are also available). This book takes these
points into consideration in order to provide a comfortable and
meaningful learning experience for the intended readers.

GETTING THE MOST FROM THIS BOOK


Some programmers learn well from prose, others learn well from
sample code (and lots of it), which means that there’s no single style
that can be used for everyone.
Moreover, some programmers want to run the code first, see what
it does, and then return to the code to delve into the details (and
others use the opposite approach).
Consequently, there are various types of code samples in this
book: some are short, some are long, and other code samples
“build” from earlier code samples.
The goal is to show (and not just tell) you a variety of visual
effects that are possible, some of which you might not find
anywhere else. You benefit from this approach because you can pick
and choose the visual effects and the code that creates those visual
effects.

WHAT TYPE OF MOBILE APPLICATIONS ARE IN THIS


BOOK?
The screenshots throughout this book are based on hybrid HTML5
mobile applications that were deployed to two Android tablets with
Android 4.x and an iPad3, as well as some screenshots from a
Chrome browser on a Macbook Pro. The final chapter in this book
shows you how to use PhoneGap 3.0 to create D3-based hybrid
HTML5 mobile applications for Android and iOS mobile devices. This
book does not focus on “thin apps,” which refers to HTML Web
pages that are accessed from a mobile device. However, you have
the option of making all the code samples in this book available on a
Website in order to access them on mobile devices.

HOW WAS THE CODE FOR THIS BOOK TESTED?


The code samples in this book have been tested in a Google
Chrome browser (version 28.0.1500.95) on a Macbook Pro with OS X
10.8.3. Unless otherwise noted, no special browser-specific features
were used, which means that the code samples ought to work in
Chrome on other platforms, and also in other modern browsers.
Exceptions are due to limitations in the cross-platform availability of
specific features of D3 itself. Although the code also works in several
earlier versions of Chrome on a Macbook Pro, you need to test the
code on your platform and browser (especially if you are using
Internet Explorer).
Another point to keep in mind is that all references to “Web
Inspector” refer to the Web Inspector in Chrome, which differs from
the Web Inspector in Safari. If you are using a different (but still
modern) browser or an early version of Chrome, you might need to
check online for the sequence of keystrokes that you need to follow
to launch and view the Web Inspector. Navigate to this link for
additional useful information:
http://benalman.com/projects/javascript-debug-console-log/

WHAT ABOUT GOOGLE’S FORK OF WEBKIT?


As this book goes to print, Google made Blink available, which is
its fork of the WebKit engine. The code base for Blink (which some
people call “WebKit 2.0”) is already available in the version of
Chrome that was used to test the code samples in this book.
Although the code (and therefore the features) for Blink will
eventually diverge from the initial code base, the D3 code samples
will render the same in other WebKit-based browsers as they do in
Chrome-based browsers.

WHAT DO I NEED TO KNOW FOR THIS BOOK?


The most important prerequisite is familiarity with HTML Web
pages and JavaScript. If you want to be sure that you can grasp the
material in this book, glance through some of the code samples to
get an idea of how much is familiar to you and how much is new for
you.

WHAT ABOUT SVG?


No prior knowledge of SVG is required in order to learn D3. Keep
in mind that D3 and SVG use the same attribute names for the 2D
shapes that they both support, so if you already know the SVG-
based attributes, that knowledge is obviously helpful. Another point
to keep in mind is that even though D3 is a JavaScript-based “layer”
over SVG, you can also use D3 with HTML5 Canvas, which is
discussed in detail in an appendix.

WHY DOES THIS BOOK HAVE 250 PAGES INSTEAD


OF 500 PAGES?
This book is part of a Pocket Primer series whose books are
between 200 and 250 pages. Second, the target audience consists of
readers ranging from beginners to intermediate in terms of their
knowledge of HTML and JavaScript. During the preparation of this
book, every effort has been made to accommodate those readers so
that they will be adequately prepared to explore more advanced
features of D3 during their self study.
WHY SO MANY CODE SAMPLES IN THE CHAPTERS?
One of the primary rules of exposition of virtually any kind is
“show, don’t tell.” While this rule is not taken literally in this book, it’s
the motivation for showing first and telling second. You can decide
for yourself if show-first-then-tell is valid in this book by performing
a simple experiment: when you see the code samples and the
accompanying graphics effects in this book, determine if it’s more
effective to explain (“tell”) the visual effects or to show them. If the
adage “a picture is worth a thousand words” is true, then this book
endeavors to provide both the pictures and the words.

WHY SO MANY CODE SAMPLES ON THE CD?

The CD contains more than 1,000 code samples that vary from
simple to moderate complexity using different combinations of
technologies. Specifically, there are D3-based code samples along
with “pure” SVG and “pure” CSS3 samples. In addition, you’ll find
code samples that combine D3 with SVG, D3 with CSS3, SVG and
CSS3. The code samples that combine CSS3 and SVG create 3D
animation effects, whereas the pure SVG samples only create static
effects.
In the code samples that are similar (admittedly there are many
on the CD), they are included as a convenience, and their purpose is
to show you stylistic nuances. Obviously the value of those subtle
differences is highly subjective and impossible to quantify, which
means that each person will evaluate the code samples in a different
manner. As a parenthetical yet relevant aside: in the art world there
can be two very similar original paintings by two different artists,
and yet one painting is valuable whereas the other has much lower
perceived value. Putting aside the intrinsic value of the code samples
on the CD, it’s likely that some of them appeal to you and not to
other people (and vice versa).
Think of the code samples as “concept code” in the sense that
they provide you with ideas that you can borrow and enhance even
further with your own variations. This approach of progressively
adding details to provide you with a “swatch-like” variety of code
samples will accommodate a range of reading styles, and you can
jump in wherever you feel most comfortable. Since there will be
concepts that cannot be fully discussed (due to the limited page
count), the inclusion of similar code samples will make it simpler for
you to grasp the additional techniques during your independent
study.
The key points to keep in mind is that supplemental code samples
on the CD show you stylistic variations and they save you the time
required to create those samples, but you can choose to view them
or to ignore them.

DOESN’T THE CD OBVIATE THE NEED FOR THIS


BOOK?
The CD contains all the code samples to save you time and effort
from the error-prone process of manually typing code into an HTML
Web page. In addition, there are situations in which you might not
have easy access to CD. Furthermore, the code samples in the book
provide explanations that are not available on the CD.
Finally, as mentioned earlier in this Preface, there are some
introductory videos available that cover HTML5, CSS3, HTML5
Canvas, and SVG. Navigate to the publisher’s Website to obtain more
information regarding their availability.

DOES THIS BOOK CONTAIN PRODUCTION-LEVEL


CODE SAMPLES?
The primary purpose of the code samples in this book is to
illustrate various features of the D3 toolkit. Clarity has higher priority
than writing more compact code that is more difficult to understand
(and possibly more prone to bugs). If you decide to use any of the
code in this book in a production Website, you ought to subject that
code to the same rigorous analysis as the other parts of your HTML
Web pages.

WHICH VERSION OF D3 IS FOR THIS BOOK?


The code samples in this book use version 3.0 of D3 (released in
December, 2012), which is currently the latest version of D3. If you
plan to use an older version of D3, you need to test the D3 code
samples in this book to ensure that they work with that older
version.

TERMINOLOGY IN THIS BOOK


You will see variations in the way that D3 methods are described.
For example, you will see “the D3 method .transition()” and “the
method d3.transition()” used interchangeably in this book. As
another example, you will see “an HTML <script> element” and “a
<script> element,” both of which refer to the same thing.

OTHER RELATED BOOKS BY THE AUTHOR


1. HTML5 Canvas and CSS3:
http://www.amazon.com/HTML5-Canvas-CSS3-Graphics-
Primer/dp/1936420341
2. jQuery, HTML5, and CSS3:
http://www.amazon.com/jQuery-HTML5-Mobile-Desktop-
Devices/dp/1938549031
3. HTML5 Pocket Primer:
http://www.amazon.com/HTML5-Pocket-Primer-Oswald-
Campesato/dp/1938549104
4. jQuery Pocket Primer:
http://www.amazon.com/dp/1938549147
Upcoming book by the author:
http://www.amazon.com/HTML5-Canvas-Pocket-Oswald-
Campesato/dp/1938549678/ref=sr_1_2?
ie=UTF8&qid=1434753297&sr=8-
2&keywords=html5+canvas+pocket+primer

The following open source projects contain code samples that


supplement the material in various chapters of this book:
https://github.com/ocampesato/angular-graphics
https://github.com/ocampesato/css3-graphics
https://github.com/ocampesato/d3-graphics
https://github.com/ocampesato/html5-graphics
https://github.com/ocampesato/jquery-css3-graphics
https://github.com/ocampesato/raphael-graphics
https://github.com/ocampesato/reactjs-graphics
https://github.com/ocampesato/svg-filters-graphics
https://github.com/ocampesato/svg-graphics
CHAPTER 1

INTRODUCTION TO D3

T his chapter introduces you to D3 and provides a collection of


short code samples that illustrate how to use some useful D3
application programming interfaces (API). This chapter moves
quickly, so even if you are already familiar with D3 it’s worth your
while to read (or at least skim through) the material in this chapter.
The code samples in subsequent chapters use many of the APIs that
are discussed in this chapter.
The first part of this chapter provides a brief description of the D3
toolkit and a list of some companies that use D3. The second part of
this chapter shows you how to use some basic D3 methods by
rendering simple two-dimensional (2D) shapes. In addition, you will
learn how to create linear gradients and radial gradients.

NOTE
Be sure to launch the HTML Web pages in a browser as you read
code samples in this book because this will show you what the
code actually does, and it will also save you time understanding
the code.

WHAT IS D3?
Mike Bostock created the open-source toolkit Protovis, and then
he created the D3 toolkit, which is a JavaScript-based open-source
project for creating very appealing data visualization. D3 is an
acronym for “Data-Driven Documents,” and its homepage is here:

http://mbostock.github.com/d3/
Although D3 can be used for practically any type of data
visualization, common use-cases include rendering maps,
geographic-related data, economic data (such as employment
figures) in conjunction with various locales, and medical data
(diabetes seems to be very popular).
In December of 2011, D3 was named the data-visualization
project of the year (by Flowing Data!), which is not surprising when
you see the functionality that is available in D3.
D3 provides a layer of abstraction that generates underlying
Scalable Vector Graphics (SVG) code. D3 enables you to create a
surprisingly rich variety of data visualizations. If you need to
generate graphics-oriented Web pages, and you prefer to work with
JavaScript instead of working with raw SVG, then you definitely
ought to consider using D3. Two key aspects of D3 involve tools for
reading data in multiple formats and the ability to transform the data
and render the data in many forms. D3 supports the following
features:

• creation of SVG-based 2D shapes


• 2D graphics and animation effects
• method chaining

D3 has an extensive collection of “helper methods,” such as


select(), append(), data(), and attr(), among others. Read the
online documentation about these and other D3 methods.

D3 ON MOBILE DEVICES
D3 works on any device that supports JavaScript and SVG,
including mobile devices such as smart phones and tablets. These
devices do vary in terms of their support for SVG features. For
instance, Android 3.x has some support for SVG, and currently no
version of Android supports SVG filters (discussed in Chapter 3 and
Chapter 5). In general, iOS devices support more SVG features than
Android-based mobile devices.
If you are writing HTML Web pages for desktops as well as mobile
devices, you probably need to take into account scenarios such as
handling mouse-related events versus touch-related events. In
particular, you ought to test multitouch support on multiple mobile
devices and operating systems to ensure that your Web pages
exhibit the expected behavior.
In addition, you might encounter D3 bugs on mobile devices that
are not readily apparent in HTML Web pages laptops or desktops. If
you do encounter inconsistent behavior, check the issues-related link
in the previous section to see if it’s a known issue. If you do not find
entries, it’s possible that you have discovered an unreported bug in
D3, in which case you can file a new issue.

D3 BOILERPLATE
If you have worked with HTML5, you are probably familiar with
various boilerplate toolkits that are available. In a similar spirit, you
can download a D3 boilerplate toolkit (d3.js-boilerplate) here:

https://github.com/zmaril/d3.js-boilerplate

According to the D3 Boilerplate Website, “d3.js boilerplate is an


opinionated template system designed to help you build a
sophisticated data-driven document as fast as possible. By providing
a full-featured template and encouraging the use of useful tools, this
project aims to help developers passively and actively cut down on
development time.” If you are a D3 novice, you might not be ready
to use this toolkit, but it’s a good idea to be aware of its
functionality.
This concludes the brief introduction to D3. The next section of
this chapter introduces you to the concept of method chaining to
facilitate the discussion of subsequent code samples.

METHOD CHAINING IN D3
Practically every code sample in this book (and almost all the
online code samples in various forums) use method chaining, so it’s
worth your time to understand method chaining before delving into
the code samples.
The key idea to remember is that a D3 search actually returns a
result set that is the set of elements that match the selection
criteria. You can then apply an action to that set of elements. For
example, you can find all the paragraphs in an HTML Web page and
then set their text in red. Here is an example (taken from Listing
1.1) that uses the d3.selectAll() method to select all the HTML
<p> elements in an HTML Web page and then invokes the style()
method to set the color of the text in those paragraphs in red:

d3.selectAll(“p”).style(“color”, “red”);

Returning to our previous discussion, after applying an action to a


set of elements, a new set of elements is returned. In fact, you can
apply a second action to that modified set, which returns yet another
set. This process of applying multiple methods to a set is called
method chaining, and the good news is that you can chain together
as many function invocations as you wish. Method chaining enables
you to write very compact yet powerful code, as you will see in the
code examples in this chapter.

THE D3 METHODS SELECT() AND SELECTALL()


D3 supports various selection-based methods that return arrays of
arrays of elements to maintain the hierarchical structure of
subselections. D3 also binds additional methods to the array of
selected elements thereby enabling you to perform operations on
those elements.
D3 provides the method selectAll() that you saw in the previous
section and the method select(). Both methods accept selector
strings, and both are used for selecting elements. The select()
method selects only the first matching element, whereas the
selectAll() method selects all matching elements (in document
traversal order). Due to space constraints, this chapter covers a
modest subset of the D3 selection-based methods, but you can find
a complete list of methods here:

https://github.com/mbostock/d3/wiki/Selections

SPECIFYING UTF-8 IN HTML5 WEB PAGES WITH D3


All versions of D3 require UTF-8, and failing to specify UTF-8 can
cause HTML5 Web pages to behave unpredictably (depending on the
browser). You can ensure that your HTML5 Web pages with D3 code
will work correctly by including the following snippet immediately
after the <head> element:

<meta charset=”utf-8” />

In particular, the preceding tag will ensure that your HTML5 Web
pages with D3 and Unicode characters will work correctly. You will
see an example of D3 with Unicode characters in Chapter 4.

CREATING NEW HTML ELEMENTS


The code sample in this section uses method chaining, the D3
.select() method, and the d3.append() method to modify an HTML
Web page. This simple example shows you how to use these two
useful D3 methods.
Listing 1.1 displays the contents of AppendElement1.html that
illustrates how to add an HTML <p> element to an HTML Web page.

LISTING 1.1 AppendElement1.html


Listing 1.1 starts by referencing the D3 JavaScript file d3.js. Next,
the <script> element appends four HTML <p> elements to the
<body> element using the d3.select() method. Finally, Listing 1.1
changes the color of all four HTML <p> elements to red with this
code snippet:

d3.selectAll(“p”).style(“color”, “red”);

Incidentally, if you want to alternate the colors in the four HTML


<p> elements, insert the following code in Listing 1.1:

The preceding code snippet uses a ternary operator to return the


color #f00 for even-numbered HTML <p> elements and #eee for odd-
numbered HTML <p> elements.

NOTE
Some older browsers run JavaScript code before the Document
Object Model (DOM) is available, in which case you can either use
window.onload() to ensure that this does not happen, or you can
insert an empty <div></div> element immediately after the
<body> element and change the occurrences of
d3.select(“body”) to d3.select(“div”). Figure 1.1 displays the
graphics image that is rendered by the code in the HTML Web
page in Listing 1.1.

FIGURE 1.1 Dynamically Appending <p> Elements Using D3.

THE MOST COMMON IDIOM IN D3


The most common idiom in D3 (TMCIID3) for programmatically
creating new DOM elements uses the following type of construct
(which, of course, involves method chaining):

Here is how to read the code in the preceding code block, starting
from the definition of the paras variable:
Step 1: Start by selecting the <body> element of the current HTML
Web page (using the select() method).
Step 2: Return the result set of all the child <p> elements using
the selectAll() method (if there are no child <p> elements, the
returned set is a set of length zero).
Step 3: Iterate or loop through the numbers in the JavaScript
array theData to create a new HTML <p> element whose text value is
the string D3.
Step 4: After each iteration in Step 3, append the newly created
<p> element to the result set in Step 2.

NOTE
The d3.selectAll() method always returns a result set, which
can be an empty set (and therefore, this method never returns a
null or undefined value).

When the preceding code snippet has completed, the JavaScript


variable paras will consist of five new HTML <p> elements. If you
understand this sequence of events, you are ready for the code
sample in the next section. If you do not understand, then continue
to the next section and launch the HTML Web page in a browser to
convince yourself that the preceding explanation is correct.
The acronym TMCIID3 is a convenient way to refer to the D3 code
snippet that was discussed in this section, and you will see this
acronym used in the code samples throughout this book.

BINDING DATA TO DOCUMENT-OBJECT-MODEL


ELEMENTS
Now that you understand method chaining and how to use the
most common idiom in D3, you are ready to see how to perform
both in an HTML Web page.
Listing 1.2 displays the contents of Binding1.html that illustrates
how to combine JavaScript variables with the D3 methods .data()
and .text()to append a set of HTML <p> elements to an HTML Web
page.
LISTING 1.2 Binding1.html

Listing 1.2 starts by referencing the D3 JavaScript file; the code in


the <script> element has already been discussed in the preceding
section. The only new code in Listing 1.2 is the following code
snippet:

d3.select(“body”).append(“paras”);

The preceding code snippet appends the contents of the paras


variable, which consists of five new HTML <p> elements, to the
existing HTML <p> elements (if there are any) that are child
elements of the <body> element.

NOTE
Because every HTML Web page in this book starts with the same
boilerplate code in the HTML <head> element, we will omit this
duplicated description for the rest of the book.

Figure 1.2 displays the result of rendering the HTML Web page in
Listing 1.2 in a Web browser.

FIGURE 1.2 Using TMCIID3 to Generate <p> Elements in a Web Page.

GENERATING TEXT STRINGS


The code sample in the previous section simply generated a set of
text strings with the same text. In this section, you will see how to
generate a set of text strings that contain the numbers in a
JavaScript array.
Listing 1.3 displays the contents of GenerateText1.html that
illustrate how to iterate through a JavaScript array (containing
numbers) and render text strings with the values in the array.

LISTING 1.3 GenerateText1.html


Listing 1.3 contains a <script> element that initializes a JavaScript
variable, dataValues1, followed by TMCIID3 to create and append a
set of new HTML <p> elements to the existing HTML Web page. The
only new construct is the use of a function, as shown in the
following code snippet:

.text(function(d) { return “Paragraph Number: “+d; })

When you define a function in TMCIID3, D3 understands that it


must populate the variable d with the value of the current iteration
through the numbers in the JavaScript array dataValues1.
You can use any legitimate name that you want in the preceding
function, but perhaps it helps to think of the variable d as datum, or
a single piece of data (such as a number in an array). Later, you will
see functions that specify a datum and an index using the following
syntax:
.text(function(d, i) { return d[i]; })

Figure 1.3 displays the result of rendering the HTML Web page in
Listing 1.3 in a Web browser.

FIGURE 1.3 Using an Array to Generate <p> Elements With Simple Styling
Effects. The next section shows you how to leverage what you have learned about
D3 to render various 2D shapes in an HTML Web page.

CREATING SIMPLE TWO-DIMENSIONAL SHAPES


This section contains a code sample that shows you how to create
simple 2D shapes in D3. The D3 code specifies attributes that are
the same as the SVG-based attributes for each 2D shape. For
example, an ellipse is defined in terms of its center point (cx, cy),
its major axis rx, and its minor axis ry. Similar comments apply for
creating a rectangle (x, y, width, and height attributes) and for
creating a line segment ((x1,y1) and (x2,y2) as the coordinates of
the two endpoints of the line segment). In fact, Listing 1.4 is nothing
more than using TMCIID3 and the D3 .attr() method to set the
attributes of various 2D shapes. Note that in Chapter 5 you will learn
about the SVG attributes for numerous 2D shapes.
Listing 1.4 displays the contents of SimpleShapes1.html that
illustrates how to create a circle, an ellipse, a rectangle, and a line
segment in D3.
LISTING 1.4 SimpleShapes1.html
Listing 1.4 contains a <script> element that creates multiple SVG
elements and uses the D3 .attr() method to set the value of the
attributes of each SVG element. When you launch the HTML Web
page in Listing 1.4, D3 appends the following code block to the
existing HTML Web page:

Compare the code in Listing 1.4 with the preceding code block to
verify that the preceding SVG elements correspond to the code in
Listing 1.4. You can use an alternate coding style that defines
multiple JavaScript variables, as shown in the following code block:
Figure 1.4 displays the graphics image that is rendered by the
code in the HTML Web page in Listing 1.4.

FIGURE 1.4 D3 Code for a Circle, an Ellipse, a Rectangle, and a Line Segment.

BEZIER CURVES AND TEXT


Listing 1.5 displays the contents of BezierCurvesAndText1.html
that illustrates how to use D3 to render a quadratic Bezier curve, a
cubic Bezier curve, and text strings that follow the path of the Bezier
curves.

LISTING 1.5 BezierCurvesAndText1.html


Listing 1.5 contains the usual boilerplate code and a <script>
element that defines a quadratic Bezier curve and a cubic Bezier
curve. The JavaScript variables bezierC, bezierQ, textC, and textQ
are set to the values for a cubic Bezier curve, a quadratic Bezier
curve, the text for the cubic Bezier curve, and the text for the
quadratic Bezier curve, respectively. These variables are used in the
D3 code that creates a <path> element, which is how you specify
quadratic and cubic Bezier curves in SVG.
As you can see, most of the code in Listing 1.5 does two things: it
creates SVG elements with the D3 .append() method, and it then
sets the required attributes with the D3 .attr() method.
Moreover, the definitions for the cubic Bezier curve and the
quadratic Bezier curve consist of a string of values, as shown here:

In fact, if you want to use standard SVG code instead of D3, you
could literally copy and paste the preceding strings as the value for
the d attribute in the SVG <path> element.
Figure 1.5 displays the graphics image that is rendered by the
code in the HTML Web page in Listing 1.5.

FIGURE 1.5 Generating Text Along Two Bezier Curves in D3.

TWO-DIMENSIONAL TRANSFORMS
D3 provides support for four 2D transforms: rotate, scale, skew,
and translate. You can apply transforms to 2D shapes using the D3
.attr() method, as shown in the following examples:

The CD contains the HTML Web page Transforms1.html that fully


illustrates how to create four 2D transform effects.

A DIGRESSION: SCALING ARRAYS OF NUMBERS TO


DIFFERENT RANGES
This section covers the d3.range() method for determining the
range of a set of numbers followed by the d3.scale() function for
scaling a set of numbers. The rationale for including this section here
is that the d3.range() method is used in the gradient-related code
samples that you will see later in this chapter. This method is both
easy to use and straightforward to understand, and you will see this
method in many code samples in this book.
When you work with D3 functions that scale the values in an
array, keep in mind that the domain specifies the input values that
you provide, and the range refers to the target values that are
calculated based on the domain values.
The simplest use of the d3.range() method is to generate a list of
integers. For example, d3.range(15) generates the integers between
0 and 14. You can verify this fact by including the following code
snippet in a D3-based HTML Web page:

console.log(“range from 0 to 14: “+d3.range(15))

When you open the Web Inspector (see comments in the Preface)
you will see the following:
Another random document with
no related content on Scribd:
But no one loves the scenes of nature more than I. The first
sunset that I remember with enjoyment occurred when I was ten
years old; and how many I have seen since then! On an autumn day
in 1903, I saw the sun sink into the ocean off the coast of Normandy,
and, by the miracle of memory, I can see it again whenever I wish. I
thought of Browning’s lines:

“Than by slow, pallid sunsets in autumn, ye watch from the shore,


At their sad level gaze o’er the ocean—a sun’s slow decline.”

I have seen the Matterhorn from the Gorner Grat, Mont Blanc
from Chamonix, and the divine flush on the summit of the Jungfrau.
Forty years ago I heard for the first time the Ninth Symphony;
and while I have heard it often since then, the most memorable
occasion was in May 1912 when I heard it at Paris, played by a
magnificent orchestra, conducted by Felix Weingartner; I have heard
Die Meistersinger in Munich, conducted by Arthur Nikisch; I have
heard the Emperor Concerto, with Ossip Gabrilowitsch at the piano; I
have heard Tod und Verklärung with Stokowski and the Philadelphia
Orchestra; I have heard De Pachmann (in his prime) play Chopin’s B
flat minor sonata, Paderewski play Liszt’s Hungarian Rhapsody No.
2, Josef Hofmann play Beethoven’s Sonata 111. I have heard
Carmen sung by Emma Calvé, Emma Eames, Jean de Reszké and
Lassalle; Tristan und Isolde sung by Jean de Reszké and Lilli
Lehmann; Faust sung by Jean and Edouard de Reszké, Emma
Eames, Maurel, and Scalchi; Mignon sung by Mme. Lucrezia Bori; I
have repeatedly heard the three greatest bassos of modern times,
Edouard de Reszké, Pol Plançon, and Chaliapin.
In the theatre I have seen Edwin Booth as Shylock, Mansfield as
Richard III, Irving in The Lyons Mail, Possart as Mephistopheles,
Sarah Bernhardt as La Tosca, Duse as Francesca, Salvini as
Othello, and twice have I seen the Passion Play at Oberammergau.
All these are memorable experiences, and for fear I may not be
conscious when I am dying, I am recalling them now. But if I should
attempt to recall all the glorious things I have seen in nature and in
art, I should have no time for fresh experiences that await me.
As for social pleasures, one of the highest enjoyments is
agreeable company and good conversation; and I especially like
men, women and children.
Transcriber’s Notes
Punctuation, hyphenation, and spelling were made
consistent when a predominant preference was found in the
original book; otherwise they were not changed.
Simple typographical errors were corrected; unbalanced
quotation marks were remedied when the change was
obvious, and otherwise left unbalanced.
Just for the curious: Chapter XVIII has four references to
“F. P. A.” but doesn’t give the full name. When this book was
written, he was a well-known columnist: Franklin P. Adams.
*** END OF THE PROJECT GUTENBERG EBOOK ESSAYS ON
THINGS ***

Updated editions will replace the previous one—the old editions


will be renamed.

Creating the works from print editions not protected by U.S.


copyright law means that no one owns a United States copyright
in these works, so the Foundation (and you!) can copy and
distribute it in the United States without permission and without
paying copyright royalties. Special rules, set forth in the General
Terms of Use part of this license, apply to copying and
distributing Project Gutenberg™ electronic works to protect the
PROJECT GUTENBERG™ concept and trademark. Project
Gutenberg is a registered trademark, and may not be used if
you charge for an eBook, except by following the terms of the
trademark license, including paying royalties for use of the
Project Gutenberg trademark. If you do not charge anything for
copies of this eBook, complying with the trademark license is
very easy. You may use this eBook for nearly any purpose such
as creation of derivative works, reports, performances and
research. Project Gutenberg eBooks may be modified and
printed and given away—you may do practically ANYTHING in
the United States with eBooks not protected by U.S. copyright
law. Redistribution is subject to the trademark license, especially
commercial redistribution.

START: FULL LICENSE


THE FULL PROJECT GUTENBERG LICENSE
PLEASE READ THIS BEFORE YOU DISTRIBUTE OR USE THIS WORK

To protect the Project Gutenberg™ mission of promoting the


free distribution of electronic works, by using or distributing this
work (or any other work associated in any way with the phrase
“Project Gutenberg”), you agree to comply with all the terms of
the Full Project Gutenberg™ License available with this file or
online at www.gutenberg.org/license.

Section 1. General Terms of Use and


Redistributing Project Gutenberg™
electronic works
1.A. By reading or using any part of this Project Gutenberg™
electronic work, you indicate that you have read, understand,
agree to and accept all the terms of this license and intellectual
property (trademark/copyright) agreement. If you do not agree to
abide by all the terms of this agreement, you must cease using
and return or destroy all copies of Project Gutenberg™
electronic works in your possession. If you paid a fee for
obtaining a copy of or access to a Project Gutenberg™
electronic work and you do not agree to be bound by the terms
of this agreement, you may obtain a refund from the person or
entity to whom you paid the fee as set forth in paragraph 1.E.8.

1.B. “Project Gutenberg” is a registered trademark. It may only


be used on or associated in any way with an electronic work by
people who agree to be bound by the terms of this agreement.
There are a few things that you can do with most Project
Gutenberg™ electronic works even without complying with the
full terms of this agreement. See paragraph 1.C below. There
are a lot of things you can do with Project Gutenberg™
electronic works if you follow the terms of this agreement and
help preserve free future access to Project Gutenberg™
electronic works. See paragraph 1.E below.
1.C. The Project Gutenberg Literary Archive Foundation (“the
Foundation” or PGLAF), owns a compilation copyright in the
collection of Project Gutenberg™ electronic works. Nearly all the
individual works in the collection are in the public domain in the
United States. If an individual work is unprotected by copyright
law in the United States and you are located in the United
States, we do not claim a right to prevent you from copying,
distributing, performing, displaying or creating derivative works
based on the work as long as all references to Project
Gutenberg are removed. Of course, we hope that you will
support the Project Gutenberg™ mission of promoting free
access to electronic works by freely sharing Project
Gutenberg™ works in compliance with the terms of this
agreement for keeping the Project Gutenberg™ name
associated with the work. You can easily comply with the terms
of this agreement by keeping this work in the same format with
its attached full Project Gutenberg™ License when you share it
without charge with others.

1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside
the United States, check the laws of your country in addition to
the terms of this agreement before downloading, copying,
displaying, performing, distributing or creating derivative works
based on this work or any other Project Gutenberg™ work. The
Foundation makes no representations concerning the copyright
status of any work in any country other than the United States.

1.E. Unless you have removed all references to Project


Gutenberg:

1.E.1. The following sentence, with active links to, or other


immediate access to, the full Project Gutenberg™ License must
appear prominently whenever any copy of a Project
Gutenberg™ work (any work on which the phrase “Project
Gutenberg” appears, or with which the phrase “Project
Gutenberg” is associated) is accessed, displayed, performed,
viewed, copied or distributed:

This eBook is for the use of anyone anywhere in the United


States and most other parts of the world at no cost and with
almost no restrictions whatsoever. You may copy it, give it
away or re-use it under the terms of the Project Gutenberg
License included with this eBook or online at
www.gutenberg.org. If you are not located in the United
States, you will have to check the laws of the country where
you are located before using this eBook.

1.E.2. If an individual Project Gutenberg™ electronic work is


derived from texts not protected by U.S. copyright law (does not
contain a notice indicating that it is posted with permission of the
copyright holder), the work can be copied and distributed to
anyone in the United States without paying any fees or charges.
If you are redistributing or providing access to a work with the
phrase “Project Gutenberg” associated with or appearing on the
work, you must comply either with the requirements of
paragraphs 1.E.1 through 1.E.7 or obtain permission for the use
of the work and the Project Gutenberg™ trademark as set forth
in paragraphs 1.E.8 or 1.E.9.

1.E.3. If an individual Project Gutenberg™ electronic work is


posted with the permission of the copyright holder, your use and
distribution must comply with both paragraphs 1.E.1 through
1.E.7 and any additional terms imposed by the copyright holder.
Additional terms will be linked to the Project Gutenberg™
License for all works posted with the permission of the copyright
holder found at the beginning of this work.

1.E.4. Do not unlink or detach or remove the full Project


Gutenberg™ License terms from this work, or any files
containing a part of this work or any other work associated with
Project Gutenberg™.
1.E.5. Do not copy, display, perform, distribute or redistribute
this electronic work, or any part of this electronic work, without
prominently displaying the sentence set forth in paragraph 1.E.1
with active links or immediate access to the full terms of the
Project Gutenberg™ License.

1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if
you provide access to or distribute copies of a Project
Gutenberg™ work in a format other than “Plain Vanilla ASCII” or
other format used in the official version posted on the official
Project Gutenberg™ website (www.gutenberg.org), you must, at
no additional cost, fee or expense to the user, provide a copy, a
means of exporting a copy, or a means of obtaining a copy upon
request, of the work in its original “Plain Vanilla ASCII” or other
form. Any alternate format must include the full Project
Gutenberg™ License as specified in paragraph 1.E.1.

1.E.7. Do not charge a fee for access to, viewing, displaying,


performing, copying or distributing any Project Gutenberg™
works unless you comply with paragraph 1.E.8 or 1.E.9.

1.E.8. You may charge a reasonable fee for copies of or


providing access to or distributing Project Gutenberg™
electronic works provided that:

• You pay a royalty fee of 20% of the gross profits you


derive from the use of Project Gutenberg™ works
calculated using the method you already use to calculate
your applicable taxes. The fee is owed to the owner of
the Project Gutenberg™ trademark, but he has agreed to
donate royalties under this paragraph to the Project
Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each
date on which you prepare (or are legally required to
prepare) your periodic tax returns. Royalty payments
should be clearly marked as such and sent to the Project
Gutenberg Literary Archive Foundation at the address
specified in Section 4, “Information about donations to the
Project Gutenberg Literary Archive Foundation.”

• You provide a full refund of any money paid by a user


who notifies you in writing (or by e-mail) within 30 days of
receipt that s/he does not agree to the terms of the full
Project Gutenberg™ License. You must require such a
user to return or destroy all copies of the works
possessed in a physical medium and discontinue all use
of and all access to other copies of Project Gutenberg™
works.

• You provide, in accordance with paragraph 1.F.3, a full


refund of any money paid for a work or a replacement
copy, if a defect in the electronic work is discovered and
reported to you within 90 days of receipt of the work.

• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.

1.E.9. If you wish to charge a fee or distribute a Project


Gutenberg™ electronic work or group of works on different
terms than are set forth in this agreement, you must obtain
permission in writing from the Project Gutenberg Literary
Archive Foundation, the manager of the Project Gutenberg™
trademark. Contact the Foundation as set forth in Section 3
below.

1.F.

1.F.1. Project Gutenberg volunteers and employees expend


considerable effort to identify, do copyright research on,
transcribe and proofread works not protected by U.S. copyright
law in creating the Project Gutenberg™ collection. Despite
these efforts, Project Gutenberg™ electronic works, and the
medium on which they may be stored, may contain “Defects,”
such as, but not limited to, incomplete, inaccurate or corrupt
data, transcription errors, a copyright or other intellectual
property infringement, a defective or damaged disk or other
medium, a computer virus, or computer codes that damage or
cannot be read by your equipment.

1.F.2. LIMITED WARRANTY, DISCLAIMER OF DAMAGES -


Except for the “Right of Replacement or Refund” described in
paragraph 1.F.3, the Project Gutenberg Literary Archive
Foundation, the owner of the Project Gutenberg™ trademark,
and any other party distributing a Project Gutenberg™ electronic
work under this agreement, disclaim all liability to you for
damages, costs and expenses, including legal fees. YOU
AGREE THAT YOU HAVE NO REMEDIES FOR NEGLIGENCE,
STRICT LIABILITY, BREACH OF WARRANTY OR BREACH
OF CONTRACT EXCEPT THOSE PROVIDED IN PARAGRAPH
1.F.3. YOU AGREE THAT THE FOUNDATION, THE
TRADEMARK OWNER, AND ANY DISTRIBUTOR UNDER
THIS AGREEMENT WILL NOT BE LIABLE TO YOU FOR
ACTUAL, DIRECT, INDIRECT, CONSEQUENTIAL, PUNITIVE
OR INCIDENTAL DAMAGES EVEN IF YOU GIVE NOTICE OF
THE POSSIBILITY OF SUCH DAMAGE.

1.F.3. LIMITED RIGHT OF REPLACEMENT OR REFUND - If


you discover a defect in this electronic work within 90 days of
receiving it, you can receive a refund of the money (if any) you
paid for it by sending a written explanation to the person you
received the work from. If you received the work on a physical
medium, you must return the medium with your written
explanation. The person or entity that provided you with the
defective work may elect to provide a replacement copy in lieu
of a refund. If you received the work electronically, the person or
entity providing it to you may choose to give you a second
opportunity to receive the work electronically in lieu of a refund.
If the second copy is also defective, you may demand a refund
in writing without further opportunities to fix the problem.
1.F.4. Except for the limited right of replacement or refund set
forth in paragraph 1.F.3, this work is provided to you ‘AS-IS’,
WITH NO OTHER WARRANTIES OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO
WARRANTIES OF MERCHANTABILITY OR FITNESS FOR
ANY PURPOSE.

1.F.5. Some states do not allow disclaimers of certain implied


warranties or the exclusion or limitation of certain types of
damages. If any disclaimer or limitation set forth in this
agreement violates the law of the state applicable to this
agreement, the agreement shall be interpreted to make the
maximum disclaimer or limitation permitted by the applicable
state law. The invalidity or unenforceability of any provision of
this agreement shall not void the remaining provisions.

1.F.6. INDEMNITY - You agree to indemnify and hold the


Foundation, the trademark owner, any agent or employee of the
Foundation, anyone providing copies of Project Gutenberg™
electronic works in accordance with this agreement, and any
volunteers associated with the production, promotion and
distribution of Project Gutenberg™ electronic works, harmless
from all liability, costs and expenses, including legal fees, that
arise directly or indirectly from any of the following which you do
or cause to occur: (a) distribution of this or any Project
Gutenberg™ work, (b) alteration, modification, or additions or
deletions to any Project Gutenberg™ work, and (c) any Defect
you cause.

Section 2. Information about the Mission of


Project Gutenberg™
Project Gutenberg™ is synonymous with the free distribution of
electronic works in formats readable by the widest variety of
computers including obsolete, old, middle-aged and new
computers. It exists because of the efforts of hundreds of
volunteers and donations from people in all walks of life.

Volunteers and financial support to provide volunteers with the


assistance they need are critical to reaching Project
Gutenberg™’s goals and ensuring that the Project Gutenberg™
collection will remain freely available for generations to come. In
2001, the Project Gutenberg Literary Archive Foundation was
created to provide a secure and permanent future for Project
Gutenberg™ and future generations. To learn more about the
Project Gutenberg Literary Archive Foundation and how your
efforts and donations can help, see Sections 3 and 4 and the
Foundation information page at www.gutenberg.org.

Section 3. Information about the Project


Gutenberg Literary Archive Foundation
The Project Gutenberg Literary Archive Foundation is a non-
profit 501(c)(3) educational corporation organized under the
laws of the state of Mississippi and granted tax exempt status by
the Internal Revenue Service. The Foundation’s EIN or federal
tax identification number is 64-6221541. Contributions to the
Project Gutenberg Literary Archive Foundation are tax
deductible to the full extent permitted by U.S. federal laws and
your state’s laws.

The Foundation’s business office is located at 809 North 1500


West, Salt Lake City, UT 84116, (801) 596-1887. Email contact
links and up to date contact information can be found at the
Foundation’s website and official page at
www.gutenberg.org/contact

Section 4. Information about Donations to


the Project Gutenberg Literary Archive
Foundation
Project Gutenberg™ depends upon and cannot survive without
widespread public support and donations to carry out its mission
of increasing the number of public domain and licensed works
that can be freely distributed in machine-readable form
accessible by the widest array of equipment including outdated
equipment. Many small donations ($1 to $5,000) are particularly
important to maintaining tax exempt status with the IRS.

The Foundation is committed to complying with the laws


regulating charities and charitable donations in all 50 states of
the United States. Compliance requirements are not uniform
and it takes a considerable effort, much paperwork and many
fees to meet and keep up with these requirements. We do not
solicit donations in locations where we have not received written
confirmation of compliance. To SEND DONATIONS or
determine the status of compliance for any particular state visit
www.gutenberg.org/donate.

While we cannot and do not solicit contributions from states


where we have not met the solicitation requirements, we know
of no prohibition against accepting unsolicited donations from
donors in such states who approach us with offers to donate.

International donations are gratefully accepted, but we cannot


make any statements concerning tax treatment of donations
received from outside the United States. U.S. laws alone swamp
our small staff.

Please check the Project Gutenberg web pages for current


donation methods and addresses. Donations are accepted in a
number of other ways including checks, online payments and
credit card donations. To donate, please visit:
www.gutenberg.org/donate.

Section 5. General Information About Project


Gutenberg™ electronic works
Professor Michael S. Hart was the originator of the Project
Gutenberg™ concept of a library of electronic works that could
be freely shared with anyone. For forty years, he produced and
distributed Project Gutenberg™ eBooks with only a loose
network of volunteer support.

Project Gutenberg™ eBooks are often created from several


printed editions, all of which are confirmed as not protected by
copyright in the U.S. unless a copyright notice is included. Thus,
we do not necessarily keep eBooks in compliance with any
particular paper edition.

Most people start at our website which has the main PG search
facility: www.gutenberg.org.

This website includes information about Project Gutenberg™,


including how to make donations to the Project Gutenberg
Literary Archive Foundation, how to help produce our new
eBooks, and how to subscribe to our email newsletter to hear
about new eBooks.

You might also like