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(bar-race): fix lines glitch with sub-pixel optimization in animations #14679 #17426

Merged
merged 11 commits into from
Aug 18, 2022
36 changes: 22 additions & 14 deletions src/component/axis/AxisBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,18 +269,22 @@ const builders: Record<'axisLine' | 'axisTickLabel' | 'axisName', AxisElementsBu
);

const line = new graphic.Line({
shape: {
x1: pt1[0],
y1: pt1[1],
x2: pt2[0],
y2: pt2[1]
},
shape: graphic.subPixelOptimizeLine({
shape: {
x1: pt1[0],
y1: pt1[1],
x2: pt2[0],
y2: pt2[1]
},
style: {
lineWidth: lineStyle.lineWidth
}
}).shape,
style: lineStyle,
strokeContainThreshold: opt.strokeContainThreshold || 5,
silent: true,
z2: 1
});
graphic.setSubPixelOptimizeLine(line);
line.anid = 'line';
Ovilia marked this conversation as resolved.
Show resolved Hide resolved
group.add(line);

Expand Down Expand Up @@ -628,18 +632,22 @@ function createTicks(
}
// Tick line, Not use group transform to have better line draw
const tickEl = new graphic.Line({
shape: {
x1: pt1[0],
y1: pt1[1],
x2: pt2[0],
y2: pt2[1]
},
shape: graphic.subPixelOptimizeLine({
shape: {
x1: pt1[0],
y1: pt1[1],
x2: pt2[0],
y2: pt2[1]
},
style: {
lineWidth: tickLineStyle.lineWidth
}
}).shape,
style: tickLineStyle,
z2: 2,
autoBatch: true,
silent: true
});
graphic.setSubPixelOptimizeLine(tickEl);
tickEl.anid = anidPrefix + '_' + ticksCoords[i].tickValue;
tickEls.push(tickEl);
}
Expand Down
36 changes: 22 additions & 14 deletions src/component/axis/CartesianAxisView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,18 +162,22 @@ const axisElementBuilders: Record<typeof selfBuilderAttrs[number], AxisElementBu
const line = new graphic.Line({
Ovilia marked this conversation as resolved.
Show resolved Hide resolved
anid: tickValue != null ? 'line_' + ticksCoords[i].tickValue : null,
autoBatch: true,
shape: {
x1: p1[0],
y1: p1[1],
x2: p2[0],
y2: p2[1]
},
shape: graphic.subPixelOptimizeLine({
shape: {
x1: p1[0],
y1: p1[1],
x2: p2[0],
y2: p2[1]
},
style: {
lineWidth: lineStyle.lineWidth
}
}).shape,
style: zrUtil.defaults({
stroke: lineColors[colorIndex]
}, lineStyle),
silent: true
});
graphic.setSubPixelOptimizeLine(line);
axisGroup.add(line);
}
},
Expand Down Expand Up @@ -216,16 +220,20 @@ const axisElementBuilders: Record<typeof selfBuilderAttrs[number], AxisElementBu
const line = new graphic.Line({
Ovilia marked this conversation as resolved.
Show resolved Hide resolved
anid: 'minor_line_' + minorTicksCoords[i][k].tickValue,
autoBatch: true,
shape: {
x1: p1[0],
y1: p1[1],
x2: p2[0],
y2: p2[1]
},
shape: graphic.subPixelOptimizeLine({
shape: {
x1: p1[0],
y1: p1[1],
x2: p2[0],
y2: p2[1]
},
style: {
lineWidth: lineStyle.lineWidth
}
}).shape,
style: lineStyle,
silent: true
});
graphic.setSubPixelOptimizeLine(line);
axisGroup.add(line);
}
}
Expand Down
19 changes: 11 additions & 8 deletions src/component/axis/SingleAxisView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,19 @@ const axisElementBuilders: Record<typeof selfBuilderAttrs[number], AxisElementBu
}

const line = new graphic.Line({
subPixelOptimize: false,
shape: {
x1: p1[0],
y1: p1[1],
x2: p2[0],
y2: p2[1]
},
shape: graphic.subPixelOptimizeLine({
shape: {
x1: p1[0],
y1: p1[1],
x2: p2[0],
y2: p2[1]
},
style: {
lineWidth: lineWidth
}
}).shape,
silent: true
});
graphic.setSubPixelOptimizeLine(line, lineWidth);

const colorIndex = (lineCount++) % lineColors.length;
splitLines[colorIndex] = splitLines[colorIndex] || [];
Expand Down
21 changes: 0 additions & 21 deletions src/util/graphic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,27 +281,6 @@ export function subPixelOptimizeLine(param: {
return param;
}

/**
* Set the line with the optimized shape.
*
* @param line the line shape to set
* @param lineWidth the line width, if not given, line.style.lineWidth is used
*/
export function setSubPixelOptimizeLine(line: Line, lineWidth?: number) {
const lineSubpixelParams = subPixelOptimizeLine({
shape: line.shape,
style: {
lineWidth: retrieve2(lineWidth, line.style.lineWidth)
}
});
const lineShape = line.shape;
const subPixelShape = lineSubpixelParams.shape;
lineShape.x1 = subPixelShape.x1;
lineShape.y1 = subPixelShape.y1;
lineShape.x2 = subPixelShape.x2;
lineShape.y2 = subPixelShape.y2;
}

/**
* Sub pixel optimize rect for canvas
*/
Expand Down