-
Notifications
You must be signed in to change notification settings - Fork 350
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Style movable points and segments on Mafs graphs (#1068)
## Summary: See this slack thread for designs and discussion: https://khanacademy.slack.com/archives/C067UM1QAR4/p1709847469823399 Issue: LEMS-1672 Test plan: ``` yarn dev open http://localhost:5173 ``` Check the "segment" box in the dropdown at the top of the screen to switch to the Mafs version of the segment graph. You should be able to move the points and line segment with the mouse and keyboard. The hover and focus states of the points should be clearly distinct. The line segment should be highlighted blue when focused. https://github.com/Khan/perseus/assets/693920/08a2bc76-2021-4fb6-96fa-d402b7c795b5 Author: benchristel Reviewers: nishasy, benchristel, #perseus, jeremywiebe, mark-fitzgerald, nedredmond Required Reviewers: Approved By: nishasy Checks: ✅ codecov/project, ✅ codecov/patch, ✅ Upload Coverage, ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ Extract i18n strings (ubuntu-latest, 20.x), ✅ Publish Storybook to Chromatic (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ gerald, ✅ Jest Coverage (ubuntu-latest, 20.x) Pull Request URL: #1068
- Loading branch information
1 parent
59d29cd
commit 881da72
Showing
5 changed files
with
122 additions
and
13 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,5 @@ | ||
--- | ||
"@khanacademy/perseus": patch | ||
--- | ||
|
||
Adjust styling of the movable points and line segments on the Mafs segment graph |
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
51 changes: 51 additions & 0 deletions
51
packages/perseus/src/widgets/interactive-graphs/movable-point.tsx
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,51 @@ | ||
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" cx={x} cy={y} /> | ||
<circle className="movable-point-ring" cx={x} cy={y} /> | ||
<circle | ||
className="movable-point-center" | ||
cx={x} | ||
cy={y} | ||
style={{fill: Color.blue}} | ||
/> | ||
</g> | ||
); | ||
}; |