Skip to content

Commit

Permalink
fix: Changed mask modal to be a toggle, increased max masking % to 200%
Browse files Browse the repository at this point in the history
  • Loading branch information
Yukthiw committed Mar 6, 2024
1 parent 133b08c commit 10e20f3
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 15 deletions.
1 change: 0 additions & 1 deletion Eplant/state/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export const pageLoad = (() => {
},
done() {
finished++
// console.log(finished / waiting)
watchers.forEach((w) => w(finished / waiting))
},
watch(cb: (progress: number) => void) {
Expand Down
1 change: 0 additions & 1 deletion Eplant/util/Storage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ export default class KeyValDB<K extends string, V> {
}

async clear() {
// console.log(await this.keys())
;(await this.keys()).forEach((key: K) => this.delete(key))
}

Expand Down
3 changes: 1 addition & 2 deletions Eplant/views/eFP/Viewer/MaskModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ const MaskModal = ({ state, onClose, onSubmit }: MaskModalProps) => {

const handleSubmit = () => {
onSubmit(sliderValue)
onClose()
}
return (
<Modal open={state.maskModalVisible} onClose={handleClose}>
Expand Down Expand Up @@ -64,7 +63,7 @@ const MaskModal = ({ state, onClose, onSubmit }: MaskModalProps) => {
valueLabelDisplay='on'
valueLabelFormat={(value) => `${value}%`}
min={0}
max={100}
max={200}
sx={{ width: 400 }}
/>
<div style={{ display: 'flex', justifyContent: 'flex-end' }}>
Expand Down
22 changes: 16 additions & 6 deletions Eplant/views/eFP/Viewer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export default class EFPViewer
zoom: 1,
},
sortBy: 'name',
maskingEnabled: false,
maskThreshold: 100,
maskModalVisible: false,
}
Expand Down Expand Up @@ -217,14 +218,23 @@ export default class EFPViewer
: ('absolute' as const),
}
case 'toggle-mask-modal':
return {
...state,
maskModalVisible: !state.maskModalVisible,
if (state.maskingEnabled) {
return {
...state,
maskingEnabled: !state.maskingEnabled,
}
} else {
return {
...state,
maskModalVisible: !state.maskModalVisible,
}
}
case 'set-mask-threshold':
return {
...state,
maskThreshold: action.threshold,
maskingEnabled: !state.maskingEnabled,
maskModalVisible: !state.maskModalVisible,
}
default:
return state
Expand Down Expand Up @@ -276,6 +286,7 @@ export default class EFPViewer
colorMode: state.colorMode,
renderAsThumbnail: false,
maskThreshold: state.maskThreshold,
maskingEnabled: state.maskingEnabled,
}}
geneticElement={geneticElement}
dispatch={() => {}}
Expand All @@ -289,12 +300,10 @@ export default class EFPViewer
sortedViewData[activeViewIndex],
state.colorMode,
state.maskThreshold,
state.maskingEnabled,
])
const ref = useRef<HTMLDivElement>(null)
const dimensions = useDimensions(ref)
{
// console.log(props)
}

if (!geneticElement) return <></>
return (
Expand Down Expand Up @@ -430,6 +439,7 @@ export default class EFPViewer
colorMode: state.colorMode,
renderAsThumbnail: false,
maskThreshold: state.maskThreshold,
maskingEnabled: state.maskingEnabled,
}}
/>
<PanZoom
Expand Down
2 changes: 2 additions & 0 deletions Eplant/views/eFP/Viewer/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export type EFPViewerState = {
transform: Transform
colorMode: ColorMode
sortBy: EFPViewerSortTypes
maskingEnabled: boolean
maskModalVisible: boolean
maskThreshold: number
}
Expand All @@ -28,5 +29,6 @@ export type EFPViewerAction =
| { type: 'set-transform'; transform: Transform }
| { type: 'toggle-color-mode' }
| { type: 'sort-by'; by: EFPViewerSortTypes }
| { type: 'toggle-masking' }
| { type: 'toggle-mask-modal' }
| { type: 'set-mask-threshold'; threshold: number }
4 changes: 3 additions & 1 deletion Eplant/views/eFP/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default class EFP implements View<EFPData, EFPState, EFPAction> {
colorMode: 'absolute',
renderAsThumbnail: false,
maskThreshold: 100,
maskingEnabled: false,
})
tooltipComponent: (props: {
el: SVGElement | null
Expand Down Expand Up @@ -191,7 +192,8 @@ export default class EFP implements View<EFPData, EFPState, EFPAction> {
id,
props.activeData,
props.state.colorMode,
props.state.maskThreshold
props.state.maskThreshold,
props.state.maskingEnabled
)
useEffect(() => {
const el = document.createElement('style')
Expand Down
11 changes: 7 additions & 4 deletions Eplant/views/eFP/svg.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,16 @@ export function getColor(
theme: Theme,
colorMode: ColorMode,
tissueStd?: number,
maskThreshold?: number
maskThreshold?: number,
maskingEnabled?: boolean
): string {
const extremum = Math.max(
Math.abs(Math.log2(group.min / control)),
Math.log2(group.max / control),
1
)
const masked =
maskThreshold && tissueStd
maskingEnabled && maskThreshold && tissueStd
? isNaN(group.std) || tissueStd >= value * (maskThreshold / 100)
: false
const norm = Math.log2(value / control) / extremum
Expand All @@ -117,7 +118,8 @@ export function useStyles(
id: string,
{ groups, control }: EFPData,
colorMode: ColorMode,
maskThreshold?: number
maskThreshold?: number,
maskingEnabled?: boolean
) {
const theme = useTheme()
const samples = groups
Expand All @@ -133,7 +135,8 @@ export function useStyles(
theme,
colorMode,
tissue.std,
maskThreshold
maskThreshold,
maskingEnabled
)} !important; }`
)
)
Expand Down
1 change: 1 addition & 0 deletions Eplant/views/eFP/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export type EFPState = {
colorMode: 'absolute' | 'relative'
renderAsThumbnail: boolean
maskThreshold: number
maskingEnabled: boolean
}

export type EFPSVG = { svg: string; xml: string; id: EFPId }
Expand Down

0 comments on commit 10e20f3

Please sign in to comment.