11import React , { useEffect , useRef } from 'react'
22
3+ import { ResizeHandle } from '@jbrowse/core/ui'
34import { getContainingView } from '@jbrowse/core/util'
45import { autorun } from 'mobx'
56import { observer } from 'mobx-react'
@@ -8,6 +9,16 @@ import { isAlive } from 'mobx-state-tree'
89import type { LinearMafDisplayModel } from '../../stateModel'
910import type { LinearGenomeViewModel } from '@jbrowse/plugin-linear-genome-view'
1011
12+ const resizeHandleStyle = {
13+ position : 'absolute' ,
14+ top : 0 ,
15+ height : '100%' ,
16+ width : 4 ,
17+ zIndex : 1001 ,
18+ background : 'rgba(0,0,0,0.1)' ,
19+ cursor : 'col-resize' ,
20+ } as const
21+
1122const SvgWrapper = observer ( function ( {
1223 children,
1324 model,
@@ -26,24 +37,38 @@ const SvgWrapper = observer(function ({
2637 if ( isAlive ( model ) ) {
2738 const {
2839 totalHeight,
29- sidebarWidth,
3040 leafMap,
3141 rowHeight,
3242 highlightedRowNames,
43+ hoveredTreeNode,
3344 } = model
45+ const { width : viewWidth } = getContainingView (
46+ model ,
47+ ) as LinearGenomeViewModel
3448
3549 ctx . resetTransform ( )
36- ctx . clearRect ( 0 , 0 , sidebarWidth , totalHeight )
50+ ctx . clearRect ( 0 , 0 , viewWidth , totalHeight )
3751
3852 if ( highlightedRowNames ) {
3953 ctx . fillStyle = 'rgba(255,165,0,0.2)'
4054 const halfRowHeight = rowHeight / 2
4155 for ( const name of highlightedRowNames ) {
4256 const leaf = leafMap . get ( name )
4357 if ( leaf ) {
44- ctx . fillRect ( 0 , leaf . x ! - halfRowHeight , sidebarWidth , rowHeight )
58+ ctx . fillRect ( 0 , leaf . x ! - halfRowHeight , viewWidth , rowHeight )
4559 }
4660 }
61+
62+ // Draw orange dot at hovered tree node
63+ if ( hoveredTreeNode ) {
64+ ctx . fillStyle = 'rgba(255,165,0,0.8)'
65+ ctx . beginPath ( )
66+ ctx . arc ( hoveredTreeNode . y , hoveredTreeNode . x , 4 , 0 , 2 * Math . PI )
67+ ctx . fill ( )
68+ ctx . strokeStyle = 'rgba(255,140,0,1)'
69+ ctx . lineWidth = 1
70+ ctx . stroke ( )
71+ }
4772 }
4873 }
4974 } )
@@ -53,7 +78,7 @@ const SvgWrapper = observer(function ({
5378 if ( exportSVG ) {
5479 return < > { children } </ >
5580 } else {
56- const { totalHeight, sidebarWidth } = model
81+ const { totalHeight, treeWidth , hierarchy } = model
5782 const { width } = getContainingView ( model ) as LinearGenomeViewModel
5883 return (
5984 < >
@@ -72,18 +97,39 @@ const SvgWrapper = observer(function ({
7297 </ svg >
7398 < canvas
7499 ref = { mouseoverRef }
75- width = { sidebarWidth }
100+ width = { width }
76101 height = { totalHeight }
77102 style = { {
78103 position : 'absolute' ,
79104 top : 0 ,
80105 left : 0 ,
81- width : sidebarWidth ,
106+ width,
82107 height : totalHeight ,
83108 zIndex : 1000 ,
84109 pointerEvents : 'none' ,
85110 } }
86111 />
112+ { hierarchy ? (
113+ < div
114+ onMouseDown = { e => {
115+ e . stopPropagation ( )
116+ } }
117+ >
118+ < ResizeHandle
119+ onDrag = { distance => {
120+ model . setTreeAreaWidth (
121+ Math . max ( 20 , model . treeAreaWidth + distance ) ,
122+ )
123+ return undefined
124+ } }
125+ style = { {
126+ ...resizeHandleStyle ,
127+ left : treeWidth ,
128+ } }
129+ vertical
130+ />
131+ </ div >
132+ ) : null }
87133 </ >
88134 )
89135 }
0 commit comments