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

Commit e0557b0

Browse files
Gondragosnick-skriabinniklubmakseq
authored
fix: DEV-1200: Reanimate tag style parameters (#365)
* [fix] Fix getting style-affecting parameters from control tag * [fix] Allow to use opacity parameter instead of fillOpacity Co-authored-by: Nick Skriabin <[email protected]> Co-authored-by: niklub <[email protected]> Co-authored-by: Max Tkachenko <[email protected]>
1 parent 5ccf3d3 commit e0557b0

File tree

8 files changed

+32
-14
lines changed

8 files changed

+32
-14
lines changed

src/core/Constants.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
export const defaultStyle = {
22
fillcolor: "#666",
3-
fillopacity: 0.2,
3+
opacity: 0.2,
44
strokecolor: "#666",
55
strokewidth: 1,
6-
opacity: 0.6,
76
};
87

98
export default {

src/hooks/useRegionColor.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ import { observe } from "mobx";
33
import { useContext, useEffect, useMemo, useState } from "react";
44
import { ImageViewContext } from "../components/ImageView/ImageViewContext";
55
import Constants, { defaultStyle } from "../core/Constants";
6+
import { isDefined } from "../utils/utilities";
67

78
const defaultStyles = {
8-
defaultFillOpacity: defaultStyle.fillopacity,
9+
defaultOpacity: defaultStyle.opacity,
910
defaultFillColor: defaultStyle.fillcolor,
1011
defaultStrokeColor: defaultStyle.strokecolor,
1112
defaultStrokeColorHighlighted: Constants.HIGHLIGHTED_STROKE_COLOR,
@@ -17,7 +18,7 @@ const defaultStyles = {
1718
export const useRegionStyles = (region, {
1819
includeFill = false,
1920
useStrokeAsFill = false,
20-
defaultFillOpacity = defaultStyle.fillopacity,
21+
defaultOpacity = defaultStyle.opacity,
2122
defaultFillColor = defaultStyle.fillcolor,
2223
defaultStrokeColor = defaultStyle.strokecolor,
2324
defaultStrokeColorHighlighted = Constants.HIGHLIGHTED_STROKE_COLOR,
@@ -35,13 +36,17 @@ export const useRegionStyles = (region, {
3536
}, [region.inSelection, highlighted]);
3637

3738
const fillColor = useMemo(() => {
39+
// @todo fillopacity should be deprecated and will be removed in future
40+
const fillopacity = style?.fillopacity;
41+
const opacity = isDefined(fillopacity) ? fillopacity : style?.opacity;
42+
3843
return shouldFill ? (
3944
chroma((useStrokeAsFill ? style?.strokecolor : style?.fillcolor) ?? defaultFillColor)
4045
.darken(0.3)
41-
.alpha(+(style?.fillopacity ?? defaultFillOpacity ?? 0.5))
46+
.alpha(+(opacity ?? defaultOpacity ?? 0.5))
4247
.css()
4348
) : null;
44-
}, [shouldFill, style, defaultFillColor, defaultFillOpacity]);
49+
}, [shouldFill, style, defaultFillColor, defaultOpacity]);
4550

4651
const strokeColor = useMemo(() => {
4752
if (selected) {

src/mixins/AreaMixin.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,13 @@ export const AreaMixin = types
9090
}
9191
const emptyStyled = self.results.find(r => r.emptyStyle);
9292

93-
return emptyStyled && emptyStyled.emptyStyle;
93+
if (emptyStyled && emptyStyled.emptyStyle) {
94+
return emptyStyled.emptyStyle;
95+
}
96+
97+
const controlStyled = self.results.find(r => self.type.startsWith(r.type));
98+
99+
return controlStyled && controlStyled.controlStyle;
94100
},
95101

96102
// @todo may be slow, consider to add some code to annotation (un)select* methods

src/regions/KeyPointRegion.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ const HtxKeyPointView = ({ item }) => {
167167
includeFill: true,
168168
defaultFillColor: "#000",
169169
defaultStrokeColor: "#fff",
170-
defaultFillOpacity: (item.style ?? item.tag) ? 0.6 : 1,
170+
defaultOpacity: (item.style ?? item.tag) ? 0.6 : 1,
171171
defaultStrokeWidth: 2,
172172
});
173173

src/regions/Result.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,14 @@ const Result = types
198198

199199
return { strokecolor, strokewidth, fillcolor, fillopacity, opacity };
200200
},
201+
202+
get controlStyle() {
203+
if (!self.from_name) return null;
204+
205+
const { fillcolor, strokecolor, strokewidth, fillopacity, opacity } = self.from_name;
206+
207+
return { strokecolor, strokewidth, fillcolor, fillopacity, opacity };
208+
},
201209
}))
202210
.volatile(() => ({
203211
pid: "",

src/tags/control/Ellipse.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ const TagAttrs = types.model({
3434
name: types.identifier,
3535
toname: types.maybeNull(types.string),
3636

37-
opacity: types.optional(customTypes.range(), "1"),
37+
opacity: types.optional(customTypes.range(), "0.2"),
3838
fillcolor: types.optional(customTypes.color, "#f48a42"),
3939

4040
strokewidth: types.optional(types.string, "1"),
4141
strokecolor: types.optional(customTypes.color, "#f48a42"),
42-
fillopacity: types.optional(customTypes.range(), "0.2"),
42+
fillopacity: types.maybeNull(customTypes.range()),
4343

4444
canrotate: types.optional(types.boolean, true),
4545
});

src/tags/control/Labels/Labels.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ const TagAttrs = types.model({
5353
// TODO this will move away from here
5454
groupdepth: types.maybeNull(types.string),
5555

56-
opacity: types.optional(customTypes.range(), "1"),
56+
opacity: types.optional(customTypes.range(), "0.2"),
5757
fillcolor: types.optional(customTypes.color, "#f48a42"),
5858

5959
strokewidth: types.optional(types.string, "1"),
6060
strokecolor: types.optional(customTypes.color, "#f48a42"),
61-
fillopacity: types.optional(customTypes.range(), "0.2"),
61+
fillopacity: types.maybeNull(customTypes.range()),
6262
allowempty: types.optional(types.boolean, false),
6363
});
6464

src/tags/control/Rectangle.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ const TagAttrs = types.model({
3434
name: types.identifier,
3535
toname: types.maybeNull(types.string),
3636

37-
opacity: types.optional(customTypes.range(), "1"),
37+
opacity: types.optional(customTypes.range(), "0.2"),
3838
fillcolor: types.optional(customTypes.color, "#f48a42"),
3939

4040
strokewidth: types.optional(types.string, "1"),
4141
strokecolor: types.optional(customTypes.color, "#f48a42"),
42-
fillopacity: types.optional(customTypes.range(), "0.2"),
42+
fillopacity: types.maybeNull(customTypes.range()),
4343

4444
canrotate: types.optional(types.boolean, true),
4545
});

0 commit comments

Comments
 (0)