1+ import { ConfigurationReference , getConf } from '@jbrowse/core/configuration' ;
2+ import { AnyConfigurationModel , } from '@jbrowse/core/configuration/configurationSchema' ;
3+ import { getContainingTrack , getSession } from '@jbrowse/core/util' ;
4+ import FilterListIcon from '@material-ui/icons/FilterList' ;
5+ import VisibilityIcon from '@material-ui/icons/Visibility' ;
6+ import configSchemaF from './configSchema' ;
7+ import { getEnv , IAnyStateTreeNode , types } from 'mobx-state-tree' ;
8+ import PaletteIcon from '@material-ui/icons/Palette' ;
9+ import { default as SetMaxHeightDlg } from '@jbrowse/plugin-linear-genome-view/src/LinearBasicDisplay/components/SetMaxHeight' ;
10+
11+ export default jbrowse => {
12+ const configSchema = jbrowse . jbrequire ( configSchemaF )
13+ const { BaseLinearDisplay } = jbrowse . getPlugin (
14+ 'LinearGenomeViewPlugin' ,
15+ ) . exports
16+
17+ return types
18+ . compose (
19+ 'ExtendedVariantDisplay' ,
20+ BaseLinearDisplay ,
21+ types . model ( {
22+ type : types . literal ( 'ExtendedVariantDisplay' ) ,
23+ trackShowLabels : types . maybe ( types . boolean ) ,
24+ trackDisplayMode : types . maybe ( types . string ) ,
25+ trackMaxHeight : types . maybe ( types . number ) ,
26+ configuration : ConfigurationReference ( configSchema ) ,
27+ } ) ,
28+ )
29+ . actions ( self => ( {
30+ setDisplayMode ( val : string ) {
31+ self . trackDisplayMode = val
32+ if ( val === 'collapse' && self . showLabels ) {
33+ self . toggleShowLabels ( )
34+ }
35+ } ,
36+
37+ setMaxHeight ( val : number ) {
38+ self . trackMaxHeight = val
39+ } ,
40+
41+ toggleShowLabels ( ) {
42+ self . trackShowLabels = ! self . showLabels
43+ } ,
44+
45+ selectFeature ( feature ) {
46+ const session = getSession ( self )
47+ const track = getContainingTrack ( self ) as IAnyStateTreeNode & { configuration : AnyConfigurationModel }
48+
49+ const trackId = getConf ( track , 'trackId' )
50+ const detailsConfig = getConf ( track , [ 'displays' , '0' , 'detailsConfig' ] )
51+
52+ const widgetId = 'Variant-' + trackId ;
53+ const featureWidget = session . addWidget (
54+ 'ExtendedVariantWidget' ,
55+ widgetId ,
56+ {
57+ featureData : feature ,
58+ trackId : trackId ,
59+ message : '' ,
60+ detailsConfig : detailsConfig
61+ }
62+ )
63+
64+ session . showWidget ( featureWidget )
65+ session . setSelection ( feature )
66+ } ,
67+ } ) )
68+
69+ . views ( self => {
70+ const { renderProps : superRenderProps } = self
71+ const filterMenu = {
72+ label : 'Filter By Attributes' ,
73+ icon : FilterListIcon ,
74+ onClick : ( ) => {
75+ const session = getSession ( self )
76+ const track = getContainingTrack ( self ) as IAnyStateTreeNode & { configuration : AnyConfigurationModel }
77+ const widgetId = 'Variant-' + getConf ( track , 'trackId' ) ;
78+ const filterWidget = session . addWidget (
79+ 'InfoFilterWidget' ,
80+ widgetId ,
81+ { track : track . configuration }
82+ )
83+ session . showWidget ( filterWidget )
84+ }
85+ }
86+ const colorMenu = {
87+ label : "Color Selection" ,
88+ icon : PaletteIcon ,
89+ onClick : ( ) => {
90+ const session = getSession ( self )
91+ const track = getContainingTrack ( self ) as IAnyStateTreeNode & { configuration : AnyConfigurationModel }
92+ const widgetId = 'Variant-' + getConf ( track , 'trackId' ) ;
93+ const colorWidget = session . addWidget (
94+ 'ColorWidget' ,
95+ widgetId ,
96+ { track : track . configuration }
97+ )
98+ session . showWidget ( colorWidget )
99+ }
100+ }
101+
102+ const sampleFilterMenu = {
103+ label : 'Filter By Sample' ,
104+ icon : FilterListIcon ,
105+ onClick : ( ) => {
106+ const session = getSession ( self )
107+ const track = getContainingTrack ( self ) as IAnyStateTreeNode & { configuration : AnyConfigurationModel }
108+ const widgetId = 'Variant-' + getConf ( track , 'trackId' ) ;
109+ const sampleFilterWidget = session . addWidget (
110+ 'SampleFilterWidget' ,
111+ widgetId ,
112+ { track : track . configuration }
113+ )
114+ session . showWidget ( sampleFilterWidget )
115+ }
116+ }
117+
118+ return {
119+ renderProps ( ) {
120+ const config = self . rendererConfig
121+ return {
122+ ...superRenderProps ( ) ,
123+ config : config ,
124+ rendererConfig : config
125+ }
126+ } ,
127+
128+ get rendererTypeName ( ) {
129+ return self . configuration . renderer . type
130+ } ,
131+
132+ get rendererConfig ( ) {
133+ const configBlob = getConf ( self , [ 'renderer' ] ) || { }
134+
135+ return self . rendererType . configSchema . create (
136+ {
137+ ...configBlob ,
138+ showLabels : this . showLabels ,
139+ displayMode : this . displayMode ,
140+ maxHeight : this . maxHeight
141+ } ,
142+ getEnv ( self ) ,
143+ )
144+ } ,
145+
146+ get showLabels ( ) {
147+ const showLabels = getConf ( self , [ 'renderer' , 'showLabels' ] )
148+ return self . trackShowLabels !== undefined
149+ ? self . trackShowLabels
150+ : showLabels
151+ } ,
152+
153+ get maxHeight ( ) {
154+ const maxHeight = getConf ( self , [ 'renderer' , 'maxHeight' ] )
155+ return self . trackMaxHeight !== undefined
156+ ? self . trackMaxHeight
157+ : maxHeight
158+ } ,
159+
160+ get displayMode ( ) {
161+ const displayMode = getConf ( self , [ 'renderer' , 'displayMode' ] )
162+ return self . trackDisplayMode !== undefined
163+ ? self . trackDisplayMode
164+ : displayMode
165+ } ,
166+
167+ trackMenuItems ( ) {
168+ return [
169+ filterMenu , sampleFilterMenu , colorMenu ,
170+ {
171+ label : 'Show labels' ,
172+ icon : VisibilityIcon ,
173+ type : 'checkbox' ,
174+ checked : self . showLabels ,
175+ onClick : ( ) => {
176+ self . toggleShowLabels ( )
177+ }
178+ } ,
179+ {
180+ label : 'Display mode' ,
181+ icon : VisibilityIcon ,
182+ subMenu : [
183+ 'compact' ,
184+ 'reducedRepresentation' ,
185+ 'normal' ,
186+ 'collapse' ,
187+ ] . map ( val => ( {
188+ label : val ,
189+ onClick : ( ) => {
190+ self . setDisplayMode ( val )
191+ } ,
192+ } ) ) ,
193+ } ,
194+ {
195+ label : 'Set max height' ,
196+ onClick : ( ) => {
197+ getSession ( self ) . queueDialog ( ( doneCallback : Function ) => [
198+ SetMaxHeightDlg ,
199+ { model : self , handleClose : doneCallback } ,
200+ ] )
201+ } ,
202+ }
203+ ]
204+ }
205+ }
206+ } )
207+ }
0 commit comments