billfeller.github.io icon indicating copy to clipboard operation
billfeller.github.io copied to clipboard

【译】D3 5.0 版本更新

Open billfeller opened this issue 6 years ago • 0 comments

D3 5.0 在 2018.03.28 正式发布。

5.0 比较 4.x 仅有少量非向后兼容特性。

  1. [新特性] 新版本加载数据接口引入 Promise 替代异步回调函数,简化异步函数调用方法,特别是在现代浏览器中,可以使用 async/await 。

例如,在 4.0 中加载 CSV 数据,如下:

d3.csv("file.csv", function(error, data) {
  if (error) throw error;
  console.log(data);
});

现在,代码可简化为:

d3.csv("file.csv").then(function(data) {
  console.log(data);
}).catch(function (error) {
  console.log(error);
})

或者使用 await :

try {
  const data = await d3.csv("file.csv");
  console.log(data);
} catch (error) {
  console.log(error);
} 
  1. [新特性] 新版本使用 Fetch API 替代 XMLHttpRequest ,即使用 d3-fetch 模块替换 d3-request 模块,从而支持 Fetch API 更多的功能特性。

  2. [废弃] 新版本废弃 d3-queue 模块,推荐使用 Promise.all 或者第三方库 p-queue 或者 control concurrency 实现异步任务队列处理任务。

  3. [废弃] 新版本废弃 d3.schemeCategory20* 配色方案,原因如下:

These twenty-color schemes were flawed because their grouped design could falsely imply relationships in the data: a shared hue can imply that the encoded data are part of a group (a super-category), while relative lightness can imply order. 新版本引入 d3-scale-chromatic 模块实现 ColorBrewer 新的配色方案,其中包括分类, 发散, 顺序的单色调和有序的多色调方案。这些方案可在离散和连续的变体中使用。

  1. [新特性] 新版本提供了 marching squaresdensity estimation算法的模块实现 d3-contour ;

  2. [新特性] 新版本中,d3-selection 引入两个新API:selection.clone 用于插入选择克隆的节点;d3.create 用于创建分离的节点。

  3. [新特性] 新版本中,地理投影现在支持角度投影(projection.angle),以便实现Philippe Rivière 多面体投射(polyhedral projections)。

  4. [bugfix] 新版本中, package.json 不再指定固定的依赖模块版本,以便修复模块重复安装问题;

以上就是 D3 5.0 版本设计的更新的特性。

原文阅读:https://github.com/d3/d3/blob/master/CHANGES.md

———————————— 数据可视化领域正在跟随高速发展中,导致与之对应的可视化工具,诸如 D3 API 也在快速变化中,但是相应的文档示例更新相对滞后,需要开发人员及时关注版本更新日志,以便更好地跟进行业技术现状,提升业务开发能力。

billfeller avatar May 05 '18 15:05 billfeller