Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve annotation styles #253

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
1 change: 1 addition & 0 deletions src/components/AnnotationCategoryItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const AnnotationCategoryItem = ({
[annotationUID: string]: {
opacity: number
color: number[]
contourOnly: boolean
}
}
checkedAnnotationUids: Set<string>
Expand Down
1 change: 1 addition & 0 deletions src/components/AnnotationCategoryList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ const AnnotationCategoryList = ({
[annotationUID: string]: {
opacity: number
color: number[]
contourOnly: boolean
}
}
checkedAnnotationUids: Set<string>
Expand Down
61 changes: 51 additions & 10 deletions src/components/ColorSettingsMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React from 'react'
import { Col, Divider, InputNumber, Row, Slider } from 'antd'
import { Checkbox, Col, Divider, InputNumber, Row, Slider } from 'antd'

interface ColorSettingsMenuProps {
annotationGroupsUIDs: string[]
defaultStyle: {
opacity: number
color: number[]
contourOnly: boolean
}
onStyleChange: Function
}
Expand All @@ -14,6 +15,7 @@ interface ColorSettingsMenuState {
currentStyle: {
opacity: number
color?: number[]
contourOnly: boolean
}
}

Expand All @@ -34,7 +36,8 @@ ColorSettingsMenuState
this.state = {
currentStyle: {
opacity: this.props.defaultStyle.opacity,
color: this.props.defaultStyle.color
color: this.props.defaultStyle.color,
contourOnly: this.props.defaultStyle.contourOnly
}
}
}
Expand All @@ -46,14 +49,16 @@ ColorSettingsMenuState
uid,
styleOptions: {
color: this.state.currentStyle.color,
opacity: value
opacity: value,
contourOnly: this.state.currentStyle.contourOnly
}
})
})
this.setState({
currentStyle: {
opacity: value,
color: this.state.currentStyle.color
color: this.state.currentStyle.color,
contourOnly: this.state.currentStyle.contourOnly
}
})
}
Expand All @@ -69,15 +74,17 @@ ColorSettingsMenuState
this.setState((state) => ({
currentStyle: {
color: color,
opacity: state.currentStyle.opacity
opacity: state.currentStyle.opacity,
contourOnly: state.currentStyle.contourOnly
}
}))
this.props.annotationGroupsUIDs.forEach((uid) => {
this.props.onStyleChange({
uid,
styleOptions: {
color: color,
opacity: this.state.currentStyle.opacity
opacity: this.state.currentStyle.opacity,
contourOnly: this.state.currentStyle.contourOnly
}
})
})
Expand All @@ -94,15 +101,17 @@ ColorSettingsMenuState
this.setState((state) => ({
currentStyle: {
color: color,
opacity: state.currentStyle.opacity
opacity: state.currentStyle.opacity,
contourOnly: state.currentStyle.contourOnly
}
}))
this.props.annotationGroupsUIDs.forEach((uid) => {
this.props.onStyleChange({
uid,
styleOptions: {
color: color,
opacity: this.state.currentStyle.opacity
opacity: this.state.currentStyle.opacity,
contourOnly: this.state.currentStyle.contourOnly
}
})
})
Expand All @@ -119,7 +128,8 @@ ColorSettingsMenuState
this.setState((state) => ({
currentStyle: {
color: color,
opacity: state.currentStyle.opacity
opacity: state.currentStyle.opacity,
contourOnly: state.currentStyle.contourOnly
}
}))

Expand All @@ -128,13 +138,35 @@ ColorSettingsMenuState
uid,
styleOptions: {
color: color,
opacity: this.state.currentStyle.opacity
opacity: this.state.currentStyle.opacity,
contourOnly: this.state.currentStyle.contourOnly
}
})
})
}
}

handleShowOutlineOnly (value: boolean): void {
this.setState({
currentStyle: {
opacity: this.state.currentStyle.opacity,
color: this.state.currentStyle.color,
contourOnly: value
}
})

this.props.annotationGroupsUIDs.forEach((uid) => {
this.props.onStyleChange({
uid,
styleOptions: {
color: this.state.currentStyle.color,
opacity: this.state.currentStyle.opacity,
contourOnly: value
}
})
})
}

getCurrentColor (): string {
const rgb2hex = (values: number[]): string => {
const r = values[0]
Expand Down Expand Up @@ -259,6 +291,15 @@ ColorSettingsMenuState
/>
</Col>
</Row>
<Row justify='start' align='middle' gutter={[8, 8]}>
<Checkbox
value={this.state.currentStyle.contourOnly}
onChange={(event) =>
this.handleShowOutlineOnly(event.target.checked)}
>
Show outline only
</Checkbox>
</Row>
</div>
)
}
Expand Down
25 changes: 18 additions & 7 deletions src/components/HoveredRoiTooltip.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const HoveredRoiTooltip = ({
xPosition,
yPosition,
attributes
rois
}: {
xPosition: number
yPosition: number
attributes: Array<{ name: string, value: string }>
rois: Array<{ index: number, roiUid: string, attributes: Array<{ name: string, value: string }>}>
}): JSX.Element => {
return (
<div
Expand All @@ -21,11 +21,22 @@ const HoveredRoiTooltip = ({
pointerEvents: 'none'
}}
>
{attributes.map((attr) => (
<div key={attr.name}>
{attr.name}: <span style={{ fontWeight: 500 }}>{attr.value}</span>
</div>
))}
{rois.map((roi, i) => {
const attributes = roi.attributes
return (
<div key={roi.roiUid}>
<span>ROI {roi.index}</span>
{attributes.map((attr) => {
return (
<div key={attr.name + roi.roiUid}>
{attr.name}: <span style={{ fontWeight: 500 }}>{attr.value}</span>
</div>
)
})}
</div>

)
})}
</div>
)
}
Expand Down
Loading