Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove "getCoordinate" from the Annotation Model #65

Merged
merged 1 commit into from
Dec 16, 2022
Merged
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
10 changes: 0 additions & 10 deletions src/annotation/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export interface IAnnotation {

export class AnnotationModel {
constructor(options: AnnotationModel.IOptions) {
this._getCoordinate = options.getCoordinate;
this._sharedModel = options.sharedModel;
const state = this._sharedModel.awareness.getLocalState();
this._user = state?.user;
Expand Down Expand Up @@ -49,13 +48,6 @@ export class AnnotationModel {
this._sharedModel.removeMetadata(key);
}

getCoordinate(id: string): [number, number] | undefined {
const annotation = this.getAnnotation(id);
if (annotation?.position) {
return this._getCoordinate(annotation.position);
}
}

addContent(id: string, value: string): void {
const newContent: IAnnotationContent = {
value,
Expand All @@ -73,14 +65,12 @@ export class AnnotationModel {
}

private _sharedModel: IJupyterCadDoc;
private _getCoordinate: (input: [number, number, number]) => [number, number];
private _updateSignal = new Signal<this, null>(this);
private _user?: User.IIdentity;
}

namespace AnnotationModel {
export interface IOptions {
sharedModel: IJupyterCadDoc;
getCoordinate: (input: [number, number, number]) => [number, number];
}
}
11 changes: 8 additions & 3 deletions src/mainview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ export class MainView extends React.Component<IProps, IStates> {
this._messageChannel.port2
);
this._annotationModel = new AnnotationModel({
sharedModel: this._model.sharedModel,
getCoordinate: this._projectVector
sharedModel: this._model.sharedModel
});
this._model.themeChanged.connect(this._handleThemeChange);
this._model.clientStateChanged.connect(this._onClientSharedStateChanged);
Expand Down Expand Up @@ -435,7 +434,13 @@ export class MainView extends React.Component<IProps, IStates> {
options.updatePosition &&
(el.style.opacity !== '0' || options.updateDisplay !== undefined)
) {
const newPos = this._annotationModel.getCoordinate(key) ?? [0, 0];
const annotation = this._annotationModel.getAnnotation(key);
let newPos: [number, number] | undefined;
if (annotation?.position) {
newPos = this._projectVector(annotation.position);
} else {
newPos = [0, 0];
}
el.style.top = `${newPos[1]}px`;
el.style.left = `${newPos[0]}px`;
}
Expand Down