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 Sep 15, 2023
1 parent b37d67c commit e269acd
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 18 deletions.
10 changes: 5 additions & 5 deletions src/chart/bar/BarView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,12 @@ class BarView extends ChartView {
}
}

incrementalPrepareRender(seriesModel: BarSeriesModel): void {
incrementalPrepareRender(seriesModel: BarSeriesModel, ecModel: GlobalModel, api: ExtensionAPI): void {
this._clear();
this._updateDrawMode(seriesModel);
// incremental also need to clip, otherwise might be overlow.
// But must not set clip in each frame, otherwise all of the children will be marked redraw.
this._updateLargeClip(seriesModel);
this._updateLargeClip(seriesModel, ecModel, api);
}

incrementalRender(params: StageHandlerProgressParams, seriesModel: BarSeriesModel): void {
Expand Down Expand Up @@ -455,18 +455,18 @@ class BarView extends ChartView {
private _renderLarge(seriesModel: BarSeriesModel, ecModel: GlobalModel, api: ExtensionAPI): void {
this._clear();
createLarge(seriesModel, this.group);
this._updateLargeClip(seriesModel);
this._updateLargeClip(seriesModel, ecModel, api);
}

private _incrementalRenderLarge(params: StageHandlerProgressParams, seriesModel: BarSeriesModel): void {
this._removeBackground();
createLarge(seriesModel, this.group, this._progressiveEls, true);
}

private _updateLargeClip(seriesModel: BarSeriesModel): void {
private _updateLargeClip(seriesModel: BarSeriesModel, ecModel: GlobalModel, api: ExtensionAPI): void {
// Use clipPath in large mode.
const clipPath = seriesModel.get('clip', true)
&& createClipPath(seriesModel.coordinateSystem, false, seriesModel);
&& createClipPath(seriesModel.coordinateSystem, false, seriesModel, api.getDevicePixelRatio());
const group = this.group;
if (clipPath) {
group.setClipPath(clipPath);
Expand Down
6 changes: 3 additions & 3 deletions src/chart/candlestick/CandlestickView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class CandlestickView extends ChartView {
this._updateDrawMode(seriesModel);

this._isLargeDraw
? this._renderLarge(seriesModel)
? this._renderLarge(seriesModel, ecModel, api)
: this._renderNormal(seriesModel);
}

Expand Down Expand Up @@ -166,13 +166,13 @@ class CandlestickView extends ChartView {
this._data = data;
}

_renderLarge(seriesModel: CandlestickSeriesModel) {
_renderLarge(seriesModel: CandlestickSeriesModel, ecModel: GlobalModel, api: ExtensionAPI) {
this._clear();

createLarge(seriesModel, this.group);

const clipPath = seriesModel.get('clip', true)
? createClipPath(seriesModel.coordinateSystem, false, seriesModel)
? createClipPath(seriesModel.coordinateSystem, false, seriesModel, api.getDevicePixelRatio())
: null;
if (clipPath) {
this.group.setClipPath(clipPath);
Expand Down
2 changes: 1 addition & 1 deletion src/chart/custom/CustomView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ export default class CustomChartView extends ChartView {

// Do clipping
const clipPath = customSeries.get('clip', true)
? createClipPath(customSeries.coordinateSystem, false, customSeries)
? createClipPath(customSeries.coordinateSystem, false, customSeries, api.getDevicePixelRatio())
: null;
if (clipPath) {
group.setClipPath(clipPath);
Expand Down
9 changes: 6 additions & 3 deletions src/chart/helper/createClipPathFromCoordSys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ function createGridClipPath(
cartesian: Cartesian2D,
hasAnimation: boolean,
seriesModel: SeriesModelWithLineWidth,
dpr: number,
done?: () => void,
during?: (percent: number, clipRect: graphic.Rect) => void
) {
Expand All @@ -43,7 +44,8 @@ function createGridClipPath(
let width = rect.width;
let height = rect.height;

const lineWidth = seriesModel.get(['lineStyle', 'width']) || 2;
const lineWidth = (seriesModel.get(['lineStyle', 'width']) || 2) * (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 @@ -146,6 +148,7 @@ function createClipPath(
coordSys: CoordinateSystem,
hasAnimation: boolean,
seriesModel: SeriesModelWithLineWidth,
dpr: number,
done?: () => void,
during?: (percent: number) => void
) {
Expand All @@ -156,7 +159,7 @@ function createClipPath(
return createPolarClipPath(coordSys as Polar, hasAnimation, seriesModel);
}
else if (coordSys.type === 'cartesian2d') {
return createGridClipPath(coordSys as Cartesian2D, hasAnimation, seriesModel, done, during);
return createGridClipPath(coordSys as Cartesian2D, hasAnimation, seriesModel, dpr, done, during);
}
return null;
}
Expand All @@ -165,4 +168,4 @@ export {
createGridClipPath,
createPolarClipPath,
createClipPath
};
};
12 changes: 7 additions & 5 deletions src/chart/line/LineView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,8 @@ function createLineClipPath(
lineView: LineView,
coordSys: Cartesian2D | Polar,
hasAnimation: boolean,
seriesModel: LineSeriesModel
seriesModel: LineSeriesModel,
dpr: number
) {
if (isCoordinateSystemType<Cartesian2D>(coordSys, 'cartesian2d')) {
const endLabelModel = seriesModel.getModel('endLabel');
Expand All @@ -531,7 +532,7 @@ function createLineClipPath(
: null;

const isHorizontal = coordSys.getBaseAxis().isHorizontal();
const clipPath = createGridClipPath(coordSys, hasAnimation, seriesModel, () => {
const clipPath = createGridClipPath(coordSys, hasAnimation, seriesModel, dpr, () => {
const endLabel = lineView._endLabel;
if (endLabel && hasAnimation) {
if (labelAnimationRecord.originalX != null) {
Expand Down Expand Up @@ -697,6 +698,7 @@ class LineView extends ChartView {
this._clipShapeForSymbol = clipShapeForSymbol;
const visualColor = getVisualGradient(data, coordSys, api)
|| data.getVisual('style')[data.getVisual('drawType')];
const dpr = api.getDevicePixelRatio();
// Initialization animation or coordinate system changed
if (
!(polyline && prevCoordSys.type === coordSys.type && step === this._step)
Expand Down Expand Up @@ -742,7 +744,7 @@ class LineView extends ChartView {
}

lineGroup.setClipPath(
createLineClipPath(this, coordSys, true, seriesModel)
createLineClipPath(this, coordSys, true, seriesModel, dpr)
);
}
else {
Expand All @@ -766,14 +768,14 @@ class LineView extends ChartView {
// Update clipPath
const oldClipPath = lineGroup.getClipPath();
if (oldClipPath) {
const newClipPath = createLineClipPath(this, coordSys, false, seriesModel);
const newClipPath = createLineClipPath(this, coordSys, false, seriesModel, dpr);
graphic.initProps(oldClipPath, {
shape: newClipPath.shape
}, seriesModel);
}
else {
lineGroup.setClipPath(
createLineClipPath(this, coordSys, true, seriesModel)
createLineClipPath(this, coordSys, true, seriesModel, dpr)
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/chart/lines/LinesView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class LinesView extends ChartView {
lineDraw.updateData(data as SeriesData);

const clipPath = seriesModel.get('clip', true) && createClipPath(
(seriesModel.coordinateSystem as Polar | Cartesian2D), false, seriesModel
(seriesModel.coordinateSystem as Polar | Cartesian2D), false, seriesModel, api.getDevicePixelRatio()
);
if (clipPath) {
this.group.setClipPath(clipPath);
Expand Down
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 e269acd

Please sign in to comment.