Skip to content

Commit

Permalink
Merge pull request #16368 from apache/emphasis-disabled
Browse files Browse the repository at this point in the history
feat(state): add emphasis.disabled
  • Loading branch information
pissang authored Jan 14, 2022
2 parents fface60 + 1d7a820 commit a652792
Show file tree
Hide file tree
Showing 34 changed files with 343 additions and 92 deletions.
4 changes: 2 additions & 2 deletions src/chart/bar/BarView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
traverseElements
} from '../../util/graphic';
import { getECData } from '../../util/innerStore';
import { enableHoverEmphasis, setStatesStylesFromModel } from '../../util/states';
import { setStatesStylesFromModel, toggleHoverEmphasis } from '../../util/states';
import { setLabelStyle, getLabelStatesModels, setLabelValueAnimation, labelInner } from '../../label/labelStyle';
import {throttle} from '../../util/throttle';
import {createClipPath} from '../helper/createClipPathFromCoordSys';
Expand Down Expand Up @@ -1037,7 +1037,7 @@ function updateStyle(
);

const emphasisModel = itemModel.getModel(['emphasis']);
enableHoverEmphasis(el, emphasisModel.get('focus'), emphasisModel.get('blurScope'));
toggleHoverEmphasis(el, emphasisModel.get('focus'), emphasisModel.get('blurScope'), emphasisModel.get('disabled'));
setStatesStylesFromModel(el, itemModel);

if (isZeroOnPolar(layout as SectorLayout)) {
Expand Down
6 changes: 2 additions & 4 deletions src/chart/bar/PictorialBarView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@

import * as zrUtil from 'zrender/src/core/util';
import * as graphic from '../../util/graphic';
import {
enableHoverEmphasis
} from '../../util/states';
import { toggleHoverEmphasis } from '../../util/states';
import {createSymbol, normalizeSymbolOffset} from '../../util/symbol';
import {parsePercent, isNumeric} from '../../util/number';
import ChartView from '../../view/Chart';
Expand Down Expand Up @@ -928,7 +926,7 @@ function updateCommon(
}
);

enableHoverEmphasis(bar, focus, blurScope);
toggleHoverEmphasis(bar, focus, blurScope, emphasisModel.get('disabled'));
}

function toIntTimes(times: number) {
Expand Down
5 changes: 3 additions & 2 deletions src/chart/boxplot/BoxplotView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import * as zrUtil from 'zrender/src/core/util';
import ChartView from '../../view/Chart';
import * as graphic from '../../util/graphic';
import { setStatesStylesFromModel, enableHoverEmphasis } from '../../util/states';
import { setStatesStylesFromModel, toggleHoverEmphasis } from '../../util/states';
import Path, { PathProps } from 'zrender/src/graphic/Path';
import BoxplotSeriesModel, { BoxplotDataItemOption } from './BoxplotSeries';
import GlobalModel from '../../model/Global';
Expand Down Expand Up @@ -184,10 +184,11 @@ function updateNormalBoxData(
el.z2 = 100;

const itemModel = data.getItemModel<BoxplotDataItemOption>(dataIndex);
const emphasisModel = itemModel.getModel('emphasis');

setStatesStylesFromModel(el, itemModel);

enableHoverEmphasis(el, itemModel.get(['emphasis', 'focus']), itemModel.get(['emphasis', 'blurScope']));
toggleHoverEmphasis(el, emphasisModel.get('focus'), emphasisModel.get('blurScope'), emphasisModel.get('disabled'));
}

function transInit(points: number[][], dim: number, itemLayout: BoxplotItemLayout) {
Expand Down
2 changes: 2 additions & 0 deletions src/chart/custom/CustomSeries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ export type CustomElementOption = CustomPathOption
export type CustomRootElementOption = CustomElementOption & {
focus?: 'none' | 'self' | 'series' | ArrayLike<number>
blurScope?: BlurScope

emphasisDisabled?: boolean
};

export type CustomElementOptionOnState = CustomDisplayableOptionOnState
Expand Down
9 changes: 7 additions & 2 deletions src/chart/custom/CustomView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
hasOwn, assert, isString, retrieve2, retrieve3, defaults, each, indexOf
} from 'zrender/src/core/util';
import * as graphicUtil from '../../util/graphic';
import { setDefaultStateProxy, enableHoverEmphasis } from '../../util/states';
import { setDefaultStateProxy, toggleHoverEmphasis } from '../../util/states';
import * as labelStyleHelper from '../../label/labelStyle';
import {getDefaultLabel} from '../helper/labelHelper';
import {getLayoutOnAxis} from '../../layout/barGrid';
Expand Down Expand Up @@ -932,7 +932,12 @@ function createOrUpdateItem(
const el = doCreateOrUpdateEl(api, existsEl, dataIndex, elOption, seriesModel, group);
el && data.setItemGraphicEl(dataIndex, el);

el && enableHoverEmphasis(el, elOption.focus, elOption.blurScope);
el && toggleHoverEmphasis(
el,
elOption.focus,
elOption.blurScope,
elOption.emphasisDisabled
);

return el;
}
Expand Down
9 changes: 7 additions & 2 deletions src/chart/funnel/FunnelView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import * as graphic from '../../util/graphic';
import { setStatesStylesFromModel, enableHoverEmphasis } from '../../util/states';
import { setStatesStylesFromModel, toggleHoverEmphasis } from '../../util/states';
import ChartView from '../../view/Chart';
import FunnelSeriesModel, {FunnelDataItemOption} from './FunnelSeries';
import GlobalModel from '../../model/Global';
Expand Down Expand Up @@ -92,7 +92,12 @@ class FunnelPiece extends graphic.Polygon {

this._updateLabel(data, idx);

enableHoverEmphasis(this, emphasisModel.get('focus'), emphasisModel.get('blurScope'));
toggleHoverEmphasis(
this,
emphasisModel.get('focus'),
emphasisModel.get('blurScope'),
emphasisModel.get('disabled')
);
}

_updateLabel(data: SeriesData, idx: number) {
Expand Down
9 changes: 6 additions & 3 deletions src/chart/gauge/GaugeView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import PointerPath from './PointerPath';
import * as graphic from '../../util/graphic';
import { setStatesStylesFromModel, enableHoverEmphasis } from '../../util/states';
import { setStatesStylesFromModel, toggleHoverEmphasis } from '../../util/states';
import {createTextStyle, setLabelValueAnimation, animateLabelValue} from '../../label/labelStyle';
import ChartView from '../../view/Chart';
import {parsePercent, round, linearMap} from '../../util/number';
Expand Down Expand Up @@ -489,6 +489,9 @@ class GaugeView extends ChartView {
data.each(function (idx) {
const itemModel = data.getItemModel<GaugeDataItemOption>(idx);
const emphasisModel = itemModel.getModel('emphasis');
const focus = emphasisModel.get('focus');
const blurScope = emphasisModel.get('blurScope');
const emphasisDisabled = emphasisModel.get('disabled');
if (showPointer) {
const pointer = data.getItemGraphicEl(idx) as ECSymbol;
const symbolStyle = data.getItemVisual(idx, 'style');
Expand Down Expand Up @@ -517,7 +520,7 @@ class GaugeView extends ChartView {

(pointer as ECElement).z2EmphasisLift = 0;
setStatesStylesFromModel(pointer, itemModel);
enableHoverEmphasis(pointer, emphasisModel.get('focus'), emphasisModel.get('blurScope'));
toggleHoverEmphasis(pointer, focus, blurScope, emphasisDisabled);
}

if (showProgress) {
Expand All @@ -526,7 +529,7 @@ class GaugeView extends ChartView {
progress.setStyle(itemModel.getModel(['progress', 'itemStyle']).getItemStyle());
(progress as ECElement).z2EmphasisLift = 0;
setStatesStylesFromModel(progress, itemModel);
enableHoverEmphasis(progress, emphasisModel.get('focus'), emphasisModel.get('blurScope'));
toggleHoverEmphasis(progress, focus, blurScope, emphasisDisabled);
}
});

Expand Down
11 changes: 7 additions & 4 deletions src/chart/heatmap/HeatmapView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import * as graphic from '../../util/graphic';
import { enableHoverEmphasis } from '../../util/states';
import { toggleHoverEmphasis } from '../../util/states';
import HeatmapLayer from './HeatmapLayer';
import * as zrUtil from 'zrender/src/core/util';
import ChartView from '../../view/Chart';
Expand Down Expand Up @@ -206,8 +206,10 @@ class HeatmapView extends ChartView {
let blurStyle = seriesModel.getModel(['blur', 'itemStyle']).getItemStyle();
let selectStyle = seriesModel.getModel(['select', 'itemStyle']).getItemStyle();
let labelStatesModels = getLabelStatesModels(seriesModel);
let focus = seriesModel.get(['emphasis', 'focus']);
let blurScope = seriesModel.get(['emphasis', 'blurScope']);
const emphasisModel = seriesModel.getModel('emphasis');
let focus = emphasisModel.get('focus');
let blurScope = emphasisModel.get('blurScope');
let emphasisDisabled = emphasisModel.get('disabled');

const dataDims = isCoordinateSystemType<Cartesian2D>(coordSys, 'cartesian2d')
? [
Expand Down Expand Up @@ -277,6 +279,7 @@ class HeatmapView extends ChartView {

focus = emphasisModel.get('focus');
blurScope = emphasisModel.get('blurScope');
emphasisDisabled = emphasisModel.get('disabled');

labelStatesModels = getLabelStatesModels(itemModel);
}
Expand All @@ -301,7 +304,7 @@ class HeatmapView extends ChartView {
rect.ensureState('blur').style = blurStyle;
rect.ensureState('select').style = selectStyle;

enableHoverEmphasis(rect, focus, blurScope);
toggleHoverEmphasis(rect, focus, blurScope, emphasisDisabled);

rect.incremental = incremental;
// PENDING
Expand Down
13 changes: 8 additions & 5 deletions src/chart/helper/EffectSymbol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import {createSymbol, normalizeSymbolOffset, normalizeSymbolSize} from '../../util/symbol';
import {Group, Path} from '../../util/graphic';
import { enterEmphasis, leaveEmphasis, enableHoverEmphasis } from '../../util/states';
import { enterEmphasis, leaveEmphasis, toggleHoverEmphasis } from '../../util/states';
import SymbolClz from './Symbol';
import SeriesData from '../../data/SeriesData';
import type { ZRColor, ECElement } from '../../util/types';
Expand Down Expand Up @@ -173,6 +173,7 @@ class EffectSymbol extends Group {

const symbolStyle = data.getItemVisual(idx, 'style');
const color = symbolStyle && symbolStyle.fill;
const emphasisModel = itemModel.getModel('emphasis');

rippleGroup.setScale(symbolSize);

Expand Down Expand Up @@ -203,8 +204,6 @@ class EffectSymbol extends Group {
effectCfg.rippleEffectColor = itemModel.get(['rippleEffect', 'color']);
effectCfg.rippleNumber = itemModel.get(['rippleEffect', 'number']);

this.off('mouseover').off('mouseout').off('emphasis').off('normal');

if (effectCfg.showEffectOn === 'render') {
this._effectCfg
? this.updateEffectAnimation(effectCfg)
Expand Down Expand Up @@ -234,11 +233,15 @@ class EffectSymbol extends Group {

this._effectCfg = effectCfg;

enableHoverEmphasis(this);
toggleHoverEmphasis(
this,
emphasisModel.get('focus'),
emphasisModel.get('blurScope'),
emphasisModel.get('disabled')
);
};

fadeOut(cb: () => void) {
this.off('mouseover').off('mouseout');
cb && cb();
};

Expand Down
23 changes: 19 additions & 4 deletions src/chart/helper/Line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,18 @@ import * as vector from 'zrender/src/core/vector';
import * as symbolUtil from '../../util/symbol';
import ECLinePath from './LinePath';
import * as graphic from '../../util/graphic';
import { enableHoverEmphasis, enterEmphasis, leaveEmphasis, SPECIAL_STATES } from '../../util/states';
import { toggleHoverEmphasis, enterEmphasis, leaveEmphasis, SPECIAL_STATES } from '../../util/states';
import {getLabelStatesModels, setLabelStyle} from '../../label/labelStyle';
import {round} from '../../util/number';
import SeriesData from '../../data/SeriesData';
import { ZRTextAlign, ZRTextVerticalAlign, LineLabelOption, ColorString } from '../../util/types';
import {
ZRTextAlign,
ZRTextVerticalAlign,
LineLabelOption,
ColorString,
DefaultEmphasisFocus,
BlurScope
} from '../../util/types';
import SeriesModel from '../../model/Series';
import type { LineDrawSeriesScope, LineDrawModelOption } from './LineDraw';
import { TextStyleProps } from 'zrender/src/graphic/Text';
Expand Down Expand Up @@ -206,13 +213,21 @@ class Line extends graphic.Group {

let labelStatesModels = seriesScope && seriesScope.labelStatesModels;

let emphasisDisabled = seriesScope && seriesScope.emphasisDisabled;
let focus = (seriesScope && seriesScope.focus) as DefaultEmphasisFocus;
let blurScope = (seriesScope && seriesScope.blurScope) as BlurScope;

// Optimization for large dataset
if (!seriesScope || lineData.hasItemOption) {
const itemModel = lineData.getItemModel<LineDrawModelOption>(idx);
const emphasisModel = itemModel.getModel('emphasis');

emphasisLineStyle = itemModel.getModel(['emphasis', 'lineStyle']).getLineStyle();
emphasisLineStyle = emphasisModel.getModel('lineStyle').getLineStyle();
blurLineStyle = itemModel.getModel(['blur', 'lineStyle']).getLineStyle();
selectLineStyle = itemModel.getModel(['select', 'lineStyle']).getLineStyle();
emphasisDisabled = emphasisModel.get('disabled');
focus = emphasisModel.get('focus');
blurScope = emphasisModel.get('blurScope');

labelStatesModels = getLabelStatesModels(itemModel);
}
Expand Down Expand Up @@ -296,7 +311,7 @@ class Line extends graphic.Group {
inside: false // Can't be inside for stroke element.
});

enableHoverEmphasis(this);
toggleHoverEmphasis(this, focus, blurScope, emphasisDisabled);
}

highlight() {
Expand Down
20 changes: 17 additions & 3 deletions src/chart/helper/LineDraw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ import {
StatesOptionMixin,
DisplayState,
LabelOption,
StatesMixinBase
DefaultEmphasisFocus,
BlurScope
} from '../../util/types';
import Displayable from 'zrender/src/graphic/Displayable';
import Model from '../../model/Model';
Expand All @@ -53,7 +54,11 @@ interface LineDrawStateOption {
}

export interface LineDrawModelOption extends LineDrawStateOption,
StatesOptionMixin<LineDrawStateOption, StatesMixinBase> {
StatesOptionMixin<LineDrawStateOption, {
emphasis?: {
focus?: DefaultEmphasisFocus
}
}> {
// If has effect
effect?: {
show?: boolean
Expand Down Expand Up @@ -88,6 +93,10 @@ export interface LineDrawSeriesScope {
selectLineStyle?: ZRStyleProps

labelStatesModels: Record<DisplayState, Model<LabelOption>>

focus?: DefaultEmphasisFocus
blurScope?: BlurScope
emphasisDisabled?: boolean;
}

class LineDraw {
Expand Down Expand Up @@ -237,12 +246,17 @@ function isEffectObject(el: Displayable) {

function makeSeriesScope(lineData: ListForLineDraw): LineDrawSeriesScope {
const hostModel = lineData.hostModel;
const emphasisModel = hostModel.getModel('emphasis');
return {
lineStyle: hostModel.getModel('lineStyle').getLineStyle(),
emphasisLineStyle: hostModel.getModel(['emphasis', 'lineStyle']).getLineStyle(),
emphasisLineStyle: emphasisModel.getModel(['lineStyle']).getLineStyle(),
blurLineStyle: hostModel.getModel(['blur', 'lineStyle']).getLineStyle(),
selectLineStyle: hostModel.getModel(['select', 'lineStyle']).getLineStyle(),

emphasisDisabled: emphasisModel.get('disabled'),
blurScope: emphasisModel.get('blurScope'),
focus: emphasisModel.get('focus'),

labelStatesModels: getLabelStatesModels(hostModel)
};
}
Expand Down
19 changes: 14 additions & 5 deletions src/chart/helper/Polyline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
*/

import * as graphic from '../../util/graphic';
import { enableHoverEmphasis } from '../../util/states';
import { toggleHoverEmphasis } from '../../util/states';
import type { LineDrawSeriesScope, LineDrawModelOption } from './LineDraw';
import type SeriesData from '../../data/SeriesData';
import { BlurScope, DefaultEmphasisFocus } from '../../util/types';

class Polyline extends graphic.Group {
constructor(lineData: SeriesData, idx: number, seriesScope: LineDrawSeriesScope) {
Expand Down Expand Up @@ -62,19 +63,27 @@ class Polyline extends graphic.Group {
const itemModel = lineData.getItemModel<LineDrawModelOption>(idx);


let hoverLineStyle = seriesScope && seriesScope.emphasisLineStyle;
let emphasisLineStyle = seriesScope && seriesScope.emphasisLineStyle;
let focus = (seriesScope && seriesScope.focus) as DefaultEmphasisFocus;
let blurScope = (seriesScope && seriesScope.blurScope) as BlurScope;
let emphasisDisabled = seriesScope && seriesScope.emphasisDisabled;


if (!seriesScope || lineData.hasItemOption) {
hoverLineStyle = itemModel.getModel(['emphasis', 'lineStyle']).getLineStyle();
const emphasisModel = itemModel.getModel('emphasis');
emphasisLineStyle = emphasisModel.getModel('lineStyle').getLineStyle();
emphasisDisabled = emphasisModel.get('disabled');
focus = emphasisModel.get('focus');
blurScope = emphasisModel.get('blurScope');
}
line.useStyle(lineData.getItemVisual(idx, 'style'));
line.style.fill = null;
line.style.strokeNoScale = true;

const lineEmphasisState = line.ensureState('emphasis');
lineEmphasisState.style = hoverLineStyle;
lineEmphasisState.style = emphasisLineStyle;

enableHoverEmphasis(this);
toggleHoverEmphasis(this, focus, blurScope, emphasisDisabled);
};

updateLayout(lineData: SeriesData, idx: number) {
Expand Down
Loading

0 comments on commit a652792

Please sign in to comment.