jbrowse-plugin-graphgenomeviewer 4.7.0 → 5.0.0

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 (65) hide show
  1. package/README.md +7 -1
  2. package/dist/chunks/ChooseWalksDialog-GVQLSGHX.js +2 -0
  3. package/dist/chunks/ChooseWalksDialog-GVQLSGHX.js.map +7 -0
  4. package/dist/chunks/GbzBaseSyntenyAdapter-CKKVHC2R.js +4 -0
  5. package/dist/chunks/GbzBaseSyntenyAdapter-CKKVHC2R.js.map +7 -0
  6. package/dist/chunks/{GraphGenomeView-HZ2EQUOC.js → GraphGenomeView-YYP4IFSI.js} +2 -2
  7. package/dist/chunks/{GraphTrackSettingsDialog-JVPM25GV.js → GraphTrackSettingsDialog-2WPJRAJC.js} +2 -2
  8. package/dist/chunks/LinearGraphDisplay-7YE624D5.js +2 -0
  9. package/dist/chunks/LinearGraphDisplay-7YE624D5.js.map +7 -0
  10. package/dist/chunks/chunk-2H7GDQ3R.js +6 -0
  11. package/dist/chunks/chunk-2H7GDQ3R.js.map +7 -0
  12. package/dist/chunks/chunk-BZOIENU5.js +2 -0
  13. package/dist/chunks/chunk-BZOIENU5.js.map +7 -0
  14. package/dist/chunks/{chunk-UTWFU4X6.js → chunk-H54W6OQQ.js} +2 -2
  15. package/dist/chunks/{chunk-UTWFU4X6.js.map → chunk-H54W6OQQ.js.map} +4 -4
  16. package/dist/chunks/{chunk-F2EPKNTV.js → chunk-O4XV3K35.js} +2 -2
  17. package/dist/chunks/{chunk-F2EPKNTV.js.map → chunk-O4XV3K35.js.map} +4 -4
  18. package/dist/chunks/chunk-SJNG2XK7.js +2 -0
  19. package/dist/chunks/chunk-SJNG2XK7.js.map +7 -0
  20. package/dist/chunks/chunk-WKVVIDCS.js +3 -0
  21. package/dist/chunks/{chunk-KCL5TF5X.js.map → chunk-WKVVIDCS.js.map} +3 -3
  22. package/dist/jbrowse-plugin-graphgenomeviewer.esm.js +5 -5
  23. package/dist/jbrowse-plugin-graphgenomeviewer.esm.js.map +4 -4
  24. package/package.json +3 -3
  25. package/src/GbzBaseSyntenyAdapter/GbzBaseSyntenyAdapter.test.ts +36 -2
  26. package/src/GbzBaseSyntenyAdapter/GbzBaseSyntenyAdapter.ts +67 -1
  27. package/src/GbzBaseSyntenyAdapter/test_data/fragmented.haplotype-index.db +0 -0
  28. package/src/GbzBaseSyntenyAdapter/test_data/micb-kir3dl1.haplotype-index.db +0 -0
  29. package/src/GbzBaseSyntenyAdapter/test_data/micb-kir3dl1.sampled.haplotype-index.db +0 -0
  30. package/src/GetHaplotypeOverview.ts +77 -0
  31. package/src/GraphGenomeView/components/ChooseWalksDialog.tsx +86 -0
  32. package/src/GraphGenomeView/components/GraphSettingsDialog.tsx +205 -187
  33. package/src/GraphGenomeView/components/TubeMapLegend.test.tsx +29 -0
  34. package/src/GraphGenomeView/components/TubeMapOverlay.tsx +8 -0
  35. package/src/GraphGenomeView/host.ts +6 -0
  36. package/src/GraphGenomeView/model.ts +10 -4224
  37. package/src/GraphGenomeView/pane/fitViews.ts +589 -0
  38. package/src/GraphGenomeView/pane/graphViews.ts +829 -0
  39. package/src/GraphGenomeView/pane/hostViews.ts +193 -0
  40. package/src/GraphGenomeView/pane/launchActions.ts +407 -0
  41. package/src/GraphGenomeView/pane/launchViews.ts +191 -0
  42. package/src/GraphGenomeView/pane/loadActions.ts +701 -0
  43. package/src/GraphGenomeView/pane/paneBase.ts +479 -0
  44. package/src/GraphGenomeView/pane/renderingActions.ts +281 -0
  45. package/src/GraphGenomeView/pane/settingActions.ts +467 -0
  46. package/src/GraphGenomeView/pane/walkRowViews.ts +205 -0
  47. package/src/HaplotypeOverview/HaplotypeOverviewCanvas.tsx +203 -0
  48. package/src/HaplotypeOverview/draw.test.ts +136 -0
  49. package/src/HaplotypeOverview/draw.ts +433 -0
  50. package/src/HaplotypeOverview/model.ts +163 -0
  51. package/src/LinearGraphDisplay/LinearGraphDisplay.test.ts +184 -0
  52. package/src/LinearGraphDisplay/components/LinearGraphDisplay.tsx +12 -2
  53. package/src/LinearGraphDisplay/model.ts +107 -3
  54. package/src/gaf/gafFile.ts +2 -0
  55. package/src/index.ts +2 -0
  56. package/src/version.ts +1 -1
  57. package/dist/chunks/GbzBaseSyntenyAdapter-AZBYMDIW.js +0 -8
  58. package/dist/chunks/GbzBaseSyntenyAdapter-AZBYMDIW.js.map +0 -7
  59. package/dist/chunks/LinearGraphDisplay-MJ4ZBJRX.js +0 -2
  60. package/dist/chunks/LinearGraphDisplay-MJ4ZBJRX.js.map +0 -7
  61. package/dist/chunks/chunk-BUXVOMDL.js +0 -2
  62. package/dist/chunks/chunk-BUXVOMDL.js.map +0 -7
  63. package/dist/chunks/chunk-KCL5TF5X.js +0 -3
  64. /package/dist/chunks/{GraphGenomeView-HZ2EQUOC.js.map → GraphGenomeView-YYP4IFSI.js.map} +0 -0
  65. /package/dist/chunks/{GraphTrackSettingsDialog-JVPM25GV.js.map → GraphTrackSettingsDialog-2WPJRAJC.js.map} +0 -0
@@ -0,0 +1,479 @@
1
+ import { lazy } from 'react'
2
+
3
+ import { BUBBLE_SPREAD_VALUES } from '@jbrowse/bandage-core/bubbleSpreads'
4
+ import { COLOR_SCHEME_VALUES } from '@jbrowse/bandage-core/colorSchemes'
5
+ import { facetSettingOf } from '@jbrowse/bandage-core/facetGrid'
6
+ import { LAYOUT_MODE_VALUES } from '@jbrowse/bandage-core/layoutModes'
7
+ import { NODE_WIDTH_VALUES } from '@jbrowse/bandage-core/nodeWidths'
8
+ import { viewportOf } from '@jbrowse/bandage-core/viewport'
9
+ import { types } from '@jbrowse/mobx-state-tree'
10
+ import { RenderLifecycleMixin } from '@jbrowse/render-core/RenderLifecycleMixin'
11
+
12
+ import { lenientMaybeEnum, lenientOptionalEnum } from '../lenientEnum'
13
+
14
+ import type { SubgraphRegion } from '../../GetSubgraph'
15
+ import type { RepeatArray } from '../repeats/repeatFeatures'
16
+ import type { MinigraphBubble } from '@jbrowse/bandage-core/bubbles/bubbleLine'
17
+ import type { FacetInput, FacetSetting } from '@jbrowse/bandage-core/facetGrid'
18
+ import type { GeneModel } from '@jbrowse/bandage-core/genes/genePins'
19
+ import type { LayoutModeValue } from '@jbrowse/bandage-core/layoutModes'
20
+ import type { Bounds } from '@jbrowse/bandage-core/pipeline'
21
+ import type { RenderBatch } from '@jbrowse/bandage-core/renderer/types'
22
+ import type { Graph, LayoutResult } from '@jbrowse/bandage-core/types'
23
+ import type { AxisScale } from '@jbrowse/bandage-core/util/geometry'
24
+ import type { WalkLayer } from '@jbrowse/bandage-core/walkEncoding'
25
+ import type { FileLocation } from '@jbrowse/core/util/types'
26
+
27
+ // Ceiling on the pane, and what it falls back to before there is a layout to
28
+ // size against. A roughly square drawing (FMMM) hits this and keeps the
29
+ // scrollable pane it has always had.
30
+ export const MAX_CANVAS_HEIGHT = 600
31
+ // Floor, so a window holding only backbone — one row, no height at all — still
32
+ // leaves room to hover a node and read its tooltip.
33
+ export const MIN_CANVAS_HEIGHT = 160
34
+ // the pane's background, as the renderer clears to it and as CSS
35
+ export const PAPER_LIGHT: [number, number, number, number] = [1, 1, 1, 1]
36
+ export const PAPER_DARK: [number, number, number, number] = [
37
+ 0.12, 0.12, 0.12, 1,
38
+ ]
39
+ export const paperCss = ([r, g, b]: number[]) =>
40
+ `rgb(${[r, g, b].map(v => Math.round(v! * 255)).join(', ')})`
41
+ // The thinnest a fit draws a tube map's tubes
42
+ export const MIN_FIT_TUBE_PX = 5
43
+
44
+ export const TUBE_MAP_MODES = new Set<string>(['tubemap', 'tubemapref'])
45
+
46
+ export const ChooseWalksDialog = lazy(
47
+ () => import('../components/ChooseWalksDialog'),
48
+ )
49
+
50
+ // Past this many walks the Walk menu lists only the lifted ones and offers a
51
+ // searchable picker
52
+ export const WALK_MENU_ITEMS = 12
53
+
54
+ export const FACETS: { value: FacetSetting['field']; label: string }[] = [
55
+ { value: '', label: 'Off' },
56
+ { value: 'walk', label: 'A panel per walk' },
57
+ { value: 'sample', label: 'A row per sample, a column per haplotype' },
58
+ ]
59
+
60
+ // The facet as a session writes it, in the shape every JBrowse display's
61
+ // `facet` takes: a bare field, or the field with the panels' order and how
62
+ // many go across. A field this pane cannot split on reads as none.
63
+ const facetModel = types.snapshotProcessor(
64
+ types.model('GraphFacet', {
65
+ field: types.optional(types.enumeration(['', 'walk', 'sample']), ''),
66
+ domain: types.optional(types.frozen<string[]>(), []),
67
+ columns: types.maybe(types.number),
68
+ }),
69
+ {
70
+ preProcessor: (snap: FacetInput | undefined) => facetSettingOf(snap),
71
+ },
72
+ )
73
+
74
+ // The sizes a tube map folds variants under. MICB's 22 kb cut draws 475
75
+ // columns whole, 34 under 3 bp and one under 50, where only its structural
76
+ // variants would stand: human windows are mostly SNPs.
77
+ export const TUBE_MAP_FOLDS = [
78
+ { bp: 0, label: 'None' },
79
+ { bp: 3, label: 'Under 3 bp' },
80
+ { bp: 10, label: 'Under 10 bp' },
81
+ { bp: 50, label: 'Under 50 bp, leaving structural variants' },
82
+ { bp: 1000, label: 'Under 1 kb' },
83
+ ]
84
+
85
+ const SEGMENTS_SUFFIX = '.segs.bed.gz'
86
+
87
+ // The rGFA index prefix an adapter config names, from either spelling the
88
+ // config schema accepts: the `uri` shorthand or an explicit segments location.
89
+ export function bubblePrefix(adapterConfig: Record<string, unknown>) {
90
+ if (typeof adapterConfig.uri === 'string') {
91
+ return adapterConfig.uri
92
+ }
93
+ const segments = adapterConfig.segmentsLocation as
94
+ { uri?: string } | undefined
95
+ const uri = segments?.uri
96
+ return typeof uri === 'string' && uri.endsWith(SEGMENTS_SUFFIX)
97
+ ? uri.slice(0, -SEGMENTS_SUFFIX.length)
98
+ : undefined
99
+ }
100
+ export const HOVER_BRIGHTEN = 1.4
101
+ export const SELECT_BRIGHTEN = 1.6
102
+ export const VIEWPORT_DEBOUNCE_MS = 150
103
+ export const VIEWPORT_PANES_BUILT = 1
104
+ // How many walk rows read their haplotype's genes, the first rows down
105
+ export const WALK_GENE_ROWS = 40
106
+
107
+ // What the canvas draws under the tube map, whose ink is all TubeMapOverlay's
108
+ export const EMPTY_BATCH: RenderBatch = {
109
+ nodeStrokes: [],
110
+ nodeStrokeRuns: new Map(),
111
+ arrows: [],
112
+ arrowRuns: new Map(),
113
+ edgeCurves: [],
114
+ edgeCurveRuns: new Map(),
115
+ }
116
+
117
+ // MobX tracks every observable read while a computed or autorun runs, so
118
+ // passing values here registers them as dependencies without otherwise using
119
+ // them.
120
+ export function dependOn(..._values: unknown[]) {}
121
+
122
+ // Hard size cap for the single-mode graph view. Past it the view declines with a
123
+ // "zoom in" message rather than switching to a degraded rendering mode — one mode
124
+ // only, since the large-region case is a linear synteny view, not a graph.
125
+ // (The `adr-027` citation this used to carry was stale: that number was reused
126
+ // for wheel-input semantics after the large-mode ADR was removed in 9d8102f0b5.)
127
+ //
128
+ // This bounds the *fetch*, and it is the only cap that can be applied before one
129
+ // happens. It is a poor proxy for cost, because cost tracks node count, so the
130
+ // number is chosen against the density of the graphs it can actually guard: a
131
+ // region is fetched through `getSubgraph`, and the rGFA cut is what this number
132
+ // was chosen against (the GBZ cut is base-level and has its own `nodeLimit`,
133
+ // which trips long before 5 Mb). Both measured rGFAs are sparse, and at 5 Mb
134
+ // both land at or under the ~2k nodes that redraw in under 10 ms (see agent-docs/GRAPH_SCALE_AND_LOD.md):
135
+ //
136
+ // HPRC MC GRCh38 ~7,000 bp/segment whole 4.9 Mb MHC 1,173 nodes
137
+ // ecoli minigraph 3,078 bp/segment whole 4.6 Mb genome 2,415 nodes
138
+ //
139
+ // Fetch cost does not scale with the window either: against the hosted HPRC
140
+ // index a 4.9 Mb links query and a 100 kb one both cost ~1.3 s, being dominated
141
+ // by HTTP setup. FMMM is the slowest consumer at this size and stays tolerable,
142
+ // ~0.1-3 s for ~1k nodes depending on layout quality (bandage-layout-js), and it
143
+ // runs off the main thread.
144
+ //
145
+ // A dense graph is what this cannot protect against, because bp per node varies
146
+ // by orders of magnitude between graph types — a base-level pggb graph runs ~17
147
+ // bp/node, where 5 Mb would be hundreds of thousands. Such a graph has no region
148
+ // query to reach this check with today, and the node budget below is the cap that
149
+ // catches it if one ever does.
150
+ export const MAX_GRAPH_REGION_BP = 5_000_000
151
+
152
+ // The cap in a message, in the unit that reads: `5 Mb`, not `5000 kb`.
153
+ export function formatSpanBp(bp: number) {
154
+ return bp >= 1_000_000
155
+ ? `${+(bp / 1_000_000).toFixed(1)} Mb`
156
+ : `${Math.round(bp / 1000)} kb`
157
+ }
158
+
159
+ // What the view will actually draw, checked once the graph is parsed and so
160
+ // applying to a whole-file import as much as to a subgraph fetch. Measured on
161
+ // bubble-chain graphs: ~1-2k nodes redraws in under 10 ms, 10k takes ~43 ms of
162
+ // geometry and ~125k canvas draw calls per frame (single-digit fps while
163
+ // panning), and 100k needs 632 ms and 75 MB of vertex buffers. So this is set
164
+ // where the tab stops being usable rather than where it stops being smooth, and
165
+ // it is a view prop rather than a constant so a session can raise it — the same
166
+ // escape hatch strangepg gives with `-T N`.
167
+ export const DEFAULT_MAX_GRAPH_NODES = 20_000
168
+
169
+ // A url bandage-figure can read again, or undefined for a local file
170
+ export function uriOf(location: FileLocation | undefined) {
171
+ return location && 'uri' in location && location.uri
172
+ ? new URL(location.uri, location.baseUri ?? window.location.href).href
173
+ : undefined
174
+ }
175
+
176
+ type ViewportOwner = 'fit' | 'user' | 'host'
177
+
178
+ interface BuiltViewport {
179
+ scale: number
180
+ bounds: Bounds
181
+ viewportDirty: number
182
+ }
183
+
184
+ export function geometryPainted(model: {
185
+ viewportRebuildPending: boolean
186
+ viewportDirty: number
187
+ builtViewport?: BuiltViewport
188
+ paintedViewport?: BuiltViewport
189
+ }) {
190
+ return (
191
+ model.builtViewport !== undefined &&
192
+ model.paintedViewport === model.builtViewport &&
193
+ model.builtViewport.viewportDirty === model.viewportDirty &&
194
+ !model.viewportRebuildPending
195
+ )
196
+ }
197
+
198
+ // What the pane shows, in layout units: what each panel shows while faceted
199
+ export function paneViewportOf(model: {
200
+ translateX: number
201
+ translateY: number
202
+ axisScale: AxisScale
203
+ viewBox: { width: number; height: number }
204
+ }): Bounds {
205
+ const { width, height } = model.viewBox
206
+ return viewportOf(model, model.axisScale, width, height)
207
+ }
208
+
209
+ // Force layouts already computed for a graph, keyed by the view props the
210
+ // engine reads. Every layout mode is local and costs a millisecond except this
211
+ // one, which is seconds: measured on the committed engine, a 1,201-node bubble
212
+ // chain is 0.6 s proportional, 4.3 s at 'Wide bubbles' and 3.4 s at the highest
213
+ // quality.
214
+ //
215
+ // Worth keeping because a session revisits the same layout. The two drawings
216
+ // answer different questions and the README's own figure is one subgraph in
217
+ // both, so Anchored <-> Force is a round trip a reader makes repeatedly — and
218
+ // every control in the settings dialog calls `recomputeLayout` on change
219
+ // whether or not the current mode reads what it changed, which made picking a
220
+ // reference path in force mode a multi-second re-run of an identical layout.
221
+ // Both are hits.
222
+ //
223
+ // Entries are the live position objects rather than copies, which a node drag
224
+ // mutates in place (see moveNode), so a layout comes back arranged the way it
225
+ // was left rather than snapping back.
226
+ //
227
+ // Weak on the graph so nothing has to invalidate it: a graph is rebuilt by
228
+ // every load and dropped by `clearGraph`, and its layouts go with it.
229
+ const forceLayouts = new WeakMap<Graph, Map<string, LayoutResult>>()
230
+
231
+ // Enough to hold the settings a comparison moves between; past that the oldest
232
+ // goes, since a big graph's positions are megabytes.
233
+ const FORCE_LAYOUT_CACHE_SIZE = 4
234
+
235
+ export function forceLayoutsOf(graph: Graph) {
236
+ let cache = forceLayouts.get(graph)
237
+ if (!cache) {
238
+ cache = new Map()
239
+ forceLayouts.set(graph, cache)
240
+ }
241
+ return cache
242
+ }
243
+
244
+ // Re-anchoring builds a new Graph, and the force layout of it is the same
245
+ // drawing: `anchorFromPaths` rewrites each node's `stable` and `samples` and
246
+ // touches neither the ids, the lengths, the depths nor the edges, which are all
247
+ // the engine reads. So the layouts follow the graph they were computed for
248
+ // rather than being thrown away with it.
249
+ export function inheritForceLayouts(from: Graph, to: Graph) {
250
+ const cache = forceLayouts.get(from)
251
+ if (cache && from !== to) {
252
+ forceLayouts.set(to, cache)
253
+ }
254
+ }
255
+
256
+ export function remember(
257
+ cache: Map<string, LayoutResult>,
258
+ key: string,
259
+ result: LayoutResult,
260
+ ) {
261
+ if (cache.size >= FORCE_LAYOUT_CACHE_SIZE) {
262
+ cache.delete(cache.keys().next().value!)
263
+ }
264
+ cache.set(key, result)
265
+ }
266
+
267
+ export const paneBase = types
268
+ .compose(
269
+ 'GraphPane',
270
+ RenderLifecycleMixin(),
271
+ types.model({
272
+ // FMMM's iteration budget, 0-4, the same scale Bandage's own settings
273
+ // dialog exposes: 3+1 iterations at 0, 15+10 at 1, 30+20 at 2, 60+40 at
274
+ // 3, 120+60 at 4 (BandageNG layout/graphlayoutworker.cpp).
275
+ //
276
+ // 2 because that is what the engine we vendor ships as its default
277
+ // (`graphLayoutQuality = IntSetting(2, 0, 4)`, program/settings.cpp).
278
+ // This was 1 for no recorded reason, i.e. one step BELOW upstream, and a
279
+ // first sight of any graph is the default: review kept asking whether
280
+ // the drawing could be iterated more ("are you sure you can't iterate it
281
+ // more times for better layout?") of figures that were simply on a lower
282
+ // setting than the tool they come from. Cost at the sizes this view
283
+ // draws is milliseconds, and the header states the layout time so the
284
+ // difference is visible rather than asserted.
285
+ layoutQuality: types.optional(types.number, 2),
286
+ linearLayout: types.optional(types.boolean, false),
287
+ // unset takes the host's default: force in a view of its own, the
288
+ // display config's in a track
289
+ layoutMode: lenientMaybeEnum(LAYOUT_MODE_VALUES),
290
+ colorScheme: lenientMaybeEnum(COLOR_SCHEME_VALUES),
291
+ // How far the force layout opens a bubble, which on a variation graph is
292
+ // the difference between a legible drawing and a rope. See
293
+ // BUBBLE_SPREADS; no effect on the reference-anchored layouts, which
294
+ // place a node from its coordinates rather than from a force sim.
295
+ bubbleSpread: lenientOptionalEnum(BUBBLE_SPREAD_VALUES, 'auto'),
296
+ // Node thickness by depth, Bandage's own device; see NODE_WIDTHS.
297
+ nodeWidth: lenientOptionalEnum(NODE_WIDTH_VALUES, 'depth'),
298
+ // Whether the node layouts draw each bubble as a halo along its nodes
299
+ // with a label that opens it. Off by default: on a base-level cut
300
+ // every SNP's halo is a blob.
301
+ showBubbles: types.optional(types.boolean, false),
302
+ showDeletionEdges: types.optional(types.boolean, true),
303
+ // The session's genes drawn onto the backbone: exons along the nodes
304
+ // that carry them, names pinned at their midpoints. See genes/.
305
+ showGenes: types.optional(types.boolean, true),
306
+ // Whether a drawing in its own coordinates inside a linear view gets
307
+ // the strip of reference segments at their bp. See referenceStrip.ts.
308
+ showReferenceStrip: types.optional(types.boolean, true),
309
+ // Variants under this many bp fold into the reference before a tube map
310
+ // is laid out, each kept as a tick on its walk's tube (coarsen.ts); 0
311
+ // draws every one
312
+ tubeMapFold: types.optional(types.number, 0),
313
+ // Which track the genes come from; empty picks the assembly's
314
+ // annotation track (pickGeneTrack).
315
+ geneTrackId: types.optional(types.string, ''),
316
+ // Which track the walk rows read tandem repeat arrays from; empty
317
+ // picks a track whose name says repeats (pickRepeatTrack).
318
+ repeatTrackId: types.optional(types.string, ''),
319
+ // The array the walk rows measure between and tile by, as
320
+ // RepeatArray.key; empty measures the whole window untiled.
321
+ repeatKey: types.optional(types.string, ''),
322
+ // Samples whose walks the walk rows show, by the name before the
323
+ // haplotype number; undefined shows every walk the cut holds.
324
+ walkRowSamples: types.maybe(types.frozen<string[]>()),
325
+ // Walk rows in a strip under a layout that draws nodes, linked to the
326
+ // drawing: a node's passes tick each bar, a bar's point lights its node
327
+ walkStrip: types.optional(types.boolean, false),
328
+ // Walks lifted out of the drawing, each a layer with a lane of its own
329
+ // and the rest fading, coloured by the encoding it states or by the
330
+ // default one. See walkEncoding.ts. Empty lifts none.
331
+ walkLayers: types.optional(types.frozen<WalkLayer[]>(), []),
332
+ // Facets, as a grammar of graphics splits a plot: `walk` draws the
333
+ // pane once per lifted walk, side by side on the same layout, each
334
+ // panel with that walk alone; `sample` puts a sample's haplotypes in
335
+ // a row; `domain` orders the panels and `columns` fixes how many go
336
+ // across. See facetPanels and facetCells.
337
+ facet: types.optional(facetModel, {}),
338
+ // Which of a general GFA's paths the anchored layouts put on x. A path
339
+ // GFA's names are arbitrary and none of them is marked as the
340
+ // reference, so this is a choice; empty means "infer", which is the
341
+ // assembly a subgraph was cut against, and the first path in the file
342
+ // for a whole-file import. No effect on an rGFA, whose segments carry
343
+ // their own coordinates. See pathAnchoring.ts.
344
+ referencePath: types.optional(types.string, ''),
345
+ // Whether the toolbar spells out `fetch 12371ms · layout 4ms · geom 9ms`.
346
+ // Off by default because it was in the toolbar of every published graph
347
+ // figure, where a machine's fetch time is noise a reader has to skip
348
+ // past. The numbers themselves are always on the element as `data-*`
349
+ // attributes, which is what browser tests assert against, so hiding the
350
+ // text costs no coverage.
351
+ showPerf: types.optional(types.boolean, false),
352
+ contigThickness: types.optional(types.number, 6),
353
+ connectorThickness: types.optional(types.number, 2),
354
+ darkMode: types.optional(types.boolean, false),
355
+ scale: types.optional(types.number, 1),
356
+ translateX: types.optional(types.number, 0),
357
+ translateY: types.optional(types.number, 0),
358
+ drawPaths: types.optional(types.boolean, false),
359
+ // Ceiling on the drawing pane, in css px, for a session or a figure that
360
+ // wants a shorter one than the drawing asks for. Unset means the built-in
361
+ // MAX_CANVAS_HEIGHT, which is what every existing session gets.
362
+ //
363
+ // Why this is a knob rather than a smaller default: the pane is as tall
364
+ // as the drawing's own aspect ratio (see canvasHeight), which is right —
365
+ // a graph that is twice as tall as it is wide should not be squeezed
366
+ // into a strip. But one very long node in a cut of short ones makes that
367
+ // aspect ratio all arc: the HPRC CHM13 figure draws a 142 kb allele
368
+ // among sub-kb backbone segments, pins the 600 px ceiling and spends
369
+ // most of it on the loop, with the chain squashed along the bottom edge.
370
+ // Lowering the ceiling there scales the whole drawing down, which is
371
+ // exactly the trade that figure wants and the wrong default for a graph
372
+ // whose height is carrying information.
373
+ paneHeight: types.maybe(types.number),
374
+ // Raise to draw a bigger graph than the default budget allows; see
375
+ // DEFAULT_MAX_GRAPH_NODES for what the numbers cost.
376
+ maxGraphNodes: types.optional(types.number, DEFAULT_MAX_GRAPH_NODES),
377
+ // The reference span the reference-position ramp runs over, for a graph
378
+ // with no region of its own to span it
379
+ colorDomain: types.maybe(types.frozen<{ start: number; end: number }>()),
380
+ // the linear view a graph of its own is paired with for the hover sync
381
+ connectedViewId: types.maybe(types.string),
382
+ }),
383
+ )
384
+ .volatile(() => ({
385
+ graph: undefined as Graph | undefined,
386
+ // the reference window the graph on screen was cut for, set with it
387
+ graphRegion: undefined as SubgraphRegion | undefined,
388
+ // The walk the track's graph lies on for the region's assembly, which
389
+ // the track's config declares; x starts along it unless the user chose
390
+ // another. Undefined for an rGFA, whose backbone is fixed, and for a
391
+ // graph with no region.
392
+ loadedReferencePath: undefined as string | undefined,
393
+ layoutResult: undefined as LayoutResult | undefined,
394
+ // what the legends in the pane's top-right corner measure, so no label
395
+ // is placed under them
396
+ legendSize: { width: 0, height: 0 },
397
+ // The bubble index rows over the cut window, when the source track has
398
+ // one beside its segments. Undefined for a graph with no index, whose
399
+ // bubbles are `derivedBubbles` instead.
400
+ indexBubbles: undefined as MinigraphBubble[] | undefined,
401
+ // the genes over the cut window, read once per cut from the gene track
402
+ geneFeatures: undefined as GeneModel[] | undefined,
403
+ // each walk row's genes, read from its haplotype's own assembly, by walk
404
+ // name
405
+ walkGeneFeatures: undefined as Map<string, GeneModel[]> | undefined,
406
+ // the tandem repeat arrays over the cut window, from the repeat track
407
+ repeatArrays: undefined as RepeatArray[] | undefined,
408
+ // The graphs the open bubble was popped out of, outermost first, each
409
+ // with what closing back to it restores without a refetch. A stack so a
410
+ // popped superbubble can be mapped and popped again.
411
+ popStack: [] as {
412
+ graph: Graph
413
+ layoutMode: LayoutModeValue
414
+ label: string
415
+ indexBubbles: MinigraphBubble[] | undefined
416
+ }[],
417
+
418
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
419
+ error: undefined as unknown,
420
+ isLoading: false,
421
+ loadCanceled: false,
422
+ statusMessage: '',
423
+ hoveredNode: null as string | null,
424
+ // the walks of the per-sample lane row the linear view's pointer is on
425
+ hoveredRowWalks: [] as string[],
426
+ // the bubble whose label the pointer is on
427
+ hoveredBubble: null as MinigraphBubble | null,
428
+ // whether the pointer is over this pane, whose own hit test then says
429
+ // what it is on
430
+ pointerInPane: false,
431
+ // the strip point the pointer is over, which lights its node above
432
+ stripHover: null as { row: string; offset: number } | null,
433
+ hoveredEdge: null as number | null,
434
+ selectedNode: null as string | null,
435
+ viewportDirty: 0,
436
+ // Bumped when the layout's positions are mutated IN PLACE, which only a
437
+ // node drag does. Separate from `viewportDirty` because that one also
438
+ // fires on pan and zoom, and the things keyed off this — the two hit
439
+ // indexes and the label placement's per-layout caches — do not depend on
440
+ // the transform at all. Rebuilding a 12k-edge hit index because the user
441
+ // panned cost ~14 ms of the first mousemove after every gesture.
442
+ positionsVersion: 0,
443
+ // Bumped per upload, so the hover autorun re-states its highlights
444
+ // against the batch the renderer now holds.
445
+ geometryVersion: 0,
446
+ // The zoom and the window the current batch was built for; a pan that
447
+ // stays inside it needs no rebuild.
448
+ builtViewport: undefined as BuiltViewport | undefined,
449
+ // The builtViewport whose batch is on the canvas
450
+ paintedViewport: undefined as BuiltViewport | undefined,
451
+ draggingNode: null as string | null,
452
+ // Dragging the background rather than a node. Lives here beside
453
+ // draggingNode instead of in a component ref+state pair, so the two
454
+ // mutually exclusive drag modes are one piece of state read from one place.
455
+ isPanning: false,
456
+ // Who places the view. 'fit' refits it to every new layout, 'user' leaves
457
+ // it where a gesture or a restored session put it, and 'host' takes x
458
+ // from the linear view the pane sits in. Not derived from
459
+ // `isDefaultViewport`, which zoomToFit itself invalidates on its first
460
+ // run — that made the fit fire once against not-yet-measured dimensions
461
+ // and then never re-fit.
462
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
463
+ viewportOwner: 'fit' as ViewportOwner,
464
+ viewportDirtyTimer: undefined as ReturnType<typeof setTimeout> | undefined,
465
+ // 0 is never a live rAF handle, so it doubles as "nothing pending"
466
+ positionsDirtyFrame: 0,
467
+ // Performance instrumentation, surfaced in GraphStats for browser tests
468
+ // to assert against budgets. `fetchMs` is the GetSubgraph RPC round-trip,
469
+ // `layoutMs` is the Bandage FMMM compute time reported by the
470
+ // GraphComputeLayout RPC, `geometryMs` is the main-thread buildGeometry
471
+ // pass and `geometryStrokeCount` the node strokes it produced.
472
+ lastFetchMs: undefined as number | undefined,
473
+ // how many of the cut's reads the tube map was handed, of how many
474
+ readsShown: undefined as { shown: number; total: number } | undefined,
475
+ lastLayoutMs: undefined as number | undefined,
476
+ lastGeometryMs: undefined as number | undefined,
477
+ lastGeometryStrokeCount: undefined as number | undefined,
478
+ viewportRebuildPending: false,
479
+ }))