Skip to content

Commit 7a39313

Browse files
authored
Merge pull request #20703 from Justin-ZS/fix/20662
feat(visualMap): add `seriesTargets` option for mapping different series -> dimension
2 parents 1e9b6e1 + b322f2c commit 7a39313

File tree

3 files changed

+176
-3
lines changed

3 files changed

+176
-3
lines changed

src/component/visualMap/VisualMapModel.ts

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ import {
3333
OptionDataValue,
3434
BuiltinVisualProperty,
3535
DimensionIndex,
36-
OptionId,
3736
ComponentOnCalendarOptionMixin,
38-
ComponentOnMatrixOptionMixin
37+
ComponentOnMatrixOptionMixin,
38+
OptionId,
3939
} from '../../util/types';
4040
import ComponentModel from '../../model/Component';
4141
import Model from '../../model/Model';
@@ -93,6 +93,16 @@ export interface VisualMapOption<T extends VisualOptionBase = VisualOptionBase>
9393
*/
9494
dimension?: number
9595

96+
/**
97+
* Series targets with specific dimensions
98+
* When provided, seriesIndex, seriesId, and dimension are ignored
99+
*/
100+
seriesTargets?: {
101+
seriesIndex?: number
102+
seriesId?: OptionId
103+
dimension: number
104+
}[]
105+
96106
/**
97107
* Visual configuration for the data in selection
98108
*/
@@ -247,6 +257,30 @@ class VisualMapModel<Opts extends VisualMapOption = VisualMapOption> extends Com
247257
* @return An array of series indices.
248258
*/
249259
protected getTargetSeriesIndices(): number[] {
260+
const seriesTargets = this.option.seriesTargets;
261+
if (seriesTargets) {
262+
// When seriesTargets is provided, collect all target series indices
263+
const indices: number[] = [];
264+
each(seriesTargets, (target) => {
265+
if (target.seriesIndex != null) {
266+
indices.push(target.seriesIndex);
267+
}
268+
else if (target.seriesId != null) {
269+
// Find series by ID
270+
let seriesModel: SeriesModel;
271+
this.ecModel.eachSeries(function (series) {
272+
if (series.id === target.seriesId) {
273+
seriesModel = series;
274+
}
275+
});
276+
if (seriesModel) {
277+
indices.push(seriesModel.componentIndex);
278+
}
279+
}
280+
});
281+
return indices;
282+
}
283+
250284
const optionSeriesId = this.option.seriesId;
251285
let optionSeriesIndex = this.option.seriesIndex;
252286
if (optionSeriesIndex == null && optionSeriesId == null) {
@@ -406,8 +440,23 @@ class VisualMapModel<Opts extends VisualMapOption = VisualMapOption> extends Com
406440
// }
407441
// }
408442

443+
getDimension(seriesIndex: number): number {
444+
const seriesTargets = this.option.seriesTargets;
445+
if (seriesTargets) {
446+
const target = zrUtil.find(seriesTargets, target =>
447+
(target.seriesIndex != null && target.seriesIndex === seriesIndex)
448+
|| (target.seriesId != null && target.seriesId === this.ecModel.getSeriesByIndex(seriesIndex).id)
449+
);
450+
if (target) {
451+
return target.dimension;
452+
}
453+
}
454+
return this.option.dimension;
455+
}
456+
409457
getDataDimensionIndex(data: SeriesData): DimensionIndex {
410-
const optDim = this.option.dimension;
458+
const seriesIndex = (data.hostModel as any).seriesIndex;
459+
const optDim = this.getDimension(seriesIndex);
411460

412461
if (optDim != null) {
413462
return data.getDimensionIndex(optDim);

src/component/visualMap/preprocessor.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,21 @@ export default function visualMapPreprocessor(option) {
5353
}
5454
});
5555
}
56+
57+
// Validate seriesTargets
58+
if (__DEV__) {
59+
const seriesTargets = opt.seriesTargets;
60+
if (seriesTargets && zrUtil.isArray(seriesTargets)) {
61+
each(seriesTargets, function (target) {
62+
if (!zrUtil.isObject(target) || target.dimension == null) {
63+
console.warn('Each seriesTarget should have a dimension property');
64+
}
65+
if (target.seriesIndex == null && target.seriesId == null) {
66+
console.warn('Each seriesTarget should have either seriesIndex or seriesId');
67+
}
68+
});
69+
}
70+
}
5671
});
5772
}
5873

test/visualmap-seriesTargets.html

Lines changed: 109 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)