@jbrowse/plugin-dotplot-view 2.6.1 → 2.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (188) hide show
  1. package/dist/ComparativeRenderer/index.js +0 -1
  2. package/dist/DotplotDisplay/components/DotplotDisplay.js +0 -1
  3. package/dist/DotplotDisplay/index.js +0 -1
  4. package/dist/DotplotDisplay/renderDotplotBlock.js +0 -1
  5. package/dist/DotplotDisplay/stateModelFactory.js +0 -1
  6. package/dist/DotplotReadVsRef/DotplotReadVsRef.js +0 -1
  7. package/dist/DotplotReadVsRef/index.js +0 -1
  8. package/dist/DotplotRenderer/ComparativeRenderRpc.js +0 -1
  9. package/dist/DotplotRenderer/DotplotRenderer.js +0 -1
  10. package/dist/DotplotRenderer/components/DotplotRendering.js +0 -1
  11. package/dist/DotplotRenderer/configSchema.js +0 -1
  12. package/dist/DotplotRenderer/index.js +0 -1
  13. package/dist/DotplotView/1dview.js +0 -1
  14. package/dist/DotplotView/blockTypes.js +0 -1
  15. package/dist/DotplotView/components/Axes.js +0 -1
  16. package/dist/DotplotView/components/CursorIcon.js +0 -1
  17. package/dist/DotplotView/components/DotplotTooltip.js +0 -1
  18. package/dist/DotplotView/components/DotplotView.js +0 -1
  19. package/dist/DotplotView/components/DotplotWarnings.js +0 -1
  20. package/dist/DotplotView/components/ExportSvgDialog.js +0 -1
  21. package/dist/DotplotView/components/Grid.js +0 -1
  22. package/dist/DotplotView/components/Header.js +0 -1
  23. package/dist/DotplotView/components/ImportCustomTrack.js +0 -1
  24. package/dist/DotplotView/components/ImportForm.js +0 -1
  25. package/dist/DotplotView/components/ImportSyntenyTrackSelector.js +0 -1
  26. package/dist/DotplotView/components/PanButtons.js +0 -1
  27. package/dist/DotplotView/components/WarningDialog.js +0 -1
  28. package/dist/DotplotView/components/util.js +0 -1
  29. package/dist/DotplotView/index.js +0 -1
  30. package/dist/DotplotView/model.js +0 -1
  31. package/dist/DotplotView/svgcomponents/SVGBackground.js +0 -1
  32. package/dist/DotplotView/svgcomponents/SVGDotplotView.js +0 -1
  33. package/dist/LaunchDotplotView.js +0 -1
  34. package/dist/ServerSideRenderedBlockContent.js +0 -1
  35. package/dist/ServerSideSyntenyRendering.js +0 -1
  36. package/dist/index.js +0 -1
  37. package/dist/util.js +0 -1
  38. package/esm/ComparativeRenderer/index.js +0 -1
  39. package/esm/DotplotDisplay/components/DotplotDisplay.js +0 -1
  40. package/esm/DotplotDisplay/index.js +0 -1
  41. package/esm/DotplotDisplay/renderDotplotBlock.js +0 -1
  42. package/esm/DotplotDisplay/stateModelFactory.js +0 -1
  43. package/esm/DotplotReadVsRef/DotplotReadVsRef.js +0 -1
  44. package/esm/DotplotReadVsRef/index.js +0 -1
  45. package/esm/DotplotRenderer/ComparativeRenderRpc.js +0 -1
  46. package/esm/DotplotRenderer/DotplotRenderer.js +0 -1
  47. package/esm/DotplotRenderer/components/DotplotRendering.js +0 -1
  48. package/esm/DotplotRenderer/configSchema.js +0 -1
  49. package/esm/DotplotRenderer/index.js +0 -1
  50. package/esm/DotplotView/1dview.js +0 -1
  51. package/esm/DotplotView/blockTypes.js +0 -1
  52. package/esm/DotplotView/components/Axes.js +0 -1
  53. package/esm/DotplotView/components/CursorIcon.js +0 -1
  54. package/esm/DotplotView/components/DotplotTooltip.js +0 -1
  55. package/esm/DotplotView/components/DotplotView.js +0 -1
  56. package/esm/DotplotView/components/DotplotWarnings.js +0 -1
  57. package/esm/DotplotView/components/ExportSvgDialog.js +0 -1
  58. package/esm/DotplotView/components/Grid.js +0 -1
  59. package/esm/DotplotView/components/Header.js +0 -1
  60. package/esm/DotplotView/components/ImportCustomTrack.js +0 -1
  61. package/esm/DotplotView/components/ImportForm.js +0 -1
  62. package/esm/DotplotView/components/ImportSyntenyTrackSelector.js +0 -1
  63. package/esm/DotplotView/components/PanButtons.js +0 -1
  64. package/esm/DotplotView/components/WarningDialog.js +0 -1
  65. package/esm/DotplotView/components/util.js +0 -1
  66. package/esm/DotplotView/index.js +0 -1
  67. package/esm/DotplotView/model.js +0 -1
  68. package/esm/DotplotView/svgcomponents/SVGBackground.js +0 -1
  69. package/esm/DotplotView/svgcomponents/SVGDotplotView.js +0 -1
  70. package/esm/LaunchDotplotView.js +0 -1
  71. package/esm/ServerSideRenderedBlockContent.js +0 -1
  72. package/esm/ServerSideSyntenyRendering.js +0 -1
  73. package/esm/index.js +0 -1
  74. package/esm/util.js +0 -1
  75. package/package.json +3 -4
  76. package/dist/ComparativeRenderer/index.js.map +0 -1
  77. package/dist/DotplotDisplay/components/DotplotDisplay.js.map +0 -1
  78. package/dist/DotplotDisplay/index.js.map +0 -1
  79. package/dist/DotplotDisplay/renderDotplotBlock.js.map +0 -1
  80. package/dist/DotplotDisplay/stateModelFactory.js.map +0 -1
  81. package/dist/DotplotReadVsRef/DotplotReadVsRef.js.map +0 -1
  82. package/dist/DotplotReadVsRef/index.js.map +0 -1
  83. package/dist/DotplotRenderer/ComparativeRenderRpc.js.map +0 -1
  84. package/dist/DotplotRenderer/DotplotRenderer.js.map +0 -1
  85. package/dist/DotplotRenderer/components/DotplotRendering.js.map +0 -1
  86. package/dist/DotplotRenderer/configSchema.js.map +0 -1
  87. package/dist/DotplotRenderer/index.js.map +0 -1
  88. package/dist/DotplotView/1dview.js.map +0 -1
  89. package/dist/DotplotView/blockTypes.js.map +0 -1
  90. package/dist/DotplotView/components/Axes.js.map +0 -1
  91. package/dist/DotplotView/components/CursorIcon.js.map +0 -1
  92. package/dist/DotplotView/components/DotplotTooltip.js.map +0 -1
  93. package/dist/DotplotView/components/DotplotView.js.map +0 -1
  94. package/dist/DotplotView/components/DotplotWarnings.js.map +0 -1
  95. package/dist/DotplotView/components/ExportSvgDialog.js.map +0 -1
  96. package/dist/DotplotView/components/Grid.js.map +0 -1
  97. package/dist/DotplotView/components/Header.js.map +0 -1
  98. package/dist/DotplotView/components/ImportCustomTrack.js.map +0 -1
  99. package/dist/DotplotView/components/ImportForm.js.map +0 -1
  100. package/dist/DotplotView/components/ImportSyntenyTrackSelector.js.map +0 -1
  101. package/dist/DotplotView/components/PanButtons.js.map +0 -1
  102. package/dist/DotplotView/components/WarningDialog.js.map +0 -1
  103. package/dist/DotplotView/components/util.js.map +0 -1
  104. package/dist/DotplotView/index.js.map +0 -1
  105. package/dist/DotplotView/model.js.map +0 -1
  106. package/dist/DotplotView/svgcomponents/SVGBackground.js.map +0 -1
  107. package/dist/DotplotView/svgcomponents/SVGDotplotView.js.map +0 -1
  108. package/dist/LaunchDotplotView.js.map +0 -1
  109. package/dist/ServerSideRenderedBlockContent.js.map +0 -1
  110. package/dist/ServerSideSyntenyRendering.js.map +0 -1
  111. package/dist/index.js.map +0 -1
  112. package/dist/util.js.map +0 -1
  113. package/esm/ComparativeRenderer/index.js.map +0 -1
  114. package/esm/DotplotDisplay/components/DotplotDisplay.js.map +0 -1
  115. package/esm/DotplotDisplay/index.js.map +0 -1
  116. package/esm/DotplotDisplay/renderDotplotBlock.js.map +0 -1
  117. package/esm/DotplotDisplay/stateModelFactory.js.map +0 -1
  118. package/esm/DotplotReadVsRef/DotplotReadVsRef.js.map +0 -1
  119. package/esm/DotplotReadVsRef/index.js.map +0 -1
  120. package/esm/DotplotRenderer/ComparativeRenderRpc.js.map +0 -1
  121. package/esm/DotplotRenderer/DotplotRenderer.js.map +0 -1
  122. package/esm/DotplotRenderer/components/DotplotRendering.js.map +0 -1
  123. package/esm/DotplotRenderer/configSchema.js.map +0 -1
  124. package/esm/DotplotRenderer/index.js.map +0 -1
  125. package/esm/DotplotView/1dview.js.map +0 -1
  126. package/esm/DotplotView/blockTypes.js.map +0 -1
  127. package/esm/DotplotView/components/Axes.js.map +0 -1
  128. package/esm/DotplotView/components/CursorIcon.js.map +0 -1
  129. package/esm/DotplotView/components/DotplotTooltip.js.map +0 -1
  130. package/esm/DotplotView/components/DotplotView.js.map +0 -1
  131. package/esm/DotplotView/components/DotplotWarnings.js.map +0 -1
  132. package/esm/DotplotView/components/ExportSvgDialog.js.map +0 -1
  133. package/esm/DotplotView/components/Grid.js.map +0 -1
  134. package/esm/DotplotView/components/Header.js.map +0 -1
  135. package/esm/DotplotView/components/ImportCustomTrack.js.map +0 -1
  136. package/esm/DotplotView/components/ImportForm.js.map +0 -1
  137. package/esm/DotplotView/components/ImportSyntenyTrackSelector.js.map +0 -1
  138. package/esm/DotplotView/components/PanButtons.js.map +0 -1
  139. package/esm/DotplotView/components/WarningDialog.js.map +0 -1
  140. package/esm/DotplotView/components/util.js.map +0 -1
  141. package/esm/DotplotView/index.js.map +0 -1
  142. package/esm/DotplotView/model.js.map +0 -1
  143. package/esm/DotplotView/svgcomponents/SVGBackground.js.map +0 -1
  144. package/esm/DotplotView/svgcomponents/SVGDotplotView.js.map +0 -1
  145. package/esm/LaunchDotplotView.js.map +0 -1
  146. package/esm/ServerSideRenderedBlockContent.js.map +0 -1
  147. package/esm/ServerSideSyntenyRendering.js.map +0 -1
  148. package/esm/index.js.map +0 -1
  149. package/esm/util.js.map +0 -1
  150. package/src/ComparativeRenderer/index.ts +0 -87
  151. package/src/DotplotDisplay/components/DotplotDisplay.tsx +0 -34
  152. package/src/DotplotDisplay/index.ts +0 -48
  153. package/src/DotplotDisplay/renderDotplotBlock.ts +0 -60
  154. package/src/DotplotDisplay/stateModelFactory.tsx +0 -196
  155. package/src/DotplotReadVsRef/DotplotReadVsRef.ts +0 -115
  156. package/src/DotplotReadVsRef/index.ts +0 -50
  157. package/src/DotplotRenderer/ComparativeRenderRpc.ts +0 -87
  158. package/src/DotplotRenderer/DotplotRenderer.ts +0 -328
  159. package/src/DotplotRenderer/__image_snapshots__/linear-synteny-renderer-test-ts-test-rendering-a-simple-synteny-from-fake-data-1-snap.png +0 -0
  160. package/src/DotplotRenderer/components/DotplotRendering.tsx +0 -12
  161. package/src/DotplotRenderer/configSchema.ts +0 -92
  162. package/src/DotplotRenderer/index.ts +0 -16
  163. package/src/DotplotView/1dview.ts +0 -98
  164. package/src/DotplotView/blockTypes.ts +0 -140
  165. package/src/DotplotView/components/Axes.tsx +0 -246
  166. package/src/DotplotView/components/CursorIcon.tsx +0 -24
  167. package/src/DotplotView/components/DotplotTooltip.tsx +0 -163
  168. package/src/DotplotView/components/DotplotView.tsx +0 -348
  169. package/src/DotplotView/components/DotplotWarnings.tsx +0 -26
  170. package/src/DotplotView/components/ExportSvgDialog.tsx +0 -129
  171. package/src/DotplotView/components/Grid.tsx +0 -112
  172. package/src/DotplotView/components/Header.tsx +0 -182
  173. package/src/DotplotView/components/ImportCustomTrack.tsx +0 -262
  174. package/src/DotplotView/components/ImportForm.tsx +0 -209
  175. package/src/DotplotView/components/ImportSyntenyTrackSelector.tsx +0 -90
  176. package/src/DotplotView/components/PanButtons.tsx +0 -93
  177. package/src/DotplotView/components/WarningDialog.tsx +0 -74
  178. package/src/DotplotView/components/util.ts +0 -118
  179. package/src/DotplotView/index.ts +0 -16
  180. package/src/DotplotView/model.test.ts +0 -17
  181. package/src/DotplotView/model.ts +0 -719
  182. package/src/DotplotView/svgcomponents/SVGBackground.tsx +0 -21
  183. package/src/DotplotView/svgcomponents/SVGDotplotView.tsx +0 -68
  184. package/src/LaunchDotplotView.ts +0 -63
  185. package/src/ServerSideRenderedBlockContent.tsx +0 -86
  186. package/src/ServerSideSyntenyRendering.tsx +0 -54
  187. package/src/index.ts +0 -41
  188. package/src/util.ts +0 -14
@@ -1,719 +0,0 @@
1
- import React, { lazy } from 'react'
2
- import {
3
- addDisposer,
4
- cast,
5
- getParent,
6
- getRoot,
7
- getSnapshot,
8
- resolveIdentifier,
9
- types,
10
- Instance,
11
- SnapshotIn,
12
- } from 'mobx-state-tree'
13
- import { saveAs } from 'file-saver'
14
- import { autorun, transaction } from 'mobx'
15
-
16
- import { getParentRenderProps } from '@jbrowse/core/util/tracks'
17
- import { BaseTrackStateModel } from '@jbrowse/core/pluggableElementTypes/models'
18
- import BaseViewModel from '@jbrowse/core/pluggableElementTypes/models/BaseViewModel'
19
- import { Base1DViewModel } from '@jbrowse/core/util/Base1DViewModel'
20
- import {
21
- getSession,
22
- isSessionModelWithWidgets,
23
- minmax,
24
- measureText,
25
- max,
26
- localStorageGetItem,
27
- } from '@jbrowse/core/util'
28
- import { getConf, AnyConfigurationModel } from '@jbrowse/core/configuration'
29
- import PluginManager from '@jbrowse/core/PluginManager'
30
- import { ElementId } from '@jbrowse/core/util/types/mst'
31
-
32
- // icons
33
- import { TrackSelector as TrackSelectorIcon } from '@jbrowse/core/ui/Icons'
34
- import FolderOpenIcon from '@mui/icons-material/FolderOpen'
35
- import PhotoCameraIcon from '@mui/icons-material/PhotoCamera'
36
-
37
- // locals
38
- import { Dotplot1DView, DotplotHView, DotplotVView } from './1dview'
39
- import { getBlockLabelKeysToHide, makeTicks } from './components/util'
40
-
41
- // lazies
42
- const ExportSvgDialog = lazy(() => import('./components/ExportSvgDialog'))
43
- const ReturnToImportFormDialog = lazy(
44
- () => import('@jbrowse/core/ui/ReturnToImportFormDialog'),
45
- )
46
- type Coord = [number, number]
47
-
48
- export interface ExportSvgOptions {
49
- rasterizeLayers?: boolean
50
- filename?: string
51
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
52
- Wrapper?: React.FC<any>
53
- themeName?: string
54
- }
55
-
56
- /**
57
- * #stateModel DotplotView
58
- * #category view
59
- * extends `BaseViewModel`
60
- */
61
- export default function stateModelFactory(pm: PluginManager) {
62
- return types
63
- .compose(
64
- BaseViewModel,
65
- types.model('DotplotView', {
66
- /**
67
- * #property
68
- */
69
- id: ElementId,
70
- /**
71
- * #property
72
- */
73
- type: types.literal('DotplotView'),
74
- /**
75
- * #property
76
- */
77
- height: 600,
78
- /**
79
- * #property
80
- */
81
- borderSize: 20,
82
- /**
83
- * #property
84
- */
85
- tickSize: 5,
86
- /**
87
- * #property
88
- */
89
- vtextRotation: 0,
90
- /**
91
- * #property
92
- */
93
- htextRotation: -90,
94
- /**
95
- * #property
96
- */
97
- fontSize: 15,
98
- /**
99
- * #property
100
- */
101
- trackSelectorType: 'hierarchical',
102
- /**
103
- * #property
104
- */
105
- assemblyNames: types.array(types.string),
106
- /**
107
- * #property
108
- */
109
- drawCigar: true,
110
- /**
111
- * #property
112
- */
113
- hview: types.optional(DotplotHView, {}),
114
- /**
115
- * #property
116
- */
117
- vview: types.optional(DotplotVView, {}),
118
-
119
- /**
120
- * #property
121
- */
122
- tracks: types.array(
123
- pm.pluggableMstType('track', 'stateModel') as BaseTrackStateModel,
124
- ),
125
-
126
- /**
127
- * #property
128
- * this represents tracks specific to this view specifically used
129
- * for read vs ref dotplots where this track would not really apply
130
- * elsewhere
131
- */
132
- viewTrackConfigs: types.array(pm.pluggableConfigSchemaType('track')),
133
- }),
134
- )
135
- .volatile(() => ({
136
- volatileWidth: undefined as number | undefined,
137
- volatileError: undefined as unknown,
138
-
139
- // these are 'personal preferences', stored in volatile and
140
- // loaded/written to localStorage
141
- cursorMode: localStorageGetItem('dotplot-cursorMode') || 'crosshair',
142
- showPanButtons: Boolean(
143
- JSON.parse(localStorageGetItem('dotplot-showPanbuttons') || 'true'),
144
- ),
145
- wheelMode: localStorageGetItem('dotplot-wheelMode') || 'zoom',
146
- borderX: 100,
147
- borderY: 100,
148
- }))
149
- .views(self => ({
150
- /**
151
- * #getter
152
- */
153
- get width(): number {
154
- if (!self.volatileWidth) {
155
- throw new Error('width not initialized')
156
- }
157
- return self.volatileWidth
158
- },
159
- }))
160
- .views(self => ({
161
- /**
162
- * #getter
163
- */
164
- get assemblyErrors() {
165
- const { assemblyManager } = getSession(self)
166
- return self.assemblyNames
167
- .map(a => assemblyManager.get(a)?.error)
168
- .filter(f => !!f)
169
- .join(', ')
170
- },
171
- /**
172
- * #getter
173
- */
174
- get assembliesInitialized() {
175
- const { assemblyManager } = getSession(self)
176
- return self.assemblyNames.every(
177
- n => assemblyManager.get(n)?.initialized ?? true,
178
- )
179
- },
180
- }))
181
- .views(self => ({
182
- /**
183
- * #getter
184
- */
185
- get initialized() {
186
- return (
187
- self.volatileWidth !== undefined &&
188
- self.hview.displayedRegions.length > 0 &&
189
- self.vview.displayedRegions.length > 0 &&
190
- self.assembliesInitialized
191
- )
192
- },
193
- /**
194
- * #getter
195
- */
196
- get hticks() {
197
- const { hview } = self
198
- const { dynamicBlocks, staticBlocks, bpPerPx } = hview
199
- return dynamicBlocks.contentBlocks.length > 5
200
- ? []
201
- : makeTicks(staticBlocks.contentBlocks, bpPerPx)
202
- },
203
- /**
204
- * #getter
205
- */
206
- get vticks() {
207
- const { vview } = self
208
- const { dynamicBlocks, staticBlocks, bpPerPx } = vview
209
- return dynamicBlocks.contentBlocks.length > 5
210
- ? []
211
- : makeTicks(staticBlocks.contentBlocks, bpPerPx)
212
- },
213
- /**
214
- * #getter
215
- */
216
- get loading() {
217
- return self.assemblyNames.length > 0 && !this.initialized
218
- },
219
- /**
220
- * #getter
221
- */
222
- get viewWidth() {
223
- return self.width - self.borderX
224
- },
225
- /**
226
- * #getter
227
- */
228
- get viewHeight() {
229
- return self.height - self.borderY
230
- },
231
- /**
232
- * #getter
233
- */
234
- get views() {
235
- return [self.hview, self.vview]
236
- },
237
-
238
- /**
239
- * #method
240
- */
241
- renderProps() {
242
- const session = getSession(self)
243
- return {
244
- ...getParentRenderProps(self),
245
- drawCigar: self.drawCigar,
246
- highResolutionScaling: getConf(session, 'highResolutionScaling'),
247
- }
248
- },
249
- }))
250
- .actions(self => ({
251
- /**
252
- * #action
253
- */
254
- setShowPanButtons(flag: boolean) {
255
- self.showPanButtons = flag
256
- },
257
- /**
258
- * #action
259
- */
260
- setWheelMode(str: string) {
261
- self.wheelMode = str
262
- },
263
- /**
264
- * #action
265
- */
266
- setCursorMode(str: string) {
267
- self.cursorMode = str
268
- },
269
- /**
270
- * #action
271
- */
272
- setDrawCigar(flag: boolean) {
273
- self.drawCigar = flag
274
- },
275
- /**
276
- * #action
277
- * returns to the import form
278
- */
279
- clearView() {
280
- self.hview.setDisplayedRegions([])
281
- self.vview.setDisplayedRegions([])
282
- self.assemblyNames = cast([])
283
- self.tracks.clear()
284
- },
285
- /**
286
- * #action
287
- */
288
- setBorderX(n: number) {
289
- self.borderX = n
290
- },
291
- /**
292
- * #action
293
- */
294
- setBorderY(n: number) {
295
- self.borderY = n
296
- },
297
- /**
298
- * #action
299
- */
300
- setWidth(newWidth: number) {
301
- self.volatileWidth = newWidth
302
- return self.volatileWidth
303
- },
304
- /**
305
- * #action
306
- */
307
- setHeight(newHeight: number) {
308
- self.height = newHeight
309
- return self.height
310
- },
311
-
312
- /**
313
- * #action
314
- */
315
- setError(e: unknown) {
316
- self.volatileError = e
317
- },
318
-
319
- /**
320
- * #action
321
- * removes the view itself from the state tree entirely by calling the
322
- * parent removeView
323
- */
324
- closeView() {
325
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
326
- getParent<any>(self, 2).removeView(self)
327
- },
328
-
329
- /**
330
- * #action
331
- */
332
- zoomOutButton() {
333
- self.hview.zoomOut()
334
- self.vview.zoomOut()
335
- },
336
- /**
337
- * #action
338
- */
339
- zoomInButton() {
340
- self.hview.zoomIn()
341
- self.vview.zoomIn()
342
- },
343
- /**
344
- * #action
345
- */
346
- activateTrackSelector() {
347
- if (self.trackSelectorType === 'hierarchical') {
348
- const session = getSession(self)
349
- if (isSessionModelWithWidgets(session)) {
350
- const selector = session.addWidget(
351
- 'HierarchicalTrackSelectorWidget',
352
- 'hierarchicalTrackSelector',
353
- { view: self },
354
- )
355
- session.showWidget(selector)
356
- return selector
357
- }
358
- }
359
- throw new Error(`invalid track selector type ${self.trackSelectorType}`)
360
- },
361
-
362
- /**
363
- * #action
364
- */
365
- showTrack(trackId: string, initialSnapshot = {}) {
366
- const schema = pm.pluggableConfigSchemaType('track')
367
- const conf = resolveIdentifier(schema, getRoot(self), trackId)
368
- const trackType = pm.getTrackType(conf.type)
369
- if (!trackType) {
370
- throw new Error(`unknown track type ${conf.type}`)
371
- }
372
- const viewType = pm.getViewType(self.type)
373
- const displayConf = conf.displays.find((d: AnyConfigurationModel) =>
374
- viewType.displayTypes.find(type => type.name === d.type),
375
- )
376
- if (!displayConf) {
377
- throw new Error(
378
- `could not find a compatible display for view type ${self.type}`,
379
- )
380
- }
381
- const track = trackType.stateModel.create({
382
- ...initialSnapshot,
383
- type: conf.type,
384
- configuration: conf,
385
- displays: [{ type: displayConf.type, configuration: displayConf }],
386
- })
387
- self.tracks.push(track)
388
- },
389
-
390
- /**
391
- * #action
392
- */
393
- hideTrack(trackId: string) {
394
- const schema = pm.pluggableConfigSchemaType('track')
395
- const conf = resolveIdentifier(schema, getRoot(self), trackId)
396
- const t = self.tracks.filter(t => t.configuration === conf)
397
- transaction(() => t.forEach(t => self.tracks.remove(t)))
398
- return t.length
399
- },
400
- /**
401
- * #action
402
- */
403
- toggleTrack(trackId: string) {
404
- const hiddenCount = this.hideTrack(trackId)
405
- if (!hiddenCount) {
406
- this.showTrack(trackId)
407
- }
408
- },
409
- /**
410
- * #action
411
- */
412
- setAssemblyNames(target: string, query: string) {
413
- self.assemblyNames = cast([target, query])
414
- },
415
- /**
416
- * #action
417
- */
418
- setViews(arr: SnapshotIn<Base1DViewModel>[]) {
419
- self.hview = cast(arr[0])
420
- self.vview = cast(arr[1])
421
- },
422
-
423
- /**
424
- * #action
425
- */
426
- getCoords(mousedown: Coord, mouseup: Coord) {
427
- const [xmin, xmax] = minmax(mouseup[0], mousedown[0])
428
- const [ymin, ymax] = minmax(mouseup[1], mousedown[1])
429
- return Math.abs(xmax - xmin) > 3 && Math.abs(ymax - ymin) > 3
430
- ? [
431
- self.hview.pxToBp(xmin),
432
- self.hview.pxToBp(xmax),
433
- self.vview.pxToBp(self.viewHeight - ymin),
434
- self.vview.pxToBp(self.viewHeight - ymax),
435
- ]
436
- : undefined
437
- },
438
-
439
- /**
440
- * #action
441
- * zooms into clicked and dragged region
442
- */
443
- zoomIn(mousedown: Coord, mouseup: Coord) {
444
- const result = this.getCoords(mousedown, mouseup)
445
- if (result) {
446
- const [x1, x2, y1, y2] = result
447
- self.hview.moveTo(x1, x2)
448
- self.vview.moveTo(y2, y1)
449
- }
450
- },
451
- /**
452
- * #action
453
- */
454
- showAllRegions() {
455
- self.hview.zoomTo(self.hview.maxBpPerPx)
456
- self.vview.zoomTo(self.vview.maxBpPerPx)
457
- self.vview.center()
458
- self.hview.center()
459
- },
460
- /**
461
- * #action
462
- * creates a linear synteny view from the clicked and dragged region
463
- */
464
- onDotplotView(mousedown: Coord, mouseup: Coord) {
465
- const result = this.getCoords(mousedown, mouseup)
466
- if (result) {
467
- const [x1, x2, y1, y2] = result
468
- const session = getSession(self)
469
-
470
- const d1 = Dotplot1DView.create({
471
- ...getSnapshot(self.hview),
472
- minimumBlockWidth: 0,
473
- interRegionPaddingWidth: 0,
474
- })
475
- const d2 = Dotplot1DView.create({
476
- ...getSnapshot(self.vview),
477
- minimumBlockWidth: 0,
478
- interRegionPaddingWidth: 0,
479
- })
480
- d1.setVolatileWidth(self.hview.width)
481
- d2.setVolatileWidth(self.vview.width)
482
- d1.moveTo(x1, x2)
483
- d2.moveTo(y2, y1)
484
- d1.zoomTo(d1.bpPerPx / (self.width / self.hview.width), 0)
485
- d2.zoomTo(d2.bpPerPx / (self.width / self.vview.width), 0)
486
-
487
- // add the specific evidence tracks to the LGVs in the split view
488
- // note: scales the bpPerPx by scaling proportional of the dotplot
489
- // width to the eventual lgv width
490
- const tracks = self.tracks
491
- .map(track =>
492
- track.configuration.displays.find(
493
- (display: { type: string }) =>
494
- display.type === 'LinearSyntenyDisplay',
495
- ),
496
- )
497
- .filter(f => !!f)
498
- .map(displayConf => {
499
- const trackConf = getParent<AnyConfigurationModel>(displayConf, 2)
500
- return {
501
- type: trackConf.type,
502
- configuration: trackConf,
503
- displays: [
504
- { type: displayConf.type, configuration: displayConf },
505
- ],
506
- }
507
- })
508
-
509
- const { id: _unused1, ...rest1 } = getSnapshot(d1)
510
- const { id: _unused2, ...rest2 } = getSnapshot(d2)
511
- const viewSnapshot = {
512
- type: 'LinearSyntenyView',
513
- views: [
514
- {
515
- type: 'LinearGenomeView',
516
- tracks: [],
517
- hideHeader: true,
518
- ...rest1,
519
- },
520
- {
521
- type: 'LinearGenomeView',
522
- tracks: [],
523
- hideHeader: true,
524
- ...rest2,
525
- },
526
- ],
527
- tracks,
528
- }
529
-
530
- session.addView('LinearSyntenyView', viewSnapshot)
531
- }
532
- },
533
- }))
534
- .actions(self => ({
535
- /**
536
- * #action
537
- * creates an svg export and save using FileSaver
538
- */
539
- async exportSvg(opts: ExportSvgOptions = {}) {
540
- const { renderToSvg } = await import('./svgcomponents/SVGDotplotView')
541
- const html = await renderToSvg(self as DotplotViewModel, opts)
542
- const blob = new Blob([html], { type: 'image/svg+xml' })
543
- saveAs(blob, opts.filename || 'image.svg')
544
- },
545
- // if any of our assemblies are temporary assemblies
546
- beforeDestroy() {
547
- const session = getSession(self)
548
- self.assemblyNames.forEach(asm => session.removeTemporaryAssembly(asm))
549
- },
550
- afterAttach() {
551
- addDisposer(
552
- self,
553
- autorun(() => {
554
- const s = (s: unknown) => JSON.stringify(s)
555
- const { showPanButtons, wheelMode, cursorMode } = self
556
- if (typeof localStorage !== 'undefined') {
557
- localStorage.setItem('dotplot-showPanbuttons', s(showPanButtons))
558
- localStorage.setItem('dotplot-cursorMode', cursorMode)
559
- localStorage.setItem('dotplot-wheelMode', wheelMode)
560
- }
561
- }),
562
- )
563
- addDisposer(
564
- self,
565
- autorun(
566
- () => {
567
- const session = getSession(self)
568
-
569
- // don't operate if width not set yet
570
- if (
571
- self.volatileWidth === undefined ||
572
- !self.assembliesInitialized
573
- ) {
574
- return
575
- }
576
-
577
- // also don't operate if displayedRegions already set, this is a
578
- // helper autorun to load regions from assembly
579
- if (
580
- self.hview.displayedRegions.length > 0 &&
581
- self.vview.displayedRegions.length > 0
582
- ) {
583
- return
584
- }
585
-
586
- const views = [self.hview, self.vview]
587
- transaction(() => {
588
- self.assemblyNames.forEach((name, index) => {
589
- const assembly = session.assemblyManager.get(name)
590
- const view = views[index]
591
- view.setDisplayedRegions(assembly?.regions || [])
592
- })
593
- self.showAllRegions()
594
- })
595
- },
596
- { delay: 1000 },
597
- ),
598
- )
599
- addDisposer(
600
- self,
601
- autorun(function borderSetter() {
602
- // make sure we have a width on the view before trying to load
603
- if (self.volatileWidth === undefined) {
604
- return
605
- }
606
- const { vview, hview, viewHeight, viewWidth } = self
607
- const padding = 40
608
- const vblocks = vview.dynamicBlocks.contentBlocks
609
- const hblocks = hview.dynamicBlocks.contentBlocks
610
- const hoffset = hview.offsetPx
611
- const voffset = vview.offsetPx
612
-
613
- const vhide = getBlockLabelKeysToHide(vblocks, viewHeight, voffset)
614
- const hhide = getBlockLabelKeysToHide(hblocks, viewWidth, hoffset)
615
-
616
- const len = (a: string) => measureText(a.slice(0, 30))
617
- const by = max(
618
- hblocks.filter(b => !hhide.has(b.key)).map(b => len(b.refName)),
619
- )
620
- const bx = max(
621
- vblocks.filter(b => !vhide.has(b.key)).map(b => len(b.refName)),
622
- )
623
- // these are set via autorun to avoid dependency cycle
624
- self.setBorderY(Math.max(by + padding, 50))
625
- self.setBorderX(Math.max(bx + padding, 50))
626
- }),
627
- )
628
- },
629
- /**
630
- * #action
631
- */
632
- squareView() {
633
- const { hview, vview } = self
634
- const avg = (hview.bpPerPx + vview.bpPerPx) / 2
635
- const hpx = hview.pxToBp(hview.width / 2)
636
- const vpx = vview.pxToBp(vview.width / 2)
637
- hview.setBpPerPx(avg)
638
- hview.centerAt(hpx.coord, hpx.refName, hpx.index)
639
- vview.setBpPerPx(avg)
640
- vview.centerAt(vpx.coord, vpx.refName, vpx.index)
641
- },
642
- /**
643
- * #action
644
- */
645
- squareViewProportional() {
646
- const { hview, vview } = self
647
- const ratio = hview.width / vview.width
648
- const avg = (hview.bpPerPx + vview.bpPerPx) / 2
649
- const hpx = hview.pxToBp(hview.width / 2)
650
- const vpx = vview.pxToBp(vview.width / 2)
651
- hview.setBpPerPx(avg / ratio)
652
- hview.centerAt(hpx.coord, hpx.refName, hpx.index)
653
- vview.setBpPerPx(avg)
654
- vview.centerAt(vpx.coord, vpx.refName, vpx.index)
655
- },
656
- }))
657
- .views(self => ({
658
- /**
659
- * #method
660
- */
661
- menuItems() {
662
- const session = getSession(self)
663
- return [
664
- {
665
- label: 'Return to import form',
666
- onClick: () => {
667
- getSession(self).queueDialog(handleClose => [
668
- ReturnToImportFormDialog,
669
- { model: self, handleClose },
670
- ])
671
- },
672
- icon: FolderOpenIcon,
673
- },
674
- {
675
- label: 'Square view - same bp per pixel',
676
- onClick: () => self.squareView(),
677
- },
678
- {
679
- label: 'Rectangular view - same total bp',
680
- onClick: () => self.squareView(),
681
- },
682
- {
683
- label: 'Show all regions',
684
- onClick: () => self.showAllRegions(),
685
- },
686
- {
687
- label: 'Export SVG',
688
- icon: PhotoCameraIcon,
689
- onClick: () => {
690
- getSession(self).queueDialog(handleClose => [
691
- ExportSvgDialog,
692
- { model: self, handleClose },
693
- ])
694
- },
695
- },
696
- ...(isSessionModelWithWidgets(session)
697
- ? [
698
- {
699
- label: 'Open track selector',
700
- onClick: self.activateTrackSelector,
701
- icon: TrackSelectorIcon,
702
- },
703
- ]
704
- : []),
705
- ]
706
- },
707
- /**
708
- * #getter
709
- */
710
- get error() {
711
- return self.volatileError || self.assemblyErrors
712
- },
713
- }))
714
- }
715
-
716
- export type DotplotViewStateModel = ReturnType<typeof stateModelFactory>
717
- export type DotplotViewModel = Instance<DotplotViewStateModel>
718
-
719
- export { type Dotplot1DViewModel, Dotplot1DView } from './1dview'