-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathy-scrollRankBar.js
257 lines (252 loc) · 7.17 KB
/
y-scrollRankBar.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
function scrollRankBar({ dHelper }) {
const svgIcon = `<svg t="1648385551691" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4341" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><defs><style type="text/css">
</style></defs><path d="M128 768h256v-85.333333H128v85.333333zM128 256v85.333333h768V256H128z m0 298.666667h512v-85.333334H128v85.333334z" p-id="4342"></path></svg>`;
return {
config: {
datas: [
{
label: 'dimension',
key: 'dimension',
required: true,
type: 'group',
},
{
label: 'metrics',
key: 'metrics',
required: true,
type: 'aggregate',
actions: {
NUMERIC: ['aggregate', 'alias', 'format', 'sortable'],
STRING: ['aggregateLimit', 'alias', 'format', 'sortable'],
},
limit: 1,
},
{
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.unit',
key: 'unit',
default: '',
comType: 'input',
},
{
label: 'config.waitTime',
key: 'waitTime',
default: '2000',
comType: 'inputNumber',
},
{
label: 'config.barColor',
key: 'barColor',
default: 'blue',
comType: 'fontColor',
},
{
label: 'config.fontColor',
key: 'fontColor',
default: '#000',
comType: 'fontColor',
},
],
},
],
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,
barColor: '柱状颜色',
fontColor: '字体颜色',
},
},
],
},
],
i18ns: [
{
lang: 'zh-CN',
translation: {
chartName: '滚动排名柱状图',
title: '配置',
config: {
rowNum: '行数',
unit: '单位',
waitTime: '切换间隔时间',
barColor: '柱状颜色',
fontColor: '字体颜色',
},
},
},
{
lang: 'en-US',
translation: {
chartName: 'scrollRankBarChart',
title: 'Config',
config: {
rowNum: 'RowNum',
unit: 'Unit',
waitTime: 'WaitTime',
barColor: 'barColor',
fontColor: 'fontColor',
},
},
},
],
},
isISOContainer: 'scrollRankBarChart',
//
dependency: [
'https://cdn.jsdelivr.net/npm/[email protected]',
'https://unpkg.com/@jiaminghi/data-view/dist/datav.map.vue.js',
],
meta: {
id: 'scrollRankBarChart',
name: '滚动排名柱状图',
icon: svgIcon,
requirements: [
{
group: 1,
aggregate: 1,
},
],
},
chartId: 'scrollRankBarChart',
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: {
data: [0],
shape: 'round',
},
zNumber: +Date.now(),
},
methods: {},
watch: {},
mounted: function () {},
});
}
},
getTemplate() {
return `
<div style="width:100%;height:100%" :key="zNumber">
<dv-scroll-ranking-board :key="zNumber" :config="chartConfig" style="margin:auto;width:90%;height:99%" />
</div>
`;
},
getChartStyle(styles) {
const [rowNum, unit, waitTime, barColor, fontColor] = dHelper.getStyles(
styles,
['config'],
['rowNum', 'unit', 'waitTime', 'barColor', 'fontColor'],
);
return {
rowNum,
unit,
waitTime,
barColor,
fontColor,
};
},
onUpdated(props, context) {
if (!props.dataset || !props.dataset.columns || !props.config) {
return;
}
const { dataset, config } = props;
const { rowNum, unit, waitTime, barColor, fontColor } =
this.getChartStyle(config.styles);
let dataValue = [];
if (dataset.rows && dataset.rows[0] && dataset.rows[0][0]) {
dataset.rows.forEach(row => {
dataValue.push({ name: row[1], value: row[0] });
});
}
const chartConfig = {
data: dataValue,
rowNum,
unit,
waitTime,
// valueFormatter: (name, value, percent, ranking) => {},
};
this.setStyle(context.document, barColor, fontColor);
this.chart.$data.chartConfig = chartConfig;
},
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);
},
onUnMount() {
this.chart = null;
},
onResize(opt, context) {},
};
}