Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/blue-lamps-invent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@khanacademy/perseus": minor
"@khanacademy/perseus-core": minor
"@khanacademy/perseus-editor": minor
"@khanacademy/perseus-linter": minor
---

Add `showAngle` field to `LockedPolygonPointType`. This option controls the display of an angle label per-vertex. It defaults to false.
10 changes: 5 additions & 5 deletions __docs__/sample-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ export const graphExample: PerseusRenderer = {
weight: "thick",
fillStyle: "translucent",
points: [
{coord: [7, -3]},
{coord: [8, -5]},
{coord: [4, -7]},
{coord: [0, -7]},
{coord: [2, -3]},
{coord: [7, -3], showAngle: false},
{coord: [8, -5], showAngle: false},
{coord: [4, -7], showAngle: false},
{coord: [0, -7], showAngle: false},
{coord: [2, -3], showAngle: false},
],
showVertices: false,
strokeStyle: "solid",
Expand Down
1 change: 1 addition & 0 deletions packages/perseus-core/src/data-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,7 @@ export type LockedEllipseType = {

export type LockedPolygonPointType = {
coord: Coord;
showAngle: boolean;
};

export type LockedPolygonType = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ describe("parseInteractiveGraphWidget", () => {
);
});

it("parses locked polygon points with coord field", () => {
it("parses locked polygon points with coord and showAngle fields", () => {
const result = parse(
{
type: "interactive-graph",
Expand All @@ -411,7 +411,7 @@ describe("parseInteractiveGraphWidget", () => {
{
type: "polygon",
points: [
{coord: [0, 0]},
{coord: [0, 0], showAngle: true},
{coord: [1, 0]},
{coord: [1, 1]},
],
Expand Down Expand Up @@ -455,9 +455,9 @@ describe("parseInteractiveGraphWidget", () => {
{
type: "polygon",
points: [
{coord: [0, 0]},
{coord: [1, 0]},
{coord: [1, 1]},
{coord: [0, 0], showAngle: true},
{coord: [1, 0], showAngle: false},
{coord: [1, 1], showAngle: false},
],
color: "blue",
showVertices: false,
Expand Down Expand Up @@ -542,9 +542,9 @@ describe("parseInteractiveGraphWidget", () => {
{
type: "polygon",
points: [
{coord: [0, 0]},
{coord: [1, 0]},
{coord: [1, 1]},
{coord: [0, 0], showAngle: false},
{coord: [1, 0], showAngle: false},
{coord: [1, 1], showAngle: false},
],
color: "blue",
showVertices: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ const parseLockedEllipseType = object({

const parseLockedPolygonPointType = object({
coord: pairOfNumbers,
showAngle: defaulted(boolean, () => false),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

});

const parseLockedPolygonPointsType = union(
Expand All @@ -266,7 +267,7 @@ const parseLockedPolygonPointsType = union(
// Normalize legacy representation of points as Coord[] to
// LockedPolygonPointType[].
pipeParsers(array(pairOfNumbers)).then(
convert((coords) => coords.map((coord) => ({coord}))),
convert((coords) => coords.map((coord) => ({coord, showAngle: false}))),
).parser,
).parser;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1180,15 +1180,9 @@ describe("generateIGLockedPolygon", () => {
expect(lockedPolygon).toEqual({
type: "polygon",
points: [
{
coord: [0, 2],
},
{
coord: [-1, 0],
},
{
coord: [1, 0],
},
{coord: [0, 2], showAngle: false},
{coord: [-1, 0], showAngle: false},
{coord: [1, 0], showAngle: false},
],
color: "grayH",
showVertices: false,
Expand All @@ -1203,15 +1197,9 @@ describe("generateIGLockedPolygon", () => {
// Arrange, Act
const lockedPolygon = generateIGLockedPolygon({
points: [
{
coord: [1, 1],
},
{
coord: [2, 2],
},
{
coord: [3, 3],
},
{coord: [1, 1], showAngle: false},
{coord: [2, 2], showAngle: true},
{coord: [3, 3], showAngle: false},
],
color: "blue",
showVertices: true,
Expand All @@ -1234,15 +1222,9 @@ describe("generateIGLockedPolygon", () => {
expect(lockedPolygon).toEqual({
type: "polygon",
points: [
{
coord: [1, 1],
},
{
coord: [2, 2],
},
{
coord: [3, 3],
},
{coord: [1, 1], showAngle: false},
{coord: [2, 2], showAngle: true},
{coord: [3, 3], showAngle: false},
],
color: "blue",
showVertices: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ describe("getDefaultFigureForType", () => {
const figure = getDefaultFigureForType("polygon");
expect(figure).toEqual({
type: "polygon",
points: [{coord: [0, 2]}, {coord: [-1, 0]}, {coord: [1, 0]}],
points: [
{coord: [0, 2], showAngle: false},
{coord: [-1, 0], showAngle: false},
{coord: [1, 0], showAngle: false},
],
color: "grayH",
showVertices: false,
fillStyle: "none",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ export function getDefaultFigureForType(type: LockedFigureType): LockedFigure {
case "polygon":
return {
type: "polygon",
points: [{coord: [0, 2]}, {coord: [-1, 0]}, {coord: [1, 0]}],
points: [
{coord: [0, 2], showAngle: false},
{coord: [-1, 0], showAngle: false},
{coord: [1, 0], showAngle: false},
],
color: DEFAULT_COLOR,
showVertices: false,
fillStyle: "none",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,10 @@ export const segmentWithLockedFigures: PerseusRenderer =
}),
generateIGLockedPolygon({
points: [
{coord: [-9, 4]},
{coord: [-6, 4]},
{coord: [-6, 1]},
{coord: [-9, 1]},
{coord: [-9, 4], showAngle: false},
{coord: [-6, 4], showAngle: false},
{coord: [-6, 1], showAngle: false},
{coord: [-9, 1], showAngle: false},
],
color: "pink",
labels: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,10 @@ describe("InteractiveGraphEditor locked figures", () => {
lockedFigures: [
expect.objectContaining({
type: "polygon",
points: [...defaultPolygon.points, {coord: [0, 0]}],
points: [
...defaultPolygon.points,
{coord: [0, 0], showAngle: false},
],
}),
],
}),
Expand All @@ -1091,10 +1094,10 @@ describe("InteractiveGraphEditor locked figures", () => {
const onChangeMock = jest.fn();

const squarePolygonPoints = [
{coord: [-9, 4]},
{coord: [-6, 4]},
{coord: [-6, 1]},
{coord: [-9, 1]},
{coord: [-9, 4], showAngle: false},
{coord: [-6, 4], showAngle: false},
{coord: [-6, 1], showAngle: false},
{coord: [-9, 1], showAngle: false},
];

renderEditor({
Expand All @@ -1120,9 +1123,9 @@ describe("InteractiveGraphEditor locked figures", () => {
expect.objectContaining({
type: "polygon",
points: [
{coord: [-6, 4]},
{coord: [-6, 1]},
{coord: [-9, 1]},
{coord: [-6, 4], showAngle: false},
{coord: [-6, 1], showAngle: false},
{coord: [-9, 1], showAngle: false},
],
}),
],
Expand Down Expand Up @@ -1153,9 +1156,9 @@ describe("InteractiveGraphEditor locked figures", () => {
expect.objectContaining({
type: "polygon",
points: [
{coord: [7, 2]},
{coord: [-1, 0]},
{coord: [1, 0]},
{coord: [7, 2], showAngle: false},
{coord: [-1, 0], showAngle: false},
{coord: [1, 0], showAngle: false},
],
}),
],
Expand Down Expand Up @@ -1186,9 +1189,9 @@ describe("InteractiveGraphEditor locked figures", () => {
expect.objectContaining({
type: "polygon",
points: [
{coord: [0, 7]},
{coord: [-1, 0]},
{coord: [1, 0]},
{coord: [0, 7], showAngle: false},
{coord: [-1, 0], showAngle: false},
{coord: [1, 0], showAngle: false},
],
}),
],
Expand Down
Loading
Loading