@@ -4,11 +4,12 @@ import type { ConvertToMarkStyleSpec, ILineLikeMarkSpec } from '../../typings/vi
4
4
import type { IPointLike } from '@visactor/vutils' ;
5
5
import { isFunction , isNil } from '@visactor/vutils' ;
6
6
import { BaseMark } from './base-mark' ;
7
- import type { IMarkGraphic , IMarkStyle } from '../interface' ;
7
+ import { DiffState , type IMarkGraphic , type IMarkStyle } from '../interface' ;
8
8
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' ;
10
10
import { isSegmentAttrEqual } from '../utils/line' ;
11
11
import type { IMarkSpec } from '../../typings/spec/common' ;
12
+ import { DEFAULT_DATA_KEY } from '../../constant/data' ;
12
13
13
14
export const LINE_SEGMENT_ATTRIBUTES = [
14
15
'stroke' ,
@@ -148,6 +149,8 @@ export abstract class BaseLineMark<T extends ILineLikeMarkSpec = ILineLikeMarkSp
148
149
const lineAttrs : any [ ] = [ ] ;
149
150
const points : IPointLike [ ] = [ ] ;
150
151
const commonAttrs : any = { } ;
152
+ const progressive = this . renderContext ?. progressive ;
153
+ const isFirstFrame = progressive && progressive . currentIndex === 0 ;
151
154
152
155
data . forEach ( ( datum : Datum , index : number ) => {
153
156
points [ index ] = { } as IPointLike ;
@@ -156,9 +159,9 @@ export abstract class BaseLineMark<T extends ILineLikeMarkSpec = ILineLikeMarkSp
156
159
Object . keys ( newStyles ) . forEach ( attrName => {
157
160
if ( this . _isValidPointChannel ( attrName ) ) {
158
161
( points [ index ] as any ) [ attrName ] = newStyles [ attrName ] ( datum ) ;
159
- } else if ( this . _segmentStyleKeys . includes ( attrName ) ) {
162
+ } else if ( this . _segmentStyleKeys . includes ( attrName ) && ! progressive ) {
160
163
lineAttrs [ index ] [ attrName ] = newStyles [ attrName ] ( datum ) ;
161
- } else if ( index === 0 ) {
164
+ } else if ( index === 0 && ( ! progressive || isFirstFrame ) ) {
162
165
commonAttrs [ attrName ] = newStyles [ attrName ] ( datum ) ;
163
166
}
164
167
} ) ;
@@ -167,7 +170,19 @@ export abstract class BaseLineMark<T extends ILineLikeMarkSpec = ILineLikeMarkSp
167
170
( points [ index ] as any ) . context = this . _keyGetter ( datum ) ?? index ;
168
171
} ) ;
169
172
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 ) {
171
186
const segments = this . _getLineSegments ( lineAttrs , points ) ;
172
187
173
188
if ( segments ) {
@@ -200,4 +215,48 @@ export abstract class BaseLineMark<T extends ILineLikeMarkSpec = ILineLikeMarkSp
200
215
protected _getDataByKey ( data : Datum [ ] ) {
201
216
return this . _dataByGroup ;
202
217
}
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
+ }
203
262
}
0 commit comments