Further simplifies shape tree
This commit is contained in:
parent
552c8457ef
commit
956c0717df
5 changed files with 13 additions and 25 deletions
|
@ -20,13 +20,9 @@ const dot = registerShapeUtils<DotShape>({
|
||||||
},
|
},
|
||||||
|
|
||||||
render(shape) {
|
render(shape) {
|
||||||
const { id } = shape
|
|
||||||
|
|
||||||
const styles = getShapeStyle(shape.style)
|
const styles = getShapeStyle(shape.style)
|
||||||
|
|
||||||
return (
|
return <use href="#dot" stroke={styles.stroke} fill={styles.stroke} />
|
||||||
<use id={id} href="#dot" stroke={styles.stroke} fill={styles.stroke} />
|
|
||||||
)
|
|
||||||
},
|
},
|
||||||
|
|
||||||
getBounds(shape) {
|
getBounds(shape) {
|
||||||
|
|
|
@ -42,8 +42,8 @@ const ellipse = registerShapeUtils<EllipseShape>({
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
|
||||||
render(shape, { isHovered }) {
|
render(shape) {
|
||||||
const { id, radiusX, radiusY, style } = shape
|
const { radiusX, radiusY, style } = shape
|
||||||
const styles = getShapeStyle(style)
|
const styles = getShapeStyle(style)
|
||||||
const strokeWidth = +styles.strokeWidth
|
const strokeWidth = +styles.strokeWidth
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ const ellipse = registerShapeUtils<EllipseShape>({
|
||||||
const path = pathCache.get(shape)
|
const path = pathCache.get(shape)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<g id={id} pointerEvents={style.isFilled ? 'all' : 'stroke'}>
|
<>
|
||||||
{style.isFilled && (
|
{style.isFilled && (
|
||||||
<ellipse
|
<ellipse
|
||||||
cx={radiusX}
|
cx={radiusX}
|
||||||
|
@ -76,9 +76,8 @@ const ellipse = registerShapeUtils<EllipseShape>({
|
||||||
stroke={styles.stroke}
|
stroke={styles.stroke}
|
||||||
strokeWidth={strokeWidth}
|
strokeWidth={strokeWidth}
|
||||||
pointerEvents="all"
|
pointerEvents="all"
|
||||||
filter={isHovered ? 'url(#expand)' : 'none'}
|
|
||||||
/>
|
/>
|
||||||
</g>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,7 +107,6 @@ const ellipse = registerShapeUtils<EllipseShape>({
|
||||||
strokeDasharray={strokeDasharray}
|
strokeDasharray={strokeDasharray}
|
||||||
strokeDashoffset={strokeDashoffset}
|
strokeDashoffset={strokeDashoffset}
|
||||||
pointerEvents={style.isFilled ? 'all' : 'stroke'}
|
pointerEvents={style.isFilled ? 'all' : 'stroke'}
|
||||||
filter={isHovered ? 'url(#expand)' : 'none'}
|
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
|
|
@ -26,11 +26,10 @@ const group = registerShapeUtils<GroupShape>({
|
||||||
},
|
},
|
||||||
|
|
||||||
render(shape) {
|
render(shape) {
|
||||||
const { id, size } = shape
|
const { size } = shape
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<StyledGroupShape
|
<StyledGroupShape
|
||||||
id={id}
|
|
||||||
width={size[0]}
|
width={size[0]}
|
||||||
height={size[1]}
|
height={size[1]}
|
||||||
data-shy={true}
|
data-shy={true}
|
||||||
|
|
|
@ -25,19 +25,19 @@ const ray = registerShapeUtils<RayShape>({
|
||||||
shouldRender(shape, prev) {
|
shouldRender(shape, prev) {
|
||||||
return shape.direction !== prev.direction || shape.style !== prev.style
|
return shape.direction !== prev.direction || shape.style !== prev.style
|
||||||
},
|
},
|
||||||
render(shape, { isHovered }) {
|
render(shape) {
|
||||||
const { id, direction } = shape
|
const { direction } = shape
|
||||||
|
|
||||||
const styles = getShapeStyle(shape.style)
|
const styles = getShapeStyle(shape.style)
|
||||||
|
|
||||||
const [x2, y2] = vec.add([0, 0], vec.mul(direction, 10000))
|
const [x2, y2] = vec.add([0, 0], vec.mul(direction, 10000))
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<g id={id} filter={isHovered ? 'url(#expand)' : 'none'}>
|
<>
|
||||||
<ThinLine x1={0} y1={0} x2={x2} y2={y2} stroke={styles.stroke} />
|
<ThinLine x1={0} y1={0} x2={x2} y2={y2} stroke={styles.stroke} />
|
||||||
<circle r={4} fill="transparent" />
|
<circle r={4} fill="transparent" />
|
||||||
<use href="#dot" />
|
<use href="#dot" />
|
||||||
</g>
|
</>
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -70,7 +70,7 @@ const text = registerShapeUtils<TextShape>({
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
|
||||||
render(shape, { isEditing, isHovered, ref }) {
|
render(shape, { isEditing, ref }) {
|
||||||
const { id, text, style } = shape
|
const { id, text, style } = shape
|
||||||
const styles = getShapeStyle(style)
|
const styles = getShapeStyle(style)
|
||||||
const font = getFontStyle(shape.scale, shape.style)
|
const font = getFontStyle(shape.scale, shape.style)
|
||||||
|
@ -131,11 +131,7 @@ const text = registerShapeUtils<TextShape>({
|
||||||
|
|
||||||
if (!isEditing) {
|
if (!isEditing) {
|
||||||
return (
|
return (
|
||||||
<g
|
<>
|
||||||
id={id}
|
|
||||||
pointerEvents="all"
|
|
||||||
filter={isHovered ? 'url(#expand)' : 'none'}
|
|
||||||
>
|
|
||||||
{text.split('\n').map((str, i) => (
|
{text.split('\n').map((str, i) => (
|
||||||
<text
|
<text
|
||||||
key={i}
|
key={i}
|
||||||
|
@ -157,7 +153,7 @@ const text = registerShapeUtils<TextShape>({
|
||||||
{str}
|
{str}
|
||||||
</text>
|
</text>
|
||||||
))}
|
))}
|
||||||
</g>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,7 +163,6 @@ const text = registerShapeUtils<TextShape>({
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<foreignObject
|
<foreignObject
|
||||||
id={id}
|
|
||||||
width={bounds.width}
|
width={bounds.width}
|
||||||
height={bounds.height}
|
height={bounds.height}
|
||||||
pointerEvents="none"
|
pointerEvents="none"
|
||||||
|
|
Loading…
Reference in a new issue