Skip to content

Commit

Permalink
plot line test
Browse files Browse the repository at this point in the history
  • Loading branch information
jhee564 committed Oct 19, 2021
1 parent c4839db commit 2a288eb
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 96 deletions.
34 changes: 27 additions & 7 deletions docs/views/lineChart/example/Default.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@
setup() {
const chartData = reactive({
series: {
series1: { name: 'series#1' },
series2: { name: 'series#2' },
series3: { name: 'series#3' },
series4: { name: 'series#4' },
series1: { name: 'series#1', point: false },
// series2: { name: 'series#2' },
// series3: { name: 'series#3' },
// series4: { name: 'series#4' },
},
labels: [],
data: {
series1: [],
series2: [],
series3: [],
series4: [],
// series2: [],
// series3: [],
// series4: [],
},
});
Expand All @@ -51,12 +51,32 @@
type: 'time',
timeFormat: 'HH:mm:ss',
interval: 'second',
plotLines: [{
color: '#BC80BD',
lineWidth: 2,
value: 100.5,
lineStyle: 'dash',
}, {
color: '#FF00FF',
lineWidth: 2,
value: 340.5,
}],
}],
axesY: [{
type: 'linear',
showGrid: true,
startToZero: true,
autoScaleRatio: 0.1,
plotLines: [{
color: '#FF0000',
lineWidth: 2,
value: 60.5,
lineStyle: 'dash',
}, {
color: '#000000',
lineWidth: 2,
value: 50.5,
}],
}],
};
Expand Down
136 changes: 57 additions & 79 deletions package-lock.json

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

41 changes: 31 additions & 10 deletions src/components/chart/scale/scale.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,6 @@ class Scale {
});
}
}
if (this.showIndicator) {
ctx.moveTo(linePosition, offsetPoint + 6);
ctx.lineTo(linePosition, offsetPoint);
}

if (ix !== 0 && this.showGrid) {
ctx.moveTo(linePosition, offsetPoint);
ctx.lineTo(linePosition, offsetCounterPoint);
Expand All @@ -273,11 +268,6 @@ class Scale {
linePosition += 1;
}

if (this.showIndicator) {
ctx.moveTo(offsetPoint - 6, linePosition);
ctx.lineTo(offsetPoint, linePosition);
}

if (ix !== 0 && this.showGrid) {
ctx.moveTo(offsetPoint, linePosition);
ctx.lineTo(offsetCounterPoint, linePosition);
Expand All @@ -287,6 +277,37 @@ class Scale {
ctx.stroke();
ctx.closePath();
}

// draw plot line
if (this.plotLines?.length) {
const padding = aliasPixel + 1;

this.plotLines.forEach((plotLine) => {
const { color, lineWidth, lineStyle, value } = plotLine;
ctx.beginPath();
ctx.save();
ctx.lineWidth = lineWidth;
ctx.strokeStyle = color;

if (lineStyle === 'dash') {
ctx.setLineDash([10, 5]);
}

if (this.type === 'x') {
const dp = aPos.x1 + value;
ctx.moveTo(dp, aPos.y2 + padding);
ctx.lineTo(dp, aPos.y1 + padding);
} else {
const dp = aPos.y2 - value;
ctx.moveTo(aPos.x1 + padding, dp);
ctx.lineTo(aPos.x2 + padding, dp);
}

ctx.stroke();
ctx.restore();
ctx.closePath();
});
}
}
}

Expand Down

0 comments on commit 2a288eb

Please sign in to comment.