Skip to content

Commit a5257e3

Browse files
authored
Merge pull request #16861 from jiawulin001/issue#16853
fix: markArea display filter correction
2 parents b2168d5 + cc3f4a7 commit a5257e3

File tree

6 files changed

+136
-14
lines changed

6 files changed

+136
-14
lines changed

src/component/marker/MarkAreaView.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,16 @@ function ifMarkAreaHasOnlyDim(
109109
function markAreaFilter(coordSys: CoordinateSystem, item: MarkAreaMergedItemOption) {
110110
const fromCoord = item.coord[0];
111111
const toCoord = item.coord[1];
112+
const item0 = {
113+
coord: fromCoord,
114+
x: item.x0,
115+
y: item.y0
116+
};
117+
const item1 = {
118+
coord: toCoord,
119+
x: item.x1,
120+
y: item.y1
121+
};
112122
if (isCoordinateSystemType<Cartesian2D>(coordSys, 'cartesian2d')) {
113123
// In case
114124
// {
@@ -123,17 +133,15 @@ function markAreaFilter(coordSys: CoordinateSystem, item: MarkAreaMergedItemOpti
123133
) {
124134
return true;
125135
}
136+
//Directly returning true may also do the work,
137+
//because markArea will not be shown automatically
138+
//when it's not included in coordinate system.
139+
//But filtering ahead can avoid keeping rendering markArea
140+
//when there are too many of them.
141+
return markerHelper.zoneFilter(coordSys, item0, item1);
126142
}
127-
return markerHelper.dataFilter(coordSys, {
128-
coord: fromCoord,
129-
x: item.x0,
130-
y: item.y0
131-
})
132-
|| markerHelper.dataFilter(coordSys, {
133-
coord: toCoord,
134-
x: item.x1,
135-
y: item.y1
136-
});
143+
return markerHelper.dataFilter(coordSys, item0)
144+
|| markerHelper.dataFilter(coordSys, item1);
137145
}
138146

139147
// dims can be ['x0', 'y0'], ['x1', 'y1'], ['x0', 'y1'], ['x1', 'y0']

src/component/marker/markerHelper.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,19 @@ export function dataFilter(
196196
? coordSys.containData(item.coord) : true;
197197
}
198198

199+
export function zoneFilter(
200+
// Currently only polar and cartesian has containData.
201+
coordSys: CoordinateSystem & {
202+
containZone?(data1: ScaleDataValue[], data2: ScaleDataValue[]): boolean
203+
},
204+
item1: MarkerPositionOption,
205+
item2: MarkerPositionOption
206+
) {
207+
// Alwalys return true if there is no coordSys
208+
return (coordSys && coordSys.containZone && item1.coord && item2.coord && !hasXOrY(item1) && !hasXOrY(item2))
209+
? coordSys.containZone(item1.coord, item2.coord) : true;
210+
}
211+
199212
export function createMarkerDimValueGetter(
200213
inCoordSys: boolean,
201214
dims: SeriesDimensionDefine[]

src/coord/cartesian/Cartesian2D.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,18 @@ class Cartesian2D extends Cartesian<Axis2D> implements CoordinateSystem {
105105
&& this.getAxis('y').containData(data[1]);
106106
}
107107

108+
containZone(data1: ScaleDataValue[], data2: ScaleDataValue[]): boolean {
109+
const zoneDiag1 = this.dataToPoint(data1);
110+
const zoneDiag2 = this.dataToPoint(data2);
111+
const area = this.getArea();
112+
const zone = new BoundingRect(
113+
zoneDiag1[0],
114+
zoneDiag1[1],
115+
zoneDiag2[0] - zoneDiag1[0],
116+
zoneDiag2[1] - zoneDiag1[1]);
117+
return area.intersect(zone);
118+
}
119+
108120
dataToPoint(data: ScaleDataValue[], clamp?: boolean, out?: number[]): number[] {
109121
out = out || [];
110122
const xVal = data[0];

test/markArea.html

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

test/runTest/actions/__meta__.json

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

test/runTest/actions/markArea.json

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

0 commit comments

Comments
 (0)