如何解决如何使用 Visx
我想知道是否有办法将图像叠加到 visx 图形上,这样当您使用缩放和工具提示时,图像会沿着图形的一侧移动。我可以将图像叠加到图形上,但是当您使用缩放功能时,图形会放大,但图片是不变的,并且当您尝试在下面的代码片段中声明 img 时,它不会出现。我希望图片成为标签的一部分。希望这能解释我遇到的问题,谢谢。
This is what it looks likes now in react
const Example = ({ width,height,levels = 5 }: RadarProps) => {
const lineRef = useRef<SVGPathElement>(null);
// set line length once it is known after initial render
if (width < 10) return null;
// Update scale output to match component dimensions
yScale.range([0,height / 2 - padding]);
const reverseYScale = yScale.copy().range(yScale.range().reverse());
const polygonPoints = genPolygonPoints(data,d => yScale(d),y,x,w,h);
return (
<>
<Zoom
width={width}
height={height}
scaleXMin={1 / 2}
scaleXMax={4}
scaleYMin={1 / 2}
scaleYMax={4}
transformMatrix={initialTransform}
>
{(zoom) => (
<svg width={width} height={height} style={{ cursor: zoom.isDragging ? "grabbing" : "grab" }}>
<g transform={zoom.toString()}>
<GridAngle
scale={xScale}
outerRadius={height / 2 - padding}
stroke={green}
strokeWidth={2.5}
strokeOpacity={0.3}
strokeDasharray="5,2"
numTicks={4}
/>
<GridRadial
scale={yScale}
numTicks={6}
stroke={blue}
strokeWidth={2.5}
fill={blue}
fillOpacity={0.00}
strokeOpacity={0.5}
/>
<AxisLeft
top={-height / 2 + padding}
scale={reverseYScale}
numTicks={5}
tickStroke="none"
hideTicks = {tickvalue}
tickLabelProps={val => ({
fontSize: 12,fill: blue,fillOpacity: 1,textAnchor: 'middle',dx: '1.4em',dy: '-0.5em',stroke: strokeColor,strokeWidth: 0.5,paintOrder: 'stroke',})}
tickFormat={formatTicks}
hideAxisLine
/>
{polygonPoints.points.map((point,i) => (
<React.Fragment key={`radar-point-${i}`}>
<rect x={point.x - (point.w / 2)} y={point.y - (point.h / 2)} width={point.w} height={point.h} stroke="red" fill="transparent" stroke-width="3" />
</React.Fragment>
))}
</g>
<rect
width={width}
height={height}
rx={14}
fill="transparent"
onTouchStart={zoom.dragStart}
onTouchMove={zoom.dragMove}
onTouchEnd={zoom.dragEnd}
onMouseDown={zoom.dragStart}
onMouseMove={zoom.dragMove}
onMouseUp={zoom.dragEnd}
onMouseLeave={() => {
if (zoom.isDragging) zoom.dragEnd();
}}
/>
</svg>
)}
</Zoom>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。