|
|
@ -29,6 +29,7 @@ export default function StandardLayer(props: { |
|
|
|
bottomPadding: number; |
|
|
|
columns: number; |
|
|
|
rows: number; |
|
|
|
visibility: "hidden" | "visible"; |
|
|
|
}) { |
|
|
|
const xStartPx = props.leftPadding; |
|
|
|
const xEndPx = props.width - props.rightPadding; |
|
|
@ -45,33 +46,14 @@ export default function StandardLayer(props: { |
|
|
|
|
|
|
|
const draw = useCallback( |
|
|
|
(ctx: CanvasRenderingContext2D) => { |
|
|
|
ctx.strokeStyle = "#999"; |
|
|
|
ctx.resetTransform(); |
|
|
|
ctx.clearRect(0, 0, props.width, props.height); |
|
|
|
// 偏移原点
|
|
|
|
const xOffset = (xEndPx - xStartPx) / 2; |
|
|
|
const yOffset = yStepPx * 2; |
|
|
|
const yMax = yEndPx - yStartPx - yOffset; |
|
|
|
ctx.translate(xStartPx + xOffset, yStartPx + yOffset); |
|
|
|
// 绘制原点交叉线
|
|
|
|
ctx.moveTo(-xOffset, 0); |
|
|
|
ctx.lineTo(xOffset, 0); |
|
|
|
ctx.moveTo(0, -yOffset); |
|
|
|
ctx.lineTo(0, yMax); |
|
|
|
ctx.stroke(); |
|
|
|
|
|
|
|
// 绘制x轴y轴 单位数值
|
|
|
|
ctx.beginPath(); |
|
|
|
ctx.fillStyle = "#333333"; |
|
|
|
ctx.textAlign = "center"; |
|
|
|
ctx.font = "normal 14px system"; |
|
|
|
for (let index = -4; index < 5; index++) { |
|
|
|
ctx.fillText((index * 10).toString(), xStepPx * index, yMax + 20); |
|
|
|
} |
|
|
|
for (let index = -1; index < 5; index++) { |
|
|
|
ctx.fillText((-index * 10).toString(), -xOffset - (index > 0 ? 18 : 14), yStepPx * index + 4); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 绘制标准线
|
|
|
|
ctx.beginPath(); |
|
|
|
ctx.strokeStyle = "red"; |
|
|
|
// ---- 右侧 (从上到下)
|
|
|
|
let point0 = pointsRight[0]; |
|
|
@ -79,39 +61,21 @@ export default function StandardLayer(props: { |
|
|
|
ctx.moveTo(point0[0], point0[1]); |
|
|
|
let param = calculateCircleBelow(point0[0], point0[1], point1[0], point1[1], 300 * unitPx); |
|
|
|
// console.log(param);
|
|
|
|
ctx.arc( |
|
|
|
param.center.x, |
|
|
|
param.center.y, |
|
|
|
300 * unitPx, |
|
|
|
param.angles.startAngle, |
|
|
|
param.angles.endAngle |
|
|
|
); |
|
|
|
ctx.arc(param.center.x, param.center.y, 300 * unitPx, param.angles.startAngle, param.angles.endAngle); |
|
|
|
|
|
|
|
point0 = pointsRight[1]; |
|
|
|
point1 = pointsRight[2]; |
|
|
|
ctx.moveTo(point0[0], point0[1]); |
|
|
|
param = calculateCircleBelow(point0[0], point0[1], point1[0], point1[1], 80 * unitPx); |
|
|
|
// console.log(param);
|
|
|
|
ctx.arc( |
|
|
|
param.center.x, |
|
|
|
param.center.y, |
|
|
|
80 * unitPx, |
|
|
|
param.angles.startAngle, |
|
|
|
param.angles.endAngle |
|
|
|
); |
|
|
|
ctx.arc(param.center.x, param.center.y, 80 * unitPx, param.angles.startAngle, param.angles.endAngle); |
|
|
|
|
|
|
|
point0 = pointsRight[2]; |
|
|
|
point1 = pointsRight[3]; |
|
|
|
ctx.moveTo(point0[0], point0[1]); |
|
|
|
param = calculateCircleBelow(point0[0], point0[1], point1[0], point1[1], 13 * unitPx); |
|
|
|
// console.log(param);
|
|
|
|
ctx.arc( |
|
|
|
param.center.x, |
|
|
|
param.center.y, |
|
|
|
13 * unitPx, |
|
|
|
param.angles.startAngle, |
|
|
|
param.angles.endAngle |
|
|
|
); |
|
|
|
ctx.arc(param.center.x, param.center.y, 13 * unitPx, param.angles.startAngle, param.angles.endAngle); |
|
|
|
|
|
|
|
point0 = pointsRight[3]; |
|
|
|
point1 = pointsRight[4]; |
|
|
@ -153,43 +117,25 @@ export default function StandardLayer(props: { |
|
|
|
ctx.moveTo(point0[0], point0[1]); |
|
|
|
param = calculateCircleBelow(point0[0], point0[1], point1[0], point1[1], 13 * unitPx); |
|
|
|
// console.log(param);
|
|
|
|
ctx.arc( |
|
|
|
param.center.x, |
|
|
|
param.center.y, |
|
|
|
13 * unitPx, |
|
|
|
param.angles.startAngle, |
|
|
|
param.angles.endAngle |
|
|
|
); |
|
|
|
ctx.arc(param.center.x, param.center.y, 13 * unitPx, param.angles.startAngle, param.angles.endAngle); |
|
|
|
|
|
|
|
point0 = pointsLeft[4]; |
|
|
|
point1 = pointsLeft[5]; |
|
|
|
ctx.moveTo(point0[0], point0[1]); |
|
|
|
param = calculateCircleBelow(point0[0], point0[1], point1[0], point1[1], 80 * unitPx); |
|
|
|
// console.log(param);
|
|
|
|
ctx.arc( |
|
|
|
param.center.x, |
|
|
|
param.center.y, |
|
|
|
80 * unitPx, |
|
|
|
param.angles.startAngle, |
|
|
|
param.angles.endAngle |
|
|
|
); |
|
|
|
ctx.arc(param.center.x, param.center.y, 80 * unitPx, param.angles.startAngle, param.angles.endAngle); |
|
|
|
|
|
|
|
point0 = pointsLeft[5]; |
|
|
|
point1 = pointsLeft[6]; |
|
|
|
ctx.moveTo(point0[0], point0[1]); |
|
|
|
param = calculateCircleBelow(point0[0], point0[1], point1[0], point1[1], 300 * unitPx); |
|
|
|
// console.log(param);
|
|
|
|
ctx.arc( |
|
|
|
param.center.x, |
|
|
|
param.center.y, |
|
|
|
300 * unitPx, |
|
|
|
param.angles.startAngle, |
|
|
|
param.angles.endAngle |
|
|
|
); |
|
|
|
ctx.arc(param.center.x, param.center.y, 300 * unitPx, param.angles.startAngle, param.angles.endAngle); |
|
|
|
|
|
|
|
ctx.stroke(); |
|
|
|
}, |
|
|
|
[pointsLeft, pointsRight, unitPx, xEndPx, xStartPx, xStepPx, yEndPx, yStartPx, yStepPx] |
|
|
|
[pointsLeft, pointsRight, props.height, props.width, unitPx, xEndPx, xStartPx, yStartPx, yStepPx] |
|
|
|
); |
|
|
|
useEffect(() => { |
|
|
|
const canvas = canvasRef.current; |
|
|
@ -201,7 +147,7 @@ export default function StandardLayer(props: { |
|
|
|
}, [draw]); |
|
|
|
|
|
|
|
return ( |
|
|
|
<div> |
|
|
|
<div style={{ visibility: props.visibility }}> |
|
|
|
<canvas ref={canvasRef} width={props.width} height={props.height}></canvas> |
|
|
|
</div> |
|
|
|
); |
|
|
|