From 858a86b03322438cdbe4d14fdaa631f740490a22 Mon Sep 17 00:00:00 2001 From: Colin Date: Wed, 29 Jan 2025 16:13:07 -0500 Subject: [PATCH] Updates --- .../components/HeaderRegionWidth.tsx | 25 +---- .../components/HeaderZoomControls.tsx | 65 ++++++----- .../components/RegionWidthEditorDialog.tsx | 30 +++--- .../components/ZoomControls.tsx | 101 ------------------ 4 files changed, 57 insertions(+), 164 deletions(-) delete mode 100644 plugins/linear-genome-view/src/LinearGenomeView/components/ZoomControls.tsx diff --git a/plugins/linear-genome-view/src/LinearGenomeView/components/HeaderRegionWidth.tsx b/plugins/linear-genome-view/src/LinearGenomeView/components/HeaderRegionWidth.tsx index 07d081e6a3..92e91eca83 100644 --- a/plugins/linear-genome-view/src/LinearGenomeView/components/HeaderRegionWidth.tsx +++ b/plugins/linear-genome-view/src/LinearGenomeView/components/HeaderRegionWidth.tsx @@ -1,24 +1,16 @@ -import { lazy } from 'react' - -import { getBpDisplayStr, getSession } from '@jbrowse/core/util' +import { getBpDisplayStr } from '@jbrowse/core/util' import { Typography } from '@mui/material' import { observer } from 'mobx-react' import { makeStyles } from 'tss-react/mui' import type { LinearGenomeViewModel } from '..' -const RegionWidthEditorDialog = lazy(() => import('./RegionWidthEditorDialog')) - const useStyles = makeStyles()({ bp: { display: 'flex', alignItems: 'center', marginLeft: 5, cursor: 'pointer', - minWidth: 50, - '&:hover': { - backgroundColor: 'rgba(0, 0, 0, 0.2)', - }, }, }) @@ -30,20 +22,7 @@ const HeaderRegionWidth = observer(function ({ const { classes } = useStyles() const { coarseTotalBp } = model return ( - { - getSession(model).queueDialog(handleClose => [ - RegionWidthEditorDialog, - { - model, - handleClose, - }, - ]) - }} - > + {getBpDisplayStr(coarseTotalBp)} ) diff --git a/plugins/linear-genome-view/src/LinearGenomeView/components/HeaderZoomControls.tsx b/plugins/linear-genome-view/src/LinearGenomeView/components/HeaderZoomControls.tsx index 6162afbcb2..74e9825fa2 100644 --- a/plugins/linear-genome-view/src/LinearGenomeView/components/HeaderZoomControls.tsx +++ b/plugins/linear-genome-view/src/LinearGenomeView/components/HeaderZoomControls.tsx @@ -1,5 +1,7 @@ -import { useEffect, useState } from 'react' +import { lazy, useEffect, useState } from 'react' +import CascadingMenuButton from '@jbrowse/core/ui/CascadingMenuButton' +import MoreVert from '@mui/icons-material/MoreVert' import ZoomIn from '@mui/icons-material/ZoomIn' import ZoomOut from '@mui/icons-material/ZoomOut' import { IconButton, Slider, Tooltip } from '@mui/material' @@ -7,6 +9,10 @@ import { observer } from 'mobx-react' import { makeStyles } from 'tss-react/mui' import type { LinearGenomeViewModel } from '..' +import { getSession } from '@jbrowse/core/util' + +// lazies +const RegionWidthEditorDialog = lazy(() => import('./RegionWidthEditorDialog')) const useStyles = makeStyles()(theme => ({ container: { @@ -35,19 +41,6 @@ const HeaderZoomControls = observer(function ({ const zoomOutDisabled = bpPerPx >= maxBpPerPx - 0.0001 return (
- - - { - model.zoom(bpPerPx * 15) - }} - > - - - - - - - { - model.zoom(model.bpPerPx / 15) - }} - > - - - - + + ({ + label: `Zoom in ${r}x`, + onClick: () => { + model.zoom(model.bpPerPx / r) + }, + })), + ...[10, 50, 100].map(r => ({ + label: `Zoom out ${r}x`, + onClick: () => { + model.zoom(model.bpPerPx * r) + }, + })), + { + label: 'Custom zoom', + onClick: () => { + getSession(model).queueDialog(handleClose => [ + RegionWidthEditorDialog, + { + model, + handleClose, + }, + ]) + }, + }, + ]} + > + +
) }) diff --git a/plugins/linear-genome-view/src/LinearGenomeView/components/RegionWidthEditorDialog.tsx b/plugins/linear-genome-view/src/LinearGenomeView/components/RegionWidthEditorDialog.tsx index e61cbe3f28..16ed339134 100644 --- a/plugins/linear-genome-view/src/LinearGenomeView/components/RegionWidthEditorDialog.tsx +++ b/plugins/linear-genome-view/src/LinearGenomeView/components/RegionWidthEditorDialog.tsx @@ -1,4 +1,4 @@ -import { useState } from 'react' +import { useEffect, useState } from 'react' import { Dialog } from '@jbrowse/core/ui' import { @@ -11,6 +11,7 @@ import { import { observer } from 'mobx-react' import type { LinearGenomeViewModel } from '../model' +import { toLocale } from '@jbrowse/core/util' const toP = (s = 0) => +(+s).toFixed(1) @@ -21,29 +22,32 @@ const RegionWidthEditorDialog = observer(function ({ model: LinearGenomeViewModel handleClose: () => void }) { - const [val, setVal] = useState(`${toP(model.bpPerPx)}`) + const { bpPerPx, width } = model + const [val, setVal] = useState(`${toLocale(toP(bpPerPx * width))}`) + useEffect(() => { + setVal(`${toLocale(bpPerPx * width)}`) + }, [bpPerPx, width]) + const val2 = val.replace(/,/g, '') return ( - Allows editing the zoom level using the 'base pairs per pixel' - measurement - - - Large numbers e.g. 10 means there are 10 base pairs in each pixel, - small numbers e.g. 0.1 means there are 10 pixels for each base pair + Editing zoom level. This is approximate and does not account for + padding between regions or off-screen scrolling { setVal(event.target.value) }} /> - Resulting region width: approximatly{' '} - {!Number.isNaN(+val) ? model.width / +val : '(error parsing number)'}