D3 js By Example 1st Edition Heydt pdf download
D3 js By Example 1st Edition Heydt pdf download
https://ebookname.com/product/d3-js-by-example-1st-edition-heydt/
https://ebookname.com/product/node-js-by-example-1st-edition-
tsonev/
https://ebookname.com/product/d3-js-in-action-third-edition-
elijah-meeks/
https://ebookname.com/product/mastering-d3-js-1st-edition-pablo-
navarro-castillo-castillo/
https://ebookname.com/product/applied-nonlinear-functional-
analysis-an-introduction-1st-edition-nikolaos-s-papageorgiou/
Magento 2 Theme Design 2nd Edition Fernando J Miguel
https://ebookname.com/product/magento-2-theme-design-2nd-edition-
fernando-j-miguel/
https://ebookname.com/product/muscle-energy-techniques-3rd-
edition-leon-chaitow/
https://ebookname.com/product/energy-statistics-of-oecd-
countries-2011-iea-statistics-1st-edition-oecd/
https://ebookname.com/product/2010-north-american-coins-prices-a-
guide-to-u-s-canadian-and-mexican-coins-north-american-coins-and-
prices-19th-edition-harry-miller/
https://ebookname.com/product/action-learning-leadership-and-
organizational-development-in-public-services-routledge-studies-
in-human-resource-development-1st-edition-clare-rigg/
A Treatise of Human Nature David Fate Norton
https://ebookname.com/product/a-treatise-of-human-nature-david-
fate-norton/
www.it-ebooks.info
D3.js By Example
Michael Heydt
BIRMINGHAM - MUMBAI
www.it-ebooks.info
D3.js By Example
All rights reserved. No part of this book may be reproduced, stored in a retrieval
system, or transmitted in any form or by any means, without the prior written
permission of the publisher, except in the case of brief quotations embedded in
critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy
of the information presented. However, the information contained in this book is
sold without warranty, either express or implied. Neither the author, nor Packt
Publishing, and its dealers and distributors will be held liable for any damages
caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the
companies and products mentioned in this book by the appropriate use of capitals.
However, Packt Publishing cannot guarantee the accuracy of this information.
ISBN 978-1-78528-008-5
www.packtpub.com
www.it-ebooks.info
Credits
Reviewers Proofreader
Patrick Cason Safis Editing
Pablo Núñez Navarro
William Sankey Indexer
Monica Ajmera Mehta
Commissioning Editor
Veena Pagare Graphics
Disha Haria
Acquisition Editors
Harsha Bharwani Production Coordinator
Conidon Miranda
Hemal Desai
Cover Work
Content Development Editor
Conidon Miranda
Merwyn D'souza
Technical Editor
Parag Topre
Copy Editor
Sonia Mathur
www.it-ebooks.info
About the Author
He is the author of numerous articles, papers, and books, such as Instant Lucene.
NET, Learning Pandas, and Mastering Pandas for Finance, all by Packt Publishing, on
technology. Michael is also a common speaker at .NET user groups and various
mobile, cloud, and IoT conferences and delivers webinars on advanced technologies.
He can be reached through his website e-mails, mike@heydt.org and mike@
seamlessthingies.tech and on Twitter at @mikeheydt.
www.it-ebooks.info
About the Reviewers
Pablo Núñez Navarro has written line of business applications for more than 15
years, from VB 6 to .NET and JavaScript among many other technologies. His work
on long-live projects and software maintenance made him focus on best practices
and clean code, with an intensive use of code reviewing to achieve consistency and
readability through working in teams. Pablo enjoys discussing software.
He has taught many courses, including the University of Malaga's master's in RIAtec,
for quite a few years. Pablo coauthored Mastering LOB Development for Silverlight
5: a Case Study in Action, Packt Publishing. He is also very active in local software
communities.
www.it-ebooks.info
William Sankey is a data professional and developer hobbyist living in College
Park, Maryland. He graduated in 2012 from Johns Hopkins University with a
master's degree in public policy and specializes in quantitative analyses. He has
worked in the public and private spheres and is currently a data scientist at Xometry.
www.it-ebooks.info
www.PacktPub.com
https://www2.packtpub.com/books/subscription/packtlib
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital
book library. Here, you can search, access, and read Packt's entire library of books.
Why subscribe?
• Fully searchable across every book published by Packt
• Copy and paste, print, and bookmark content
• On demand and accessible via a web browser
www.it-ebooks.info
www.it-ebooks.info
Table of Contents
Preface vii
Chapter 1: Getting Started with D3.js 1
A brief overview of D3.js 2
Selections 3
Data and data binding 4
Interaction and animation 5
Modules 6
Tools for creating and sharing D3.js visualizations 7
Js Bin 7
bl.ocks.org 9
Google Chrome and Developer tools 11
Hello World – D3.js style 12
Examining the DOM generated by D3.js 15
Summary 16
Chapter 2: Selections and Data Binding 17
D3.js selections 18
Changing the style of a DOM element 18
Changing the style of multiple items 19
D3.js and data binding 23
Data binding 23
Specifying the entering elements with .enter() 29
Adding new items using .enter() 31
Updating values 33
Removing items with .exit() 35
A few notes for the wise about the general update pattern 37
Summary 39
[i]
www.it-ebooks.info
Table of Contents
[ ii ]
www.it-ebooks.info
Table of Contents
Ordinal scales 86
Mapping color strings to codes 86
Mapping integers to color scales 87
The ordinal scale using rangeBands 88
Visualizing The Walking Dead viewership 90
Summary 94
Chapter 6: Creating Scatter and Bubble Plots 95
Creating scatter plots 96
Plotting points 96
Sprucing up the scatter plot 99
Adding gridlines 100
Creating a bubble plot 103
Summary 106
Chapter 7: Creating Animated Visuals 107
Introduction to animation 108
Animating using transitions 108
Animating the fill color of a rectangle 108
Animating multiple properties simultaneously 110
Delaying a transition 111
Creating chained transitions 111
Handling the start and end events of transitions 112
Changing the content and size of text using tweening 113
Timers 116
Adding a fifth dimension to a bubble plot – time 117
Summary 122
Chapter 8: Adding User Interactivity 123
Handling mouse events 124
Tracking the mouse position using mousemove 124
Capturing the mouse entering and exiting an SVG element 125
Letting the user know they have clicked the mouse 126
Using behaviors to drag, pan, and zoom 127
Drag 128
Pan and zoom 129
Enhancing a bar graph with interactivity 131
Highlighting selected items using brushes 135
Online examples of brushes 135
Implementing focus + context 138
Summary 142
[ iii ]
www.it-ebooks.info
Table of Contents
[ iv ]
www.it-ebooks.info
Table of Contents
[v]
www.it-ebooks.info
Table of Contents
[ vi ]
www.it-ebooks.info
Preface
Learning D3.js on your own can be a daunting task. There are literally thousands of
examples online with differing degrees of effective, or ineffective, explanation.
This book uses examples that take you right from the beginning, with the basic
concepts of D3.js, using practical examples that progressively build on each other
both within a specific chapter and also with reference to previous chapters.
We will focus on the examples created for this book as well as those found online
that are excellent but could use some additional explanation. Each example will
explain how the example works either line by line or by comparison with other
examples and concepts learned earlier in the book.
Chapter 2, Selections and Data Binding, teaches you how to use D3.js selections to
create DOM elements based on data.
Chapter 3, Creating Visuals with SVG, introduces you to Scalable Vector Graphics
and how to use them to render various shapes that are commonly used in D3.js
visualizations.
Chapter 4, Creating a Bar Graph, demonstrates how to create a bar graph from
given data.
Chapter 5, Using Data and Scales, shows you how to load data from external sources
in different formats and convert it into information suitable for visualization.
[ vii ]
www.it-ebooks.info
Preface
Chapter 6, Creating Scatter and Bubble Plots, demonstrates how to load, scale, and plot
multidimensional data in a manner that makes patterns clear to users.
Chapter 7, Creating Animated Visuals, teaches you to use animations in your D3.js
applications to demonstrate how data changes over time.
Chapter 8, Adding User Interactivity, shows you how to allow users to interact with
your visualizations using the mouse.
Chapter 9, Complex Shapes Using Paths, shows you how to use many of the built-in
tools in D3.js to automatically generate complex paths with a few simple statements.
Chapter 10, Using Layouts to Visualize Series and Hierarchical Data, focuses on creating
complex graphs that utilize the layout objects of D3.js. This includes a multitude
of graphs in different categories, including stacked, packed, clustered, flow-based,
hierarchical, and radial.
Chapter 11, Visualizing Information Networks, dives into demonstrating how you can
use D3.js to visualize network data such as is found in social networks.
Chapter 12, Creating Maps with GeoJSON and TopoJSON, teaches you how to create
maps and highlight regions on them using two forms of geographic data: Geo and
TopoJSON.
Chapter 13, Combining D3.js and AngularJS, discusses how you can integrate multiple
D3.js visualizations using Angular.js to create reactive visualizations.
[ viii ]
www.it-ebooks.info
Preface
Conventions
In this book, you will find a number of text styles that distinguish between different
kinds of information. Here are some examples of these styles and an explanation of
their meaning.
Code words in text, database table names, folder names, filenames, file extensions,
pathnames, dummy URLs, user input, and Twitter handles are shown as follows:
"Now using the selector variable we call the .enter() function and assign it to a
variable named entering."
When we wish to draw your attention to a particular part of a code block, the
relevant lines or items are set in bold:
function render(dataToRender) {
var selector = d3.select('body')
.selectAll('div')
.data(dataToRender);
[ ix ]
www.it-ebooks.info
Preface
New terms and important words are shown in bold. Words that you see on the
screen, for example, in menus or dialog boxes, appear in the text like this: "The value
for Mikael was changed to 25."
Reader feedback
Feedback from our readers is always welcome. Let us know what you think about
this book—what you liked or disliked. Reader feedback is important for us as it helps
us develop titles that you will really get the most out of.
If there is a topic that you have expertise in and you are interested in either writing
or contributing to a book, see our author guide at www.packtpub.com/authors.
Customer support
Now that you are the proud owner of a Packt book, we have a number of things to
help you to get the most from your purchase.
This will take you to a page on http://bl.ocks.org/ for the example. This page
will also contain a link to take you to jsbin.com where you can interactively make
changes to the code.
[x]
www.it-ebooks.info
Preface
You can download the example code files from your account at http://www.
packtpub.com for all the Packt Publishing books you have purchased. If you
purchased this book elsewhere, you can visit http://www.packtpub.com/support
and register to have the files e-mailed directly to you.
Errata
Although we have taken every care to ensure the accuracy of our content, mistakes
do happen. If you find a mistake in one of our books—maybe a mistake in the text or
the code—we would be grateful if you could report this to us. By doing so, you can
save other readers from frustration and help us improve subsequent versions of this
book. If you find any errata, please report them by visiting http://www.packtpub.
com/submit-errata, selecting your book, clicking on the Errata Submission Form
link, and entering the details of your errata. Once your errata are verified, your
submission will be accepted and the errata will be uploaded to our website or added
to any list of existing errata under the Errata section of that title.
Piracy
Piracy of copyrighted material on the Internet is an ongoing problem across all
media. At Packt, we take the protection of our copyright and licenses very seriously.
If you come across any illegal copies of our works in any form on the Internet, please
provide us with the location address or website name immediately so that we can
pursue a remedy.
We appreciate your help in protecting our authors and our ability to bring you
valuable content.
Questions
If you have a problem with any aspect of this book, you can contact us at
questions@packtpub.com, and we will do our best to address the problem.
[ xi ]
www.it-ebooks.info
www.it-ebooks.info
Getting Started with D3.js
D3.js is an open source JavaScript library that provides the facility for manipulating
HTML documents based upon data, using JavaScript as the language for
implementing the mapping of data to the documents. Hence, the name D3 (Data
Driven Documents). Many consider D3.js as a data visualization library. This may be
correct, but D3.JS provides much more to its user than just visualization, such as:
We are about to start on a fabulous journey of discovery with creating rich data
visualizations with D3.js, and focusing on project-based learning of D3.js through
practical examples. We will start out with the basic concepts, and then move through
various examples of creating living data visualizations with D3.js.
In this first chapter, we will start with a brief overview of several of the concepts in
D3.js, create a minimal D3.js application, and examine several of the tools that you
can use to build D3.js applications.
[1]
www.it-ebooks.info
Getting Started with D3.js
[2]
www.it-ebooks.info
Chapter 1
D3.js differs from other data visualization frameworks such as Processing (https://
processing.org/) in that it provides a domain-specific language for transforming
the DOM based upon data, whereas tools like Processing provide a lower level direct
rendering model. D3.js lets you describe the means of visualizing the data instead
of coding all of the specific details to draw the pixels of the visualizations. This
facilitates easy creation of visualizations by allowing D3.js to worry about the details
on rendering the data, based on the standards of SVG and CSS.
A fundamental concept in D3.js is the ability to easily manipulate the DOM in a web
document. This is often a complicated problem, and many frameworks (such as
jQuery) have been created to perform this task. D3.js provides capabilities similar to
jQuery, and for those familiar with jQuery, much of D3.js will feel familiar.
But D3.js takes what libraries like jQuery provide and extends them to provide
a more declarative nature of modifying the DOM to create visuals based on the
structure of the data instead of simply being a framework for low level DOM
manipulation.
We will not cover jQuery in this book. Our focus will purely be on how
we can manipulate the DOM using the facilities provided by D3.js. We
will use D3.js constructs to apply styles instead of depending on CSS.
All of this is to exemplify how to use the facilities of D3.js instead of
hiding any of it with other tools.
We will examine many concepts in D3.js in detail, but let's start with a few high-level
ideas in D3.js that are worth mentioning first.
Selections
The core operation in D3.js is selection, which is a filtered set of DOM elements
queried from the document. As the data changes (that is, it is either loaded or
modified), the result of the selection filter is changed by D3.js based on how the data
was changed. Hence, the visual representation also changes.
[3]
www.it-ebooks.info
Getting Started with D3.js
Selections are implemented by D3.js through the global namespace d3, which
provides the d3.select() and d3.selectAll() functions. These functions utilize
the mini-language and return, respectively, the first or all items matching the
specification. Using the result of these selections, D3.js provides additional abilities
for modifying those elements based upon your data using a process known as data
binding.
The process of binding in D3.js consists of three stages: Enter, Update, and Exit.
When performing a selection for the first time with D3.js, you can specify the data
that is to be bound and needs to be entered. You can also specify the code to be
executed for each of these stages.
When data is first joined into a selection, new visuals will need to be created in the
DOM for each data item. This is performed using the enter process which is started
by calling the .enter() function. Code that you specify after the .enter() function
will be used to specify each and every piece of data that is represented visually, and
D3.js will use this code to automatically generate the DOM that is required instead of
you needing to code it all in detail.
As the application modifies this bound data, we will execute the selection repeatedly.
D3.js will make a note of the existing visuals and the data they are bound to, and
allow us to make modifications to the visuals based upon the way the data changed.
If data items are removed, we can use the D3.js .exit() function in a selection to
inform D3.js to remove the visuals from the display. Normally, this is done by telling
D3.js to remove the associated DOM elements, but we can also execute animations
to make the removal demonstrate to the user how the visual is changing instead of a
jarring change of display.
[4]
www.it-ebooks.info
Exploring the Variety of Random
Documents with Different Content
The Project Gutenberg eBook of School Credit
for Home Work
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.
Author: L. R. Alderman
Language: English
TO THE MEMORY
OF
MY FATHER AND MOTHER
Who made their boys happy partners in the
work of the home and farm
PREFACE
It has been a surprise and a delight to me, as this book has been in
progress, to learn of the many different ways that people have
worked out these home credit plans. It has been as if I could see
into many happy schoolrooms. Letters from mothers and fathers
boasting of the accomplishments of their children, have brought to
me a little glow from the hearthsides of many homes. A father
brought his boy—or rather the boy brought his father—up to see me
and talk over what the boy was doing at home. The father boasted
of the boy's fine garden, his big pumpkins, his watermelons that
would attract the neighbors. Johnny almost burst the top button off
his vest with pride as his father praised him and patted him on the
head. After this happy meeting, the father and the son got on the
high wagon seat and rode home; and as I saw them going down the
street, I could imagine what they talked about. Such glimpses help
to make a school man's life worth while; and I have had many of
them as I have been writing this book.
For the fact that this book exists at all, I am indebted to my wife,
who has helped me with every part of it, and to Mr. and Mrs. C. C.
Thomason, of Olympia, Washington, who believed in the book from
the first. Mrs. Thomason has also done much work on the book; she
has gathered all the illustrative material, visiting many schools and
writing many letters. She and my wife have done most of the
organizing of material, and have gone over the manuscript together.
To Miss Fanny Louise Barber, of the Washington High School,
Portland, I am grateful for her careful reading and revision of several
chapters. I owe thanks to Mrs. Sarah J. Hoagland, of Belt, Montana,
for the true and vivid stories she has sent me; and I am thankful to
all the home credit teachers, with whom we have been
corresponding, for their painstaking answers to our letters, as well
as for the valuable plans that they have originated.
L. R. Alderman.
Portland, Oregon,
November 16, 1914.
CONTENTS
PART ONE
I.Introduction 1
II. Mary 7
III.The Spring Valley School 11
IV. What will become of the Algebra? 24
V. Honoring Labor 34
VI. Habit-Building 39
VII. That Other Teacher and that Teacher's Laboratory 46
VIII. Stella and Sadie 53
IX. A Story and Letters from Teachers 60
PART TWO
I.Illustrative Home Credit Plans 71
II. Home Credit in High Schools 156
Appendix 167
Index 177
ILLUSTRATIONS
Feeding her Bird Frontispiece
Spring Valley School 12
Picnic Luncheon, Spring Valley 20
Joe in the Garage 28
Work Credited at School 36
Earning Home Credits 42
O. H. Benson Potato Club 88
High School Boys in Railroad Shops 156
SCHOOL CREDIT FOR HOME WORK
PART ONE
I
INTRODUCTION
The child is a born worker; activity is the law of his nature.
Francis W. Parker.
After the home-credit schools of Mr. O'Reilly and Mr. Conklin were
well under way, I received many inquiries about the home credit
idea. As I was then State Superintendent, I had a pamphlet printed
by the State Office, describing the workings of the plan, and had it
distributed to Oregon teachers. Fifteen thousand copies were also
printed for Mr. Claxton, Commissioner of Education, in the summer
of 1912, and distributed by the National Bureau to superintendents
and teachers throughout the United States. Since this pamphlet has
been out of print there have been many inquiries sent me about
home credit, and I hope that this book may answer some of them.
II
MARY
The brain and the hand, too long divorced, and each mean and
weak without the other; use and beauty, each alone vulgar;
letters and labor, each soulless without the other, are henceforth
to be one and inseparable; and this union will lift man to a
higher level.—G. Stanley Hall.
The idea of giving school credit for home work first occurred to me
when I was a high-school principal in McMinnville, Oregon, in 1901.
Often, in the few years that I had been teaching, I had felt keenly a
lack of understanding between school and home. As I was thinking
over this problem, and wondering what could be done, I chanced to
meet on the street the mother of one of my rosiest-cheeked,
strongest-looking high-school girls. I saw that the little mother
looked forlorn and tired. There was a nervous twitch of the hand
that adjusted the robes about the crippled child she was wheeling in
a baby buggy. I had frequently noticed that Mary, the daughter, who
was one of the very poorest students in her class, was on the streets
the greater part of the time after school hours. I thought, "What
value can there be in my teaching that girl quadratic equations and
the nebular hypothesis, when what she most needs to learn is the
art of helping her mother?"
In the algebra recitation next day I asked, "How many helped with
the work before coming to school?" Hands were raised, but not
Mary's. "How many got breakfast?" Hands again, not Mary's. "I
made some bread a few days ago, bread that kept, and kept, and
kept on keeping. How many of you know how to make bread?"
Some hands, not Mary's. I then announced that the lesson for the
following day would consist as usual of ten problems in advance, but
that five would be in the book, and five out of the book. The five out
of the book for the girls would consist of helping with supper,
helping with the kitchen work after supper, preparing breakfast,
helping with the dishes and kitchen work after breakfast, and putting
a bedroom in order. Surprise and merriment gave place to
enthusiasm when the boys and girls saw that I was in downright
earnest. When I asked for a report on the algebra lesson next day all
hands went up for all the problems both in algebra and in home-
helping. As I looked my approval, all hands fell again, that is, all
hands but Mary's. "What is it, Mary?" I asked. "I worked five in
advance," she replied with sparkling eyes: "I worked all you gave us,
and five ahead in the book!"
Since that day I have been a firm believer in giving children credit at
school for work done at home. We did not work home problems
every day that year, but at various times the children were assigned
lessons like the one mentioned, and scarcely a day passed that we
did not talk over home tasks, and listen to the boys and girls as they
told what each had achieved. The idea that washing dishes and
caring for chickens was of equal importance with algebra and
general history, and that credit and honor would frequently be given
for home work, proved a stimulus to all the children, and especially
to Mary. Her interest in all her school duties was doubled, and it is
needless to say that her mother's interest in the school was many
times increased as her heavy household cares were in part assumed
by her healthy daughter.
A few weeks after the first home credit lesson Mary brought her
luncheon to school. At the noon hour she came to my desk, opened
her basket, and displaying a nicely made sandwich said, "I made this
bread." The bread looked good, and must have been all right, for
she ate the sandwich, and it did not seem to hurt her. She came
again wearing a pretty new shirt-waist, and told me she had made it
herself, and that it had cost just eighty-five cents.
After Mary graduated from high school she went out into the country
to teach, and boarded with her uncle's family. Her uncle's wife was ill
for a while, and Mary showed that she knew how to cook a fine
meal, and how to set a table so that the food looked good to eat.
She made herself generally useful. Her uncle came to my office one
day and told me that Mary was the finest girl he ever saw, and that
every girl like that should go to college, and that he was going to
see that she went to college if he had to sell the farm to send her.
She went to college, but it didn't take the farm to send her.
III
THE SPRING VALLEY SCHOOL
An excellent result of the absence of centralization in the United
States.... The widest possible scope being allowed to individual
and local preferences, ... one part of our vast country can profit
by the experience of the other parts.
John Fiske.
Kindly convey my blessing to that genius of a teacher in Spring
Valley, the same to stand good till judgment day.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookname.com