Skip to content

Commit

Permalink
Update to sliders
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Jan 8, 2024
1 parent cbbe070 commit cf025a2
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 71 deletions.
32 changes: 15 additions & 17 deletions lib/src/components/TreePanel/TreeCanvasBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ const TreeCanvasBlock = observer(function ({

const width = treeAreaWidth + padding
const height = blockSize
const w2 = width * highResScaleFactor
const h2 = height * highResScaleFactor

const vref = useCallback(
(arg: HTMLCanvasElement) => {
Expand Down Expand Up @@ -118,7 +120,13 @@ const TreeCanvasBlock = observer(function ({
? { ...entry, x: event.clientX, y: event.clientY }
: undefined
}

const style = {
width,
height,
top: scrollY + offsetY,
left: 0,
position: 'absolute',
} as const
return (
<>
{branchMenu?.id ? (
Expand All @@ -138,15 +146,9 @@ const TreeCanvasBlock = observer(function ({
) : null}

<canvas
width={(treeAreaWidth + padding) * highResScaleFactor}
height={blockSize * highResScaleFactor}
style={{
width: treeAreaWidth + padding,
height: blockSize,
top: scrollY + offsetY,
left: 0,
position: 'absolute',
}}
width={w2}
height={h2}
style={style}
onMouseMove={event => {
if (!ref.current) {
return
Expand All @@ -173,16 +175,12 @@ const TreeCanvasBlock = observer(function ({
/>
<canvas
style={{
width: treeAreaWidth + padding,
height: blockSize,
top: scrollY + offsetY,
left: 0,
position: 'absolute',
...style,
pointerEvents: 'none',
zIndex: 100,
}}
width={treeAreaWidth + padding}
height={blockSize}
width={width}
height={height}
ref={mouseoverRef}
/>
</>
Expand Down
99 changes: 55 additions & 44 deletions lib/src/components/dialogs/SettingsDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react'
import React from 'react'
import { observer } from 'mobx-react'
import { makeStyles } from 'tss-react/mui'
import { Dialog } from '@jbrowse/core/ui'
Expand All @@ -9,7 +9,9 @@ import {
DialogContent,
FormControlLabel,
MenuItem,
Slider,
TextField,
Typography,
} from '@mui/material'

import { MsaViewModel } from '../../model'
Expand All @@ -29,90 +31,100 @@ const SettingsDialog = observer(function ({
onClose: () => void
}) {
const { classes } = useStyles()
const { colorSchemeName, noTree } = model
const [rowHeight, setRowHeight] = useState(`${model.rowHeight}`)
const [colWidth, setColWidth] = useState(`${model.colWidth}`)
const [treeWidth, setTreeWidth] = useState(`${model.treeWidth}`)

function error(n: string) {
return Number.isNaN(+n) || +n < 0
}
const rowHeightError = error(rowHeight)
const colWidthError = error(colWidth)
const treeWidthError = error(treeWidth)
const {
colorSchemeName,
drawTree,
labelsAlignRight,
drawNodeBubbles,
bgColor,
treeWidth,
showBranchLen,
noTree,
rowHeight,
colWidth,
} = model

return (
<Dialog open onClose={() => onClose()} title="Settings">
<DialogContent>
<FormControlLabel
control={
<Checkbox
checked={model.showBranchLen}
onChange={() => model.toggleBranchLen()}
checked={showBranchLen}
onChange={() => model.setShowBranchLen(!showBranchLen)}
/>
}
label="Show branch length"
/>
<FormControlLabel
control={
<Checkbox
checked={model.bgColor}
onChange={() => model.toggleBgColor()}
checked={bgColor}
onChange={() => model.setBgColor(!bgColor)}
/>
}
label="Color background"
/>
<FormControlLabel
control={
<Checkbox
checked={model.drawNodeBubbles}
onChange={() => model.toggleNodeBubbles()}
checked={drawNodeBubbles}
onChange={() => model.setDrawNodeBubbles(!drawNodeBubbles)}
/>
}
label="Draw node bubbles"
/>
<FormControlLabel
control={
<Checkbox
checked={model.drawTree}
onChange={() => model.toggleDrawTree()}
checked={drawTree}
onChange={() => model.setDrawTree(!drawTree)}
/>
}
label="Draw tree (if available)"
/>
<FormControlLabel
control={
<Checkbox
checked={model.labelsAlignRight}
onChange={() => model.toggleLabelsAlignRight()}
checked={labelsAlignRight}
onChange={() => model.setLabelsAlignRight(!labelsAlignRight)}
/>
}
label="Labels align right (note: labels may draw over tree, but can adjust tree width or tree area width in UI)"
/>

<TextField
className={classes.field}
label="Row height (px)"
value={rowHeight}
error={rowHeightError}
onChange={event => setRowHeight(event.target.value)}
/>
<TextField
className={classes.field}
label="Column width (px)"
value={colWidth}
error={colWidthError}
onChange={event => setColWidth(event.target.value)}
/>
<br />
{!noTree ? (
<TextField
<div>
<Typography>Column width ({colWidth}px)</Typography>
<Slider
className={classes.field}
min={1}
max={50}
value={colWidth}
onChange={(_, val) => model.setColWidth(val as number)}
/>
</div>
<div>
<Typography>Row height ({rowHeight}px)</Typography>
<Slider
className={classes.field}
label="Tree width (px)"
value={treeWidth}
error={treeWidthError}
onChange={event => setTreeWidth(event.target.value)}
min={1}
max={50}
value={rowHeight}
onChange={(_, val) => model.setRowHeight(val as number)}
/>
</div>

{!noTree ? (
<div>
<Typography>Tree width ({treeWidth}px)</Typography>
<Slider
className={classes.field}
min={50}
max={600}
value={treeWidth}
onChange={(_, val) => model.setTreeWidth(val as number)}
/>
</div>
) : null}

<br />
Expand All @@ -131,7 +143,6 @@ const SettingsDialog = observer(function ({
</TextField>
<DialogActions>
<Button
disabled={rowHeightError || colWidthError || treeWidthError}
onClick={() => {
model.setRowHeight(+rowHeight)
model.setColWidth(+colWidth)
Expand Down
20 changes: 10 additions & 10 deletions lib/src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,14 +371,14 @@ const model = types
/**
* #action
*/
toggleLabelsAlignRight() {
self.labelsAlignRight = !self.labelsAlignRight
setLabelsAlignRight(arg: boolean) {
self.labelsAlignRight = arg
},
/**
* #action
*/
toggleDrawTree() {
self.drawTree = !self.drawTree
setDrawTree(arg: boolean) {
self.drawTree = arg
},
/**
* #action
Expand All @@ -399,20 +399,20 @@ const model = types
/**
* #action
*/
toggleBranchLen() {
self.showBranchLen = !self.showBranchLen
setShowBranchLen(arg: boolean) {
self.showBranchLen = arg
},
/**
* #action
*/
toggleBgColor() {
self.bgColor = !self.bgColor
setBgColor(arg: boolean) {
self.bgColor = arg
},
/**
* #action
*/
toggleNodeBubbles() {
self.drawNodeBubbles = !self.drawNodeBubbles
setDrawNodeBubbles(arg: boolean) {
self.drawNodeBubbles = arg
},
/**
* #action
Expand Down

0 comments on commit cf025a2

Please sign in to comment.