RED-10426: rewrote sorting considering given point as bottom left.

This commit is contained in:
Nicoleta Panaghiu 2024-11-25 14:28:48 +02:00
parent 8d60e8d864
commit 0b367efa27
2 changed files with 21 additions and 21 deletions

View File

@ -40,7 +40,7 @@ export class AnnotationWrapper implements IListable {
typeLabel?: string;
color: string;
numberOfComments = 0;
firstTopLeftPoint: IPoint;
firstBottomLeftPoint: IPoint;
shortContent: string;
content: AnnotationContent;
value: string;
@ -199,11 +199,11 @@ export class AnnotationWrapper implements IListable {
}
get x() {
return this.firstTopLeftPoint.x;
return this.firstBottomLeftPoint.x;
}
get y() {
return this.firstTopLeftPoint.y;
return this.firstBottomLeftPoint.y;
}
get legalBasis() {
@ -228,7 +228,7 @@ export class AnnotationWrapper implements IListable {
annotationWrapper.value = 'Imported';
annotationWrapper.color = earmark.hexColor;
annotationWrapper.positions = earmark.positions;
annotationWrapper.firstTopLeftPoint = earmark.positions[0]?.topLeft;
annotationWrapper.firstBottomLeftPoint = earmark.positions[0]?.topLeft;
annotationWrapper.superTypeLabel = annotationTypesTranslations[annotationWrapper.superType];
return annotationWrapper;
@ -249,7 +249,7 @@ export class AnnotationWrapper implements IListable {
annotationWrapper.isChangeLogEntry = logEntry.state === EntryStates.REMOVED || !!changeLogType;
annotationWrapper.type = logEntry.type;
annotationWrapper.value = logEntry.value;
annotationWrapper.firstTopLeftPoint = { x: logEntry.positions[0].rectangle[0], y: logEntry.positions[0].rectangle[1] };
annotationWrapper.firstBottomLeftPoint = { x: logEntry.positions[0].rectangle[0], y: logEntry.positions[0].rectangle[1] };
annotationWrapper.pageNumber = logEntry.positions[0].pageNumber;
annotationWrapper.positions = logEntry.positions.map(p => ({
page: p.pageNumber,

View File

@ -1,18 +1,18 @@
import { AnnotationWrapper } from '@models/file/annotation.wrapper';
export const sortTopLeftToBottomRight = (a1: AnnotationWrapper, a2: AnnotationWrapper): number => {
const top = Math.min(a1.y, a2.y);
const bottom = Math.max(a1.y - a1.height, a2.y - a2.height);
const top = Math.min(a1.y + a1.height, a2.y + a2.height);
const bottom = Math.max(a1.y, a2.y);
const intersectionHeight = Math.max(0, top - bottom);
const a1IntersectionPercentage = (intersectionHeight / a1.height) * 100;
const a2IntersectionPercentage = (intersectionHeight / a2.height) * 100;
if (a1IntersectionPercentage || a2IntersectionPercentage) {
if (a1IntersectionPercentage > 10 || a2IntersectionPercentage > 10) {
return a1.x < a2.x ? -1 : 1;
}
if (a1.y > a2.y) {
if (a1.y + a1.height > a2.y + a2.height) {
return -1;
}
if (a1.y < a2.y) {
if (a1.y + a1.height < a2.y + a2.height) {
return 1;
}
return a1.x < a2.x ? -1 : 1;
@ -24,8 +24,8 @@ export const sortBottomLeftToTopRight = (a1: AnnotationWrapper, a2: AnnotationWr
const intersectionHeight = Math.max(0, bottom - top);
const a1IntersectionPercentage = (intersectionHeight / a1.width) * 100;
const a2IntersectionPercentage = (intersectionHeight / a2.width) * 100;
if (a1IntersectionPercentage || a2IntersectionPercentage) {
return a1.y < a2.y ? -1 : 1;
if (a1IntersectionPercentage > 10 || a2IntersectionPercentage > 10) {
return a1.y + a1.height < a2.y + a2.height ? -1 : 1;
}
if (a1.x < a2.x) {
return -1;
@ -33,7 +33,7 @@ export const sortBottomLeftToTopRight = (a1: AnnotationWrapper, a2: AnnotationWr
if (a1.x > a2.x) {
return 1;
}
return a1.y < a2.y ? -1 : 1;
return a1.y + a1.height < a2.y + a2.height ? -1 : 1;
};
export const sortBottomRightToTopLeft = (a1: AnnotationWrapper, a2: AnnotationWrapper): number => {
@ -42,8 +42,8 @@ export const sortBottomRightToTopLeft = (a1: AnnotationWrapper, a2: AnnotationWr
const intersectionHeight = Math.max(0, bottom - top);
const a1IntersectionPercentage = (intersectionHeight / a1.height) * 100;
const a2IntersectionPercentage = (intersectionHeight / a2.height) * 100;
if (a1IntersectionPercentage || a2IntersectionPercentage) {
return a1.x > a2.x ? -1 : 1;
if (a1IntersectionPercentage > 10 || a2IntersectionPercentage > 10) {
return a1.x + a1.width > a2.x + a2.width ? -1 : 1;
}
if (a1.y < a2.y) {
return -1;
@ -51,7 +51,7 @@ export const sortBottomRightToTopLeft = (a1: AnnotationWrapper, a2: AnnotationWr
if (a1.y > a2.y) {
return 1;
}
return a1.x > a2.x ? -1 : 1;
return a1.x + a1.width > a2.x + a2.width ? -1 : 1;
};
export const sortTopRightToBottomLeft = (a1: AnnotationWrapper, a2: AnnotationWrapper): number => {
const top = Math.min(a1.x + a1.width, a2.x + a2.width);
@ -59,14 +59,14 @@ export const sortTopRightToBottomLeft = (a1: AnnotationWrapper, a2: AnnotationWr
const intersectionHeight = Math.max(0, top - bottom);
const a1IntersectionPercentage = (intersectionHeight / a1.width) * 100;
const a2IntersectionPercentage = (intersectionHeight / a2.width) * 100;
if (a1IntersectionPercentage || a2IntersectionPercentage) {
return a1.y > a2.y ? -1 : 1;
if (a1IntersectionPercentage > 10 || a2IntersectionPercentage > 10) {
return a1.y + a1.height > a2.y + a2.height ? -1 : 1;
}
if (a1.x > a2.x) {
if (a1.x + a1.width > a2.x + a2.width) {
return -1;
}
if (a1.x < a2.x) {
if (a1.x + a1.width < a2.x + a2.width) {
return 1;
}
return a1.y > a2.y ? -1 : 1;
return a1.y + a1.height > a2.y + a2.height ? -1 : 1;
};