@visactor/vchart-extension 0.0.1 → 0.0.2-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/build/index.js +354 -0
- package/build/index.min.js +1 -0
- package/esm/index.d.ts +1 -0
- package/esm/index.js +1 -0
- package/esm/index.js.map +1 -0
- package/esm/ranking-bar/interface.d.ts +45 -0
- package/esm/ranking-bar/interface.js +2 -0
- package/esm/ranking-bar/interface.js.map +1 -0
- package/esm/ranking-bar/ranking-bar-transformer.d.ts +10 -0
- package/esm/ranking-bar/ranking-bar-transformer.js +300 -0
- package/esm/ranking-bar/ranking-bar-transformer.js.map +1 -0
- package/esm/ranking-bar/ranking-bar.d.ts +14 -0
- package/esm/ranking-bar/ranking-bar.js +26 -0
- package/esm/ranking-bar/ranking-bar.js.map +1 -0
- package/esm/type/index.d.ts +1 -0
- package/esm/type/index.js +2 -0
- package/esm/type/index.js.map +1 -0
- package/esm/type/type.d.ts +8 -0
- package/esm/type/type.js +2 -0
- package/esm/type/type.js.map +1 -0
- package/package.json +5 -5
package/build/index.js
ADDED
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@visactor/vchart'), require('@visactor/vutils')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', '@visactor/vchart', '@visactor/vutils'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.VChartExtension = {}, global.VChart, global.VUtils));
|
|
5
|
+
})(this, (function (exports, vchart, vutils) { 'use strict';
|
|
6
|
+
|
|
7
|
+
class RankingBarChartSpecTransformer extends vchart.BaseChartSpecTransformer {
|
|
8
|
+
transformSpec(spec) {
|
|
9
|
+
const { timeData, timeNodes } = processData(spec);
|
|
10
|
+
const { interval: userInterval, xField, yField, color, icon, iconPosition, iconShape, timeLabel, label, nameLabel, xAxis, yAxis } = spec;
|
|
11
|
+
const interval = userInterval ? userInterval : 1000;
|
|
12
|
+
const exchangeDuration = Math.min(interval, 500);
|
|
13
|
+
spec.type = 'common';
|
|
14
|
+
spec.data = [
|
|
15
|
+
{
|
|
16
|
+
id: 'timeData',
|
|
17
|
+
values: timeData.get(timeNodes[0])
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
id: 'time',
|
|
21
|
+
values: [{ time: timeNodes[0] }]
|
|
22
|
+
}
|
|
23
|
+
];
|
|
24
|
+
spec.color = {
|
|
25
|
+
specified: Object.assign({}, color)
|
|
26
|
+
};
|
|
27
|
+
spec.region = [{ clip: true }];
|
|
28
|
+
spec.series = [
|
|
29
|
+
{
|
|
30
|
+
type: 'bar',
|
|
31
|
+
id: 'ranking-bar',
|
|
32
|
+
dataId: 'timeData',
|
|
33
|
+
direction: 'horizontal',
|
|
34
|
+
yField,
|
|
35
|
+
xField,
|
|
36
|
+
seriesField: yField,
|
|
37
|
+
extensionMark: [],
|
|
38
|
+
label: labelSpec(label, Object.assign(Object.assign({}, nameLabel), { yField }), { interval, exchangeDuration })
|
|
39
|
+
}
|
|
40
|
+
];
|
|
41
|
+
spec.axes = axisSpec(xAxis, yAxis);
|
|
42
|
+
spec.player = {
|
|
43
|
+
type: 'continuous',
|
|
44
|
+
auto: true,
|
|
45
|
+
loop: false,
|
|
46
|
+
interval,
|
|
47
|
+
specs: timeNodes.map(time => ({
|
|
48
|
+
data: [
|
|
49
|
+
{ id: 'timeData', values: timeData.get(time) },
|
|
50
|
+
{ id: 'time', values: [{ time }] }
|
|
51
|
+
]
|
|
52
|
+
}))
|
|
53
|
+
};
|
|
54
|
+
spec.tooltip = { visible: false };
|
|
55
|
+
spec.customMark = [];
|
|
56
|
+
transformAnimationSpec(spec, { interval, exchangeDuration });
|
|
57
|
+
if (!timeLabel || timeLabel.visible !== false) {
|
|
58
|
+
spec.customMark.push(timeLabelSpec(timeLabel.style));
|
|
59
|
+
}
|
|
60
|
+
if (icon) {
|
|
61
|
+
const icon = iconSpec(iconPosition, iconShape, { interval, exchangeDuration });
|
|
62
|
+
spec.series[0].extensionMark.push(icon);
|
|
63
|
+
}
|
|
64
|
+
super.transformSpec(spec);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function processData(spec) {
|
|
68
|
+
const { xField, yField, timeField, data, topN = 10, icon } = spec;
|
|
69
|
+
const timeNodes = new Set();
|
|
70
|
+
const timeData = new Map();
|
|
71
|
+
data.sort((d1, d2) => Number(d2[xField]) - Number(d1[xField]));
|
|
72
|
+
data.forEach(d => {
|
|
73
|
+
const time = d[timeField];
|
|
74
|
+
if (vutils.isValid(time)) {
|
|
75
|
+
timeNodes.add(time);
|
|
76
|
+
}
|
|
77
|
+
if (!timeData.has(time)) {
|
|
78
|
+
timeData.set(time, []);
|
|
79
|
+
}
|
|
80
|
+
const currentData = timeData.get(time);
|
|
81
|
+
if (currentData.length < topN) {
|
|
82
|
+
const _d = Object.assign({}, d);
|
|
83
|
+
if (icon && icon[_d[yField]]) {
|
|
84
|
+
_d['icon'] = icon[_d[yField]];
|
|
85
|
+
}
|
|
86
|
+
currentData.push(_d);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
return { timeData, timeNodes: Array.from(timeNodes).sort() };
|
|
90
|
+
}
|
|
91
|
+
function transformAnimationSpec(spec, { interval, exchangeDuration }) {
|
|
92
|
+
spec.animationAppear = false;
|
|
93
|
+
spec.animationUpdate = {
|
|
94
|
+
bar: [
|
|
95
|
+
{
|
|
96
|
+
type: 'update',
|
|
97
|
+
options: { excludeChannels: ['y'] },
|
|
98
|
+
easing: 'linear',
|
|
99
|
+
duration: interval
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
channel: ['y'],
|
|
103
|
+
easing: 'circInOut',
|
|
104
|
+
duration: exchangeDuration
|
|
105
|
+
}
|
|
106
|
+
],
|
|
107
|
+
axis: {
|
|
108
|
+
duration: interval,
|
|
109
|
+
easing: 'linear'
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
spec.animationEnter = {
|
|
113
|
+
bar: [
|
|
114
|
+
{
|
|
115
|
+
type: 'moveIn',
|
|
116
|
+
duration: exchangeDuration,
|
|
117
|
+
easing: 'cubicInOut',
|
|
118
|
+
options: {
|
|
119
|
+
direction: 'y',
|
|
120
|
+
orient: 'negative',
|
|
121
|
+
point: (datum, element, param) => {
|
|
122
|
+
return {
|
|
123
|
+
y: param.groupHeight + element.getBounds().height()
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
]
|
|
129
|
+
};
|
|
130
|
+
spec.animationExit = {
|
|
131
|
+
bar: [
|
|
132
|
+
{
|
|
133
|
+
type: 'moveOut',
|
|
134
|
+
duration: exchangeDuration,
|
|
135
|
+
easing: 'cubicInOut',
|
|
136
|
+
options: {
|
|
137
|
+
direction: 'y',
|
|
138
|
+
orient: 'negative'
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
]
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
function labelSpec(label = {}, nameLabel, { interval, exchangeDuration }) {
|
|
145
|
+
var _a, _b, _c, _e;
|
|
146
|
+
const spec = [];
|
|
147
|
+
if (label.visible !== false) {
|
|
148
|
+
spec.push({
|
|
149
|
+
visible: true,
|
|
150
|
+
overlap: false,
|
|
151
|
+
style: Object.assign({ fill: `rgb(64, 64, 64)` }, label.style),
|
|
152
|
+
smartInvert: {
|
|
153
|
+
fillStrategy: ((_a = label.style) === null || _a === void 0 ? void 0 : _a.fill) ? 'null' : undefined,
|
|
154
|
+
strokeStrategy: ((_b = label.style) === null || _b === void 0 ? void 0 : _b.stroke) ? 'null' : undefined
|
|
155
|
+
},
|
|
156
|
+
animationUpdate: [
|
|
157
|
+
{
|
|
158
|
+
duration: exchangeDuration,
|
|
159
|
+
easing: 'cubicInOut',
|
|
160
|
+
channel: ['y']
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
options: { excludeChannels: ['y'] },
|
|
164
|
+
easing: 'linear',
|
|
165
|
+
duration: interval
|
|
166
|
+
}
|
|
167
|
+
]
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
if (nameLabel.visible) {
|
|
171
|
+
spec.push({
|
|
172
|
+
visible: true,
|
|
173
|
+
overlap: false,
|
|
174
|
+
style: Object.assign({}, nameLabel.style),
|
|
175
|
+
smartInvert: {
|
|
176
|
+
fillStrategy: ((_c = nameLabel.style) === null || _c === void 0 ? void 0 : _c.fill) ? 'null' : undefined,
|
|
177
|
+
strokeStrategy: ((_e = nameLabel.style) === null || _e === void 0 ? void 0 : _e.stroke) ? 'null' : undefined
|
|
178
|
+
},
|
|
179
|
+
position: nameLabel.position === 'bar-end' ? 'inside-right' : 'inside-left',
|
|
180
|
+
formatter: `{${nameLabel.yField}}`,
|
|
181
|
+
animationUpdate: customMarkUpdateAnimation(interval, exchangeDuration)
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
return spec;
|
|
185
|
+
}
|
|
186
|
+
function axisSpec(xAxis = {}, yAxis = {}) {
|
|
187
|
+
const leftAxis = {
|
|
188
|
+
orient: 'left',
|
|
189
|
+
type: 'band',
|
|
190
|
+
inverse: true,
|
|
191
|
+
label: { style: yAxis.label },
|
|
192
|
+
domainLine: { style: yAxis.domainLine },
|
|
193
|
+
grid: { style: yAxis.grid }
|
|
194
|
+
};
|
|
195
|
+
const bottomAxis = {
|
|
196
|
+
orient: 'bottom',
|
|
197
|
+
type: 'linear',
|
|
198
|
+
nice: false,
|
|
199
|
+
animation: true,
|
|
200
|
+
label: { style: xAxis.label },
|
|
201
|
+
domainLine: { style: xAxis.domainLine },
|
|
202
|
+
grid: { style: xAxis.grid },
|
|
203
|
+
innerOffset: { right: '10%' }
|
|
204
|
+
};
|
|
205
|
+
if (xAxis.label) {
|
|
206
|
+
bottomAxis.label = xAxis.label;
|
|
207
|
+
}
|
|
208
|
+
return [leftAxis, bottomAxis];
|
|
209
|
+
}
|
|
210
|
+
function timeLabelSpec(textStyle = {}) {
|
|
211
|
+
return {
|
|
212
|
+
type: 'text',
|
|
213
|
+
dataId: 'time',
|
|
214
|
+
style: Object.assign({ textBaseline: 'bottom', fontSize: 200, textAlign: 'end', fontWeight: 600, text: (datum) => datum.time, x: (datum, ctx) => {
|
|
215
|
+
var _a;
|
|
216
|
+
return ((_a = ctx.vchart.getChart().getCanvasRect()) === null || _a === void 0 ? void 0 : _a.width) - 50;
|
|
217
|
+
}, y: (datum, ctx) => {
|
|
218
|
+
var _a;
|
|
219
|
+
return ((_a = ctx.vchart.getChart().getCanvasRect()) === null || _a === void 0 ? void 0 : _a.height) - 80;
|
|
220
|
+
}, fill: 'grey', fillOpacity: 0.5 }, textStyle)
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
function iconSpec(iconPosition = 'bar-end', iconShape = 'circle', { interval, exchangeDuration }) {
|
|
224
|
+
return {
|
|
225
|
+
type: 'symbol',
|
|
226
|
+
dataId: 'timeData',
|
|
227
|
+
style: {
|
|
228
|
+
symbolType: iconShape,
|
|
229
|
+
stroke: 'white',
|
|
230
|
+
lineWidth: 1,
|
|
231
|
+
size: (data, ctx) => {
|
|
232
|
+
var _a, _b;
|
|
233
|
+
const vchart = ctx.vchart;
|
|
234
|
+
const series = (_a = vchart.getChart()) === null || _a === void 0 ? void 0 : _a.getSeriesInIndex(0)[0];
|
|
235
|
+
if (vchart && series) {
|
|
236
|
+
const bandwidth = (_b = series.getYAxisHelper().getBandwidth(0)) !== null && _b !== void 0 ? _b : 0;
|
|
237
|
+
return Math.max(bandwidth - 4, 0);
|
|
238
|
+
}
|
|
239
|
+
return 10;
|
|
240
|
+
},
|
|
241
|
+
background: (data) => data.icon,
|
|
242
|
+
x: (data, ctx) => {
|
|
243
|
+
var _a, _b;
|
|
244
|
+
const vchart = ctx.vchart;
|
|
245
|
+
const series = (_a = vchart.getChart()) === null || _a === void 0 ? void 0 : _a.getSeriesInIndex(0)[0];
|
|
246
|
+
if (vchart && series) {
|
|
247
|
+
const bandwidth = (_b = series.getYAxisHelper().getBandwidth(0)) !== null && _b !== void 0 ? _b : 0;
|
|
248
|
+
if (iconPosition === 'bar-start') {
|
|
249
|
+
return bandwidth / 2;
|
|
250
|
+
}
|
|
251
|
+
else if (iconPosition === 'axis') {
|
|
252
|
+
return -bandwidth / 2;
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
return series.dataToPositionX(data) - bandwidth / 2;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return undefined;
|
|
259
|
+
},
|
|
260
|
+
y: (data, ctx) => {
|
|
261
|
+
var _a, _b;
|
|
262
|
+
const vchart = ctx.vchart;
|
|
263
|
+
const series = (_a = vchart.getChart()) === null || _a === void 0 ? void 0 : _a.getSeriesInIndex(0)[0];
|
|
264
|
+
if (vchart && series) {
|
|
265
|
+
const bandwidth = (_b = series.getYAxisHelper().getBandwidth(0)) !== null && _b !== void 0 ? _b : 0;
|
|
266
|
+
return series.dataToPositionY(data) + bandwidth / 2;
|
|
267
|
+
}
|
|
268
|
+
return undefined;
|
|
269
|
+
},
|
|
270
|
+
scaleY: iconShape === 'rect' ? 1.2 : 1
|
|
271
|
+
},
|
|
272
|
+
animationUpdate: customMarkUpdateAnimation(interval, exchangeDuration),
|
|
273
|
+
animationEnter: [
|
|
274
|
+
{
|
|
275
|
+
type: 'moveIn',
|
|
276
|
+
duration: exchangeDuration,
|
|
277
|
+
easing: 'cubicInOut',
|
|
278
|
+
options: {
|
|
279
|
+
direction: 'y',
|
|
280
|
+
orient: 'negative',
|
|
281
|
+
point: (datum, element, param) => {
|
|
282
|
+
return {
|
|
283
|
+
y: param.groupHeight + element.getBounds().height()
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
],
|
|
289
|
+
animationExit: [
|
|
290
|
+
{
|
|
291
|
+
type: 'moveOut',
|
|
292
|
+
duration: exchangeDuration,
|
|
293
|
+
easing: 'cubicInOut',
|
|
294
|
+
options: {
|
|
295
|
+
direction: 'y',
|
|
296
|
+
orient: 'negative'
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
]
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
function customMarkUpdateAnimation(duration, exchangeDuration) {
|
|
303
|
+
return [
|
|
304
|
+
{
|
|
305
|
+
duration: exchangeDuration,
|
|
306
|
+
easing: 'cubicInOut',
|
|
307
|
+
channel: ['y']
|
|
308
|
+
},
|
|
309
|
+
{
|
|
310
|
+
options: { excludeChannels: ['y'] },
|
|
311
|
+
channel: ['x', 'x2', 'x1'],
|
|
312
|
+
easing: 'linear',
|
|
313
|
+
duration
|
|
314
|
+
}
|
|
315
|
+
];
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
class RankingBar extends vchart.BaseChart {
|
|
319
|
+
constructor() {
|
|
320
|
+
super(...arguments);
|
|
321
|
+
this.type = 'rankingBar';
|
|
322
|
+
this.transformerConstructor = RankingBarChartSpecTransformer;
|
|
323
|
+
}
|
|
324
|
+
init() {
|
|
325
|
+
if (!this.isValid()) {
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
super.init();
|
|
329
|
+
}
|
|
330
|
+
isValid() {
|
|
331
|
+
var _a, _b, _c, _d;
|
|
332
|
+
const { xField, yField, timeField, data } = this._spec;
|
|
333
|
+
if (!xField || !yField || !timeField) {
|
|
334
|
+
(_b = (_a = this._option).onError) === null || _b === void 0 ? void 0 : _b.call(_a, 'Missing Required Config: `xField`, `yField`, `timeField` ');
|
|
335
|
+
return false;
|
|
336
|
+
}
|
|
337
|
+
if (!data) {
|
|
338
|
+
(_d = (_c = this._option).onError) === null || _d === void 0 ? void 0 : _d.call(_c, 'Data is required');
|
|
339
|
+
return false;
|
|
340
|
+
}
|
|
341
|
+
return true;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
RankingBar.type = 'rankingBar';
|
|
345
|
+
RankingBar.view = 'singleDefault';
|
|
346
|
+
RankingBar.transformerConstructor = RankingBarChartSpecTransformer;
|
|
347
|
+
const registerRankingBarChart = () => {
|
|
348
|
+
vchart.VChart.useChart([RankingBar]);
|
|
349
|
+
};
|
|
350
|
+
|
|
351
|
+
exports.RankingBar = RankingBar;
|
|
352
|
+
exports.registerRankingBarChart = registerRankingBarChart;
|
|
353
|
+
|
|
354
|
+
}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@visactor/vchart"),require("@visactor/vutils")):"function"==typeof define&&define.amd?define(["exports","@visactor/vchart","@visactor/vutils"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).VChartExtension={},e.VChart,e.VUtils)}(this,(function(e,t,i){"use strict";class n extends t.BaseChartSpecTransformer{transformSpec(e){const{timeData:t,timeNodes:n}=function(e){const{xField:t,yField:n,timeField:a,data:o,topN:r=10,icon:s}=e,l=new Set,d=new Map;return o.sort(((e,i)=>Number(i[t])-Number(e[t]))),o.forEach((e=>{const t=e[a];i.isValid(t)&&l.add(t),d.has(t)||d.set(t,[]);const o=d.get(t);if(o.length<r){const t=Object.assign({},e);s&&s[t[n]]&&(t.icon=s[t[n]]),o.push(t)}})),{timeData:d,timeNodes:Array.from(l).sort()}}(e),{interval:r,xField:s,yField:l,color:d,icon:u,iconPosition:c,iconShape:g,timeLabel:v,label:p,nameLabel:h,xAxis:y,yAxis:m}=e,b=r||1e3,f=Math.min(b,500);if(e.type="common",e.data=[{id:"timeData",values:t.get(n[0])},{id:"time",values:[{time:n[0]}]}],e.color={specified:Object.assign({},d)},e.region=[{clip:!0}],e.series=[{type:"bar",id:"ranking-bar",dataId:"timeData",direction:"horizontal",yField:l,xField:s,seriesField:l,extensionMark:[],label:a(p,Object.assign(Object.assign({},h),{yField:l}),{interval:b,exchangeDuration:f})}],e.axes=function(e={},t={}){const i={orient:"left",type:"band",inverse:!0,label:{style:t.label},domainLine:{style:t.domainLine},grid:{style:t.grid}},n={orient:"bottom",type:"linear",nice:!1,animation:!0,label:{style:e.label},domainLine:{style:e.domainLine},grid:{style:e.grid},innerOffset:{right:"10%"}};e.label&&(n.label=e.label);return[i,n]}(y,m),e.player={type:"continuous",auto:!0,loop:!1,interval:b,specs:n.map((e=>({data:[{id:"timeData",values:t.get(e)},{id:"time",values:[{time:e}]}]})))},e.tooltip={visible:!1},e.customMark=[],function(e,{interval:t,exchangeDuration:i}){e.animationAppear=!1,e.animationUpdate={bar:[{type:"update",options:{excludeChannels:["y"]},easing:"linear",duration:t},{channel:["y"],easing:"circInOut",duration:i}],axis:{duration:t,easing:"linear"}},e.animationEnter={bar:[{type:"moveIn",duration:i,easing:"cubicInOut",options:{direction:"y",orient:"negative",point:(e,t,i)=>({y:i.groupHeight+t.getBounds().height()})}}]},e.animationExit={bar:[{type:"moveOut",duration:i,easing:"cubicInOut",options:{direction:"y",orient:"negative"}}]}}(e,{interval:b,exchangeDuration:f}),v&&!1===v.visible||e.customMark.push(function(e={}){return{type:"text",dataId:"time",style:Object.assign({textBaseline:"bottom",fontSize:200,textAlign:"end",fontWeight:600,text:e=>e.time,x:(e,t)=>{var i;return(null===(i=t.vchart.getChart().getCanvasRect())||void 0===i?void 0:i.width)-50},y:(e,t)=>{var i;return(null===(i=t.vchart.getChart().getCanvasRect())||void 0===i?void 0:i.height)-80},fill:"grey",fillOpacity:.5},e)}}(v.style)),u){const t=function(e="bar-end",t="circle",{interval:i,exchangeDuration:n}){return{type:"symbol",dataId:"timeData",style:{symbolType:t,stroke:"white",lineWidth:1,size:(e,t)=>{var i,n;const a=t.vchart,o=null===(i=a.getChart())||void 0===i?void 0:i.getSeriesInIndex(0)[0];if(a&&o){const e=null!==(n=o.getYAxisHelper().getBandwidth(0))&&void 0!==n?n:0;return Math.max(e-4,0)}return 10},background:e=>e.icon,x:(t,i)=>{var n,a;const o=i.vchart,r=null===(n=o.getChart())||void 0===n?void 0:n.getSeriesInIndex(0)[0];if(o&&r){const i=null!==(a=r.getYAxisHelper().getBandwidth(0))&&void 0!==a?a:0;return"bar-start"===e?i/2:"axis"===e?-i/2:r.dataToPositionX(t)-i/2}},y:(e,t)=>{var i,n;const a=t.vchart,o=null===(i=a.getChart())||void 0===i?void 0:i.getSeriesInIndex(0)[0];if(a&&o){const t=null!==(n=o.getYAxisHelper().getBandwidth(0))&&void 0!==n?n:0;return o.dataToPositionY(e)+t/2}},scaleY:"rect"===t?1.2:1},animationUpdate:o(i,n),animationEnter:[{type:"moveIn",duration:n,easing:"cubicInOut",options:{direction:"y",orient:"negative",point:(e,t,i)=>({y:i.groupHeight+t.getBounds().height()})}}],animationExit:[{type:"moveOut",duration:n,easing:"cubicInOut",options:{direction:"y",orient:"negative"}}]}}(c,g,{interval:b,exchangeDuration:f});e.series[0].extensionMark.push(t)}super.transformSpec(e)}}function a(e={},t,{interval:i,exchangeDuration:n}){var a,r,s,l;const d=[];return!1!==e.visible&&d.push({visible:!0,overlap:!1,style:Object.assign({fill:"rgb(64, 64, 64)"},e.style),smartInvert:{fillStrategy:(null===(a=e.style)||void 0===a?void 0:a.fill)?"null":void 0,strokeStrategy:(null===(r=e.style)||void 0===r?void 0:r.stroke)?"null":void 0},animationUpdate:[{duration:n,easing:"cubicInOut",channel:["y"]},{options:{excludeChannels:["y"]},easing:"linear",duration:i}]}),t.visible&&d.push({visible:!0,overlap:!1,style:Object.assign({},t.style),smartInvert:{fillStrategy:(null===(s=t.style)||void 0===s?void 0:s.fill)?"null":void 0,strokeStrategy:(null===(l=t.style)||void 0===l?void 0:l.stroke)?"null":void 0},position:"bar-end"===t.position?"inside-right":"inside-left",formatter:`{${t.yField}}`,animationUpdate:o(i,n)}),d}function o(e,t){return[{duration:t,easing:"cubicInOut",channel:["y"]},{options:{excludeChannels:["y"]},channel:["x","x2","x1"],easing:"linear",duration:e}]}class r extends t.BaseChart{constructor(){super(...arguments),this.type="rankingBar",this.transformerConstructor=n}init(){this.isValid()&&super.init()}isValid(){var e,t,i,n;const{xField:a,yField:o,timeField:r,data:s}=this._spec;return a&&o&&r?!!s||(null===(n=(i=this._option).onError)||void 0===n||n.call(i,"Data is required"),!1):(null===(t=(e=this._option).onError)||void 0===t||t.call(e,"Missing Required Config: `xField`, `yField`, `timeField` "),!1)}}r.type="rankingBar",r.view="singleDefault",r.transformerConstructor=n;e.RankingBar=r,e.registerRankingBarChart=()=>{t.VChart.useChart([r])}}));
|
package/esm/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ranking-bar/ranking-bar';
|
package/esm/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./ranking-bar/ranking-bar";
|
package/esm/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC","file":"index.js","sourcesContent":["export * from './ranking-bar/ranking-bar';\n"]}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { ILineGraphicAttribute, ITextGraphicAttribute } from '@visactor/vrender-core';
|
|
2
|
+
export type IRankingBarData = any[];
|
|
3
|
+
export interface IPlayConfig {
|
|
4
|
+
interval?: number;
|
|
5
|
+
}
|
|
6
|
+
export interface IRankingBarSpec extends IPlayConfig {
|
|
7
|
+
type: string;
|
|
8
|
+
data: IRankingBarData;
|
|
9
|
+
timeField: string;
|
|
10
|
+
xField: string;
|
|
11
|
+
yField: string;
|
|
12
|
+
topN?: number;
|
|
13
|
+
bar?: {
|
|
14
|
+
padding?: number;
|
|
15
|
+
cornerRadius?: number;
|
|
16
|
+
};
|
|
17
|
+
color?: Record<string, string>;
|
|
18
|
+
icon?: Record<string, string>;
|
|
19
|
+
iconPosition?: 'bar-end' | 'bar-start' | 'axis';
|
|
20
|
+
iconShape?: 'circle' | 'rect';
|
|
21
|
+
background?: string;
|
|
22
|
+
label?: {
|
|
23
|
+
visible?: boolean;
|
|
24
|
+
style?: ITextGraphicAttribute;
|
|
25
|
+
};
|
|
26
|
+
nameLabel?: ITextGraphicAttribute & {
|
|
27
|
+
visible?: boolean;
|
|
28
|
+
position?: 'bar-end' | 'bar-start';
|
|
29
|
+
style?: ITextGraphicAttribute;
|
|
30
|
+
};
|
|
31
|
+
timeLabel?: {
|
|
32
|
+
visible?: boolean;
|
|
33
|
+
style?: ITextGraphicAttribute;
|
|
34
|
+
};
|
|
35
|
+
xAxis?: {
|
|
36
|
+
label?: ITextGraphicAttribute;
|
|
37
|
+
domainLine?: ILineGraphicAttribute;
|
|
38
|
+
grid?: ILineGraphicAttribute;
|
|
39
|
+
};
|
|
40
|
+
yAxis?: {
|
|
41
|
+
label?: ITextGraphicAttribute;
|
|
42
|
+
domainLine?: ILineGraphicAttribute;
|
|
43
|
+
grid?: ILineGraphicAttribute;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["ranking-bar/interface.ts"],"names":[],"mappings":"","file":"interface.js","sourcesContent":["import type { ILineGraphicAttribute, ITextGraphicAttribute } from '@visactor/vrender-core';\n\nexport type IRankingBarData = any[];\n\nexport interface IPlayConfig {\n interval?: number; // 单位毫秒\n}\n\nexport interface IRankingBarSpec extends IPlayConfig {\n type: string;\n data: IRankingBarData;\n\n timeField: string;\n xField: string;\n yField: string;\n\n topN?: number;\n\n bar?: {\n padding?: number;\n cornerRadius?: number;\n };\n\n color?: Record<string, string>;\n\n icon?: Record<string, string>;\n\n iconPosition?: 'bar-end' | 'bar-start' | 'axis';\n\n iconShape?: 'circle' | 'rect';\n\n background?: string;\n\n label?: {\n visible?: boolean;\n style?: ITextGraphicAttribute;\n };\n\n nameLabel?: ITextGraphicAttribute & {\n visible?: boolean;\n position?: 'bar-end' | 'bar-start';\n style?: ITextGraphicAttribute;\n };\n\n timeLabel?: {\n visible?: boolean;\n style?: ITextGraphicAttribute;\n };\n\n xAxis?: {\n label?: ITextGraphicAttribute;\n domainLine?: ILineGraphicAttribute;\n grid?: ILineGraphicAttribute;\n };\n\n yAxis?: {\n label?: ITextGraphicAttribute;\n domainLine?: ILineGraphicAttribute;\n grid?: ILineGraphicAttribute;\n };\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { IRankingBarSpec } from './interface';
|
|
2
|
+
import type { ICommonChartSpec } from '@visactor/vchart';
|
|
3
|
+
import { BaseChartSpecTransformer } from '@visactor/vchart';
|
|
4
|
+
export declare class RankingBarChartSpecTransformer<T extends ICommonChartSpec> extends BaseChartSpecTransformer<any> {
|
|
5
|
+
transformSpec(spec: T): void;
|
|
6
|
+
}
|
|
7
|
+
export declare function processData(spec: IRankingBarSpec): {
|
|
8
|
+
timeData: Map<any, any>;
|
|
9
|
+
timeNodes: string[];
|
|
10
|
+
};
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import { BaseChartSpecTransformer } from "@visactor/vchart";
|
|
2
|
+
|
|
3
|
+
import { isValid } from "@visactor/vutils";
|
|
4
|
+
|
|
5
|
+
export class RankingBarChartSpecTransformer extends BaseChartSpecTransformer {
|
|
6
|
+
transformSpec(spec) {
|
|
7
|
+
const {timeData: timeData, timeNodes: timeNodes} = processData(spec), {interval: userInterval, xField: xField, yField: yField, color: color, icon: icon, iconPosition: iconPosition, iconShape: iconShape, timeLabel: timeLabel, label: label, nameLabel: nameLabel, xAxis: xAxis, yAxis: yAxis} = spec, interval = userInterval || 1e3, exchangeDuration = Math.min(interval, 500);
|
|
8
|
+
if (spec.type = "common", spec.data = [ {
|
|
9
|
+
id: "timeData",
|
|
10
|
+
values: timeData.get(timeNodes[0])
|
|
11
|
+
}, {
|
|
12
|
+
id: "time",
|
|
13
|
+
values: [ {
|
|
14
|
+
time: timeNodes[0]
|
|
15
|
+
} ]
|
|
16
|
+
} ], spec.color = {
|
|
17
|
+
specified: Object.assign({}, color)
|
|
18
|
+
}, spec.region = [ {
|
|
19
|
+
clip: !0
|
|
20
|
+
} ], spec.series = [ {
|
|
21
|
+
type: "bar",
|
|
22
|
+
id: "ranking-bar",
|
|
23
|
+
dataId: "timeData",
|
|
24
|
+
direction: "horizontal",
|
|
25
|
+
yField: yField,
|
|
26
|
+
xField: xField,
|
|
27
|
+
seriesField: yField,
|
|
28
|
+
extensionMark: [],
|
|
29
|
+
label: labelSpec(label, Object.assign(Object.assign({}, nameLabel), {
|
|
30
|
+
yField: yField
|
|
31
|
+
}), {
|
|
32
|
+
interval: interval,
|
|
33
|
+
exchangeDuration: exchangeDuration
|
|
34
|
+
})
|
|
35
|
+
} ], spec.axes = axisSpec(xAxis, yAxis), spec.player = {
|
|
36
|
+
type: "continuous",
|
|
37
|
+
auto: !0,
|
|
38
|
+
loop: !1,
|
|
39
|
+
interval: interval,
|
|
40
|
+
specs: timeNodes.map((time => ({
|
|
41
|
+
data: [ {
|
|
42
|
+
id: "timeData",
|
|
43
|
+
values: timeData.get(time)
|
|
44
|
+
}, {
|
|
45
|
+
id: "time",
|
|
46
|
+
values: [ {
|
|
47
|
+
time: time
|
|
48
|
+
} ]
|
|
49
|
+
} ]
|
|
50
|
+
})))
|
|
51
|
+
}, spec.tooltip = {
|
|
52
|
+
visible: !1
|
|
53
|
+
}, spec.customMark = [], transformAnimationSpec(spec, {
|
|
54
|
+
interval: interval,
|
|
55
|
+
exchangeDuration: exchangeDuration
|
|
56
|
+
}), timeLabel && !1 === timeLabel.visible || spec.customMark.push(timeLabelSpec(timeLabel.style)),
|
|
57
|
+
icon) {
|
|
58
|
+
const icon = iconSpec(iconPosition, iconShape, {
|
|
59
|
+
interval: interval,
|
|
60
|
+
exchangeDuration: exchangeDuration
|
|
61
|
+
});
|
|
62
|
+
spec.series[0].extensionMark.push(icon);
|
|
63
|
+
}
|
|
64
|
+
super.transformSpec(spec);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function processData(spec) {
|
|
69
|
+
const {xField: xField, yField: yField, timeField: timeField, data: data, topN: topN = 10, icon: icon} = spec, timeNodes = new Set, timeData = new Map;
|
|
70
|
+
return data.sort(((d1, d2) => Number(d2[xField]) - Number(d1[xField]))), data.forEach((d => {
|
|
71
|
+
const time = d[timeField];
|
|
72
|
+
isValid(time) && timeNodes.add(time), timeData.has(time) || timeData.set(time, []);
|
|
73
|
+
const currentData = timeData.get(time);
|
|
74
|
+
if (currentData.length < topN) {
|
|
75
|
+
const _d = Object.assign({}, d);
|
|
76
|
+
icon && icon[_d[yField]] && (_d.icon = icon[_d[yField]]), currentData.push(_d);
|
|
77
|
+
}
|
|
78
|
+
})), {
|
|
79
|
+
timeData: timeData,
|
|
80
|
+
timeNodes: Array.from(timeNodes).sort()
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function transformAnimationSpec(spec, {interval: interval, exchangeDuration: exchangeDuration}) {
|
|
85
|
+
spec.animationAppear = !1, spec.animationUpdate = {
|
|
86
|
+
bar: [ {
|
|
87
|
+
type: "update",
|
|
88
|
+
options: {
|
|
89
|
+
excludeChannels: [ "y" ]
|
|
90
|
+
},
|
|
91
|
+
easing: "linear",
|
|
92
|
+
duration: interval
|
|
93
|
+
}, {
|
|
94
|
+
channel: [ "y" ],
|
|
95
|
+
easing: "circInOut",
|
|
96
|
+
duration: exchangeDuration
|
|
97
|
+
} ],
|
|
98
|
+
axis: {
|
|
99
|
+
duration: interval,
|
|
100
|
+
easing: "linear"
|
|
101
|
+
}
|
|
102
|
+
}, spec.animationEnter = {
|
|
103
|
+
bar: [ {
|
|
104
|
+
type: "moveIn",
|
|
105
|
+
duration: exchangeDuration,
|
|
106
|
+
easing: "cubicInOut",
|
|
107
|
+
options: {
|
|
108
|
+
direction: "y",
|
|
109
|
+
orient: "negative",
|
|
110
|
+
point: (datum, element, param) => ({
|
|
111
|
+
y: param.groupHeight + element.getBounds().height()
|
|
112
|
+
})
|
|
113
|
+
}
|
|
114
|
+
} ]
|
|
115
|
+
}, spec.animationExit = {
|
|
116
|
+
bar: [ {
|
|
117
|
+
type: "moveOut",
|
|
118
|
+
duration: exchangeDuration,
|
|
119
|
+
easing: "cubicInOut",
|
|
120
|
+
options: {
|
|
121
|
+
direction: "y",
|
|
122
|
+
orient: "negative"
|
|
123
|
+
}
|
|
124
|
+
} ]
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function labelSpec(label = {}, nameLabel, {interval: interval, exchangeDuration: exchangeDuration}) {
|
|
129
|
+
var _a, _b, _c, _e;
|
|
130
|
+
const spec = [];
|
|
131
|
+
return !1 !== label.visible && spec.push({
|
|
132
|
+
visible: !0,
|
|
133
|
+
overlap: !1,
|
|
134
|
+
style: Object.assign({
|
|
135
|
+
fill: "rgb(64, 64, 64)"
|
|
136
|
+
}, label.style),
|
|
137
|
+
smartInvert: {
|
|
138
|
+
fillStrategy: (null === (_a = label.style) || void 0 === _a ? void 0 : _a.fill) ? "null" : void 0,
|
|
139
|
+
strokeStrategy: (null === (_b = label.style) || void 0 === _b ? void 0 : _b.stroke) ? "null" : void 0
|
|
140
|
+
},
|
|
141
|
+
animationUpdate: [ {
|
|
142
|
+
duration: exchangeDuration,
|
|
143
|
+
easing: "cubicInOut",
|
|
144
|
+
channel: [ "y" ]
|
|
145
|
+
}, {
|
|
146
|
+
options: {
|
|
147
|
+
excludeChannels: [ "y" ]
|
|
148
|
+
},
|
|
149
|
+
easing: "linear",
|
|
150
|
+
duration: interval
|
|
151
|
+
} ]
|
|
152
|
+
}), nameLabel.visible && spec.push({
|
|
153
|
+
visible: !0,
|
|
154
|
+
overlap: !1,
|
|
155
|
+
style: Object.assign({}, nameLabel.style),
|
|
156
|
+
smartInvert: {
|
|
157
|
+
fillStrategy: (null === (_c = nameLabel.style) || void 0 === _c ? void 0 : _c.fill) ? "null" : void 0,
|
|
158
|
+
strokeStrategy: (null === (_e = nameLabel.style) || void 0 === _e ? void 0 : _e.stroke) ? "null" : void 0
|
|
159
|
+
},
|
|
160
|
+
position: "bar-end" === nameLabel.position ? "inside-right" : "inside-left",
|
|
161
|
+
formatter: `{${nameLabel.yField}}`,
|
|
162
|
+
animationUpdate: customMarkUpdateAnimation(interval, exchangeDuration)
|
|
163
|
+
}), spec;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function axisSpec(xAxis = {}, yAxis = {}) {
|
|
167
|
+
const leftAxis = {
|
|
168
|
+
orient: "left",
|
|
169
|
+
type: "band",
|
|
170
|
+
inverse: !0,
|
|
171
|
+
label: {
|
|
172
|
+
style: yAxis.label
|
|
173
|
+
},
|
|
174
|
+
domainLine: {
|
|
175
|
+
style: yAxis.domainLine
|
|
176
|
+
},
|
|
177
|
+
grid: {
|
|
178
|
+
style: yAxis.grid
|
|
179
|
+
}
|
|
180
|
+
}, bottomAxis = {
|
|
181
|
+
orient: "bottom",
|
|
182
|
+
type: "linear",
|
|
183
|
+
nice: !1,
|
|
184
|
+
animation: !0,
|
|
185
|
+
label: {
|
|
186
|
+
style: xAxis.label
|
|
187
|
+
},
|
|
188
|
+
domainLine: {
|
|
189
|
+
style: xAxis.domainLine
|
|
190
|
+
},
|
|
191
|
+
grid: {
|
|
192
|
+
style: xAxis.grid
|
|
193
|
+
},
|
|
194
|
+
innerOffset: {
|
|
195
|
+
right: "10%"
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
return xAxis.label && (bottomAxis.label = xAxis.label), [ leftAxis, bottomAxis ];
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function timeLabelSpec(textStyle = {}) {
|
|
202
|
+
return {
|
|
203
|
+
type: "text",
|
|
204
|
+
dataId: "time",
|
|
205
|
+
style: Object.assign({
|
|
206
|
+
textBaseline: "bottom",
|
|
207
|
+
fontSize: 200,
|
|
208
|
+
textAlign: "end",
|
|
209
|
+
fontWeight: 600,
|
|
210
|
+
text: datum => datum.time,
|
|
211
|
+
x: (datum, ctx) => {
|
|
212
|
+
var _a;
|
|
213
|
+
return (null === (_a = ctx.vchart.getChart().getCanvasRect()) || void 0 === _a ? void 0 : _a.width) - 50;
|
|
214
|
+
},
|
|
215
|
+
y: (datum, ctx) => {
|
|
216
|
+
var _a;
|
|
217
|
+
return (null === (_a = ctx.vchart.getChart().getCanvasRect()) || void 0 === _a ? void 0 : _a.height) - 80;
|
|
218
|
+
},
|
|
219
|
+
fill: "grey",
|
|
220
|
+
fillOpacity: .5
|
|
221
|
+
}, textStyle)
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function iconSpec(iconPosition = "bar-end", iconShape = "circle", {interval: interval, exchangeDuration: exchangeDuration}) {
|
|
226
|
+
return {
|
|
227
|
+
type: "symbol",
|
|
228
|
+
dataId: "timeData",
|
|
229
|
+
style: {
|
|
230
|
+
symbolType: iconShape,
|
|
231
|
+
stroke: "white",
|
|
232
|
+
lineWidth: 1,
|
|
233
|
+
size: (data, ctx) => {
|
|
234
|
+
var _a, _b;
|
|
235
|
+
const vchart = ctx.vchart, series = null === (_a = vchart.getChart()) || void 0 === _a ? void 0 : _a.getSeriesInIndex(0)[0];
|
|
236
|
+
if (vchart && series) {
|
|
237
|
+
const bandwidth = null !== (_b = series.getYAxisHelper().getBandwidth(0)) && void 0 !== _b ? _b : 0;
|
|
238
|
+
return Math.max(bandwidth - 4, 0);
|
|
239
|
+
}
|
|
240
|
+
return 10;
|
|
241
|
+
},
|
|
242
|
+
background: data => data.icon,
|
|
243
|
+
x: (data, ctx) => {
|
|
244
|
+
var _a, _b;
|
|
245
|
+
const vchart = ctx.vchart, series = null === (_a = vchart.getChart()) || void 0 === _a ? void 0 : _a.getSeriesInIndex(0)[0];
|
|
246
|
+
if (vchart && series) {
|
|
247
|
+
const bandwidth = null !== (_b = series.getYAxisHelper().getBandwidth(0)) && void 0 !== _b ? _b : 0;
|
|
248
|
+
return "bar-start" === iconPosition ? bandwidth / 2 : "axis" === iconPosition ? -bandwidth / 2 : series.dataToPositionX(data) - bandwidth / 2;
|
|
249
|
+
}
|
|
250
|
+
},
|
|
251
|
+
y: (data, ctx) => {
|
|
252
|
+
var _a, _b;
|
|
253
|
+
const vchart = ctx.vchart, series = null === (_a = vchart.getChart()) || void 0 === _a ? void 0 : _a.getSeriesInIndex(0)[0];
|
|
254
|
+
if (vchart && series) {
|
|
255
|
+
const bandwidth = null !== (_b = series.getYAxisHelper().getBandwidth(0)) && void 0 !== _b ? _b : 0;
|
|
256
|
+
return series.dataToPositionY(data) + bandwidth / 2;
|
|
257
|
+
}
|
|
258
|
+
},
|
|
259
|
+
scaleY: "rect" === iconShape ? 1.2 : 1
|
|
260
|
+
},
|
|
261
|
+
animationUpdate: customMarkUpdateAnimation(interval, exchangeDuration),
|
|
262
|
+
animationEnter: [ {
|
|
263
|
+
type: "moveIn",
|
|
264
|
+
duration: exchangeDuration,
|
|
265
|
+
easing: "cubicInOut",
|
|
266
|
+
options: {
|
|
267
|
+
direction: "y",
|
|
268
|
+
orient: "negative",
|
|
269
|
+
point: (datum, element, param) => ({
|
|
270
|
+
y: param.groupHeight + element.getBounds().height()
|
|
271
|
+
})
|
|
272
|
+
}
|
|
273
|
+
} ],
|
|
274
|
+
animationExit: [ {
|
|
275
|
+
type: "moveOut",
|
|
276
|
+
duration: exchangeDuration,
|
|
277
|
+
easing: "cubicInOut",
|
|
278
|
+
options: {
|
|
279
|
+
direction: "y",
|
|
280
|
+
orient: "negative"
|
|
281
|
+
}
|
|
282
|
+
} ]
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
function customMarkUpdateAnimation(duration, exchangeDuration) {
|
|
287
|
+
return [ {
|
|
288
|
+
duration: exchangeDuration,
|
|
289
|
+
easing: "cubicInOut",
|
|
290
|
+
channel: [ "y" ]
|
|
291
|
+
}, {
|
|
292
|
+
options: {
|
|
293
|
+
excludeChannels: [ "y" ]
|
|
294
|
+
},
|
|
295
|
+
channel: [ "x", "x2", "x1" ],
|
|
296
|
+
easing: "linear",
|
|
297
|
+
duration: duration
|
|
298
|
+
} ];
|
|
299
|
+
}
|
|
300
|
+
//# sourceMappingURL=ranking-bar-transformer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["ranking-b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,QAAQ;SACT;KACF,CAAC;AACJ,CAAC","file":"ranking-bar-transformer.js","sourcesContent":["import type { IRankingBarSpec } from './interface';\nimport type { ICartesianAxisSpec, ICommonChartSpec, ILabelSpec } from '@visactor/vchart';\nimport type { ITextGraphicAttribute } from '@visactor/vrender-core';\nimport { BaseChartSpecTransformer } from '@visactor/vchart';\nimport { isValid } from '@visactor/vutils';\n\nexport class RankingBarChartSpecTransformer<T extends ICommonChartSpec> extends BaseChartSpecTransformer<any> {\n transformSpec(spec: T): void {\n const { timeData, timeNodes } = processData(spec as unknown as IRankingBarSpec);\n const {\n interval: userInterval,\n xField,\n yField,\n color,\n icon,\n iconPosition,\n iconShape,\n timeLabel,\n label,\n nameLabel,\n xAxis,\n yAxis\n } = spec as unknown as IRankingBarSpec;\n\n const interval = userInterval ? userInterval : 1000;\n const exchangeDuration = Math.min(interval, 500);\n\n spec.type = 'common';\n spec.data = [\n {\n id: 'timeData',\n values: timeData.get(timeNodes[0])\n },\n {\n id: 'time',\n values: [{ time: timeNodes[0] }]\n }\n ];\n\n // @ts-ignore FIXME: type definition\n spec.color = {\n specified: {\n ...color\n }\n };\n spec.region = [{ clip: true }];\n spec.series = [\n {\n type: 'bar',\n id: 'ranking-bar',\n dataId: 'timeData',\n direction: 'horizontal',\n yField,\n xField,\n seriesField: yField,\n extensionMark: [],\n label: labelSpec(label, { ...nameLabel, yField }, { interval, exchangeDuration }) as any\n }\n ];\n spec.axes = axisSpec(xAxis, yAxis);\n spec.player = {\n type: 'continuous',\n auto: true,\n loop: false,\n interval,\n specs: timeNodes.map(time => ({\n data: [\n { id: 'timeData', values: timeData.get(time) },\n { id: 'time', values: [{ time }] }\n ]\n }))\n };\n spec.tooltip = { visible: false };\n spec.customMark = [];\n\n transformAnimationSpec(spec, { interval, exchangeDuration });\n\n if (!timeLabel || timeLabel.visible !== false) {\n spec.customMark.push(timeLabelSpec(timeLabel.style) as any);\n }\n if (icon) {\n const icon = iconSpec(iconPosition, iconShape, { interval, exchangeDuration });\n spec.series[0].extensionMark.push(icon as any);\n }\n\n super.transformSpec(spec);\n }\n}\n\nexport function processData(spec: IRankingBarSpec) {\n const { xField, yField, timeField, data, topN = 10, icon } = spec;\n\n // 数据处理\n const timeNodes = new Set<string>();\n const timeData = new Map();\n\n data.sort((d1, d2) => Number(d2[xField]) - Number(d1[xField]));\n\n data.forEach(d => {\n const time = d[timeField];\n if (isValid(time)) {\n timeNodes.add(time);\n }\n if (!timeData.has(time)) {\n timeData.set(time, []);\n }\n const currentData = timeData.get(time);\n if (currentData.length < topN) {\n const _d = { ...d };\n if (icon && icon[_d[yField]]) {\n _d['icon'] = icon[_d[yField]];\n }\n currentData.push(_d);\n }\n });\n\n return { timeData, timeNodes: Array.from(timeNodes).sort() };\n}\n\nfunction transformAnimationSpec(\n spec: ICommonChartSpec,\n { interval, exchangeDuration }: { interval: number; exchangeDuration: number }\n) {\n (spec as any).animationAppear = false;\n (spec as any).animationUpdate = {\n bar: [\n {\n type: 'update',\n options: { excludeChannels: ['y'] },\n easing: 'linear',\n duration: interval\n },\n {\n channel: ['y'],\n easing: 'circInOut',\n duration: exchangeDuration\n }\n ],\n axis: {\n duration: interval,\n easing: 'linear'\n }\n };\n (spec as any).animationEnter = {\n bar: [\n {\n type: 'moveIn',\n duration: exchangeDuration,\n easing: 'cubicInOut',\n options: {\n direction: 'y',\n orient: 'negative',\n point: (datum: any, element: any, param: any) => {\n return {\n y: param.groupHeight + element.getBounds().height()\n };\n }\n }\n }\n ]\n };\n (spec as any).animationExit = {\n bar: [\n {\n type: 'moveOut',\n duration: exchangeDuration,\n easing: 'cubicInOut',\n options: {\n direction: 'y',\n orient: 'negative'\n }\n }\n ]\n };\n}\n\nfunction labelSpec(\n label: IRankingBarSpec['label'] = {},\n nameLabel: IRankingBarSpec['nameLabel'] & { yField: string },\n { interval, exchangeDuration }: any\n) {\n const spec: ILabelSpec[] = [];\n\n if (label.visible !== false) {\n spec.push({\n visible: true,\n overlap: false,\n style: {\n // @ts-ignore\n fill: `rgb(64, 64, 64)`,\n ...label.style\n },\n smartInvert: {\n fillStrategy: label.style?.fill ? 'null' : undefined,\n strokeStrategy: label.style?.stroke ? 'null' : undefined\n },\n animationUpdate: [\n {\n duration: exchangeDuration,\n easing: 'cubicInOut',\n channel: ['y']\n },\n {\n options: { excludeChannels: ['y'] },\n easing: 'linear',\n duration: interval\n }\n ]\n });\n }\n\n if (nameLabel.visible) {\n spec.push({\n visible: true,\n overlap: false,\n // @ts-ignore\n style: {\n ...nameLabel.style\n },\n smartInvert: {\n fillStrategy: nameLabel.style?.fill ? 'null' : undefined,\n strokeStrategy: nameLabel.style?.stroke ? 'null' : undefined\n },\n position: nameLabel.position === 'bar-end' ? 'inside-right' : 'inside-left',\n formatter: `{${nameLabel.yField}}`,\n animationUpdate: customMarkUpdateAnimation(interval, exchangeDuration)\n });\n }\n\n return spec;\n}\n\nfunction axisSpec(xAxis: IRankingBarSpec['xAxis'] = {}, yAxis: IRankingBarSpec['yAxis'] = {}) {\n const leftAxis: ICartesianAxisSpec = {\n orient: 'left',\n type: 'band',\n inverse: true,\n label: { style: yAxis.label },\n domainLine: { style: yAxis.domainLine },\n grid: { style: yAxis.grid }\n };\n const bottomAxis: ICartesianAxisSpec = {\n orient: 'bottom',\n type: 'linear',\n nice: false,\n animation: true,\n label: { style: xAxis.label },\n domainLine: { style: xAxis.domainLine },\n grid: { style: xAxis.grid },\n innerOffset: { right: '10%' }\n };\n\n if (xAxis.label) {\n bottomAxis.label = xAxis.label;\n }\n return [leftAxis, bottomAxis];\n}\n\nfunction timeLabelSpec(textStyle: ITextGraphicAttribute = {}) {\n return {\n type: 'text',\n dataId: 'time',\n style: {\n textBaseline: 'bottom',\n fontSize: 200,\n textAlign: 'end',\n fontWeight: 600,\n text: (datum: any) => datum.time,\n x: (datum: any, ctx: any) => {\n return ctx.vchart.getChart().getCanvasRect()?.width - 50;\n },\n y: (datum: any, ctx: any) => {\n return ctx.vchart.getChart().getCanvasRect()?.height - 80;\n },\n fill: 'grey',\n fillOpacity: 0.5,\n ...textStyle\n }\n };\n}\n\nfunction iconSpec(\n iconPosition: IRankingBarSpec['iconPosition'] = 'bar-end',\n iconShape: IRankingBarSpec['iconShape'] = 'circle',\n { interval, exchangeDuration }: any\n) {\n return {\n type: 'symbol',\n dataId: 'timeData',\n style: {\n symbolType: iconShape,\n stroke: 'white',\n lineWidth: 1,\n size: (data: any, ctx: any) => {\n const vchart = ctx.vchart;\n const series = vchart.getChart()?.getSeriesInIndex(0)[0];\n if (vchart && series) {\n const bandwidth = series.getYAxisHelper().getBandwidth(0) ?? 0;\n return Math.max(bandwidth - 4, 0);\n }\n return 10;\n },\n background: (data: any) => data.icon,\n // globalZIndex 有bug,会有动画闪烁和报错\n // globalZIndex: 1, // 否则会被 region 区域 clip\n x: (data: any, ctx: any) => {\n const vchart = ctx.vchart;\n const series = vchart.getChart()?.getSeriesInIndex(0)[0];\n if (vchart && series) {\n const bandwidth = series.getYAxisHelper().getBandwidth(0) ?? 0;\n if (iconPosition === 'bar-start') {\n return bandwidth / 2;\n } else if (iconPosition === 'axis') {\n return -bandwidth / 2;\n } else {\n return series.dataToPositionX(data) - bandwidth / 2;\n }\n }\n return undefined;\n },\n y: (data: any, ctx: any) => {\n const vchart = ctx.vchart;\n const series = vchart.getChart()?.getSeriesInIndex(0)[0];\n if (vchart && series) {\n const bandwidth = series.getYAxisHelper().getBandwidth(0) ?? 0;\n return series.dataToPositionY(data) + bandwidth / 2;\n }\n return undefined;\n },\n scaleY: iconShape === 'rect' ? 1.2 : 1\n },\n animationUpdate: customMarkUpdateAnimation(interval, exchangeDuration),\n animationEnter: [\n {\n type: 'moveIn',\n duration: exchangeDuration,\n easing: 'cubicInOut',\n options: {\n direction: 'y',\n orient: 'negative',\n point: (datum: any, element: any, param: any) => {\n return {\n y: param.groupHeight + element.getBounds().height()\n };\n }\n }\n }\n ],\n animationExit: [\n {\n type: 'moveOut',\n duration: exchangeDuration,\n easing: 'cubicInOut',\n options: {\n direction: 'y',\n orient: 'negative'\n }\n }\n ]\n };\n}\n\nfunction customMarkUpdateAnimation(duration: number, exchangeDuration: number) {\n return [\n {\n duration: exchangeDuration,\n easing: 'cubicInOut',\n channel: ['y']\n },\n {\n options: { excludeChannels: ['y'] },\n channel: ['x', 'x2', 'x1'],\n easing: 'linear',\n duration\n }\n ];\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { IRankingBarSpec } from './interface';
|
|
2
|
+
import { BaseChart } from '@visactor/vchart';
|
|
3
|
+
import { RankingBarChartSpecTransformer } from './ranking-bar-transformer';
|
|
4
|
+
export declare class RankingBar extends BaseChart<Omit<IRankingBarSpec, 'color'>> {
|
|
5
|
+
type: string;
|
|
6
|
+
static type: string;
|
|
7
|
+
static readonly view: string;
|
|
8
|
+
_spec: IRankingBarSpec;
|
|
9
|
+
static readonly transformerConstructor: typeof RankingBarChartSpecTransformer;
|
|
10
|
+
readonly transformerConstructor: typeof RankingBarChartSpecTransformer;
|
|
11
|
+
init(): void;
|
|
12
|
+
protected isValid(): boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare const registerRankingBarChart: () => void;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { BaseChart, VChart } from "@visactor/vchart";
|
|
2
|
+
|
|
3
|
+
import { RankingBarChartSpecTransformer } from "./ranking-bar-transformer";
|
|
4
|
+
|
|
5
|
+
export class RankingBar extends BaseChart {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(...arguments), this.type = "rankingBar", this.transformerConstructor = RankingBarChartSpecTransformer;
|
|
8
|
+
}
|
|
9
|
+
init() {
|
|
10
|
+
this.isValid() && super.init();
|
|
11
|
+
}
|
|
12
|
+
isValid() {
|
|
13
|
+
var _a, _b, _c, _d;
|
|
14
|
+
const {xField: xField, yField: yField, timeField: timeField, data: data} = this._spec;
|
|
15
|
+
return xField && yField && timeField ? !!data || (null === (_d = (_c = this._option).onError) || void 0 === _d || _d.call(_c, "Data is required"),
|
|
16
|
+
!1) : (null === (_b = (_a = this._option).onError) || void 0 === _b || _b.call(_a, "Missing Required Config: `xField`, `yField`, `timeField` "),
|
|
17
|
+
!1);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
RankingBar.type = "rankingBar", RankingBar.view = "singleDefault", RankingBar.transformerConstructor = RankingBarChartSpecTransformer;
|
|
22
|
+
|
|
23
|
+
export const registerRankingBarChart = () => {
|
|
24
|
+
VChart.useChart([ RankingBar ]);
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=ranking-bar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["ranking-bar/ranking-bar.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,8BAA8B,EAAE,MAAM,2BAA2B,CAAC;AAE3E,MAAM,OAAO,UAAW,SAAQ,SAAyC;IAAzE;;QACE,SAAI,GAAG,YAAY,CAAC;QAOX,2BAAsB,GAAG,8BAA8B,CAAC;IAqBnE,CAAC;IAnBC,IAAI;QACF,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE;YACnB,OAAO;SACR;QACD,KAAK,CAAC,IAAI,EAAE,CAAC;IACf,CAAC;IAES,OAAO;;QACf,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;QACvD,IAAI,CAAC,MAAM,IAAI,CAAC,MAAM,IAAI,CAAC,SAAS,EAAE;YACpC,MAAA,MAAA,IAAI,CAAC,OAAO,EAAC,OAAO,mDAAG,2DAA2D,CAAC,CAAC;YACpF,OAAO,KAAK,CAAC;SACd;QACD,IAAI,CAAC,IAAI,EAAE;YACT,MAAA,MAAA,IAAI,CAAC,OAAO,EAAC,OAAO,mDAAG,kBAAkB,CAAC,CAAC;YAC3C,OAAO,KAAK,CAAC;SACd;QACD,OAAO,IAAI,CAAC;IACd,CAAC;;AA1BM,eAAI,GAAG,YAAY,CAAC;AACX,eAAI,GAAW,eAAe,CAAC;AAI/B,iCAAsB,GAAG,8BAA8B,CAAC;AAwB1E,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,EAAE;IAC1C,MAAM,CAAC,QAAQ,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC;AAChC,CAAC,CAAC","file":"ranking-bar.js","sourcesContent":["import { IRankingBarSpec } from './interface';\nimport { BaseChart, VChart } from '@visactor/vchart';\nimport { RankingBarChartSpecTransformer } from './ranking-bar-transformer';\n\nexport class RankingBar extends BaseChart<Omit<IRankingBarSpec, 'color'>> {\n type = 'rankingBar';\n static type = 'rankingBar';\n static readonly view: string = 'singleDefault';\n\n declare _spec: IRankingBarSpec;\n\n static readonly transformerConstructor = RankingBarChartSpecTransformer;\n readonly transformerConstructor = RankingBarChartSpecTransformer;\n\n init() {\n if (!this.isValid()) {\n return;\n }\n super.init();\n }\n\n protected isValid() {\n const { xField, yField, timeField, data } = this._spec;\n if (!xField || !yField || !timeField) {\n this._option.onError?.('Missing Required Config: `xField`, `yField`, `timeField` ');\n return false;\n }\n if (!data) {\n this._option.onError?.('Data is required');\n return false;\n }\n return true;\n }\n}\n\nexport const registerRankingBarChart = () => {\n VChart.useChart([RankingBar]);\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../ranking-bar/interface';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["type/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC","file":"index.js","sourcesContent":["export * from '../ranking-bar/interface';\n"]}
|
package/esm/type/type.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["type/type.ts"],"names":[],"mappings":"","file":"type.js","sourcesContent":["import type { IStage } from '@visactor/vrender-core';\n\nexport type IContext = {\n dom: string | HTMLElement;\n width: number;\n height: number;\n stage: IStage;\n canvas: HTMLCanvasElement;\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@visactor/vchart-extension",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2-alpha.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "cjs/index.js",
|
|
7
|
-
"module": "
|
|
8
|
-
"types": "
|
|
7
|
+
"module": "esm/index.js",
|
|
8
|
+
"types": "esm/index.d.ts",
|
|
9
9
|
"files": [
|
|
10
10
|
"cjs",
|
|
11
|
-
"
|
|
12
|
-
"
|
|
11
|
+
"esm",
|
|
12
|
+
"build"
|
|
13
13
|
],
|
|
14
14
|
"scripts": {
|
|
15
15
|
"compile": "tsc --noEmit",
|