Full Download D3 Data Driven Documents Pocket Primer 1st Edition Oswald Campesato PDF
Full Download D3 Data Driven Documents Pocket Primer 1st Edition Oswald Campesato PDF
Full Download D3 Data Driven Documents Pocket Primer 1st Edition Oswald Campesato PDF
com
https://ebookmeta.com/product/d3-data-driven-
documents-pocket-primer-1st-edition-oswald-
campesato/
OR CLICK BUTTON
DOWLOAD EBOOK
https://ebookmeta.com/product/data-science-fundamentals-pocket-
primer-1st-edition-oswald-campesato/
https://ebookmeta.com/product/bash-for-data-scientists-1st-
edition-oswald-campesato/
https://ebookmeta.com/product/data-structures-in-java-1st-
edition-oswald-campesato/
https://ebookmeta.com/product/python-for-programmers-1st-edition-
oswald-campesato/
Natural Language Processing Fundamentals for Developers
1st Edition Oswald Campesato
https://ebookmeta.com/product/natural-language-processing-
fundamentals-for-developers-1st-edition-oswald-campesato/
https://ebookmeta.com/product/data-architecture-a-primer-for-the-
data-scientist-a-primer-for-the-data-scientist-2nd-edition-w-h-
inmon/
https://ebookmeta.com/product/data-driven-model-free-
controllers-1st-edition-precup/
https://ebookmeta.com/product/integrating-d3-js-with-react-learn-
to-bring-data-visualization-to-life-1st-edition-elad-elrom/
https://ebookmeta.com/product/data-architecture-a-primer-for-the-
data-scientist-2nd-edition-w-h-inmon/
D3
Pocket Primer
LICENSE, DISCLAIMER OF LIABILITY, AND
LIMITED WARRANTY
By purchasing or using this book and disc (the “Work”), you agree that this license
grants permission to use the contents contained herein, including the disc, but
does not give you the right of ownership to any of the textual content in the book
/ disc or ownership to any of the information or products contained in it. This
license does not permit uploading of the Work onto the Internet or on a network
(of any kind) without the written consent of the Publisher. Duplication or
dissemination of any text, code, simulations, images, etc. contained herein is
limited to and subject to licensing terms for the respective products, and
permission must be obtained from the Publisher or the owner of the content, etc.,
in order to reproduce or network any portion of the textual material (in any media)
that is contained in the Work.
MERCURY LEARNING AND INFORMATION (“MLI” or “the Publisher”) and anyone involved in
the creation, writing, or production of the companion disc, accompanying
algorithms, code, or computer programs (“the software”), and any accompanying
Web site or software of the Work, cannot and do not warrant the performance or
results that might be obtained by using the contents of the Work. The author,
developers, and the Publisher have used their best efforts to insure the accuracy
and functionality of the textual material and/or programs contained in this
package; we, however, make no warranty of any kind, express or implied,
regarding the performance of these contents or programs. The Work is sold “as is”
without warranty (except for defective materials used in manufacturing the book
or due to faulty workmanship).
The author, developers, and the publisher of any accompanying content, and
anyone involved in the composition, production, and manufacturing of this work
will not be liable for damages of any kind arising out of the use of (or the inability
to use) the algorithms, source code, computer programs, or textual material
contained in this publication. This includes, but is not limited to, loss of revenue or
profit, or other incidental, physical, or consequential damages arising out of the
use of this Work.
The sole remedy in the event of a claim of any kind is expressly limited to
replacement of the book and/or disc, and only at the discretion of the Publisher.
The use of “implied warranty” and certain “exclusions” vary from state to state,
and might not apply to the purchaser of this product.
D3
Pocket Primer
Oswald Campesato
Preface
Chapter 1: Introduction to D3
What is D3?
D3 on Mobile Devices
D3 Boilerplate
Method Chaining in D3
The D3 Methods select() and selectAll()
Specifying UTF-8 in HTML5 Web Pages with D3
Creating New HTML Elements
The Most Common Idiom in D3
Binding Data to Document-Object-Model Elements
Generating Text Strings
Creating Simple Two-Dimensional Shapes
Bezier Curves and Text
Two-Dimensional Transforms
A Digression: Scaling Arrays of Numbers to Different Ranges
Tweening in D3
Formatting Numbers
Working with Gradients
Linear Gradients
Radial Gradients
Adding HTML <div> Elements with Gradient Effects
Working with Portable Network Graphics Files
D3 Application Programing Interface Reference
Additional Code Samples on the CD
Summary
Chapter 2: Arrays, Mouse Events, and Animation Effects
Finding the Maximum and Minimum Values in an Array
Working with Multidimensional Arrays
Two-Dimensional Arrays and Scatter Charts
D3 Data Scaling Functions
Other D3.js Scaling Functions
D3 Path Data Generator
What About this, $this, and $(this)?
D3 and Mouse Events
Mouse Events and Randomly Located Two-Dimensional Shapes
A “Follow the Mouse” Example
A Drag-and-Drop Example
Animation Effects with D3
Easing Functions in D3
Zoom, Pan, and Rescale Effects with D3
Handling Keyboard Events with D3
Additional Code Samples on the CD
Summary
Chapter 3: Working with Bar Charts in D3
A Simple Horizontal Bar Chart
Rendering Horizontal and Vertical Axes with Labels
A Scaled Vertical Bar Chart with Labeled Axes
Using Date and Time Stamps to Label Axes
D3 Bar Charts with Unicode Characters
Bar Charts with Three-Dimensional Effects
Bar Charts with Filter Effects and Tooltips
Additional Filter Effects
Updating Bar Charts
Dynamically Adding and Removing Data From Bar Charts
Scrolling Animation Effects with Bar Charts
Additional Code Samples on the CD
Summary
Chapter 4: Other Chart Types and Data Formats
Rendering A Line Graph
Rendering Multiple Nonlinear Graphs
Scatter Charts with Axes and Mouse Events
Selecting Equal Data Points in Scatter Charts
Rendering Pie Charts
A Histogram with Animation Effects
Working with Other Data Formats and Data Files
The XMLHttpRequest Request Object
The jQuery .ajax() Method
Useful D3 Methods for CSV Files
CSV: Synchronous Versus Nonsynchronous D3 Methods
Line Graphs with CSV Data and Mouse Events
Bar Charts with Three-Dimensional Effects from Comma-Separated-Value Files
Additional Code Samples on the CD
Summary
Chapter 5: SVG Essentials
Overview of SVG
Basic Two-Dimensional Shapes in SVG
SVG Gradients and the <path> Element
SVG <polygon> Element
Bezier Curves and Transforms
SVG Filters and Shadow Effects
Rendering Text Along an SVG <path> Element
SVG Transforms
The SVG <clipPath> Element
Other SVG Features
SVG Animation
Creating Three-Dimensional Effects in SVG
SVG and HTML
SVG and JavaScript
CSS3 and SVG
CSS3 and SVG Bar Charts
Similarities and Differences Between SVG And CSS3
SVG and XSLT (Extensible Stylesheet Language Transformations)
Additional Code Samples on the CD
Summary
Chapter 6: Introduction to CSS3 Graphics and Animation
CSS3 Support and Browser-Specific Prefixes for CSS3
Quick Overview of CSS3 Features
CSS3 Pseudoclasses, Attribute Selection, and Relational Symbols
CSS3 Pseudoclasses
CSS3 Attribute Selection
CSS3 Shadow Effects and Rounded Corners
Specifying Colors with Red/Green/Blue Triples and Hue/Saturation/Lightness
Representations
CSS3 and Text Shadow Effects
CSS3 and Box Shadow Effects
CSS3 and Rounded Corners
CSS3 Gradients
Linear Gradients
Radial Gradients
CSS3 Two-Dimensional Transforms
Rotate Transforms
CSS3 Three-Dimensional Animation Effects
CSS3 Media Queries
CSS3 and SVG
Additional Code Samples on the CD
Summary
Chapter 7: D3 with CSS3, SVG, and HTML5 Canvas
D3 Code Samples with HTML5 Canvas
Updated CSS3 Stylesheets for this Chapter
D3 and CSS3 Effects
D3 and CSS3 Animation Effects
D3 and HTML5 Canvas
D3 and SVG
Bubble Charts with JSON Data
Additional Code Samples on the CD
Summary
Chapter 8: D3 with Ajax, HTML5 WebSockets, and NodeJS
D3 and Ajax Requests
D3 with PHP Data
D3 with MySQL Data
D3 Bar Charts with a WebSocket Server
D3 and NodeJS (Optional)
Inserting an <svg> Element in an HTML Web Page
Rendering SVG Graphics with D3 and NodeJS (Optional)
Additional Code Samples on the CD
Summary
Chapter 9: Miscellaneous D3 Application Programming
Interfaces and Other Toolkits
Maps in D3 (Choropleth)
Adding Tooltips to a United States Map
D3 and Google Maps
GeoJSON and D3 TopoJSON
Other Maps
The D3 Force Layout
Using D3 Force with CSS Instead of SVG
D3 Trees
Voronoi Diagrams
Toolkits That are D3 Extensions
The ChartBuilder Extension
The CrossFilter Extension
The dc.js Extension
Rickshaw
D3 and Other Toolkits
D3 Plugins
DVL(Dynamic Visualization LEGO) for Data Visualization
Vega: A Visualization Grammar
NVD3
DexChart: Reusable Charts
R Programming with D3-Based Toolkits
Additional D3 APIs
The D3 Brushes API
D3 and HTML5 Web Audio
What About D3 for Three-Dimensional Graphics and Animation?
Other D3 Resources
Additional Code Samples on the CD
Summary
Chapter 10: HTML5 Mobile Applications on Android and iOS
HTML5/CSS3 and Android Applications
SVG and Android Applications
HTML5 Canvas and Android Applications
Android and HTML5 Canvas Multiline Graphs
What is PhoneGap?
How Does PhoneGap Work?
Software Dependencies for PhoneGap 3.0
Creating Android Hybrid Applications with PhoneGap 3.0
Creating iOS Hybrid Applications with PhoneGap 3.0
Requirements for Deploying Mobile Apps to iOS Devices
Rendering a CSS3 Cube on iOS Using PhoneGap
D3 and Android Applications
D3 and iOS Applications
Developing D3-Based Mobile Applications for Google Glass
How does Google Glass Work?
Supported HTML5 Tags
Unsupported HTML5 Tags
Deploying Android Applications to Google Glass
Displaying Google Glass in an Emulator
Other Useful Links for Google Glass
Other Google Glass Code Samples
Additional Code Samples on the CD
Summary
Index
On The CD
Appendix A: Overview of SVG
Appendix B: Introduction to Android
Appendix C: HTML5 and JavaScript Toolkits
Appendix D: Rendering 2D Shapes in HTLM5 Canvas
PREFACE
The CD contains more than 1,000 code samples that vary from
simple to moderate complexity using different combinations of
technologies. Specifically, there are D3-based code samples along
with “pure” SVG and “pure” CSS3 samples. In addition, you’ll find
code samples that combine D3 with SVG, D3 with CSS3, SVG and
CSS3. The code samples that combine CSS3 and SVG create 3D
animation effects, whereas the pure SVG samples only create static
effects.
In the code samples that are similar (admittedly there are many
on the CD), they are included as a convenience, and their purpose is
to show you stylistic nuances. Obviously the value of those subtle
differences is highly subjective and impossible to quantify, which
means that each person will evaluate the code samples in a different
manner. As a parenthetical yet relevant aside: in the art world there
can be two very similar original paintings by two different artists,
and yet one painting is valuable whereas the other has much lower
perceived value. Putting aside the intrinsic value of the code samples
on the CD, it’s likely that some of them appeal to you and not to
other people (and vice versa).
Think of the code samples as “concept code” in the sense that
they provide you with ideas that you can borrow and enhance even
further with your own variations. This approach of progressively
adding details to provide you with a “swatch-like” variety of code
samples will accommodate a range of reading styles, and you can
jump in wherever you feel most comfortable. Since there will be
concepts that cannot be fully discussed (due to the limited page
count), the inclusion of similar code samples will make it simpler for
you to grasp the additional techniques during your independent
study.
The key points to keep in mind is that supplemental code samples
on the CD show you stylistic variations and they save you the time
required to create those samples, but you can choose to view them
or to ignore them.
INTRODUCTION TO D3
NOTE
Be sure to launch the HTML Web pages in a browser as you read
code samples in this book because this will show you what the
code actually does, and it will also save you time understanding
the code.
WHAT IS D3?
Mike Bostock created the open-source toolkit Protovis, and then
he created the D3 toolkit, which is a JavaScript-based open-source
project for creating very appealing data visualization. D3 is an
acronym for “Data-Driven Documents,” and its homepage is here:
http://mbostock.github.com/d3/
Although D3 can be used for practically any type of data
visualization, common use-cases include rendering maps,
geographic-related data, economic data (such as employment
figures) in conjunction with various locales, and medical data
(diabetes seems to be very popular).
In December of 2011, D3 was named the data-visualization
project of the year (by Flowing Data!), which is not surprising when
you see the functionality that is available in D3.
D3 provides a layer of abstraction that generates underlying
Scalable Vector Graphics (SVG) code. D3 enables you to create a
surprisingly rich variety of data visualizations. If you need to
generate graphics-oriented Web pages, and you prefer to work with
JavaScript instead of working with raw SVG, then you definitely
ought to consider using D3. Two key aspects of D3 involve tools for
reading data in multiple formats and the ability to transform the data
and render the data in many forms. D3 supports the following
features:
D3 ON MOBILE DEVICES
D3 works on any device that supports JavaScript and SVG,
including mobile devices such as smart phones and tablets. These
devices do vary in terms of their support for SVG features. For
instance, Android 3.x has some support for SVG, and currently no
version of Android supports SVG filters (discussed in Chapter 3 and
Chapter 5). In general, iOS devices support more SVG features than
Android-based mobile devices.
If you are writing HTML Web pages for desktops as well as mobile
devices, you probably need to take into account scenarios such as
handling mouse-related events versus touch-related events. In
particular, you ought to test multitouch support on multiple mobile
devices and operating systems to ensure that your Web pages
exhibit the expected behavior.
In addition, you might encounter D3 bugs on mobile devices that
are not readily apparent in HTML Web pages laptops or desktops. If
you do encounter inconsistent behavior, check the issues-related link
in the previous section to see if it’s a known issue. If you do not find
entries, it’s possible that you have discovered an unreported bug in
D3, in which case you can file a new issue.
D3 BOILERPLATE
If you have worked with HTML5, you are probably familiar with
various boilerplate toolkits that are available. In a similar spirit, you
can download a D3 boilerplate toolkit (d3.js-boilerplate) here:
https://github.com/zmaril/d3.js-boilerplate
METHOD CHAINING IN D3
Practically every code sample in this book (and almost all the
online code samples in various forums) use method chaining, so it’s
worth your time to understand method chaining before delving into
the code samples.
The key idea to remember is that a D3 search actually returns a
result set that is the set of elements that match the selection
criteria. You can then apply an action to that set of elements. For
example, you can find all the paragraphs in an HTML Web page and
then set their text in red. Here is an example (taken from Listing
1.1) that uses the d3.selectAll() method to select all the HTML
<p> elements in an HTML Web page and then invokes the style()
method to set the color of the text in those paragraphs in red:
d3.selectAll(“p”).style(“color”, “red”);
https://github.com/mbostock/d3/wiki/Selections
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.
d3.selectAll(“p”).style(“color”, “red”);
NOTE
Some older browsers run JavaScript code before the Document
Object Model (DOM) is available, in which case you can either use
window.onload() to ensure that this does not happen, or you can
insert an empty <div></div> element immediately after the
<body> element and change the occurrences of
d3.select(“body”) to d3.select(“div”). Figure 1.1 displays the
graphics image that is rendered by the code in the HTML Web
page in Listing 1.1.
Here is how to read the code in the preceding code block, starting
from the definition of the paras variable:
Step 1: Start by selecting the <body> element of the current HTML
Web page (using the select() method).
Step 2: Return the result set of all the child <p> elements using
the selectAll() method (if there are no child <p> elements, the
returned set is a set of length zero).
Step 3: Iterate or loop through the numbers in the JavaScript
array theData to create a new HTML <p> element whose text value is
the string D3.
Step 4: After each iteration in Step 3, append the newly created
<p> element to the result set in Step 2.
NOTE
The d3.selectAll() method always returns a result set, which
can be an empty set (and therefore, this method never returns a
null or undefined value).
d3.select(“body”).append(“paras”);
NOTE
Because every HTML Web page in this book starts with the same
boilerplate code in the HTML <head> element, we will omit this
duplicated description for the rest of the book.
Figure 1.2 displays the result of rendering the HTML Web page in
Listing 1.2 in a Web browser.
Figure 1.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.
Compare the code in Listing 1.4 with the preceding code block to
verify that the preceding SVG elements correspond to the code in
Listing 1.4. You can use an alternate coding style that defines
multiple JavaScript variables, as shown in the following code block:
Figure 1.4 displays the graphics image that is rendered by the
code in the HTML Web page in Listing 1.4.
FIGURE 1.4 D3 Code for a Circle, an Ellipse, a Rectangle, and a Line Segment.
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.
TWO-DIMENSIONAL TRANSFORMS
D3 provides support for four 2D transforms: rotate, scale, skew,
and translate. You can apply transforms to 2D shapes using the D3
.attr() method, as shown in the following examples:
When you open the Web Inspector (see comments in the Preface)
you will see the following:
Another random document with
no related content on Scribd:
But no one loves the scenes of nature more than I. The first
sunset that I remember with enjoyment occurred when I was ten
years old; and how many I have seen since then! On an autumn day
in 1903, I saw the sun sink into the ocean off the coast of Normandy,
and, by the miracle of memory, I can see it again whenever I wish. I
thought of Browning’s lines:
I have seen the Matterhorn from the Gorner Grat, Mont Blanc
from Chamonix, and the divine flush on the summit of the Jungfrau.
Forty years ago I heard for the first time the Ninth Symphony;
and while I have heard it often since then, the most memorable
occasion was in May 1912 when I heard it at Paris, played by a
magnificent orchestra, conducted by Felix Weingartner; I have heard
Die Meistersinger in Munich, conducted by Arthur Nikisch; I have
heard the Emperor Concerto, with Ossip Gabrilowitsch at the piano; I
have heard Tod und Verklärung with Stokowski and the Philadelphia
Orchestra; I have heard De Pachmann (in his prime) play Chopin’s B
flat minor sonata, Paderewski play Liszt’s Hungarian Rhapsody No.
2, Josef Hofmann play Beethoven’s Sonata 111. I have heard
Carmen sung by Emma Calvé, Emma Eames, Jean de Reszké and
Lassalle; Tristan und Isolde sung by Jean de Reszké and Lilli
Lehmann; Faust sung by Jean and Edouard de Reszké, Emma
Eames, Maurel, and Scalchi; Mignon sung by Mme. Lucrezia Bori; I
have repeatedly heard the three greatest bassos of modern times,
Edouard de Reszké, Pol Plançon, and Chaliapin.
In the theatre I have seen Edwin Booth as Shylock, Mansfield as
Richard III, Irving in The Lyons Mail, Possart as Mephistopheles,
Sarah Bernhardt as La Tosca, Duse as Francesca, Salvini as
Othello, and twice have I seen the Passion Play at Oberammergau.
All these are memorable experiences, and for fear I may not be
conscious when I am dying, I am recalling them now. But if I should
attempt to recall all the glorious things I have seen in nature and in
art, I should have no time for fresh experiences that await me.
As for social pleasures, one of the highest enjoyments is
agreeable company and good conversation; and I especially like
men, women and children.
Transcriber’s Notes
Punctuation, hyphenation, and spelling were made
consistent when a predominant preference was found in the
original book; otherwise they were not changed.
Simple typographical errors were corrected; unbalanced
quotation marks were remedied when the change was
obvious, and otherwise left unbalanced.
Just for the curious: Chapter XVIII has four references to
“F. P. A.” but doesn’t give the full name. When this book was
written, he was a well-known columnist: Franklin P. Adams.
*** END OF THE PROJECT GUTENBERG EBOOK ESSAYS ON
THINGS ***
1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside
the United States, check the laws of your country in addition to
the terms of this agreement before downloading, copying,
displaying, performing, distributing or creating derivative works
based on this work or any other Project Gutenberg™ work. The
Foundation makes no representations concerning the copyright
status of any work in any country other than the United States.
1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if
you provide access to or distribute copies of a Project
Gutenberg™ work in a format other than “Plain Vanilla ASCII” or
other format used in the official version posted on the official
Project Gutenberg™ website (www.gutenberg.org), you must, at
no additional cost, fee or expense to the user, provide a copy, a
means of exporting a copy, or a means of obtaining a copy upon
request, of the work in its original “Plain Vanilla ASCII” or other
form. Any alternate format must include the full Project
Gutenberg™ License as specified in paragraph 1.E.1.
• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.
1.F.
Most people start at our website which has the main PG search
facility: www.gutenberg.org.