Skip to content
This repository was archived by the owner on Apr 18, 2024. It is now read-only.

Commit 44995c2

Browse files
authored
fix: DEV-2577: keep keypoints the same size (#690)
* fix: DEV-2577: keep keypoints the same size They shouldn't grow when user zoom in * don't change keypoint size on select previously selected and highlighted keypoint had strokeWidth=2 * fix selected keypoint size via hook option
1 parent 72736a0 commit 44995c2

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/hooks/useRegionColor.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ type StyleOptions = (typeof defaultStyles) & {
2222
suggestion?: boolean,
2323
includeFill?: boolean,
2424
useStrokeAsFill?: boolean,
25+
sameStrokeWidthForSelected?: boolean,
2526
}
2627

2728
export const getRegionStyles = ({
2829
region,
2930
highlighted = false,
3031
shouldFill = false,
3132
useStrokeAsFill = false,
33+
sameStrokeWidthForSelected = false,
3234
suggestion = false,
3335
defaultOpacity = defaultStyle.opacity,
3436
defaultFillColor = defaultStyle.fillcolor,
@@ -59,7 +61,7 @@ export const getRegionStyles = ({
5961
const strokeWidth = (() => {
6062
if (suggestion) {
6163
return defaultSuggestionWidth;
62-
} else if (selected) {
64+
} else if (selected && !sameStrokeWidthForSelected) {
6365
return defaultStrokeWidthHighlighted;
6466
} else {
6567
return +(style?.strokewidth ?? defaultStrokeWidth);

src/regions/KeyPointRegion.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ const HtxKeyPointView = ({ item }) => {
174174
defaultFillColor: "#000",
175175
defaultStrokeColor: "#fff",
176176
defaultOpacity: (item.style ?? item.tag) ? 0.6 : 1,
177-
defaultStrokeWidth: 2,
177+
// avoid size glitching when user select/unselect region
178+
sameStrokeWidthForSelected: true,
178179
});
179180

180181
const props = {
@@ -193,11 +194,13 @@ const HtxKeyPointView = ({ item }) => {
193194
<Circle
194195
x={x}
195196
y={y}
196-
radius={Math.max(item.width, 2)}
197+
// keypoint should always be the same visual size
198+
radius={Math.max(item.width, 2) / item.parent.zoomScale}
197199
// fixes performance, but opactity+borders might look not so good
198200
perfectDrawEnabled={false}
199-
scaleX={1 / item.parent.zoomScale}
200-
scaleY={1 / item.parent.zoomScale}
201+
// for some reason this scaling doesn't work, so moved this to radius
202+
// scaleX={1 / item.parent.zoomScale}
203+
// scaleY={1 / item.parent.zoomScale}
201204
name={`${item.id} _transformable`}
202205
onDragStart={e => {
203206
if (item.parent.getSkipInteractions()) {

0 commit comments

Comments
 (0)