You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by sh...@apache.org on 2022/01/21 15:31:25 UTC

[echarts-handbook] branch master updated: update 5.3.0 feature

This is an automated email from the ASF dual-hosted git repository.

shenyi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/echarts-handbook.git


The following commit(s) were added to refs/heads/master by this push:
     new a1ca923  update 5.3.0 feature
a1ca923 is described below

commit a1ca923d029fd349fc112d782f1f798e282b8aeb
Author: pissang <bm...@gmail.com>
AuthorDate: Fri Jan 21 23:30:58 2022 +0800

    update 5.3.0 feature
---
 contents/zh/basics/release-note/5-3-0.md | 165 +++++++++++++++++++++++++++++--
 static/images/5-3-0/map-projection.gif   | Bin 0 -> 4607050 bytes
 2 files changed, 159 insertions(+), 6 deletions(-)

diff --git a/contents/zh/basics/release-note/5-3-0.md b/contents/zh/basics/release-note/5-3-0.md
index f53c7c6..ad960d0 100644
--- a/contents/zh/basics/release-note/5-3-0.md
+++ b/contents/zh/basics/release-note/5-3-0.md
@@ -264,7 +264,7 @@ function renderItem() {
 
 如果你不想一一写出每个要动画的属性,现在你可以直接配置`transition: 'all'`为所有属性都加上动画过渡。
 
-同时还新增了`enterAnimation`, `updateAnimation`, `leaveAnimation`分别配置每个图形入场,更新,出场动画的时长(duration),延迟(delay)和缓动(easing)
+与此同时我们还新增了`enterAnimation`, `updateAnimation`, `leaveAnimation`分别配置每个图形入场,更新,出场动画的时长(duration),延迟(delay)和缓动(easing)
 
 ## 全新的 SVG 渲染器
 
@@ -278,17 +278,170 @@ function renderItem() {
 | :------------------------------------: | :----------------------------------: |
 | ![before](images/5-3-0/svg-before.gif) | ![after](images/5-3-0/svg-after.gif) |
 
-这次更新对于使用和用户体验来说,除了变得更流畅,其它方面都是无感的。
-
 ## 零依赖的服务端渲染
 
-除了性能的提升,新的 SVG 渲染器可以实现完全零依赖的服务端渲染,输出更精简并且带有 CSS 动画的 SVG 字符串。
+在之前的版本 ECharts 也可以实现服务端的渲染,但是必须得依赖 [node-canvas](https://github.com/Automattic/node-canvas),如果是使用 SVG 模式则需要依赖 [JSDom](https://github.com/jsdom/jsdom) 来模拟 DOM 环境。这些依赖一是带来了额外的体积和使用要求,二是也会有更多的性能损耗。
+
+这次新的 SVG 渲染器除了性能的提升,也带来了完全零依赖的服务端渲染,输出更精简并且带有 CSS 动画的 SVG 字符串。
+
+```ts
+const echarts = require('echarts');
+
+// 在 SSR 模式下第一个参数不需要再传入 DOM 对象
+const chart = echarts.init(null, null, {
+  renderer: 'svg', // 必须使用 SVG 模式
+  ssr: true, // 开启 SSR
+  width: 400, // 需要指明高和宽
+  height: 300
+});
+
+// 像正常使用一样 setOption
+chart.setOption({
+  xAxis: {
+    type: 'category',
+    data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
+  },
+  yAxis: {
+    type: 'value'
+  },
+  series: [
+    {
+      data: [120, 200, 150, 80, 70, 110, 130],
+      type: 'bar'
+    }
+  ]
+});
+
+// 输出字符串
+const svgStr = chart.renderToSVGString();
+```
+
+我们在 CodeSandbox 中搭建一个最简单的 NodeJS 服务器然后使用 ECharts 服务端渲染的效果:
+
+<iframe src="https://codesandbox.io/embed/heuristic-leftpad-oq23t?autoresize=1&codemirror=1&fontsize=12&hidenavigation=1&&theme=dark"
+     style="width:100%; height:400px; border:0; border-radius: 4px; overflow:hidden;"
+     title="heuristic-leftpad-oq23t"
+     allow="accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking"
+     sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"
+   ></iframe>
 
 ## 自定义地图投影
 
-## 多坐标轴对齐
+地图一直是 ECharts 中使用非常广泛的组件。一般地图组件会使用存储了经纬度的 GeoJSON 格式的数据。而 ECharts 则计算出合适的显示区域然后把经纬度线性映射到这个区域。这是一种最简单的地图投影方式。但是简单的线性投影并无法满足某些复杂的地图场景,例如使用 [Albers](https://en.wikipedia.org/wiki/Albers_projection) 投影解决线性投影中面积失真的问题,或者在世界地图中让太平洋区域显示在中间等等。
+
+因此在 5.3.0 里中我们引入了自定义的地图投影,可以通过`project`和`unproject`两个方法告诉 ECharts 如何投影坐标,以及如何根据投影后坐标计算经纬度。下面是简单的使用墨卡托投影的例子:
+
+```ts
+series = {
+  type: 'map',
+  projection: {
+    project: point => [
+      (point[0] / 180) * Math.PI,
+      -Math.log(Math.tan((Math.PI / 2 + (point[1] / 180) * Math.PI) / 2))
+    ],
+    unproject: point => [
+      (point[0] * 180) / Math.PI,
+      ((2 * 180) / Math.PI) * Math.atan(Math.exp(point[1])) - 90
+    ]
+  }
+};
+```
+
+除了我们自己实现投影公式,我们也可以使用 [d3-geo](https://github.com/d3/d3-geo) 等第三方库提供的现成的投影实现:
+
+```ts
+const projection = d3.geoConicEqualArea();
+// ...
+series = {
+  type: 'map',
+  projection: {
+    project: point => projection(point),
+    unproject: point => projection.invert(point)
+  }
+};
+```
+
+配合在 5.2 里新增的全局过渡动画特性,我们可以实现不同投影效果之间的动画过渡:
+
+![地图投影动画](images/5-3-0/map-projection.gif)
+
+除了地图的投影之外,我们在这个版本对于地图还做了下面两个增强:
+
+- 对 GeoJSON 数据提供了`'LineString'`和`'MultiLineString'`的支持。
+- 将默认标签位置的计算从包围盒中心改为最大区域的重心坐标,计算结果更加准确。
+
+## 多坐标轴的刻度对齐
+
+多坐标轴的刻度对齐是社区中提了很久的一个功能了,我们在网上也可以看到很多开发者写的如何在 echarts 中实现坐标轴对齐的文章,通常都会比较麻烦而且会有比较多的局限性。
+
+在 5.3.0 中我们终于引入了数值轴坐标轴刻度对齐的功能。可以在需要对齐刻度的坐标轴中配置`alignTicks: true`。该坐标轴就会根据第一个坐标轴的刻度划分去调整自己的刻度,实现自动对齐。
+
+```js live { layout: 'bt' }
+option = {
+  tooltip: {
+    trigger: 'axis'
+  },
+  legend: {},
+  xAxis: [
+    {
+      type: 'category',
+      data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
+      axisPointer: {
+        type: 'shadow'
+      }
+    }
+  ],
+  yAxis: [
+    {
+      type: 'value',
+      name: 'Precipitation',
+      alignTicks: true,
+      axisLabel: {
+        formatter: '{value} ml'
+      }
+    },
+    {
+      type: 'value',
+      name: 'Temperature',
+      axisLabel: {
+        formatter: '{value} °C'
+      }
+    }
+  ],
+  series: [
+    {
+      name: 'Evaporation',
+      type: 'bar',
+      // prettier-ignore
+      data: [2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3]
+    },
+    {
+      name: 'Precipitation',
+      type: 'bar',
+      // prettier-ignore
+      data: [2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3]
+    },
+    {
+      name: 'Temperature',
+      type: 'line',
+      yAxisIndex: 1,
+      data: [2.0, 2.2, 3.3, 4.5, 6.3, 10.2, 20.3, 23.4, 23.0, 16.5, 12.0, 6.2]
+    }
+  ]
+};
+```
+
+## 支持高亮和选中状态的关闭
+
+ECharts 中高亮状态可以在鼠标移到图形上的时候给用户提供反馈,但是在图表中有海量图形的时候,高亮的动画也可能带来交互上的性能问题。特别在 tooltip 或者图例组件联动触发的高亮会同时高亮多个图形。
+
+因此在这个版本中我们新增了`emphasis.disabled`配置项。如果不需要高亮的反馈,又堆交互性能非常在意的话,可以通过这个配置项来关闭高亮状态。
+
+与此同时,对于选中状态,我们也新增了`select.disabled`。该配置项可以用于细粒度配置部分数据不可选。
+
+## 支持整个系列的选中
 
-## 关闭高亮和选中状态
+在 5.3.0 中我们支持将`selectedMode`配置为`'series'`以实现系列所有数据的选中。
 
 ## tooltip 中的数值格式化
 
diff --git a/static/images/5-3-0/map-projection.gif b/static/images/5-3-0/map-projection.gif
new file mode 100644
index 0000000..188b8f6
Binary files /dev/null and b/static/images/5-3-0/map-projection.gif differ

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org