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(scatter): fix edge scatter may be unexpectedly clipped due to tiny offset #18867

Merged
merged 4 commits into from
Jul 10, 2023
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
9 changes: 6 additions & 3 deletions src/chart/scatter/ScatterView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,12 @@ class ScatterView extends ChartView {
}

_getClipShape(seriesModel: ScatterSeriesModel) {
if (!seriesModel.get('clip', true)) {
return;
}
const coordSys = seriesModel.coordinateSystem;
const clipArea = coordSys && coordSys.getArea && coordSys.getArea();
return seriesModel.get('clip', true) ? clipArea : null;
// PENDING make `0.1` configurable, for example, `clipTolerance`?
return coordSys && coordSys.getArea && coordSys.getArea(.1);
}

_updateSymbolDraw(data: SeriesData, seriesModel: ScatterSeriesModel) {
Expand Down Expand Up @@ -131,4 +134,4 @@ class ScatterView extends ChartView {
dispose() {}
}

export default ScatterView;
export default ScatterView;
2 changes: 1 addition & 1 deletion src/coord/CoordinateSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export interface CoordinateSystem {

getRoamTransform?: () => MatrixArray;

getArea?: () => CoordinateSystemClipArea
getArea?: (tolerance?: number) => CoordinateSystemClipArea

// Only `coord/View.js` implements `getBoundingRect`.
// But if other coord sys implement it, should follow this signature.
Expand Down
12 changes: 7 additions & 5 deletions src/coord/cartesian/Cartesian2D.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,15 @@ class Cartesian2D extends Cartesian<Axis2D> implements CoordinateSystem {
* Get rect area of cartesian.
* Area will have a contain function to determine if a point is in the coordinate system.
*/
getArea(): Cartesian2DArea {
getArea(tolerance?: number): Cartesian2DArea {
tolerance = tolerance || 0;

const xExtent = this.getAxis('x').getGlobalExtent();
const yExtent = this.getAxis('y').getGlobalExtent();
const x = Math.min(xExtent[0], xExtent[1]);
const y = Math.min(yExtent[0], yExtent[1]);
const width = Math.max(xExtent[0], xExtent[1]) - x;
const height = Math.max(yExtent[0], yExtent[1]) - y;
const x = Math.min(xExtent[0], xExtent[1]) - tolerance;
const y = Math.min(yExtent[0], yExtent[1]) - tolerance;
const width = Math.max(xExtent[0], xExtent[1]) - x + tolerance;
const height = Math.max(yExtent[0], yExtent[1]) - y + tolerance;

return new BoundingRect(x, y, width, height);
}
Expand Down
8 changes: 3 additions & 5 deletions test/clip.html

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

157 changes: 157 additions & 0 deletions test/clip2.html

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

1 change: 1 addition & 0 deletions test/runTest/actions/__meta__.json

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

1 change: 1 addition & 0 deletions test/runTest/actions/clip2.json

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