Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
{
"$ref": "#/definitions/PolygonTool"
},
{
"$ref": "#/definitions/RelationTool"
},
{
"$ref": "#/definitions/CuboidTool"
},
Expand Down Expand Up @@ -323,6 +326,55 @@
},
"required": ["toolName", "result"]
},
"RelationTool": {
"type": "object",
"properties": {
"toolName": {
"type": "string",
"const": "relationTool"
},
"result": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "string",
"description": "唯一标识"
},
"sourceId": {
"type": "string",
"description": "起始标注id"
},
"targetId": {
"type": "string",
"description": "目标标注id"
},
"visible": {
"type": "boolean",
"description": "是否可见",
"default": true
},
"attributes": {
"$ref": "#/definitions/Attribute"
},
"order": {
"type": "integer",
"description": "标注顺序",
"minimum": 0
},
"label": {
"type": "string",
"description": "标注标签",
"default": "none"
}
},
"required": ["sourceId", "targetId", "id", "order", "label"]
}
}
},
"required": ["toolName", "result"]
},
"RectTool": {
"type": "object",
"properties": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
"$ref": "#/definitions/LabelItem"
}
},
"relationTool": {
"type": "array",
"items": {
"$ref": "#/definitions/LabelItem"
}
},
"cuboidTool": {
"type": "array",
"items": {
Expand Down Expand Up @@ -161,6 +167,24 @@
},
"required": ["toolName", "result"]
},
"relationTool": {
"type": "object",
"properties": {
"toolName": {
"type": "string",
"const": "relationTool",
"default": "relationTool"
},
"result": {
"description": "标注结果",
"type": "array",
"items": {
"$ref": "#/definitions/RelationTool"
}
}
},
"required": ["toolName", "result"]
},
"textTool": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -608,6 +632,55 @@
},
"required": ["direction", "front", "back", "x", "y", "width", "height", "id", "order", "label"]
},
"RelationTool": {
"type": "object",
"properties": {
"toolName": {
"type": "string",
"const": "relationTool"
},
"result": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "string",
"description": "唯一标识"
},
"sourceId": {
"type": "string",
"description": "起始标注id"
},
"targetId": {
"type": "string",
"description": "目标标注id"
},
"visible": {
"type": "boolean",
"description": "是否可见",
"default": true
},
"attributes": {
"$ref": "#/definitions/Attribute"
},
"order": {
"type": "integer",
"description": "标注顺序",
"minimum": 0
},
"label": {
"type": "string",
"description": "标注标签",
"default": "none"
}
},
"required": ["sourceId", "targetId", "id", "order", "label"]
}
}
},
"required": ["toolName", "result"]
},
"TextTool": {
"type": "array",
"items": {
Expand Down
9 changes: 6 additions & 3 deletions apps/frontend/src/pages/tasks.[id].samples.[id]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ export const imageAnnotationRef = createRef<ImageAnnotatorRef>();
export const videoAnnotationRef = createRef<AudioAndVideoAnnotatorRef>();
export const audioAnnotationRef = createRef<AudioAndVideoAnnotatorRef>();

const PREVIEW_OFFSET_TOP = 102;
const OFFSET_TOP = 158;

const AnnotationPage = () => {
const routeParams = useParams();
const { task } = useRouteLoaderData('task') as TaskLoaderResult;
Expand Down Expand Up @@ -308,7 +311,7 @@ const AnnotationPage = () => {
ref={imageAnnotationRef}
onError={onError}
// windows platform pixel issue
offsetTop={configFromParent ? 100 : 158}
offsetTop={configFromParent ? PREVIEW_OFFSET_TOP : OFFSET_TOP}
editingSample={editingSample}
config={config}
disabled={disabled}
Expand All @@ -326,7 +329,7 @@ const AnnotationPage = () => {
<Annotator
primaryColor="#0d53de"
ref={videoAnnotationRef}
offsetTop={configFromParent ? 100 : 156}
offsetTop={configFromParent ? PREVIEW_OFFSET_TOP : OFFSET_TOP}
editingSample={editingSample}
config={config}
toolbarRight={topActionContent}
Expand All @@ -346,7 +349,7 @@ const AnnotationPage = () => {
<AudioAnnotator
primaryColor="#0d53de"
ref={audioAnnotationRef}
offsetTop={configFromParent ? 100 : 156}
offsetTop={configFromParent ? PREVIEW_OFFSET_TOP : OFFSET_TOP}
editingSample={editingSample}
config={config}
disabled={disabled}
Expand Down
6 changes: 4 additions & 2 deletions packages/image-annotator-react/src/assets/tools/relation.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 8 additions & 1 deletion packages/image/src/annotations/Annotation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,21 @@ export class Annotation<Data extends BasicImageAnnotation, Style> {
return { x, y, rotate: finalRotate };
}

static createTextDomPortal(content: string, isAboveLine: boolean, order: number, bindShape: Line): DomPortal {
static createTextDomPortal(
content: string,
isAboveLine: boolean,
order: number,
bindShape: Line,
style?: Record<string, string>,
): DomPortal {
return new DomPortal({
content,
getPosition: (shape, container) =>
Annotation.calculateTextPosition({ shape: shape as Line, container, isAboveLine }),
order,
preventPointerEvents: true,
bindShape,
style,
});
}

Expand Down
6 changes: 6 additions & 0 deletions packages/image/src/annotations/Cuboid.annotation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ export class AnnotationCuboid extends Annotation<CuboidData, CuboidStyle> {
order: data.order,
preventPointerEvents: true,
bindShape: backShape,
style: {
display: visible ? 'block' : 'none',
},
}),
);

Expand All @@ -255,6 +258,9 @@ export class AnnotationCuboid extends Annotation<CuboidData, CuboidStyle> {
order: data.order,
preventPointerEvents: true,
bindShape: frontShape,
style: {
display: visible ? 'block' : 'none',
},
}),
);
}
Expand Down
6 changes: 6 additions & 0 deletions packages/image/src/annotations/Line.annotation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ export class AnnotationLine extends Annotation<LineData, LineStyle> {
order: data.order,
preventPointerEvents: true,
bindShape: group.shapes[0] as Line,
style: {
display: visible ? 'block' : 'none',
},
}),
);

Expand All @@ -157,6 +160,9 @@ export class AnnotationLine extends Annotation<LineData, LineStyle> {
order: data.order,
preventPointerEvents: true,
bindShape: group.shapes[0],
style: {
display: visible ? 'block' : 'none',
},
}),
);
}
Expand Down
6 changes: 6 additions & 0 deletions packages/image/src/annotations/Point.annotation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ export class AnnotationPoint extends Annotation<PointData, PointStyle> {
order: data.order,
preventPointerEvents: true,
bindShape: group.shapes[0],
style: {
display: visible ? 'block' : 'none',
},
}),
);

Expand All @@ -90,6 +93,9 @@ export class AnnotationPoint extends Annotation<PointData, PointStyle> {
order: data.order,
preventPointerEvents: true,
bindShape: group.shapes[0],
style: {
display: visible ? 'block' : 'none',
},
}),
);
}
Expand Down
6 changes: 6 additions & 0 deletions packages/image/src/annotations/Polygon.annotation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ export class AnnotationPolygon extends Annotation<PolygonData, PolygonStyle> {
order: data.order,
preventPointerEvents: true,
bindShape: group.shapes[0],
style: {
display: visible ? 'block' : 'none',
},
}),
);

Expand All @@ -151,6 +154,9 @@ export class AnnotationPolygon extends Annotation<PolygonData, PolygonStyle> {
order: data.order,
preventPointerEvents: true,
bindShape: group.shapes[0],
style: {
display: visible ? 'block' : 'none',
},
}),
);
}
Expand Down
6 changes: 6 additions & 0 deletions packages/image/src/annotations/Rect.annotation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ export class AnnotationRect extends Annotation<RectData, RectStyle> {
order: data.order,
preventPointerEvents: true,
bindShape: group.shapes[0] as Rect,
style: {
display: visible ? 'block' : 'none',
},
}),
);

Expand All @@ -95,6 +98,9 @@ export class AnnotationRect extends Annotation<RectData, RectStyle> {
order: data.order,
preventPointerEvents: true,
bindShape: group.shapes[0] as Rect,
style: {
display: visible ? 'block' : 'none',
},
}),
);
}
Expand Down
6 changes: 6 additions & 0 deletions packages/image/src/annotations/Relation.annotation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ export class AnnotationRelation extends Annotation<RelationData, LineStyle> {
false, // 标签文本在线条下方
data.order,
group.shapes[0] as Line,
{
display: visible ? 'block' : 'none',
},
),
);

Expand All @@ -175,6 +178,9 @@ export class AnnotationRelation extends Annotation<RelationData, LineStyle> {
true, // 属性文本在线条上方
data.order,
group.shapes[0] as Line,
{
display: visible ? 'block' : 'none',
},
),
);
}
Expand Down
10 changes: 6 additions & 4 deletions packages/image/src/core/DomPortal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface DomPortalParams {
content: HTMLElement | string;
bindShape: AllShape;
preventPointerEvents?: boolean;
style?: Record<string, string>;
}

export class DomPortal {
Expand Down Expand Up @@ -48,6 +49,7 @@ export class DomPortal {
order = 2,
rotate = 0,
getPosition,
style,
}: DomPortalParams) {
this._content = content;
this._shape = bindShape;
Expand Down Expand Up @@ -100,6 +102,10 @@ export class DomPortal {

this._container.appendChild(this._wrapper);
this._setupElementStyle();

if (style) {
Object.assign(this._wrapper.style, style);
}
}

private _setupElementStyle() {
Expand Down Expand Up @@ -154,10 +160,6 @@ export class DomPortal {
this._wrapper.style.display = 'none';
}

public setOpacity(opacity: number) {
this._wrapper.style.opacity = `${opacity}`;
}

public toTop() {
this._wrapper.style.zIndex = '1049';
}
Expand Down
Loading