Skip to content

Commit

Permalink
chore: fixed code format with prettier (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yukthiw authored Jan 7, 2024
1 parent 1f85b5a commit 2ab5b14
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 93 deletions.
1 change: 0 additions & 1 deletion Eplant/Eplant.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import { Theme } from '@mui/system'
import ErrorBoundary from './util/ErrorBoundary'
import { dark, light } from './theme'


// TODO: Make this drawer support opening/closing on mobile

const sideBarWidth = 300
Expand Down
10 changes: 5 additions & 5 deletions Eplant/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ function RootApp() {
return (
<React.StrictMode>
<Provider>
<BrowserRouter>
<Config.Provider value={defaultConfig}>
<Eplant />
</Config.Provider>
</BrowserRouter>
<BrowserRouter>
<Config.Provider value={defaultConfig}>
<Eplant />
</Config.Provider>
</BrowserRouter>
</Provider>
</React.StrictMode>
)
Expand Down
4 changes: 2 additions & 2 deletions Eplant/views/eFP/EFPPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ export default function EFPPreview({
state={{
renderAsThumbnail: true,
colorMode: colorModeDeferred,
maskThreshold: maskThreshold
maskThreshold: maskThreshold,
}}
geneticElement={gene}
dispatch={() => { }}
dispatch={() => {}}
/>
<div
style={{
Expand Down
117 changes: 60 additions & 57 deletions Eplant/views/eFP/Viewer/MaskModal.tsx
Original file line number Diff line number Diff line change
@@ -1,68 +1,71 @@
// Import necessary dependencies from Material-UI
import React, { useState } from 'react';
import { Modal, Slider, Typography, Button, useTheme } from '@mui/material';
import { EFPViewerState } from './types';
import React, { useState } from 'react'
import { Modal, Slider, Typography, Button, useTheme } from '@mui/material'
import { EFPViewerState } from './types'

// Modal component with a slider
interface MaskModalProps {
state: EFPViewerState
onClose: () => void
onSubmit: (threshhold: number) => void
state: EFPViewerState
onClose: () => void
onSubmit: (threshhold: number) => void
}

const MaskModal = ({ state, onClose, onSubmit }: MaskModalProps) => {
const [sliderValue, setSliderValue] = useState<number>(state.maskThreshold);
const theme = useTheme()
const handleSliderChange = (event: Event, newValue: number | number[]) => {
setSliderValue(newValue as number);
};
const [sliderValue, setSliderValue] = useState<number>(state.maskThreshold)
const theme = useTheme()
const handleSliderChange = (event: Event, newValue: number | number[]) => {
setSliderValue(newValue as number)
}

const handleClose = () => {
setSliderValue(state.maskThreshold)
onClose();
};
const handleClose = () => {
setSliderValue(state.maskThreshold)
onClose()
}

const handleSubmit = () => {
onSubmit(sliderValue);
onClose();
};
const handleSubmit = () => {
onSubmit(sliderValue)
onClose()
}

return (
<Modal open={state.maskModalVisible} onClose={handleClose}>
<div style={{
width: 350,
height: 200,
padding: 20,
background: theme.palette.background.paperOverlay,
margin: 'auto',
marginTop: 100,
borderRadius: '8px',
display: 'flex',
flexDirection: 'column',
justifyContent: 'space-between',
}}>
<Typography variant="body2" gutterBottom>
Mask samples if the expression level is within a given range of their standard deviation.
</Typography>
<Slider
value={sliderValue}
onChange={handleSliderChange}
valueLabelDisplay="on"
valueLabelFormat={(value) => `${value}%`}
min={0}
max={100}
/>
<div style={{ display: 'flex', justifyContent: 'flex-end' }}>
<Button onClick={handleClose} style={{ marginRight: 8 }}>
Cancel
</Button>
<Button variant="contained" color="inherit" onClick={handleSubmit}>
Mask Thresholds
</Button>
</div>
</div>
</Modal>
);
};
return (
<Modal open={state.maskModalVisible} onClose={handleClose}>
<div
style={{
width: 350,
height: 200,
padding: 20,
background: theme.palette.background.paperOverlay,
margin: 'auto',
marginTop: 100,
borderRadius: '8px',
display: 'flex',
flexDirection: 'column',
justifyContent: 'space-between',
}}
>
<Typography variant="body2" gutterBottom>
Mask samples if the expression level is within a given range of their
standard deviation.
</Typography>
<Slider
value={sliderValue}
onChange={handleSliderChange}
valueLabelDisplay="on"
valueLabelFormat={(value) => `${value}%`}
min={0}
max={100}
/>
<div style={{ display: 'flex', justifyContent: 'flex-end' }}>
<Button onClick={handleClose} style={{ marginRight: 8 }}>
Cancel
</Button>
<Button variant="contained" color="inherit" onClick={handleSubmit}>
Mask Thresholds
</Button>
</div>
</div>
</Modal>
)
}

export default MaskModal;
export default MaskModal
26 changes: 15 additions & 11 deletions Eplant/views/eFP/Viewer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export default class EFPViewer
public icon: () => JSX.Element,
public description?: string,
public thumbnail?: string,
) { }
) {}
getInitialData = async (
gene: GeneticElement | null,
loadEvent: (progress: number) => void,
Expand Down Expand Up @@ -162,7 +162,6 @@ export default class EFPViewer
viewData: viewData,
efps: this.efps,
colorMode: 'absolute' as const,

}
}
reducer = (state: EFPViewerState, action: EFPViewerAction) => {
Expand Down Expand Up @@ -201,12 +200,12 @@ export default class EFPViewer
case 'toggle-mask-modal':
return {
...state,
maskModalVisible: state.maskModalVisible ? false : true
maskModalVisible: state.maskModalVisible ? false : true,
}
case 'set-mask-threshold':
return {
...state,
maskThreshold: action.threshold
maskThreshold: action.threshold,
}
default:
return state
Expand Down Expand Up @@ -254,10 +253,10 @@ export default class EFPViewer
state={{
colorMode: props.state.colorMode,
renderAsThumbnail: false,
maskThreshold: props.state.maskThreshold
maskThreshold: props.state.maskThreshold,
}}
geneticElement={props.geneticElement}
dispatch={() => { }}
dispatch={() => {}}
/>
)
}, [
Expand All @@ -266,7 +265,7 @@ export default class EFPViewer
props.dispatch,
sortedViewData[activeViewIndex],
props.state.colorMode,
props.state.maskThreshold
props.state.maskThreshold,
])
const ref = React.useRef<HTMLDivElement>(null)
const dimensions = useDimensions(ref)
Expand Down Expand Up @@ -387,7 +386,12 @@ export default class EFPViewer
<MaskModal
state={props.state}
onClose={() => props.dispatch({ type: 'toggle-mask-modal' })}
onSubmit={(threshold) => props.dispatch({ type: 'set-mask-threshold', threshold: threshold })}
onSubmit={(threshold) =>
props.dispatch({
type: 'set-mask-threshold',
threshold: threshold,
})
}
/>
<Legend
sx={(theme) => ({
Expand All @@ -402,7 +406,7 @@ export default class EFPViewer
state={{
colorMode: props.state.colorMode,
renderAsThumbnail: false,
maskThreshold: props.state.maskThreshold
maskThreshold: props.state.maskThreshold,
}}
/>
<PanZoom
Expand Down Expand Up @@ -455,8 +459,8 @@ export default class EFPViewer
},
{
action: { type: 'toggle-mask-modal' },
render: () => <>Mask data</>
}
render: () => <>Mask data</>,
},
]
header: View<EFPViewerData, EFPViewerState, EFPViewerAction>['header'] = (
props,
Expand Down
20 changes: 13 additions & 7 deletions Eplant/views/eFP/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default class EFP implements View<EFPData, EFPState, EFPAction> {
getInitialState: () => EFPState = () => ({
colorMode: 'absolute',
renderAsThumbnail: false,
maskThreshold: 100
maskThreshold: 100,
})
tooltipComponent: (props: {
el: SVGElement | null
Expand Down Expand Up @@ -52,8 +52,9 @@ export default class EFP implements View<EFPData, EFPState, EFPAction> {
const database = xml.getElementsByTagName('view')[0]?.getAttribute('db')
let webservice = xml.getElementsByTagName('webservice')[0]?.textContent
if (!webservice)
webservice = `https://bar.utoronto.ca/eplant/cgi-bin/plantefp.cgi?datasource=${database ?? 'atgenexp_plus'
}&`
webservice = `https://bar.utoronto.ca/eplant/cgi-bin/plantefp.cgi?datasource=${
database ?? 'atgenexp_plus'
}&`

// Get a list of groups and samples
const sampleNames: string[] = []
Expand Down Expand Up @@ -95,9 +96,9 @@ export default class EFP implements View<EFPData, EFPState, EFPAction> {
chunks.map((names) =>
fetch(
webservice +
`id=${gene.id}&samples=${encodeURIComponent(
JSON.stringify(names),
)}`,
`id=${gene.id}&samples=${encodeURIComponent(
JSON.stringify(names),
)}`,
)
.then((res) => res.json())
.then(
Expand Down Expand Up @@ -184,7 +185,12 @@ export default class EFP implements View<EFPData, EFPState, EFPAction> {
(props.geneticElement?.id ?? 'no-gene') +
'-' +
useMemo(() => Math.random().toString(16).slice(3), [])
const styles = useStyles(id, props.activeData, props.state.colorMode, props.state.maskThreshold)
const styles = useStyles(
id,
props.activeData,
props.state.colorMode,
props.state.maskThreshold,
)
useEffect(() => {
const el = document.createElement('style')
el.innerHTML = styles
Expand Down
22 changes: 12 additions & 10 deletions Eplant/views/eFP/svg.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ export const useEFPSVG = (
if (!cache[view.id]) return { view: null, loading: true }
const parser = new DOMParser()
const svg = parser.parseFromString(cache[view.id].svg, 'text/xml')
;['width', 'height', 'x', 'y', 'id'].map((s) =>
svg.documentElement.removeAttribute(s),
)
;['width', 'height', 'x', 'y', 'id'].map((s) =>
svg.documentElement.removeAttribute(s),
)
svg.documentElement.setAttribute('class', 'eFP-svg')
// Remove styling from all of the text tags
for (const text of svg.querySelectorAll('text, tspan')) {
Expand Down Expand Up @@ -85,19 +85,20 @@ export function getColor(
theme: Theme,
colorMode: ColorMode,
tissueStd?: number,
maskThreshold?: number
maskThreshold?: number,
): string {
const extremum = Math.max(
Math.abs(Math.log2(group.min / control)),
Math.log2(group.max / control),
1,
)
const masked = maskThreshold && tissueStd ?
isNaN(group.std) || (tissueStd >= value * (maskThreshold / 100)) :
false
const masked =
maskThreshold && tissueStd
? isNaN(group.std) || tissueStd >= value * (maskThreshold / 100)
: false
const norm = Math.log2(value / control) / extremum
if (masked) {
return (theme.palette.secondary.dark)
return theme.palette.secondary.dark
} else if (colorMode === 'relative')
return norm < 0
? mix(theme.palette.neutral.main, theme.palette.cold.main, Math.abs(norm))
Expand All @@ -121,7 +122,8 @@ export function useStyles(
.flatMap((group) =>
group.tissues.map(
(tissue) => `
#${id} .efp-group-${tissue.id} *, #${id} .efp-group-${tissue.id
#${id} .efp-group-${tissue.id} *, #${id} .efp-group-${
tissue.id
} { fill: ${getColor(
tissue.mean,
group,
Expand All @@ -130,7 +132,7 @@ export function useStyles(
colorMode,
tissue.std,
maskThreshold,
)} !important; }`
)} !important; }`,
),
)
.join('\n')
Expand Down

0 comments on commit 2ab5b14

Please sign in to comment.