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

fix: markArea display filter correction #16861

Merged
merged 11 commits into from
Apr 15, 2022
28 changes: 18 additions & 10 deletions src/component/marker/MarkAreaView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@ function ifMarkAreaHasOnlyDim(
function markAreaFilter(coordSys: CoordinateSystem, item: MarkAreaMergedItemOption) {
const fromCoord = item.coord[0];
const toCoord = item.coord[1];
const item0 = {
coord: fromCoord,
x: item.x0,
y: item.y0
};
const item1 = {
coord: toCoord,
x: item.x1,
y: item.y1
};
if (isCoordinateSystemType<Cartesian2D>(coordSys, 'cartesian2d')) {
// In case
// {
Expand All @@ -123,17 +133,15 @@ function markAreaFilter(coordSys: CoordinateSystem, item: MarkAreaMergedItemOpti
) {
return true;
}
//Directly returning true may also do the work,
//because markArea will not be shown automatically
//when it's not included in coordinate system.
//But filtering ahead can avoid keeping rendering markArea
//when there are too many of them.
return markerHelper.zoneFilter(coordSys, item0, item1);
}
return markerHelper.dataFilter(coordSys, {
coord: fromCoord,
x: item.x0,
y: item.y0
})
|| markerHelper.dataFilter(coordSys, {
coord: toCoord,
x: item.x1,
y: item.y1
});
return markerHelper.dataFilter(coordSys, item0)
|| markerHelper.dataFilter(coordSys, item1);
}

// dims can be ['x0', 'y0'], ['x1', 'y1'], ['x0', 'y1'], ['x1', 'y0']
Expand Down
13 changes: 13 additions & 0 deletions src/component/marker/markerHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,19 @@ export function dataFilter(
? coordSys.containData(item.coord) : true;
}

export function zoneFilter(
// Currently only polar and cartesian has containData.
coordSys: CoordinateSystem & {
containZone?(data1: ScaleDataValue[], data2: ScaleDataValue[]): boolean
},
item1: MarkerPositionOption,
item2: MarkerPositionOption
) {
// Alwalys return true if there is no coordSys
return (coordSys && coordSys.containZone && item1.coord && item2.coord && !hasXOrY(item1) && !hasXOrY(item2))
? coordSys.containZone(item1.coord, item2.coord) : true;
}

export function createMarkerDimValueGetter(
inCoordSys: boolean,
dims: SeriesDimensionDefine[]
Expand Down
12 changes: 12 additions & 0 deletions src/coord/cartesian/Cartesian2D.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,18 @@ class Cartesian2D extends Cartesian<Axis2D> implements CoordinateSystem {
&& this.getAxis('y').containData(data[1]);
}

containZone(data1: ScaleDataValue[], data2: ScaleDataValue[]): boolean {
const zoneDiag1 = this.dataToPoint(data1);
const zoneDiag2 = this.dataToPoint(data2);
const area = this.getArea();
const zone = new BoundingRect(
zoneDiag1[0],
zoneDiag1[1],
zoneDiag2[0] - zoneDiag1[0],
zoneDiag2[1] - zoneDiag1[1]);
return area.intersect(zone);
}

dataToPoint(data: ScaleDataValue[], clamp?: boolean, out?: number[]): number[] {
out = out || [];
const xVal = data[0];
Expand Down
93 changes: 91 additions & 2 deletions test/markArea.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/runTest/actions/__meta__.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/runTest/actions/markArea.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.