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
import tokens from '../../visual/tokens';
112111

112+
113113
const EMPHASIS = 'emphasis' as const;
114114
const NORMAL = 'normal' as const;
115115
const BLUR = 'blur' as const;
@@ -290,7 +290,7 @@ export default class CustomChartView extends ChartView {
290290
function setIncrementalAndHoverLayer(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 (let idx = 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
function updateIncrementalAndHover(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
function updateIncrementalAndHover(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 (let idx = 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-
function isUseHoverLayer(api: ExtensionAPI) {
728-
const list = api.getZr().storage.getDisplayList();
729-
let emphasisState: DisplayableState;
730-
let i = 0;
731-
const len = list.length;
732-
while (i < len && !(emphasisState = list[i].states.emphasis)) {
733-
i++;
734-
}
735-
return emphasisState && emphasisState.hoverLayer;
736-
}
737-
738727
function dispatchHighlightAction(
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
abstract getViewOfSeriesModel(seriesModel: SeriesModel): ChartView;
7474
abstract getModel(): GlobalModel;
7575
abstract getECMainCycleVersion(): 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+
abstract usingTHL(): boolean;
7684
}
7785

7886
export default ExtensionAPI;

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
import SeriesModel from '../model/Series';
3535
import ChartView from '../view/Chart';
3636
import SeriesData from '../data/SeriesData';
37+
import { ZRenderType } from 'zrender/src/zrender';
3738

3839
export type GeneralTask = Task<TaskContext>;
3940
export type SeriesTask = Task<SeriesTaskContext>;
@@ -233,12 +234,12 @@ class Scheduler {
233234
};
234235
}
235236

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

240241
ecModel.eachSeries(function (seriesModel) {
241-
const progressive = seriesModel.getProgressive();
242+
const progressive = zr.painter.type === 'canvas' && seriesModel.getProgressive();
242243
const pipelineId = 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+
const ecInner = modelUtil.makeInner<{
314+
// Using hoverLayer due to over hoverLayerThreshold.
315+
usingTHL: boolean;
316+
}, ECharts>();
317+
313318
type EventMethodName = 'on' | 'off';
314319
function createRegisterEventWithLowercaseECharts(method: EventMethodName) {
315320
return function (this: ECharts, ...args: any): ECharts {
@@ -1638,7 +1643,7 @@ class ECharts extends Eventful<ECEventDefinition> {
16381643

16391644
const scheduler = 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
function updateHoverLayerStatus(ecIns: ECharts, ecModel: GlobalModel): void {
25402545
const zr = ecIns._zr;
2546+
2547+
if (zr.painter.type !== 'canvas') {
2548+
return;
2549+
}
2550+
25412551
const storage = zr.storage;
25422552
let elCount = 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+
const inner = ecInner(ecIns);
2561+
const shouldUseHoverLayer = 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
const chartView = 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+
const emphasis = 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
return ecIns[EC_MAIN_CYCLE_VERSION_KEY];
27282745
}
2746+
usingTHL(): boolean {
2747+
return ecInner(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
export const XY = ['x', 'y'] as const;
9898
export const WH = ['width', 'height'] as const;
9999

100+
/**
101+
* NOTICE: Only canvas renderer can set these hoverLayer flags.
102+
* @see ElementCommonState['hoverLayer']
103+
*/
104+
export const HOVER_LAYER_NO = 0;
105+
export const HOVER_LAYER_FROM_THRESHOLD = 1;
106+
export const HOVER_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)