D3 Data Driven Documents Pocket Primer 1st Edition Oswald Campesato
D3 Data Driven Documents Pocket Primer 1st Edition Oswald Campesato
D3 Data Driven Documents Pocket Primer 1st Edition Oswald Campesato
D3 Data Driven Documents Pocket Primer 1st Edition Oswald Campesato
1. Read Anytime Anywhere Easy Ebook Downloads at ebookmeta.com
D3 Data Driven Documents Pocket Primer 1st Edition
Oswald Campesato
https://ebookmeta.com/product/d3-data-driven-documents-
pocket-primer-1st-edition-oswald-campesato/
OR CLICK HERE
DOWLOAD EBOOK
Visit and Get More Ebook Downloads Instantly at https://ebookmeta.com
2. Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.
Data Science Fundamentals Pocket Primer 1st Edition Oswald
Campesato
https://ebookmeta.com/product/data-science-fundamentals-pocket-
primer-1st-edition-oswald-campesato/
ebookmeta.com
Bash for Data Scientists 1st Edition Oswald Campesato
https://ebookmeta.com/product/bash-for-data-scientists-1st-edition-
oswald-campesato/
ebookmeta.com
Data Structures in Java 1st Edition Oswald Campesato
https://ebookmeta.com/product/data-structures-in-java-1st-edition-
oswald-campesato/
ebookmeta.com
Artful Truths The Philosophy of Memoir 1st Edition Helena
De Bres
https://ebookmeta.com/product/artful-truths-the-philosophy-of-
memoir-1st-edition-helena-de-bres/
ebookmeta.com
3. Shapes of Tourism Employment: HRM in the Worlds of Hotels
and Air Transport 1st Edition Gwenaelle Grefe
https://ebookmeta.com/product/shapes-of-tourism-employment-hrm-in-the-
worlds-of-hotels-and-air-transport-1st-edition-gwenaelle-grefe/
ebookmeta.com
Advances in Neural Computation Machine Learning and
Cognitive Research V Selected Papers from the XXIII
International Conference on 1st Edition Boris
Kryzhanovsky
https://ebookmeta.com/product/advances-in-neural-computation-machine-
learning-and-cognitive-research-v-selected-papers-from-the-xxiii-
international-conference-on-1st-edition-boris-kryzhanovsky/
ebookmeta.com
Phenomenology of Bioethics Technoethics and Lived
Experience The International Library of Bioethics 84 Susi
Ferrarello (Editor)
https://ebookmeta.com/product/phenomenology-of-bioethics-technoethics-
and-lived-experience-the-international-library-of-bioethics-84-susi-
ferrarello-editor/
ebookmeta.com
Effective Trading in Financial Markets Using Technical
Analysis 1st Edition Smita Roy Trivedi
https://ebookmeta.com/product/effective-trading-in-financial-markets-
using-technical-analysis-1st-edition-smita-roy-trivedi/
ebookmeta.com
Schaum s Outline of Probability Random Variables and
Random Processes 4th Edition Hwei P Hsu
https://ebookmeta.com/product/schaum-s-outline-of-probability-random-
variables-and-random-processes-4th-edition-hwei-p-hsu/
ebookmeta.com
4. NFPA 92 Standard for Smoke Control Systems 2021 Edition
National Fire Protection Association
https://ebookmeta.com/product/nfpa-92-standard-for-smoke-control-
systems-2021-edition-national-fire-protection-association/
ebookmeta.com
7. 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.
10. I’d like to dedicate this book to my parents – may
this bring joy and happiness into their lives.
11. 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
12. 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
13. 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
14. 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
15. 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
16. T
PREFACE
WHAT IS THE PRIMARY VALUE PROPOSITION FOR
THIS BOOK?
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.
17. 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
18. 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.
19. 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.
20. 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).
21. 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
22. (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
23. 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
24. T
CHAPTER 1
INTRODUCTION TO D3
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/
25. 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.
26. 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
27. 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
28. 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
29. 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
30. 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).
31. 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.
32. 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
33. 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
34. 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:
35. .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.
38. 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:
39. 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
42. 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
43. 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
44. .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:
46. with a club thorough the Air, those of the contrary side catching it at
the fall; and if any one chance to catch it in his hands, before it
touch ground, then the order of the play is inverted, and this side
strikes out the ball, the other is fain to catch. Thus play the men and
women, the boies and girles together, nor do the men shew
themselves more expert at it then the women. They besides have
another play at ball: in the hard frozen snow they draw two lines at
some distance from one another, then all the multitude both of men
and women parting into two sides, one applies it self to the defence
of this, the other of that line; then they meet in the middle space
between their two goals, and fling down the ball, then each partie
with bandies and clubs strives to strike the ball cross the opposite
parties line, each party still maintaining the defence of its own line;
but if one side chance to strike the ball with their bandies over the
others line (for it is foul play to fling it with their hands) and so take
their goal, that is accounted the conquering side. The sports as yet
mentioned are such as belong to the younger sort, as well as to
those of more mature age: the next is peculiar to these last and only
to men. Their custom is to separate themselves into two companies,
and attacque one another by wrestling: first each company stands
like a file of Soldiers all along in order to confront the adverse
company: then each man catches his adversary by the girdle,
wherewith all Laplanders are alwaies girt, as is elswhere shown,
(their girdle goes six times round their body, and so is fast and fittest
for their purpose,) so each man having caught hold, endeavors to
fling the other down, which they are not allowed to attempt by craft
or deceit, as by any lock or the like; Any one that is found delinquent
in this kind, is branded for a fowl plaier, and excluded the lists.
These are the sports that are almost peculiar to the Laplanders:
besides them they use some, which they borrow from other places,
such is playing at Cards, a sport sufficiently known thorough all
Europe, for even the Laplanders take no little satisfaction in it: they
procure their Cards of the Merchants that trade thither. They use
likewise to play at dice, which they themselves make of wood after
the common fashion, with this only difference, that whereas dice
commonly have some number of spots inscribed on every side, they
47. have a figure made only on one side like an X. he wins in this sport,
that casting two Dies, on the top of either can show the X. their
stakes are usually Squirrils skins, or some small trifles, and in the
failance of these leaden bullets, which they use in their hunting to
charge their Guns withal: and it happens sometimes that a fellow
having lost all his bullets, in hope of repairing his damage by
winning again, not only at present will be sensible of the harm, but
being disappointed of his Hunting puts to stake and looses his future
acquisitions and hope of livelihood. These are the usual waies,
whereby the people of Lapland spend their leisure times and divert
themselves.
48. CHAP. XXV.
Of their Contracts and Marriages.
We have hitherto taken a survey of their ordinary imploiments, and
such as are almost every day in use, as well those peculiar to each
Sex, as common to both; likewise of their Divertisements and sports,
wherewith they use to intermingle those emploiments: It remains that
we treat of those businesses, which do not every day occur, but are
singular and solemn, and undertaken upon special occasions. And first
of what appertain to their Marriages; Concerning them ’tis most
memorable, that whenever any person purposes to marry, ’tis his first
business, to make search after a Maid well stock’d with Raindeers. For
the Laplanders have a custom, (as shall hereafter more particularly be
mentioned) of bestowing upon their Children soon after their birth,
some certain number of those Raindeers, and their increase is
accounted of, not as the Parents estate, but the Childs portion. She
therefore, that is best provided of them, is in most likely-hood of
meeting with an Husband. Nor have they regard to any thing else, as
either good breeding, or beauty, or other the common allurements of
woers. For they who dwell on a hard and barren soile are generally
solicitous concerning food, which because their Rain-deer afford, every
one thinks himself best secured against want when he is best provided
of them. As soon therefore as the young man has cast about him for a
wife, which is usually done at their public meetings for paying of taxes,
or upon the account of fairs; next he makes a journy to her parents,
taking along with him his father, if alive, and one or two more whom
he thinks will be most kindly welcome, but especially one who may
declare his affections, and win the favor of the Maids parents. When
they arrive at the hut, they are all kindly invited in, only the suiter is
fain to wait at door, and bestow his time in chopping wood, or some
such trivial business, till he be summon’d in also, for without express
49. permission ’tis uncivil in him to enter. When they have drank of the
Spirit of Wine, which the spokes-man brings, he applies himself to the
management of his province, discloses the Suiters affections to the
Daughter, and makes his address to her Father, that he will please to
bestow her in Marriage upon him. Which that he may atcheive with
more success, he honors the Father with the greatest titles and names
of renown that he can devise, at every one bowing the knee, as if he
were treating with a prince. He stiles him with the High and Mighty
Father, the Worshipful Father, as if he were one of the Patriarcks, the
best and most illustrious Father, and no doubt if they were acquainted
with the Roial title of His Majestie, He would not scruple to call him,
the most Majestic Father. The Wine, that the Suiter is supposed to
have brought along with him therewith to pay his respects to her
parents, whom he pretends to, they call either Pouristwyn (that is) the
Wine of prosperous access, or that Wine wherewith he designs to
caress his Father and Mother in Law, that are to be; or else, Soubowiin
(that is) the Wine of wooers which tis expedient for wooers to bestow,
thereby to procure permission of converse with the daughter, and gain
the favour and liking of the future Bride. But we must take notice, that
the business is nor proposed to the maid her self first, but her parents;
nor may the Suiter have any conference with her without their
permission. Nay ’tis the usual custom, at this time to dispatch her
away upon some sleevless arrand, either to the Rain-deers pastures in
the Woods, or a Neighbors hut, so as neither the Suiter nor any of his
company may have a sight of her; but if at last either she or some
other woman procure leave for Her of her Parents or kindred, to speak
to him, their entertainment finished he gets him out of the hut to his
sledg, and then takes out his woollen Cloth-Garments, (such as they
use to spruce themselves up withal, at their public Festivals, or more
solemn affairs) and what else is requisite to the present business:
when he has trimm’d himself up, he makes his address to his Mistress
and salutes her. Their manner of Salutation is by a kiss; in which that
they mainly aim at is, that each not only apply his mouth to the
others, but also that both their noses touch; for otherwise it goes not
for a true salute. Next he makes her a present of the rarest delicacies
that Lapland affords, the Rain-deers tongue, the Beavers flesh, and
other dainties, which she refuses to accept of in the presence of any
50. body; presently after she is call’d aside to some convenient place
without the hut, then if she profess her self willing to receive them,
the Suiter farther puts it to her, whether she will grant him leave, that
he may take his repose by her in the hut; if she grant it, ’tis concluded
between them of their future marriage: withal he presents his gifts
above mentioned. If she rejects his suit, she casts them all down at his
feet. The Bridegroom usually carries them in his bosom, before he
presents them. The full approbation of the Parents, and the celebration
of the wedding is used oftentimes to be deferr’d for a considerable
while, sometimes for two or three years together; and all that while
they bestow upon courting their Mistresses. The reason why their time
of Courtship or wooing proves so long, is because the Bridegroom is
necessitated to gratifie with frequent presents, the parents and friends
nearest in blood to the Bride, without the leave of each of which he
cannot compass the possession of her. This is expressed by Samuel
Rheen in these words, When any Person pretends marriage to the
Daughter of one of the richer sort, he is obliged to make a present to
her parents and nearest Kinsmen, such as is made for state to
Ambassadors or cheif Officers, as large as his means will reach to,
which present they call Peck, that is, Peices, every peice at least must
contain two marks of silver, that is, six ounces, there are some too,
that must contain twenty, forty, sometimes threescore ounces a peice,
such peices the Bridegroom is bound to bestow upon His Mistresses
parents and her near kindred. In what things these presents
particularly consist, I shall mention hereafter, for they do not give
barely silver, but moulded into some fashion, or other things besides;
while therefore the Bridegroom is emploied in procuring these pieces,
’tis no inconsiderable while that passes.
In this interval he ever and anon makes a visit to his Mistress, to
whom while he is travelling he solaces himself with a Love Song, and
diverts the wearisomness of his journy. And ’tis their common custom,
to use such kind of Songs, not with any set tune, but such as every
one thinks best himself, nor in the same manner, but sometimes one
way, sometimes another, as goes best to every man, when he is in the
mode of singing. An ensampel of one they use in the Winter season,
communicated to me by Olaus Matthias, a Laplander, I here annex.
51. Kulnasatz niraosam æugaos joao audas jordee skaode
Nurte waota waolges skaode
Abeide kockit laidi ede
Fauruogaoidhe sadicde
Ællao momiaiat kuekan kaigewarri.
Patzao buaorest kællueiaur tuuni
Maode paoti millasan
Kaiga waonaide waiedin
Aogo niraome buaorebæst
Nute aotzaon sargabæst
Taide sun monia lii aigoamass
Saraogaoin waolgat amass
Ios iuao sarga aoinasim
Kiuresam katzesim
Kulnaasatz nirasam
Katze aoinakaos tun su salm.
The meaning of this Song is this,
52. Kulnasatz my Rain-deer
We have a long journy to go;
The Moor’s are vast,
And we must hast,
Our strength I fear
Will fail if we are slow,
And so
Our Songs will do.
Kaigè the watery Moor
Is pleasant unto me,
Though long it be;
Since it doth to my Mistriss lead,
Whom I adore;
The Kilwa Moor,
I nere again will tread.
Thoughts fill’d my mind
Whilst I thro Kaigè past.
Swift as the wind,
And my desire,
Winged with impatient fire,
My Rain-deer let us hast.
So shall we quickly end our pleasing pain:
Behold my Mistresse there,
With decent motion walking ore the Plain.
Kulnasatz my Rain-deer;
Look yonder, where
She washes in the Lake.
See while she swims,
The waters from her purer limbs
New cleerness take.
This is a love Song of the Laplanders, wherewith they incourage
their Rain-deers to travell nimbly along. For all delay, tho in it self
53. short, is tedious to lovers. They use too at other times to entertain
themselves with such Sonnets, when at some distance from their
Mistresses, and therein to make mention of them, and extoll their
beauty. One of this kind I received of the said Olaus, and seeing we
have lit upon this subject, I here set it down.
54. Pastos paiwa Kiufwresist jawra Orre Iawra
Ios kaosa kirrakeid korngatzim
Ia tiedadzim man oinæmam jaufre Orre Jawra
Ma tangast lomest lie sun lie
Kaika taidæ mooraid dzim soopadzim
Mak taben sadde sist oddasist
Ia poaka taidæ ousid dzim karsadzim
Makqwodde roamaid poorid ronaid
Kuliked palwaid tim suteatim
Mak kulki woasta Iaufræ Orre Iaufræ
Ios mun tæckas dzim kirdadzim sææst worodzæ sææst
Æ muste læ sææ dziodgæ sææ maina taockao kirdadzim
Æka læ Iulgæ songiaga Iulgæ, akælæ siædza
Fauron sietza, maan koima lusad
Dzim norbadzim.
Kalle ju leck kucka madzie wordamadzie
Morredabboit dadd paiwidad, linna sabboid
Dadd salmidad liegæ sabboid waimodadd
Ius kuckas sick patæridziek
Tannagtied sarga dzien iusadzim
Mi os matta lædæ sabbo Korrassabbo
Nu ly paddæ soona paddæ, ia salwam route salwam
Kæk dziabræi siste karrasistæ.
In kæsæ myna, tæm airvitæm punie poaka
Tæmæ jardækitæmæ Parne miela
Piægga miela noara iorda kockes jorda
Ios taidæ poakaid læm kuldælæm
Luidæm radda wæra radda
Ouita lie miela oudas waldæman
Nute tiedam poreponne oudastan man kauneman.
The sense of the Song is thus,
55. With brightest beams let the Sun shine
On Orra Moor,
Could I be sure,
That from the top o’th lofty Pine,
I Orra Moor might see,
I to his highest bow would climb,
And with industrious labor try,
Thence to descry
My Mistress, if that there she be.
Could I but know amidst what Flowers,
Or in what shade she staies,
The gaudy Bowers
With all their verdant pride,
Their blossomes and their spraies,
Which make my Mistress disappear;
And her in Envious darkness hide,
I from the roots and bed of Earth would tear.
Upon the raft of clouds I’de ride
Which unto Orra fly,
O’th Ravens I would borrow wings,
And all the feathered In-mates of the sky:
But wings alas are me denied,
The Stork and Swan their pinions will not lend,
There’s none who unto Orra brings,
Or will by that kind conduct me befriend.
Enough enough thou hast delaied
So many Summers daies,
The best of daies that crown the year,
Which light upon the eielids dart,
And melting joy upon the heart:
But since that thou so long hast staied,
They in unwelcome darkness disappear.
Yet vainly dost thou me forsake,
I will pursue and overtake
56. I will pursue and overtake.
What stronger is then bolts of steel?
What can more surely bind?
Love is stronger far then it;
Upon the Head in triumph she doth sit:
Fetters the mind,
And doth controul,
The thought and soul.
A youths desire is the desire of wind,
All his Essaies
Are long delaies,
No issue can they find.
Away fond Counsellors, away,
No more advice obtrude:
I’le rather prove,
The guidance of blind Love;
To follow you is certainly to stray:
One single Counsel tho unwise is good.
As they come to visit their Mistresses, they are necessitated to
bring along with them some spirit of Wine, as a singular and most
acceptable present, and Tobacco too. But if in the mean while, as it
often falls out, the father intends not to bestow his daughter upon the
man that hath made pretensions to her, he seldom refuses them, but
defers the positive answer till the year following, that he may the
oftner entertain himself with the spirit of Wine the Suiter brings along
with him. And thus he delaies his answer from one year to the other,
till the Suiter perceive himself cheated, and be constrained to require
at his hands his charges made to no purpose. There is then no other
remedy to be taken, then bringing the business before the Judg,
where the Maids Father is sentenced to refund either the entire sum,
or half of it, as the case stands. Where withal we must observe this,
that the expences made by the Suiter on the Spirit of Wine, at his first
arrival, do not fall under this compensation, but he alone stands to the
loss of that. But if after the downright refusal of the Maid, he of his
own accord will show his liberality, he may try what luck he will have
57. at his own peril. If all things happen conformable to his wishes, then
some set day is appointed for the wedding. The day before it, all the
kindred and Neighbors as well of the Bridegroom as Bride resort to her
parents hut, and the Bridegroom presents them all with wedding gifts,
about which they had agreed, and of which mention is made above.
The Bridegroom is bound to present the Father with a silver cup,
to drink in; this is the first of those they call Stycke. The second is a
large Kettle, either of Copper or Alchymy. The third, a bed or at least
hansom bedding. The presents for the Mother are, first a girdle of
silver, secondly a Robe of honor such as they use to call Vospi. Thirdly
a Whisk, which they wear about their neck, and let it hang down to
their brest, interlaced all about with bosses of silver, and this they call
Krake. These are the presents for the Father and Mother: besides he
bestows upon the Brothers, Sisters, and all the near kindred, silver
spoons, silver bosses, and some other such kind of things of silver, for
each of them must be presented with some gift by the Bridegroom, if
he mean to obtain his Bride. These are the presents, which the
Bridegroom is more especially bound to make to his Father and Mother
in law that are to be, and the rest of the kindred. And he makes them
in his father in laws hut, in the sight of all there. The day following the
wedding is celebrated, first by the ceremonious joining of the Priest in
the Church, afterwards by a set dinner. The new Wife together with
the Bridegroom walk along, both dress’d in the best clothes they can
procure at their own charges. For ’tis looked upon among them as
unhansom to make use of the borrowed cloths of others, unless it be
wool as I have elswhere shown. They take saies Tornæus so great
pleasure in good cloth of what ever color, that as far as their patrimony
will permit, they procure their extraordinary apparel and festival
Garments of that kind: who declares expressly that their festival
apparel, or that which they wore on more solemn daies, was not of
skins but rich cloth. These Garments the Bridegroom girds up with a
silver girdle, but the Bride first looses her hair: and the fillet wherewith
she bound it up together before, she gives to the Virgin that is next a
kin to her: afterwards, on her bare head, and loose hair she puts a
kind of a silver fillet gilt over, or two, such as is the womens custom to
wear at other times besides, instead of a Garland or Coronet, so that
58. by how much this fillet is looser, then to environ only her head; so
much it hangs down the more behind: likewise about her middle they
put on a silver girdle. This is the Brides apparel, unless that sometimes
they put upon her head something of linnen, instead of a veil, which at
other times the women use when they have a mind to make
themselves extraordinary gallant, for as for what appertains to their
garments, we have before observed, that both the Bridegroom and
Bride wear their own, and those their best, and such as on festival
daies they deck themselves withal. We have shown in another place,
that the womens were called Volpi, and were made either of wool, or
the richer sort of cloth, so that neither about this does Olaus Magnus
in his place a forecited, concerning the Lapland Bride, sufficiently
agree with their custom at this day. They set the Bride saies he,
apparell’d in Ermins and Sables skins on a Rain-deer. At this day both
dress’d very fine are carried to the Church or Priest, to be joined in
Marriage; this was not the custom in old times, if we give credit to
Olaus Magnus, for then they were joined at home, not by the Priests
but the Parents, his words are in Lib. 4. Cap. 7. in which place he
treats of the Laplanders weddings, as the Title of the Chapter informs
us. In the presence of friends and kindred, the Parents solemnly ratifie
their Childrens Marriages, and that too by the striking of fire with a
flint and steel, particularly there he makes the Parents joining them,
and adds moreover the manner, viz. by fire striken out of a flint, which
without doubt as some other things, he cull’d out of Zeigler, but as for
the parents doing it, Zeigler has nothing of that, the manner of their
joining he explains in these words, They ratifie their Marriages, and
begin them in a ceremony of fire and flint, so pat a conjugal mysterie,
that they think nothing can be more agreeable, for as the flint
conceals within it self fire, which by concussion breaks forth, so in
both sexes there is life hid, which by the mutual coupling of marriage
is propagated at last to be a living ofspring. And just so Olaus has it,
so that there can be no doubt made but that he followed Ziegler.
When they arrive near the Church, they observe in their procession a
certain order, first walk the Men, the Women follow. The Men are led
up by a Laplander, whom they call Automwatze, or foreman, then
follows the Bridegroom, after him the rest. Some number of Virgins
lead up the womens company, after them comes the Bride led
59. between a man and a woman, next to her follow the rest of the
women. Tis here to be observed that the Bride like one strugling
against it, and endeavoring the contrary, is dragged along by the man
and woman that are to wait upon her, and would seem to admit of her
marriage with great unwillingness and reluctancy, and therefore in her
countenance makes shew of extraordinary sadness and dejection: so
afterwards in the Church they are joined together by praiers and
benediction according to the Christian rite. After the same manner
does John Tornæus relate this busines, only that he saies the Bride is
led by two men, her Father and Brother, if alive, or otherwise by her
two next Kinsmen. The portraicture of the Bride in her wedding
apparel, and with her two leaders you have in the next page. After the
solemnity of the marriage is ended, there follows a wedding feast, that
is made in her Parents hut, and as for the provision, each of the
persons invited contributes his share of the victuals, tho they bring it
not thither just then, but the day before: when the Bridegroom
distributes his presents to the Brides parents and kindred, then every
one brings his victuals that will be serviceable to the feast. But
because the meat they bring is ordinarily raw, they deliver it to a
Laplander, on purpose appointed to that office, viz. to receive it of
every Person that brings, and afterwards to boil it, and lastly to
distribute it among the guests, tho commonly the greatest part of the
provision be made, by the Bridegrooms as well as Brides parents. In
their sitting at table they keep this order, in the uppermost places sit
the Bridegroom and Bride next to one another, then follow in order the
rest, as the parents, and kindred. At the table no person helps himself,
but receives his meat from the hands of a Laplander, who is both
dresser and carver of it. First of all he serves the Bridegroom and Bride
with their portion, and in order the rest. Now they who by reason of
the scantiness of room in the hut, cannot be admitted to the feast,
such are boies and girles, climb up to the roof of the hut, and from
thence let down threds with hooks tied to them, to which they fasten
pieces of meat, and the like, so that they also enjoy their share of the
banquet. The entertainment ended, they give thanks, as at other times
they use, and shake hands one with another. The last thing wherewith
they shut up the merriment of the feast, is drinking Spirit of Wine,
which if they can light upon, they then are sure to buy; first the
60. Bridegroom drinks, then the Brides parents, then each man shifts for
himself, and so they make merry, but this custom the richer sort only
observe, and those too who have the opportunity of buying, by the
presence of those who sell these commodities; as for the meaner sort
they are accustomed to divert themselves with talk. When the
Wedding is over, the Husband may not take along with him his Wife
with her goods and fortune, but must remain for an whole year in
service with his Father; when that time is past, if he sees convenient
he may set up for himself, and turn housekeeper; and then the Father
bestows upon his Daughter at her departure, the Rain-deer, which are
her due, because given her in her younger years: he gives her also
other gifts besides, and what furniture will be requisite for the new
married couple, particularly he gives for her dowry an hundred or
more Rain-deers, as likewise silver, copper, Alchymy, a tent, bedding,
and other houshold-stuff. And next all the kindred, the Brothers and
Sisters, and whoever have received of the Bridegroom his gifts of
respect, are likewise obliged to return him back again some present,
so that he who had received one or two markes of silver, returns for a
gift again one or two Rain-deers: so that it comes to pass, that the
Laplanders, who can gratifie the friends and kindred with numerous
presents, if they wed a rich Laplanders Daughter, come to great wealth
in Rain-deer by this kind of marriage. These are the cheif things the
Laplanders observe in their contracts and marriages, which before we
quite leave, we may take notice first, that it is unlawful among them,
to marry a wife too near in blood. And they have so special a regard to
the degrees of consanguinity and affinity, that they never request
marriage in the prohibited ones. And again ’tis unlawful, having one
wife to marry another, or when one is married to put her away, by
Divorce. Polygamy and Divorce were never heard of among the
Laplanders, neither in the time of Paganism, saies Tornæus, nor
afterwards, but they alwaies observed marriage honestly and like
Christians; yet in former daies perhaps they did not altogether abhor
the communicating their wives, whom they permitted to strangers
especially and guests. So indeed writes Herberstenius. But John
Tornæus mentions an instance of later date, and the Testimony too of
a Laplander of Luhla, tho he doubts to give credit to him. ’Twas
reported to me, saies he, that in the time of my Predecessor of Luhla-
61. Lapmark, a certain immodest Laplander, came to lodg with another, in
Torne-Lapmark, a civil honest man, as was his whole family, who could
read books, and lived a pious life, for which he was stiled by scorners
Zuan Bishop. Then the Man of Luhla, when he had disordered himself
with drinking Spirit of Wine, addressed himself to his hosts wife, in
hope of debauching her, but because there were there present two
officers, who had Spirit of Wine to sell, the Zuan Bishop call’d for
them, and told them the fellows design, desiring likewise that they
being Ministers of the State, would apprehend and bind him: they
immediately bound him to a Tree, and left him there for a whole
Winter night together, to be frozen with cold. At last he was forced to
regain his liberty with mony; and pleaded it as an excuse, that it was
the custom in Luli-Lapmark, that if any person visited another, the
entertainer permitted such familiarity with his Wife. Thus saies
Tornæus, but doubtingly, for the fellow might have only framed this for
his own excuse; ’tis certain no other person has taken notice of it in
them of Luhla, and the other Laplanders are so ignorant of this
communion of their wives, that they cannot endure they should look
upon other men. The Laplanders dwelling towards Norway at the river
Torna are so jealous, that if a Woman chance to meet a man, and
speak but a few words to him, they immediatly fall into a suspicion of
her.
63. CHAP. XXVI.
Of their Child-bearing, and the Education of
their Children.
Next to Marriage it will be expedient to treat of their Child-bearing,
and their Children. Where we may note first, that they wish for nothing
more, and that they take no greater plesure in any thing then fruitfull
Matrimony. And hence it is, I suppose, they are so prone to lust, as is
elsewhere shown: but altho they desire this so ardently, yet they are
very seldome fruitfull in Children, for they can scarce beget more then
eight, which number is the greatest, and usually they beget but one,
two, or three. An occasion of this their barreness, Sam. Rheen
imagines their bad diet, as likewise the extreme coldness of the
Country, which I think may be very true. He moreover adds Gods
anger, which he collects from this, because tho they are not worn
away with War or Plague, yet notwithstanding their Country is never
the more populous, and their Nation wasts rather daily. The motive of
this anger he supposes to be their obstinateness in maintaining their
ancient impieties. They use indeed at this very day, not only in Child-
bearing, but other affairs too, to be solicitous concerning the events,
and to search after them by their superstitious rites. Their first care is
concerning the sex, for as soon as they perceive the wife to be big
with child, they have an opinion that they can inform themselves
whether it will prove a Boy or a Girl, after this manner: they forthwith
view the Moon (for they imagine that a Child-bearing woman bears
some resemblance to the Moon, as we shall hear) if there be a Star
just above the Moon, they thence collect that the burden will prove of
the male sex, if below, of the female. But I wonder they make a
comparison between the Moon and a woman with child. For can there
be any account given of their resemblance? is it, that like the Moon,
64. she grows big with her burden, and when that is laid, lessens again? I
rather suppose that these are the reliques of their Pagan superstition,
which made the Moon the tutelar Goddess to women with child. For so
most of the Pagans did account other, which opinion being outdated,
they yet pretend some resemblance between them. Their second care
is touching the health or sickness of the child, which thing also they
suppose the Moon will inform them in. For if a Star be just before the
Moon, they take it for a sign that the child will prove healthfull, and
grow up to be a man. But if it comes just after her, they thence
presage that the child will be a very sickly one, and not long lived.
The woman with child laies her burden in a hut, but (which any
body may understand) a sufficient incommodious one, especially if the
time of her delivery happen to be in the Winter, for tho they have a
fire kindled in the middle of the hut, yet that can give her but little
warmth. After her delivery, her first restorative and cordial, is a good
draught of Whales fat, which they procure out of Norway, the tast of
which is as strong and ill savoured as of a Sea-calves lard, when dried.
The child, as soon as brought forth is washed over as in other
Countries, but it is a peculiar custom of the Laplanders that first they
do it with cold water or snow, and then afterwards dip them in hot
water, when it begins to fetch its wind, and can scarcely draw breath.
And also they use to dip in the water all the other parts of the body,
the head only excepted; They heat water, saies Sam. Rheen, in a
Caldron, and in that they set the infant streight up to his neck, but
they let no water come upon his head, before such time as he is
baptized by the Priest. The newborn Babe is instantly wrapped up in
an Hares skin, instead of linnen swadling clothes.
The woman lying in, hath her peculiar place assigned her in the
hut where she lodges, till she recover her health. And it is just by the
door usually on the left hand: there is no other reason given for it then
that this part of the hut is less frequently disturb’d by company, and
there they have all things needfull for them administred. Tho this
seldom resort thither be rather, by reason of the womans lying in in
that place, either because they would not disturb her with their
company, or, which I rather suppose, because they look upon her at
that time as unclean. But the women of Lapland seldom keep their
65. beds long after their delivery, and in that while are extraordinary
carefull touching the Baptism of their Infants: for after they began
more diligently to be instructed in the Christian Religion, they take the
greatest pains imaginable to have their Children baptized as soon as
possibly may be. In former times it was otherwise, most of them then
were baptized very late, and at their mature age; some deferred it for
altogether. Of this Gustavus the first is a witness, in his Charter, the
words whereof I have cited elsewhere. As touching the former
Gustavus Adolphus in an other Charter and Preface, premised to that
which he published Anno 1634, in which the State of the Religion in
Lapland is declared at large; Baptism, saies he, is administred indeed
to them but only at Winter, if their young children can live till then, it is
well; if not, they die without Baptism. Some of their children come to
years of Discretion before it, so that with those that are grown up,
there is no small paines to be taken when they are to be baptized. The
time of Baptism being the Winter time, was because they have
Sermons then preached to them, and the Sacrament administred, and
that no oftner then twice; once about New-years-day, and againe at
Lady-day, of which I have treated in another place. Before these times
there was not so much done as that, but the Laplanders were fain to
come with their Children to the neighbouring Churches of the Swedes
in Angermannia and Bothnia, of which Olaus Magnus must be
understood to speak, when he saies Lib. 4. c. 17. Once or twice in a
year they visit the Baptismall Churches, and bring along with them
their sucking Babes in Baskets tied to their backs, to be baptized. But
at this day those women that are able, and not impeded by some
grievous sickness, carry their Children to the Priest themselves, about
a fourtnight after their delivery, that by him they may receive Baptism.
So much good hath building Churches in Lapland done, and having
Sermons there, not in a strange Tongue, but the Laplanders proper
own: and so zealous are they for hastening their Childrens Baptism,
that the Mother scarce lying in above a week or fortnight, after her
delivery, will undertake a most tedious journy, over the tops of
Mountains, thorough wide Marshes and high Woods with her Infant to
the Priest; for the women of this Country are naturally hardy, and able
to endure any thing without trouble, and therefore, tho they feed upon
course food in their sicknesses, and drink nothing else but water, yet
66. they recover again quickly. They carry their young Infants to the
Priest, one way in the Summer time, and another way in the Winter. In
Winter they lay it upon a sledge. In Summer they put it in a Pannier
fastned to the back of a Rain-deer. The Infant is not set upon the back
of the Raindeer, but is tied in his cradle, and fastned to the pack
saddle after this fashion.
Olaus Magnus makes them put in Baskets, as his words afore
quoted do intimate, and those Baskets too to be tied at their backs,
and the Picture he makes of them represents not only the woman, but
the man too so laden, each with two Children a piece: so that together
they travell with four Children, and with wooden shoes on their feet;
but here I am afraid the Painter followed his own fancy too much.
Certain it is that the Baskets there represented, bear no resemblance
to those of Lapland. The Laplanders are wholly ignorant of this sort of
Baskets, that are carried at ones back. Nor are their Baskets like
wooden square Boxes, such as his figure represents them, but of a
round compass, and one part shut down upon the other, as I have said
elsewhere. But to return to their Baptism, in it they give their Children
names, according to the names of some of their friends and kindred.
Samuel Rheen adds that they affect to put Pagan names upon them,
such as Thor, Guaarm, Finne, Pagge; but that the Priests avert them
from so doing as much as possibly they can. And this is peculiar with
67. them, that they often change their names, and put others upon them
then those that were given them at their Baptism, for the love they
bear to some friend or kinsman deceased, whose memory thereby
they desire to preserve. Tornæus too avouches the same thing, and if
at any time in their younger years they fall into sickness, then they use
the name given them in Baptism instead of a surname, especially they
observe this in boies. But altho the Laplanders wives are hardy, so as
to be able to undertake a journy a week or two after their delivery,
and to go about other emploiments, tho they have made their public
appearance, and have been churched by the Priest, yet by their
husbands they are looked upon as unclean, till six weeks be
accomplished, so that they admit of no familiarity or conjugal society
with them for all that space of time. And thus much of their child-
bearing.
I proceed next to their Education of them, the first thing that
occurs here is their Nursing, which is alwaies by their own Mothers
milk, for the Laplanders make no use of Nurses. And this they do not
only for some small time, but usuall for two years, three or four
together; but if sickness or any other occasion happen, so that they
cannot themselves suckle their young ones, they give them the Rain-
deers milk, which is grosser and thicker, then they can well draw out of
a suck-bottle, (as at sometimes they are accustomed to do, elswhere)
and for that reason, if the necessity be urgent they give it in a spoon.
Besides their Mothers milk, they instantly accustom their young
Infants, to eat flesh, for they thrust into their mouths a piece of Rain-
deers flesh, that they may suck the gravie out of it, and so get
nurishment.
The rocking the infant in his cradle, follows next, whereby they
get him a sleep. Their Cradles are made of the stock of a tree
hollowed, like a boat: these they cover with leather, and at the head
they erect an arched kind of roof, of leather likewise. In such a cradle
they lay & tie in the Infant, without any linnen clothes or sheets,
instead of which they lay him on a sort of soft moss, of a red color,
which they dry in Summer, and have great plenty of it. When the
Infant is to be rocked, they let the cradle hang by a rope from the roof
of the hut, and by thrusting the cradle and tossing it from one side to
68. the other, they lull him a sleep. They use likewise to please their young
children with some certain baubles, for at their cradles they tie some
rings of Alchamy, to make a noise and clinking. To these rings which
serve instead of rattles they moreover add some emblems, wherewith
their children may be timely admonished of their condition and future
duty. If it be a boy, they hang up at his cradle a bow and arrows, and
a spear made very artificially out of Rain-deers horn, whereby they
signifie, that their children must diligently practise to be expert and
ready in using the bow and spear. If it be a girle; the wings, feet, and
beak of a white Partridge, which they call Smæripa, and is call’d
Lagopus having feet like the feet of an hare, thereby implying, that
their Daughters must carefully learn to be cleanly, and like those birds
nimble and active. As soon as the children come to some age, they
instruct them in all necessary arts, the Fathers the boies, the Mothers
the girles, for they have no School-masters among them, but each
person is his own childerns Master, and they are so far put on by their
parents as to be able to perform any works in use among them. Their
boies they cheifly teach the Art of Shooting, and hitting marks with an
arrow, because in old time they were necessitated to get their living by
the help of bow and arrows, whereas the greatest part of them
maintain themselves by hunting, and therefore when they have
practised never so little the use of the bow, the boies victuals are kept
from them, till they can hit a mark with an arrow, and as it was the
custom anciently among the Baleares, and so now among the
Laplanders, their boies earn their food every day by their dexterity in
shooting, and thereby at last they prove most excellent marks-men.
Olaus Magnus makes mention of this their practice, and wonderfully
extolls their dextrousness herein, and avers that he himself has seen
some of them who could exactly hit a farthing or a nedle, set at such a
distance off as would just let them see it. On the boies, that they may
take more care to hit the mark, when they have hit it, they bestow a
white girdle, wherein they take huge delight, and sometime a new
bow. But as the Laplanders do look to their children in time to teach
them arts requisite to get their living, so also to provide them means
to maintain themselves withal, where it will not be impertinent to
mention, that tis a custom with them to bestow upon their infant a
female Rain-deer, soon after its birth or Baptism, if it be of female Sex,
69. and upon the horns of it they ingrave her mark, so to prevent all
controversies or quarrels, that may arise concerning her right. She
receives likewise another, when she cuts her first tooth. Which they
call Pannikeis, that is, the tooth Rain-deer. John Tornæus writes as if
these gifts were given only by women. The Woman saies he, that first
spies a tooth in his mouth, is fain to honor him with a present of a
Rain-deers Calve. This custom might probably have its rise thus,
because, when the infants have gotten teeth, they have need of more
solid meat, therefore they stock them with Rain-deer as being their
cheifest food. That Rain-deer then, and whatever encrease comes of
it, are preserv’d to the future uses of the child, as may appear by what
we have elsewhere said, in the Chapter of their marriages, and so
likewise of the other Rain-deer which parents give the child besides,
for tis usual among them to superadd one to the former, and this they
call Waddom, that is, the given one. And this is the chief care of the
Parents towards their children, but if they die, instead of them are
substituted Guardians, as among other nations, out of their nearest
kindred, who manage all these affairs for them.