Book Image

Learning D3.js Mapping

Book Image

Learning D3.js Mapping

Overview of this book

Table of Contents (14 chapters)
Learning D3.js Mapping
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
6
Finding and Working with Geographic Data
Index

Preface

This book explores the JavaScript library, D3.js, and its ability to help us create maps and amazing visualizations. You will no longer be confined to third-party tools in order to get a nice looking map. With D3.js, you can build your own maps and customize them as you please. This book will go from the basics of SVG and JavaScript to data trimming and modification with TopoJSON. Using D3.js to glue together these three key ingredients, we will create very attractive maps that will cover many common use cases for maps, such as choropleths, data overlays on maps, and interactivity.

What this book covers

Chapter 1, Gather Your Cartographer's Toolbox, covers the tools you need to install to build maps effectively with D3. We will cover the instructions to add NodeJS, npm, and TopoJSON to your system. This is needed in order to quickly bootstrap a local web server and to have the ability to manipulate map data.

Chapter 2, Creating Images from Simple Text, describes the basics of creating multiple shapes and designs with Scalable Vector Graphics (SVG).

Chapter 3, Producing Graphics from Data – the Foundations of D3, will deep dive into the main library of this book, D3.js. Concepts such as enter, update, and exit will be explained in detail with the use of some clever experiments and examples.

Chapter 4, Creating a Map, takes you through every step required to build a map with D3. Asynchronous loading of data, bounding box and projection creation, and TopoJSON element modification and data binding will be the bread and butter of this chapter.

Chapter 5, Click-click Boom! Applying Interactivity to Your Map, covers hover, panning, zooming, and their equivalent in touch events. Also, we'll dive into some nifty 3D projections, and a la par, we will learn transitions via experimentation.

Chapter 6, Finding and Working with Geographic Data, will take you through the process of acquiring data and optimizing it to your needs. This chapter covers one of the most important aspects of map visualization in detail via the use of TopoJSON.

Chapter 7, Testing, explains how to structure your codebase in order to have reusable chart components that are easily unit tested and primed for reuse in future projects.

What you need for this book

The following are the requirements for this book; these work on OS X, Windows, and Linux:

  • A D3.js library v3.4.12

  • NodeJS v0.10.32

Who this book is for

This book is carefully designed to allow the reader to jump between chapters based on what they are planning to get out of the book. Here is a brief guide to help you navigate the book:

  • In all cases, briefly read Chapter 1, Gather Your Cartographer's Toolbox, as it will provide a baseline on how your system is set up to easily follow the rest of the examples.

  • If you are new to SVG and D3, then read Chapter 2, Creating Images from Simple Text, and Chapter 3, Producing Graphics from Data – the Foundations of D3. Chapter 3, Producing Graphics from Data – the Foundations of D3, also provides a refresher to the enter, update, and exit pattern for those who have experience in D3.

  • If you are comfortable with all these basics and ready to jump into map creation immediately, then you can proceed directly to Chapter 4, Creating a Map, and Chapter 5, Click-click Boom! Applying Interactivity to Your Map. The examples should be easy to follow and help you get bootstrapped with map making quickly.

  • Once you are comfortable with map making, then Chapter 6, Finding and Working with Geographic Data, will help you further your craft by providing tools to help you work with the data.

  • If you are interested in testing D3 visualizations (not just maps), then read Chapter 7, Testing. It does not assume any prior map-making knowledge and can be read independently of chapters 4, 5, and 6.

Every chapter is full of pragmatic examples that can easily provide the foundation to more complex work. We have explained, step by step, how each example works. That said, we also firmly believe in "learning by doing". As you work through the examples, continue to experiment with the sample code provided. Change the data. Change the scaling functions and colors. See how the map reacts and play with D3. Most importantly, have fun!

Conventions

In this book, you will find a number of styles of text 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: "Then open your web browser to http://localhost:8080."

A block of code is set as follows:

<?xml version="1.0"?>
<svg width="200" height="200">
  <circle cx="60" cy="60" r="50"/>
  <circle cx ="5" cy="5" r="10" />
  <circle cx="25" cy="35" r="45" />
  <circle cx="180" cy="180" r="10"/>
  <circle cx="80" cy="130" r="40" />
  <circle cx="50" cy="50" r="5" />
  <circle cx="2" cy="2" r="7"/>
  <circle cx="77" cy="77" r="17"/>
  <circle cx="100" cy="100" r="40"/>
  <circle cx="146" cy="109" r="22"/>
</svg>

Any command-line input or output is written as follows:

npm install -g http-server

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "Click on the INSTALL button."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

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.

To send us general feedback, simply e-mail , and mention the book's title in the subject of your message.

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.

Downloading the example code

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.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

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.

Please contact us at with a link to the suspected pirated material.

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 , and we will do our best to address the problem.