- Learning D3.js Mapping
- Thomas Newton Oscar Villarreal
- 563字
- 2021-08-06 19:42:43
Using the web browser as a development tool
Although any modern browser supports SVG and has some kind of console, we strongly recommend you to use Google Chrome for these examples. It comes bundled with developer tools that will allow you to very easily open, explore, and modify the code. If you are not using Google Chrome, please go to http://www.google.com/chrome and install Google Chrome.
Installing the sample code
Go to https://github.com/climboid/d3jsMaps and either clone the repo, if you are familiar with Git cloning, or simply download the zipped version. Once it is downloaded, make sure to extract the file if you have it zipped.
Use the command prompt or terminal to go to the directory where you downloaded your file. For instance, if you downloaded the file to your desktop, type in the following:
cd ~/Desktop/d3jsMaps http-server
The last command will launch the simple server we installed previously for the supplied sample code. This means that, if you open your browser and go to http://localhost:8080/chapter-1/example-1.html
, you should see a map of Europe, similar to the one shown earlier.
Working with the developer tools
It's time to open the developer tools. On the top-right corner of the browser, you will see the icon as shown in the following screenshot:

This icon opens a submenu. Click on Tools. Then click on Developer tools. A panel will open at the bottom of the browser, containing all the developer tools at your disposal.

Within developer tools, you have a series of tabs (Elements, Network, Sources, and so on). These tools are extremely valuable and will allow you to inspect different aspects of your code. For more information on the Chrome developer tools, please go to the link https://developer.chrome.com/devtools/docs/authoring-development-workflow.
Since we are going to focus on the Elements tab, click on it if it is not already selected.
You should see something similar to the preceding screenshot; it will have the following code statement:
<svg width="812" height="584">
If you click on the SVG item, you should see it expand and display the path tag. The path tag will have several numbers and characters tied to a d
attribute. These numbers are control points that draw the path. We will cover how the path is drawn in the next chapter and how path tags are used to create maps in Chapter 4, Creating a Map and Chapter 5, Click-click Boom! Applying Interactivity to Your Map.
We also want to draw your attention to how the HTML5 application loads the D3 library. Again in the Elements tag, after the SVG tag, you should see the <script>
tag pointing to D3.js and topojson:
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script> <script src="http://d3js.org/topojson.v1.min.js"></script>
If you click on the path located inside the SVG tag, you will see a new panel called the CSS inspector or the styles inspector. It shows and controls all the styles that are applied to a selected element—in this case the path element.
These three components create a D3 visualization:
- HTML5 (the SVG and path elements)
- JavaScript (the D3.js library and map code)
- CSS (the styling of the HTML5 elements)
Creating maps and visualizations using these three components will be discussed and analyzed throughout the book.
- 輕松學(xué)C語言
- Hands-On Artificial Intelligence on Amazon Web Services
- 數(shù)據(jù)中心建設(shè)與管理指南
- Mobile DevOps
- 數(shù)據(jù)挖掘?qū)嵱冒咐治?/a>
- Deep Reinforcement Learning Hands-On
- Microsoft System Center Confi guration Manager
- 中國戰(zhàn)略性新興產(chǎn)業(yè)研究與發(fā)展·增材制造
- 計算智能算法及其生產(chǎn)調(diào)度應(yīng)用
- Apache Spark Quick Start Guide
- Hands-On Microservices with C#
- 基于元胞自動機的人群疏散系統(tǒng)建模與分析
- Flash CS3動畫制作
- Microsoft 365 Mobility and Security:Exam Guide MS-101
- CAD應(yīng)用程序開發(fā)詳解