@visactor/vgrammar-core 0.7.2 → 0.7.4-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.
- package/README.md +136 -97
- package/README.zh-CN.md +195 -6
- package/cjs/graph/animation/animation/update.js +2 -4
- package/cjs/graph/animation/animation/update.js.map +1 -1
- package/cjs/graph/animation/attribute.d.ts +1 -0
- package/cjs/graph/animation/attribute.js +11 -1
- package/cjs/graph/animation/attribute.js.map +1 -1
- package/cjs/index.d.ts +1 -1
- package/cjs/index.js +1 -1
- package/cjs/index.js.map +1 -1
- package/es/graph/animation/animation/update.js +1 -5
- package/es/graph/animation/animation/update.js.map +1 -1
- package/es/graph/animation/attribute.d.ts +1 -0
- package/es/graph/animation/attribute.js +12 -2
- package/es/graph/animation/attribute.js.map +1 -1
- package/es/index.d.ts +1 -1
- package/es/index.js +1 -1
- package/es/index.js.map +1 -1
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -1,12 +1,65 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
|
+
<a href="https://github.com/VisActor#gh-light-mode-only" target="_blank">
|
|
3
|
+
<img alt="VisActor Logo" width="200" src="https://github.com/VisActor/.github/blob/main/profile/logo_500_200_light.svg"/>
|
|
4
|
+
</a>
|
|
5
|
+
<a href="https://github.com/VisActor#gh-dark-mode-only" target="_blank">
|
|
6
|
+
<img alt="VisActor Logo" width="200" src="https://github.com/VisActor/.github/blob/main/profile/logo_500_200_dark.svg"/>
|
|
7
|
+
</a>
|
|
8
|
+
</div>
|
|
2
9
|
|
|
3
|
-
|
|
10
|
+
<div align="center">
|
|
11
|
+
<h1>VGrammar</h1>
|
|
12
|
+
</div>
|
|
4
13
|
|
|
5
|
-
|
|
14
|
+
<div align="center">
|
|
6
15
|
|
|
7
|
-
|
|
16
|
+
VGrammar, not only generate charts, but also provide data visualization tools.
|
|
8
17
|
|
|
9
|
-
|
|
18
|
+
<p align="center">
|
|
19
|
+
<a href="https://www.visactor.io/vgrammar">Introduction</a> •
|
|
20
|
+
<a href="https://www.visactor.io/vgrammar/example">Demo</a> •
|
|
21
|
+
<a href="https://www.visactor.io/vgrammar/guide/guides/quick-start">Tutorial</a> •
|
|
22
|
+
<a href="https://www.visactor.io/vgrammar/api/API/View">API</a>•
|
|
23
|
+
<a href="https://www.visactor.io/vgrammar/option/">Option</a>
|
|
24
|
+
</p>
|
|
25
|
+
|
|
26
|
+

|
|
27
|
+

|
|
28
|
+
[](https://www.npmjs.com/package/@visactor/vgrammar)
|
|
29
|
+
[](https://www.npmjs.com/package/@visactor/vgrammar)
|
|
30
|
+
[](https://github.com/visactor/vgrammar/blob/main/LICENSE)
|
|
31
|
+
|
|
32
|
+
</div>
|
|
33
|
+
|
|
34
|
+
<div align="center">
|
|
35
|
+
|
|
36
|
+
English| [简体中文](./README.zh-CN.md)
|
|
37
|
+
|
|
38
|
+
</div>
|
|
39
|
+
|
|
40
|
+
<div align="center">
|
|
41
|
+
|
|
42
|
+
(video)
|
|
43
|
+
|
|
44
|
+
</div>
|
|
45
|
+
|
|
46
|
+
# Introduction
|
|
47
|
+
|
|
48
|
+
VGrammar is a visual grammar library based on visual rendering engine [VRender](https://github.com/VisActor/VRender). The core capabilities are as follows:
|
|
49
|
+
|
|
50
|
+
1. Easy to Use by Default: VGrammar features a concise syntax, comprehensive interface, rich component library, and simplified development process.
|
|
51
|
+
2. Rich in Capabilities: VGrammar provides extensive capabilities for chart definition, animation arrangement, artistic expression, and complete coverage of various needs.
|
|
52
|
+
3. Flexible and Extensible: VGrammar offers flexible extension options, including custom rendering of graphical elements, data mapping, automatic layout, and effortless expansion possibilities.
|
|
53
|
+
|
|
54
|
+
# Repo Intro
|
|
55
|
+
|
|
56
|
+
This repository includes the following packages:
|
|
57
|
+
|
|
58
|
+
1. VGrammar: The main package of VGrammar
|
|
59
|
+
|
|
60
|
+
# Usage
|
|
61
|
+
|
|
62
|
+
## Installation
|
|
10
63
|
|
|
11
64
|
[npm package](https://www.npmjs.com/package/@visactor/vgrammar)
|
|
12
65
|
|
|
@@ -18,126 +71,86 @@ npm install @visactor/vgrammar
|
|
|
18
71
|
yarn add @visactor/vgrammar
|
|
19
72
|
```
|
|
20
73
|
|
|
21
|
-
|
|
74
|
+
## Quick Start
|
|
22
75
|
|
|
23
76
|
```javascript
|
|
24
|
-
import { View } from '@visactor/vgrammar
|
|
77
|
+
import { View } from '@visactor/vgrammar';
|
|
25
78
|
|
|
26
79
|
const spec = {
|
|
27
|
-
padding: { top: 5, right: 5, bottom: 30, left: 60 },
|
|
28
80
|
data: [
|
|
29
81
|
{
|
|
30
82
|
id: 'table',
|
|
31
83
|
values: [
|
|
32
84
|
{
|
|
33
|
-
|
|
34
|
-
|
|
85
|
+
value: 3676,
|
|
86
|
+
name: ' ~ 29'
|
|
35
87
|
},
|
|
36
88
|
{
|
|
37
|
-
|
|
38
|
-
|
|
89
|
+
value: 3872,
|
|
90
|
+
name: '30 ~ 39'
|
|
39
91
|
},
|
|
40
92
|
{
|
|
41
|
-
|
|
42
|
-
|
|
93
|
+
value: 1668,
|
|
94
|
+
name: '40 ~ 49'
|
|
43
95
|
},
|
|
44
96
|
{
|
|
45
|
-
|
|
46
|
-
|
|
97
|
+
value: 610,
|
|
98
|
+
name: '50 ~'
|
|
99
|
+
}
|
|
100
|
+
]
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
id: 'pie',
|
|
104
|
+
source: 'table',
|
|
105
|
+
transform: [
|
|
106
|
+
{
|
|
107
|
+
type: 'pie',
|
|
108
|
+
field: 'value',
|
|
109
|
+
asStartAngle: 'startAngle',
|
|
110
|
+
asEndAngle: 'endAngle'
|
|
47
111
|
}
|
|
48
112
|
]
|
|
49
113
|
}
|
|
50
114
|
],
|
|
115
|
+
|
|
51
116
|
scales: [
|
|
52
117
|
{
|
|
53
|
-
id: '
|
|
54
|
-
type: '
|
|
118
|
+
id: 'colorScale',
|
|
119
|
+
type: 'ordinal',
|
|
55
120
|
domain: { data: 'table', field: 'name' },
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
range: (scale, params) => {
|
|
69
|
-
return [params.viewBox.y2, params.viewBox.y1];
|
|
70
|
-
},
|
|
71
|
-
nice: true
|
|
121
|
+
range: [
|
|
122
|
+
'#6690F2',
|
|
123
|
+
'#70D6A3',
|
|
124
|
+
'#B4E6E2',
|
|
125
|
+
'#63B5FC',
|
|
126
|
+
'#FF8F62',
|
|
127
|
+
'#FFDC83',
|
|
128
|
+
'#BCC5FD',
|
|
129
|
+
'#A29BFE',
|
|
130
|
+
'#63C4C7',
|
|
131
|
+
'#F68484'
|
|
132
|
+
]
|
|
72
133
|
}
|
|
73
134
|
],
|
|
74
135
|
|
|
75
136
|
marks: [
|
|
76
137
|
{
|
|
77
|
-
type: '
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
tickCount: -1,
|
|
81
|
-
dependency: ['viewBox'],
|
|
82
|
-
encode: {
|
|
83
|
-
update: (scale, elment, params) => {
|
|
84
|
-
return {
|
|
85
|
-
x: params.viewBox.x1,
|
|
86
|
-
y: params.viewBox.y2,
|
|
87
|
-
start: { x: 0, y: 0 },
|
|
88
|
-
end: { x: params.viewBox.width(), y: 0 }
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
},
|
|
93
|
-
{
|
|
94
|
-
type: 'component',
|
|
95
|
-
componentType: 'axis',
|
|
96
|
-
scale: 'yscale',
|
|
97
|
-
dependency: ['viewBox'],
|
|
98
|
-
encode: {
|
|
99
|
-
update: (scale, elment, params) => {
|
|
100
|
-
return {
|
|
101
|
-
x: params.viewBox.x1,
|
|
102
|
-
y: params.viewBox.y1,
|
|
103
|
-
start: { x: 0, y: params.viewBox.height() },
|
|
104
|
-
end: { x: 0, y: 0 },
|
|
105
|
-
verticalFactor: -1
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
},
|
|
110
|
-
{
|
|
111
|
-
type: 'component',
|
|
112
|
-
componentType: 'crosshair',
|
|
113
|
-
scale: 'xscale',
|
|
114
|
-
crosshairShape: 'rect',
|
|
115
|
-
crosshairType: 'x',
|
|
116
|
-
dependency: ['viewBox'],
|
|
138
|
+
type: 'arc',
|
|
139
|
+
from: { data: 'pie' },
|
|
140
|
+
dependency: ['viewBox', 'colorScale'],
|
|
117
141
|
encode: {
|
|
118
|
-
update: (
|
|
142
|
+
update: (datum, element, params) => {
|
|
143
|
+
const viewBox = params.viewBox;
|
|
144
|
+
const maxR = Math.min(viewBox.width() / 2, viewBox.height() / 2);
|
|
119
145
|
return {
|
|
120
|
-
|
|
121
|
-
|
|
146
|
+
x: viewBox.x1 + viewBox.width() / 2,
|
|
147
|
+
y: viewBox.y1 + viewBox.height() / 2,
|
|
148
|
+
startAngle: datum.startAngle,
|
|
149
|
+
endAngle: datum.endAngle,
|
|
150
|
+
innerRadius: 100,
|
|
151
|
+
outerRadius: maxR,
|
|
152
|
+
fill: params.colorScale.scale(datum.name)
|
|
122
153
|
};
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
},
|
|
126
|
-
{
|
|
127
|
-
type: 'rect',
|
|
128
|
-
from: { data: 'table' },
|
|
129
|
-
encode: {
|
|
130
|
-
update: {
|
|
131
|
-
x: { scale: 'xscale', field: 'name' },
|
|
132
|
-
width: { scale: 'xscale', band: 1 },
|
|
133
|
-
y: { scale: 'yscale', field: 'value' },
|
|
134
|
-
y1: {
|
|
135
|
-
callback: (datum, element, params) => {
|
|
136
|
-
return params.yscale.scale(params.yscale.domain()[0]);
|
|
137
|
-
},
|
|
138
|
-
dependency: ['yscale']
|
|
139
|
-
},
|
|
140
|
-
fill: '#6690F2'
|
|
141
154
|
},
|
|
142
155
|
hover: {
|
|
143
156
|
fill: 'red'
|
|
@@ -149,8 +162,6 @@ const spec = {
|
|
|
149
162
|
|
|
150
163
|
const vGrammarView = new View({
|
|
151
164
|
autoFit: true,
|
|
152
|
-
width: spec.width,
|
|
153
|
-
height: spec.height,
|
|
154
165
|
container: 'chart',
|
|
155
166
|
hover: true
|
|
156
167
|
});
|
|
@@ -158,3 +169,31 @@ vGrammarView.parseSpec(spec);
|
|
|
158
169
|
|
|
159
170
|
vGrammarView.runAsync();
|
|
160
171
|
```
|
|
172
|
+
|
|
173
|
+
##
|
|
174
|
+
|
|
175
|
+
[More demos and detailed tutorials](https://visactor.io/vgrammar)
|
|
176
|
+
|
|
177
|
+
# Related Links
|
|
178
|
+
|
|
179
|
+
- [Official website](https://visactor.io/vgrammar)
|
|
180
|
+
|
|
181
|
+
# Ecosystem
|
|
182
|
+
|
|
183
|
+
| Project | Description |
|
|
184
|
+
| ----------------------------------------------------------- | -------------------------------------------------------------------------------------- |
|
|
185
|
+
| [VChart](https://visactor.io/vchart) | A charts lib based on [VisActor/VGrammar](https://visactor.io/vgrammar) |
|
|
186
|
+
| [React Component Library](https://visactor.io/react-vchart) | A React chart component library based on [VisActor/VChart](https://visactor.io/vchart) |
|
|
187
|
+
| [AI-generated Components](https://visactor.io/ai-vchart) | AI-generated chart component. |
|
|
188
|
+
|
|
189
|
+
# Contribution
|
|
190
|
+
|
|
191
|
+
If you would like to contribute, please read the [Code of Conduct ](./CODE_OF_CONDUCT.md) and [ Guide](./CONTRIBUTING.zh-CN.md) first。
|
|
192
|
+
|
|
193
|
+
Small streams converge to make great rivers and seas!
|
|
194
|
+
|
|
195
|
+
<a href="https://github.com/visactor/vgrammar/graphs/contributors"><img src="https://contrib.rocks/image?repo=visactor/vgrammar" /></a>
|
|
196
|
+
|
|
197
|
+
# License
|
|
198
|
+
|
|
199
|
+
[MIT License](./LICENSE)
|
package/README.zh-CN.md
CHANGED
|
@@ -1,11 +1,200 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
|
+
<a href="https://github.com/VisActor#gh-light-mode-only" target="_blank">
|
|
3
|
+
<img alt="VisActor Logo" width="200" src="https://github.com/VisActor/.github/blob/main/profile/logo_500_200_light.svg"/>
|
|
4
|
+
</a>
|
|
5
|
+
<a href="https://github.com/VisActor#gh-dark-mode-only" target="_blank">
|
|
6
|
+
<img alt="VisActor Logo" width="200" src="https://github.com/VisActor/.github/blob/main/profile/logo_500_200_dark.svg"/>
|
|
7
|
+
</a>
|
|
8
|
+
</div>
|
|
2
9
|
|
|
3
|
-
|
|
10
|
+
<div align="center">
|
|
11
|
+
<h1>VGrammar</h1>
|
|
12
|
+
</div>
|
|
4
13
|
|
|
5
|
-
|
|
14
|
+
<div align="center">
|
|
6
15
|
|
|
7
|
-
|
|
16
|
+
VGrammar,不只是生成万千图表的可视化语法,更是化枯燥为神奇的数据魔法师。
|
|
8
17
|
|
|
9
|
-
|
|
10
|
-
|
|
18
|
+
<p align="center">
|
|
19
|
+
<a href="https://www.visactor.io/vgrammar">简介</a> •
|
|
20
|
+
<a href="https://www.visactor.io/vgrammar/example">Demo</a> •
|
|
21
|
+
<a href="https://www.visactor.io/vgrammar/guide/guides/quick-start">教程</a> •
|
|
22
|
+
<a href="https://www.visactor.io/vgrammar/api/API/View">API</a>•
|
|
23
|
+
<a href="https://www.visactor.io/vgrammar/option/">配置</a>
|
|
24
|
+
</p>
|
|
25
|
+
|
|
26
|
+

|
|
27
|
+

|
|
28
|
+
[](https://www.npmjs.com/package/@visactor/vgrammar)
|
|
29
|
+
[](https://www.npmjs.com/package/@visactor/vgrammar)
|
|
30
|
+
[](https://github.com/visactor/vgrammar/blob/main/LICENSE)
|
|
31
|
+
|
|
32
|
+
</div>
|
|
33
|
+
|
|
34
|
+
<div align="center">
|
|
35
|
+
|
|
36
|
+
[English](./README.md) | 简体中文
|
|
37
|
+
|
|
38
|
+
</div>
|
|
39
|
+
|
|
40
|
+
<div align="center">
|
|
41
|
+
|
|
42
|
+
(演示视频)
|
|
43
|
+
|
|
44
|
+
</div>
|
|
45
|
+
|
|
46
|
+
# 简介
|
|
47
|
+
|
|
48
|
+
VGrammar 是 VisActor 可视化体系中的可视化语法库,基于可视化渲染引擎 [VRender](https://github.com/VisActor/VRender) 进行组件封装。核心能力如下:
|
|
49
|
+
|
|
50
|
+
1. 默认好用:语法简洁,接口完备,组件丰富,开发简单;
|
|
51
|
+
2. 能力丰富:图表定义,动画编排,艺术表达,完整覆盖;
|
|
52
|
+
3. 灵活扩展:图元渲染,数据映射,自动布局,轻松扩展;
|
|
53
|
+
|
|
54
|
+
# 仓库简介
|
|
55
|
+
|
|
56
|
+
本仓库包含如下 package
|
|
57
|
+
|
|
58
|
+
1. VGrammar: 图形语法
|
|
59
|
+
|
|
60
|
+
# 使用
|
|
61
|
+
|
|
62
|
+
## 安装
|
|
63
|
+
|
|
64
|
+
[npm package](https://www.npmjs.com/package/@visactor/vgrammar)
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
// npm
|
|
68
|
+
npm install @visactor/vgrammar
|
|
69
|
+
|
|
70
|
+
// yarn
|
|
71
|
+
yarn add @visactor/vgrammar
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## 快速上手
|
|
75
|
+
|
|
76
|
+
```javascript
|
|
77
|
+
import { View } from '@visactor/vgrammar';
|
|
78
|
+
|
|
79
|
+
const spec = {
|
|
80
|
+
data: [
|
|
81
|
+
{
|
|
82
|
+
id: 'table',
|
|
83
|
+
values: [
|
|
84
|
+
{
|
|
85
|
+
value: 3676,
|
|
86
|
+
name: ' ~ 29'
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
value: 3872,
|
|
90
|
+
name: '30 ~ 39'
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
value: 1668,
|
|
94
|
+
name: '40 ~ 49'
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
value: 610,
|
|
98
|
+
name: '50 ~'
|
|
99
|
+
}
|
|
100
|
+
]
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
id: 'pie',
|
|
104
|
+
source: 'table',
|
|
105
|
+
transform: [
|
|
106
|
+
{
|
|
107
|
+
type: 'pie',
|
|
108
|
+
field: 'value',
|
|
109
|
+
asStartAngle: 'startAngle',
|
|
110
|
+
asEndAngle: 'endAngle'
|
|
111
|
+
}
|
|
112
|
+
]
|
|
113
|
+
}
|
|
114
|
+
],
|
|
115
|
+
|
|
116
|
+
scales: [
|
|
117
|
+
{
|
|
118
|
+
id: 'colorScale',
|
|
119
|
+
type: 'ordinal',
|
|
120
|
+
domain: { data: 'table', field: 'name' },
|
|
121
|
+
range: [
|
|
122
|
+
'#6690F2',
|
|
123
|
+
'#70D6A3',
|
|
124
|
+
'#B4E6E2',
|
|
125
|
+
'#63B5FC',
|
|
126
|
+
'#FF8F62',
|
|
127
|
+
'#FFDC83',
|
|
128
|
+
'#BCC5FD',
|
|
129
|
+
'#A29BFE',
|
|
130
|
+
'#63C4C7',
|
|
131
|
+
'#F68484'
|
|
132
|
+
]
|
|
133
|
+
}
|
|
134
|
+
],
|
|
135
|
+
|
|
136
|
+
marks: [
|
|
137
|
+
{
|
|
138
|
+
type: 'arc',
|
|
139
|
+
from: { data: 'pie' },
|
|
140
|
+
dependency: ['viewBox', 'colorScale'],
|
|
141
|
+
encode: {
|
|
142
|
+
update: (datum, element, params) => {
|
|
143
|
+
const viewBox = params.viewBox;
|
|
144
|
+
const maxR = Math.min(viewBox.width() / 2, viewBox.height() / 2);
|
|
145
|
+
return {
|
|
146
|
+
x: viewBox.x1 + viewBox.width() / 2,
|
|
147
|
+
y: viewBox.y1 + viewBox.height() / 2,
|
|
148
|
+
startAngle: datum.startAngle,
|
|
149
|
+
endAngle: datum.endAngle,
|
|
150
|
+
innerRadius: 100,
|
|
151
|
+
outerRadius: maxR,
|
|
152
|
+
fill: params.colorScale.scale(datum.name)
|
|
153
|
+
};
|
|
154
|
+
},
|
|
155
|
+
hover: {
|
|
156
|
+
fill: 'red'
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
]
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
const vGrammarView = new View({
|
|
164
|
+
autoFit: true,
|
|
165
|
+
container: 'chart',
|
|
166
|
+
hover: true
|
|
167
|
+
});
|
|
168
|
+
vGrammarView.parseSpec(spec);
|
|
169
|
+
|
|
170
|
+
vGrammarView.runAsync();
|
|
11
171
|
```
|
|
172
|
+
|
|
173
|
+
##
|
|
174
|
+
|
|
175
|
+
[更多 demo 和详细教程](https://visactor.io/vgrammar)
|
|
176
|
+
|
|
177
|
+
# 相关链接
|
|
178
|
+
|
|
179
|
+
- [官网](https://visactor.io/vgrammar)
|
|
180
|
+
|
|
181
|
+
# 生态
|
|
182
|
+
|
|
183
|
+
| 项目 | 介绍 |
|
|
184
|
+
| ---- | ---- |
|
|
185
|
+
|
|
186
|
+
| [VChart](https://visactor.io/vchart) | 基于 [VisActor/VGrammar](https://visactor.io/vgrammar) 封装的图表库。 |
|
|
187
|
+
| [React 组件库](https://visactor.io/react-vgrammar) | 基于 [VisActor/VChart](https://visactor.io/vgrammar) 的 React 图表 组件库。 |
|
|
188
|
+
| [智能生成组件](https://visactor.io/ai-vgrammar) | 基于 AI 的智能图表生成组件 |
|
|
189
|
+
|
|
190
|
+
# 参与贡献
|
|
191
|
+
|
|
192
|
+
如想参与贡献,请先阅读 [行为准则](./CODE_OF_CONDUCT.md) 和 [贡献指南](./CONTRIBUTING.zh-CN.md)。
|
|
193
|
+
|
|
194
|
+
细流成河,终成大海!
|
|
195
|
+
|
|
196
|
+
<a href="https://github.com/visactor/vgrammar/graphs/contributors"><img src="https://contrib.rocks/image?repo=visactor/vgrammar" /></a>
|
|
197
|
+
|
|
198
|
+
# 许可证
|
|
199
|
+
|
|
200
|
+
[MIT 协议](./LICENSE)
|
|
@@ -4,11 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: !0
|
|
5
5
|
}), exports.update = void 0;
|
|
6
6
|
|
|
7
|
-
const vutils_1 = require("@visactor/vutils"), vgrammar_util_1 = require("@visactor/vgrammar-util"),
|
|
7
|
+
const vutils_1 = require("@visactor/vutils"), vgrammar_util_1 = require("@visactor/vgrammar-util"), update = (element, options, animationParameters) => {
|
|
8
8
|
const from = Object.assign({}, element.getPrevGraphicAttributes()), to = Object.assign({}, element.getNextGraphicAttributes());
|
|
9
|
-
return
|
|
10
|
-
delete from[key], delete to[key];
|
|
11
|
-
})), (0, vutils_1.array)(null == options ? void 0 : options.excludeChannels).forEach((key => {
|
|
9
|
+
return (0, vutils_1.array)(null == options ? void 0 : options.excludeChannels).forEach((key => {
|
|
12
10
|
delete from[key], delete to[key];
|
|
13
11
|
})), Object.keys(to).forEach((key => {
|
|
14
12
|
(0, vgrammar_util_1.isEqual)(key, from, to) && (delete from[key], delete to[key]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/graph/animation/animation/update.ts"],"names":[],"mappings":";;;AAAA,6CAAyC;AACzC,2DAAkD;
|
|
1
|
+
{"version":3,"sources":["../src/graph/animation/animation/update.ts"],"names":[],"mappings":";;;AAAA,6CAAyC;AACzC,2DAAkD;AAQ3C,MAAM,MAAM,GAA4B,CAC7C,OAAiB,EACjB,OAAgC,EAChC,mBAAyC,EACzC,EAAE;IACF,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,OAAO,CAAC,wBAAwB,EAAE,CAAC,CAAC;IACnE,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,OAAO,CAAC,wBAAwB,EAAE,CAAC,CAAC;IACjE,IAAA,cAAK,EAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,eAAe,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;QAC5C,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;QACjB,OAAO,EAAE,CAAC,GAAG,CAAC,CAAC;IACjB,CAAC,CAAC,CAAC;IACH,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;QAC5B,IAAI,IAAA,uBAAO,EAAC,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC,EAAE;YAC1B,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;YACjB,OAAO,EAAE,CAAC,GAAG,CAAC,CAAC;SAChB;IACH,CAAC,CAAC,CAAC;IACH,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;AACtB,CAAC,CAAC;AAlBW,QAAA,MAAM,UAkBjB","file":"update.js","sourcesContent":["import { array } from '@visactor/vutils';\nimport { isEqual } from '@visactor/vgrammar-util';\nimport type { IElement } from '../../../types';\nimport type { IAnimationParameters, TypeAnimation } from '../../../types/animate';\n\nexport interface IUpdateAnimationOptions {\n excludeChannels: string[];\n}\n\nexport const update: TypeAnimation<IElement> = (\n element: IElement,\n options: IUpdateAnimationOptions,\n animationParameters: IAnimationParameters\n) => {\n const from = Object.assign({}, element.getPrevGraphicAttributes());\n const to = Object.assign({}, element.getNextGraphicAttributes());\n array(options?.excludeChannels).forEach(key => {\n delete from[key];\n delete to[key];\n });\n Object.keys(to).forEach(key => {\n if (isEqual(key, from, to)) {\n delete from[key];\n delete to[key];\n }\n });\n return { from, to };\n};\n"]}
|
|
@@ -23,5 +23,6 @@ export declare class AttributeAnimate extends ACustomAnimate<any> {
|
|
|
23
23
|
onBind(): void;
|
|
24
24
|
onStart(): void;
|
|
25
25
|
onEnd(): void;
|
|
26
|
+
update(end: boolean, ratio: number, out: Record<string, any>): void;
|
|
26
27
|
onUpdate(end: boolean, ratio: number, out: Record<string, any>): void;
|
|
27
28
|
}
|
|
@@ -99,9 +99,12 @@ class AttributeAnimate extends vrender_1.ACustomAnimate {
|
|
|
99
99
|
this.from = null !== (_a = this.from) && void 0 !== _a ? _a : {}, this.to = null !== (_b = this.to) && void 0 !== _b ? _b : {};
|
|
100
100
|
}
|
|
101
101
|
onStart() {
|
|
102
|
+
var _a;
|
|
103
|
+
const excludedChannelMap = null !== (_a = this.target.constructor.NOWORK_ANIMATE_ATTR) && void 0 !== _a ? _a : vrender_1.NOWORK_ANIMATE_ATTR, excludedChannels = Object.keys(excludedChannelMap).filter((channel => 0 !== excludedChannelMap[channel]));
|
|
104
|
+
this.subAnimate.animate.preventAttrs(excludedChannels);
|
|
102
105
|
const from = Object.assign({}, this.from), to = Object.assign({}, this.to);
|
|
103
106
|
Object.keys(to).forEach((k => {
|
|
104
|
-
(0, vutils_1.isNil)(from[k]) && (from[k] = this.target.getComputedAttribute(k));
|
|
107
|
+
excludedChannels.includes(k) ? (from[k] = to[k], this.from[k] = to[k]) : (0, vutils_1.isNil)(from[k]) && (from[k] = this.target.getComputedAttribute(k));
|
|
105
108
|
})), this.target.setAttributes(from, !1, {
|
|
106
109
|
type: vrender_1.AttributeUpdateType.ANIMATE_UPDATE,
|
|
107
110
|
animationState: {
|
|
@@ -115,6 +118,13 @@ class AttributeAnimate extends vrender_1.ACustomAnimate {
|
|
|
115
118
|
type: vrender_1.AttributeUpdateType.ANIMATE_END
|
|
116
119
|
});
|
|
117
120
|
}
|
|
121
|
+
update(end, ratio, out) {
|
|
122
|
+
0 === this.updateCount && this.onFirstRun(), this.updateCount += 1;
|
|
123
|
+
const lastProps = this.step.getLastProps();
|
|
124
|
+
Object.keys(lastProps).forEach((key => {
|
|
125
|
+
this.subAnimate.animate.validAttr(key) && (out[key] = lastProps[key]);
|
|
126
|
+
})), this.onUpdate(end, ratio, out), end && this.onEnd();
|
|
127
|
+
}
|
|
118
128
|
onUpdate(end, ratio, out) {
|
|
119
129
|
this.target.stepInterpolate(this.subAnimate, this.subAnimate.animate, out, this.step, ratio, end, this._toAttribute, this._fromAttribute);
|
|
120
130
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/graph/animation/attribute.ts"],"names":[],"mappings":";;;AAEA,+CAAwE;AACxE,6CAAiF;AASjF,mDAA6D;AAC7D,gDAA6C;AAE7C,MAAM,4BAA4B,GAAG,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IH,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,EAAE,KAAK,EAAE;YACrC,IAAI,EAAE,6BAAmB,CAAC,cAAc;YACxC,cAAc,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE;SACzC,CAAC,CAAC;QAEH,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;QAC3B,IAAI,CAAC,YAAY,GAAG,EAAE,CAAC;IACzB,CAAC;IAED,KAAK;QACH,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,YAAY,EAAE,KAAK,EAAE;YAClD,IAAI,EAAE,6BAAmB,CAAC,WAAW;SACtC,CAAC,CAAC;IACL,CAAC;IAED,QAAQ,CAAC,GAAY,EAAE,KAAa,EAAE,GAAwB;QAC5D,IAAI,CAAC,MAAM,CAAC,eAAe,CACzB,IAAI,CAAC,UAAU,EACf,IAAI,CAAC,UAAU,CAAC,OAAO,EACvB,GAAG,EACH,IAAI,CAAC,IAAI,EACT,KAAK,EACL,GAAG,EACH,IAAI,CAAC,YAAY,EACjB,IAAI,CAAC,cAAc,CACpB,CAAC;IACJ,CAAC;CACF;AArDD,4CAqDC","file":"attribute.js","sourcesContent":["import type { EasingType, IGraphic } from '@visactor/vrender';\n// eslint-disable-next-line no-duplicate-imports\nimport { ACustomAnimate, AttributeUpdateType } from '@visactor/vrender';\nimport { isArray, isFunction, isNil, isObject, isValid } from '@visactor/vutils';\nimport type {\n IAnimationChannelInterpolator,\n IAnimationEffect,\n IAnimationParameters,\n IElement,\n IGlyphElement,\n IParsedAnimationAttrs\n} from '../../types';\nimport { isValidPointsChannel } from '../attributes/helpers';\nimport { Factory } from '../../core/factory';\n\nconst transformAnimationAttributes = (attributes: IParsedAnimationAttrs, element: IElement): IParsedAnimationAttrs => {\n if (!attributes) {\n return null;\n }\n\n if (attributes?.from) {\n const from = attributes.from;\n Object.keys(from).forEach(channel => {\n if (isNil(from[channel])) {\n delete from[channel];\n }\n });\n const computePoints = isValidPointsChannel(Object.keys(from), element.mark.markType) && !isValid(from.segments);\n if (computePoints) {\n const items = element.items.map(item => Object.assign({}, item, { nextAttrs: from }));\n attributes.from = element.transformElementItems(items, element.mark.markType, computePoints);\n }\n }\n if (attributes?.to) {\n const to = attributes.to;\n Object.keys(to).forEach(channel => {\n if (isNil(to[channel])) {\n delete to[channel];\n }\n });\n const computePoints = isValidPointsChannel(Object.keys(to), element.mark.markType) && !isValid(to.segments);\n if (computePoints) {\n const items = element.items.map(item => Object.assign({}, item, { nextAttrs: to }));\n attributes.to = element.transformElementItems(items, element.mark.markType, computePoints);\n }\n }\n\n return attributes;\n};\n\nexport function typeAnimationAttributes(\n element: IElement,\n effect: IAnimationEffect,\n animationParameters: IAnimationParameters,\n parameters: any\n): IParsedAnimationAttrs {\n // const parameters =\n const options = isFunction(effect.options)\n ? effect.options.call(null, element.getDatum(), element, parameters)\n : effect.options;\n if (!effect.type || !Factory.getAnimationType(effect.type)) {\n return null;\n }\n const attributes = Factory.getAnimationType(effect.type)(element as IGlyphElement, options, animationParameters);\n return transformAnimationAttributes(attributes, element);\n}\n\nconst parseChannelValue = (\n element: IElement,\n channel: string,\n channelValue: any,\n animationParameters: IAnimationParameters,\n parameters: any\n) => {\n return isFunction(channelValue) ? channelValue(element.getDatum(), element, parameters) : channelValue;\n};\n\nexport function channelAnimationAttributes(\n element: IElement,\n effect: IAnimationEffect,\n animationParameters: IAnimationParameters,\n parameters: any\n): IParsedAnimationAttrs {\n const channel = effect.channel;\n let attributes: IParsedAnimationAttrs = null;\n\n if (isArray(channel)) {\n attributes = channel.reduce(\n (res, key) => {\n res.from[key] = element.getGraphicAttribute(key, true);\n res.to[key] = element.getGraphicAttribute(key, false);\n return res;\n },\n { from: {}, to: {} }\n );\n } else if (isObject(channel)) {\n attributes = Object.keys(channel).reduce(\n (res, key) => {\n const hasFrom = !isNil(channel[key]?.from);\n const hasTo = !isNil(channel[key]?.to);\n\n if (hasFrom || hasTo) {\n res.from[key] = hasFrom\n ? parseChannelValue(element, key, channel[key].from, animationParameters, parameters)\n : undefined;\n res.to[key] = hasTo\n ? parseChannelValue(element, key, channel[key].to, animationParameters, parameters)\n : element.getGraphicAttribute(key, false);\n }\n\n return res;\n },\n { from: {}, to: {} }\n );\n }\n\n return transformAnimationAttributes(attributes, element);\n}\n\nexport class CustomInterpolator extends ACustomAnimate<any> {\n private _element: IElement;\n private _interpolator?: IAnimationChannelInterpolator;\n\n constructor(\n from: any,\n to: any,\n duration: number,\n easing: EasingType,\n params: { interpolator: IAnimationChannelInterpolator; element: IElement; parameters?: any }\n ) {\n super(from, to, duration, easing, params);\n this._interpolator = params?.interpolator;\n this._element = params?.element;\n }\n\n onBind() {\n this.from = this.from ?? {};\n this.to = this.to ?? {};\n }\n\n getEndProps(): void | Record<string, any> {\n return this.to;\n }\n\n onUpdate(end: boolean, ratio: number, out: Record<string, any>): void {\n if (!this._interpolator || !this._element) {\n return;\n }\n this._interpolator.call(\n this,\n ratio,\n this.from,\n this.to,\n out,\n this._element.getDatum(),\n this._element,\n this.params.parameters\n );\n }\n}\n\nexport class AttributeAnimate extends ACustomAnimate<any> {\n declare target: IGraphic;\n\n private _fromAttribute: any;\n private _toAttribute: any;\n\n getEndProps(): Record<string, any> {\n return this.to;\n }\n\n onBind() {\n this.from = this.from ?? {};\n this.to = this.to ?? {};\n }\n\n onStart(): void {\n const from = Object.assign({}, this.from);\n const to = Object.assign({}, this.to);\n Object.keys(to).forEach(k => {\n if (isNil(from[k])) {\n from[k] = this.target.getComputedAttribute(k);\n }\n // if (this.to[k] === from[k]) {\n // delete from[k];\n // }\n });\n this.target.setAttributes(from, false, {\n type: AttributeUpdateType.ANIMATE_UPDATE,\n animationState: { ratio: 0, end: false }\n });\n\n this._fromAttribute = from;\n this._toAttribute = to;\n }\n\n onEnd(): void {\n this.target.setAttributes(this._toAttribute, false, {\n type: AttributeUpdateType.ANIMATE_END\n });\n }\n\n onUpdate(end: boolean, ratio: number, out: Record<string, any>): void {\n this.target.stepInterpolate(\n this.subAnimate,\n this.subAnimate.animate,\n out,\n this.step,\n ratio,\n end,\n this._toAttribute,\n this._fromAttribute\n );\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/graph/animation/attribute.ts"],"names":[],"mappings":";;;AAEA,+CAA6F;AAC7F,6CAAiF;AASjF,mDAA6D;AAC7D,gDAA6C;AAE7C,MAAM,4BAA4B,GAAG,CAAC,UAAiC,EAAE,OAAiB,EAAyB,EAAE;IACnH,IAAI,CAAC,UAAU,EAAE;QACf,OAAO,IAAI,CAAC;KACb;IAED,IAAI,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,IAAI,EAAE;QACpB,MAAM,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC;QAC7B,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;YAClC,IAAI,IAAA,cAAK,EAAC,IAAI,CAAC,OAAO,CAAC,CAAC,EAAE;gBACxB,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;aACtB;QACH,CAAC,CAAC,CAAC;QACH,MAAM,aAAa,GAAG,IAAA,8BAAoB,EAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAA,gBAAO,EAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAChH,IAAI,aAAa,EAAE;YACjB,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;YACtF,UAAU,CAAC,IAAI,GAAG,OAAO,CAAC,qBAAqB,CAAC,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC;SAC9F;KACF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;YAClD,IAAI,EAAE,6BAAmB,CAAC,WAAW;SACtC,CAAC,CAAC;IACL,CAAC;IAED,MAAM,CAAC,GAAY,EAAE,KAAa,EAAE,GAAwB;QAC1D,IAAI,IAAI,CAAC,WAAW,KAAK,CAAC,EAAE;YAC1B,IAAI,CAAC,UAAU,EAAE,CAAC;SACnB;QACD,IAAI,CAAC,WAAW,IAAI,CAAC,CAAC;QAGtB,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC;QAC3C,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;YACnC,IAAI,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE;gBAC1C,GAAG,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;aAC3B;QACH,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;QAC/B,IAAI,GAAG,EAAE;YACP,IAAI,CAAC,KAAK,EAAE,CAAC;SACd;IACH,CAAC;IAED,QAAQ,CAAC,GAAY,EAAE,KAAa,EAAE,GAAwB;QAC5D,IAAI,CAAC,MAAM,CAAC,eAAe,CACzB,IAAI,CAAC,UAAU,EACf,IAAI,CAAC,UAAU,CAAC,OAAO,EACvB,GAAG,EACH,IAAI,CAAC,IAAI,EACT,KAAK,EACL,GAAG,EACH,IAAI,CAAC,YAAY,EACjB,IAAI,CAAC,cAAc,CACpB,CAAC;IACJ,CAAC;CACF;AAhFD,4CAgFC","file":"attribute.js","sourcesContent":["import type { EasingType, IGraphic } from '@visactor/vrender';\n// eslint-disable-next-line no-duplicate-imports\nimport { ACustomAnimate, AttributeUpdateType, NOWORK_ANIMATE_ATTR } from '@visactor/vrender';\nimport { isArray, isFunction, isNil, isObject, isValid } from '@visactor/vutils';\nimport type {\n IAnimationChannelInterpolator,\n IAnimationEffect,\n IAnimationParameters,\n IElement,\n IGlyphElement,\n IParsedAnimationAttrs\n} from '../../types';\nimport { isValidPointsChannel } from '../attributes/helpers';\nimport { Factory } from '../../core/factory';\n\nconst transformAnimationAttributes = (attributes: IParsedAnimationAttrs, element: IElement): IParsedAnimationAttrs => {\n if (!attributes) {\n return null;\n }\n\n if (attributes?.from) {\n const from = attributes.from;\n Object.keys(from).forEach(channel => {\n if (isNil(from[channel])) {\n delete from[channel];\n }\n });\n const computePoints = isValidPointsChannel(Object.keys(from), element.mark.markType) && !isValid(from.segments);\n if (computePoints) {\n const items = element.items.map(item => Object.assign({}, item, { nextAttrs: from }));\n attributes.from = element.transformElementItems(items, element.mark.markType, computePoints);\n }\n }\n if (attributes?.to) {\n const to = attributes.to;\n Object.keys(to).forEach(channel => {\n if (isNil(to[channel])) {\n delete to[channel];\n }\n });\n const computePoints = isValidPointsChannel(Object.keys(to), element.mark.markType) && !isValid(to.segments);\n if (computePoints) {\n const items = element.items.map(item => Object.assign({}, item, { nextAttrs: to }));\n attributes.to = element.transformElementItems(items, element.mark.markType, computePoints);\n }\n }\n\n return attributes;\n};\n\nexport function typeAnimationAttributes(\n element: IElement,\n effect: IAnimationEffect,\n animationParameters: IAnimationParameters,\n parameters: any\n): IParsedAnimationAttrs {\n // const parameters =\n const options = isFunction(effect.options)\n ? effect.options.call(null, element.getDatum(), element, parameters)\n : effect.options;\n if (!effect.type || !Factory.getAnimationType(effect.type)) {\n return null;\n }\n const attributes = Factory.getAnimationType(effect.type)(element as IGlyphElement, options, animationParameters);\n return transformAnimationAttributes(attributes, element);\n}\n\nconst parseChannelValue = (\n element: IElement,\n channel: string,\n channelValue: any,\n animationParameters: IAnimationParameters,\n parameters: any\n) => {\n return isFunction(channelValue) ? channelValue(element.getDatum(), element, parameters) : channelValue;\n};\n\nexport function channelAnimationAttributes(\n element: IElement,\n effect: IAnimationEffect,\n animationParameters: IAnimationParameters,\n parameters: any\n): IParsedAnimationAttrs {\n const channel = effect.channel;\n let attributes: IParsedAnimationAttrs = null;\n\n if (isArray(channel)) {\n attributes = channel.reduce(\n (res, key) => {\n res.from[key] = element.getGraphicAttribute(key, true);\n res.to[key] = element.getGraphicAttribute(key, false);\n return res;\n },\n { from: {}, to: {} }\n );\n } else if (isObject(channel)) {\n attributes = Object.keys(channel).reduce(\n (res, key) => {\n const hasFrom = !isNil(channel[key]?.from);\n const hasTo = !isNil(channel[key]?.to);\n\n if (hasFrom || hasTo) {\n res.from[key] = hasFrom\n ? parseChannelValue(element, key, channel[key].from, animationParameters, parameters)\n : undefined;\n res.to[key] = hasTo\n ? parseChannelValue(element, key, channel[key].to, animationParameters, parameters)\n : element.getGraphicAttribute(key, false);\n }\n\n return res;\n },\n { from: {}, to: {} }\n );\n }\n\n return transformAnimationAttributes(attributes, element);\n}\n\nexport class CustomInterpolator extends ACustomAnimate<any> {\n private _element: IElement;\n private _interpolator?: IAnimationChannelInterpolator;\n\n constructor(\n from: any,\n to: any,\n duration: number,\n easing: EasingType,\n params: { interpolator: IAnimationChannelInterpolator; element: IElement; parameters?: any }\n ) {\n super(from, to, duration, easing, params);\n this._interpolator = params?.interpolator;\n this._element = params?.element;\n }\n\n onBind() {\n this.from = this.from ?? {};\n this.to = this.to ?? {};\n }\n\n getEndProps(): void | Record<string, any> {\n return this.to;\n }\n\n onUpdate(end: boolean, ratio: number, out: Record<string, any>): void {\n if (!this._interpolator || !this._element) {\n return;\n }\n this._interpolator.call(\n this,\n ratio,\n this.from,\n this.to,\n out,\n this._element.getDatum(),\n this._element,\n this.params.parameters\n );\n }\n}\n\nexport class AttributeAnimate extends ACustomAnimate<any> {\n declare target: IGraphic;\n\n private _fromAttribute: any;\n private _toAttribute: any;\n\n getEndProps(): Record<string, any> {\n return this.to;\n }\n\n onBind() {\n this.from = this.from ?? {};\n this.to = this.to ?? {};\n }\n\n onStart(): void {\n const excludedChannelMap = (this.target.constructor as any).NOWORK_ANIMATE_ATTR ?? NOWORK_ANIMATE_ATTR;\n const excludedChannels = Object.keys(excludedChannelMap).filter(channel => excludedChannelMap[channel] !== 0);\n this.subAnimate.animate.preventAttrs(excludedChannels);\n\n const from = Object.assign({}, this.from);\n const to = Object.assign({}, this.to);\n Object.keys(to).forEach(k => {\n if (excludedChannels.includes(k)) {\n from[k] = to[k];\n this.from[k] = to[k];\n } else if (isNil(from[k])) {\n from[k] = this.target.getComputedAttribute(k);\n }\n // if (this.to[k] === from[k]) {\n // delete from[k];\n // }\n });\n\n this.target.setAttributes(from, false, {\n type: AttributeUpdateType.ANIMATE_UPDATE,\n animationState: { ratio: 0, end: false }\n });\n\n this._fromAttribute = from;\n this._toAttribute = to;\n }\n\n onEnd(): void {\n this.target.setAttributes(this._toAttribute, false, {\n type: AttributeUpdateType.ANIMATE_END\n });\n }\n\n update(end: boolean, ratio: number, out: Record<string, any>): void {\n if (this.updateCount === 0) {\n this.onFirstRun();\n }\n this.updateCount += 1;\n\n // Hack: waiting for canopus to remove invalid key when updating\n const lastProps = this.step.getLastProps();\n Object.keys(lastProps).forEach(key => {\n if (this.subAnimate.animate.validAttr(key)) {\n out[key] = lastProps[key];\n }\n });\n this.onUpdate(end, ratio, out);\n if (end) {\n this.onEnd();\n }\n }\n\n onUpdate(end: boolean, ratio: number, out: Record<string, any>): void {\n this.target.stepInterpolate(\n this.subAnimate,\n this.subAnimate.animate,\n out,\n this.step,\n ratio,\n end,\n this._toAttribute,\n this._fromAttribute\n );\n }\n}\n"]}
|
package/cjs/index.d.ts
CHANGED
package/cjs/index.js
CHANGED
|
@@ -18,7 +18,7 @@ var __createBinding = this && this.__createBinding || (Object.create ? function(
|
|
|
18
18
|
Object.defineProperty(exports, "__esModule", {
|
|
19
19
|
value: !0
|
|
20
20
|
}), exports.ThemeManager = exports.SIGNAL_VIEW_BOX = exports.SIGNAL_WIDTH = exports.SIGNAL_VIEW_WIDTH = exports.SIGNAL_VIEW_HEIGHT = exports.SIGNAL_PADDING = exports.SIGNAL_HEIGHT = exports.SIGNAL_AUTOFIT = exports.Factory = exports.GrammarBase = exports.invokeFunctionType = exports.parseFunctionType = exports.View = exports.version = void 0,
|
|
21
|
-
exports.version = "0.7.
|
|
21
|
+
exports.version = "0.7.4-alpha.0", __exportStar(require("./graph"), exports);
|
|
22
22
|
|
|
23
23
|
var view_1 = require("./view");
|
|
24
24
|
|
package/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AACa,QAAA,OAAO,GAAG,
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AACa,QAAA,OAAO,GAAG,eAAe,CAAC;AAEvC,0CAAwB;AAExB,+BAA8B;AAArB,4FAAA,IAAI,OAAA;AACb,qCAAqE;AAA5D,yGAAA,iBAAiB,OAAA;AAAE,0GAAA,kBAAkB,OAAA;AAC9C,oDAAkD;AAAzC,2GAAA,WAAW,OAAA;AACpB,8CAA4B;AAC5B,0CAAwB;AACxB,0CAAyC;AAAhC,kGAAA,OAAO,OAAA;AAChB,8CAQ0B;AAPxB,2GAAA,cAAc,OAAA;AACd,0GAAA,aAAa,OAAA;AACb,2GAAA,cAAc,OAAA;AACd,+GAAA,kBAAkB,OAAA;AAClB,8GAAA,iBAAiB,OAAA;AACjB,yGAAA,YAAY,OAAA;AACZ,4GAAA,eAAe,OAAA;AAGjB,uDAAqD;AAA5C,6GAAA,YAAY,OAAA;AAErB,0CAAwB;AACxB,8CAA4B;AAC5B,+CAA6B;AAC7B,8DAA4C","file":"index.js","sourcesContent":["// -- Exports -----\nexport const version = \"0.7.4-alpha.0\";\n\nexport * from './graph';\n\nexport { View } from './view';\nexport { parseFunctionType, invokeFunctionType } from './parse/util';\nexport { GrammarBase } from './view/grammar-base';\nexport * from './util/text';\nexport * from './types';\nexport { Factory } from './core/factory';\nexport {\n SIGNAL_AUTOFIT,\n SIGNAL_HEIGHT,\n SIGNAL_PADDING,\n SIGNAL_VIEW_HEIGHT,\n SIGNAL_VIEW_WIDTH,\n SIGNAL_WIDTH,\n SIGNAL_VIEW_BOX\n} from './view/constants';\n\nexport { ThemeManager } from './theme/theme-manager';\n\nexport * from './glyph';\nexport * from './component';\nexport * from './transforms';\nexport * from './graph/animation/animation';\n"]}
|
|
@@ -2,13 +2,9 @@ import { array } from "@visactor/vutils";
|
|
|
2
2
|
|
|
3
3
|
import { isEqual } from "@visactor/vgrammar-util";
|
|
4
4
|
|
|
5
|
-
const defaultExcludedChannels = [ "visible", "path", "text", "lineWidth", "textBaseline", "textAlign" ];
|
|
6
|
-
|
|
7
5
|
export const update = (element, options, animationParameters) => {
|
|
8
6
|
const from = Object.assign({}, element.getPrevGraphicAttributes()), to = Object.assign({}, element.getNextGraphicAttributes());
|
|
9
|
-
return
|
|
10
|
-
delete from[key], delete to[key];
|
|
11
|
-
})), array(null == options ? void 0 : options.excludeChannels).forEach((key => {
|
|
7
|
+
return array(null == options ? void 0 : options.excludeChannels).forEach((key => {
|
|
12
8
|
delete from[key], delete to[key];
|
|
13
9
|
})), Object.keys(to).forEach((key => {
|
|
14
10
|
isEqual(key, from, to) && (delete from[key], delete to[key]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/graph/animation/animation/update.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"sources":["../src/graph/animation/animation/update.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAQlD,MAAM,CAAC,MAAM,MAAM,GAA4B,CAC7C,OAAiB,EACjB,OAAgC,EAChC,mBAAyC,EACzC,EAAE;IACF,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,OAAO,CAAC,wBAAwB,EAAE,CAAC,CAAC;IACnE,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,OAAO,CAAC,wBAAwB,EAAE,CAAC,CAAC;IACjE,KAAK,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,eAAe,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;QAC5C,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;QACjB,OAAO,EAAE,CAAC,GAAG,CAAC,CAAC;IACjB,CAAC,CAAC,CAAC;IACH,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;QAC5B,IAAI,OAAO,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC,EAAE;YAC1B,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;YACjB,OAAO,EAAE,CAAC,GAAG,CAAC,CAAC;SAChB;IACH,CAAC,CAAC,CAAC;IACH,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;AACtB,CAAC,CAAC","file":"update.js","sourcesContent":["import { array } from '@visactor/vutils';\nimport { isEqual } from '@visactor/vgrammar-util';\nimport type { IElement } from '../../../types';\nimport type { IAnimationParameters, TypeAnimation } from '../../../types/animate';\n\nexport interface IUpdateAnimationOptions {\n excludeChannels: string[];\n}\n\nexport const update: TypeAnimation<IElement> = (\n element: IElement,\n options: IUpdateAnimationOptions,\n animationParameters: IAnimationParameters\n) => {\n const from = Object.assign({}, element.getPrevGraphicAttributes());\n const to = Object.assign({}, element.getNextGraphicAttributes());\n array(options?.excludeChannels).forEach(key => {\n delete from[key];\n delete to[key];\n });\n Object.keys(to).forEach(key => {\n if (isEqual(key, from, to)) {\n delete from[key];\n delete to[key];\n }\n });\n return { from, to };\n};\n"]}
|
|
@@ -23,5 +23,6 @@ export declare class AttributeAnimate extends ACustomAnimate<any> {
|
|
|
23
23
|
onBind(): void;
|
|
24
24
|
onStart(): void;
|
|
25
25
|
onEnd(): void;
|
|
26
|
+
update(end: boolean, ratio: number, out: Record<string, any>): void;
|
|
26
27
|
onUpdate(end: boolean, ratio: number, out: Record<string, any>): void;
|
|
27
28
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ACustomAnimate, AttributeUpdateType } from "@visactor/vrender";
|
|
1
|
+
import { ACustomAnimate, AttributeUpdateType, NOWORK_ANIMATE_ATTR } from "@visactor/vrender";
|
|
2
2
|
|
|
3
3
|
import { isArray, isFunction, isNil, isObject, isValid } from "@visactor/vutils";
|
|
4
4
|
|
|
@@ -91,9 +91,12 @@ export class AttributeAnimate extends ACustomAnimate {
|
|
|
91
91
|
this.from = null !== (_a = this.from) && void 0 !== _a ? _a : {}, this.to = null !== (_b = this.to) && void 0 !== _b ? _b : {};
|
|
92
92
|
}
|
|
93
93
|
onStart() {
|
|
94
|
+
var _a;
|
|
95
|
+
const excludedChannelMap = null !== (_a = this.target.constructor.NOWORK_ANIMATE_ATTR) && void 0 !== _a ? _a : NOWORK_ANIMATE_ATTR, excludedChannels = Object.keys(excludedChannelMap).filter((channel => 0 !== excludedChannelMap[channel]));
|
|
96
|
+
this.subAnimate.animate.preventAttrs(excludedChannels);
|
|
94
97
|
const from = Object.assign({}, this.from), to = Object.assign({}, this.to);
|
|
95
98
|
Object.keys(to).forEach((k => {
|
|
96
|
-
isNil(from[k]) && (from[k] = this.target.getComputedAttribute(k));
|
|
99
|
+
excludedChannels.includes(k) ? (from[k] = to[k], this.from[k] = to[k]) : isNil(from[k]) && (from[k] = this.target.getComputedAttribute(k));
|
|
97
100
|
})), this.target.setAttributes(from, !1, {
|
|
98
101
|
type: AttributeUpdateType.ANIMATE_UPDATE,
|
|
99
102
|
animationState: {
|
|
@@ -107,6 +110,13 @@ export class AttributeAnimate extends ACustomAnimate {
|
|
|
107
110
|
type: AttributeUpdateType.ANIMATE_END
|
|
108
111
|
});
|
|
109
112
|
}
|
|
113
|
+
update(end, ratio, out) {
|
|
114
|
+
0 === this.updateCount && this.onFirstRun(), this.updateCount += 1;
|
|
115
|
+
const lastProps = this.step.getLastProps();
|
|
116
|
+
Object.keys(lastProps).forEach((key => {
|
|
117
|
+
this.subAnimate.animate.validAttr(key) && (out[key] = lastProps[key]);
|
|
118
|
+
})), this.onUpdate(end, ratio, out), end && this.onEnd();
|
|
119
|
+
}
|
|
110
120
|
onUpdate(end, ratio, out) {
|
|
111
121
|
this.target.stepInterpolate(this.subAnimate, this.subAnimate.animate, out, this.step, ratio, end, this._toAttribute, this._fromAttribute);
|
|
112
122
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/graph/animation/attribute.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AASjF,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7C,MAAM,4BAA4B,GAAG,CAAC,UAAiC,EAAE,OAAiB,EAAyB,EAAE;IACnH,IAAI,CAAC,UAAU,EAAE;QACf,OAAO,IAAI,CAAC;KACb;IAED,IAAI,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,IAAI,EAAE;QACpB,MAAM,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC;QAC7B,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;YAClC,IAAI,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,EAAE;gBACxB,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;aACtB;QACH,CAAC,CAAC,CAAC;QACH,MAAM,aAAa,GAAG,oBAAoB,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,OAAO,CAA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GAAG,EACH,IAAI,CAAC,IAAI,EACT,KAAK,EACL,GAAG,EACH,IAAI,CAAC,YAAY,EACjB,IAAI,CAAC,cAAc,CACpB,CAAC;IACJ,CAAC;CACF","file":"attribute.js","sourcesContent":["import type { EasingType, IGraphic } from '@visactor/vrender';\n// eslint-disable-next-line no-duplicate-imports\nimport { ACustomAnimate, AttributeUpdateType } from '@visactor/vrender';\nimport { isArray, isFunction, isNil, isObject, isValid } from '@visactor/vutils';\nimport type {\n IAnimationChannelInterpolator,\n IAnimationEffect,\n IAnimationParameters,\n IElement,\n IGlyphElement,\n IParsedAnimationAttrs\n} from '../../types';\nimport { isValidPointsChannel } from '../attributes/helpers';\nimport { Factory } from '../../core/factory';\n\nconst transformAnimationAttributes = (attributes: IParsedAnimationAttrs, element: IElement): IParsedAnimationAttrs => {\n if (!attributes) {\n return null;\n }\n\n if (attributes?.from) {\n const from = attributes.from;\n Object.keys(from).forEach(channel => {\n if (isNil(from[channel])) {\n delete from[channel];\n }\n });\n const computePoints = isValidPointsChannel(Object.keys(from), element.mark.markType) && !isValid(from.segments);\n if (computePoints) {\n const items = element.items.map(item => Object.assign({}, item, { nextAttrs: from }));\n attributes.from = element.transformElementItems(items, element.mark.markType, computePoints);\n }\n }\n if (attributes?.to) {\n const to = attributes.to;\n Object.keys(to).forEach(channel => {\n if (isNil(to[channel])) {\n delete to[channel];\n }\n });\n const computePoints = isValidPointsChannel(Object.keys(to), element.mark.markType) && !isValid(to.segments);\n if (computePoints) {\n const items = element.items.map(item => Object.assign({}, item, { nextAttrs: to }));\n attributes.to = element.transformElementItems(items, element.mark.markType, computePoints);\n }\n }\n\n return attributes;\n};\n\nexport function typeAnimationAttributes(\n element: IElement,\n effect: IAnimationEffect,\n animationParameters: IAnimationParameters,\n parameters: any\n): IParsedAnimationAttrs {\n // const parameters =\n const options = isFunction(effect.options)\n ? effect.options.call(null, element.getDatum(), element, parameters)\n : effect.options;\n if (!effect.type || !Factory.getAnimationType(effect.type)) {\n return null;\n }\n const attributes = Factory.getAnimationType(effect.type)(element as IGlyphElement, options, animationParameters);\n return transformAnimationAttributes(attributes, element);\n}\n\nconst parseChannelValue = (\n element: IElement,\n channel: string,\n channelValue: any,\n animationParameters: IAnimationParameters,\n parameters: any\n) => {\n return isFunction(channelValue) ? channelValue(element.getDatum(), element, parameters) : channelValue;\n};\n\nexport function channelAnimationAttributes(\n element: IElement,\n effect: IAnimationEffect,\n animationParameters: IAnimationParameters,\n parameters: any\n): IParsedAnimationAttrs {\n const channel = effect.channel;\n let attributes: IParsedAnimationAttrs = null;\n\n if (isArray(channel)) {\n attributes = channel.reduce(\n (res, key) => {\n res.from[key] = element.getGraphicAttribute(key, true);\n res.to[key] = element.getGraphicAttribute(key, false);\n return res;\n },\n { from: {}, to: {} }\n );\n } else if (isObject(channel)) {\n attributes = Object.keys(channel).reduce(\n (res, key) => {\n const hasFrom = !isNil(channel[key]?.from);\n const hasTo = !isNil(channel[key]?.to);\n\n if (hasFrom || hasTo) {\n res.from[key] = hasFrom\n ? parseChannelValue(element, key, channel[key].from, animationParameters, parameters)\n : undefined;\n res.to[key] = hasTo\n ? parseChannelValue(element, key, channel[key].to, animationParameters, parameters)\n : element.getGraphicAttribute(key, false);\n }\n\n return res;\n },\n { from: {}, to: {} }\n );\n }\n\n return transformAnimationAttributes(attributes, element);\n}\n\nexport class CustomInterpolator extends ACustomAnimate<any> {\n private _element: IElement;\n private _interpolator?: IAnimationChannelInterpolator;\n\n constructor(\n from: any,\n to: any,\n duration: number,\n easing: EasingType,\n params: { interpolator: IAnimationChannelInterpolator; element: IElement; parameters?: any }\n ) {\n super(from, to, duration, easing, params);\n this._interpolator = params?.interpolator;\n this._element = params?.element;\n }\n\n onBind() {\n this.from = this.from ?? {};\n this.to = this.to ?? {};\n }\n\n getEndProps(): void | Record<string, any> {\n return this.to;\n }\n\n onUpdate(end: boolean, ratio: number, out: Record<string, any>): void {\n if (!this._interpolator || !this._element) {\n return;\n }\n this._interpolator.call(\n this,\n ratio,\n this.from,\n this.to,\n out,\n this._element.getDatum(),\n this._element,\n this.params.parameters\n );\n }\n}\n\nexport class AttributeAnimate extends ACustomAnimate<any> {\n declare target: IGraphic;\n\n private _fromAttribute: any;\n private _toAttribute: any;\n\n getEndProps(): Record<string, any> {\n return this.to;\n }\n\n onBind() {\n this.from = this.from ?? {};\n this.to = this.to ?? {};\n }\n\n onStart(): void {\n const from = Object.assign({}, this.from);\n const to = Object.assign({}, this.to);\n Object.keys(to).forEach(k => {\n if (isNil(from[k])) {\n from[k] = this.target.getComputedAttribute(k);\n }\n // if (this.to[k] === from[k]) {\n // delete from[k];\n // }\n });\n this.target.setAttributes(from, false, {\n type: AttributeUpdateType.ANIMATE_UPDATE,\n animationState: { ratio: 0, end: false }\n });\n\n this._fromAttribute = from;\n this._toAttribute = to;\n }\n\n onEnd(): void {\n this.target.setAttributes(this._toAttribute, false, {\n type: AttributeUpdateType.ANIMATE_END\n });\n }\n\n onUpdate(end: boolean, ratio: number, out: Record<string, any>): void {\n this.target.stepInterpolate(\n this.subAnimate,\n this.subAnimate.animate,\n out,\n this.step,\n ratio,\n end,\n this._toAttribute,\n this._fromAttribute\n );\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/graph/animation/attribute.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAC7F,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AASjF,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7C,MAAM,4BAA4B,GAAG,CAAC,UAAiC,EAAE,OAAiB,EAAyB,EAAE;IACnH,IAAI,CAAC,UAAU,EAAE;QACf,OAAO,IAAI,CAAC;KACb;IAED,IAAI,UAAU,aAAV,UAAU,u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,GAAG,CAAC,CAAC;aAC3B;QACH,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;QAC/B,IAAI,GAAG,EAAE;YACP,IAAI,CAAC,KAAK,EAAE,CAAC;SACd;IACH,CAAC;IAED,QAAQ,CAAC,GAAY,EAAE,KAAa,EAAE,GAAwB;QAC5D,IAAI,CAAC,MAAM,CAAC,eAAe,CACzB,IAAI,CAAC,UAAU,EACf,IAAI,CAAC,UAAU,CAAC,OAAO,EACvB,GAAG,EACH,IAAI,CAAC,IAAI,EACT,KAAK,EACL,GAAG,EACH,IAAI,CAAC,YAAY,EACjB,IAAI,CAAC,cAAc,CACpB,CAAC;IACJ,CAAC;CACF","file":"attribute.js","sourcesContent":["import type { EasingType, IGraphic } from '@visactor/vrender';\n// eslint-disable-next-line no-duplicate-imports\nimport { ACustomAnimate, AttributeUpdateType, NOWORK_ANIMATE_ATTR } from '@visactor/vrender';\nimport { isArray, isFunction, isNil, isObject, isValid } from '@visactor/vutils';\nimport type {\n IAnimationChannelInterpolator,\n IAnimationEffect,\n IAnimationParameters,\n IElement,\n IGlyphElement,\n IParsedAnimationAttrs\n} from '../../types';\nimport { isValidPointsChannel } from '../attributes/helpers';\nimport { Factory } from '../../core/factory';\n\nconst transformAnimationAttributes = (attributes: IParsedAnimationAttrs, element: IElement): IParsedAnimationAttrs => {\n if (!attributes) {\n return null;\n }\n\n if (attributes?.from) {\n const from = attributes.from;\n Object.keys(from).forEach(channel => {\n if (isNil(from[channel])) {\n delete from[channel];\n }\n });\n const computePoints = isValidPointsChannel(Object.keys(from), element.mark.markType) && !isValid(from.segments);\n if (computePoints) {\n const items = element.items.map(item => Object.assign({}, item, { nextAttrs: from }));\n attributes.from = element.transformElementItems(items, element.mark.markType, computePoints);\n }\n }\n if (attributes?.to) {\n const to = attributes.to;\n Object.keys(to).forEach(channel => {\n if (isNil(to[channel])) {\n delete to[channel];\n }\n });\n const computePoints = isValidPointsChannel(Object.keys(to), element.mark.markType) && !isValid(to.segments);\n if (computePoints) {\n const items = element.items.map(item => Object.assign({}, item, { nextAttrs: to }));\n attributes.to = element.transformElementItems(items, element.mark.markType, computePoints);\n }\n }\n\n return attributes;\n};\n\nexport function typeAnimationAttributes(\n element: IElement,\n effect: IAnimationEffect,\n animationParameters: IAnimationParameters,\n parameters: any\n): IParsedAnimationAttrs {\n // const parameters =\n const options = isFunction(effect.options)\n ? effect.options.call(null, element.getDatum(), element, parameters)\n : effect.options;\n if (!effect.type || !Factory.getAnimationType(effect.type)) {\n return null;\n }\n const attributes = Factory.getAnimationType(effect.type)(element as IGlyphElement, options, animationParameters);\n return transformAnimationAttributes(attributes, element);\n}\n\nconst parseChannelValue = (\n element: IElement,\n channel: string,\n channelValue: any,\n animationParameters: IAnimationParameters,\n parameters: any\n) => {\n return isFunction(channelValue) ? channelValue(element.getDatum(), element, parameters) : channelValue;\n};\n\nexport function channelAnimationAttributes(\n element: IElement,\n effect: IAnimationEffect,\n animationParameters: IAnimationParameters,\n parameters: any\n): IParsedAnimationAttrs {\n const channel = effect.channel;\n let attributes: IParsedAnimationAttrs = null;\n\n if (isArray(channel)) {\n attributes = channel.reduce(\n (res, key) => {\n res.from[key] = element.getGraphicAttribute(key, true);\n res.to[key] = element.getGraphicAttribute(key, false);\n return res;\n },\n { from: {}, to: {} }\n );\n } else if (isObject(channel)) {\n attributes = Object.keys(channel).reduce(\n (res, key) => {\n const hasFrom = !isNil(channel[key]?.from);\n const hasTo = !isNil(channel[key]?.to);\n\n if (hasFrom || hasTo) {\n res.from[key] = hasFrom\n ? parseChannelValue(element, key, channel[key].from, animationParameters, parameters)\n : undefined;\n res.to[key] = hasTo\n ? parseChannelValue(element, key, channel[key].to, animationParameters, parameters)\n : element.getGraphicAttribute(key, false);\n }\n\n return res;\n },\n { from: {}, to: {} }\n );\n }\n\n return transformAnimationAttributes(attributes, element);\n}\n\nexport class CustomInterpolator extends ACustomAnimate<any> {\n private _element: IElement;\n private _interpolator?: IAnimationChannelInterpolator;\n\n constructor(\n from: any,\n to: any,\n duration: number,\n easing: EasingType,\n params: { interpolator: IAnimationChannelInterpolator; element: IElement; parameters?: any }\n ) {\n super(from, to, duration, easing, params);\n this._interpolator = params?.interpolator;\n this._element = params?.element;\n }\n\n onBind() {\n this.from = this.from ?? {};\n this.to = this.to ?? {};\n }\n\n getEndProps(): void | Record<string, any> {\n return this.to;\n }\n\n onUpdate(end: boolean, ratio: number, out: Record<string, any>): void {\n if (!this._interpolator || !this._element) {\n return;\n }\n this._interpolator.call(\n this,\n ratio,\n this.from,\n this.to,\n out,\n this._element.getDatum(),\n this._element,\n this.params.parameters\n );\n }\n}\n\nexport class AttributeAnimate extends ACustomAnimate<any> {\n declare target: IGraphic;\n\n private _fromAttribute: any;\n private _toAttribute: any;\n\n getEndProps(): Record<string, any> {\n return this.to;\n }\n\n onBind() {\n this.from = this.from ?? {};\n this.to = this.to ?? {};\n }\n\n onStart(): void {\n const excludedChannelMap = (this.target.constructor as any).NOWORK_ANIMATE_ATTR ?? NOWORK_ANIMATE_ATTR;\n const excludedChannels = Object.keys(excludedChannelMap).filter(channel => excludedChannelMap[channel] !== 0);\n this.subAnimate.animate.preventAttrs(excludedChannels);\n\n const from = Object.assign({}, this.from);\n const to = Object.assign({}, this.to);\n Object.keys(to).forEach(k => {\n if (excludedChannels.includes(k)) {\n from[k] = to[k];\n this.from[k] = to[k];\n } else if (isNil(from[k])) {\n from[k] = this.target.getComputedAttribute(k);\n }\n // if (this.to[k] === from[k]) {\n // delete from[k];\n // }\n });\n\n this.target.setAttributes(from, false, {\n type: AttributeUpdateType.ANIMATE_UPDATE,\n animationState: { ratio: 0, end: false }\n });\n\n this._fromAttribute = from;\n this._toAttribute = to;\n }\n\n onEnd(): void {\n this.target.setAttributes(this._toAttribute, false, {\n type: AttributeUpdateType.ANIMATE_END\n });\n }\n\n update(end: boolean, ratio: number, out: Record<string, any>): void {\n if (this.updateCount === 0) {\n this.onFirstRun();\n }\n this.updateCount += 1;\n\n // Hack: waiting for canopus to remove invalid key when updating\n const lastProps = this.step.getLastProps();\n Object.keys(lastProps).forEach(key => {\n if (this.subAnimate.animate.validAttr(key)) {\n out[key] = lastProps[key];\n }\n });\n this.onUpdate(end, ratio, out);\n if (end) {\n this.onEnd();\n }\n }\n\n onUpdate(end: boolean, ratio: number, out: Record<string, any>): void {\n this.target.stepInterpolate(\n this.subAnimate,\n this.subAnimate.animate,\n out,\n this.step,\n ratio,\n end,\n this._toAttribute,\n this._fromAttribute\n );\n }\n}\n"]}
|
package/es/index.d.ts
CHANGED
package/es/index.js
CHANGED
package/es/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,MAAM,OAAO,GAAG,
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,MAAM,OAAO,GAAG,eAAe,CAAC;AAEvC,cAAc,SAAS,CAAC;AAExB,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACrE,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzC,OAAO,EACL,cAAc,EACd,aAAa,EACb,cAAc,EACd,kBAAkB,EAClB,iBAAiB,EACjB,YAAY,EACZ,eAAe,EAChB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,6BAA6B,CAAC","file":"index.js","sourcesContent":["// -- Exports -----\nexport const version = \"0.7.4-alpha.0\";\n\nexport * from './graph';\n\nexport { View } from './view';\nexport { parseFunctionType, invokeFunctionType } from './parse/util';\nexport { GrammarBase } from './view/grammar-base';\nexport * from './util/text';\nexport * from './types';\nexport { Factory } from './core/factory';\nexport {\n SIGNAL_AUTOFIT,\n SIGNAL_HEIGHT,\n SIGNAL_PADDING,\n SIGNAL_VIEW_HEIGHT,\n SIGNAL_VIEW_WIDTH,\n SIGNAL_WIDTH,\n SIGNAL_VIEW_BOX\n} from './view/constants';\n\nexport { ThemeManager } from './theme/theme-manager';\n\nexport * from './glyph';\nexport * from './component';\nexport * from './transforms';\nexport * from './graph/animation/animation';\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@visactor/vgrammar-core",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.4-alpha.0",
|
|
4
4
|
"description": "VGrammar is a visual grammar library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"grammar",
|
|
@@ -24,13 +24,13 @@
|
|
|
24
24
|
"dist"
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@visactor/vgrammar-coordinate": "0.7.
|
|
28
|
-
"@visactor/vgrammar-util": "0.7.
|
|
29
|
-
"@visactor/vscale": "~0.
|
|
30
|
-
"@visactor/vrender": "~0.15.
|
|
31
|
-
"@visactor/vrender-components": "~0.15.
|
|
32
|
-
"@visactor/vutils": "~0.
|
|
33
|
-
"@visactor/vdataset": "~0.
|
|
27
|
+
"@visactor/vgrammar-coordinate": "0.7.4-alpha.0",
|
|
28
|
+
"@visactor/vgrammar-util": "0.7.4-alpha.0",
|
|
29
|
+
"@visactor/vscale": "~0.16.0",
|
|
30
|
+
"@visactor/vrender": "~0.15.2",
|
|
31
|
+
"@visactor/vrender-components": "~0.15.2",
|
|
32
|
+
"@visactor/vutils": "~0.16.0",
|
|
33
|
+
"@visactor/vdataset": "~0.16.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@rushstack/eslint-patch": "~1.1.4",
|