资源与延伸阅读 — 第 20/21 章拆解
资源与延伸阅读 — 第 20/21 章拆解
这一章讲什么: 原书第 20 章是一张资源地图——规范、工具、社区、数据集, 每样都标了在哪些章用过;第 21 章是 Packt 书籍的解锁权益说明(换 PDF、在线阅读器), 与 D3 知识无关,我们的拆解只留一句。这份文档照原书的分类重排,并保留了 「什么工具治什么病」的对应关系——这是本章最有信息量的部分。
1. 规范与文档(治病的「药典」)
原书列的官方规格与社区文档,按用途分1:
| 用途 | 资源 |
|---|---|
| D3 一切 | d3js.org——下载库、看文档、翻交互示例(全书所有章) |
| JavaScript 语言 | ECMAScript 2019 官方规范(262.ecma-international.org);MDN 的 JavaScript 参考 |
| 选择器语法 | W3C Selectors 规范(D3 的 select 只支持其一部分) |
| DOM / Canvas | W3C DOM Level 3;WhatWG Canvas 规范 + MDN Canvas 教程(第 2 章) |
| SVG | SVG 1.1 与 SVG 2 规范、MDN SVG 参考;SVG 1.1 的 animate 一章对应第 13 章的 SVG 动画 |
| 事件 | MDN Event 与 Pointer events 参考(第 14 章) |
| 地理数据 | GeoJSON RFC 7946(2016);TopoJSON 规范(2013)——两都在第 19 章重度使用 |
一个值得记住的不兼容:D3 的 GeoJSON 处理不完全遵循 RFC 7946, 多边形缠绕顺序(winding order)不同会导致某些 shapefile 转出的文件渲染错误—— 这正是下一节 GIS 工具存在的理由2。
2. GIS 转换工具(治病的「药房」)
四个工具,都围绕同一个病:D3 与 RFC 7946 的缠绕顺序差异3:
| 工具 | 干什么 |
|---|---|
| mapshaper.org | 任意 GIS 格式 → GeoJSON/TopoJSON;导出给 D3 的 GeoJSON 要用命令行选项 gj2008 |
| geojson.io | 在线创建/编辑 GeoJSON;导出时选 Advanced Options →「D3 winding order」 |
| rfc7946-to-d3(Martin Raifer) | 文件已是 RFC 7946 合规格式时,用这个小工具转一次即可 |
| QGIS | 桌面 GIS,可导出多种格式与缠绕顺序 |
3. 库与社区
| 资源 | 干什么 | 书中位置 |
|---|---|---|
| github.com/d3 | D3 各模块仓库,README 即文档 | 全部 |
| Observable(observablehq.com/@d3) | D3 生态的主社区:交互 notebook、官方示例、创意解法 | 第 1 章起反复出现 |
jsDelivr / Skypack 的 d3@7 CDN 链接 | 引库方式(全书代码的引法) | 全部 |
| Color Brewer(colorbrewer2.org) | 配色方案的出处;可按色盲安全/灰度打印筛选 | 第 10 章 |
| versor(github.com/d3/versor) | 四元数旋转库,地图拖拽的正确解法 | 第 19 章 |
| d3-inertia(github.com/Fil/d3-inertia) | 地图惯性拖拽插件 | 第 19 章 |
4. 书中数据集的出处
原书示例全部用公开数据,来源照实列出(我们转述类别,具体条目见原文)4:
- Natural Earth:世界与各大洲的 GeoJSON/TopoJSON 底图(经 mapshaper 转换)——第 1、4、19 章所有地图的底;
- NASA GISS:全球变暖教程的温度距平数据(第 11、13 章);
- 联合国 / 世界银行:人口、HDI、GDP、移民数据(散点图、气泡图、网络图的数据源);
- GeoNames:城市坐标库(点密度图、分级圆点图、多源加载练习);
- slavevoyages.org:跨大西洋奴隶贸易数据(第 12 章堆叠面积图教程);
- 维基百科:谱系、地层、海岸、航线等小数据集;
- RATP/NY/圣保罗开放数据:第 18 章地铁网络;
- 其余还有火星(Mars ASU)、土卫六(USGS)、星表(NASA HEASARC Hipparcos)——第 19 章「地图不限于地球」的例子。
仓库的 Appendix/ 还附了四份补充材料:模块速查、D3 v7 迁移指南、npm 环境搭建、React 集成示例5。
5. 第 21 章(Packt 权益)
纸质书附带 Packt 账户权益的解锁流程(扫码、上传购书凭证、换 PDF/ePub 与在线阅读器)。 与 D3 无关,拆解到此为止6。
6. 可带走的
- 出问题先查 d3js.org 与 MDN,规范层的细节(SVG 动画、指针事件)回原书第 20 章的链接表;
- 地图文件渲染不对 → 缠绕顺序病 → mapshaper(
gj2008)/ geojson.io(D3 winding order); - 学 D3 的主社区是 Observable;配色先去 Color Brewer;
- 地图拖拽旋转用 versor + d3-inertia,别自己写两角近似;
- 书中数据集全部公开可下载,来源在第 20 章照实列出——自己练手直接复用。
7. 原文地图
| 主题 | 原书章 | 原文位置 |
|---|---|---|
| 规范与文档清单 | References and Additional Resources | text/28-ch20-chapter-20-references-and-additional-resources.txt:14(搜「d3js.org」) · text/28-ch20-chapter-20-references-and-additional-resources.txt:43(搜「RFC 7946」) |
| 不兼容声明 | References and Additional Resources | text/28-ch20-chapter-20-references-and-additional-resources.txt:50(搜「not fully follow RFC 7946」) |
| GIS 工具四件 | References and Additional Resources | text/28-ch20-chapter-20-references-and-additional-resources.txt:54(搜「mapshaper.org」) · text/28-ch20-chapter-20-references-and-additional-resources.txt:58(搜「D3 winding order」) |
| 库与社区 | References and Additional Resources | text/28-ch20-chapter-20-references-and-additional-resources.txt:66(搜「github.com/d3」) · text/28-ch20-chapter-20-references-and-additional-resources.txt:72(搜「cdn.jsdelivr.net」) · text/28-ch20-chapter-20-references-and-additional-resources.txt:76(搜「versor」) |
| 数据集出处 | References and Additional Resources | text/28-ch20-chapter-20-references-and-additional-resources.txt:87(搜「naturalearthdata.com」) · text/28-ch20-chapter-20-references-and-additional-resources.txt:95(搜「data.un.org」) · text/28-ch20-chapter-20-references-and-additional-resources.txt:112(搜「geonames.org」) |
| Appendix 四件 | References and Additional Resources | text/28-ch20-chapter-20-references-and-additional-resources.txt:128(搜「Appendix/Modules」) |
| 第 21 章权益 | Unlock Your Exclusive Benefits | text/29-ch21-chapter-21-unlock-your-exclusive-benefits.txt:2(搜「exclusive benefit」) |
Footnotes
-
出处:「References and Additional Resources」第 9–47 段(
text/28-ch20-chapter-20-references-and-additional-resources.txt:14,搜「d3js.org」;:43,搜「RFC 7946」)。 ↩ -
出处:「References and Additional Resources」第 43–45 段(
text/28-ch20-chapter-20-references-and-additional-resources.txt:45,搜「not fully conformant」)。 ↩ -
出处:「References and Additional Resources」第 49–61 段(
text/28-ch20-chapter-20-references-and-additional-resources.txt:54,搜「mapshaper.org」;:56,搜「D3 winding order」;:59,搜「rfc7946-to-d3」)。 ↩ -
出处:「References and Additional Resources」第 82–122 段(
text/28-ch20-chapter-20-references-and-additional-resources.txt:87,搜「naturalearthdata.com」;:101,搜「data.giss.nasa.gov」;:112,搜「geonames.org」;:116,搜「Hipparcos」)。 ↩ -
出处:「References and Additional Resources」第 124–134 段(
text/28-ch20-chapter-20-references-and-additional-resources.txt:128,搜「Appendix/Modules」;:132,搜「Migration」)。 ↩ -
出处:「Unlock Your Exclusive Benefits」第 1–13 段(
text/29-ch21-chapter-21-unlock-your-exclusive-benefits.txt:2,搜「exclusive benefit」)。 ↩