1
0
Fork 0
freesewing/sites/shared/components/workbench/draft/point/index.js

108 lines
3.3 KiB
JavaScript
Raw Normal View History

2022-01-25 11:22:09 +01:00
import Text from '../text'
import Circle from '../circle'
2022-06-18 13:15:15 +02:00
import { Tr, KeyTd, ValTd, Attributes, pointCoords } from '../path/index'
import { withinPartBounds } from '../utils.js'
2022-01-25 11:22:09 +01:00
const RevealPoint = (props) => {
2022-01-30 12:21:08 +01:00
const r = 15 * props.gist.scale
const { x, y } = props.point
const { topLeft, bottomRight } = props.part
const i =
Object.keys(props.gist._state.xray.reveal[props.partName].points).indexOf(props.pointName) % 10
2022-01-30 12:21:08 +01:00
const classes = `stroke-sm stroke-color-${i} stroke-dashed`
return (
<g>
<circle cx={x} cy={y} r={r} className={classes} />
<path
d={`
2022-01-30 12:21:08 +01:00
M ${x} ${topLeft.y} L ${x} ${y - r}
m 0 ${2 * r} L ${x} ${bottomRight.y}
2022-01-30 12:21:08 +01:00
M ${topLeft.x} ${y} L ${x - r} ${y}
m ${2 * r} 0 L ${bottomRight.x} ${y}`}
className={classes}
/>
2022-01-30 12:21:08 +01:00
</g>
)
2022-01-30 15:14:44 +01:00
}
const pointInfo = (props) =>
props.point ? (
2022-06-18 13:15:15 +02:00
<div className="p-4 border bg-neutral bg-opacity-60 shadow rounded-lg">
<h5 className="text-neutral-content text-center pb-4">Point info</h5>
2022-06-18 18:15:17 +02:00
<table className="border-collapse h-fit">
<tbody>
<Tr>
<KeyTd>Coordinates</KeyTd>
<ValTd>{pointCoords(props.point)}</ValTd>
</Tr>
<Tr>
<KeyTd>Name</KeyTd>
<ValTd>{props.pointName}</ValTd>
</Tr>
<Tr>
<KeyTd>Part</KeyTd>
<ValTd>{props.partName}</ValTd>
</Tr>
<Tr>
<KeyTd>Attributes</KeyTd>
<ValTd>
<Attributes list={props.point.attributes.list} />
</ValTd>
2022-06-18 18:15:17 +02:00
</Tr>
</tbody>
</table>
<div className="flex flex-col flex-wrap gap-2 mt-4">
<button className="btn btn-success" onClick={() => console.log(props.point)}>
console.log(point)
</button>
<button className="btn btn-success" onClick={() => console.table(props.point)}>
console.table(point)
</button>
2022-06-18 13:15:15 +02:00
</div>
</div>
) : null
2022-01-30 15:14:44 +01:00
const XrayPoint = (props) => (
2022-01-28 19:55:32 +01:00
<g>
<circle
cx={props.point.x}
cy={props.point.y}
r={2 * props.gist.scale}
className="stroke-sm stroke-lining fill-lining fill-opacity-25"
/>
2022-01-28 19:55:32 +01:00
<circle
cx={props.point.x}
cy={props.point.y}
r={7.5 * props.gist.scale}
2022-01-29 10:50:02 +01:00
className="opacity-0 stroke-lining fill-lining hover:opacity-25 hover:cursor-pointer"
2022-06-18 13:15:15 +02:00
onClick={(evt) => {
props.showInfo(pointInfo(props))
evt.stopPropagation()
2022-06-18 13:15:15 +02:00
}}
2022-01-28 19:55:32 +01:00
/>
</g>
)
const Point = (props) => {
const { point, pointName, partName, gist, part } = props
// Don't include parts outside the part bounding box
if (!withinPartBounds(point, part)) return null
2022-01-25 11:22:09 +01:00
const output = []
if (gist._state?.xray?.enabled) {
2022-06-18 13:15:15 +02:00
// Xray for points
output.push(<XrayPoint {...props} key={'xp-' + pointName} />)
// Reveal (based on clicking the seach icon in sidebar
if (gist._state?.xray?.reveal?.[partName]?.points?.[pointName])
output.push(<RevealPoint {...props} key={'rp-' + pointName} />)
}
2022-01-30 15:14:44 +01:00
// Render text
2022-01-28 19:55:32 +01:00
if (point.attributes && point.attributes.get('data-text'))
2022-01-29 10:50:02 +01:00
output.push(<Text {...props} key={'point-' + pointName} />)
2022-01-30 15:14:44 +01:00
// Render circle
2022-01-28 19:55:32 +01:00
if (point.attributes && point.attributes.get('data-circle'))
2022-01-29 10:50:02 +01:00
output.push(<Circle point={point} key={'circle-' + pointName} />)
2022-01-25 11:22:09 +01:00
return output.length < 1 ? null : output
}
export default Point