diff --git a/plugins/linear-genome-view/src/BaseLinearDisplay/components/LinearBlocks.tsx b/plugins/linear-genome-view/src/BaseLinearDisplay/components/LinearBlocks.tsx index ff82a9a1f6..d1a50abb3b 100644 --- a/plugins/linear-genome-view/src/BaseLinearDisplay/components/LinearBlocks.tsx +++ b/plugins/linear-genome-view/src/BaseLinearDisplay/components/LinearBlocks.tsx @@ -52,6 +52,7 @@ const RenderedBlocks = observer(function ({ {blockDefinitions.map(block => { if (block instanceof ContentBlock) { const state = blockState.get(block.key) + return ( ({ + /** + * #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) ) }, })) diff --git a/plugins/linear-genome-view/src/LinearBasicDisplay/model.ts b/plugins/linear-genome-view/src/LinearBasicDisplay/model.ts index 108c27ecda..f6cfbe0049 100644 --- a/plugins/linear-genome-view/src/LinearBasicDisplay/model.ts +++ b/plugins/linear-genome-view/src/LinearBasicDisplay/model.ts @@ -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' @@ -55,13 +55,6 @@ function stateModelFactory(configSchema: AnyConfigurationSchemaType) { * #property */ configuration: ConfigurationReference(configSchema), - /** - * #property - */ - adjustLayoutHeight: types.optional( - types.string, - () => localStorageGetItem('lgv-adjustLayoutHeight') || 'off', - ), }), ) .views(self => ({ @@ -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 => ({ @@ -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 { @@ -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'), - }, - ], - }, ] }, } diff --git a/plugins/linear-genome-view/src/LinearGenomeView/model.ts b/plugins/linear-genome-view/src/LinearGenomeView/model.ts index 2745ed75ba..50ad8fd41f 100644 --- a/plugins/linear-genome-view/src/LinearGenomeView/model.ts +++ b/plugins/linear-genome-view/src/LinearGenomeView/model.ts @@ -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 @@ -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 */ @@ -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 */ @@ -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 diff --git a/plugins/linear-genome-view/src/index.ts b/plugins/linear-genome-view/src/index.ts index d1d34986d1..ca816093d3 100644 --- a/plugins/linear-genome-view/src/index.ts +++ b/plugins/linear-genome-view/src/index.ts @@ -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) {