-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathy-scrollTable.js
435 lines (418 loc) · 12.6 KB
/
y-scrollTable.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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
function yScrollTable({ dHelper }) {
const svgIcon = `<svg t="1648430390479" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="19264" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><defs><style type="text/css">
</style></defs><path d="M768 214.016l169.984 0 0 169.984-169.984 0 0-169.984zM768 809.984l0-169.984 169.984 0 0 169.984-169.984 0zM553.984 809.984l0-169.984 171.989333 0 0 169.984-171.989333 0zM342.016 809.984l0-169.984 169.984 0 0 169.984-169.984 0zM128 809.984l0-169.984 169.984 0 0 169.984-169.984 0zM768 598.016l0-171.989333 169.984 0 0 171.989333-169.984 0zM553.984 214.016l171.989333 0 0 169.984-171.989333 0 0-169.984zM342.016 384l0-169.984 169.984 0 0 169.984-169.984 0zM553.984 598.016l0-171.989333 171.989333 0 0 171.989333-171.989333 0zM342.016 598.016l0-171.989333 169.984 0 0 171.989333-169.984 0zM128 598.016l0-171.989333 169.984 0 0 171.989333-169.984 0zM128 384l0-169.984 169.984 0 0 169.984-169.984 0z" p-id="19265"></path></svg>`;
return {
config: {
datas: [
{
label: 'mixed',
key: 'mixed',
required: true,
type: 'mixed',
},
{
label: 'filter',
key: 'filter',
type: 'filter',
allowSameField: true,
},
],
styles: [
{
label: 'title',
key: 'config',
comType: 'group',
rows: [
{
label: 'config.rowNum',
key: 'rowNum',
default: '10',
comType: 'inputNumber',
},
{
label: 'config.showHeader',
key: 'showHeader',
default: true,
comType: 'switch',
},
{
label: 'config.headerBGC',
key: 'headerBGC',
default: 'blue',
comType: 'fontColor',
},
{
label: 'config.headerFont',
key: 'headerFont',
comType: 'font',
default: {
fontFamily: 'PingFang SC',
fontSize: '12',
fontWeight: 'normal',
fontStyle: 'normal',
color: '#fff',
},
},
{
label: 'config.headerHeight',
key: 'headerHeight',
default: '35',
comType: 'inputNumber',
},
{
label: 'config.index',
key: 'index',
default: true,
comType: 'switch',
},
{
label: 'config.indexHeader',
key: 'indexHeader',
default: '#',
comType: 'input',
},
{
label: 'config.indexBGC',
key: 'indexBGC',
default: '#495057',
comType: 'fontColor',
},
{
label: 'config.carousel',
key: 'carousel',
default: 'single',
comType: 'select',
options: {
items: [
{ label: '行轮播', value: 'single' },
{ label: '页轮播', value: 'page' },
],
},
},
{
label: 'config.waitTime',
key: 'waitTime',
default: '2000',
comType: 'inputNumber',
},
{
label: 'config.oddRowBGC',
key: 'oddRowBGC',
default: '#1976d2',
comType: 'fontColor',
},
{
label: 'config.evenRowBGC',
key: 'evenRowBGC',
default: '#0D47A1',
comType: 'fontColor',
},
{
label: 'config.bodyFont',
key: 'boardFont',
comType: 'font',
default: {
fontFamily: 'PingFang SC',
fontSize: '12',
fontWeight: 'normal',
fontStyle: 'normal',
color: '#fff',
},
},
],
},
],
settings: [
{
label: 'viz.palette.setting.paging.title',
key: 'paging',
comType: 'group',
rows: [
{
label: 'viz.palette.setting.paging.pageSize',
key: 'pageSize',
default: 1000,
comType: 'inputNumber',
},
],
},
],
i18ns: [
{
lang: 'zh-CN',
translation: {
chartName: '滚动图表',
title: '配置',
config: {
rowNum: '表行数',
showHeader: '显示表头',
carousel: '轮播方式',
headerFont: '表头字体',
bodyFont: '表体字体',
waitTime: '轮播时间间隔(ms)',
oddRowBGC: '奇数行背景色',
evenRowBGC: '偶数行背景色',
headerHeight: '表头高度',
headerBGC: '表头背景色',
index: '显示行号',
indexHeader: '行号标题',
indexBGC: '行号背景色',
},
},
},
{
lang: 'en-US',
translation: {
chartName: 'scrollTable',
title: 'Config',
config: {
rowNum: 'rowNum',
showHeader: 'showHeader',
carousel: 'carousel',
headerFont: 'headerFont',
bodyFont: 'bodyFont',
waitTime: 'waitTime(ms)',
oddRowBGC: 'oddRowBGC',
evenRowBGC: 'evenRowBGC',
headerHeight: 'headerHeight',
headerBGC: 'headerBGC',
index: 'show index',
indexHeader: 'indexHeader',
indexBGC: 'indexBGC',
},
},
},
],
},
isISOContainer: 'yScrollTable',
//
dependency: [
'https://cdn.jsdelivr.net/npm/vue@2.6.14',
'https://unpkg.com/@jiaminghi/data-view/dist/datav.map.vue.js',
],
meta: {
id: 'yScrollTable',
name: '滚动排名柱状图',
icon: svgIcon,
requirements: [
{
group: [0, 999],
aggregate: [0, 999],
},
],
},
chartId: 'yScrollTable',
timer: null,
onMount(options, context) {
if ('Vue' in context.window) {
context.document.getElementById(
options.containerId,
).innerHTML = `<div id='${this.chartId}'></div>`;
const Vue = context.window.Vue;
this.chart = new Vue({
el: `#${this.chartId}`,
template: this.getTemplate(),
data: {
chartConfig: {},
zNumber: +Date.now(),
},
methods: {},
watch: {},
mounted: function () {},
});
}
},
getTemplate() {
return `
<div style="width:100%;height:100%" :key="zNumber">
<dv-scroll-board :key="zNumber" :config="chartConfig" style="margin:auto;width:100%;height:100%" />
</div>
`;
},
getChartStyle(styles) {
const [
rowNum,
showHeader,
headerBGC,
headerHeight,
oddRowBGC,
evenRowBGC,
waitTime,
index,
indexHeader,
carousel,
headerFont,
boardFont,
] = dHelper.getStyles(
styles,
['config'],
[
'rowNum',
'showHeader',
'headerBGC',
'headerHeight',
'oddRowBGC',
'evenRowBGC',
'waitTime',
'index', //显示行号
'indexHeader', //行号表头
'carousel',
'headerFont',
'boardFont',
],
);
return {
rowNum,
showHeader,
headerBGC,
headerHeight,
oddRowBGC,
evenRowBGC,
waitTime,
index,
indexHeader,
carousel,
headerFont,
boardFont,
};
},
setStyle(document, barColor, fontColor) {
const styleId = 'scrollRankBarId';
let style = document.createElement('style');
style.setAttribute('type', 'text/css');
style.setAttribute('id', styleId);
let styleText = `
.dv-scroll-ranking-board{
color:${fontColor};
// font-size:30px;
}
.dv-scroll-ranking-board .ranking-info .rank{
color:${barColor};
// font-size:30px;
}
.dv-scroll-ranking-board .ranking-info{
// font-size:30px;
}
.dv-scroll-ranking-board .ranking-column {
border-color:${barColor}
}
.dv-scroll-ranking-board .ranking-column .inside-column{
background-color:${barColor}
}
`;
try {
style.appendChild(document.createTextNode(styleText));
} catch (ex) {
style.styleSheet.cssText = styleText;
}
let head = document.getElementsByTagName('head')[0];
head.appendChild(style);
//
// var self = document.getElementById(styleId);
// //获取需要删除节点的父节点
// var parent = self.parentElement;
// //进行删除操作
// //var removed = parent.removeChild(self);
// parent.removeChild(self);
},
onUpdated(props, context) {
if (!props.dataset || !props.dataset.columns || !props.config) {
return;
}
const { dataset, config } = props;
const chartDataSet = dHelper.transformToObjectArray(
dataset.rows,
dataset.columns,
config.datas || [],
);
const headerData = this.getHeader(config);
console.log('__ chartDataSet', chartDataSet);
const dataValues = [];
chartDataSet.forEach(item => {
dataValues.push(Object.values(item));
});
const {
rowNum,
showHeader,
headerBGC,
headerHeight,
oddRowBGC,
evenRowBGC,
waitTime,
index,
indexHeader,
carousel,
headerFont,
boardFont,
} = this.getChartStyle(config.styles);
this.setStyle(context.document, headerFont, boardFont);
// const dataValue = JSON.parse(JSON.stringify(dataset.rows));
const chartConfig = {
data: dataValues,
// header: headerData,
oddRowBGC,
evenRowBGC,
waitTime,
index,
indexHeader,
rowNum,
carousel,
align: ['center'],
};
if (showHeader) {
chartConfig.header = headerData;
chartConfig.headerBGC = headerBGC;
chartConfig.headerHeight = headerHeight;
}
// this.setStyle(context.document, barColor, fontColor);
this.chart.$data.chartConfig = chartConfig;
},
getHeader(config) {
const mixedColNames = (config.datas || [])
.filter(c => c.type === 'mixed')
.flatMap(config => config.rows || []);
const headerData = mixedColNames.map(dHelper.getColumnRenderName);
return headerData;
},
setStyle(document, headerFont, boardFont) {
const styleId = 'scrollTableId';
let style = document.createElement('style');
style.setAttribute('type', 'text/css');
style.setAttribute('id', styleId);
let styleText = `
.dv-scroll-board .header{
color:${headerFont.color};
font-family:${headerFont.fontFamily};
font-size:${headerFont.fontSize};
font-weight:${headerFont.fontWeight};
font-style:${headerFont.fontStyle};
}
.dv-scroll-board .row-item{
color:${boardFont.color};
font-family:${boardFont.fontFamily};
font-size:${boardFont.fontSize};
font-weight:${boardFont.fontWeight};
font-style:${boardFont.fontStyle};
}
`;
try {
style.appendChild(document.createTextNode(styleText));
} catch (ex) {
style.styleSheet.cssText = styleText;
}
let head = document.getElementsByTagName('head')[0];
head.appendChild(style);
//
// var self = document.getElementById(styleId);
// //获取需要删除节点的父节点
// var parent = self.parentElement;
// //进行删除操作
// //var removed = parent.removeChild(self);
// parent.removeChild(self);
},
onUnMount() {
this.chart = null;
},
onResize(opt, context) {},
};
}