Skip to content

Commit

Permalink
feat: make graphexercise and graphinput match figma (#91)
Browse files Browse the repository at this point in the history
* Graph matches Figma

* Graph Figma and ran lint

---------

Co-authored-by: Sanjna <[email protected]>
  • Loading branch information
NotAmaia and SanjnaT41756 authored Apr 17, 2024
1 parent 74eb4f5 commit c927469
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 7 deletions.
93 changes: 90 additions & 3 deletions src/components/shared/ExerciseSide.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,17 @@ function ExerciseSide({
ExerciseSideProps): JSX.Element {
const [displayExercise, setDisplayExercise] = useState(0);

type availableExercises = 'axis' | 'congrats' | 'graph' | 'unitcircle';
type availableExercises =
| 'axis'
| 'congrats'
| 'graph0'
| 'unitcircle'
| 'graph1';

const exercises: availableExercises[] = [
'unitcircle',
'axis',
'graph',
'graph0',
'congrats',
];
let curExercise;
Expand All @@ -39,7 +44,89 @@ ExerciseSideProps): JSX.Element {
setDisplayExercise(ExercisesNum);
}

if (exercises[displayExercise] == 'graph') {
if (exercises[displayExercise] == 'graph0') {
curExercise = (
<div>
<div>
<GraphExercise
origin={{ x: 0, y: 0 }}
points={[
{ x: 0, y: 0, label: '' },
{ x: 2, y: 1, label: 'A', line: 1 },
{ x: 1, y: -1, label: 'B', line: 1 },
{ x: 0, y: -1, label: 'C', line: 1 },
]}
pointerPosition={{ x: 0, y: 0 }}
pointerOrientation={0}
/>
</div>
<div style={{ paddingTop: '10vw' }}>
<GraphInput
questionArray={[
{
textArray: [
{
type: 'text',
text: '# Goto point A and draw on the dotted line',
},
],
},
{
textArray: [
{ type: 'text', text: 'turtle.goto(' },
{ type: 'input', width: 2 },
{ type: 'text', text: ', -1)' },
],
},
{
textArray: [
{ type: 'text', text: 'turtle.setheading(' },
{ type: 'input', width: 4 },
{ type: 'text', text: ')' },
],
},
{
textArray: [
{ type: 'text', text: 'turtle.' },
{ type: 'input', width: 8 },
{ type: 'text', text: '()' },
],
},
{
textArray: [
{ type: 'text', text: 'turtle.goto(' },
{ type: 'input', width: 2 },
{ type: 'text', text: ', ' },
{ type: 'input', width: 2 },
{ type: 'text', text: ')' },
],
},
]}
nextExercise={() => incrementExercise()}
/>
</div>
</div>
);

/*<div className="exercise-box">
<AxisParent
axisMarkers={[
[-2, -1, 0, 1, 2],
[-1, 0, 1, 2],
]}
axisLabels={[
['A', '', '', 'B', 'C'],
['A', '', '', 'B'],
]}
toNextExercise={() => {
setCompleteExercises(completeExercises + 1);
incrementExercise();
return;
}}
/>
</div>
);*/
} else if (exercises[displayExercise] == 'graph1') {
curExercise = (
<div>
<div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/shared/Exercises/GraphExercise.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ GraphProps): JSX.Element {
const dyPercent = yPos(endY) - yPos(startY);
// use this factor because dyPercent is relative to height,
// but we express a line's length as a percentage of width.
const yxRatio = 22.5 / 40;
const yxRatio = 22.5 / 50;
const lineLengthPercent =
Math.sqrt(
(dxPercent / 100) ** 2 + ((dyPercent * yxRatio) / 100) ** 2
Expand Down
3 changes: 2 additions & 1 deletion src/styles/Exercises/GraphInput.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
font-style: normal;
font-weight: bold;
margin-bottom: 2vh;
margin-left: -20px;
margin-left: 0;
margin-right: auto;
margin-top: 100px;
padding-left: 8%;
}

Expand Down
5 changes: 3 additions & 2 deletions src/styles/Graph.scss
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
.graph-container {
align-items: center;
border: solid 2px #000;
border: solid 1px rgb(209, 209, 209);
border-radius: 12px;
height: 0;
margin-left: 5%;
// If editing the sizing of graph-container (padding-bottom or width),
// modify the value of `yxRatio` in Graph.tsx
padding-bottom: 22.5%;
position: absolute;
top: 5%;
width: 40%; // see above warning
width: 50%; // see above warning
}

.grid-line {
Expand Down

0 comments on commit c927469

Please sign in to comment.