Skip to content

Commit

Permalink
Create concept of global hovered state (#4013)
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin authored Oct 27, 2023
1 parent 479e97e commit 7806999
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
2 changes: 2 additions & 0 deletions packages/core/util/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ export interface AbstractSessionModel extends AbstractViewContainer {
selection?: unknown
focusedViewId?: string
themeName?: string
hovered: unknown
setHovered: (arg: unknown) => void
setFocusedViewId?: (id: string) => void
allThemes?: () => Record<string, ThemeOptions | undefined>
setSelection: (feature: Feature) => void
Expand Down
13 changes: 13 additions & 0 deletions packages/product-core/src/Session/BaseSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ export function BaseSessionModel<
* is.
*/
selection: undefined as unknown,
/**
* #volatile
* this is the globally "hovered" object. can be anything. code that
* wants to deal with this should examine it to see what kind of thing it
* is.
*/
hovered: undefined as unknown,
}))
.views(self => ({
get root() {
Expand Down Expand Up @@ -109,6 +116,12 @@ export function BaseSessionModel<
clearSelection() {
self.selection = undefined
},
/**
* #action
*/
setHovered(thing: unknown) {
self.hovered = thing
},
}))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,22 @@ const LinearGenomeView = observer(({ model }: { model: LGV }) => {
const HeaderComponent = model.HeaderComponent()

return (
<div className={classes.rel} ref={ref}>
<div
className={classes.rel}
ref={ref}
onMouseLeave={() => session.setHovered(undefined)}
onMouseMove={event => {
const c = ref.current
if (!c) {
return
}
const { tracks } = model
const leftPx = event.clientX - c.getBoundingClientRect().left
const hoverPosition = model.pxToBp(leftPx)
const hoverFeature = tracks.find(t => t.displays[0].featureUnderMouse)
session.setHovered({ hoverPosition, hoverFeature })
}}
>
<HeaderComponent model={model} />
<MiniControlsComponent model={model} />
<TracksContainer model={model}>
Expand Down
2 changes: 1 addition & 1 deletion plugins/svg/src/SvgFeatureRenderer/configSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ const SvgFeatureRenderer = ConfigurationSchema(
maxHeight: {
type: 'integer',
description: 'the maximum height to be used in a svg rendering',
defaultValue: 600,
defaultValue: 1200,
},

/**
Expand Down

0 comments on commit 7806999

Please sign in to comment.