Skip to content
Open
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
6 changes: 5 additions & 1 deletion src/ReactPictureAnnotation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,11 @@ export default class ReactPictureAnnotation extends React.Component<
);

if (isSelected) {
if (!this.currentTransformer) {
if (
!this.currentTransformer ||
this.currentTransformer.shape.getAnnotationData().id !==
item.getAnnotationData().id
) {
this.currentTransformer = new Transformer(
item,
this.scaleState.scale
Expand Down
3 changes: 2 additions & 1 deletion src/Transformer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { IShape, IShapeBase } from "Shape";

export interface ITransformer {
shape: IShape;
checkBoundary: (positionX: number, positionY: number) => boolean;
startTransformation: (positionX: number, positionY: number) => void;
onTransformation: (positionX: number, positionY: number) => void;
Expand All @@ -12,7 +13,7 @@ export interface ITransformer {
}

export default class Transformer implements ITransformer {
private readonly shape: IShape;
public readonly shape: IShape;
private currentNodeCenterIndex: number;
private scale: number;

Expand Down
65 changes: 44 additions & 21 deletions stories/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,28 +53,51 @@ storiesOf("Hello World", module)
};
}, []);

const onSelectNextClick = () => {
let i = 0;
let annotationId = "";
while (i < annotationData.length) {
if (annotationData[i].id === selectedId) {
if (i + 1 < annotationData.length) {
annotationId = annotationData[i + 1].id;
} else {
annotationId = annotationData[0].id;
}
}
i += 1;
}
setSelectedId(annotationId);
};

return (
<ReactPictureAnnotation
width={size.width}
height={size.height}
annotationData={annotationData}
onChange={(data) => setAnnotationData(data)}
selectedId={selectedId}
onSelect={(e) => setSelectedId(e)}
annotationStyle={{
...defaultShapeStyle,
shapeStrokeStyle: "#2193ff",
transformerBackground: "black",
}}
defaultAnnotationSize={[120, 90]}
image="https://bequank.oss-cn-beijing.aliyuncs.com/landpage/large/60682895_p0_master1200.jpg"
inputElement={(value, onChange, onDelete) => (
<DefaultInputSection
placeholder={"Hello world"}
{...{ value, onChange, onDelete }}
/>
)}
/>
<div>
<input
value={"Select next"}
type={"button"}
onClick={onSelectNextClick}
/>
<ReactPictureAnnotation
width={size.width}
height={size.height}
annotationData={annotationData}
onChange={(data) => setAnnotationData(data)}
selectedId={selectedId}
onSelect={(e) => setSelectedId(e)}
annotationStyle={{
...defaultShapeStyle,
shapeStrokeStyle: "#2193ff",
transformerBackground: "black",
}}
defaultAnnotationSize={[120, 90]}
image="https://bequank.oss-cn-beijing.aliyuncs.com/landpage/large/60682895_p0_master1200.jpg"
inputElement={(value, onChange, onDelete) => (
<DefaultInputSection
placeholder={"Hello world"}
{...{ value, onChange, onDelete }}
/>
)}
/>
</div>
);
};

Expand Down