Skip to content

Commit 2a234b3

Browse files
committed
feat(visualMap): able to set the 'dimension' to an array
1 parent be1028e commit 2a234b3

File tree

8 files changed

+184
-11
lines changed

8 files changed

+184
-11
lines changed

src/component/visualMap/ContinuousModel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ class ContinuousModel extends VisualMapModel<ContinousVisualMapOption> {
221221
const dataIndices: number[] = [];
222222
const data = seriesModel.getData();
223223

224-
data.each(this.getDataDimensionIndex(data), function (value: number, dataIndex) {
224+
data.each(this.getDataDimensionIndex(data, seriesModel.seriesIndex), function (value: number, dataIndex) {
225225
range[0] <= value && value <= range[1] && dataIndices.push(dataIndex);
226226
}, this);
227227

src/component/visualMap/ContinuousView.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,8 @@ class ContinuousView extends VisualMapView {
855855
}
856856

857857
const data = dataModel.getData(ecData.dataType);
858-
const value = data.getStore().get(visualMapModel.getDataDimensionIndex(data), ecData.dataIndex) as number;
858+
const value = data.getStore()
859+
.get(visualMapModel.getDataDimensionIndex(data, dataModel.seriesIndex), ecData.dataIndex) as number;
859860

860861
if (!isNaN(value)) {
861862
this._showIndicator(value, value);

src/component/visualMap/PiecewiseModel.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -313,11 +313,13 @@ class PiecewiseModel extends VisualMapModel<PiecewiseVisualMapOption> {
313313
const dataIndices: number[] = [];
314314
const data = seriesModel.getData();
315315

316-
data.each(this.getDataDimensionIndex(data), function (value: number, dataIndex: number) {
317-
// Should always base on model pieceList, because it is order sensitive.
318-
const pIdx = VisualMapping.findPieceIndex(value, pieceList);
319-
pIdx === pieceIndex && dataIndices.push(dataIndex);
320-
}, this);
316+
data.each(
317+
this.getDataDimensionIndex(data, seriesModel.seriesIndex),
318+
function (value: number, dataIndex: number) {
319+
// Should always base on model pieceList, because it is order sensitive.
320+
const pIdx = VisualMapping.findPieceIndex(value, pieceList);
321+
pIdx === pieceIndex && dataIndices.push(dataIndex);
322+
}, this);
321323

322324
result.push({seriesId: seriesModel.id, dataIndex: dataIndices});
323325
}, this);

src/component/visualMap/VisualMapModel.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export interface VisualMapOption<T extends VisualOptionBase = VisualOptionBase>
9191
/**
9292
* Dimension to be encoded
9393
*/
94-
dimension?: number
94+
dimension?: number | number[]
9595

9696
/**
9797
* Visual configuration for the data in selection
@@ -406,8 +406,17 @@ class VisualMapModel<Opts extends VisualMapOption = VisualMapOption> extends Com
406406
// }
407407
// }
408408

409-
getDataDimensionIndex(data: SeriesData): DimensionIndex {
409+
getDimension(seriesIndex: number): number {
410410
const optDim = this.option.dimension;
411+
if (isArray(optDim) && seriesIndex != null) {
412+
const idx = this.getTargetSeriesIndices().indexOf(seriesIndex);
413+
return optDim[idx] ?? optDim[optDim.length - 1];
414+
}
415+
return [].concat(optDim)[0];
416+
}
417+
418+
getDataDimensionIndex(data: SeriesData, seriesIndex: number): DimensionIndex {
419+
const optDim = this.getDimension(seriesIndex);
411420

412421
if (optDim != null) {
413422
return data.getDimensionIndex(optDim);

src/component/visualMap/visualEncoding.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export const visualMapEncodingHandlers: StageHandler[] = [
4242
visualMapModel.stateList,
4343
visualMapModel.targetVisuals,
4444
zrUtil.bind(visualMapModel.getValueState, visualMapModel),
45-
visualMapModel.getDataDimensionIndex(seriesModel.getData())
45+
visualMapModel.getDataDimensionIndex(seriesModel.getData(), seriesModel.seriesIndex)
4646
));
4747
});
4848

@@ -65,7 +65,7 @@ export const visualMapEncodingHandlers: StageHandler[] = [
6565
outerColors: []
6666
} as VisualMeta;
6767

68-
const dimIdx = visualMapModel.getDataDimensionIndex(data);
68+
const dimIdx = visualMapModel.getDataDimensionIndex(data, seriesModel.seriesIndex);
6969
if (dimIdx >= 0) {
7070
// visualMeta.dimension should be dimension index, but not concrete dimension.
7171
visualMeta.dimension = dimIdx;

test/runTest/actions/__meta__.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/runTest/actions/visualmap-dimension.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/visualmap-dimension.html

Lines changed: 159 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)