-
Notifications
You must be signed in to change notification settings - Fork 350
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Style movable points and segments on Mafs graphs #1068
Changes from 5 commits
68de771
3cce1be
2e92e19
df79343
aea2b1a
b3f3e59
a12cdeb
162f667
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@khanacademy/perseus": patch | ||
--- | ||
|
||
Adjust styling of the movable points and line segments on the Mafs segment graph |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import Color from "@khanacademy/wonder-blocks-color"; | ||
import {vec, useMovable, useTransformContext} from "mafs"; | ||
import * as React from "react"; | ||
import {useRef} from "react"; | ||
|
||
type Props = { | ||
point: vec.Vector2; | ||
onMove: (newPoint: vec.Vector2) => unknown; | ||
}; | ||
|
||
export const MovablePoint = (props: Props) => { | ||
const hitboxRef = useRef<SVGCircleElement>(null); | ||
const {point, onMove} = props; | ||
|
||
const {dragging} = useMovable({ | ||
gestureTarget: hitboxRef, | ||
point, | ||
onMove, | ||
constrain: (p) => p, | ||
}); | ||
|
||
const {viewTransform, userTransform} = useTransformContext(); | ||
const transformToPx = vec.matrixMult(viewTransform, userTransform); | ||
const [x, y] = vec.transform(point, transformToPx); | ||
|
||
return ( | ||
<g | ||
ref={hitboxRef} | ||
className="movable-point" | ||
tabIndex={0} | ||
style={ | ||
{ | ||
cursor: dragging ? "grabbing" : "grab", | ||
touchAction: "none", | ||
outline: "none", | ||
"--movable-point-color": Color.blue, | ||
} as any | ||
} | ||
> | ||
<circle className="movable-point-hitbox" r={30} cx={x} cy={y} /> | ||
<circle className="movable-point-halo" r={11} cx={x} cy={y} /> | ||
<circle className="movable-point-ring" r={8} cx={x} cy={y} /> | ||
<circle | ||
className="movable-point-center" | ||
r={6} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it make sense to break out these scalar numbers into a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good call-out. Probably all of the radii should be in CSS, at least. I'll move these. |
||
cx={x} | ||
cy={y} | ||
style={{fill: Color.blue}} | ||
/> | ||
</g> | ||
); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional suggestion: Maybe also move the hitbox radius to the styles for consistency?