Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(circle-packing): restore border support
- Loading branch information
Showing
10 changed files
with
113 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import React from 'react' | ||
import { animated, to, SpringValue, Interpolation } from 'react-spring' | ||
import { CircleProps } from './types' | ||
import { useNodeMouseHandlers } from './hooks' | ||
|
||
export const interpolatePosition = ( | ||
positionValue: SpringValue<number>, | ||
radiusValue: Interpolation<number> | ||
) => to([positionValue, radiusValue], (position, radius) => position - radius) | ||
|
||
export const interpolateSize = (radiusValue: Interpolation<number>) => | ||
to([radiusValue], radius => radius * 2) | ||
|
||
export const interpolateBorderWidth = (borderWidth: number, radiusValue: Interpolation<number>) => | ||
to([radiusValue], radius => Math.min(borderWidth, radius)) | ||
|
||
export const CircleHtml = <RawDatum,>({ | ||
node, | ||
style, | ||
onMouseEnter, | ||
onMouseMove, | ||
onMouseLeave, | ||
onClick, | ||
}: CircleProps<RawDatum>) => { | ||
const size = interpolateSize(style.radius) | ||
|
||
const handlers = useNodeMouseHandlers<RawDatum>(node, { | ||
onMouseEnter, | ||
onMouseMove, | ||
onMouseLeave, | ||
onClick, | ||
}) | ||
|
||
return ( | ||
<animated.div | ||
style={{ | ||
position: 'absolute', | ||
top: interpolatePosition(style.y, style.radius), | ||
left: interpolatePosition(style.x, style.radius), | ||
height: size, | ||
width: size, | ||
borderRadius: style.radius, | ||
backgroundColor: style.color, | ||
borderWidth: interpolateBorderWidth(style.borderWidth, style.radius), | ||
borderStyle: 'solid', | ||
borderColor: style.borderColor, | ||
boxSizing: 'border-box', | ||
}} | ||
onMouseEnter={handlers.onMouseEnter} | ||
onMouseMove={handlers.onMouseMove} | ||
onMouseLeave={handlers.onMouseLeave} | ||
onClick={handlers.onClick} | ||
/> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters