Skip to content

Commit 9335851

Browse files
committed
fix: (1) Previously hoverLayerThreshold modification does not work. (2) Restrict the triggering of hoverLayer to only canvas renderer.
1 parent abb3ad4 commit 9335851

10 files changed

Lines changed: 53 additions & 26 deletions

File tree

‎src/chart/custom/CustomView.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ import CustomSeriesModel, {
9494
CustomRootElementOption,
9595
CustomSeriesOption,
9696
CustomCompoundPathOption,
97-
CustomSeriesRenderItemCoordinateSystemAPI
9897
}from'./CustomSeries';
9998
import{PatternObject}from'zrender/src/graphic/Pattern';
10099
import{
@@ -110,6 +109,7 @@ import type SeriesModel from '../../model/Series';
110109
import{getCustomSeries}from'./customSeriesRegister';
111110
importtokensfrom'../../visual/tokens';
112111

112+
113113
constEMPHASIS='emphasis'asconst;
114114
constNORMAL='normal'asconst;
115115
constBLUR='blur'asconst;
@@ -290,7 +290,7 @@ export default class CustomChartView extends ChartView {
290290
functionsetIncrementalAndHoverLayer(el: Displayable){
291291
if(!el.isGroup){
292292
el.incremental=true;
293-
el.ensureState('emphasis').hoverLayer=true;
293+
el.ensureState('emphasis').hoverLayer=graphicUtil.HOVER_LAYER_FOR_INCREMENTAL;
294294
}
295295
}
296296
for(letidx=params.start;idx<params.end;idx++){

‎src/chart/heatmap/HeatmapView.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ class HeatmapView extends ChartView {
346346
// PENDING
347347
if(incremental){
348348
// Rect must use hover layer if it's incremental.
349-
rect.states.emphasis.hoverLayer=true;
349+
rect.states.emphasis.hoverLayer=graphic.HOVER_LAYER_FOR_INCREMENTAL;
350350
}
351351

352352
group.add(rect);

‎src/chart/helper/LineDraw.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ class LineDraw {
172172
functionupdateIncrementalAndHover(el: Displayable){
173173
if(!el.isGroup&&!isEffectObject(el)){
174174
el.incremental=true;
175-
el.ensureState('emphasis').hoverLayer=true;
175+
el.ensureState('emphasis').hoverLayer=graphic.HOVER_LAYER_FOR_INCREMENTAL;
176176
}
177177
}
178178

‎src/chart/helper/SymbolDraw.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ class SymbolDraw {
292292
functionupdateIncrementalAndHover(el: Displayable){
293293
if(!el.isGroup){
294294
el.incremental=true;
295-
el.ensureState('emphasis').hoverLayer=true;
295+
el.ensureState('emphasis').hoverLayer=graphic.HOVER_LAYER_FOR_INCREMENTAL;
296296
}
297297
}
298298
for(letidx=taskParams.start;idx<taskParams.end;idx++){

‎src/component/legend/LegendView.ts‎

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -724,25 +724,13 @@ function dispatchSelectAction(
724724
dispatchHighlightAction(seriesName,dataName,api,excludeSeriesId);
725725
}
726726

727-
functionisUseHoverLayer(api: ExtensionAPI){
728-
constlist=api.getZr().storage.getDisplayList();
729-
letemphasisState: DisplayableState;
730-
leti=0;
731-
constlen=list.length;
732-
while(i<len&&!(emphasisState=list[i].states.emphasis)){
733-
i++;
734-
}
735-
returnemphasisState&&emphasisState.hoverLayer;
736-
}
737-
738727
functiondispatchHighlightAction(
739728
seriesName: string,
740729
dataName: string,
741730
api: ExtensionAPI,
742731
excludeSeriesId: string[]
743732
){
744-
// If element hover will move to a hoverLayer.
745-
if(!isUseHoverLayer(api)){
733+
if(!api.usingTHL()){
746734
api.dispatchAction({
747735
type: 'highlight',
748736
seriesName: seriesName,
@@ -758,8 +746,7 @@ function dispatchDownplayAction(
758746
api: ExtensionAPI,
759747
excludeSeriesId: string[]
760748
){
761-
// If element hover will move to a hoverLayer.
762-
if(!isUseHoverLayer(api)){
749+
if(!api.usingTHL()){
763750
api.dispatchAction({
764751
type: 'downplay',
765752
seriesName: seriesName,

‎src/core/ExtensionAPI.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ abstract class ExtensionAPI {
7373
abstractgetViewOfSeriesModel(seriesModel: SeriesModel): ChartView;
7474
abstractgetModel(): GlobalModel;
7575
abstractgetECMainCycleVersion(): number;
76+
/**
77+
* PENDING: a temporary method - may be refactored.
78+
* Whether a "threshold hoverLayer" is used.
79+
* `true` means using hover layer due to over `hoverLayerThreshold`.
80+
* Otherwise, if `false`, hover layer may be still used due to progressive (incremental),
81+
* but this method does not need to cover this case.
82+
*/
83+
abstractusingTHL(): boolean;
7684
}
7785

7886
exportdefaultExtensionAPI;

‎src/core/Scheduler.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import { EChartsType } from './echarts';
3434
importSeriesModelfrom'../model/Series';
3535
importChartViewfrom'../view/Chart';
3636
importSeriesDatafrom'../data/SeriesData';
37+
import{ZRenderType}from'zrender/src/zrender';
3738

3839
exporttypeGeneralTask=Task<TaskContext>;
3940
exporttypeSeriesTask=Task<SeriesTaskContext>;
@@ -233,12 +234,12 @@ class Scheduler {
233234
};
234235
}
235236

236-
restorePipelines(ecModel: GlobalModel): void{
237+
restorePipelines(zr: ZRenderType,ecModel: GlobalModel): void{
237238
constscheduler=this;
238239
constpipelineMap=scheduler._pipelineMap=createHashMap();
239240

240241
ecModel.eachSeries(function(seriesModel){
241-
constprogressive=seriesModel.getProgressive();
242+
constprogressive=zr.painter.type==='canvas'&&seriesModel.getProgressive();
242243
constpipelineId=seriesModel.uid;
243244

244245
pipelineMap.set(pipelineId,{

‎src/core/echarts.ts‎

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,11 @@ interface PostIniter {
310310
(chart: EChartsType): void
311311
}
312312

313+
constecInner=modelUtil.makeInner<{
314+
// Using hoverLayer due to over hoverLayerThreshold.
315+
usingTHL: boolean;
316+
},ECharts>();
317+
313318
typeEventMethodName='on'|'off';
314319
functioncreateRegisterEventWithLowercaseECharts(method: EventMethodName){
315320
returnfunction(this: ECharts, ...args: any): ECharts{
@@ -1638,7 +1643,7 @@ class ECharts extends Eventful<ECEventDefinition> {
16381643

16391644
constscheduler=ecIns._scheduler;
16401645

1641-
scheduler.restorePipelines(ecIns._model);
1646+
scheduler.restorePipelines(ecIns._zr,ecIns._model);
16421647
scheduler.prepareStageTasks();
16431648

16441649
prepareView(ecIns,true);
@@ -2538,6 +2543,11 @@ class ECharts extends Eventful<ECEventDefinition> {
25382543

25392544
functionupdateHoverLayerStatus(ecIns: ECharts,ecModel: GlobalModel): void{
25402545
constzr=ecIns._zr;
2546+
2547+
if(zr.painter.type!=='canvas'){
2548+
return;
2549+
}
2550+
25412551
conststorage=zr.storage;
25422552
letelCount=0;
25432553

@@ -2547,20 +2557,27 @@ class ECharts extends Eventful<ECEventDefinition> {
25472557
}
25482558
});
25492559

2550-
if(elCount>ecModel.get('hoverLayerThreshold')&&!env.node&&!env.worker){
2560+
constinner=ecInner(ecIns);
2561+
constshouldUseHoverLayer=elCount>ecModel.get('hoverLayerThreshold')&&!env.node&&!env.worker;
2562+
2563+
if(inner.usingTHL||shouldUseHoverLayer){
25512564
ecModel.eachSeries(function(seriesModel){
25522565
if(seriesModel.preventUsingHoverLayer){
25532566
return;
25542567
}
25552568
constchartView=ecIns._chartsMap[seriesModel.__viewId];
25562569
if(chartView.__alive){
25572570
chartView.eachRendered((el: ECElement)=>{
2558-
if(el.states.emphasis){
2559-
el.states.emphasis.hoverLayer=true;
2571+
constemphasis=el.states.emphasis;
2572+
if(emphasis&&emphasis.hoverLayer!==graphic.HOVER_LAYER_FOR_INCREMENTAL){
2573+
emphasis.hoverLayer=shouldUseHoverLayer
2574+
? graphic.HOVER_LAYER_FROM_THRESHOLD
2575+
: graphic.HOVER_LAYER_NO;
25602576
}
25612577
});
25622578
}
25632579
});
2580+
inner.usingTHL=shouldUseHoverLayer;
25642581
}
25652582
};
25662583

@@ -2726,6 +2743,9 @@ class ECharts extends Eventful<ECEventDefinition> {
27262743
getECMainCycleVersion(): number{
27272744
returnecIns[EC_MAIN_CYCLE_VERSION_KEY];
27282745
}
2746+
usingTHL(): boolean{
2747+
returnecInner(ecIns).usingTHL;
2748+
}
27292749
})(ecIns);
27302750
};
27312751

‎src/util/graphic.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ type ExtendShapeReturn = ReturnType<typeof Path.extend>;
9797
exportconstXY=['x','y']asconst;
9898
exportconstWH=['width','height']asconst;
9999

100+
/**
101+
* NOTICE: Only canvas renderer can set these hoverLayer flags.
102+
* @see ElementCommonState['hoverLayer']
103+
*/
104+
exportconstHOVER_LAYER_NO=0;
105+
exportconstHOVER_LAYER_FROM_THRESHOLD=1;
106+
exportconstHOVER_LAYER_FOR_INCREMENTAL=2;
107+
100108
/**
101109
* Extend shape with parameters
102110
*/

‎src/view/Chart.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,9 @@ function toggleHighlight(data: SeriesData, payload: Payload, state: DisplayState
249249
});
250250
}
251251
else{
252+
// In progressive mode, `data._graphicEls` has typically no items,
253+
// thereby skipping this hover style changing.
254+
// PENDING: more robust approaches?
252255
data.eachItemGraphicEl(function(el){
253256
elSetState(el,state,highlightDigit);
254257
});

0 commit comments

Comments
 (0)