Skip to content

Commit 11d5745

Browse files
committed
Properly size linear genome view after creation
1 parent e8cb35c commit 11d5745

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

plugins/linear-genome-view/src/BaseLinearDisplay/models/BaseLinearDisplayModel.tsx

+20-7
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
import { BaseBlock } from '@jbrowse/core/util/blockTypes'
1717
import CompositeMap from '@jbrowse/core/util/compositeMap'
1818
import { getParentRenderProps } from '@jbrowse/core/util/tracks'
19-
import { autorun } from 'mobx'
19+
import { autorun, when } from 'mobx'
2020
import {
2121
addDisposer,
2222
isAlive,
@@ -305,7 +305,7 @@ function stateModelFactory() {
305305
},
306306
{
307307
label: 'Collapse introns',
308-
onClick: () => {
308+
onClick: async () => {
309309
const { contextMenuFeature } = self
310310
if (contextMenuFeature) {
311311
const refName = contextMenuFeature.get('refName')
@@ -323,11 +323,24 @@ function stateModelFactory() {
323323
assemblyName: view.assemblyNames[0],
324324
})) || []
325325
res.sort((a, b) => a.start - b.start)
326-
getSession(self).addView('LinearGenomeView', {
327-
...getSnapshot(view),
328-
id: nanoid(),
329-
displayedRegions: res,
330-
})
326+
327+
// need to strip ID before copying view snap
328+
const { id, ...rest } = getSnapshot(view)
329+
const newView = getSession(self).addView(
330+
'LinearGenomeView',
331+
{
332+
...rest,
333+
id: nanoid(),
334+
tracks: rest.tracks.map(track => {
335+
const { id, ...rest } = track
336+
return { ...rest, id: nanoid() }
337+
}),
338+
displayedRegions: res,
339+
},
340+
) as LGV
341+
await when(() => newView.initialized)
342+
343+
newView.showAllRegions()
331344
}
332345
},
333346
},

plugins/linear-genome-view/src/LinearGenomeView/components/Header.tsx

+3-6
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,11 @@ const Controls = ({ model }: { model: LGV }) => {
112112
}
113113

114114
const LinearGenomeViewHeader = observer(({ model }: { model: LGV }) => {
115+
const Wrapper = model.hideHeaderOverview ? React.Fragment : OverviewScalebar
115116
return !model.hideHeader ? (
116-
model.hideHeaderOverview ? (
117+
<Wrapper model={model}>
117118
<Controls model={model} />
118-
) : (
119-
<OverviewScalebar model={model}>
120-
<Controls model={model} />
121-
</OverviewScalebar>
122-
)
119+
</Wrapper>
123120
) : null
124121
})
125122

0 commit comments

Comments
 (0)