Skip to content

Commit

Permalink
Hide annotations when movable line is hidden
Browse files Browse the repository at this point in the history
  • Loading branch information
bgoldowsky committed Mar 27, 2024
1 parent 16f7218 commit 19f3953
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,11 @@ export const MovableLineModel = AdornmentModel
.views(self => ({
getAnnotatableObjects(tileId: string) {
const objects: IClueObject[] = [];
for (const key of self.lines.keys()) {
objects.push({ tileId, objectType: "movable-line-handle", objectId: getAnnotationId(key, "lower") });
objects.push({ tileId, objectType: "movable-line-handle", objectId: getAnnotationId(key, "upper") });
if (self.isVisible) {
for (const key of self.lines.keys()) {
objects.push({ tileId, objectType: "movable-line-handle", objectId: getAnnotationId(key, "lower") });
objects.push({ tileId, objectType: "movable-line-handle", objectId: getAnnotationId(key, "upper") });
}
}
return objects;
}
Expand Down
7 changes: 6 additions & 1 deletion src/plugins/graph/adornments/movable-line/movable-line.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,11 @@ export const MovableLine = observer(function MovableLine(props: IProps) {
.attr('cx', x)
.attr('cy', y);
const annotationId = getAnnotationId(instanceKey, index===1 ? "lower" : "upper");
annotationLocationSetter?.set(annotationId, { x, y });
if (model.isVisible) {
annotationLocationSetter?.set(annotationId, { x, y });
} else {

Check warning on line 140 in src/plugins/graph/adornments/movable-line/movable-line.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/graph/adornments/movable-line/movable-line.tsx#L140

Added line #L140 was not covered by tests
annotationLocationSetter?.set(annotationId, undefined);
}
}
}

Expand Down Expand Up @@ -387,6 +391,7 @@ export const MovableLine = observer(function MovableLine(props: IProps) {
newLineObject.equation = equationDiv;
setLineObject(newLineObject);

// disposer
return () => {
equationDiv.remove();
};
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/graph/graph-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export const GraphEditModes = ["none", "edit", "add"];
export type GraphEditMode = typeof GraphEditModes[number];

export interface ILocationSetterContext {
set: (id: string, location: Point) => void;
set: (id: string, location: Point|undefined) => void;
}

export const LocationSetterContext = createContext<ILocationSetterContext|undefined>(undefined);
8 changes: 6 additions & 2 deletions src/plugins/graph/models/graph-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,12 @@ export const GraphModel = TileContentModel
setInteractionInProgress(value: boolean) {
self.interactionInProgress = value;
},
setAnnotationLocation(id: string, location: Point) {
self.annotationLocationCache.set(id, location);
setAnnotationLocation(id: string, location: Point|undefined) {
if (location) {
self.annotationLocationCache.set(id, location);
} else {

Check warning on line 420 in src/plugins/graph/models/graph-model.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/graph/models/graph-model.ts#L420

Added line #L420 was not covered by tests
self.annotationLocationCache.delete(id);
}
}
}))
.actions(self => ({
Expand Down

0 comments on commit 19f3953

Please sign in to comment.