Learning D3.js 5 Mapping - Second Edition

Book description

Crisp and concise guide on building impressive maps as well as visualizations with D3 a JavaScript library

About This Book

  • Dive into D3.js and apply its powerful data binding ability in order to create stunning visualizations
  • Learn the key concepts of SVG, JavaScript, CSS and the DOM to bring data and shapes to live in the browser
  • Solve common problems faced while building interactive maps
  • Acquire key web development skills from the creating your interactive to testing and finally publishing it.

Who This Book Is For

This book is for people with at least a basic knowledge of of web development (basic HTML/CSS/JavaScript). You don't need to have worked with D3.js before.

What You Will Learn

  • Work with SVG geometric shapes
  • Learn to manage map data and plot it with D3.js
  • Add interactivity and points of interest to your maps
  • Compress and manipulate geoJSON files with the use of topoJSON
  • Learn how to write testable D3.js visualizations
  • Build a globe with D3.js and Canvas and add interactivity to it.
  • Create a hexbin map with D3.js

In Detail

D3.js is a visualization library used for the creation and control of dynamic and interactive graphical forms. It is a library used to manipulate HTML and SVG documents as well as the Canvas element based on data. Using D3.js, developers can create interactive maps for the web, that look and feel beautiful.

This book will show you how build and design maps with D3.js and gives you great insight into projections, colors, and the most appropriate types of map.

The book begins by helping you set up all the tools necessary to build visualizations and maps. Then it covers obtaining geographic data, modifying it to your specific needs, visualizing it with augmented data using D3.js. It will further show you how to draw and map with the Canvas API and how to publish your visualization. By the end of this book, you'll be creating maps like the election maps and the kind of infographics you'll find on sites like the New York Times.

Style and approach

This step by step guide with pragmatic examples will help you create maps and amazing visualizations.

Table of contents

  1. Title Page
    1. Second Edition
  2. Copyright
    1. Learning D3.js 5 Mapping
      1. Second Edition
  3. Credits
  4. Foreword
  5. About the Authors
  6. About the Reviewers
  7. www.PacktPub.com
    1. Why subscribe?
  8. Customer Feedback
  9. Preface
    1. What this book covers
    2. What you need for this book
    3. Who this book is for
    4. Conventions
    5. Reader feedback
    6. Customer support
      1. Downloading the example code
      2. Downloading the color images of this book 
      3. Errata
      4. Piracy
      5. Questions
  10. Gathering Your Cartography Toolbox
    1. Quick bootstrap
    2. Step-by-step bootstrap
      1. A lightweight web server
    3. Using the web browser as a development tool
      1. Installing the sample code
      2. Working with the developer tools
    4. Summary
  11. Creating Images from Simple Text
    1. The SVG coordinate system
    2. Line
    3. Rectangle
    4. Circle
    5. Polygon
    6. Path
      1. Experiment
      2. Paths with curves
    7. Transform
      1. Translate
      2. Scale
    8. Grouping
    9. Text
    10. Summary
  12. Producing Graphics from Data - the Foundations of D3
    1. Creating basic SVG elements
    2. The enter() function
    3. The update function
    4. The exit() function
    5. Fetch
    6. Summary
  13. Creating a Map
    1. Foundation - creating your basic map
      1. Including the dataset
    2. Experiment 1 – adjusting the bounding box
    3. Experiment 2 – creating choropleths
    4. Experiment 3 – adding click events to our visualization
    5. Experiment 4 – using updates and transitions to enhance our visualization
    6. Experiment 5 – adding points of interest
    7. Experiment 6 – adding visualizations as a point of interest
    8. Summary
  14. Click-Click Boom! Applying Interactivity to Your Map
    1. Events and how they occur
    2. Experiment 1 – hover events and tooltips
    3. Experiment 2 – tooltips with visualizations
    4. Experiment 3 – panning and zooming
    5. Experiment 4 – orthographic projections
    6. Experiment 5 – rotating orthographic projections
    7. Experiment 6 – dragging orthographic projections
    8. Summary
  15. Finding and Working with Geographic Data
    1. Geodata file types
      1. What are shapefiles and how do I get them?
        1. Acquiring shapefiles for a specific country
      2. GeoJSON
      3. A quick map in D3 with only GeoJSON
      4. TopoJSON basics
      5. TopoJSON command-line tips
        1. Simplification
        2. Merging files
    2. Summary
  16. Testing
    1. Code organization and reusable assets
    2. Project structure
      1. Exploring the code directory
      2. Other administrative files
    3. Writing testable code
      1. Keeping methods/functions small
      2. Preventing side effects
      3. An example with viz.js
    4. Unit testing
    5. Creating resilient visualization code
      1. Adding a new test case
    6. Summary
  17. Drawing with Canvas and D3
    1. Introducing Canvas
      1. Drawing with Canvas
        1. The three drawing steps of every Canvas visual
        2. Drawing various shapes with Canvas
    2. Animating the Canvas
      1. Animating the Canvas way
        1. Getting a general overview
        2. Preparing the rain data
        3. Updating each drop
        4. Drawing frame by frame
      2. Canvas and D3
        1. Getting an overview of our experiment
        2. The data
        3. Updating each drop
          1. Binding the data
          2. Drawing the data
          3. Running the app
    3. Summary
  18. Mapping with Canvas and D3
    1. Choosing Canvas or SVG
      1. Reasons to choose SVG
      2. Reasons to choose Canvas
    2. Visualizing flight paths with Canvas and D3
      1. The data
      2. Building the flight path map in SVG
        1. Measuring the performance
      3. Building the flight path map in Canvas
        1. Setting up the map
        2. Drawing the map and listening for user input
        3. Preparing and drawing with Canvas
          1. Drawing the background scene
          2. Defining the planes
          3. Calculating the plane's positions
          4. Animating the plane
        4. Measuring the performance
          1. Optimizing performance
          2. Continuing with measuring performance
    3. Summary
  19. Adding Interactivity to Your Canvas Map
    1. Why Canvas interaction is different
    2. Drawing the world on a Canvas
      1. Setting up
      2. Drawing the world
    3. Making the world move
      1. Setting up the behavior
      2. Handling zoom and rotation
    4. Finding the Canvas object under the mouse - Picking
      1. Picking, the theory
        1. Creating all things hidden
        2. Drawing the hidden Canvas
        3. Picking the values
          1. Storing more data and using a lookup array
      2. Highlighting the country on mouse over
    5. Visualizing data per country and adding a tooltip
      1. Adding new data to our old globe
      2. Coloring the globe
      3. Adding a tooltip
        1. The HTML
        2. Building the static parts of the tooltip
        3. Showing and hiding the tooltip
    6. Summary
  20. Shaping Maps with Data - Hexbin Maps
    1. Reviewing map visualization techniques
      1. Choropleth maps
      2. Cartograms
      3. Dot density maps
    2. Value and use of the hexagon
    3. Making a hexbin map
      1. Reviewing the hexbin algorithm
      2. Setting it up
      3. Drawing the map
      4. Drawing a point grid for our hexagons
      5. Keeping only the points within the map
      6. Making the hex tile
        1. Retrieving the hexagon center points
        2. Drawing the hex tiles
      7. Joining data points to the layout points
      8. Dressing our data for the final act
      9. Turning our visual into an interactive app
        1. Adding additional information on hover and click
        2. Changing the hexagon size
        3. Changing the color scale interpolator
        4. Browsing different datasets
        5. Encoding data as hexagon size
    4. Summary
  21. Publishing Your Visualization with GitHub Pages
    1. What we will publish
    2. Understanding the type of content you can publish
    3. Hosting your code on GitHub
      1. Making sense of some key terms and concepts
        1. Tracking historic changes of your files
        2. Collaborating on a project
        3. Working on project branches
      2. Setting up a GitHub account
      3. Creating a repository
      4. Editing a file on GitHub
      5. Uploading files to the repository
    4. Publishing your project on GitHub Pages
      1. Preparing the files for publishing
        1. Keeping your paths absolute
        2. Changing the main HTML filename to index.html
      2. Publishing your project
    5. Summary

Product information

  • Title: Learning D3.js 5 Mapping - Second Edition
  • Author(s): Thomas Newton, Oscar Villarreal, Lars Verspohl
  • Release date: November 2017
  • Publisher(s): Packt Publishing
  • ISBN: 9781787280175