Skip to content

Commit 91a60fc

Browse files
committed
fix(progressive): (1) Fix that candlestick large data progressive rendering was broken by Doji feature. (2) Fix bar large and progressive might throw NPE. (3) Follow the fixing of progressive rendering in zrender#1151 (3) Fix parallels did not clear previous rendered content when switching between progressive and normal mode. (4) Fix that chart.on('finished') event might not be called in some edge case (when multiple iterations are executed in one frame at the end).
1 parent f019371 commit 91a60fc

32 files changed

Lines changed: 1533 additions & 118 deletions

‎src/chart/bar/BarSeries.ts‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ import { inheritDefaultOption } from '../../util/component';
3737
importSeriesDatafrom'../../data/SeriesData';
3838
import{BrushCommonSelectorsForSeries}from'../../component/brush/selector';
3939
importtokensfrom'../../visual/tokens';
40+
import{preparePipelineContext}from'../../util/model';
41+
importtype{Pipeline}from'../../core/Scheduler';
42+
importtypeChartViewfrom'../../view/Chart';
4043

4144
typePolarBarLabelPositionExtra='start'|'insideStart'|'middle'|'end'|'insideEnd';
4245
exporttypePolarBarLabelPosition=SeriesLabelOption['position']|PolarBarLabelPositionExtra;
@@ -119,16 +122,18 @@ class BarSeriesModel extends BaseBarSeriesModel<BarSeriesOption> {
119122
}
120123

121124
/**
122-
* @override
125+
* @implement
123126
*/
124-
getProgressiveThreshold(){
127+
__preparePipelineContext(
128+
view: ChartView,
129+
pipeline: Pick<Pipeline,'progressiveEnabled'|'threshold'>
130+
){
131+
constcontext=preparePipelineContext(this,view,pipeline);
125132
// Do not support progressive in normal mode.
126-
letprogressiveThreshold=this.get('progressiveThreshold');
127-
constlargeThreshold=this.get('largeThreshold');
128-
if(largeThreshold>progressiveThreshold){
129-
progressiveThreshold=largeThreshold;
133+
if(context.progressiveRender){
134+
context.large=true;
130135
}
131-
returnprogressiveThreshold;
136+
returncontext;
132137
}
133138

134139
brushSelector(dataIndex: number,data: SeriesData,selectors: BrushCommonSelectorsForSeries): boolean{

‎src/chart/bar/BarView.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ import {createSectorCalculateTextPosition, SectorTextPosition, setSectorTextRota
6969
import{saveOldStyle}from'../../animation/basicTransition';
7070
importElementfrom'zrender/src/Element';
7171
import{getSectorCornerRadius}from'../helper/sectorHelper';
72+
import{getIncrementalId}from'../../util/model';
7273

7374
constmathMax=Math.max;
7475
constmathMin=Math.min;
@@ -173,7 +174,7 @@ class BarView extends ChartView {
173174
}
174175

175176
incrementalRender(params: StageHandlerProgressParams,seriesModel: BarSeriesModel): void{
176-
// Reset
177+
// Reset for eachRendered
177178
this._progressiveEls=[];
178179
// Do not support progressive in normal mode.
179180
this._incrementalRenderLarge(params,seriesModel);
@@ -1169,13 +1170,14 @@ function createLarge(
11691170

11701171
constbackgroundModel=seriesModel.getModel('backgroundStyle');
11711172
constbgPoints=data.getLayout('largeBackgroundPoints');
1173+
constincrementalId=incremental ? getIncrementalId(seriesModel) : 0;
11721174

11731175
if(bgPoints){
11741176
constbgEl=newLargePath({
11751177
shape: {
11761178
points: bgPoints
11771179
},
1178-
incremental: !!incremental,
1180+
incremental: incrementalId,
11791181
silent: true,
11801182
z2: 0
11811183
});
@@ -1190,7 +1192,7 @@ function createLarge(
11901192

11911193
constel=newLargePath({
11921194
shape: {points: data.getLayout('largePoints')},
1193-
incremental: !!incremental,
1195+
incremental: incrementalId,
11941196
ignoreCoarsePointer: true,
11951197
z2: 1
11961198
});

‎src/chart/candlestick/CandlestickView.ts‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import { saveOldStyle } from '../../animation/basicTransition';
3737
importElementfrom'zrender/src/Element';
3838
import{getBorderColor,getColor}from'./candlestickVisual';
3939
import{resolveNormalBoxClipping}from'../helper/whiskerBoxCommon';
40+
import{getIncrementalId}from'../../util/model';
4041

4142
constSKIP_PROPS=['color','borderColor']asconst;
4243

@@ -209,7 +210,7 @@ class CandlestickView extends ChartView {
209210
constel=createNormalBox(itemLayout,dataIndex,transPointDim);
210211
setBoxCommon(el,data,dataIndex,isSimpleBox);
211212

212-
el.incremental=true;
213+
el.incremental=getIncrementalId(seriesModel);
213214
this.group.add(el);
214215

215216
this._progressiveEls.push(el);
@@ -407,12 +408,13 @@ function createLarge(
407408
setLargeStyle(0,elDoji,seriesModel,data);
408409

409410
if(incremental){
410-
elP.incremental=true;
411-
elN.incremental=true;
411+
elP.incremental=getIncrementalId(seriesModel);
412+
elN.incremental=getIncrementalId(seriesModel);
413+
elDoji.incremental=getIncrementalId(seriesModel);
412414
}
413415

414416
if(progressiveEls){
415-
progressiveEls.push(elP,elN);
417+
progressiveEls.push(elP,elN,elDoji);
416418
}
417419
}
418420

‎src/chart/custom/CustomView.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ import {
108108
importtypeSeriesModelfrom'../../model/Series';
109109
import{getCustomSeries}from'./customSeriesRegister';
110110
importtokensfrom'../../visual/tokens';
111+
import{getIncrementalId}from'../../util/model';
111112

112113

113114
constEMPHASIS='emphasis'asconst;
@@ -289,7 +290,7 @@ export default class CustomChartView extends ChartView {
289290

290291
functionsetIncrementalAndHoverLayer(el: Displayable){
291292
if(!el.isGroup){
292-
el.incremental=true;
293+
el.incremental=getIncrementalId(customSeries);
293294
el.ensureState('emphasis').hoverLayer=graphicUtil.HOVER_LAYER_FOR_INCREMENTAL;
294295
}
295296
}

‎src/chart/heatmap/HeatmapView.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import { setLabelStyle, getLabelStatesModels } from '../../label/labelStyle';
3636
importtypeElementfrom'zrender/src/Element';
3737
importtypeMatrixfrom'../../coord/matrix/Matrix';
3838
import{calcBandWidth}from'../../coord/axisBand';
39+
import{getIncrementalId}from'../../util/model';
3940

4041
// Coord can be 'geo' 'bmap' 'amap' 'leaflet'...
4142
interfaceGeoLikeCoordSysextendsCoordinateSystem{
@@ -176,7 +177,7 @@ class HeatmapView extends ChartView {
176177
api: ExtensionAPI,
177178
start: number,
178179
end: number,
179-
incremental?: boolean
180+
useIncremental?: boolean
180181
){
181182
constcoordSys=seriesModel.coordinateSystemasCartesian2D|Calendar|Matrix;
182183
constisCartesian2d=isCoordinateSystemType<Cartesian2D>(coordSys,'cartesian2d');
@@ -342,9 +343,9 @@ class HeatmapView extends ChartView {
342343

343344
toggleHoverEmphasis(rect,focus,blurScope,emphasisDisabled);
344345

345-
rect.incremental=incremental;
346+
rect.incremental=getIncrementalId(seriesModel,useIncremental);
346347
// PENDING
347-
if(incremental){
348+
if(useIncremental){
348349
// Rect must use hover layer if it's incremental.
349350
rect.states.emphasis.hoverLayer=graphic.HOVER_LAYER_FOR_INCREMENTAL;
350351
}

‎src/chart/helper/LargeLineDraw.ts‎

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@ import * as lineContain from 'zrender/src/contain/line';
2424
import*asquadraticContainfrom'zrender/src/contain/quadratic';
2525
import{PathProps}from'zrender/src/graphic/Path';
2626
importSeriesDatafrom'../../data/SeriesData';
27-
import{StageHandlerProgressParams,LineStyleOption,ColorString}from'../../util/types';
27+
import{StageHandlerProgressParams,LineStyleOption,ColorString,SeriesOption}from'../../util/types';
2828
importModelfrom'../../model/Model';
2929
import{getECData}from'../../util/innerStore';
3030
importElementfrom'zrender/src/Element';
3131
importtokensfrom'../../visual/tokens';
32+
importDisplayable,{BeforeBrushParam}from'zrender/src/graphic/Displayable';
3233

3334
classLargeLinesPathShape{
3435
polyline=false;
@@ -73,6 +74,12 @@ class LargeLinesPath extends graphic.Path {
7374
this._off=0;
7475
}
7576

77+
beforeBrush(param: BeforeBrushParam){
78+
if(param&&!param.contentRetained){
79+
this.reset();
80+
}
81+
}
82+
7683
getDefaultStyle(){
7784
return{
7885
stroke: tokens.color.neutral99,
@@ -238,18 +245,16 @@ class LargeLineDraw {
238245
this._setCommon(lineEl,data);
239246
};
240247

241-
/**
242-
* @override
243-
*/
244248
incrementalPrepareUpdate(data: LargeLinesData){
245249
this.group.removeAll();
246250
this._clear();
247251
};
248252

249-
/**
250-
* @override
251-
*/
252-
incrementalUpdate(taskParams: StageHandlerProgressParams,data: LargeLinesData){
253+
incrementalUpdate(
254+
taskParams: StageHandlerProgressParams,
255+
data: LargeLinesData,
256+
incrementalId: Displayable['incremental']
257+
){
253258
constlastAdded=this._newAdded[0];
254259
constlinePoints=data.getLayout('linesPoints');
255260

@@ -272,7 +277,7 @@ class LargeLineDraw {
272277
this._newAdded=[];
273278

274279
constlineEl=this._create();
275-
lineEl.incremental=true;
280+
lineEl.incremental=incrementalId;
276281
lineEl.setShape({
277282
segs: linePoints
278283
});

‎src/chart/helper/LargeSymbolDraw.ts‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { StageHandlerProgressParams } from '../../util/types';
3131
import{CoordinateSystemClipArea}from'../../coord/CoordinateSystem';
3232
import{getECData}from'../../util/innerStore';
3333
importElementfrom'zrender/src/Element';
34+
importDisplayable,{BeforeBrushParam}from'zrender/src/graphic/Displayable';
3435

3536
constBOOST_SIZE_THRESHOLD=4;
3637

@@ -80,6 +81,12 @@ class LargeSymbolPath extends graphic.Path<LargeSymbolPathProps> {
8081
this._off=0;
8182
}
8283

84+
beforeBrush(param: BeforeBrushParam){
85+
if(param&&!param.contentRetained){
86+
this.reset();
87+
}
88+
}
89+
8390
buildPath(path: PathProxy|CanvasRenderingContext2D,shape: LargeSymbolPathShape){
8491
constpoints=shape.points;
8592
constsize=shape.size;
@@ -276,7 +283,12 @@ class LargeSymbolDraw {
276283
this._clear();
277284
}
278285

279-
incrementalUpdate(taskParams: StageHandlerProgressParams,data: SeriesData,opt: UpdateOpt){
286+
incrementalUpdate(
287+
taskParams: StageHandlerProgressParams,
288+
data: SeriesData<SeriesModel>,
289+
incrementalId: Displayable['incremental'],
290+
opt: UpdateOpt
291+
){
280292
constlastAdded=this._newAdded[0];
281293
constpoints=data.getLayout('points');
282294
constoldPoints=lastAdded&&lastAdded.shape.points;
@@ -299,7 +311,7 @@ class LargeSymbolDraw {
299311
constsymbolEl=this._create();
300312
symbolEl.startIndex=taskParams.start;
301313
symbolEl.endIndex=taskParams.end;
302-
symbolEl.incremental=true;
314+
symbolEl.incremental=incrementalId;
303315
symbolEl.setShape({
304316
points
305317
});

‎src/chart/helper/LineDraw.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,17 @@ class LineDraw {
165165
this.group.removeAll();
166166
};
167167

168-
incrementalUpdate(taskParams: StageHandlerProgressParams,lineData: ListForLineDraw){
168+
incrementalUpdate(
169+
taskParams: StageHandlerProgressParams,
170+
lineData: ListForLineDraw,
171+
incrementalId: Displayable['incremental']
172+
){
169173

170174
this._progressiveEls=[];
171175

172176
functionupdateIncrementalAndHover(el: Displayable){
173177
if(!el.isGroup&&!isEffectObject(el)){
174-
el.incremental=true;
178+
el.incremental=incrementalId;
175179
el.ensureState('emphasis').hoverLayer=graphic.HOVER_LAYER_FOR_INCREMENTAL;
176180
}
177181
}

‎src/chart/helper/SymbolDraw.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,12 @@ class SymbolDraw {
282282
/**
283283
* Update symbols draw by new data
284284
*/
285-
incrementalUpdate(taskParams: StageHandlerProgressParams,data: ListForSymbolDraw,opt?: UpdateOpt){
285+
incrementalUpdate(
286+
taskParams: StageHandlerProgressParams,
287+
data: ListForSymbolDraw,
288+
incrementalId: Displayable['incremental'],
289+
opt?: UpdateOpt
290+
){
286291

287292
// Clear
288293
this._progressiveEls=[];
@@ -291,7 +296,7 @@ class SymbolDraw {
291296

292297
functionupdateIncrementalAndHover(el: Displayable){
293298
if(!el.isGroup){
294-
el.incremental=true;
299+
el.incremental=incrementalId;
295300
el.ensureState('emphasis').hoverLayer=graphic.HOVER_LAYER_FOR_INCREMENTAL;
296301
}
297302
}

‎src/chart/lines/LinesView.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import SeriesData from '../../data/SeriesData';
3535
importtypePolarfrom'../../coord/polar/Polar';
3636
importtypeCartesian2Dfrom'../../coord/cartesian/Cartesian2D';
3737
importElementfrom'zrender/src/Element';
38+
import{getIncrementalId}from'../../util/model';
3839

3940
classLinesViewextendsChartView{
4041

@@ -118,7 +119,7 @@ class LinesView extends ChartView {
118119
seriesModel: LinesSeriesModel,
119120
ecModel: GlobalModel
120121
){
121-
this._lineDraw.incrementalUpdate(taskParams,seriesModel.getData()asany);
122+
this._lineDraw.incrementalUpdate(taskParams,seriesModel.getData()asany,getIncrementalId(seriesModel));
122123

123124
this._finished=taskParams.end===seriesModel.getData().count();
124125
}

0 commit comments

Comments
 (0)