前端渲染算法优化
This commit is contained in:
@@ -234,7 +234,7 @@ class AreaChart {
|
||||
drawArea(ctx, values, getX, getY, chartH, p, fillColorTop, fillColorBottom, strokeColor, len) {
|
||||
if (!values || values.length === 0) return;
|
||||
|
||||
const useSimple = len > 500;
|
||||
const useSimple = len > 250;
|
||||
|
||||
// Fill
|
||||
ctx.beginPath();
|
||||
@@ -469,16 +469,20 @@ class MetricChart {
|
||||
});
|
||||
|
||||
} else {
|
||||
// Draw Single Line Path
|
||||
const useSimple = len > 250;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(getX(0), getY(values[0]));
|
||||
for (let i = 1; i < len; i++) {
|
||||
const prevX = getX(i - 1);
|
||||
const currX = getX(i);
|
||||
const prevY = getY(values[i - 1]);
|
||||
const currY = getY(values[i]);
|
||||
const midX = (prevX + currX) / 2;
|
||||
ctx.bezierCurveTo(midX, prevY, midX, currY, currX, currY);
|
||||
if (useSimple) {
|
||||
ctx.lineTo(getX(i), getY(values[i]));
|
||||
} else {
|
||||
const prevX = getX(i - 1);
|
||||
const currX = getX(i);
|
||||
const prevY = getY(values[i - 1]);
|
||||
const currY = getY(values[i]);
|
||||
const midX = (prevX + currX) / 2;
|
||||
ctx.bezierCurveTo(midX, prevY, midX, currY, currX, currY);
|
||||
}
|
||||
}
|
||||
|
||||
// Stroke
|
||||
|
||||
Reference in New Issue
Block a user