Skip to content

Commit

Permalink
fix(markLine): fix subPixel in markLine #9598
Browse files Browse the repository at this point in the history
  • Loading branch information
deqingli committed Dec 19, 2018
1 parent b7b7e2f commit ddee8a4
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions src/chart/helper/Line.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,33 @@ function createSymbol(name, lineData, idx) {
return symbolPath;
}

function createLine(points) {
function createLine(points, lineWidth) {
var line = new LinePath({
name: 'line'
});
setLinePoints(line.shape, points);
setLinePoints(line.shape, points, lineWidth);
return line;
}

function setLinePoints(targetShape, points) {
var p1 = points[0];
var p2 = points[1];
function setLinePoints(targetShape, points, lineWidth) {
var subPixelParam = graphic.subPixelOptimizeLine({
shape: {
x1: points[0][0],
y1: points[0][1],
x2: points[1][0],
y2: points[1][1]
},
style: {
lineWidth: lineWidth
}
});

var shape = subPixelParam.shape;
var cp1 = points[2];
targetShape.x1 = p1[0];
targetShape.y1 = p1[1];
targetShape.x2 = p2[0];
targetShape.y2 = p2[1];
targetShape.x1 = shape.x1;
targetShape.y1 = shape.y1;
targetShape.x2 = shape.x2;
targetShape.y2 = shape.y2;
targetShape.percent = 1;

if (cp1) {
Expand Down Expand Up @@ -206,8 +217,8 @@ lineProto.beforeUpdate = updateSymbolAndLabelBeforeLineUpdate;
lineProto._createLine = function (lineData, idx, seriesScope) {
var seriesModel = lineData.hostModel;
var linePoints = lineData.getItemLayout(idx);

var line = createLine(linePoints);
var lineStyle = seriesScope && seriesScope.lineStyle;
var line = createLine(linePoints, lineStyle.lineWidth);

This comment has been minimized.

Copy link
@ezubarev

ezubarev Dec 19, 2018

@deqingli The same question for this line.

line.shape.percent = 0;
graphic.initProps(line, {
shape: {
Expand Down Expand Up @@ -242,7 +253,9 @@ lineProto.updateData = function (lineData, idx, seriesScope) {
var target = {
shape: {}
};
setLinePoints(target.shape, linePoints);
var lineStyle = seriesScope && seriesScope.lineStyle;

setLinePoints(target.shape, linePoints, lineStyle.lineWidth);

This comment has been minimized.

Copy link
@ezubarev

ezubarev Dec 19, 2018

@deqingli
I can't understand why you added this condition:
seriesScope && seriesScope.lineStyle;
If seriesScope is undefined then accesing lineStyle.lineWidth will lead to an error.

This comment has been minimized.

Copy link
@jonavila

jonavila Dec 19, 2018

Contributor

This comment has been minimized.

Copy link
@ezubarev

ezubarev Dec 20, 2018

I mean, you could simply write this:
var lineStyle = seriesScope.lineStyle;

This comment has been minimized.

Copy link
@deqingli

deqingli Dec 20, 2018

Author Member

@ezubarev It's my fault, I thought that MarkLineModel.js has the default value of lineStyle.lineWidth, so I use the value of lineStyle.lineWidth directly, without fault tolerance. I added a commit with fault tolerance. You can see if there have other questions, thank you very much for your guidance.

This comment has been minimized.

Copy link
@deqingli

deqingli Dec 20, 2018

Author Member

I mean, you could simply write this:
var lineStyle = seriesScope.lineStyle;

yes, in this situation I can, here seriesScope always be an object, I have modified this with the commit.

graphic.updateProps(line, target, seriesModel, idx);

zrUtil.each(SYMBOL_CATEGORIES, function (symbolCategory) {
Expand Down Expand Up @@ -394,7 +407,7 @@ lineProto.updateLayout = function (lineData, idx) {

lineProto.setLinePoints = function (points) {
var linePath = this.childOfName('line');
setLinePoints(linePath.shape, points);
setLinePoints(linePath.shape, points, linePath.style.lineWidth);
linePath.dirty();
};

Expand Down

0 comments on commit ddee8a4

Please sign in to comment.