Skip to content

Commit a9a5a01

Browse files
committed
annotations/ improve infoboxes and labels
1 parent 7be220a commit a9a5a01

35 files changed

+873
-505
lines changed

libraries/mapping/annotations/core/src/lib/types/annotationTypes.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ type NodeChainAnnotationBase = {
6868
name?: string;
6969
hidden?: boolean;
7070
segmentLineMode?: LinearSegmentLineMode;
71+
distanceLineVisibility?: {
72+
direct: boolean;
73+
vertical: boolean;
74+
horizontal: boolean;
75+
};
7176
verticalOffsetMeters?: number;
7277
nodeIds: string[];
7378
edgeRelationIds: string[];

libraries/mapping/annotations/core/src/lib/utils/annotationLabel.ts

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -256,33 +256,31 @@ export const buildStandaloneDistancePointSets = <
256256

257257
type BuildDesiredPointLabelAnchorByIdParams<
258258
TPointMeasurement extends PointLabelMeasurementLike,
259-
TPolyline extends PolylineLabelLike
259+
TNodeChain extends { id: string; nodeIds: ReadonlyArray<string> }
260260
> = {
261261
pointMeasurements: ReadonlyArray<TPointMeasurement>;
262-
polylines: ReadonlyArray<TPolyline>;
262+
nodeChains: ReadonlyArray<TNodeChain>;
263263
focusedNodeChainAnnotationId: string | null;
264264
pointMarkerBadgeByPointId: Readonly<Record<string, PointMarkerBadgeLike>>;
265265
standaloneDistanceHighestPointIds: ReadonlySet<string>;
266266
unfocusedStandaloneDistanceNonHighestPointIds: ReadonlySet<string>;
267267
focusedStandaloneDistanceNonHighestPointIds: ReadonlySet<string>;
268-
formatDistanceLabel: (distanceMeters: number) => string;
269268
};
270269

271270
export const buildDesiredPointLabelAnchorById = <
272271
TPointMeasurement extends PointLabelMeasurementLike,
273-
TPolyline extends PolylineLabelLike
272+
TNodeChain extends { id: string; nodeIds: ReadonlyArray<string> }
274273
>({
275274
pointMeasurements,
276-
polylines,
275+
nodeChains,
277276
focusedNodeChainAnnotationId,
278277
pointMarkerBadgeByPointId,
279278
standaloneDistanceHighestPointIds,
280279
unfocusedStandaloneDistanceNonHighestPointIds,
281280
focusedStandaloneDistanceNonHighestPointIds,
282-
formatDistanceLabel,
283281
}: BuildDesiredPointLabelAnchorByIdParams<
284282
TPointMeasurement,
285-
TPolyline
283+
TNodeChain
286284
>): Readonly<Record<string, AnnotationLabelAnchor | undefined>> => {
287285
const byPointId: Record<string, AnnotationLabelAnchor | undefined> = {};
288286
pointMeasurements.forEach((measurement) => {
@@ -317,19 +315,15 @@ export const buildDesiredPointLabelAnchorById = <
317315
};
318316
});
319317

320-
polylines.forEach((polyline) => {
321-
if (polyline.id === focusedNodeChainAnnotationId) return;
322-
polyline.nodeIds.forEach((pointId) => {
318+
nodeChains.forEach((nodeChain) => {
319+
if (nodeChain.id === focusedNodeChainAnnotationId) {
320+
return;
321+
}
322+
323+
nodeChain.nodeIds.forEach((pointId) => {
323324
if (!pointId) return;
324325
byPointId[pointId] = undefined;
325326
});
326-
const lastPointId = polyline.nodeIds[polyline.nodeIds.length - 1] ?? null;
327-
if (!lastPointId) return;
328-
byPointId[lastPointId] = {
329-
anchorPointId: lastPointId,
330-
compactContent: `${formatDistanceLabel(polyline.totalLengthMeters)}m`,
331-
collapseToCompact: true,
332-
};
333327
});
334328

335329
return byPointId;

libraries/mapping/annotations/core/src/lib/utils/annotationStateEquality.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,29 @@ const areStringArraysEqual = (
2020
return true;
2121
};
2222

23+
const areDistanceLineVisibilityEqual = (
24+
left:
25+
| {
26+
direct: boolean;
27+
vertical: boolean;
28+
horizontal: boolean;
29+
}
30+
| undefined,
31+
right:
32+
| {
33+
direct: boolean;
34+
vertical: boolean;
35+
horizontal: boolean;
36+
}
37+
| undefined
38+
) =>
39+
left === right ||
40+
(!!left &&
41+
!!right &&
42+
left.direct === right.direct &&
43+
left.vertical === right.vertical &&
44+
left.horizontal === right.horizontal);
45+
2346
const areOptionalNumbersEqual = (
2447
left: number | undefined,
2548
right: number | undefined,
@@ -95,6 +118,10 @@ export const arePolygonAnnotationsEquivalent = (
95118
left.hidden === right.hidden &&
96119
left.type === right.type &&
97120
left.segmentLineMode === right.segmentLineMode &&
121+
areDistanceLineVisibilityEqual(
122+
left.distanceLineVisibility,
123+
right.distanceLineVisibility
124+
) &&
98125
areOptionalNumbersEqual(
99126
left.verticalOffsetMeters,
100127
right.verticalOffsetMeters,

libraries/mapping/annotations/core/src/lib/utils/syncNodeChainEdgeDistanceRelations.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ export const syncNodeChainEdgeDistanceRelations = ({
3939
pointAId: string;
4040
pointBId: string;
4141
showDirectLine: boolean;
42+
showVerticalLine: boolean;
43+
showHorizontalLine: boolean;
4244
showComponentLines: boolean;
4345
}
4446
>();
@@ -53,15 +55,23 @@ export const syncNodeChainEdgeDistanceRelations = ({
5355
? defaultPolylineSegmentLineMode
5456
: LINEAR_SEGMENT_LINE_MODE_DIRECT);
5557
const showDirectLine = isDistanceGroup
56-
? true
58+
? group.distanceLineVisibility?.direct ?? true
5759
: isPolylineGroup
5860
? segmentLineMode === LINEAR_SEGMENT_LINE_MODE_DIRECT
5961
: true;
60-
const showComponentLines = isDistanceGroup
61-
? false
62+
const showVerticalLine = isDistanceGroup
63+
? group.distanceLineVisibility?.vertical ?? false
6264
: isPolylineGroup
6365
? segmentLineMode === LINEAR_SEGMENT_LINE_MODE_COMPONENTS
6466
: false;
67+
const showHorizontalLine = isDistanceGroup
68+
? group.distanceLineVisibility?.horizontal ?? false
69+
: isPolylineGroup
70+
? segmentLineMode === LINEAR_SEGMENT_LINE_MODE_COMPONENTS
71+
: false;
72+
const showComponentLines = isDistanceGroup
73+
? showVerticalLine || showHorizontalLine
74+
: showVerticalLine || showHorizontalLine;
6575
const orderedVertices = group.nodeIds;
6676
for (let index = 0; index < orderedVertices.length - 1; index += 1) {
6777
const pointAId = orderedVertices[index];
@@ -73,6 +83,8 @@ export const syncNodeChainEdgeDistanceRelations = ({
7383
pointAId,
7484
pointBId,
7585
showDirectLine,
86+
showVerticalLine,
87+
showHorizontalLine,
7688
showComponentLines,
7789
});
7890
}
@@ -86,6 +98,8 @@ export const syncNodeChainEdgeDistanceRelations = ({
8698
pointAId: last,
8799
pointBId: first,
88100
showDirectLine,
101+
showVerticalLine,
102+
showHorizontalLine,
89103
showComponentLines,
90104
});
91105
}
@@ -113,8 +127,8 @@ export const syncNodeChainEdgeDistanceRelations = ({
113127
anchorPointId: desired.pointAId,
114128
polygonGroupId: desired.groupId,
115129
showDirectLine: desired.showDirectLine,
116-
showVerticalLine: desired.showComponentLines,
117-
showHorizontalLine: desired.showComponentLines,
130+
showVerticalLine: desired.showVerticalLine,
131+
showHorizontalLine: desired.showHorizontalLine,
118132
showComponentLines: desired.showComponentLines,
119133
labelVisibilityByKind: {
120134
...defaultDistanceRelationLabelVisibility,
@@ -134,8 +148,8 @@ export const syncNodeChainEdgeDistanceRelations = ({
134148
anchorPointId: desired.pointAId,
135149
polygonGroupId: desired.groupId,
136150
showDirectLine: desired.showDirectLine,
137-
showVerticalLine: desired.showComponentLines,
138-
showHorizontalLine: desired.showComponentLines,
151+
showVerticalLine: desired.showVerticalLine,
152+
showHorizontalLine: desired.showHorizontalLine,
139153
showComponentLines: desired.showComponentLines,
140154
labelVisibilityByKind: {
141155
...defaultDistanceRelationLabelVisibility,

libraries/mapping/annotations/runtime/src/lib/components/annotation-info-box/AnnotationInfo.types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ export type AnnotationInfoBoxPayload = {
44
pixelWidth: number;
55
headingColor: string;
66
headingTitle: string;
7-
headingActions?: ReactNode;
87
collapsible: boolean;
98
footer: ReactNode;
109
subtitle: ReactNode;

libraries/mapping/annotations/runtime/src/lib/components/annotation-info-box/AnnotationInfoBox.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ export function AnnotationInfoBox({
1414
pixelWidth: boxWidth,
1515
headingColor,
1616
headingTitle,
17-
headingActions,
1817
collapsible,
1918
footer,
2019
subtitle,
@@ -31,11 +30,10 @@ export function AnnotationInfoBox({
3130
headingColor={headingColor}
3231
footer={footer}
3332
heading={
34-
<div className="w-full px-2 flex items-center justify-between">
33+
<div className="w-full px-2 flex items-center">
3534
<span className="truncate" title={headingTitle}>
3635
{headingTitle}
3736
</span>
38-
{headingActions ?? null}
3937
</div>
4038
}
4139
subtitle={subtitle}

libraries/mapping/annotations/runtime/src/lib/components/annotation-info-box/annotationInfoBoxSlots.types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ export type AnnotationInfoBoxEntryPayload = {
8585

8686
export type AnnotationSlots = {
8787
headingTitle: string;
88-
headingActions?: ReactNode;
8988
subtitle: ReactNode;
9089
content: ReactNode;
9190
collapsible: boolean;

libraries/mapping/annotations/runtime/src/lib/components/annotation-info-box/components/AnnotationInfoBoxActionIcon.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
22
import { Tooltip } from "antd";
33
import type { IconDefinition } from "@fortawesome/fontawesome-svg-core";
44
import type { MouseEvent as ReactMouseEvent } from "react";
5+
import { annotationTooltipProps } from "../../shared/annotationTooltip";
56

67
const DEFAULT_ICON_CLASSNAME =
78
"cursor-pointer text-base text-[#808080] hover:text-[#a0a0a0]";
@@ -24,7 +25,7 @@ export const AnnotationInfoBoxActionIcon = ({
2425
ariaLabel,
2526
}: AnnotationInfoBoxActionIconProps) => {
2627
return (
27-
<Tooltip title={title}>
28+
<Tooltip {...annotationTooltipProps} title={title}>
2829
<FontAwesomeIcon
2930
onClick={onClick}
3031
className={className ?? DEFAULT_ICON_CLASSNAME}

libraries/mapping/annotations/runtime/src/lib/components/annotation-info-box/components/AnnotationJsonPreview.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ export const AnnotationJsonPreview = ({
99
}: AnnotationJsonPreviewProps) => {
1010
if (value == null) {
1111
return (
12-
<div className="mt-2 w-[90%] p-2 text-[#212529] font-normal text-xs leading-normal">
12+
<div className="mt-2 w-[90%] p-2 text-[#212529] font-normal text-[12px] leading-normal">
1313
{emptyText}
1414
</div>
1515
);
1616
}
1717

1818
return (
19-
<pre className="m-0 w-full overflow-auto px-2 pb-2 text-[11px] leading-normal text-[#212529] whitespace-pre-wrap break-words">
19+
<pre className="m-0 w-full overflow-auto px-2 pb-2 text-[12px] leading-normal text-[#212529] whitespace-pre-wrap break-words">
2020
{JSON.stringify(value, null, 2)}
2121
</pre>
2222
);

libraries/mapping/annotations/runtime/src/lib/components/annotation-info-box/content-generators/getDistanceAnnotationInfoBoxSlots.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import type {
1616
import {
1717
DISTANCE_TITLE,
1818
getDistanceInstructionText,
19-
getDistanceTitleToken,
19+
getInfoBoxDistanceDefaultName,
2020
renderDistanceTableContent,
2121
renderEditableAnnotationSubtitle,
2222
} from "./shared";
@@ -244,8 +244,7 @@ export const getDistanceAnnotationInfoBoxSlots = (
244244
return {
245245
headingTitle: DISTANCE_TITLE,
246246
subtitle: renderEditableAnnotationSubtitle({
247-
annotationTypeTitle: DISTANCE_TITLE,
248-
titleToken: getDistanceTitleToken({
247+
defaultDisplayName: getInfoBoxDistanceDefaultName({
249248
currentOrderToken,
250249
currentOrder,
251250
nextOrder,

0 commit comments

Comments
 (0)