Skip to content

Commit 6326ada

Browse files
committed
feat: support progressive of mark
1 parent 2727819 commit 6326ada

File tree

3 files changed

+277
-44
lines changed

3 files changed

+277
-44
lines changed

packages/vchart/src/mark/base/base-line.ts

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import type { ConvertToMarkStyleSpec, ILineLikeMarkSpec } from '../../typings/vi
44
import type { IPointLike } from '@visactor/vutils';
55
import { isFunction, isNil } from '@visactor/vutils';
66
import { BaseMark } from './base-mark';
7-
import type { IMarkGraphic, IMarkStyle } from '../interface';
7+
import { DiffState, type IMarkGraphic, type IMarkStyle } from '../interface';
88
import type { Datum } from '../../typings/common';
9-
import type { ILine, ILineGraphicAttribute } from '@visactor/vrender-core';
9+
import type { IGroup, ILine, ILineGraphicAttribute } from '@visactor/vrender-core';
1010
import { isSegmentAttrEqual } from '../utils/line';
1111
import type { IMarkSpec } from '../../typings/spec/common';
12+
import { DEFAULT_DATA_KEY } from '../../constant/data';
1213

1314
export const LINE_SEGMENT_ATTRIBUTES = [
1415
'stroke',
@@ -148,6 +149,8 @@ export abstract class BaseLineMark<T extends ILineLikeMarkSpec = ILineLikeMarkSp
148149
const lineAttrs: any[] = [];
149150
const points: IPointLike[] = [];
150151
const commonAttrs: any = {};
152+
const progressive = this.renderContext?.progressive;
153+
const isFirstFrame = progressive && progressive.currentIndex === 0;
151154

152155
data.forEach((datum: Datum, index: number) => {
153156
points[index] = {} as IPointLike;
@@ -156,9 +159,9 @@ export abstract class BaseLineMark<T extends ILineLikeMarkSpec = ILineLikeMarkSp
156159
Object.keys(newStyles).forEach(attrName => {
157160
if (this._isValidPointChannel(attrName)) {
158161
(points[index] as any)[attrName] = newStyles[attrName](datum);
159-
} else if (this._segmentStyleKeys.includes(attrName)) {
162+
} else if (this._segmentStyleKeys.includes(attrName) && !progressive) {
160163
lineAttrs[index][attrName] = newStyles[attrName](datum);
161-
} else if (index === 0) {
164+
} else if (index === 0 && (!progressive || isFirstFrame)) {
162165
commonAttrs[attrName] = newStyles[attrName](datum);
163166
}
164167
});
@@ -167,7 +170,19 @@ export abstract class BaseLineMark<T extends ILineLikeMarkSpec = ILineLikeMarkSp
167170
(points[index] as any).context = this._keyGetter(datum) ?? index;
168171
});
169172

170-
if (this._segmentStyleKeys && this._segmentStyleKeys.length) {
173+
if (progressive) {
174+
const segments = (g as any).attribute?.segments ?? [];
175+
176+
segments.push({
177+
points
178+
});
179+
return isFirstFrame
180+
? {
181+
...commonAttrs,
182+
segments
183+
}
184+
: { segments };
185+
} else if (this._segmentStyleKeys && this._segmentStyleKeys.length) {
171186
const segments = this._getLineSegments(lineAttrs, points);
172187

173188
if (segments) {
@@ -200,4 +215,48 @@ export abstract class BaseLineMark<T extends ILineLikeMarkSpec = ILineLikeMarkSp
200215
protected _getDataByKey(data: Datum[]) {
201216
return this._dataByGroup;
202217
}
218+
219+
protected _runProgressiveJoin() {
220+
const currentIndex = this.renderContext.progressive.currentIndex;
221+
const graphics: IMarkGraphic[] = [];
222+
223+
this._dataByGroup.keys.forEach((groupKey, index) => {
224+
const data = this.renderContext.progressive.groupedData.get(groupKey as string);
225+
const groupStep = this.renderContext.progressive.step;
226+
const dataSlice = data.slice(currentIndex * groupStep, (currentIndex + 1) * groupStep);
227+
228+
if (currentIndex === 0) {
229+
const g = {
230+
context: {
231+
...this._getCommonContext(),
232+
diffState: DiffState.enter,
233+
data: dataSlice,
234+
uniqueKey: groupKey,
235+
key: groupKey,
236+
groupKey: groupKey
237+
}
238+
};
239+
240+
graphics.push(g as IMarkGraphic);
241+
} else {
242+
const g = this._graphics[index];
243+
g.context.data = dataSlice;
244+
}
245+
});
246+
const res = currentIndex === 0 ? graphics : this._graphics;
247+
248+
return {
249+
graphicsByGroup: { [DEFAULT_DATA_KEY]: res },
250+
graphics: res,
251+
needUpdate: false
252+
};
253+
}
254+
255+
protected _setCommonAttributesToTheme(g: IMarkGraphic) {
256+
// do nothing in line/area
257+
}
258+
protected _addProgressiveGraphic(parent: IGroup, g: IMarkGraphic) {
259+
g.incremental = 1;
260+
(parent as IGroup).appendChild(g);
261+
}
203262
}

0 commit comments

Comments
 (0)