diff --git a/src/chart/scatter/ScatterView.ts b/src/chart/scatter/ScatterView.ts index 849d96a9d2..972c36e4cb 100644 --- a/src/chart/scatter/ScatterView.ts +++ b/src/chart/scatter/ScatterView.ts @@ -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) { @@ -131,4 +134,4 @@ class ScatterView extends ChartView { dispose() {} } -export default ScatterView; \ No newline at end of file +export default ScatterView; diff --git a/src/coord/CoordinateSystem.ts b/src/coord/CoordinateSystem.ts index f89235b77b..8c778ab837 100644 --- a/src/coord/CoordinateSystem.ts +++ b/src/coord/CoordinateSystem.ts @@ -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. diff --git a/src/coord/cartesian/Cartesian2D.ts b/src/coord/cartesian/Cartesian2D.ts index b0ce785552..4072684d14 100644 --- a/src/coord/cartesian/Cartesian2D.ts +++ b/src/coord/cartesian/Cartesian2D.ts @@ -178,13 +178,15 @@ class Cartesian2D extends Cartesian 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); } diff --git a/test/clip.html b/test/clip.html index 165e3f73f3..508375bfac 100644 --- a/test/clip.html +++ b/test/clip.html @@ -103,8 +103,6 @@ }) - -
+ + + + + + + + + + +
+ + +
+ + + diff --git a/test/runTest/actions/__meta__.json b/test/runTest/actions/__meta__.json index 562693a828..0d67363c0e 100644 --- a/test/runTest/actions/__meta__.json +++ b/test/runTest/actions/__meta__.json @@ -51,6 +51,7 @@ "candlestick-large2": 1, "candlestickConnect": 4, "clip": 12, + "clip2": 2, "coarse-pointer": 3, "color-mix-aqi": 2, "connect": 1, diff --git a/test/runTest/actions/clip2.json b/test/runTest/actions/clip2.json new file mode 100644 index 0000000000..e563f40376 --- /dev/null +++ b/test/runTest/actions/clip2.json @@ -0,0 +1 @@ +[{"name":"Action 1","ops":[{"type":"mousedown","time":491,"x":266,"y":91},{"type":"mouseup","time":640,"x":266,"y":91},{"time":641,"delay":400,"type":"screenshot-auto"},{"type":"mousemove","time":835,"x":265,"y":91},{"type":"mousemove","time":1035,"x":276,"y":97},{"type":"mousemove","time":1235,"x":360,"y":101},{"type":"mousemove","time":1435,"x":386,"y":99},{"type":"mousemove","time":1635,"x":399,"y":97},{"type":"mousemove","time":1839,"x":401,"y":95},{"type":"mousedown","time":1906,"x":401,"y":95},{"type":"mousemove","time":1968,"x":402,"y":95},{"type":"mouseup","time":2094,"x":402,"y":95},{"time":2095,"delay":400,"type":"screenshot-auto"},{"type":"mousemove","time":2173,"x":402,"y":95}],"scrollY":0,"scrollX":0,"timestamp":1688898127640},{"name":"Action 2","ops":[{"type":"screenshot","time":1732}],"scrollY":434.3999938964844,"scrollX":0,"timestamp":1688897861656}] \ No newline at end of file