Skip to content

Commit

Permalink
move options to track menu, add first_render functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
carolinebridge committed Mar 5, 2024
1 parent 1bd1797 commit 2a97565
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const RenderedBlocks = observer(function ({
{blockDefinitions.map(block => {
if (block instanceof ContentBlock) {
const state = blockState.get(block.key)

return (
<ContentBlockComponent
block={block}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ function stateModelFactory() {
/**
* #getter
* max height determined by the blockState
* configurable to default track height to this to show all features
* configurable to default the track height to this to show all features
*/
get layoutMaxHeight() {
const { blockDefinitions, blockState } = self
Expand All @@ -118,6 +118,7 @@ function stateModelFactory() {
)
return maxHeight
},

/**
* #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,8 @@
import { getConf } from '@jbrowse/core/configuration'
import { types } from 'mobx-state-tree'
import { getConf } from '@jbrowse/core/configuration'
import { getContainingView } from '@jbrowse/core/util'

import { LinearGenomeViewModel } from '../../LinearGenomeView'

const minDisplayHeight = 20

Expand All @@ -26,24 +29,48 @@ export default function TrackHeightMixin() {
* #property
*/
scrollTop: 0,
/**
* #property
*/
firstRenderHeight: 100,
}))
.actions(self => ({
/**
* #action
*/
setFirstRenderHeight(val: number) {
self.firstRenderHeight = val
return val
},
}))
.views(self => ({
/**
* #getter
* returns the height value as determined by the trackHeightSetting
*/
get adjustLayout() {
return (
// @ts-expect-error
self.trackHeightSetting === 'on' ||
// @ts-expect-error
self.trackHeightSetting === 'first_render'
)
const { trackHeightSetting } = getContainingView(
self,
) as LinearGenomeViewModel

// @ts-expect-error
const height = self.layoutMaxHeight

return trackHeightSetting === 'on'
? height
: trackHeightSetting === 'first_render' &&
self.firstRenderHeight === 100
? self.setFirstRenderHeight(height)
: trackHeightSetting === 'first_render'
? self.firstRenderHeight
: undefined
},
get height() {
return (
self.heightPreConfig ??
(this.adjustLayout
? // @ts-expect-error
self.layoutMaxHeight
: // @ts-expect-error
(getConf(self, 'height') as number))
this.adjustLayout ??
// @ts-expect-error
(getConf(self, 'height') as number)
)
},
}))
Expand Down
49 changes: 1 addition & 48 deletions plugins/linear-genome-view/src/LinearBasicDisplay/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
ConfigurationReference,
AnyConfigurationSchemaType,
} from '@jbrowse/core/configuration'
import { getSession, localStorageGetItem } from '@jbrowse/core/util'
import { getSession } from '@jbrowse/core/util'
import { MenuItem } from '@jbrowse/core/ui'
import { types, getEnv, Instance } from 'mobx-state-tree'

Expand Down Expand Up @@ -55,13 +55,6 @@ function stateModelFactory(configSchema: AnyConfigurationSchemaType) {
* #property
*/
configuration: ConfigurationReference(configSchema),
/**
* #property
*/
adjustLayoutHeight: types.optional(
types.string,
() => localStorageGetItem('lgv-adjustLayoutHeight') || 'off',
),
}),
)
.views(self => ({
Expand Down Expand Up @@ -124,16 +117,6 @@ function stateModelFactory(configSchema: AnyConfigurationSchemaType) {
getEnv(self),
)
},
/**
* #getter
*/
get trackHeightSetting() {
const sessionSetting = getConf(getSession(self), [
'renderer',
'trackHeight',
])
return self.adjustLayoutHeight || sessionSetting
},
}))

.actions(self => ({
Expand Down Expand Up @@ -161,13 +144,6 @@ function stateModelFactory(configSchema: AnyConfigurationSchemaType) {
setMaxHeight(val?: number) {
self.trackMaxHeight = val
},
/**
* #action
*/
setAdjustLayoutHeight(setting: 'on' | 'off' | 'first_render') {
localStorage.setItem('lgv-adjustLayoutHeight', setting)
self.adjustLayoutHeight = setting
},
}))
.views(self => {
const {
Expand Down Expand Up @@ -230,29 +206,6 @@ function stateModelFactory(configSchema: AnyConfigurationSchemaType) {
])
},
},
{
label: 'Auto-adjust track height',
subMenu: [
{
label: 'Off (use trackHeight from config)',
type: 'radio',
checked: self.trackHeightSetting === 'off',
onClick: () => self.setAdjustLayoutHeight('off'),
},
{
label: 'On (auto-adjust to show all features)',
type: 'radio',
checked: self.trackHeightSetting === 'on',
onClick: () => self.setAdjustLayoutHeight('on'),
},
{
label: 'On first render (auto-adjust to show all features)',
type: 'radio',
checked: self.trackHeightSetting === 'first_render',
onClick: () => self.setAdjustLayoutHeight('first_render'),
},
],
},
]
},
}
Expand Down
50 changes: 50 additions & 0 deletions plugins/linear-genome-view/src/LinearGenomeView/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,15 @@ export function stateModelFactory(pluginManager: PluginManager) {
() => localStorageGetItem('lgv-trackLabels') || '',
),

/**
* #property
* setting to auto-adjust the layout height of tracks
*/
adjustLayoutHeight: types.optional(
types.string,
() => localStorageGetItem('lgv-adjustLayoutHeight') || 'off',
),

/**
* #property
* show the "gridlines" in the track area
Expand Down Expand Up @@ -280,6 +289,16 @@ export function stateModelFactory(pluginManager: PluginManager) {
])
return self.trackLabels || sessionSetting
},
/**
* #getter
*/
get trackHeightSetting() {
const sessionSetting = getConf(getSession(self), [
'LinearGenomeViewPlugin',
'trackHeight',
])
return self.adjustLayoutHeight || sessionSetting
},
/**
* #getter
*/
Expand Down Expand Up @@ -796,6 +815,14 @@ export function stateModelFactory(pluginManager: PluginManager) {
self.trackLabels = setting
},

/**
* #action
*/
setAdjustLayoutHeight(setting: 'on' | 'off' | 'first_render') {
localStorage.setItem('lgv-adjustLayoutHeight', setting)
self.adjustLayoutHeight = setting
},

/**
* #action
*/
Expand Down Expand Up @@ -1182,6 +1209,29 @@ export function stateModelFactory(pluginManager: PluginManager) {
},
],
},
{
label: 'Track height',
subMenu: [
{
label: 'Use default (from config)',
type: 'radio',
checked: self.trackHeightSetting === 'off',
onClick: () => self.setAdjustLayoutHeight('off'),
},
{
label: 'Auto-adjust to show all features on track',
type: 'radio',
checked: self.trackHeightSetting === 'on',
onClick: () => self.setAdjustLayoutHeight('on'),
},
{
label: 'Auto-adjust to show height of initial features',
type: 'radio',
checked: self.trackHeightSetting === 'first_render',
onClick: () => self.setAdjustLayoutHeight('first_render'),
},
],
},
]

// add track's view level menu options
Expand Down
12 changes: 12 additions & 0 deletions plugins/linear-genome-view/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ export default class LinearGenomeViewPlugin extends Plugin {
'hidden',
]),
},
/**
* #slot configuration.LinearGenomeViewPlugin.trackLabels
*/
trackHeight: {
type: 'string',
defaultValue: 'off',
model: types.enumeration('trackHeightOptions', [
'off',
'on',
'first_render',
]),
},
})

install(pluginManager: PluginManager) {
Expand Down

0 comments on commit 2a97565

Please sign in to comment.