Skip to content

Commit 952d763

Browse files
committed
[benc/parser-todos] Remove conditional checks for labels
1 parent 4a89b05 commit 952d763

File tree

8 files changed

+41
-95
lines changed

8 files changed

+41
-95
lines changed

packages/perseus-editor/src/widgets/interactive-graph-editor/locked-figures/locked-ellipse-settings.tsx

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ const LockedEllipseSettings = (props: Props) => {
111111
};
112112

113113
// Update the coord by the same amount as the point for all labels
114-
newProps.labels = labels?.map((label) => ({
114+
newProps.labels = labels.map((label) => ({
115115
...label,
116116
coord: [label.coord[0] + xOffset, label.coord[1] + yOffset],
117117
}));
@@ -125,7 +125,7 @@ const LockedEllipseSettings = (props: Props) => {
125125
};
126126

127127
// Update the color of the all labels to match the point
128-
newProps.labels = labels?.map((label) => ({
128+
newProps.labels = labels.map((label) => ({
129129
...label,
130130
color: newValue,
131131
}));
@@ -137,10 +137,6 @@ const LockedEllipseSettings = (props: Props) => {
137137
updatedLabel: Partial<LockedLabelType>,
138138
labelIndex: number,
139139
) {
140-
if (!labels) {
141-
return;
142-
}
143-
144140
const updatedLabels = [...labels];
145141
updatedLabels[labelIndex] = {
146142
...labels[labelIndex],
@@ -151,10 +147,6 @@ const LockedEllipseSettings = (props: Props) => {
151147
}
152148

153149
function handleLabelRemove(labelIndex: number) {
154-
if (!labels) {
155-
return;
156-
}
157-
158150
const updatedLabels = labels.filter((_, index) => index !== labelIndex);
159151

160152
onChangeProps({labels: updatedLabels});
@@ -268,7 +260,7 @@ const LockedEllipseSettings = (props: Props) => {
268260
<View style={styles.horizontalRule} />
269261
<Strut size={spacing.small_12} />
270262
<LabelMedium>Visible labels</LabelMedium>
271-
{labels?.map((label, labelIndex) => (
263+
{labels.map((label, labelIndex) => (
272264
<LockedLabelSettings
273265
{...label}
274266
key={labelIndex}
@@ -292,14 +284,14 @@ const LockedEllipseSettings = (props: Props) => {
292284
center[0],
293285
// Additional vertical offset for each
294286
// label so they don't overlap.
295-
center[1] - (labels?.length ?? 0),
287+
center[1] - labels.length,
296288
],
297289
// Default to the same color as the ellipse
298290
color: color,
299291
} satisfies LockedLabelType;
300292

301293
onChangeProps({
302-
labels: [...(labels ?? []), newLabel],
294+
labels: [...labels, newLabel],
303295
});
304296
}}
305297
style={styles.addButton}

packages/perseus-editor/src/widgets/interactive-graph-editor/locked-figures/locked-function-settings.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const LockedFunctionSettings = (props: Props) => {
6161
onMove,
6262
onRemove,
6363
} = props;
64-
const labels = props.labels ?? [];
64+
const labels = props.labels;
6565
const equationPrefix = directionalAxis === "x" ? "y=" : "x=";
6666
const lineLabel = `Function (${equationPrefix}${equation})`;
6767

@@ -332,7 +332,7 @@ const LockedFunctionSettings = (props: Props) => {
332332
<View style={styles.horizontalRule} />
333333
<Strut size={spacing.small_12} />
334334
<LabelMedium>Visible labels</LabelMedium>
335-
{labels.map((label, labelIndex, allLabels) => (
335+
{labels.map((label, labelIndex) => (
336336
<LockedLabelSettings
337337
key={labelIndex}
338338
{...label}

packages/perseus-editor/src/widgets/interactive-graph-editor/locked-figures/locked-line-settings.tsx

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ const LockedLineSettings = (props: Props) => {
128128
newMidpoint[0] - oldMidpoint[0],
129129
newMidpoint[1] - oldMidpoint[1],
130130
];
131-
const newLabels = labels?.map((label, labelIndex) => ({
131+
const newLabels = labels.map((label, labelIndex) => ({
132132
...label,
133133
coord: [
134134
label.coord[0] + offset[0],
@@ -143,7 +143,7 @@ const LockedLineSettings = (props: Props) => {
143143
}
144144

145145
function handleColorChange(newColor: LockedFigureColor) {
146-
const newLabels = labels?.map((label) => ({
146+
const newLabels = labels.map((label) => ({
147147
...label,
148148
color: newColor,
149149
}));
@@ -155,15 +155,15 @@ const LockedLineSettings = (props: Props) => {
155155
{
156156
...point1,
157157
color: newColor,
158-
labels: point1.labels?.map((label) => ({
158+
labels: point1.labels.map((label) => ({
159159
...label,
160160
color: newColor,
161161
})),
162162
},
163163
{
164164
...point2,
165165
color: newColor,
166-
labels: point2.labels?.map((label) => ({
166+
labels: point2.labels.map((label) => ({
167167
...label,
168168
color: newColor,
169169
})),
@@ -178,10 +178,6 @@ const LockedLineSettings = (props: Props) => {
178178
updatedLabel: Partial<LockedLabelType>,
179179
labelIndex: number,
180180
) {
181-
if (!labels) {
182-
return;
183-
}
184-
185181
const updatedLabels = [...labels];
186182
updatedLabels[labelIndex] = {
187183
...labels[labelIndex],
@@ -192,10 +188,6 @@ const LockedLineSettings = (props: Props) => {
192188
}
193189

194190
function handleLabelRemove(labelIndex: number) {
195-
if (!labels) {
196-
return;
197-
}
198-
199191
const updatedLabels = labels.filter((_, index) => index !== labelIndex);
200192

201193
onChangeProps({labels: updatedLabels});
@@ -299,7 +291,7 @@ const LockedLineSettings = (props: Props) => {
299291
<Strut size={spacing.small_12} />
300292
<LabelMedium>Visible labels</LabelMedium>
301293

302-
{labels?.map((label, labelIndex) => (
294+
{labels.map((label, labelIndex) => (
303295
<LockedLabelSettings
304296
{...label}
305297
key={labelIndex}
@@ -321,7 +313,7 @@ const LockedLineSettings = (props: Props) => {
321313
// they don't overlap.
322314
const offsetPerLabel: vec.Vector2 = [0, -1];
323315
const labelLocation = vec.add(
324-
vec.scale(offsetPerLabel, labels?.length ?? 0),
316+
vec.scale(offsetPerLabel, labels.length),
325317
vec.midpoint(points[0].coord, points[1].coord),
326318
);
327319

@@ -333,7 +325,7 @@ const LockedLineSettings = (props: Props) => {
333325
} satisfies LockedLabelType;
334326

335327
onChangeProps({
336-
labels: [...(labels ?? []), newLabel],
328+
labels: [...labels, newLabel],
337329
});
338330
}}
339331
style={styles.addButton}

packages/perseus-editor/src/widgets/interactive-graph-editor/locked-figures/locked-point-settings.tsx

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,10 @@ const LockedPointSettings = (props: Props) => {
129129
};
130130

131131
// Update the color of the all labels to match the point
132-
if (labels) {
133-
newProps.labels = labels.map((label) => ({
134-
...label,
135-
color: newValue,
136-
}));
137-
}
132+
newProps.labels = labels.map((label) => ({
133+
...label,
134+
color: newValue,
135+
}));
138136

139137
onChangeProps(newProps);
140138
}
@@ -148,12 +146,10 @@ const LockedPointSettings = (props: Props) => {
148146
};
149147

150148
// Update the coord by the same amount as the point for all labels
151-
if (labels) {
152-
newProps.labels = labels.map((label) => ({
153-
...label,
154-
coord: [label.coord[0] + xOffset, label.coord[1] + yOffset],
155-
}));
156-
}
149+
newProps.labels = labels.map((label) => ({
150+
...label,
151+
coord: [label.coord[0] + xOffset, label.coord[1] + yOffset],
152+
}));
157153

158154
onChangeProps(newProps);
159155
}
@@ -162,10 +158,6 @@ const LockedPointSettings = (props: Props) => {
162158
updatedLabel: Partial<LockedLabelType>,
163159
labelIndex: number,
164160
) {
165-
if (!labels) {
166-
return;
167-
}
168-
169161
const updatedLabels = [...labels];
170162
updatedLabels[labelIndex] = {
171163
...labels[labelIndex],
@@ -176,10 +168,6 @@ const LockedPointSettings = (props: Props) => {
176168
}
177169

178170
function handleLabelRemove(labelIndex: number) {
179-
if (!labels) {
180-
return;
181-
}
182-
183171
const updatedLabels = labels.filter((_, index) => index !== labelIndex);
184172

185173
onChangeProps({labels: updatedLabels});
@@ -257,7 +245,7 @@ const LockedPointSettings = (props: Props) => {
257245
<View style={styles.horizontalRule} />
258246
<Strut size={spacing.small_12} />
259247
<LabelMedium>Visible labels</LabelMedium>
260-
{labels?.map((label, labelIndex) => (
248+
{labels.map((label, labelIndex) => (
261249
<LockedLabelSettings
262250
{...label}
263251
key={labelIndex}
@@ -286,14 +274,14 @@ const LockedPointSettings = (props: Props) => {
286274
coord[0] + 0.5,
287275
// Additional offset for each label so
288276
// they don't overlap.
289-
coord[1] - 1 * (labels?.length ?? 0),
277+
coord[1] - labels.length,
290278
],
291279
// Default to the same color as the point
292280
color: pointColor,
293281
} satisfies LockedLabelType;
294282

295283
onChangeProps({
296-
labels: [...(labels ?? []), newLabel],
284+
labels: [...labels, newLabel],
297285
});
298286
}}
299287
style={styles.addButton}

packages/perseus-editor/src/widgets/interactive-graph-editor/locked-figures/locked-polygon-settings.tsx

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ const LockedPolygonSettings = (props: Props) => {
100100
};
101101

102102
// Update the color of the all labels to match the point
103-
newProps.labels = labels?.map((label) => ({
103+
newProps.labels = labels.map((label) => ({
104104
...label,
105105
color: newValue,
106106
}));
@@ -113,7 +113,7 @@ const LockedPolygonSettings = (props: Props) => {
113113
case "up":
114114
onChangeProps({
115115
points: points.map(([x, y]) => [x, y + 1]),
116-
labels: labels?.map((label) => ({
116+
labels: labels.map((label) => ({
117117
...label,
118118
coord: [label.coord[0], label.coord[1] + 1],
119119
})),
@@ -122,7 +122,7 @@ const LockedPolygonSettings = (props: Props) => {
122122
case "down":
123123
onChangeProps({
124124
points: points.map(([x, y]) => [x, y - 1]),
125-
labels: labels?.map((label) => ({
125+
labels: labels.map((label) => ({
126126
...label,
127127
coord: [label.coord[0], label.coord[1] - 1],
128128
})),
@@ -131,7 +131,7 @@ const LockedPolygonSettings = (props: Props) => {
131131
case "left":
132132
onChangeProps({
133133
points: points.map(([x, y]) => [x - 1, y]),
134-
labels: labels?.map((label) => ({
134+
labels: labels.map((label) => ({
135135
...label,
136136
coord: [label.coord[0] - 1, label.coord[1]],
137137
})),
@@ -140,7 +140,7 @@ const LockedPolygonSettings = (props: Props) => {
140140
case "right":
141141
onChangeProps({
142142
points: points.map(([x, y]) => [x + 1, y]),
143-
labels: labels?.map((label) => ({
143+
labels: labels.map((label) => ({
144144
...label,
145145
coord: [label.coord[0] + 1, label.coord[1]],
146146
})),
@@ -153,10 +153,6 @@ const LockedPolygonSettings = (props: Props) => {
153153
updatedLabel: Partial<LockedLabelType>,
154154
labelIndex: number,
155155
) {
156-
if (!labels) {
157-
return;
158-
}
159-
160156
const updatedLabels = [...labels];
161157
updatedLabels[labelIndex] = {
162158
...labels[labelIndex],
@@ -167,10 +163,6 @@ const LockedPolygonSettings = (props: Props) => {
167163
}
168164

169165
function handleLabelRemove(labelIndex: number) {
170-
if (!labels) {
171-
return;
172-
}
173-
174166
const updatedLabels = labels.filter((_, index) => index !== labelIndex);
175167

176168
onChangeProps({labels: updatedLabels});
@@ -362,7 +354,7 @@ const LockedPolygonSettings = (props: Props) => {
362354
<View style={styles.horizontalRule} />
363355
<Strut size={spacing.small_12} />
364356
<LabelMedium>Visible labels</LabelMedium>
365-
{labels?.map((label, labelIndex) => (
357+
{labels.map((label, labelIndex) => (
366358
<LockedLabelSettings
367359
{...label}
368360
key={labelIndex}
@@ -386,14 +378,14 @@ const LockedPolygonSettings = (props: Props) => {
386378
points[0][0],
387379
// Additional vertical offset for each
388380
// label so they don't overlap.
389-
points[0][1] - (labels?.length ?? 0),
381+
points[0][1] - labels.length,
390382
],
391383
// Default to the same color as the ellipse
392384
color: color,
393385
} satisfies LockedLabelType;
394386

395387
onChangeProps({
396-
labels: [...(labels ?? []), newLabel],
388+
labels: [...labels, newLabel],
397389
});
398390
}}
399391
style={styles.addButton}

0 commit comments

Comments
 (0)