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

Adds option to auto-adjust the track height to show all features #4252

Open
wants to merge 37 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
a27fb29
Possible approach for calculating the current layout max height
cmdcolin Feb 28, 2024
0282cad
WIP: adds option to auto-adjust the track height to show all features
carolinebridge Mar 1, 2024
8e465ce
Merge branch 'main' into layout_max_height_calc
carolinebridge Mar 1, 2024
1bd1797
lint and correct default value for layout
carolinebridge Mar 1, 2024
2a97565
move options to track menu, add first_render functionality
carolinebridge Mar 5, 2024
1d571b7
define firstRenderHeight in autorun ;; adds clearer definition of "fi…
carolinebridge Mar 5, 2024
8355237
rename variables to clearly state layout dependency
carolinebridge Mar 6, 2024
9badcc2
wip: working on alignments track resize
carolinebridge Mar 14, 2024
49214ed
adjustments for alignments view, no scrollbar when using max height s…
carolinebridge Mar 15, 2024
cb58e7b
Merge branch 'main' into layout_max_height_calc
carolinebridge Mar 25, 2024
b9df587
Renames settings for clarity ;; replaces "first render" with "bounded…
carolinebridge Mar 28, 2024
cea3010
check getRectangles on layout
carolinebridge Mar 28, 2024
3f3de93
verify rectangles are defined in blockHeight calc
carolinebridge Mar 28, 2024
2c7d85a
unsafe chaining fix
carolinebridge Mar 28, 2024
a4837a4
unsafe chaining fix
carolinebridge Mar 28, 2024
900eb73
fix some awkward jittering ;; clarifying text
carolinebridge Mar 29, 2024
9dc2a19
Merge branch 'main' into layout_max_height_calc
carolinebridge Apr 19, 2024
378cd17
fixing incorrect svg sizing with dynamic setting
carolinebridge Apr 19, 2024
3211200
snap update
carolinebridge Apr 19, 2024
e512bd1
fix issue where non-layout lgv's were assuming height adjustment beha…
carolinebridge Apr 19, 2024
9b4f71f
per-track adjustment setting
carolinebridge May 3, 2024
63c7206
lint
carolinebridge May 3, 2024
a8d60e0
Merge branch 'main' into layout_max_height_calc
carolinebridge May 29, 2024
f6ee32c
fix on bound heights
carolinebridge May 29, 2024
302b268
remove comment and adjust setheight
carolinebridge May 30, 2024
1eb7d51
snaps
carolinebridge May 30, 2024
eb6e5dd
adds transition to height change
carolinebridge May 31, 2024
9a88035
remove animation when static
carolinebridge Jun 4, 2024
6e9febb
Merge branch 'main' into layout_max_height_calc
carolinebridge Jun 5, 2024
0dba081
Merge branch 'main' into layout_max_height_calc
carolinebridge Jun 5, 2024
ed11425
snaps
carolinebridge Jun 5, 2024
2ec27dd
Use contentBlocks only for gathering block heights
cmdcolin Jun 5, 2024
630c0fe
Only access blocks after view.initialized
cmdcolin Jun 5, 2024
f301f15
remove references to bound setting
carolinebridge Jun 7, 2024
86bbb14
add track height adjustment to alignments
carolinebridge Jun 7, 2024
6ff2f10
fix crash
carolinebridge Jun 10, 2024
ef113ec
Merge branch 'main' into layout_max_height_calc
carolinebridge Jul 11, 2024
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
17 changes: 15 additions & 2 deletions packages/core/pluggableElementTypes/renderers/BoxRendererType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import FeatureRendererType, {
ResultsSerialized as FeatureResultsSerialized,
ResultsDeserialized as FeatureResultsDeserialized,
} from './FeatureRendererType'
import { getLayoutId, Region, Feature } from '../../util'
import { getLayoutId, Region, Feature, max } from '../../util'
import { readConfObject, AnyConfigurationModel } from '../../configuration'
import SerializableFilterChain from './util/serializableFilterChain'
import RpcManager from '../../rpc/RpcManager'
Expand Down Expand Up @@ -102,6 +102,7 @@ export interface RenderArgsDeserialized extends FeatureRenderArgsDeserialized {

export interface RenderResults extends FeatureRenderResults {
layout: BaseLayout<Feature>
blockHeight: number
}

export interface ResultsSerialized extends FeatureResultsSerialized {
Expand Down Expand Up @@ -224,6 +225,18 @@ export default class BoxRendererType extends FeatureRendererType {
(props.layout as undefined | BaseLayout<unknown>) ||
this.createLayoutInWorker(props)
const result = await super.render({ ...props, layout })
return { ...result, layout }

const rects = layout?.getRectangles?.() || undefined

const blockHeight = rects
? max(
[...rects]
.filter(([key]) => [...result.features.keys()].includes(key))
.flatMap(rect => rect[1][3]), // only interested in the 'bottom' value
0,
)
: 0

return { ...result, layout, blockHeight }
}
}
33 changes: 24 additions & 9 deletions plugins/alignments/src/LinearAlignmentsDisplay/models/model.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ function stateModelFactory(
* #action
*/
resizeHeight(distance: number) {
self.PileupDisplay.resizeHeight(distance)
const oldHeight = self.height
const newHeight = this.setHeight(self.height + distance)
return newHeight - oldHeight
Expand Down Expand Up @@ -270,15 +271,6 @@ function stateModelFactory(
self.setSNPCoverageHeight(self.SNPCoverageDisplay.height)
}),
)

addDisposer(
self,
autorun(() => {
self.PileupDisplay.setHeight(
self.height - self.SNPCoverageDisplay.height,
)
}),
)
},
/**
* #action
Expand Down Expand Up @@ -348,6 +340,29 @@ function stateModelFactory(
const { height, ...rest } = snap
return { heightPreConfig: height, ...rest }
})
.actions(self => ({
afterAttach() {
addDisposer(
self,
autorun(() => {
// Sets the heightPreConfig conditional to whether the user has the layout height setting on (impacts the PileupDisplay)
const { PileupDisplay, SNPCoverageDisplay } = self

const setting = PileupDisplay.adjustTrackLayoutHeightSetting

if (setting === 'dynamic' || setting === 'bound') {
self.setHeight(PileupDisplay.height + SNPCoverageDisplay.height)
}

if (setting === 'static') {
self.PileupDisplay.setHeight(
self.height - SNPCoverageDisplay.height,
)
}
}),
)
},
}))
}

export default stateModelFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -520,14 +520,35 @@ export function SharedLinearPileupDisplayMixin(
],
},
{
label: 'Set max height...',
label: 'Set max height',
onClick: () => {
getSession(self).queueDialog(doneCallback => [
SetMaxHeightDialog,
{ model: self, handleClose: doneCallback },
])
},
},
{
label: 'Track height adjustment',
subMenu: [
{
label: 'Static (resized, or configured height)',
type: 'radio',
checked: self.adjustTrackLayoutHeightSetting === 'static',
onClick: () =>
// @ts-expect-error
self.setAdjustTrackLayoutHeightSetting('static'),
},
{
label: 'Dynamic (auto-adjust to show all features)',
type: 'radio',
checked: self.adjustTrackLayoutHeightSetting === 'dynamic',
onClick: () =>
// @ts-expect-error
self.setAdjustTrackLayoutHeightSetting('dynamic'),
},
],
},
]
},
}
Expand Down
12 changes: 11 additions & 1 deletion plugins/alignments/src/LinearPileupDisplay/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ function stateModelFactory(configSchema: AnyConfigurationSchemaType) {
* #property
*/
mismatchAlpha: types.maybe(types.boolean),

/**
* #property
* setting to auto-adjust the layout height of tracks
*/
adjustTrackLayoutHeight: types.optional(types.string, 'static'),
/**
* #property
*/
Expand Down Expand Up @@ -161,6 +165,12 @@ function stateModelFactory(configSchema: AnyConfigurationSchemaType) {
self.sortReady = false
self.featureHeight = n
},
/**
* #action
*/
setAdjustTrackLayoutHeightSetting(setting: 'static' | 'dynamic') {
self.adjustTrackLayoutHeight = setting
},
}))
.actions(self => {
// resets the sort object and refresh whole display on reload
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,27 @@ function stateModelFactory() {
},
}))
.views(self => ({
/**
* #getter
* array of the current block heights rendered
*/
get currentLayoutBlockHeights() {
const view = getContainingView(self) as LinearGenomeViewModel
return view.initialized
? self.blockDefinitions.contentBlocks.map(
block => self.blockState.get(block.key)?.blockHeight,
)
: []
},

/**
* #getter
* returns true if all blocks are defined
*/
get allLayoutBlocksRendered() {
return this.currentLayoutBlockHeights.every(b => b !== undefined)
},

/**
* #getter
* how many milliseconds to wait for the display to
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { addDisposer, types } from 'mobx-state-tree'
import { getConf } from '@jbrowse/core/configuration'
import { types } from 'mobx-state-tree'
import { getSession, max } from '@jbrowse/core/util'
import { autorun } from 'mobx'

const minDisplayHeight = 20

Expand Down Expand Up @@ -28,12 +30,42 @@ export default function TrackHeightMixin() {
scrollTop: 0,
}))
.views(self => ({
/**
* #getter
* returns the value of the track height setting from the view model
*/
get adjustTrackLayoutHeightSetting() {
// @ts-ignore
const { adjustTrackLayoutHeight } = self

return adjustTrackLayoutHeight
},
/**
* #getter
* the max height between the rendered blocks and the configured height
*/
get maxLayoutBlockHeight() {
// @ts-expect-error
const confHeight = getConf(self, 'height') as number
// @ts-expect-error
return max(self.currentLayoutBlockHeights, confHeight)
},
/**
* #getter
* returns the height of the track as a combination of the config and the settings
*/
get height() {
// @ts-expect-error
return self.heightPreConfig ?? (getConf(self, 'height') as number)
},
}))
.actions(self => ({
notifyStaticSettingChange() {
getSession(self).notify(
'LGV track height setting has changed to Static to use your manually set height.',
'info',
)
},
/**
* #action
*/
Expand All @@ -51,9 +83,34 @@ export default function TrackHeightMixin() {
* #action
*/
resizeHeight(distance: number) {
// if the user resizes their height, we want the setting to turn off and maintain their set height
if (self.adjustTrackLayoutHeightSetting !== 'static') {
// @ts-ignore
self.setAdjustTrackLayoutHeightSetting('static')
this.notifyStaticSettingChange()
}
const oldHeight = self.height
const newHeight = this.setHeight(self.height + distance)
return newHeight - oldHeight
},
}))
.actions(self => ({
afterAttach() {
addDisposer(
self,
autorun(() => {
// @ts-expect-error
if (self.allLayoutBlocksRendered) {
switch (self.adjustTrackLayoutHeightSetting) {
case 'dynamic':
self.setHeight(self.maxLayoutBlockHeight)
break
default:
break
}
}
}),
)
},
}))
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const blockState = types
reactElement: undefined as React.ReactElement | undefined,
features: undefined as Map<string, Feature> | undefined,
layout: undefined as any,
blockHeight: undefined as number | undefined,
status: '',
error: undefined as unknown,
message: undefined as string | undefined,
Expand Down Expand Up @@ -98,6 +99,7 @@ const blockState = types
self.reactElement = undefined
self.features = undefined
self.layout = undefined
self.blockHeight = undefined
self.error = undefined
self.maxHeightReached = false
self.renderProps = undefined
Expand All @@ -112,6 +114,7 @@ const blockState = types
self.reactElement = undefined
self.features = undefined
self.layout = undefined
self.blockHeight = undefined
self.error = undefined
self.maxHeightReached = false
self.renderProps = undefined
Expand All @@ -123,6 +126,7 @@ const blockState = types
reactElement: React.ReactElement
features: Map<string, Feature>
layout: any
blockHeight: number
maxHeightReached: boolean
renderProps: any
}
Expand All @@ -135,6 +139,7 @@ const blockState = types
reactElement,
features,
layout,
blockHeight,
maxHeightReached,
renderProps,
} = props
Expand All @@ -143,6 +148,7 @@ const blockState = types
self.reactElement = reactElement
self.features = features
self.layout = layout
self.blockHeight = blockHeight
self.error = undefined
self.maxHeightReached = maxHeightReached
self.renderProps = renderProps
Expand All @@ -159,6 +165,7 @@ const blockState = types
self.reactElement = undefined
self.features = undefined
self.layout = undefined
self.blockHeight = undefined
self.maxHeightReached = false
self.error = error
self.renderProps = undefined
Expand All @@ -173,6 +180,7 @@ const blockState = types
self.reactElement = undefined
self.features = undefined
self.layout = undefined
self.blockHeight = undefined
self.error = undefined
self.message = undefined
self.maxHeightReached = false
Expand Down Expand Up @@ -303,7 +311,7 @@ async function renderBlockEffect(
return undefined
}

const { reactElement, features, layout, maxHeightReached } =
const { reactElement, features, layout, blockHeight, maxHeightReached } =
await rendererType.renderInClient(rpcManager, {
...renderArgs,
...renderProps,
Expand All @@ -314,6 +322,7 @@ async function renderBlockEffect(
reactElement,
features,
layout,
blockHeight,
maxHeightReached,
renderProps,
}
Expand Down
Loading
Loading