Skip to content

Commit 57f93b6

Browse files
committed
[Editor] Various bug fixes
Fixed the following issues - Double assignments - Pre Annotation loading - History undo & redo doesn't unhighlight fixation - preview algorithm annotations not working - preview algorithm annotations colours config not applying -
1 parent a332ca1 commit 57f93b6

File tree

6 files changed

+52
-37
lines changed

6 files changed

+52
-37
lines changed

src/editor/config.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const autoSaveInterval = ref( 60000 );
2424
export const assignedLineColor = ref( rs.getPropertyValue( '--theme-information-shade' ) );
2525

2626
// TODO: Do we want this setting?
27-
export const machineAssignedLineColor = ref( rs.getPropertyValue( '--theme-information-shade' ) );
27+
export const machineAssignedLineColor = ref( rs.getPropertyValue( '--theme-warning-shade' ) );
2828

2929
export const cursorLineColor = ref( rs.getPropertyValue( '--theme-bg-4' ) );
3030

@@ -76,8 +76,7 @@ export const selectedFixationRadius = ref( 8 );
7676

7777
export const lineWidth = ref( 3 );
7878

79-
// TODO: Do we want this setting?
80-
export const machineAssignedLineWidth = ref( 3 );
79+
export const machineAssignedLineWidth = ref( 1 );
8180

8281
export const indicesFontSize = ref( 14 );
8382

src/editor/loaders/backend.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,19 +105,21 @@ export const loadEditorDataFromBackend = async ( renderer: Renderer ) => {
105105
const algos = Object.keys( additionalAnnotationLoad );
106106

107107
algos.forEach( algo => {
108-
const details = additionalAnnotationLoad[ algo ]! as AnnotationDto;
108+
const details = additionalAnnotationLoad[ algo ]! as AnnotationDto[];
109109

110-
if ( details.fixation && details.characterBoundingBox ) {
111-
const ann: EditorAnnotation = {
112-
'fixationIdx': getFixIdxFromId( details.fixation!.id! ),
113-
'boxIdx': getBoxIdxFromId( details.characterBoundingBox!.id! ),
114-
'algorithm': algo
115-
};
110+
details.forEach( annotation => {
111+
if ( annotation.fixation && annotation.characterBoundingBox ) {
112+
const ann: EditorAnnotation = {
113+
'fixationIdx': getFixIdxFromId( annotation.fixation!.id! ),
114+
'boxIdx': getBoxIdxFromId( annotation.characterBoundingBox!.id! ),
115+
'algorithm': algo
116+
};
116117

117-
fixations.value[ ann.fixationIdx ]!.assigned = details.annotationType === 'ANNOTATED' ? 'assigned' : 'machine';
118+
fixations.value[ ann.fixationIdx ]!.assigned = annotation.annotationType === 'ANNOTATED' ? 'assigned' : 'machine';
118119

119-
annotations.value.push( ann );
120-
}
120+
annotations.value.push( ann );
121+
}
122+
} );
121123
} );
122124
}
123125

src/editor/manager/annotations.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export const annotationManager = ( renderer: Renderer ): AnnotationManager => {
4646

4747
// Add to history
4848
if ( !skipHistory )
49-
history.add( annotation, fixationIndex );
49+
history.add( annotation, fixationIndex, fixations.value[ fixationIndex ]!.assigned );
5050

5151
if ( highlight )
5252
highlightBox( boundingBoxIndex, 1000 );
@@ -92,7 +92,7 @@ export const annotationManager = ( renderer: Renderer ): AnnotationManager => {
9292

9393
if ( fixations.value[ fixationId ]!.assigned === 'assigned' ) {
9494
for ( let i = 0; i < annotations.value.length; i++ ) {
95-
if ( annotations.value[ i ]!.fixationIdx === fixationId ) {
95+
if ( annotations.value[ i ]!.fixationIdx === fixationId && !annotations.value[ i ]!.algorithm ) {
9696
idx = i;
9797
break;
9898
}
@@ -101,15 +101,19 @@ export const annotationManager = ( renderer: Renderer ): AnnotationManager => {
101101
if ( idx > -1 ) {
102102
const d = annotations.value.splice( idx, 1 );
103103

104-
fixations.value[ fixationId ]!.assigned = 'unassigned';
104+
console.log( 'Removing annotation', d, 'with fix idx', fixationId );
105+
105106

106107
if ( addActionToHistory ) {
107-
history.remove( d[ 0 ]!, selectedFixation.value );
108-
renderer.renderLines.render();
109-
renderer.renderFixations.render();
110-
renderer.renderIndices.render();
108+
history.remove( d[ 0 ]!, selectedFixation.value, fixations.value[ fixationId ]!.assigned );
111109
}
112110

111+
fixations.value[ fixationId ]!.assigned = 'unassigned';
112+
113+
renderer.renderIndices.render();
114+
renderer.renderFixations.render();
115+
renderer.renderLines.render();
116+
113117
highlightBox( d[ 0 ]!.boxIdx, 3000 );
114118
}
115119
}
@@ -123,7 +127,7 @@ export const annotationManager = ( renderer: Renderer ): AnnotationManager => {
123127
let idx = -1;
124128

125129
for ( let i = 0; i < annotations.value.length; i++ ) {
126-
if ( annotations.value[ i ]!.boxIdx === boxId ) {
130+
if ( annotations.value[ i ]!.boxIdx === boxId && !annotations.value[ i ]!.algorithm ) {
127131
idx = i;
128132
break;
129133
}

src/editor/manager/history.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,24 +53,25 @@ const startHistoryTracker = ( renderer: Renderer, annotation: AnnotationManager
5353
if ( last.action === 'delete' ) annotation.deleteByFixID( last.annotation.fixationIdx );
5454
else annotation.create( last.annotation.boxIdx, last.annotation.fixationIdx, true, false );
5555

56-
if ( last.annotation.boxIdx !== undefined ) {
57-
fixations.value[ last.annotation.fixationIdx ]!.assigned = 'assigned';
58-
} else {
59-
fixations.value[ last.annotation.fixationIdx ]!.assigned = 'unassigned';
60-
}
56+
fixations.value[ last.annotation.fixationIdx ]!.assigned = last.fixationState;
6157

6258
renderer.renderLines.render();
6359
renderer.renderFixations.render();
6460
};
6561

66-
const add = ( annotation: EditorAnnotation, selectedFixation: number ) => {
62+
const add = (
63+
annotation: EditorAnnotation,
64+
selectedFixation: number,
65+
oldState: 'assigned' | 'unassigned' | 'machine' | 'invalid'
66+
) => {
6767
revision.value++;
6868

6969
undoHistory.value.push( {
7070
'annotation': {
7171
...annotation
7272
},
7373
'selectedFixation': selectedFixation,
74+
'fixationState': oldState,
7475
'action': 'add'
7576
} );
7677
clearRedo();
@@ -81,14 +82,19 @@ const startHistoryTracker = ( renderer: Renderer, annotation: AnnotationManager
8182
* @param annotation - The annotation that was removed
8283
* @param selectedFixation - The fixation that was selected
8384
*/
84-
const remove = ( annotation: EditorAnnotation, selectedFixation: number ) => {
85+
const remove = (
86+
annotation: EditorAnnotation,
87+
selectedFixation: number,
88+
oldState: 'assigned' | 'unassigned' | 'machine' | 'invalid'
89+
) => {
8590
revision.value++;
8691

8792
undoHistory.value.push( {
8893
'annotation': {
8994
...annotation
9095
},
9196
'selectedFixation': selectedFixation,
97+
'fixationState': oldState,
9298
'action': 'delete'
9399
} );
94100
clearRedo();
@@ -106,13 +112,9 @@ const startHistoryTracker = ( renderer: Renderer, annotation: AnnotationManager
106112
if ( last.action === 'add' ) annotation.deleteByFixID( last.annotation.fixationIdx );
107113
else annotation.create( last.annotation.boxIdx, last.annotation.fixationIdx, true, false );
108114

109-
if ( last.annotation.boxIdx !== undefined ) {
110-
fixations.value[ last.annotation.fixationIdx ]!.assigned = 'assigned';
111-
} else {
112-
fixations.value[ last.annotation.fixationIdx ]!.assigned = 'unassigned';
113-
}
115+
fixations.value[ last.annotation.fixationIdx ]!.assigned = last.fixationState;
114116

115-
selectedFixation.value = last.selectedFixation + 1;
117+
selectedFixation.value = last.selectedFixation;
116118

117119
renderer.renderLines.render();
118120
renderer.renderFixations.render();

src/editor/render/lines.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import {
1616
assignedLineColor,
1717
lineWidth,
1818
linesDisplay,
19+
machineAssignedLineColor,
20+
machineAssignedLineWidth,
1921
numberOfLinesToRenderInSurroundingMode
2022
} from '../config';
2123
import {
@@ -55,10 +57,12 @@ export const linesRenderer = ( linesCanvas: Ref<HTMLCanvasElement | null> ) => {
5557
filterAlgorithms( l, surroundingDrawer );
5658
} );
5759
} else if ( linesDisplay.value === 'allalgos' ) {
58-
// TODO: Do we want more settings here? (like )
60+
ctx.lineWidth = scale( machineAssignedLineWidth.value );
61+
ctx.strokeStyle = machineAssignedLineColor.value;
62+
5963
if ( selectedFixation.value >= 0 )
6064
annotations.value.forEach( l => {
61-
if ( l.fixationIdx === selectedFixation.value )
65+
if ( l.fixationIdx === selectedFixation.value && l.algorithm )
6266
drawLine( l );
6367
} );
6468
}
@@ -69,7 +73,10 @@ export const linesRenderer = ( linesCanvas: Ref<HTMLCanvasElement | null> ) => {
6973

7074
if ( assignType === 'invalid' ) return;
7175

72-
if ( assignType === 'assigned' ) drawFunc( l );
76+
if ( assignType === 'assigned' ) {
77+
if ( !l.algorithm )
78+
drawFunc( l );
79+
}
7380

7481

7582
if ( !l.algorithm ) {

src/editor/types/history.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export interface HistoryEntry {
66
'annotation': EditorAnnotation;
77
'selectedFixation': number;
88
'action': 'add' | 'delete';
9+
'fixationState': 'assigned' | 'unassigned' | 'machine' | 'invalid';
910
}
1011

1112
export interface AnnotationManager {

0 commit comments

Comments
 (0)