vislite 1.2.0-alpha.1 → 1.2.0-alpha.3

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 (77) hide show
  1. package/CHANGELOG +257 -250
  2. package/README.md +165 -166
  3. package/lib/Buffer/index.es.js +1 -1
  4. package/lib/Buffer/index.es.min.js +1 -1
  5. package/lib/Canvas/index.es.js +17 -8
  6. package/lib/Canvas/index.es.min.js +2 -2
  7. package/lib/Cardinal/index.es.js +1 -1
  8. package/lib/Cardinal/index.es.min.js +1 -1
  9. package/lib/Eoap/index.es.js +1 -1
  10. package/lib/Eoap/index.es.min.js +1 -1
  11. package/lib/Hermite/index.es.js +1 -1
  12. package/lib/Hermite/index.es.min.js +1 -1
  13. package/lib/Matrix4/index.es.js +1 -1
  14. package/lib/Matrix4/index.es.min.js +1 -1
  15. package/lib/Mercator/index.es.js +1 -1
  16. package/lib/Mercator/index.es.min.js +1 -1
  17. package/lib/RawCanvas/index.es.js +12 -3
  18. package/lib/RawCanvas/index.es.min.js +2 -2
  19. package/lib/SVG/index.es.js +1 -1
  20. package/lib/SVG/index.es.min.js +1 -1
  21. package/lib/Shader/index.es.js +1 -1
  22. package/lib/Shader/index.es.min.js +1 -1
  23. package/lib/Texture/index.es.js +1 -1
  24. package/lib/Texture/index.es.min.js +1 -1
  25. package/lib/TreeLayout/index.es.js +6 -6
  26. package/lib/TreeLayout/index.es.min.js +1 -1
  27. package/lib/animation/index.es.js +1 -1
  28. package/lib/animation/index.es.min.js +1 -1
  29. package/lib/assemble/index.es.d.ts +3 -0
  30. package/lib/assemble/index.es.js +23 -0
  31. package/lib/assemble/index.es.min.d.ts +3 -0
  32. package/lib/assemble/index.es.min.js +5 -0
  33. package/lib/getLoopColors/index.es.js +1 -1
  34. package/lib/getLoopColors/index.es.min.js +1 -1
  35. package/lib/getWebGLContext/index.es.js +1 -1
  36. package/lib/getWebGLContext/index.es.min.js +1 -1
  37. package/lib/index.umd.js +60 -12
  38. package/lib/index.umd.min.js +2 -2
  39. package/lib/initOption/index.es.d.ts +3 -0
  40. package/lib/initOption/index.es.js +12 -0
  41. package/lib/initOption/index.es.min.d.ts +3 -0
  42. package/lib/initOption/index.es.min.js +5 -0
  43. package/lib/mergeOption/index.es.d.ts +3 -0
  44. package/lib/mergeOption/index.es.js +42 -0
  45. package/lib/mergeOption/index.es.min.d.ts +3 -0
  46. package/lib/mergeOption/index.es.min.js +5 -0
  47. package/lib/move/index.es.js +1 -1
  48. package/lib/move/index.es.min.js +1 -1
  49. package/lib/rotate/index.es.js +1 -1
  50. package/lib/rotate/index.es.min.js +1 -1
  51. package/lib/ruler/index.es.js +1 -1
  52. package/lib/ruler/index.es.min.js +1 -1
  53. package/lib/scale/index.es.js +1 -1
  54. package/lib/scale/index.es.min.js +1 -1
  55. package/lib/throttle/index.es.js +5 -5
  56. package/lib/throttle/index.es.min.js +1 -1
  57. package/miniprogram/ui-canvas/index.js +115 -115
  58. package/package/assemble/index.ts +3 -0
  59. package/package/index.ts +11 -1
  60. package/package/initOption/index.ts +3 -0
  61. package/package/mergeOption/index.ts +3 -0
  62. package/package.json +1 -1
  63. package/src/Canvas.ts +84 -84
  64. package/src/animation.ts +98 -98
  65. package/src/common/canvas/gradient.ts +32 -24
  66. package/src/common/canvas/index.ts +182 -177
  67. package/src/common/option.ts +30 -0
  68. package/src/common/tree/index.ts +2 -2
  69. package/src/common/type.ts +27 -0
  70. package/src/layout/TreeLayout.ts +2 -2
  71. package/src/throttle.ts +2 -2
  72. package/types/Canvas.d.ts +10 -1
  73. package/types/assemble.d.ts +6 -0
  74. package/types/index.d.ts +161 -146
  75. package/types/option.d.ts +13 -0
  76. package/types/uni-canvas.d.ts +4 -0
  77. package/src/common/mergeOption.ts +0 -7
@@ -0,0 +1,3 @@
1
+ import assemble from "../../src/common/assemble"
2
+
3
+ export default assemble
package/package/index.ts CHANGED
@@ -26,6 +26,11 @@ import throttle from "./throttle/index"
26
26
 
27
27
  import TreeLayout from "./TreeLayout/index"
28
28
 
29
+ import initOption from "./initOption/index"
30
+ import mergeOption from "./mergeOption/index"
31
+
32
+ import assemble from "./assemble/index"
33
+
29
34
  export default {
30
35
 
31
36
  // 插值
@@ -60,7 +65,12 @@ export default {
60
65
 
61
66
  // 辅助
62
67
  throttle,
68
+ assemble,
63
69
 
64
70
  // 布局
65
- TreeLayout
71
+ TreeLayout,
72
+
73
+ // 配置项
74
+ initOption,
75
+ mergeOption
66
76
  }
@@ -0,0 +1,3 @@
1
+ import { initOption } from "../../src/common/option"
2
+
3
+ export default initOption
@@ -0,0 +1,3 @@
1
+ import { mergeOption } from "../../src/common/option"
2
+
3
+ export default mergeOption
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vislite",
3
- "version": "1.2.0-alpha.1",
3
+ "version": "1.2.0-alpha.3",
4
4
  "description": "灵活、快速、简单的数据可视化交互式跨端前端库",
5
5
  "main": "./lib/index.umd.min.js",
6
6
  "typings": "./types/index.d.ts",
package/src/Canvas.ts CHANGED
@@ -1,85 +1,85 @@
1
- import type CanvasType from '../types/Canvas'
2
- import type CanvasOptionType from '../types/CanvasOption'
3
-
4
- import OralCanvas from './common/canvas/index'
5
- import mergeOption from './common/mergeOption'
6
-
7
- class Canvas extends OralCanvas implements CanvasType {
8
- private __canvas: HTMLCanvasElement
9
- private __el: HTMLElement
10
- constructor(el: HTMLElement | null, option: CanvasOptionType = {}, width: number = 0, height: number = 0) {
11
- if (!el) {
12
- throw new Error("VISLite Canvas:The mount point requires an HTMLElement type but encountered null.")
13
- }
14
-
15
- option = mergeOption(option, {
16
- region: true,
17
- willReadFrequently: false
18
- })
19
-
20
- width = width || el.clientWidth
21
- height = height || el.clientHeight
22
-
23
- let ViewCanvas: HTMLCanvasElement, RegionCanvas: HTMLCanvasElement | null = null
24
-
25
- const _el = el as any
26
-
27
- // 如果已经初始化过了
28
- if (_el._vislite_canvas_) {
29
- ViewCanvas = _el._vislite_canvas_[0]
30
- RegionCanvas = _el._vislite_canvas_[1]
31
- }
32
-
33
- // 否则就初始化
34
- else {
35
- ViewCanvas = document.createElement('canvas')
36
- el.appendChild(ViewCanvas)
37
-
38
- if (option.region) {
39
- RegionCanvas = document.createElement('canvas')
40
- }
41
-
42
- _el._vislite_canvas_ = [ViewCanvas, RegionCanvas]
43
-
44
- el.setAttribute('vislite', 'Canvas')
45
- }
46
-
47
- // 设置画布大小
48
- const canvasArray = [RegionCanvas, ViewCanvas]
49
- for (let index = 0; index < canvasArray.length; index++) {
50
- const canvas = canvasArray[index]
51
- if (canvas) {
52
- canvas.style.width = width + "px"
53
- canvas.setAttribute('width', (index * width + width) + "")
54
-
55
- canvas.style.height = height + "px"
56
- canvas.setAttribute('height', (index * height + height) + "")
57
- }
58
- }
59
-
60
- super(ViewCanvas, RegionCanvas, {
61
- willReadFrequently: option.willReadFrequently,
62
- }, 2)
63
-
64
- this.__canvas = ViewCanvas
65
- this.__el = el
66
- this.painter.scale(2, 2)
67
- }
68
-
69
- toDataURL(): Promise<string> {
70
- return new Promise(resolve => {
71
- resolve(this.__canvas.toDataURL())
72
- })
73
- }
74
-
75
- bind(eventName: string, callback: (regionName: string) => void) {
76
- this.__el.addEventListener(eventName, (event: any) => {
77
- this.getRegion(event.offsetX, event.offsetY).then(regionName => {
78
- callback(regionName)
79
- })
80
- })
81
- return this
82
- }
83
- }
84
-
1
+ import type CanvasType from '../types/Canvas'
2
+ import type CanvasOptionType from '../types/CanvasOption'
3
+
4
+ import OralCanvas from './common/canvas/index'
5
+ import { initOption } from './common/option'
6
+
7
+ class Canvas extends OralCanvas implements CanvasType {
8
+ private __canvas: HTMLCanvasElement
9
+ private __el: HTMLElement
10
+ constructor(el: HTMLElement | null, option: CanvasOptionType = {}, width: number = 0, height: number = 0) {
11
+ if (!el) {
12
+ throw new Error("VISLite Canvas:The mount point requires an HTMLElement type but encountered null.")
13
+ }
14
+
15
+ option = initOption(option, {
16
+ region: true,
17
+ willReadFrequently: false
18
+ })
19
+
20
+ width = width || el.clientWidth
21
+ height = height || el.clientHeight
22
+
23
+ let ViewCanvas: HTMLCanvasElement, RegionCanvas: HTMLCanvasElement | null = null
24
+
25
+ const _el = el as any
26
+
27
+ // 如果已经初始化过了
28
+ if (_el._vislite_canvas_) {
29
+ ViewCanvas = _el._vislite_canvas_[0]
30
+ RegionCanvas = _el._vislite_canvas_[1]
31
+ }
32
+
33
+ // 否则就初始化
34
+ else {
35
+ ViewCanvas = document.createElement('canvas')
36
+ el.appendChild(ViewCanvas)
37
+
38
+ if (option.region) {
39
+ RegionCanvas = document.createElement('canvas')
40
+ }
41
+
42
+ _el._vislite_canvas_ = [ViewCanvas, RegionCanvas]
43
+
44
+ el.setAttribute('vislite', 'Canvas')
45
+ }
46
+
47
+ // 设置画布大小
48
+ const canvasArray = [RegionCanvas, ViewCanvas]
49
+ for (let index = 0; index < canvasArray.length; index++) {
50
+ const canvas = canvasArray[index]
51
+ if (canvas) {
52
+ canvas.style.width = width + "px"
53
+ canvas.setAttribute('width', (index * width + width) + "")
54
+
55
+ canvas.style.height = height + "px"
56
+ canvas.setAttribute('height', (index * height + height) + "")
57
+ }
58
+ }
59
+
60
+ super(ViewCanvas, RegionCanvas, {
61
+ willReadFrequently: option.willReadFrequently,
62
+ }, 2)
63
+
64
+ this.__canvas = ViewCanvas
65
+ this.__el = el
66
+ this.painter.scale(2, 2)
67
+ }
68
+
69
+ toDataURL(): Promise<string> {
70
+ return new Promise(resolve => {
71
+ resolve(this.__canvas.toDataURL())
72
+ })
73
+ }
74
+
75
+ bind(eventName: string, callback: (regionName: string, x: number, y: number) => void) {
76
+ this.__el.addEventListener(eventName, (event: any) => {
77
+ this.getRegion(event.offsetX, event.offsetY).then(regionName => {
78
+ callback(regionName, event.offsetX, event.offsetY)
79
+ })
80
+ })
81
+ return this
82
+ }
83
+ }
84
+
85
85
  export default Canvas
package/src/animation.ts CHANGED
@@ -1,99 +1,99 @@
1
- //当前正在运动的动画的tick函数堆栈
2
- let $timers: any[] = []
3
- //唯一定时器的定时间隔
4
- const $interval = 13
5
- //定时器ID
6
- let $timerId: any
7
-
8
- /**
9
- * 动画轮播
10
- * @param {function} doback 轮询函数,有一个形参deep,0-1,表示执行进度
11
- * @param {number} duration 动画时长,可选
12
- * @param {function} callback 动画结束回调,可选,有一个形参deep,0-1,表示执行进度
13
- *
14
- * @returns {function} 返回一个函数,调用该函数,可以提前结束动画
15
- */
16
- export default function (doback: (deep: number) => void, duration: number = 400, callback: (deep: number) => void = () => { }): Function {
17
-
18
- const clock = {
19
- //把tick函数推入堆栈
20
- "timer": function (tick: (deep: number) => void, duration: number, callback: (deep: number) => void) {
21
- if (!tick) {
22
- throw new Error('Tick is required!')
23
- }
24
- const id = new Date().valueOf() + "_" + (Math.random() * 1000).toFixed(0)
25
- $timers.push({
26
- "id": id,
27
- "createTime": new Date(),
28
- "tick": tick,
29
- "duration": duration,
30
- "callback": callback
31
- });
32
- clock.start()
33
- return id
34
- },
35
-
36
- //开启唯一的定时器timerId
37
- "start": function () {
38
- if (!$timerId) {
39
- $timerId = setInterval(clock.tick, $interval)
40
- }
41
- },
42
-
43
- //被定时器调用,遍历timers堆栈
44
- "tick": function () {
45
- let createTime: Date, flag: number, tick: (deep: number) => void, callback: (deep: number) => void, timer: any, duration: number, passTime: number
46
- const timers: any[] = $timers
47
- $timers = []
48
- $timers.length = 0
49
- for (flag = 0; flag < timers.length; flag++) {
50
- //初始化数据
51
- timer = timers[flag]
52
- createTime = timer.createTime
53
- tick = timer.tick
54
- duration = timer.duration
55
- callback = timer.callback
56
-
57
- //执行
58
- passTime = (+new Date().valueOf() - createTime.valueOf()) / duration
59
- passTime = passTime > 1 ? 1 : passTime
60
- tick(passTime)
61
- if (passTime < 1 && timer.id) {
62
- //动画没有结束再添加
63
- $timers.push(timer)
64
- } else {
65
- callback(passTime)
66
- }
67
- }
68
- if ($timers.length <= 0) {
69
- clock.stop()
70
- }
71
- },
72
-
73
- //停止定时器,重置timerId=null
74
- "stop": function () {
75
- if ($timerId) {
76
- clearInterval($timerId)
77
- $timerId = null
78
- }
79
- }
80
- }
81
-
82
- const id = clock.timer(function (deep: number) {
83
- //其中deep为0-1,表示改变的程度
84
- doback(deep)
85
- }, duration, callback)
86
-
87
- // 返回一个函数
88
- // 用于在动画结束前结束动画
89
- return function () {
90
- let i: string
91
- for (i in $timers) {
92
- if ($timers[i].id == id) {
93
- $timers[i].id = void 0
94
- return
95
- }
96
- }
97
- }
98
-
1
+ //当前正在运动的动画的tick函数堆栈
2
+ let $timers: any[] = []
3
+ //唯一定时器的定时间隔
4
+ const $interval = 13
5
+ //定时器ID
6
+ let $timerId: any
7
+
8
+ /**
9
+ * 动画轮播
10
+ * @param {function} doback 轮询函数,有一个形参deep,0-1,表示执行进度
11
+ * @param {number} duration 动画时长,可选
12
+ * @param {function} callback 动画结束回调,可选,有一个形参deep,0-1,表示执行进度
13
+ *
14
+ * @returns {function} 返回一个函数,调用该函数,可以提前结束动画
15
+ */
16
+ export default function (doback: (deep: number) => void, duration: number = 400, callback: (deep: number) => void = () => { }): Function {
17
+
18
+ const clock = {
19
+ //把tick函数推入堆栈
20
+ "timer": function (tick: (deep: number) => void, duration: number, callback: (deep: number) => void) {
21
+ if (!tick) {
22
+ throw new Error('Tick is required!')
23
+ }
24
+ const id = new Date().valueOf() + "_" + (Math.random() * 1000).toFixed(0)
25
+ $timers.push({
26
+ "id": id,
27
+ "createTime": new Date(),
28
+ "tick": tick,
29
+ "duration": duration,
30
+ "callback": callback
31
+ })
32
+ clock.start()
33
+ return id
34
+ },
35
+
36
+ //开启唯一的定时器timerId
37
+ "start": function () {
38
+ if (!$timerId) {
39
+ $timerId = setInterval(clock.tick, $interval)
40
+ }
41
+ },
42
+
43
+ //被定时器调用,遍历timers堆栈
44
+ "tick": function () {
45
+ let createTime: Date, flag: number, tick: (deep: number) => void, callback: (deep: number) => void, timer: any, duration: number, passTime: number
46
+ const timers: any[] = $timers
47
+ $timers = []
48
+ $timers.length = 0
49
+ for (flag = 0; flag < timers.length; flag++) {
50
+ //初始化数据
51
+ timer = timers[flag]
52
+ createTime = timer.createTime
53
+ tick = timer.tick
54
+ duration = timer.duration
55
+ callback = timer.callback
56
+
57
+ //执行
58
+ passTime = (+new Date().valueOf() - createTime.valueOf()) / duration
59
+ passTime = passTime > 1 ? 1 : passTime
60
+ tick(passTime)
61
+ if (passTime < 1 && timer.id) {
62
+ //动画没有结束再添加
63
+ $timers.push(timer)
64
+ } else {
65
+ callback(passTime)
66
+ }
67
+ }
68
+ if ($timers.length <= 0) {
69
+ clock.stop()
70
+ }
71
+ },
72
+
73
+ //停止定时器,重置timerId=null
74
+ "stop": function () {
75
+ if ($timerId) {
76
+ clearInterval($timerId)
77
+ $timerId = null
78
+ }
79
+ }
80
+ }
81
+
82
+ const id = clock.timer(function (deep: number) {
83
+ //其中deep为0-1,表示改变的程度
84
+ doback(deep)
85
+ }, duration, callback)
86
+
87
+ // 返回一个函数
88
+ // 用于在动画结束前结束动画
89
+ return function () {
90
+ let i: string
91
+ for (i in $timers) {
92
+ if ($timers[i].id == id) {
93
+ $timers[i].id = void 0
94
+ return
95
+ }
96
+ }
97
+ }
98
+
99
99
  }
@@ -1,24 +1,32 @@
1
- let enhanceGradient = function (gradient: CanvasGradient) {
2
- const enhanceGradient = {
3
- "value": function () {
4
- return gradient
5
- },
6
- "setColor": function (stop: number, color: string) {
7
- gradient.addColorStop(stop, color)
8
- return enhanceGradient
9
- }
10
- };
11
- return enhanceGradient
12
- }
13
-
14
- // 线性渐变
15
- export const linearGradient = function (painter: CanvasRenderingContext2D, x0: number, y0: number, x1: number, y1: number) {
16
- const gradient = painter.createLinearGradient(x0, y0, x1, y1)
17
- return enhanceGradient(gradient)
18
- }
19
-
20
- // 环形渐变
21
- export const radialGradient = function (painter: CanvasRenderingContext2D, cx: number, cy: number, r: number) {
22
- const gradient = painter.createRadialGradient(cx, cy, 0, cx, cy, r)
23
- return enhanceGradient(gradient)
24
- }
1
+ let enhanceGradient = function (gradient: CanvasGradient, calcStop?: Function) {
2
+ const enhanceGradient = {
3
+ "value": function () {
4
+ return gradient
5
+ },
6
+ "setColor": function (stop: number, color: string) {
7
+ gradient.addColorStop(calcStop ? calcStop(stop) : stop, color)
8
+ return enhanceGradient
9
+ }
10
+ };
11
+ return enhanceGradient
12
+ }
13
+
14
+ // 线性渐变
15
+ export const linearGradient = function (painter: CanvasRenderingContext2D, x0: number, y0: number, x1: number, y1: number) {
16
+ const gradient = painter.createLinearGradient(x0, y0, x1, y1)
17
+ return enhanceGradient(gradient)
18
+ }
19
+
20
+ // 环形渐变
21
+ export const radialGradient = function (painter: CanvasRenderingContext2D, cx: number, cy: number, r: number) {
22
+ const gradient = painter.createRadialGradient(cx, cy, 0, cx, cy, r)
23
+ return enhanceGradient(gradient)
24
+ }
25
+
26
+ // 角度渐变
27
+ export const conicGradient = function (painter: CanvasRenderingContext2D, cx: number, cy: number, startDeg: number, deg?: number) {
28
+ const gradient = painter.createConicGradient(startDeg, cx, cy)
29
+ return enhanceGradient(gradient, deg ? (stop: number) => {
30
+ return deg / (Math.PI * 2) * stop
31
+ } : undefined)
32
+ }