vislite 1.9.1 → 1.11.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/CHANGELOG +12 -0
  2. package/README.md +53 -52
  3. package/lib/BarLayout/index.es.js +45 -16
  4. package/lib/BarLayout/index.es.min.js +1 -1
  5. package/lib/PieLayout/index.es.js +45 -16
  6. package/lib/PieLayout/index.es.min.js +1 -1
  7. package/lib/TreeLayout/index.es.js +45 -16
  8. package/lib/TreeLayout/index.es.min.js +1 -1
  9. package/lib/animation/index.es.js +45 -16
  10. package/lib/animation/index.es.min.js +1 -1
  11. package/lib/index.umd.js +50 -21
  12. package/lib/index.umd.min.js +2 -2
  13. package/lib/throttle/index.es.js +4 -4
  14. package/lib/throttle/index.es.min.js +1 -1
  15. package/package.json +3 -2
  16. package/skills/vislite-lib/BarLayout.md +118 -0
  17. package/skills/vislite-lib/Canvas.md +184 -0
  18. package/skills/vislite-lib/Interpolation.md +130 -0
  19. package/skills/vislite-lib/Matrix.md +175 -0
  20. package/skills/vislite-lib/PieLayout.md +132 -0
  21. package/skills/vislite-lib/Projections.md +159 -0
  22. package/skills/vislite-lib/SKILL.md +176 -0
  23. package/skills/vislite-lib/SVG.md +138 -0
  24. package/skills/vislite-lib/TreeLayout.md +177 -0
  25. package/skills/vislite-lib/Utilities.md +177 -0
  26. package/skills/vislite-lib/WebGL.md +107 -0
  27. package/skills/vislite-lib/minialipay/ui-canvas.md +96 -0
  28. package/skills/vislite-lib/miniprogram/ui-canvas.md +99 -0
  29. package/skills/vislite-lib/uniapp/ui-canvas.md +114 -0
  30. package/types/Buffer.d.ts +15 -8
  31. package/types/Canvas.d.ts +4 -0
  32. package/types/CanvasConfig.d.ts +20 -47
  33. package/types/Cardinal.d.ts +9 -2
  34. package/types/Gradient.d.ts +10 -4
  35. package/types/Hermite.d.ts +15 -8
  36. package/types/Matrix4.d.ts +47 -15
  37. package/types/SVG.d.ts +4 -0
  38. package/types/SVGConfig.d.ts +18 -35
  39. package/types/Shader.d.ts +10 -4
  40. package/types/Texture.d.ts +12 -6
  41. package/types/TreeConfig.d.ts +32 -16
  42. package/types/TreeLayout.d.ts +25 -13
  43. package/types/animation.d.ts +15 -0
  44. package/types/assemble.d.ts +10 -1
  45. package/types/getLoopColors.d.ts +9 -1
  46. package/types/index.d.ts +52 -27
  47. package/types/move.d.ts +11 -1
  48. package/types/painterConfig.d.ts +10 -0
  49. package/types/rotate.d.ts +11 -1
  50. package/types/ruler.d.ts +15 -1
  51. package/types/scale.d.ts +11 -1
  52. package/types/throttle.d.ts +2 -1
package/CHANGELOG CHANGED
@@ -372,3 +372,15 @@ v1.9.1:
372
372
  1、调整打包若干细节
373
373
  2、优化uni-app(Vue3版本)的在支付宝小程序中不合理的警告提示
374
374
  3、针对SVG画笔优化初始化方式
375
+ v1.10.0:
376
+ date:2026-05-01
377
+ changes:
378
+ - 优化改造
379
+ 1、校对或补充types相关文件
380
+ 2、简化依赖
381
+ v1.11.0:
382
+ date:
383
+ changes:
384
+ - 新增功能
385
+ 1、添加skills技能
386
+ * vislite-lib 说明本库如何使用
package/README.md CHANGED
@@ -33,31 +33,35 @@
33
33
 
34
34
  # VISLite
35
35
 
36
- `VISLite`是一个使用`TypeScript`开发的可视化库。官网地址:[https://oi-contrib.github.io/VISLite](https://oi-contrib.github.io/VISLite)
36
+ 🚀 一款轻量、优雅的跨端数据可视化解决方案
37
37
 
38
- 主要提供了跨端的画布和计算,开发人员只需要按照文档的描述就可以非常简单的完成包括Web、uni-app、微信小程序、支付宝小程序等平台的可视化开发,除了初始化时可能存在一些差异外,主要的业务代码部分在不同端完全一致。
38
+ `VISLite` 是一个使用 `TypeScript` 构建的高性能可视化库。官网地址:[https://oi-contrib.github.io/VISLite](https://oi-contrib.github.io/VISLite)
39
+
40
+ 它提供了统一的跨端画布绘制与计算能力,让开发者只需关注业务逻辑,即可轻松实现 Web、uni-app、微信小程序、支付宝小程序等多平台的可视化应用。除初始化配置存在细微平台差异外,核心业务代码完全通用。
39
41
 
40
42
  ## 简介
41
43
 
42
- 这是一个轻量级的数据可视化资源库,目标是:帮助你更快速、简单、高效的开发出任意的可视化业务产品。
44
+ 🎯 轻量级数据可视化开发库 —— 助你更快速、简洁、高效地构建可视化产品。
43
45
 
44
46
  > 本项目已在[开源中国](https://www.oschina.net/p/vislite)中开源,欢迎关注和留言。
45
47
 
46
- ## 如何使用?
48
+ ## 快速开始
47
49
 
48
- 首先,需要进行安装:
50
+ ### 📦 安装
49
51
 
50
- ```js
52
+ ```bash
51
53
  npm install --save vislite
52
54
  ```
53
55
 
54
- 然后,准备好画布:
56
+ ### 🖼️ 准备画布
55
57
 
56
58
  ```html
57
59
  <div id="root" style="width:500px;height:300px;"></div>
58
60
  ```
59
61
 
60
- 现在,就可以获取画笔绘制自己需要的内容了。比如获取canvas画笔,绘制一个红色的圆:
62
+ ### 🎨 开始绘制
63
+
64
+ 获取画笔即可绘制你需要的任意内容。例如,获取 Canvas 画笔绘制一个红色圆:
61
65
 
62
66
  ```js
63
67
  import { Canvas } from 'vislite';
@@ -69,12 +73,10 @@ painter.config({
69
73
  }).fillCircle(200, 150, 100);
70
74
  ```
71
75
 
72
- 更复杂的图表,我们也提供了丰富的辅助API。比如使用树布局,可以非常快速的绘制一个树图:
76
+ 更复杂的图表?我们提供了丰富的辅助 API。以树布局为例,只需简单几步即可绘制树图:
73
77
 
74
78
  <img src="https://oi-contrib.github.io/VISLite/images/docs/tree.png" width="500"/>
75
79
 
76
- 具体代码如下:
77
-
78
80
  ```js
79
81
  import { Canvas, TreeLayout } from 'vislite';
80
82
 
@@ -119,7 +121,6 @@ painter.config({
119
121
  for (var key in tree.node) {
120
122
  var pid = tree.node[key].pid;
121
123
 
122
- // 如果父结点存在,和父结点连起来
123
124
  if (pid) {
124
125
  var dist = (tree.node[key].top - tree.node[pid].top) * 0.5;
125
126
 
@@ -150,90 +151,90 @@ for (var key in tree.node) {
150
151
  }
151
152
  ```
152
153
 
153
- 关于树布局更具体的使用细节,你可以访问:[ 《教程 / 树布局》 ](https://oi-contrib.github.io/VISLite/#/course/tree-layout)一节。
154
+ 树布局的详细用法,请参阅:[《教程 / 树布局》](https://oi-contrib.github.io/VISLite/#/course/tree-layout)
154
155
 
155
- ## 部分功能
156
+ ## 核心功能
156
157
 
157
- ### 常用的算法
158
+ ### 🧮 可视化算法库
158
159
 
159
- 我们通过提供可视化常用的算法来帮助你绘制复杂图表。比如下面的树图,通过简单的配置就可以把任意格式的数据变成任意绘制的带坐标的数据:
160
+ 我们封装了可视化开发中常用的算法,助你轻松绘制复杂图表。通过简单的配置,即可将任意格式的数据转换为带坐标的绘制数据:
160
161
 
161
162
  <img src="https://oi-contrib.github.io/VISLite/images/docs/what_1.png" width="400"/>
162
163
 
163
- > 上述例子的运行地址:[从左到右树状图](https://oi-contrib.github.io/VISLite/#/example/canvas/tree-layout-lr)
164
+ > 示例运行地址:[从左到右树状图](https://oi-contrib.github.io/VISLite/#/example/canvas/tree-layout-lr)
164
165
 
165
- 除了[树布局](https://oi-contrib.github.io/VISLite/#/api/treeLayout)外,我们还提供了:[刻度尺算法](https://oi-contrib.github.io/VISLite/#/api/ruler)来帮助你计算刻度应该如何确定、[等角斜方位投影](https://oi-contrib.github.io/VISLite/#/api/eoap)[墨卡托投影](https://oi-contrib.github.io/VISLite/#/api/mercator)来绘制地图、[插值函数](https://oi-contrib.github.io/VISLite/#/api/cardinal)来完成折线变光滑的曲线、[变换矩阵](https://oi-contrib.github.io/VISLite/#/api/matrix4)提供各种坐标变换等。
166
+ [树布局](https://oi-contrib.github.io/VISLite/#/api/treeLayout)外,还提供:[刻度尺算法](https://oi-contrib.github.io/VISLite/#/api/ruler)[等角斜方位投影](https://oi-contrib.github.io/VISLite/#/api/eoap)[墨卡托投影](https://oi-contrib.github.io/VISLite/#/api/mercator)[插值函数](https://oi-contrib.github.io/VISLite/#/api/cardinal)[变换矩阵](https://oi-contrib.github.io/VISLite/#/api/matrix4)等。
166
167
 
167
- ### 画笔加强
168
+ ### 🖌️ 增强型画笔
168
169
 
169
- 我们对画笔进行了加强,使得其更简单好用。比如canvas,抽象出区域的概念,使得无论你绘制的图形多么的不规则,都可以很轻松的实现交互功能:
170
+ 画笔经过精心设计,使用更简单、功能更强大。以 Canvas 为例,抽象出「区域」概念,无论图形多么不规则,都能轻松实现交互:
170
171
 
171
172
  <img src="https://oi-contrib.github.io/VISLite/images/docs/what_2.png" width="400"/>
172
173
 
173
- > 上述例子的运行地址:[中国地图](https://oi-contrib.github.io/VISLite/#/example/canvas/china)
174
+ > 示例运行地址:[中国地图](https://oi-contrib.github.io/VISLite/#/example/canvas/china)
174
175
 
175
- 画笔除了像上面那样为了方便交互而补充区域的设计外,还对原来的API进行了一次抽象,使得API更友好简单`(比如WebGL,即使不会3D的人也可以轻松使用,而SVG的使用,你无需去记忆那些晦涩难懂的属性)`,同时,我们还抹平了不同版本浏览器等之间的差异。
176
+ 画笔不仅为交互而设计区域,还对原生 API 进行了优雅封装,接口更友好直观(如 WebGL3D开发零门槛,SVG 无需记忆晦涩属性)。同时自动抹平浏览器兼容性差异。
176
177
 
177
- ### 支持跨端开发
178
+ ### 📱 跨端支持
178
179
 
179
- 除了Web端外,我们还针对uni-app、微信小程序、支付宝小程序等端进行了支持,并且不同端API保持一致,大大提高了代码的复用性:
180
+ Web 端外,还支持 uni-app、微信小程序、支付宝小程序等多端,API 统一,极大提升代码复用率:
180
181
 
181
182
  <img src="https://oi-contrib.github.io/VISLite/images/docs/what_3.png" width="600"/>
182
183
 
183
- > 上述例子的运行地址:[金额波浪球](https://oi-contrib.github.io/VISLite/#/example/svg/money-schedule)
184
+ > 示例运行地址:[金额波浪球](https://oi-contrib.github.io/VISLite/#/example/svg/money-schedule)
184
185
 
185
- 基于实际需要,我们目前对 `Canvas` 提供了跨端支持,除 `Web端` 外,还支持 `原生微信小程序` 、 `原生支付宝小程序` 和 `uni-app端` (编译成H5、微信小程序、支付宝小程序等) ,如果后续有必要,我们会对Canvas支持的端或SVG、WebGL等画笔进行更多端扩展。
186
+ 目前 `Canvas` 已支持:Web、原生微信小程序、原生支付宝小程序、uni-app(编译为 H5、微信小程序、支付宝小程序等)。后续将持续扩展更多端和画笔类型。
186
187
 
187
- ## 特点
188
+ ## 核心优势
188
189
 
189
- - 灵活的引入方式:包括npm安装后按照`ES Module`或`CommonJS`规范引入或直接使用script标签的`CDN`方式。
190
- - 按需引入或全局引入:支持源码TS引入、按需JS引入或者全量引入等多种方式。
191
- - 简单与复杂共存:一方面我们提供了可视化需要的基础功能,你可以按照自己的需要组合使用;另一方面,为了加速开发,我们针对常见的可视化业务场景进行了封装,可以帮助你快速完成,你可以根据实际情况进行选择。
192
- - 向下兼容:我们向你保证,同一个大版本下始终向下兼容`(alphabeta版本为测试版本,不包括)`,因此,无论何时,在同一个大版本号下,最新版本总是最好的选择。
190
+ - **灵活的引入方式**:支持 npm 安装后的 ES Module / CommonJS 引入,以及 script 标签 CDN 方式
191
+ - **按需加载**:源码 TS 引入、按需 JS 引入或全量引入,多种模式按需选择
192
+ - **简洁与强大并存**:提供可视化基础组件可自由组合,同时也支持常见场景的封装方案
193
+ - **稳定可靠**:同一大版本完全向下兼容(alphabeta 版本除外),始终保持最新版本为最优选择
193
194
 
194
- > 版本说明:alpha为开发阶段、beta为发布前测试、rc为候选版本、next为未来版本、无后缀的为正式版本。
195
+ > 版本规范:alpha(开发版)→ beta(测试版)→ rc(候选版)→ next(预发布版)→ 正式版
195
196
 
196
- ## 需求墙
197
+ ## 需求反馈
197
198
 
198
- 我们的目标是不断完善丰富可视化功能,非常希望获得你宝贵的建议和批评,无论任何想法,都可以给我们[留言](https://github.com/oi-contrib/VISLite/issues)告诉我们。
199
+ 我们致力于不断完善可视化功能,期待你的宝贵建议!欢迎通过 [留言](https://github.com/oi-contrib/VISLite/issues) 与我们交流。
199
200
 
200
- 你所提的任何建议我们都会在最长一周内进行反馈说明。
201
+ 所有建议将在一周内得到回复。
201
202
 
202
203
  ## 更新日志
203
204
 
204
- 详见[正式版更新日志](./CHANGELOG),我们会在每次发布完正式版本后更新其内容。
205
+ 详见[正式版更新日志](./CHANGELOG),每次正式版本发布后更新。
205
206
 
206
- ## 下一步
207
+ ## Roadmap
207
208
 
208
- 我们会在这里列出接下来的工作重心:
209
+ 近期工作重点:
209
210
 
210
- - 为加速开发,提供常用坐标系和布局
211
- - 文档优化(提高可读性、丰富用例、补充教程)
211
+ - 提供常用坐标系和布局组件,加速开发
212
+ - 持续优化文档(提升可读性、丰富示例、完善教程)
212
213
 
213
- 给我们[留言](https://github.com/oi-contrib/VISLite/issues)告诉我们你希望快速扩展的功能,我们会优先你的建议考虑哦~
214
+ 有想要的功能?[告诉我们](https://github.com/oi-contrib/VISLite/issues),我们会优先考虑!
214
215
 
215
- ## 参与贡献
216
+ ## 贡献指南
216
217
 
217
- 你可以选择下列一项或多项进行参与:
218
+ 欢迎通过以下方式参与项目:
218
219
 
219
- - 代码维护:由于新功能或一些BUG的出现,对代码进行维护和升级。
220
- - 文档编辑:主要是接口文档和教程需要编辑,这很重要。
221
- - 用例开发和测试:在项目的test文件夹下有一些测试,而在docs文档中存在一些例子需要补充。
222
- - 参与讨论:主要是讨论未来如何发展,改造的方向等。
220
+ - **代码维护**:处理新功能开发与 Bug 修复
221
+ - **文档完善**:接口文档和教程的编写与优化
222
+ - **测试用例**:补充 test 目录下的测试用例和 docs 目录下的示例
223
+ - **方向讨论**:参与项目未来发展的讨论
223
224
 
224
- 如果有意向加入我们,你可以通过提 [issue](https://github.com/oi-contrib/VISLite/issues) 和我们取到联系,请简单说明一下情况,我们会尽快回复。
225
+ 有意加入?请通过 [issue](https://github.com/oi-contrib/VISLite/issues) 联系我们,请简要说明情况,我们会尽快回复。
225
226
 
226
- 你可以查看[VISLite 贡献指南](./.github/CONTRIBUTING.md)文件了解更多细节,查看[AUTHORS.txt](./AUTHORS.txt)了解所有的贡献者。
227
+ 详见 [VISLite 贡献指南](./.github/CONTRIBUTING.md)[AUTHORS.txt](./AUTHORS.txt)
227
228
 
228
- ## 例子项目
229
+ ## 示例项目
229
230
 
230
- 主要是基于本项目及相关项目(比如 [ @vislite/canvas](https://github.com/oi-contrib/vislite-plugin-canvas) [ @vislite/chart](https://github.com/oi-contrib/vislite-plugin-chart))开发的一些用例:
231
+ 基于 VISLite 及相关插件(如 [@vislite/canvas](https://github.com/oi-contrib/vislite-plugin-canvas)、[@vislite/chart](https://github.com/oi-contrib/vislite-plugin-chart))开发的示例:
231
232
 
232
233
  <img src="https://oi-contrib.github.io/VISLite/images/docs/examples/review1.png" style="width:700px;border:2px solid black;margin-bottom:20px;"/>
233
234
  <img src="https://oi-contrib.github.io/VISLite/images/docs/examples/review2.png" style="width:700px;border:2px solid black;margin-bottom:20px;"/>
234
235
  <img src="https://oi-contrib.github.io/VISLite/images/docs/examples/review3.png" style="width:300px;border:2px solid black;margin-bottom:20px;"/>
235
236
 
236
- 更多内容,你可以直接访问: [VISLite 例子项目](https://rapid-start.github.io/VISLite-examples/index.html)
237
+ 更多示例请访问:[VISLite 示例项目](https://rapid-start.github.io/VISLite-examples/index.html)
237
238
 
238
239
  ## 版权
239
240
 
@@ -144,11 +144,11 @@ function ruler (maxValue, minValue, num, option) {
144
144
  }
145
145
 
146
146
  //当前正在运动的动画的tick函数堆栈
147
- var $timers = [];
147
+ let $timers = [];
148
148
  //唯一定时器的定时间隔
149
- var $interval = 13;
149
+ let $interval = 13;
150
150
  //定时器ID
151
- var $timerId;
151
+ let $timerId;
152
152
 
153
153
  /**
154
154
  * 动画轮播
@@ -162,16 +162,19 @@ function animation(doback, duration, callback) {
162
162
  if (arguments.length < 2) duration = 400;
163
163
  if (arguments.length < 3) callback = function () { };
164
164
 
165
- var clock = {
165
+ let clock = {
166
166
  //把tick函数推入堆栈
167
167
  "timer": function (tick, duration, callback) {
168
168
  if (!tick) {
169
169
  throw new Error('Tick is required!');
170
170
  }
171
- var id = new Date().valueOf() + "_" + (Math.random() * 1000).toFixed(0);
171
+ let id = new Date().valueOf() + "_" + (Math.random() * 1000).toFixed(0);
172
172
  $timers.push({
173
173
  "id": id,
174
- "createTime": new Date(),
174
+ "createTime": new Date(), // 开始时间
175
+ "pauseTime": -1, // 暂停的时间,继续运行的时候,借助此计算暂停的时间差
176
+ "pauseKeepTime": 0, // 暂停用去的时间
177
+ "status": "running", // running(运行中), paused(暂停中)
175
178
  "tick": tick,
176
179
  "duration": duration,
177
180
  "callback": callback
@@ -200,7 +203,7 @@ function animation(doback, duration, callback) {
200
203
 
201
204
  //被定时器调用,遍历timers堆栈
202
205
  "tick": function () {
203
- var createTime, flag, tick, callback, timer, duration, passTime, timers = $timers;
206
+ let createTime, flag, tick, callback, timer, duration, passTime, timers = $timers;
204
207
 
205
208
  $timers = [];
206
209
  $timers.length = 0;
@@ -214,15 +217,21 @@ function animation(doback, duration, callback) {
214
217
  callback = timer.callback;
215
218
 
216
219
  //执行
217
- passTime = (+new Date().valueOf() - createTime.valueOf()) / duration;
220
+ passTime = (+new Date().valueOf() - createTime.valueOf() - timer.pauseKeepTime) / duration;
218
221
  passTime = passTime > 1 ? 1 : passTime;
219
- tick(passTime);
220
- if (passTime < 1 && timer.id) {
222
+
223
+ if (timer.status === "running") {
224
+ tick(passTime);
225
+ }
226
+
227
+ // 只有当动画没有结束或者动画处于暂停状态时,才继续添加到timers堆栈
228
+ if ((passTime < 1 || timer.status === "paused") && timer.id) {
221
229
  //动画没有结束再添加
222
230
  $timers.push(timer);
223
231
  } else {
224
232
  callback(passTime);
225
233
  }
234
+
226
235
  }
227
236
  if ($timers.length <= 0) {
228
237
  clock.stop();
@@ -243,20 +252,40 @@ function animation(doback, duration, callback) {
243
252
  }
244
253
  };
245
254
 
246
- var id = clock.timer(function (deep) {
255
+ let id = clock.timer(function (deep) {
247
256
  //其中deep为0-1,表示改变的程度
248
257
  doback(deep);
249
258
  }, duration, callback);
250
259
 
251
260
  return {
252
- // 一个函数
253
- // 用于在动画结束前结束动画
261
+ // 结束动画
254
262
  stop: function () {
255
- var i;
256
- for (i in $timers) {
263
+ for (let i in $timers) {
257
264
  if ($timers[i].id == id) {
258
265
  $timers[i].id = void 0;
259
- return;
266
+ }
267
+ }
268
+ },
269
+ // 暂停动画
270
+ pause: function () {
271
+ for (let i in $timers) {
272
+ if ($timers[i].id == id) {
273
+ if ($timers[i].pauseTime === -1) {
274
+ $timers[i].pauseTime = new Date();
275
+ $timers[i].status = "paused";
276
+ }
277
+ }
278
+ }
279
+ },
280
+ // 继续动画
281
+ resume: function () {
282
+ for (let i in $timers) {
283
+ if ($timers[i].id == id) {
284
+ if ($timers[i].pauseTime !== -1) {
285
+ $timers[i].pauseKeepTime += (new Date().valueOf() - $timers[i].pauseTime.valueOf());
286
+ $timers[i].pauseTime = -1;
287
+ $timers[i].status = "running";
288
+ }
260
289
  }
261
290
  }
262
291
  }
@@ -1 +1 @@
1
- function t(t,i){for(var a in t)i[a]=t[a];return i}var i,a=[];var e=function(){function e(i){void 0===i&&(i={}),this.name="BarLayout",this.__option={x:50,y:350,width:400,height:300,category:"xAxis",duration:200},this.__config=t(i,{})}return e.prototype.setOption=function(i){return t(i,this.__option),this},e.prototype.use=function(t){var i={coordinate:{x:this.__option.x,y:this.__option.y,width:this.__option.width,height:this.__option.height,xAxis:{type:"xAxis"===this.__option.category?"category":"value",data:[]},yAxis:{type:"xAxis"===this.__option.category?"value":"category",data:[]}},node:[]},a=void 0,e=void 0;if(t.data)for(var n=0,r=t.data;n<r.length;n++){var o=r[n];(void 0===a||o>a)&&(a=o),(void 0===e||o<e)&&(e=o)}else{if(!t.value)throw new Error("No data leads to parsing errors");for(var h=0,u=t.value;h<u.length;h++)for(var l=0,s=u[h].data;l<s.length;l++){o=s[l];(void 0===a||o>a)&&(a=o),(void 0===e||o<e)&&(e=o)}}var _,d,f=function(t,i,a,e){if(t<i){var n=i;i=t,t=n}else if(t==i)return[t];var r=function(t){for(var i=t<100&&t>-100?10:.1,a=-1,e=t;10==i?e>=-100&&e<=100:e<=-100||e>=100;)a+=1,e*=i;if(10==i)return Math.pow(10,a);for(var n="0.",r=1;r<a;r++)n+="0";return+(n+"1")}(t-i),o=Math.ceil((t-i)*r/a),h=function(a){var e=({3:2,4:5,6:5,7:5,8:10,9:10,11:10,12:10,13:15,14:15,16:15,17:15,18:20,19:20,21:20,22:20,23:25,24:25,26:25,27:25}[o+a]||o+a)/r,n=Math.floor(i/e)*e,h=[];h.push(n);for(var u=1;h[h.length-1]<t;u++)h.push(n+e*u);return h},u=h(0),l=function(){for(var t=[],a=u[u.length-1]-(null==e?void 0:e.max),n=0;n<u.length;n++)n+1<u.length&&u[n+1]-a<i||t.push(u[n]-a);return t},s=function(){for(var i=[],a=u[0]-(null==e?void 0:e.min),n=0;n<u.length&&(i[n]=u[n]-a,!(t<=i[n]));n++);return i};if(e){if("max"in e&&"min"in e&&e.max>=t&&e.min<=i){var _=function(){if(u[0]>=e.min&&u[u.length-1]<=e.max)return!0;var t=l();if(t[0]>=e.min&&t[t.length-1]<=e.max)return u=t,!0;var i=s();return i[0]>=e.min&&i[t.length-1]<=e.max?(u=i,!0):void 0};if(_())return u;for(var d=1;d<100;d++){if(u=h(d),_())return u;if(u=h(-d),_())return u}}"max"in e&&e.max>=t?e.max<u[u.length-1]&&(u=l()):"min"in e&&e.min<=i&&e.min>u[0]&&(u=s())}for(var f=0;f<u.length;f++){var c=u[f]+"";/\./.test(c)&&(/9{7,}$/.test(c)?(c=c.replace(/9{7,}$/,""),u[f]=+(c.substring(0,c.length-1)+(+c[c.length-1]+1))):/0{7,}\d$/.test(c)&&(u[f]=+c.replace(/0{7,}\d$/,"")))}return u}(a||0,e||0,5);"xAxis"===this.__option.category?(i.coordinate.xAxis.data=t.category,i.coordinate.yAxis.data=f,_=this.__option.width,d=-1*this.__option.height):(i.coordinate.xAxis.data=f,i.coordinate.yAxis.data=t.category,_=this.__option.height,d=this.__option.width);var c=[],v=_/t.category.length,p=.9*v,g=.05*v;if(t.data)for(var x=0;x<t.data.length;x++)c.push([g+v*x,p]);else{var m=p/t.value.length,y=.9*m,b=.05*m;for(x=0;x<t.value[0].data.length;x++){c[x]=[];for(var w=0;w<t.value.length;w++)c[x].push([g+v*x+m*w+b,y])}}var A=d/(f[f.length-1]-f[0]),k=function(t){return A*(t-f[0])};if("xAxis"===this.__option.category)if(t.data){var B=[];for(x=0;x<t.data.length;x++)B.push({x:this.__option.x+c[x][0],y:this.__option.y,width:c[x][1],height:k(t.data[x]),value:t.data[x]});i.node.push({bar:B})}else for(w=0;w<t.value.length;w++){for(B=[],x=0;x<t.value[w].data.length;x++)B.push({x:this.__option.x+c[x][w][0],y:this.__option.y,width:c[x][w][1],height:k(t.value[w].data[x]),value:t.value[w].data[x]});i.node.push({name:t.value[w].name,bar:B})}else if(t.data){for(B=[],x=0;x<t.data.length;x++)B.push({x:this.__option.x,y:this.__option.y-this.__option.height+c[x][0],width:k(t.data[x]),height:c[x][1],value:t.data[x]});i.node.push({bar:B})}else for(w=0;w<t.value.length;w++){for(B=[],x=0;x<t.value[w].data.length;x++)B.push({x:this.__option.x,y:this.__option.y-this.__option.height+c[x][w][0],width:k(t.value[w].data[x]),height:c[x][w][1],value:t.value[w].data[x]});i.node.push({name:t.value[w].name,bar:B})}return i},e.prototype.bind=function(t,i){return this.__rback=i,this.__oralBar=t,this.__preBar=this.use(this.__oralBar),this.__rback(this.__preBar),this},e.prototype.unbind=function(){return this.__rback=function(){return null},this.__oralBar=null,this.__preBar=null,this},e.prototype.doUpdate=function(){var t=this,e=this.use(this.__oralBar),n=JSON.parse(JSON.stringify(e));return function(t,e,n){arguments.length<2&&(e=400),arguments.length<3&&(n=function(){});var r={timer:function(t,i,e){if(!t)throw new Error("Tick is required!");var n=(new Date).valueOf()+"_"+(1e3*Math.random()).toFixed(0);return a.push({id:n,createTime:new Date,tick:t,duration:i,callback:e}),r.start(),n},start:function(){if(!i)try{i=globalThis&&globalThis.requestAnimationFrame?globalThis.requestAnimationFrame((function t(){r.tick(),i&&(i=globalThis.requestAnimationFrame(t))})):setInterval(r.tick,13)}catch(t){i=setInterval(r.tick,13)}},tick:function(){var t,i,e,n,o,h,u,l=a;for((a=[]).length=0,i=0;i<l.length;i++)t=(o=l[i]).createTime,e=o.tick,h=o.duration,n=o.callback,e(u=(u=(+(new Date).valueOf()-t.valueOf())/h)>1?1:u),u<1&&o.id?a.push(o):n(u);a.length<=0&&r.stop()},stop:function(){if(i){try{globalThis&&globalThis.requestAnimationFrame?globalThis.cancelAnimationFrame(i):clearInterval(i)}catch(t){clearInterval(i)}i=null}}},o=r.timer((function(i){t(i)}),e,n)}((function(i){t.__preBar||t.__rback(n)}),this.__option.duration,(function(){t.__preBar=e,t.__rback(t.__preBar)})),this},e}();export{e as default};
1
+ function t(t,i){for(var a in t)i[a]=t[a];return i}let i,a=[];var e=function(){function e(i){void 0===i&&(i={}),this.name="BarLayout",this.__option={x:50,y:350,width:400,height:300,category:"xAxis",duration:200},this.__config=t(i,{})}return e.prototype.setOption=function(i){return t(i,this.__option),this},e.prototype.use=function(t){var i={coordinate:{x:this.__option.x,y:this.__option.y,width:this.__option.width,height:this.__option.height,xAxis:{type:"xAxis"===this.__option.category?"category":"value",data:[]},yAxis:{type:"xAxis"===this.__option.category?"value":"category",data:[]}},node:[]},a=void 0,e=void 0;if(t.data)for(var n=0,r=t.data;n<r.length;n++){var o=r[n];(void 0===a||o>a)&&(a=o),(void 0===e||o<e)&&(e=o)}else{if(!t.value)throw new Error("No data leads to parsing errors");for(var h=0,s=t.value;h<s.length;h++)for(var u=0,l=s[h].data;u<l.length;u++){o=l[u];(void 0===a||o>a)&&(a=o),(void 0===e||o<e)&&(e=o)}}var _,d,p=function(t,i,a,e){if(t<i){var n=i;i=t,t=n}else if(t==i)return[t];var r=function(t){for(var i=t<100&&t>-100?10:.1,a=-1,e=t;10==i?e>=-100&&e<=100:e<=-100||e>=100;)a+=1,e*=i;if(10==i)return Math.pow(10,a);for(var n="0.",r=1;r<a;r++)n+="0";return+(n+"1")}(t-i),o=Math.ceil((t-i)*r/a),h=function(a){var e=({3:2,4:5,6:5,7:5,8:10,9:10,11:10,12:10,13:15,14:15,16:15,17:15,18:20,19:20,21:20,22:20,23:25,24:25,26:25,27:25}[o+a]||o+a)/r,n=Math.floor(i/e)*e,h=[];h.push(n);for(var s=1;h[h.length-1]<t;s++)h.push(n+e*s);return h},s=h(0),u=function(){for(var t=[],a=s[s.length-1]-(null==e?void 0:e.max),n=0;n<s.length;n++)n+1<s.length&&s[n+1]-a<i||t.push(s[n]-a);return t},l=function(){for(var i=[],a=s[0]-(null==e?void 0:e.min),n=0;n<s.length&&(i[n]=s[n]-a,!(t<=i[n]));n++);return i};if(e){if("max"in e&&"min"in e&&e.max>=t&&e.min<=i){var _=function(){if(s[0]>=e.min&&s[s.length-1]<=e.max)return!0;var t=u();if(t[0]>=e.min&&t[t.length-1]<=e.max)return s=t,!0;var i=l();return i[0]>=e.min&&i[t.length-1]<=e.max?(s=i,!0):void 0};if(_())return s;for(var d=1;d<100;d++){if(s=h(d),_())return s;if(s=h(-d),_())return s}}"max"in e&&e.max>=t?e.max<s[s.length-1]&&(s=u()):"min"in e&&e.min<=i&&e.min>s[0]&&(s=l())}for(var p=0;p<s.length;p++){var f=s[p]+"";/\./.test(f)&&(/9{7,}$/.test(f)?(f=f.replace(/9{7,}$/,""),s[p]=+(f.substring(0,f.length-1)+(+f[f.length-1]+1))):/0{7,}\d$/.test(f)&&(s[p]=+f.replace(/0{7,}\d$/,"")))}return s}(a||0,e||0,5);"xAxis"===this.__option.category?(i.coordinate.xAxis.data=t.category,i.coordinate.yAxis.data=p,_=this.__option.width,d=-1*this.__option.height):(i.coordinate.xAxis.data=p,i.coordinate.yAxis.data=t.category,_=this.__option.height,d=this.__option.width);var f=[],c=_/t.category.length,v=.9*c,g=.05*c;if(t.data)for(var m=0;m<t.data.length;m++)f.push([g+c*m,v]);else{var x=v/t.value.length,y=.9*x,b=.05*x;for(m=0;m<t.value[0].data.length;m++){f[m]=[];for(var w=0;w<t.value.length;w++)f[m].push([g+c*m+x*w+b,y])}}var A=d/(p[p.length-1]-p[0]),k=function(t){return A*(t-p[0])};if("xAxis"===this.__option.category)if(t.data){var T=[];for(m=0;m<t.data.length;m++)T.push({x:this.__option.x+f[m][0],y:this.__option.y,width:f[m][1],height:k(t.data[m]),value:t.data[m]});i.node.push({bar:T})}else for(w=0;w<t.value.length;w++){for(T=[],m=0;m<t.value[w].data.length;m++)T.push({x:this.__option.x+f[m][w][0],y:this.__option.y,width:f[m][w][1],height:k(t.value[w].data[m]),value:t.value[w].data[m]});i.node.push({name:t.value[w].name,bar:T})}else if(t.data){for(T=[],m=0;m<t.data.length;m++)T.push({x:this.__option.x,y:this.__option.y-this.__option.height+f[m][0],width:k(t.data[m]),height:f[m][1],value:t.data[m]});i.node.push({bar:T})}else for(w=0;w<t.value.length;w++){for(T=[],m=0;m<t.value[w].data.length;m++)T.push({x:this.__option.x,y:this.__option.y-this.__option.height+f[m][w][0],width:k(t.value[w].data[m]),height:f[m][w][1],value:t.value[w].data[m]});i.node.push({name:t.value[w].name,bar:T})}return i},e.prototype.bind=function(t,i){return this.__rback=i,this.__oralBar=t,this.__preBar=this.use(this.__oralBar),this.__rback(this.__preBar),this},e.prototype.unbind=function(){return this.__rback=function(){return null},this.__oralBar=null,this.__preBar=null,this},e.prototype.doUpdate=function(){var t=this,e=this.use(this.__oralBar),n=JSON.parse(JSON.stringify(e));return function(t,e,n){arguments.length<2&&(e=400),arguments.length<3&&(n=function(){});let r={timer:function(t,i,e){if(!t)throw new Error("Tick is required!");let n=(new Date).valueOf()+"_"+(1e3*Math.random()).toFixed(0);return a.push({id:n,createTime:new Date,pauseTime:-1,pauseKeepTime:0,status:"running",tick:t,duration:i,callback:e}),r.start(),n},start:function(){if(!i)try{i=globalThis&&globalThis.requestAnimationFrame?globalThis.requestAnimationFrame((function t(){r.tick(),i&&(i=globalThis.requestAnimationFrame(t))})):setInterval(r.tick,13)}catch(t){i=setInterval(r.tick,13)}},tick:function(){let t,i,e,n,o,h,s,u=a;for(a=[],a.length=0,i=0;i<u.length;i++)o=u[i],t=o.createTime,e=o.tick,h=o.duration,n=o.callback,s=(+(new Date).valueOf()-t.valueOf()-o.pauseKeepTime)/h,s=s>1?1:s,"running"===o.status&&e(s),(s<1||"paused"===o.status)&&o.id?a.push(o):n(s);a.length<=0&&r.stop()},stop:function(){if(i){try{globalThis&&globalThis.requestAnimationFrame?globalThis.cancelAnimationFrame(i):clearInterval(i)}catch(t){clearInterval(i)}i=null}}},o=r.timer((function(i){t(i)}),e,n)}((function(i){t.__preBar||t.__rback(n)}),this.__option.duration,(function(){t.__preBar=e,t.__rback(t.__preBar)})),this},e}();export{e as default};
@@ -14,11 +14,11 @@ function rotate (cx, cy, deg, x, y) {
14
14
  }
15
15
 
16
16
  //当前正在运动的动画的tick函数堆栈
17
- var $timers = [];
17
+ let $timers = [];
18
18
  //唯一定时器的定时间隔
19
- var $interval = 13;
19
+ let $interval = 13;
20
20
  //定时器ID
21
- var $timerId;
21
+ let $timerId;
22
22
 
23
23
  /**
24
24
  * 动画轮播
@@ -32,16 +32,19 @@ function animation(doback, duration, callback) {
32
32
  if (arguments.length < 2) duration = 400;
33
33
  if (arguments.length < 3) callback = function () { };
34
34
 
35
- var clock = {
35
+ let clock = {
36
36
  //把tick函数推入堆栈
37
37
  "timer": function (tick, duration, callback) {
38
38
  if (!tick) {
39
39
  throw new Error('Tick is required!');
40
40
  }
41
- var id = new Date().valueOf() + "_" + (Math.random() * 1000).toFixed(0);
41
+ let id = new Date().valueOf() + "_" + (Math.random() * 1000).toFixed(0);
42
42
  $timers.push({
43
43
  "id": id,
44
- "createTime": new Date(),
44
+ "createTime": new Date(), // 开始时间
45
+ "pauseTime": -1, // 暂停的时间,继续运行的时候,借助此计算暂停的时间差
46
+ "pauseKeepTime": 0, // 暂停用去的时间
47
+ "status": "running", // running(运行中), paused(暂停中)
45
48
  "tick": tick,
46
49
  "duration": duration,
47
50
  "callback": callback
@@ -70,7 +73,7 @@ function animation(doback, duration, callback) {
70
73
 
71
74
  //被定时器调用,遍历timers堆栈
72
75
  "tick": function () {
73
- var createTime, flag, tick, callback, timer, duration, passTime, timers = $timers;
76
+ let createTime, flag, tick, callback, timer, duration, passTime, timers = $timers;
74
77
 
75
78
  $timers = [];
76
79
  $timers.length = 0;
@@ -84,15 +87,21 @@ function animation(doback, duration, callback) {
84
87
  callback = timer.callback;
85
88
 
86
89
  //执行
87
- passTime = (+new Date().valueOf() - createTime.valueOf()) / duration;
90
+ passTime = (+new Date().valueOf() - createTime.valueOf() - timer.pauseKeepTime) / duration;
88
91
  passTime = passTime > 1 ? 1 : passTime;
89
- tick(passTime);
90
- if (passTime < 1 && timer.id) {
92
+
93
+ if (timer.status === "running") {
94
+ tick(passTime);
95
+ }
96
+
97
+ // 只有当动画没有结束或者动画处于暂停状态时,才继续添加到timers堆栈
98
+ if ((passTime < 1 || timer.status === "paused") && timer.id) {
91
99
  //动画没有结束再添加
92
100
  $timers.push(timer);
93
101
  } else {
94
102
  callback(passTime);
95
103
  }
104
+
96
105
  }
97
106
  if ($timers.length <= 0) {
98
107
  clock.stop();
@@ -113,20 +122,40 @@ function animation(doback, duration, callback) {
113
122
  }
114
123
  };
115
124
 
116
- var id = clock.timer(function (deep) {
125
+ let id = clock.timer(function (deep) {
117
126
  //其中deep为0-1,表示改变的程度
118
127
  doback(deep);
119
128
  }, duration, callback);
120
129
 
121
130
  return {
122
- // 一个函数
123
- // 用于在动画结束前结束动画
131
+ // 结束动画
124
132
  stop: function () {
125
- var i;
126
- for (i in $timers) {
133
+ for (let i in $timers) {
127
134
  if ($timers[i].id == id) {
128
135
  $timers[i].id = void 0;
129
- return;
136
+ }
137
+ }
138
+ },
139
+ // 暂停动画
140
+ pause: function () {
141
+ for (let i in $timers) {
142
+ if ($timers[i].id == id) {
143
+ if ($timers[i].pauseTime === -1) {
144
+ $timers[i].pauseTime = new Date();
145
+ $timers[i].status = "paused";
146
+ }
147
+ }
148
+ }
149
+ },
150
+ // 继续动画
151
+ resume: function () {
152
+ for (let i in $timers) {
153
+ if ($timers[i].id == id) {
154
+ if ($timers[i].pauseTime !== -1) {
155
+ $timers[i].pauseKeepTime += (new Date().valueOf() - $timers[i].pauseTime.valueOf());
156
+ $timers[i].pauseTime = -1;
157
+ $timers[i].status = "running";
158
+ }
130
159
  }
131
160
  }
132
161
  }
@@ -1 +1 @@
1
- function t(t,i){for(var e in t)i[e]=t[e];return i}function i(t,i,e,n,r){var o=Math.cos(e),a=Math.sin(e);return[(n-t)*o-(r-i)*a+t,(n-t)*a+(r-i)*o+i]}var e,n=[];var r=function(){function r(i){void 0===i&&(i={}),this.name="PieLayout",this.__option={cx:200,cy:200,radius:[50,100],duration:200},this.__hoverIndex=-1,this.__config=t(i,{name:function(t,i){return t.name},value:function(t,i){return t.value}})}return r.prototype.setOption=function(i){return t(i,this.__option),this},r.prototype.use=function(t,e){void 0===e&&(e=-1);for(var n={count:t.length,cx:this.__option.cx,cy:this.__option.cy,radius:this.__option.radius,hoverIndex:e,node:[]},r=0,o=[],a=[],s=0;s<t.length;s++)o[s]=this.__config.name(t[s],t),a[s]=this.__config.value(t[s],t),r+=a[s];var u,_=-.5*Math.PI;for(s=0;s<t.length;s++){u=a[s]/r*Math.PI*2;var h=[this.__option.radius[0]*(1+(this.__option.radius[0]>0&&e===s?-.1:0)),this.__option.radius[1]*(1+(e===s?.05:0))],c=_+.5*u,l=Math.max(this.__option.radius[0],this.__option.radius[1]),d=i(n.cx,n.cy,c,n.cx+l,n.cy),p=i(n.cx,n.cy,c,n.cx+l+15,n.cy),f=d[0]>n.cx?1:-1,v=[p[0]+20*f,p[1]],g=[p[0]+25*f,p[1]];n.node[s]={value:a[s],name:o[s],beginDeg:_,deg:u,isHover:e===s,radius:h,label:{line:[d,p,v],position:g,align:-1===f?"right":"left"}},_+=u}return n},r.prototype.bind=function(t,i){return this.__rback=i,this.__oralPie=t,this.__prePie=this.use(this.__oralPie,this.__hoverIndex),this.__rback(this.__prePie),this},r.prototype.unbind=function(){return this.__rback=function(){return null},this.__oralPie=null,this.__prePie=null,this.__hoverIndex=-1,this},r.prototype.setHover=function(t){return this.__prePie&&this.__hoverIndex!==t?(this.__hoverIndex=t,this.doUpdate(),this):this},r.prototype.doUpdate=function(){var t=this,i=this.use(this.__oralPie,this.__hoverIndex),r=JSON.parse(JSON.stringify(i));return function(t,i,r){arguments.length<2&&(i=400),arguments.length<3&&(r=function(){});var o={timer:function(t,i,e){if(!t)throw new Error("Tick is required!");var r=(new Date).valueOf()+"_"+(1e3*Math.random()).toFixed(0);return n.push({id:r,createTime:new Date,tick:t,duration:i,callback:e}),o.start(),r},start:function(){if(!e)try{e=globalThis&&globalThis.requestAnimationFrame?globalThis.requestAnimationFrame((function t(){o.tick(),e&&(e=globalThis.requestAnimationFrame(t))})):setInterval(o.tick,13)}catch(t){e=setInterval(o.tick,13)}},tick:function(){var t,i,e,r,a,s,u,_=n;for((n=[]).length=0,i=0;i<_.length;i++)t=(a=_[i]).createTime,e=a.tick,s=a.duration,r=a.callback,e(u=(u=(+(new Date).valueOf()-t.valueOf())/s)>1?1:u),u<1&&a.id?n.push(a):r(u);n.length<=0&&o.stop()},stop:function(){if(e){try{globalThis&&globalThis.requestAnimationFrame?globalThis.cancelAnimationFrame(e):clearInterval(e)}catch(t){clearInterval(e)}e=null}}},a=o.timer((function(i){t(i)}),i,r)}((function(e){if(t.__prePie)for(var n=0;n<r.count;n++)r.node[n].radius[0]=t.__prePie.node[n].radius[0]+(i.node[n].radius[0]-t.__prePie.node[n].radius[0])*e,r.node[n].radius[1]=t.__prePie.node[n].radius[1]+(i.node[n].radius[1]-t.__prePie.node[n].radius[1])*e;t.__rback(r)}),this.__option.duration,(function(){t.__prePie=i,t.__rback(t.__prePie)})),this},r}();export{r as default};
1
+ function t(t,i){for(var e in t)i[e]=t[e];return i}function i(t,i,e,n,r){var o=Math.cos(e),a=Math.sin(e);return[(n-t)*o-(r-i)*a+t,(n-t)*a+(r-i)*o+i]}let e,n=[];var r=function(){function r(i){void 0===i&&(i={}),this.name="PieLayout",this.__option={cx:200,cy:200,radius:[50,100],duration:200},this.__hoverIndex=-1,this.__config=t(i,{name:function(t,i){return t.name},value:function(t,i){return t.value}})}return r.prototype.setOption=function(i){return t(i,this.__option),this},r.prototype.use=function(t,e){void 0===e&&(e=-1);for(var n={count:t.length,cx:this.__option.cx,cy:this.__option.cy,radius:this.__option.radius,hoverIndex:e,node:[]},r=0,o=[],a=[],s=0;s<t.length;s++)o[s]=this.__config.name(t[s],t),a[s]=this.__config.value(t[s],t),r+=a[s];var u,_=-.5*Math.PI;for(s=0;s<t.length;s++){u=a[s]/r*Math.PI*2;var h=[this.__option.radius[0]*(1+(this.__option.radius[0]>0&&e===s?-.1:0)),this.__option.radius[1]*(1+(e===s?.05:0))],c=_+.5*u,l=Math.max(this.__option.radius[0],this.__option.radius[1]),d=i(n.cx,n.cy,c,n.cx+l,n.cy),p=i(n.cx,n.cy,c,n.cx+l+15,n.cy),f=d[0]>n.cx?1:-1,v=[p[0]+20*f,p[1]],g=[p[0]+25*f,p[1]];n.node[s]={value:a[s],name:o[s],beginDeg:_,deg:u,isHover:e===s,radius:h,label:{line:[d,p,v],position:g,align:-1===f?"right":"left"}},_+=u}return n},r.prototype.bind=function(t,i){return this.__rback=i,this.__oralPie=t,this.__prePie=this.use(this.__oralPie,this.__hoverIndex),this.__rback(this.__prePie),this},r.prototype.unbind=function(){return this.__rback=function(){return null},this.__oralPie=null,this.__prePie=null,this.__hoverIndex=-1,this},r.prototype.setHover=function(t){return this.__prePie&&this.__hoverIndex!==t?(this.__hoverIndex=t,this.doUpdate(),this):this},r.prototype.doUpdate=function(){var t=this,i=this.use(this.__oralPie,this.__hoverIndex),r=JSON.parse(JSON.stringify(i));return function(t,i,r){arguments.length<2&&(i=400),arguments.length<3&&(r=function(){});let o={timer:function(t,i,e){if(!t)throw new Error("Tick is required!");let r=(new Date).valueOf()+"_"+(1e3*Math.random()).toFixed(0);return n.push({id:r,createTime:new Date,pauseTime:-1,pauseKeepTime:0,status:"running",tick:t,duration:i,callback:e}),o.start(),r},start:function(){if(!e)try{e=globalThis&&globalThis.requestAnimationFrame?globalThis.requestAnimationFrame((function t(){o.tick(),e&&(e=globalThis.requestAnimationFrame(t))})):setInterval(o.tick,13)}catch(t){e=setInterval(o.tick,13)}},tick:function(){let t,i,e,r,a,s,u,_=n;for(n=[],n.length=0,i=0;i<_.length;i++)a=_[i],t=a.createTime,e=a.tick,s=a.duration,r=a.callback,u=(+(new Date).valueOf()-t.valueOf()-a.pauseKeepTime)/s,u=u>1?1:u,"running"===a.status&&e(u),(u<1||"paused"===a.status)&&a.id?n.push(a):r(u);n.length<=0&&o.stop()},stop:function(){if(e){try{globalThis&&globalThis.requestAnimationFrame?globalThis.cancelAnimationFrame(e):clearInterval(e)}catch(t){clearInterval(e)}e=null}}},a=o.timer((function(i){t(i)}),i,r)}((function(e){if(t.__prePie)for(var n=0;n<r.count;n++)r.node[n].radius[0]=t.__prePie.node[n].radius[0]+(i.node[n].radius[0]-t.__prePie.node[n].radius[0])*e,r.node[n].radius[1]=t.__prePie.node[n].radius[1]+(i.node[n].radius[1]-t.__prePie.node[n].radius[1])*e;t.__rback(r)}),this.__option.duration,(function(){t.__prePie=i,t.__rback(t.__prePie)})),this},r}();export{r as default};
@@ -184,11 +184,11 @@ var Tree = (function () {
184
184
  }());
185
185
 
186
186
  //当前正在运动的动画的tick函数堆栈
187
- var $timers = [];
187
+ let $timers = [];
188
188
  //唯一定时器的定时间隔
189
- var $interval = 13;
189
+ let $interval = 13;
190
190
  //定时器ID
191
- var $timerId;
191
+ let $timerId;
192
192
 
193
193
  /**
194
194
  * 动画轮播
@@ -202,16 +202,19 @@ function animation(doback, duration, callback) {
202
202
  if (arguments.length < 2) duration = 400;
203
203
  if (arguments.length < 3) callback = function () { };
204
204
 
205
- var clock = {
205
+ let clock = {
206
206
  //把tick函数推入堆栈
207
207
  "timer": function (tick, duration, callback) {
208
208
  if (!tick) {
209
209
  throw new Error('Tick is required!');
210
210
  }
211
- var id = new Date().valueOf() + "_" + (Math.random() * 1000).toFixed(0);
211
+ let id = new Date().valueOf() + "_" + (Math.random() * 1000).toFixed(0);
212
212
  $timers.push({
213
213
  "id": id,
214
- "createTime": new Date(),
214
+ "createTime": new Date(), // 开始时间
215
+ "pauseTime": -1, // 暂停的时间,继续运行的时候,借助此计算暂停的时间差
216
+ "pauseKeepTime": 0, // 暂停用去的时间
217
+ "status": "running", // running(运行中), paused(暂停中)
215
218
  "tick": tick,
216
219
  "duration": duration,
217
220
  "callback": callback
@@ -240,7 +243,7 @@ function animation(doback, duration, callback) {
240
243
 
241
244
  //被定时器调用,遍历timers堆栈
242
245
  "tick": function () {
243
- var createTime, flag, tick, callback, timer, duration, passTime, timers = $timers;
246
+ let createTime, flag, tick, callback, timer, duration, passTime, timers = $timers;
244
247
 
245
248
  $timers = [];
246
249
  $timers.length = 0;
@@ -254,15 +257,21 @@ function animation(doback, duration, callback) {
254
257
  callback = timer.callback;
255
258
 
256
259
  //执行
257
- passTime = (+new Date().valueOf() - createTime.valueOf()) / duration;
260
+ passTime = (+new Date().valueOf() - createTime.valueOf() - timer.pauseKeepTime) / duration;
258
261
  passTime = passTime > 1 ? 1 : passTime;
259
- tick(passTime);
260
- if (passTime < 1 && timer.id) {
262
+
263
+ if (timer.status === "running") {
264
+ tick(passTime);
265
+ }
266
+
267
+ // 只有当动画没有结束或者动画处于暂停状态时,才继续添加到timers堆栈
268
+ if ((passTime < 1 || timer.status === "paused") && timer.id) {
261
269
  //动画没有结束再添加
262
270
  $timers.push(timer);
263
271
  } else {
264
272
  callback(passTime);
265
273
  }
274
+
266
275
  }
267
276
  if ($timers.length <= 0) {
268
277
  clock.stop();
@@ -283,20 +292,40 @@ function animation(doback, duration, callback) {
283
292
  }
284
293
  };
285
294
 
286
- var id = clock.timer(function (deep) {
295
+ let id = clock.timer(function (deep) {
287
296
  //其中deep为0-1,表示改变的程度
288
297
  doback(deep);
289
298
  }, duration, callback);
290
299
 
291
300
  return {
292
- // 一个函数
293
- // 用于在动画结束前结束动画
301
+ // 结束动画
294
302
  stop: function () {
295
- var i;
296
- for (i in $timers) {
303
+ for (let i in $timers) {
297
304
  if ($timers[i].id == id) {
298
305
  $timers[i].id = void 0;
299
- return;
306
+ }
307
+ }
308
+ },
309
+ // 暂停动画
310
+ pause: function () {
311
+ for (let i in $timers) {
312
+ if ($timers[i].id == id) {
313
+ if ($timers[i].pauseTime === -1) {
314
+ $timers[i].pauseTime = new Date();
315
+ $timers[i].status = "paused";
316
+ }
317
+ }
318
+ }
319
+ },
320
+ // 继续动画
321
+ resume: function () {
322
+ for (let i in $timers) {
323
+ if ($timers[i].id == id) {
324
+ if ($timers[i].pauseTime !== -1) {
325
+ $timers[i].pauseKeepTime += (new Date().valueOf() - $timers[i].pauseTime.valueOf());
326
+ $timers[i].pauseTime = -1;
327
+ $timers[i].status = "running";
328
+ }
300
329
  }
301
330
  }
302
331
  }