Skip to content

Commit

Permalink
fix(clip): calculate with dpr when extending clip path. close #19051
Browse files Browse the repository at this point in the history
  • Loading branch information
RexSkz committed Aug 30, 2023
1 parent bb1e18c commit cff1a3d
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/chart/helper/createClipPathFromCoordSys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import type Cartesian2D from '../../coord/cartesian/Cartesian2D';
import type Polar from '../../coord/polar/Polar';
import { CoordinateSystem } from '../../coord/CoordinateSystem';
import { isFunction } from 'zrender/src/core/util';
import CanvasPainter from 'zrender/src/canvas/Painter';

type SeriesModelWithLineWidth = SeriesModel<SeriesOption & {
lineStyle?: { width?: number }
Expand All @@ -43,7 +44,14 @@ function createGridClipPath(
let width = rect.width;
let height = rect.height;

const lineWidth = seriesModel.get(['lineStyle', 'width']) || 2;
const zr = cartesian.model.ecModel.scheduler.ecInstance.getZr();
const dpr = zr.painter instanceof CanvasPainter
? zr.painter.dpr
: window.devicePixelRatio; /* global window */

const _lineWidth = seriesModel.get(['lineStyle', 'width']) || 2;
const lineWidth = _lineWidth * (dpr || 1);

// Expand the clip path a bit to avoid the border is clipped and looks thinner
x -= lineWidth / 2;
y -= lineWidth / 2;
Expand Down Expand Up @@ -165,4 +173,4 @@ export {
createGridClipPath,
createPolarClipPath,
createClipPath
};
};
93 changes: 93 additions & 0 deletions test/clip-line-cap.html

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

0 comments on commit cff1a3d

Please sign in to comment.