Skip to content
This repository was archived by the owner on May 30, 2023. It is now read-only.

Commit ac4dbc1

Browse files
authored
Merge branch 'develop' into dependabot/npm_and_yarn/develop/react-toastify-9.1.1
2 parents a441da8 + ff4c1fb commit ac4dbc1

90 files changed

Lines changed: 2723 additions & 1856 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "daita-interface",
3-
"version": "0.1.0",
3+
"version": "1.1.0",
44
"private": true,
55
"description": "React-based user interface for the DAITA platform.",
66
"author": "DAITA Technologies",
@@ -52,6 +52,7 @@
5252
"@types/react-router-dom": "^5.1.7",
5353
"@types/react-virtualized": "^9.21.15",
5454
"@types/react-window": "^1.8.5",
55+
"@types/uuid": "^8.3.4",
5556
"axios": "^0.21.1",
5657
"axios-middleware": "^0.3.1",
5758
"chart.js": "^3.7.1",
@@ -89,7 +90,7 @@
8990
"styled-components": "^5.3.1",
9091
"typescript": "^4.3.2",
9192
"use-image": "^1.0.12",
92-
"uuid": "^8.3.2"
93+
"uuid": "^9.0.0"
9394
},
9495
"devDependencies": {
9596
"@typescript-eslint/eslint-plugin": "^5.4.0",

src/components/Annotation/Editor/Shape/EllipseShape.tsx

Lines changed: 89 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,31 @@ import {
1212
selectorDrawObjectState,
1313
selectorSelectedEllipse,
1414
} from "reduxes/annotation/selector";
15-
import { DrawState } from "reduxes/annotation/type";
16-
import { CIRCLE_STYLE, CORNER_RADIUS } from "../const";
15+
import { DrawObject, DrawState, DrawType } from "reduxes/annotation/type";
16+
import { selectorCurrentImageInEditorProps } from "reduxes/annotationmanager/selecetor";
17+
import { CIRCLE_STYLE, CORNER_RADIUS, LINE_STYLE } from "../const";
1718
import { EllipseCompProps, EllipseProps, EllipseSpec } from "../type";
1819
import useCommonShapeEvent from "../useCommonShapeEvent";
1920

20-
const EllipseComp = function ({
21+
export const createEllipse = (position: {
22+
x: number;
23+
y: number;
24+
}): DrawObject => {
25+
const id = `ELLIPSE-${Math.floor(Math.random() * 100000)}`;
26+
const shape: EllipseSpec = {
27+
x: position.x,
28+
y: position.y,
29+
radiusX: 1,
30+
radiusY: 1,
31+
rotation: 0,
32+
id,
33+
label: { label: id },
34+
cssStyle: { ...LINE_STYLE },
35+
};
36+
return { type: DrawType.ELLIPSE, data: shape };
37+
};
38+
39+
function EllipseComp({
2140
spec,
2241
onMouseOverHandler,
2342
onMouseOutHandler,
@@ -29,16 +48,19 @@ const EllipseComp = function ({
2948
const commonShapeEvent = useCommonShapeEvent({ drawObject: spec });
3049
const currentDrawState = useSelector(selectorCurrentDrawState);
3150
const drawObjectState = useSelector(selectorDrawObjectState(spec.id));
32-
51+
const currentImageInEditorProps = useSelector(
52+
selectorCurrentImageInEditorProps
53+
);
3354
const [strokeWidth, setStrokeWidth] = useState<number>(
3455
spec.cssStyle.strokeWidth
3556
);
3657

37-
const isSelected = useMemo(() => {
38-
return currentShape != null && spec.id === currentShape.id;
39-
}, [currentShape?.id]);
58+
const isSelected = useMemo(
59+
() => currentShape != null && spec.id === currentShape.id,
60+
[currentShape?.id]
61+
);
4062
useEffect(() => {
41-
if (isSelected == true) {
63+
if (isSelected === true) {
4264
shapeRef.current?.moveToTop();
4365
}
4466
}, [isSelected]);
@@ -56,42 +78,74 @@ const EllipseComp = function ({
5678
trRef.current.getLayer().batchDraw();
5779
}
5880
}, [isSelected]);
59-
const [stage, setStage] = useState<Konva.Stage | null>(null);
6081

6182
const groupDragBound = (pos: Vector2d) => {
6283
let { x, y } = pos;
63-
const sw = stage ? stage.width() : 0;
64-
const sh = stage ? stage.height() : 0;
65-
if (shapeRef && shapeRef.current) {
84+
if (shapeRef && shapeRef.current && currentImageInEditorProps) {
85+
const { clientRectOfBaseImage } = currentImageInEditorProps;
6686
const box = shapeRef.current.getClientRect();
6787

68-
if (y - box.height / 2 < 0) y = box.height / 2;
69-
if (x - box.width / 2 < 0) x = box.width / 2;
70-
if (y + box.height / 2 > sh) y = sh - box.height / 2;
71-
if (x + box.width / 2 > sw) x = sw - box.width / 2;
72-
return { x, y };
88+
if (clientRectOfBaseImage) {
89+
if (x - box.width / 2 < clientRectOfBaseImage.x) {
90+
x = clientRectOfBaseImage.x + box.width / 2;
91+
}
92+
if (y - box.height / 2 < clientRectOfBaseImage.y) {
93+
y = clientRectOfBaseImage.y + box.height / 2;
94+
}
95+
if (
96+
x + box.width >
97+
clientRectOfBaseImage.x + clientRectOfBaseImage.width
98+
) {
99+
x =
100+
clientRectOfBaseImage.x +
101+
clientRectOfBaseImage.width -
102+
box.width / 2;
103+
}
104+
if (
105+
y + box.height >
106+
clientRectOfBaseImage.y + clientRectOfBaseImage.height
107+
) {
108+
y =
109+
clientRectOfBaseImage.y +
110+
clientRectOfBaseImage.height -
111+
box.height / 2;
112+
}
113+
}
73114
}
74-
return { x: 0, y: 0 };
75-
};
76115

77-
const handleDragStart = (e: KonvaEventObject<DragEvent>) => {
78-
setStage(e.target.getStage());
79-
commonShapeEvent.handleDragStart(e);
116+
return {
117+
x,
118+
y,
119+
};
80120
};
121+
// const groupDragBound = (pos: Vector2d) => {
122+
// let { x, y } = pos;
123+
// const sw = stage ? stage.width() : 0;
124+
// const sh = stage ? stage.height() : 0;
125+
// if (shapeRef && shapeRef.current) {
126+
// const box = shapeRef.current.getClientRect();
127+
128+
// if (y - box.height / 2 < 0) y = box.height / 2;
129+
// if (x - box.width / 2 < 0) x = box.width / 2;
130+
// if (y + box.height / 2 > sh) y = sh - box.height / 2;
131+
// if (x + box.width / 2 > sw) x = sw - box.width / 2;
132+
// return { x, y };
133+
// }
134+
// return { x: 0, y: 0 };
135+
// };
136+
81137
const handleTransformEnd = (e: KonvaEventObject<Event>) => {
82138
const node = shapeRef.current;
83139
if (!node) return;
84-
85-
let radiusX = (node.width() * node.scaleX()) / 2.0;
86-
let radiusY = (node.height() * node.scaleY()) / 2.0;
87-
140+
const radiusX = (node.width() * node.scaleX()) / 2.0;
141+
const radiusY = (node.height() * node.scaleY()) / 2.0;
88142
onChange({
89143
...spec,
90144
x: node.x(),
91145
y: node.y(),
92146
rotation: node.attrs.rotation,
93-
radiusX: radiusX,
94-
radiusY: radiusY,
147+
radiusX,
148+
radiusY,
95149
});
96150
node.scale({ x: 1, y: 1 });
97151
commonShapeEvent.handleTransformEnd(e);
@@ -122,7 +176,7 @@ const EllipseComp = function ({
122176
};
123177

124178
return (
125-
<React.Fragment>
179+
<>
126180
<Ellipse
127181
ref={shapeRef}
128182
dragBoundFunc={groupDragBound}
@@ -133,7 +187,6 @@ const EllipseComp = function ({
133187
onMouseOut={onMouseOut}
134188
draggable={commonShapeEvent.isLock !== true}
135189
onDragEnd={handleDragEnd}
136-
onDragStart={handleDragStart}
137190
onTransformEnd={handleTransformEnd}
138191
strokeScaleEnabled={false}
139192
{...spec}
@@ -149,14 +202,14 @@ const EllipseComp = function ({
149202
anchorStrokeWidth={CIRCLE_STYLE.strokeWidth}
150203
anchorStroke={CIRCLE_STYLE.stroke}
151204
anchorSize={CORNER_RADIUS * 1.8}
152-
ignoreStroke={true}
205+
ignoreStroke
153206
boundBoxFunc={boundBoxFunc}
154207
/>
155208
)}
156-
</React.Fragment>
209+
</>
157210
);
158-
};
159-
const EllipseShape = function ({
211+
}
212+
function EllipseShape({
160213
id,
161214
onMouseOverHandler,
162215
onMouseOutHandler,
@@ -171,6 +224,6 @@ const EllipseShape = function ({
171224
/>
172225
);
173226
}
174-
return <></>;
175-
};
227+
return null;
228+
}
176229
export default EllipseShape;

0 commit comments

Comments
 (0)