-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathliquid-chart.js
313 lines (302 loc) · 9.13 KB
/
liquid-chart.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
/**
* Datart
*
* Copyright 2021
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
function LiquidChart({ dHelper }) {
const svgIcon = `<svg t="1648655744871" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="6036" width="200" height="200"><path d="M116.382296 637.714099a542.627177 542.627177 0 0 1 99.353117-257.120286c25.351043-41.021105 54.722154-84.25735 87.456996-128.642186q59.644687-80.647493 125.278454-158.095339 25.925338-30.765829 52.917226-60.711235l4.266195-4.676406L511.661664 0l26.171466 28.468647 4.184152 4.676406 11.732036 12.962669q20.920764 23.710199 41.021105 47.748566 65.633768 77.037635 125.44254 158.095339c32.816884 44.384836 62.023911 87.539038 87.292911 128.642186a542.873304 542.873304 0 0 1 99.271074 257.120286 390.602962 390.602962 0 0 1-395.443452 385.598387 390.602962 390.602962 0 0 1-395.279368-385.598387M482.372595 135.369647q-64.157008 75.314749-122.571061 154.567523a1830.689876 1830.689876 0 0 0-84.421435 124.129864A496.109244 496.109244 0 0 0 185.707964 637.714099a326.117785 326.117785 0 0 0 652.071486 0A497.093751 497.093751 0 0 0 748.107314 414.067034c-24.612663-39.544345-52.753141-81.139746-84.339392-124.129864q-58.578138-79.252775-122.571062-154.567523c-9.763023-11.485909-19.608088-22.807734-29.535196-34.12956a3579.501626 3579.501626 0 0 0-29.289069 34.12956" p-id="6037"></path><path d="M511.743707 908.453392a269.918871 269.918871 0 0 1-275.825911-263.765705c0-145.624923 143.327741-71.868976 275.825911 0s275.82591-145.624923 275.82591 0a270.000913 270.000913 0 0 1-275.82591 263.765705" p-id="6038"></path></svg>`;
return {
config: {
datas: [
{
label: 'metrics',
key: 'metrics',
required: true,
type: 'aggregate',
limit: 1,
actions: {
NUMERIC: ['aggregate', 'format'],
STRING: ['aggregate', 'format'],
},
},
{
label: 'filter',
key: 'filter',
type: 'filter',
allowSameField: true,
},
],
styles: [
{
label: '边框',
key: 'outline',
comType: 'group',
rows: [
{
label: '边框类型',
key: 'type',
default: 'circle',
comType: 'select',
options: {
items: [
{ label: '圆形', value: 'circle' },
{ label: '矩形', value: 'rect' },
{ label: '钻石', value: 'diamond' },
{ label: '三角形', value: 'triangle' },
{ label: '钉子', value: 'pin' },
],
},
},
{
label: '宽度',
key: 'width',
default: 4,
comType: 'inputNumber',
},
{
label: '颜色',
key: 'color',
comType: 'fontColor',
},
{
label: '与波形距离',
key: 'distance',
default: 2,
min: 0,
comType: 'inputNumber',
},
],
},
{
label: '填充',
key: 'fill',
comType: 'group',
rows: [
{
label: '颜色',
key: 'color',
comType: 'fontColor',
},
{
label: '透明度',
key: 'opacity',
min: 0,
max: 1,
step: 0.1,
default: 0.8,
comType: 'inputNumber',
},
{
label: '贴图样式',
key: 'pattern',
comType: 'select',
default: 'default',
options: {
items: [
{ label: '无贴图', value: 'default' },
{ label: '线', value: 'line' },
{ label: '点点', value: 'dot' },
{ label: '方块', value: 'square' },
],
},
},
],
},
{
label: '波形',
key: 'wave',
comType: 'group',
rows: [
{
label: '水波数量',
key: 'count',
default: 3,
min: 0,
max: 10,
comType: 'inputNumber',
},
{
label: '水波长度',
key: 'length',
min: 0,
max: 1000,
default: 192,
comType: 'inputNumber',
},
],
},
{
label: '指标',
key: 'statistic',
comType: 'group',
rows: [
{
label: '标题',
key: 'title',
comType: 'input',
},
{
label: '前缀文字',
key: 'prefix',
comType: 'input',
},
{
label: '后缀文字',
key: 'suffix',
comType: 'input',
},
],
},
],
settings: [
{
label: 'viz.palette.setting.paging.title',
key: 'paging',
comType: 'group',
rows: [
{
label: 'viz.palette.setting.paging.pageSize',
key: 'pageSize',
default: 1000,
comType: 'inputNumber',
options: {
needRefresh: true,
step: 1,
min: 0,
},
},
],
},
],
i18ns: [],
},
isISOContainer: 'radar-chart',
dependency: ['https://unpkg.com/@antv/g2plot@latest/dist/g2plot.min.js'],
meta: {
id: 'liquid-chart',
name: 'LiquidChart',
icon: svgIcon,
},
onMount(options, context) {
if (!context.document) {
return;
}
const { G2Plot } = context.window;
let containerDom = context.document.getElementById(options.containerId);
this.liquid = new G2Plot.Liquid(
containerDom,
this.getOptions(options.dataset, options.config),
);
this.liquid.render();
},
onUpdated(options, context) {
if (
!options.dataset ||
!options.dataset.columns ||
!options.config ||
!this.liquid
) {
return;
}
const newOptions = this.getOptions(options.dataset, options.config);
this.liquid?.update(Object.assign({}, newOptions));
},
onUnMount() {
this.liquid?.destroy();
},
getOptions(dataset, config) {
const dataConfigs = config.datas || [];
const styleConfigs = config.styles || [];
const aggregateConfigs = dataConfigs
.filter(c => c.type === 'aggregate')
.flatMap(config => config.rows || []);
let chartDataSet = dHelper.transformToDataSet(
dataset.rows,
dataset.columns,
config.datas,
);
let percent = chartDataSet?.[0]?.getCell?.(aggregateConfigs[0]);
const [pattern] = dHelper.getStyles(styleConfigs, ['fill'], ['pattern']);
const [color, opacity] = dHelper.getStyles(
styleConfigs,
['fill'],
['color', 'opacity'],
);
return {
percent,
...this.getOutLine(styleConfigs),
...this.getWave(styleConfigs),
...this.getStatistic(styleConfigs),
liquidStyle: {
fill: color,
opacity: opacity,
},
color,
pattern: {
type: pattern,
},
};
},
getOutLine(styles) {
const [type, width, color, distance] = dHelper.getStyles(
styles,
['outline'],
['type', 'width', 'color', 'distance'],
);
return {
shape: type,
outline: {
border: width,
color,
distance,
},
};
},
getWave(styles) {
const [count, length] = dHelper.getStyles(
styles,
['wave'],
['count', 'length'],
);
return {
wave: {
count,
length,
},
};
},
getStatistic(styles) {
const [title, prefix, suffix] = dHelper.getStyles(
styles,
['statistic'],
['title', 'prefix', 'suffix'],
);
let statistic = {};
if (title) {
statistic.title = {
content: title,
};
}
statistic.content = {
formatter: ({ percent }) => {
return [prefix, `${(percent * 100).toFixed(2)}%`, suffix]
.filter(item => item !== undefined)
.join('');
},
};
return { statistic };
},
};
}