Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(gauge): Add data index and series index for indexing the data #14688

Merged
merged 3 commits into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/chart/gauge/GaugeView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import Sausage from '../../util/shape/sausage';
import {createSymbol} from '../../util/symbol';
import ZRImage from 'zrender/src/graphic/Image';
import {extend} from 'zrender/src/core/util';
import {setCommonECData} from '../../util/innerStore';

type ECSymbol = ReturnType<typeof createSymbol>;

Expand Down Expand Up @@ -439,6 +440,9 @@ class GaugeView extends ChartView {
}
}, seriesModel);
group.add(progress);
// Add data index and series index for indexing the data by element
// Useful in tooltip
setCommonECData(seriesModel.seriesIndex, data.dataType, idx, progress);
progressList[idx] = progress;
}
})
Expand Down Expand Up @@ -471,6 +475,9 @@ class GaugeView extends ChartView {
}
}, seriesModel);
group.add(progress);
// Add data index and series index for indexing the data by element
// Useful in tooltip
setCommonECData(seriesModel.seriesIndex, data.dataType, newIdx, progress);
progressList[newIdx] = progress;
}
})
Expand Down
30 changes: 5 additions & 25 deletions src/data/List.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {
DecalObject
} from '../util/types';
import {isDataItemOption, convertOptionIdName} from '../util/model';
import { getECData } from '../util/innerStore';
import {getECData, setCommonECData} from '../util/innerStore';
import type Graph from './Graph';
import type Tree from './Tree';
import type { VisualMeta } from '../component/visualMap/VisualMapModel';
Expand Down Expand Up @@ -180,7 +180,6 @@ let normalizeDimensions: (dimensions: ItrParamDims) => Array<DimensionLoose>;
let validateDimensions: (list: List, dims: DimensionName[]) => void;
let cloneListForMapAndSample: (original: List, excludeDimensions: DimensionName[]) => List;
let getInitialExtent: () => [number, number];
let setItemDataAndSeriesIndex: (this: Element, child: Element) => void;
let transferProperties: (target: List, source: List) => void;


Expand Down Expand Up @@ -1905,21 +1904,10 @@ class List<
* Set graphic element relative to data. It can be set as null
*/
setItemGraphicEl(idx: number, el: Element): void {
const hostModel = this.hostModel;

if (el) {
const ecData = getECData(el);
// Add data index and series index for indexing the data by element
// Useful in tooltip
ecData.dataIndex = idx;
ecData.dataType = this.dataType;
ecData.seriesIndex = hostModel && (hostModel as any).seriesIndex;

// TODO: not store dataIndex on children.
if (el.type === 'group') {
el.traverse(setItemDataAndSeriesIndex, el);
}
}
const seriesIndex = this.hostModel && (this.hostModel as any).seriesIndex;
// Add data index and series index for indexing the data by element
// Useful in tooltip
setCommonECData(seriesIndex, this.dataType, idx, el);

this._graphicEls[idx] = el;
}
Expand Down Expand Up @@ -2213,14 +2201,6 @@ class List<
return [Infinity, -Infinity];
};

setItemDataAndSeriesIndex = function (this: Element, child: Element): void {
const childECData = getECData(child);
const thisECData = getECData(this);
childECData.seriesIndex = thisECData.seriesIndex;
childECData.dataIndex = thisECData.dataIndex;
childECData.dataType = thisECData.dataType;
};

transferProperties = function (target: List, source: List): void {
zrUtil.each(
TRANSFERABLE_PROPERTIES.concat(source.__wrappedMethods || []),
Expand Down
22 changes: 22 additions & 0 deletions src/util/innerStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,26 @@ export interface ECData {
option: ComponentItemTooltipOption<unknown>;
};
}

export const getECData = makeInner<ECData, Element>();

export const setCommonECData = (seriesIndex: number, dataType: SeriesDataType, dataIdx: number, el: Element) => {
if (el) {
const ecData = getECData(el);
// Add data index and series index for indexing the data by element
// Useful in tooltip
ecData.dataIndex = dataIdx;
ecData.dataType = dataType;
ecData.seriesIndex = seriesIndex;

// TODO: not store dataIndex on children.
if (el.type === 'group') {
el.traverse(function (child: Element): void {
const childECData = getECData(child);
childECData.seriesIndex = seriesIndex;
childECData.dataIndex = dataIdx;
childECData.dataType = dataType;
});
}
}
};