|
|
@ -1,8 +1,6 @@ |
|
|
|
import { useCallback, useEffect, useRef } from "react"; |
|
|
|
import { calculateCircleAbove, calculateCircleBelow } from "../../../../utils"; |
|
|
|
|
|
|
|
const unitPx = 8; |
|
|
|
|
|
|
|
const pointsR: [number, number][] = [ |
|
|
|
[0, 0], |
|
|
|
[9.949007022412, 0.1650166186941], |
|
|
@ -21,8 +19,6 @@ const pointsL: [number, number][] = [ |
|
|
|
[-9.949007022412, 0.1650166186941], |
|
|
|
[0, 0], |
|
|
|
]; |
|
|
|
const pointsRight = pointsR.map(p => [p[0] * unitPx, p[1] * unitPx]); |
|
|
|
const pointsLeft = pointsL.map(p => [p[0] * unitPx, p[1] * unitPx]); |
|
|
|
|
|
|
|
export default function StandardLayer(props: { |
|
|
|
width: number; |
|
|
@ -41,6 +37,10 @@ export default function StandardLayer(props: { |
|
|
|
const yEndPx = props.height - props.bottomPadding; |
|
|
|
const yStepPx = (props.height - props.topPadding - props.bottomPadding) / props.rows; |
|
|
|
|
|
|
|
const unitPx = xStepPx / 10; |
|
|
|
const pointsRight = pointsR.map(p => [p[0] * unitPx, p[1] * unitPx]); |
|
|
|
const pointsLeft = pointsL.map(p => [p[0] * unitPx, p[1] * unitPx]); |
|
|
|
|
|
|
|
const canvasRef = useRef<HTMLCanvasElement | null>(null); |
|
|
|
|
|
|
|
const draw = useCallback( |
|
|
@ -73,44 +73,44 @@ export default function StandardLayer(props: { |
|
|
|
// 绘制标准线
|
|
|
|
ctx.beginPath(); |
|
|
|
ctx.strokeStyle = "red"; |
|
|
|
// ---- 右侧
|
|
|
|
// ---- 右侧 (从上到下)
|
|
|
|
let point0 = pointsRight[0]; |
|
|
|
let point1 = pointsRight[1]; |
|
|
|
ctx.moveTo(point0[0], point0[1]); |
|
|
|
let param = calculateCircleBelow(point0[0], point0[1], point1[0], point1[1], 300 * unitPx); |
|
|
|
console.log(param); |
|
|
|
// console.log(param);
|
|
|
|
ctx.arc( |
|
|
|
param.center.x, |
|
|
|
param.center.y, |
|
|
|
300 * unitPx, |
|
|
|
param.anglesForCenter.startAngle, |
|
|
|
param.anglesForCenter.endAngle |
|
|
|
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); |
|
|
|
// console.log(param);
|
|
|
|
ctx.arc( |
|
|
|
param.center.x, |
|
|
|
param.center.y, |
|
|
|
80 * unitPx, |
|
|
|
param.anglesForCenter.startAngle, |
|
|
|
param.anglesForCenter.endAngle |
|
|
|
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); |
|
|
|
// console.log(param);
|
|
|
|
ctx.arc( |
|
|
|
param.center.x, |
|
|
|
param.center.y, |
|
|
|
13 * unitPx, |
|
|
|
param.anglesForCenter.startAngle, |
|
|
|
param.anglesForCenter.endAngle |
|
|
|
param.angles.startAngle, |
|
|
|
param.angles.endAngle |
|
|
|
); |
|
|
|
|
|
|
|
point0 = pointsRight[3]; |
|
|
@ -122,15 +122,15 @@ export default function StandardLayer(props: { |
|
|
|
point1 = pointsRight[5]; |
|
|
|
ctx.moveTo(point0[0], point0[1]); |
|
|
|
param = calculateCircleAbove(point0[0], point0[1], point1[0], point1[1], 5 * unitPx); |
|
|
|
console.log(param); |
|
|
|
ctx.arc(param.center.x, param.center.y, 5 * unitPx, param.anglesForCenter.startAngle, param.anglesForCenter.endAngle); |
|
|
|
// console.log(param);
|
|
|
|
ctx.arc(param.center.x, param.center.y, 5 * unitPx, param.angles.startAngle, param.angles.endAngle); |
|
|
|
|
|
|
|
point0 = pointsRight[5]; |
|
|
|
point1 = pointsRight[6]; |
|
|
|
ctx.moveTo(point0[0], point0[1]); |
|
|
|
ctx.lineTo(point1[0], point1[1]); |
|
|
|
|
|
|
|
// ---- 左侧
|
|
|
|
// ---- 左侧 (从下向上)
|
|
|
|
point0 = pointsLeft[0]; |
|
|
|
point1 = pointsLeft[1]; |
|
|
|
ctx.moveTo(point0[0], point0[1]); |
|
|
@ -140,8 +140,8 @@ export default function StandardLayer(props: { |
|
|
|
point1 = pointsLeft[2]; |
|
|
|
ctx.moveTo(point0[0], point0[1]); |
|
|
|
param = calculateCircleAbove(point0[0], point0[1], point1[0], point1[1], 5 * unitPx); |
|
|
|
console.log(param); |
|
|
|
ctx.arc(param.center.x, param.center.y, 5 * unitPx, param.anglesForCenter.startAngle, param.anglesForCenter.endAngle); |
|
|
|
// console.log(param);
|
|
|
|
ctx.arc(param.center.x, param.center.y, 5 * unitPx, param.angles.startAngle, param.angles.endAngle); |
|
|
|
|
|
|
|
point0 = pointsLeft[2]; |
|
|
|
point1 = pointsLeft[3]; |
|
|
@ -152,45 +152,44 @@ export default function StandardLayer(props: { |
|
|
|
point1 = pointsLeft[4]; |
|
|
|
ctx.moveTo(point0[0], point0[1]); |
|
|
|
param = calculateCircleBelow(point0[0], point0[1], point1[0], point1[1], 13 * unitPx); |
|
|
|
console.log(param); |
|
|
|
// console.log(param);
|
|
|
|
ctx.arc( |
|
|
|
param.center.x, |
|
|
|
param.center.y, |
|
|
|
13 * unitPx, |
|
|
|
param.anglesForCenter.startAngle, |
|
|
|
param.anglesForCenter.endAngle |
|
|
|
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); |
|
|
|
// console.log(param);
|
|
|
|
ctx.arc( |
|
|
|
param.center.x, |
|
|
|
param.center.y, |
|
|
|
80 * unitPx, |
|
|
|
param.anglesForCenter.startAngle, |
|
|
|
param.anglesForCenter.endAngle |
|
|
|
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); |
|
|
|
// console.log(param);
|
|
|
|
ctx.arc( |
|
|
|
param.center.x, |
|
|
|
param.center.y, |
|
|
|
300 * unitPx, |
|
|
|
param.anglesForCenter.startAngle, |
|
|
|
param.anglesForCenter.endAngle |
|
|
|
param.angles.startAngle, |
|
|
|
param.angles.endAngle |
|
|
|
); |
|
|
|
|
|
|
|
ctx.stroke(); |
|
|
|
// ctx.fillRect(100, 100, 150, 100); // 绘制一个矩形
|
|
|
|
}, |
|
|
|
[xEndPx, xStartPx, xStepPx, yEndPx, yStartPx, yStepPx] |
|
|
|
[pointsLeft, pointsRight, unitPx, xEndPx, xStartPx, xStepPx, yEndPx, yStartPx, yStepPx] |
|
|
|
); |
|
|
|
useEffect(() => { |
|
|
|
const canvas = canvasRef.current; |
|
|
|