Skip to content

Commit

Permalink
feat(state): add focus ascendant, descendant on tree
Browse files Browse the repository at this point in the history
  • Loading branch information
pissang committed Jul 15, 2020
1 parent ff88adc commit e6c0f31
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 163 deletions.
20 changes: 13 additions & 7 deletions src/chart/helper/Symbol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ import { setLabelStyle, getLabelStatesModels } from '../../label/labelStyle';

type ECSymbol = ReturnType<typeof createSymbol>;

interface SymbolOpts {
useNameLabel?: boolean
symbolInnerColor?: string
}

class Symbol extends graphic.Group {

private _seriesModel: SeriesModel;
Expand All @@ -46,9 +51,9 @@ class Symbol extends graphic.Group {

private _z2: number;

constructor(data: List, idx: number, seriesScope?: SymbolDrawSeriesScope) {
constructor(data: List, idx: number, seriesScope?: SymbolDrawSeriesScope, opts?: SymbolOpts) {
super();
this.updateData(data, idx, seriesScope);
this.updateData(data, idx, seriesScope, opts);
}

_createSymbol(
Expand Down Expand Up @@ -139,7 +144,7 @@ class Symbol extends graphic.Group {
/**
* Update symbol properties
*/
updateData(data: List, idx: number, seriesScope?: SymbolDrawSeriesScope) {
updateData(data: List, idx: number, seriesScope?: SymbolDrawSeriesScope, opts?: SymbolOpts) {
this.silent = false;

const symbolType = data.getItemVisual(idx, 'symbol') || 'circle';
Expand All @@ -160,7 +165,7 @@ class Symbol extends graphic.Group {
}, seriesModel, idx);
}

this._updateCommon(data, idx, symbolSize, seriesScope);
this._updateCommon(data, idx, symbolSize, seriesScope, opts);

if (isInit) {
const symbolPath = this.childAt(0) as ECSymbol;
Expand All @@ -187,7 +192,8 @@ class Symbol extends graphic.Group {
data: List,
idx: number,
symbolSize: number[],
seriesScope?: SymbolDrawSeriesScope
seriesScope?: SymbolDrawSeriesScope,
opts?: SymbolOpts
) {
const symbolPath = this.childAt(0) as ECSymbol;
const seriesModel = data.hostModel as SeriesModel;
Expand Down Expand Up @@ -263,7 +269,7 @@ class Symbol extends graphic.Group {
else {
symbolPath.useStyle(symbolStyle);
}
symbolPath.setColor(visualColor, seriesScope && seriesScope.symbolInnerColor);
symbolPath.setColor(visualColor, opts && opts.symbolInnerColor);
symbolPath.style.strokeNoScale = true;

const liftZ = data.getItemVisual(idx, 'liftZ');
Expand All @@ -279,7 +285,7 @@ class Symbol extends graphic.Group {
this._z2 = null;
}

const useNameLabel = seriesScope && seriesScope.useNameLabel;
const useNameLabel = opts && opts.useNameLabel;

setLabelStyle(
symbolPath, labelStatesModels,
Expand Down
3 changes: 1 addition & 2 deletions src/chart/helper/SymbolDraw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,9 @@ export interface SymbolDrawSeriesScope {

hoverAnimation?: boolean
itemModel?: Model<SymbolDrawItemModelOption>
symbolInnerColor?: ColorString

cursorStyle?: string
fadeIn?: boolean
useNameLabel?: boolean
}

function makeSeriesScope(data: List): SymbolDrawSeriesScope {
Expand Down
23 changes: 5 additions & 18 deletions src/chart/sunburst/SunburstPiece.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,24 +127,11 @@ class SunburstPiece extends graphic.Sector {
this._ecModel = ecModel || this._ecModel;

const focus = emphasisModel.get('focus');
let focusDataIndices: number[];

switch (focus) {
case 'ancestor':
focusDataIndices = [];
let currNode = node;
while (currNode) {
focusDataIndices.push(currNode.dataIndex);
currNode = currNode.parentNode;
}
break;
case 'descendant':
focusDataIndices = [];
node.eachNode(childNode => {
focusDataIndices.push(childNode.dataIndex);
});
break;
}

const focusDataIndices: number[] = focus === 'ancestor'
? node.getAncestorsIndices()
: focus === 'descendant' ? node.getDescendantIndices() : null;


enableHoverEmphasis(this, focusDataIndices || focus, emphasisModel.get('blurScope'));
}
Expand Down
Loading

0 comments on commit e6c0f31

Please sign in to comment.