From a560bc6209cac617c71166fcbb743469e1a21265 Mon Sep 17 00:00:00 2001 From: buhi Date: Fri, 22 Jan 2021 11:47:26 +0800 Subject: [PATCH] fix: https://github.com/apache/echarts/issues/14093 --- src/graphic/helper/subPixelOptimize.ts | 24 ++++++++++++++---------- src/graphic/shape/Line.ts | 2 +- src/graphic/shape/Rect.ts | 4 +++- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/graphic/helper/subPixelOptimize.ts b/src/graphic/helper/subPixelOptimize.ts index 6e4231108..51ba63765 100644 --- a/src/graphic/helper/subPixelOptimize.ts +++ b/src/graphic/helper/subPixelOptimize.ts @@ -32,7 +32,9 @@ type RectShape = { export function subPixelOptimizeLine( outputShape: Partial, inputShape: LineShape, - style: Pick // DO not optimize when lineWidth is 0 + style: Pick, // DO not optimize when lineWidth is 0 + scaleX: number, + scaleY: number ): LineShape { if (!inputShape) { return; @@ -53,11 +55,11 @@ export function subPixelOptimizeLine( return outputShape as LineShape; } - if (round(x1 * 2) === round(x2 * 2)) { - outputShape.x1 = outputShape.x2 = subPixelOptimize(x1, lineWidth, true); + if (round(x1 * 2 * scaleX) === round(x2 * 2 * scaleX)) { + outputShape.x1 = outputShape.x2 = subPixelOptimize(x1 * scaleX, lineWidth, true) / scaleX; } - if (round(y1 * 2) === round(y2 * 2)) { - outputShape.y1 = outputShape.y2 = subPixelOptimize(y1, lineWidth, true); + if (round(y1 * 2 * scaleY) === round(y2 * 2 * scaleY)) { + outputShape.y1 = outputShape.y2 = subPixelOptimize(y1 * scaleY, lineWidth, true) / scaleY; } return outputShape as LineShape; @@ -74,7 +76,9 @@ export function subPixelOptimizeLine( export function subPixelOptimizeRect( outputShape: Partial, inputShape: RectShape, - style: Pick // DO not optimize when lineWidth is 0 + style: Pick, // DO not optimize when lineWidth is 0 + scaleX: number, + scaleY: number ): RectShape { if (!inputShape) { return; @@ -95,14 +99,14 @@ export function subPixelOptimizeRect( return outputShape as RectShape; } - outputShape.x = subPixelOptimize(originX, lineWidth, true); - outputShape.y = subPixelOptimize(originY, lineWidth, true); + outputShape.x = subPixelOptimize(originX * scaleX, lineWidth, true) / scaleY; + outputShape.y = subPixelOptimize(originY * scaleY, lineWidth, true) / scaleY; outputShape.width = Math.max( - subPixelOptimize(originX + originWidth, lineWidth, false) - outputShape.x, + subPixelOptimize((originX + originWidth) * scaleX, lineWidth, false) / scaleX - outputShape.x, originWidth === 0 ? 0 : 1 ); outputShape.height = Math.max( - subPixelOptimize(originY + originHeight, lineWidth, false) - outputShape.y, + subPixelOptimize((originY + originHeight) * scaleX, lineWidth, false) / scaleY - outputShape.y, originHeight === 0 ? 0 : 1 ); diff --git a/src/graphic/shape/Line.ts b/src/graphic/shape/Line.ts index a4a6d2c25..152f1d7eb 100644 --- a/src/graphic/shape/Line.ts +++ b/src/graphic/shape/Line.ts @@ -52,7 +52,7 @@ class Line extends Path { if (this.subPixelOptimize) { const optimizedShape = subPixelOptimizeLine( - subPixelOptimizeOutputShape, shape, this.style + subPixelOptimizeOutputShape, shape, this.style, this.transform[0], this.transform[3] ); x1 = optimizedShape.x1; y1 = optimizedShape.y1; diff --git a/src/graphic/shape/Rect.ts b/src/graphic/shape/Rect.ts index 5968b8212..f1a82c478 100644 --- a/src/graphic/shape/Rect.ts +++ b/src/graphic/shape/Rect.ts @@ -46,7 +46,9 @@ class Rect extends Path { let height: number; if (this.subPixelOptimize) { - const optimizedShape = subPixelOptimizeRect(subPixelOptimizeOutputShape, shape, this.style); + const optimizedShape = subPixelOptimizeRect( + subPixelOptimizeOutputShape, shape, this.style, this.transform[0], this.transform[3] + ); x = optimizedShape.x; y = optimizedShape.y; width = optimizedShape.width;