Skip to content

Commit

Permalink
Use MST view instead of partition for pinned track
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettjstevens committed Apr 12, 2024
1 parent 1b0f3be commit ef1ec12
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 26 deletions.
18 changes: 0 additions & 18 deletions packages/core/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1321,24 +1321,6 @@ export function groupBy<T>(array: Iterable<T>, predicate: (v: T) => string) {
return result
}

/**
* Partition an array into two arrays based on a condition. See
* {@link https://www.30secondsofcode.org/js/s/partition-array/}
*/
export function partition<T>(
array: T[],
callback: (value: T, currentIndex: number, originalArray: T[]) => boolean,
) {
// eslint-disable-next-line unicorn/no-array-reduce
return array.reduce(
(acc, val, i, arr) => {
acc[callback(val, i, arr) ? 0 : 1].push(val)
return acc
},
[[] as T[], [] as T[]],
)
}

export function notEmpty<T>(value: T | null | undefined): value is T {
return value !== null && value !== undefined
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { lazy, useEffect, useRef } from 'react'
import { Button, Paper, Typography } from '@mui/material'
import { makeStyles } from 'tss-react/mui'
import { LoadingEllipses, VIEW_HEADER_HEIGHT } from '@jbrowse/core/ui'
import { getSession, partition } from '@jbrowse/core/util'
import { getSession } from '@jbrowse/core/util'
import { observer } from 'mobx-react'

// icons
Expand Down Expand Up @@ -72,7 +72,13 @@ function NoTracksActive({ model }: { model: LinearGenomeViewModel }) {
}

const LinearGenomeView = observer(({ model }: { model: LGV }) => {
const { tracks, error, initialized, hasDisplayedRegions } = model
const {
pinnedTracks,
unpinnedTracks,
error,
initialized,
hasDisplayedRegions,
} = model
const ref = useRef<HTMLDivElement>(null)
const session = getSession(model)
const { classes } = useStyles()
Expand Down Expand Up @@ -111,11 +117,6 @@ const LinearGenomeView = observer(({ model }: { model: LGV }) => {
}
}

const [pinnedTracks, unpinnedTracks] = partition(
tracks,
track => track.pinned,
)

return (
<div
className={classes.rel}
Expand All @@ -138,7 +139,7 @@ const LinearGenomeView = observer(({ model }: { model: LGV }) => {
<MiniControlsComponent model={model} />
</div>
<TracksContainer model={model}>
{!tracks.length ? (
{!(pinnedTracks.length + unpinnedTracks.length) ? (
<NoTracksActive model={model} />
) : (
<>
Expand Down
12 changes: 12 additions & 0 deletions plugins/linear-genome-view/src/LinearGenomeView/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,18 @@ export function stateModelFactory(pluginManager: PluginManager) {
rightOffset: undefined as undefined | BpOffset,
}))
.views(self => ({
/**
* #getter
*/
get pinnedTracks() {
return self.tracks.filter(t => t.pinned)
},
/**
* #getter
*/
get unpinnedTracks() {
return self.tracks.filter(t => !t.pinned)
},
/**
* #getter
* this is the effective value of the track labels setting, incorporating
Expand Down

0 comments on commit ef1ec12

Please sign in to comment.