问题描述
我用 react Konva Arc 对象绘制了这个半周长:
这是我的代码:
import React,{ useState } from "react";
import {Circle,Shape,Rect,Line,Group,Arc } from "react-konva";
export const Pitch = props => {
const [width,setWidth] = useState(28);
const [height,setHeight] = useState(15);
const wWidth = 850;
const wHeight = 440;
const widthScaleFactor = wWidth / width;
const heightScaleFactor = wHeight / height;
const xOffset = 2 * widthScaleFactor;
const yOffset = 2 * heightScaleFactor;
const rectWidth = wWidth - 2*xOffset;
const rectHeight = wHeight - 2*yOffset;
return (
<Group>
<Rect
x={0}
y={0}
width={wWidth}
height={wHeight}
fill="green"
/>
<Rect
x={xOffset}
y={yOffset}
width={rectWidth}
height={rectHeight}
fill="green"
stroke="white"
strokeWidth={4}
/>
<Line
x={xOffset}
y={yOffset}
points={[0,0.9*heightScaleFactor,1.575*widthScaleFactor,0.9*heightScaleFactor]}
stroke="white"
strokeWidth={4}
/>
<Line
x={xOffset}
y={-yOffset}
points={[0,wHeight - 0.9*heightScaleFactor,wHeight - 0.9*heightScaleFactor]}
stroke="white"
strokeWidth={4}
/>
<Arc
x={xOffset + 1.575*widthScaleFactor }
y={yOffset + rectHeight/2}
angle={180}
rotation={-90}
innerRadius={0}
outerRadius={rectHeight/2 - 0.9*heightScaleFactor}
stroke="white"
strokeWidth={4}
/>
</Group>
)
};
可以不画圆周的直径吗?
也许我应该使用不同的组件? 我查看了 Arc 对象的文档,但找不到解决方案。
谢谢谁能帮我
解决方法
您可以根据需要使用 Konva.Path shape 绘制圆弧:
<Path
stroke="white"
strokeWidth={4}
data={`M 0 ${-radius} A ${radius} ${radius} 0 0 1 0 ${radius}`}
/>