|
|
|
|
@ -94,6 +94,11 @@ export class CanvasViewImpl implements CanvasView, Listener {
|
|
|
|
|
return this.serviceFlags.drawHidden[clientID] || false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private stateIsLocked(state: any): boolean {
|
|
|
|
|
const { configuration } = this.controller;
|
|
|
|
|
return state.lock || configuration.forceDisableEditing;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private setupServiceHidden(clientID: number, value: boolean): void {
|
|
|
|
|
this.serviceFlags.drawHidden[clientID] = value;
|
|
|
|
|
const shape = this.svgShapes[clientID];
|
|
|
|
|
@ -455,8 +460,8 @@ export class CanvasViewImpl implements CanvasView, Listener {
|
|
|
|
|
// Transform all text
|
|
|
|
|
for (const key in this.svgShapes) {
|
|
|
|
|
if (
|
|
|
|
|
Object.prototype.hasOwnProperty.call(this.svgShapes, key) &&
|
|
|
|
|
Object.prototype.hasOwnProperty.call(this.svgTexts, key)
|
|
|
|
|
Object.prototype.hasOwnProperty.call(this.svgShapes, key)
|
|
|
|
|
&& Object.prototype.hasOwnProperty.call(this.svgTexts, key)
|
|
|
|
|
) {
|
|
|
|
|
this.updateTextPosition(this.svgTexts[key], this.svgShapes[key]);
|
|
|
|
|
}
|
|
|
|
|
@ -874,9 +879,9 @@ export class CanvasViewImpl implements CanvasView, Listener {
|
|
|
|
|
this.content.addEventListener('mousedown', (event): void => {
|
|
|
|
|
if ([0, 1].includes(event.button)) {
|
|
|
|
|
if (
|
|
|
|
|
[Mode.IDLE, Mode.DRAG_CANVAS, Mode.MERGE, Mode.SPLIT].includes(this.mode) ||
|
|
|
|
|
event.button === 1 ||
|
|
|
|
|
event.altKey
|
|
|
|
|
[Mode.IDLE, Mode.DRAG_CANVAS, Mode.MERGE, Mode.SPLIT].includes(this.mode)
|
|
|
|
|
|| event.button === 1
|
|
|
|
|
|| event.altKey
|
|
|
|
|
) {
|
|
|
|
|
self.controller.enableDrag(event.clientX, event.clientY);
|
|
|
|
|
}
|
|
|
|
|
@ -1325,8 +1330,8 @@ export class CanvasViewImpl implements CanvasView, Listener {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
state.points.length !== drawnState.points.length ||
|
|
|
|
|
state.points.some((p: number, id: number): boolean => p !== drawnState.points[id])
|
|
|
|
|
state.points.length !== drawnState.points.length
|
|
|
|
|
|| state.points.some((p: number, id: number): boolean => p !== drawnState.points[id])
|
|
|
|
|
) {
|
|
|
|
|
const translatedPoints: number[] = translate(state.points);
|
|
|
|
|
|
|
|
|
|
@ -1542,7 +1547,7 @@ export class CanvasViewImpl implements CanvasView, Listener {
|
|
|
|
|
if (state && state.shapeType === 'points') {
|
|
|
|
|
this.svgShapes[clientID]
|
|
|
|
|
.remember('_selectHandler')
|
|
|
|
|
.nested.style('pointer-events', state.lock ? 'none' : '');
|
|
|
|
|
.nested.style('pointer-events', this.stateIsLocked(state) ? 'none' : '');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!state || state.hidden || state.outside) {
|
|
|
|
|
@ -1550,8 +1555,14 @@ export class CanvasViewImpl implements CanvasView, Listener {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const shape = this.svgShapes[clientID];
|
|
|
|
|
let text = this.svgTexts[clientID];
|
|
|
|
|
if (!text) {
|
|
|
|
|
text = this.addText(state);
|
|
|
|
|
this.svgTexts[state.clientID] = text;
|
|
|
|
|
}
|
|
|
|
|
this.updateTextPosition(text, shape);
|
|
|
|
|
|
|
|
|
|
if (state.lock) {
|
|
|
|
|
if (this.stateIsLocked(state)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -1567,12 +1578,6 @@ export class CanvasViewImpl implements CanvasView, Listener {
|
|
|
|
|
(shape as any).attr('projections', true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let text = this.svgTexts[clientID];
|
|
|
|
|
if (!text) {
|
|
|
|
|
text = this.addText(state);
|
|
|
|
|
this.svgTexts[state.clientID] = text;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const hideText = (): void => {
|
|
|
|
|
if (text) {
|
|
|
|
|
text.addClass('cvat_canvas_hidden');
|
|
|
|
|
@ -1601,12 +1606,14 @@ export class CanvasViewImpl implements CanvasView, Listener {
|
|
|
|
|
const p2 = e.detail.p;
|
|
|
|
|
const delta = 1;
|
|
|
|
|
const { offset } = this.controller.geometry;
|
|
|
|
|
if (Math.sqrt((p1.x - p2.x) ** 2 + (p1.y - p2.y) ** 2) >= delta) {
|
|
|
|
|
const dx2 = (p1.x - p2.x) ** 2;
|
|
|
|
|
const dy2 = (p1.y - p2.y) ** 2;
|
|
|
|
|
if (Math.sqrt(dx2 + dy2) >= delta) {
|
|
|
|
|
const points = pointsToNumberArray(
|
|
|
|
|
shape.attr('points') ||
|
|
|
|
|
`${shape.attr('x')},${shape.attr('y')} ` +
|
|
|
|
|
`${shape.attr('x') + shape.attr('width')},` +
|
|
|
|
|
`${shape.attr('y') + shape.attr('height')}`,
|
|
|
|
|
shape.attr('points')
|
|
|
|
|
|| `${shape.attr('x')},${shape.attr('y')} `
|
|
|
|
|
+ `${shape.attr('x') + shape.attr('width')},`
|
|
|
|
|
+ `${shape.attr('y') + shape.attr('height')}`,
|
|
|
|
|
).map((x: number): number => x - offset);
|
|
|
|
|
|
|
|
|
|
this.drawnStates[state.clientID].points = points;
|
|
|
|
|
@ -1677,10 +1684,10 @@ export class CanvasViewImpl implements CanvasView, Listener {
|
|
|
|
|
const { offset } = this.controller.geometry;
|
|
|
|
|
|
|
|
|
|
const points = pointsToNumberArray(
|
|
|
|
|
shape.attr('points') ||
|
|
|
|
|
`${shape.attr('x')},${shape.attr('y')} ` +
|
|
|
|
|
`${shape.attr('x') + shape.attr('width')},` +
|
|
|
|
|
`${shape.attr('y') + shape.attr('height')}`,
|
|
|
|
|
shape.attr('points')
|
|
|
|
|
|| `${shape.attr('x')},${shape.attr('y')} `
|
|
|
|
|
+ `${shape.attr('x') + shape.attr('width')},`
|
|
|
|
|
+ `${shape.attr('y') + shape.attr('height')}`,
|
|
|
|
|
).map((x: number): number => x - offset);
|
|
|
|
|
|
|
|
|
|
this.drawnStates[state.clientID].points = points;
|
|
|
|
|
@ -1697,7 +1704,6 @@ export class CanvasViewImpl implements CanvasView, Listener {
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.updateTextPosition(text, shape);
|
|
|
|
|
this.canvas.dispatchEvent(
|
|
|
|
|
new CustomEvent('canvas.activated', {
|
|
|
|
|
bubbles: false,
|
|
|
|
|
@ -1757,8 +1763,8 @@ export class CanvasViewImpl implements CanvasView, Listener {
|
|
|
|
|
// Find the best place for a text
|
|
|
|
|
let [clientX, clientY]: number[] = [box.x + box.width, box.y];
|
|
|
|
|
if (
|
|
|
|
|
clientX + ((text.node as any) as SVGTextElement).getBBox().width + consts.TEXT_MARGIN >
|
|
|
|
|
this.canvas.offsetWidth
|
|
|
|
|
clientX + ((text.node as any) as SVGTextElement).getBBox().width + consts.TEXT_MARGIN
|
|
|
|
|
> this.canvas.offsetWidth
|
|
|
|
|
) {
|
|
|
|
|
[clientX, clientY] = [box.x, box.y];
|
|
|
|
|
}
|
|
|
|
|
@ -1778,7 +1784,9 @@ export class CanvasViewImpl implements CanvasView, Listener {
|
|
|
|
|
|
|
|
|
|
private addText(state: any): SVG.Text {
|
|
|
|
|
const { undefinedAttrValue } = this.configuration;
|
|
|
|
|
const { label, clientID, attributes, source } = state;
|
|
|
|
|
const {
|
|
|
|
|
label, clientID, attributes, source,
|
|
|
|
|
} = state;
|
|
|
|
|
const attrNames = label.attributes.reduce((acc: any, val: any): void => {
|
|
|
|
|
acc[val.id] = val.name;
|
|
|
|
|
return acc;
|
|
|
|
|
|