Skip to content

Commit

Permalink
Remove "getCoordinate" from the Annotation Model (#65)
Browse files Browse the repository at this point in the history
This will make it easier to reuse the annotation model from outside the
main view
  • Loading branch information
martinRenou authored Dec 16, 2022
1 parent 012976e commit f172644
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
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

0 comments on commit f172644

Please sign in to comment.