react-msaview 7.0.0 → 8.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 (310) hide show
  1. package/README.md +11 -10
  2. package/bundle/index.js +122 -111
  3. package/bundle/index.js.map +4 -4
  4. package/dist/colorSchemes.js +1 -2
  5. package/dist/colorSchemes.js.map +1 -1
  6. package/dist/columnStats.d.ts +28 -0
  7. package/dist/columnStats.js +34 -0
  8. package/dist/columnStats.js.map +1 -0
  9. package/dist/components/DragHandle.d.ts +3 -2
  10. package/dist/components/DragHandle.js +11 -5
  11. package/dist/components/DragHandle.js.map +1 -1
  12. package/dist/components/Loading.js.map +1 -1
  13. package/dist/components/MSAView.js +17 -6
  14. package/dist/components/MSAView.js.map +1 -1
  15. package/dist/components/MSAViewer.d.ts +64 -7
  16. package/dist/components/MSAViewer.js +128 -23
  17. package/dist/components/MSAViewer.js.map +1 -1
  18. package/dist/components/PortalTooltip.d.ts +11 -0
  19. package/dist/components/PortalTooltip.js +29 -0
  20. package/dist/components/PortalTooltip.js.map +1 -0
  21. package/dist/components/ResizeHandles.js +11 -29
  22. package/dist/components/ResizeHandles.js.map +1 -1
  23. package/dist/components/SequenceTextArea.js +3 -3
  24. package/dist/components/SequenceTextArea.js.map +1 -1
  25. package/dist/components/Track.js +41 -22
  26. package/dist/components/Track.js.map +1 -1
  27. package/dist/components/dialogs/ExportSVGDialog.js +5 -3
  28. package/dist/components/dialogs/ExportSVGDialog.js.map +1 -1
  29. package/dist/components/dialogs/TrackInfoDialog.js +1 -1
  30. package/dist/components/dialogs/TrackInfoDialog.js.map +1 -1
  31. package/dist/components/header/GappynessSlider.js +6 -11
  32. package/dist/components/header/GappynessSlider.js.map +1 -1
  33. package/dist/components/header/Header.js +3 -0
  34. package/dist/components/header/Header.js.map +1 -1
  35. package/dist/components/header/LoadWarnings.js +3 -4
  36. package/dist/components/header/LoadWarnings.js.map +1 -1
  37. package/dist/components/header/ScrollZoomIcons.d.ts +6 -0
  38. package/dist/components/header/ScrollZoomIcons.js +35 -0
  39. package/dist/components/header/ScrollZoomIcons.js.map +1 -0
  40. package/dist/components/header/TreeSettingsMenu.js +1 -3
  41. package/dist/components/header/TreeSettingsMenu.js.map +1 -1
  42. package/dist/components/header/UnshareableDataWarning.js +2 -4
  43. package/dist/components/header/UnshareableDataWarning.js.map +1 -1
  44. package/dist/components/header/ZoomControls.js +49 -6
  45. package/dist/components/header/ZoomControls.js.map +1 -1
  46. package/dist/components/header/getAnnotationsMenu.js +3 -6
  47. package/dist/components/header/getAnnotationsMenu.js.map +1 -1
  48. package/dist/components/header/settingsMenuItems.js +10 -7
  49. package/dist/components/header/settingsMenuItems.js.map +1 -1
  50. package/dist/components/import/util.js +1 -2
  51. package/dist/components/import/util.js.map +1 -1
  52. package/dist/components/minimap/Minimap.js +1 -2
  53. package/dist/components/minimap/Minimap.js.map +1 -1
  54. package/dist/components/msa/AnnotationLegend.js +27 -19
  55. package/dist/components/msa/AnnotationLegend.js.map +1 -1
  56. package/dist/components/msa/MSACanvas.js +1 -1
  57. package/dist/components/msa/MSACanvas.js.map +1 -1
  58. package/dist/components/msa/MSACanvasBlock.js +13 -15
  59. package/dist/components/msa/MSACanvasBlock.js.map +1 -1
  60. package/dist/components/msa/MSAMouseoverCanvas.js +2 -1
  61. package/dist/components/msa/MSAMouseoverCanvas.js.map +1 -1
  62. package/dist/components/msa/domainBandCursor.d.ts +7 -11
  63. package/dist/components/msa/domainBandCursor.js +7 -11
  64. package/dist/components/msa/domainBandCursor.js.map +1 -1
  65. package/dist/components/msa/drawFeatureSpans.d.ts +53 -0
  66. package/dist/components/msa/drawFeatureSpans.js +78 -0
  67. package/dist/components/msa/drawFeatureSpans.js.map +1 -0
  68. package/dist/components/msa/legendRows.d.ts +8 -0
  69. package/dist/components/msa/legendRows.js +16 -0
  70. package/dist/components/msa/legendRows.js.map +1 -0
  71. package/dist/components/msa/msaRaster.d.ts +24 -31
  72. package/dist/components/msa/msaRaster.js +30 -39
  73. package/dist/components/msa/msaRaster.js.map +1 -1
  74. package/dist/components/msa/packDomainLanes.d.ts +20 -0
  75. package/dist/components/msa/packDomainLanes.js +33 -0
  76. package/dist/components/msa/packDomainLanes.js.map +1 -0
  77. package/dist/components/msa/renderBoxFeatureCanvasBlock.d.ts +3 -1
  78. package/dist/components/msa/renderBoxFeatureCanvasBlock.js +51 -87
  79. package/dist/components/msa/renderBoxFeatureCanvasBlock.js.map +1 -1
  80. package/dist/components/msa/renderHighlights.d.ts +15 -13
  81. package/dist/components/msa/renderHighlights.js +43 -20
  82. package/dist/components/msa/renderHighlights.js.map +1 -1
  83. package/dist/components/msa/renderMSABlock.js +5 -4
  84. package/dist/components/msa/renderMSABlock.js.map +1 -1
  85. package/dist/components/msa/tileColor.js +4 -7
  86. package/dist/components/msa/tileColor.js.map +1 -1
  87. package/dist/components/msa/useMsaBlockMouse.d.ts +5 -3
  88. package/dist/components/msa/useMsaBlockMouse.js +6 -6
  89. package/dist/components/msa/useMsaBlockMouse.js.map +1 -1
  90. package/dist/components/rowpanels/RowPanelBlock.d.ts +9 -0
  91. package/dist/components/rowpanels/RowPanelBlock.js +86 -0
  92. package/dist/components/rowpanels/RowPanelBlock.js.map +1 -0
  93. package/dist/components/rowpanels/RowPanelHeaders.d.ts +12 -0
  94. package/dist/components/rowpanels/RowPanelHeaders.js +38 -0
  95. package/dist/components/rowpanels/RowPanelHeaders.js.map +1 -0
  96. package/dist/components/{msa/ColumnStats.d.ts → rowpanels/RowPanels.d.ts} +2 -2
  97. package/dist/components/rowpanels/RowPanels.js +32 -0
  98. package/dist/components/rowpanels/RowPanels.js.map +1 -0
  99. package/dist/components/rowpanels/headerLayout.d.ts +1 -0
  100. package/dist/components/rowpanels/headerLayout.js +5 -0
  101. package/dist/components/rowpanels/headerLayout.js.map +1 -0
  102. package/dist/components/rowpanels/renderFeaturePanel.d.ts +21 -0
  103. package/dist/components/rowpanels/renderFeaturePanel.js +37 -0
  104. package/dist/components/rowpanels/renderFeaturePanel.js.map +1 -0
  105. package/dist/components/rowpanels/renderRowPanel.d.ts +23 -0
  106. package/dist/components/rowpanels/renderRowPanel.js +22 -0
  107. package/dist/components/rowpanels/renderRowPanel.js.map +1 -0
  108. package/dist/components/rowpanels/renderStrip.d.ts +20 -0
  109. package/dist/components/rowpanels/renderStrip.js +26 -0
  110. package/dist/components/rowpanels/renderStrip.js.map +1 -0
  111. package/dist/components/tracks/TrackBlocks.js +3 -5
  112. package/dist/components/tracks/TrackBlocks.js.map +1 -1
  113. package/dist/components/tracks/TrackTooltipContent.d.ts +15 -0
  114. package/dist/components/tracks/TrackTooltipContent.js +109 -0
  115. package/dist/components/tracks/TrackTooltipContent.js.map +1 -0
  116. package/dist/components/tracks/drawTracks.d.ts +4 -4
  117. package/dist/components/tracks/drawTracks.js +17 -34
  118. package/dist/components/tracks/drawTracks.js.map +1 -1
  119. package/dist/components/tracks/useTrackHover.d.ts +22 -0
  120. package/dist/components/tracks/useTrackHover.js +30 -0
  121. package/dist/components/tracks/useTrackHover.js.map +1 -0
  122. package/dist/components/tree/CladeLabels.d.ts +12 -0
  123. package/dist/components/tree/CladeLabels.js +48 -0
  124. package/dist/components/tree/CladeLabels.js.map +1 -0
  125. package/dist/components/tree/TreeCanvas.js +4 -1
  126. package/dist/components/tree/TreeCanvas.js.map +1 -1
  127. package/dist/components/tree/TreeCanvasBlock.js +4 -21
  128. package/dist/components/tree/TreeCanvasBlock.js.map +1 -1
  129. package/dist/components/tree/TreeOverview.d.ts +14 -0
  130. package/dist/components/tree/TreeOverview.js +75 -0
  131. package/dist/components/tree/TreeOverview.js.map +1 -0
  132. package/dist/components/tree/TreeRuler.js +9 -13
  133. package/dist/components/tree/TreeRuler.js.map +1 -1
  134. package/dist/components/tree/cladeBrackets.d.ts +25 -0
  135. package/dist/components/tree/cladeBrackets.js +51 -0
  136. package/dist/components/tree/cladeBrackets.js.map +1 -0
  137. package/dist/components/tree/dialogs/TreeNodeInfoDialog.js +2 -2
  138. package/dist/components/tree/dialogs/TreeNodeInfoDialog.js.map +1 -1
  139. package/dist/components/tree/renderTreeCanvas.js +158 -24
  140. package/dist/components/tree/renderTreeCanvas.js.map +1 -1
  141. package/dist/components/tree/renderTreeOverview.d.ts +52 -0
  142. package/dist/components/tree/renderTreeOverview.js +138 -0
  143. package/dist/components/tree/renderTreeOverview.js.map +1 -0
  144. package/dist/components/tree/useTreeHover.js +2 -4
  145. package/dist/components/tree/useTreeHover.js.map +1 -1
  146. package/dist/constants.d.ts +15 -0
  147. package/dist/constants.js +48 -22
  148. package/dist/constants.js.map +1 -1
  149. package/dist/createPaletteMap.d.ts +7 -6
  150. package/dist/createPaletteMap.js +10 -9
  151. package/dist/createPaletteMap.js.map +1 -1
  152. package/dist/element.d.ts +13 -0
  153. package/dist/element.js +269 -0
  154. package/dist/element.js.map +1 -0
  155. package/dist/featureFields.d.ts +11 -0
  156. package/dist/featureFields.js +17 -0
  157. package/dist/featureFields.js.map +1 -0
  158. package/dist/flatToTree.js +1 -2
  159. package/dist/flatToTree.js.map +1 -1
  160. package/dist/ggplotPalettes.d.ts +10 -0
  161. package/dist/ggplotPalettes.js +58 -0
  162. package/dist/ggplotPalettes.js.map +1 -1
  163. package/dist/hierarchy.d.ts +27 -0
  164. package/dist/hierarchy.js +66 -9
  165. package/dist/hierarchy.js.map +1 -1
  166. package/dist/index.d.ts +9 -1
  167. package/dist/index.js +5 -3
  168. package/dist/index.js.map +1 -1
  169. package/dist/model/DataModel.js +2 -5
  170. package/dist/model/DataModel.js.map +1 -1
  171. package/dist/model/msaModel.d.ts +3 -2
  172. package/dist/model/msaModel.js +3 -2
  173. package/dist/model/msaModel.js.map +1 -1
  174. package/dist/model/treeModel.d.ts +30 -0
  175. package/dist/model/treeModel.js +37 -1
  176. package/dist/model/treeModel.js.map +1 -1
  177. package/dist/model.d.ts +531 -275
  178. package/dist/model.js +1295 -547
  179. package/dist/model.js.map +1 -1
  180. package/dist/mount.d.ts +11 -0
  181. package/dist/mount.js +22 -0
  182. package/dist/mount.js.map +1 -0
  183. package/dist/neighborJoining.js +8 -32
  184. package/dist/neighborJoining.js.map +1 -1
  185. package/dist/renderToStaticMarkup.d.ts +10 -19
  186. package/dist/renderToStaticMarkup.js +13 -24
  187. package/dist/renderToStaticMarkup.js.map +1 -1
  188. package/dist/renderToSvg.js +180 -56
  189. package/dist/renderToSvg.js.map +1 -1
  190. package/dist/rowCoordinateCalculations.d.ts +4 -6
  191. package/dist/rowCoordinateCalculations.js +4 -6
  192. package/dist/rowCoordinateCalculations.js.map +1 -1
  193. package/dist/scales.d.ts +22 -0
  194. package/dist/scales.js +30 -0
  195. package/dist/scales.js.map +1 -0
  196. package/dist/seqPosToGlobalCol.d.ts +2 -3
  197. package/dist/seqPosToGlobalCol.js +2 -3
  198. package/dist/seqPosToGlobalCol.js.map +1 -1
  199. package/dist/sequenceLogo.d.ts +6 -11
  200. package/dist/sequenceLogo.js +6 -11
  201. package/dist/sequenceLogo.js.map +1 -1
  202. package/dist/stripDefault.d.ts +7 -14
  203. package/dist/stripDefault.js +7 -14
  204. package/dist/stripDefault.js.map +1 -1
  205. package/dist/svgTestUtil.d.ts +172 -52
  206. package/dist/types.d.ts +219 -21
  207. package/dist/umd.d.ts +2 -0
  208. package/dist/umd.js +4 -2
  209. package/dist/umd.js.map +1 -1
  210. package/dist/useCanvasAutorun.d.ts +5 -10
  211. package/dist/useCanvasAutorun.js +5 -10
  212. package/dist/useCanvasAutorun.js.map +1 -1
  213. package/dist/useMsaSvgFigure.d.ts +20 -0
  214. package/dist/useMsaSvgFigure.js +46 -0
  215. package/dist/useMsaSvgFigure.js.map +1 -0
  216. package/dist/util.d.ts +5 -6
  217. package/dist/util.js +13 -6
  218. package/dist/util.js.map +1 -1
  219. package/dist/version.d.ts +1 -1
  220. package/dist/version.js +1 -1
  221. package/package.json +19 -12
  222. package/src/colorSchemes.ts +1 -2
  223. package/src/columnStats.ts +58 -0
  224. package/src/components/DragHandle.tsx +18 -7
  225. package/src/components/Loading.tsx +2 -6
  226. package/src/components/MSAView.tsx +19 -5
  227. package/src/components/MSAViewer.tsx +240 -28
  228. package/src/components/PortalTooltip.tsx +47 -0
  229. package/src/components/ResizeHandles.tsx +17 -32
  230. package/src/components/SequenceTextArea.tsx +3 -3
  231. package/src/components/Track.tsx +55 -18
  232. package/src/components/dialogs/ExportSVGDialog.tsx +7 -2
  233. package/src/components/dialogs/TrackInfoDialog.tsx +1 -1
  234. package/src/components/header/GappynessSlider.tsx +6 -11
  235. package/src/components/header/Header.tsx +6 -0
  236. package/src/components/header/LoadWarnings.tsx +3 -4
  237. package/src/components/header/ScrollZoomIcons.tsx +52 -0
  238. package/src/components/header/TreeSettingsMenu.tsx +1 -3
  239. package/src/components/header/UnshareableDataWarning.tsx +2 -4
  240. package/src/components/header/ZoomControls.tsx +74 -14
  241. package/src/components/header/getAnnotationsMenu.ts +3 -6
  242. package/src/components/header/settingsMenuItems.ts +11 -6
  243. package/src/components/import/ImportFormExamples.tsx +2 -2
  244. package/src/components/import/util.ts +1 -2
  245. package/src/components/minimap/Minimap.tsx +1 -2
  246. package/src/components/msa/AnnotationLegend.tsx +48 -38
  247. package/src/components/msa/MSACanvas.tsx +3 -5
  248. package/src/components/msa/MSACanvasBlock.tsx +13 -16
  249. package/src/components/msa/MSAMouseoverCanvas.tsx +2 -1
  250. package/src/components/msa/domainBandCursor.ts +7 -11
  251. package/src/components/msa/drawFeatureSpans.ts +150 -0
  252. package/src/components/msa/legendRows.ts +24 -0
  253. package/src/components/msa/msaRaster.ts +30 -39
  254. package/src/components/msa/packDomainLanes.ts +36 -0
  255. package/src/components/msa/renderBoxFeatureCanvasBlock.ts +69 -123
  256. package/src/components/msa/renderHighlights.ts +53 -20
  257. package/src/components/msa/renderMSABlock.ts +5 -3
  258. package/src/components/msa/tileColor.ts +4 -7
  259. package/src/components/msa/useMsaBlockMouse.ts +6 -6
  260. package/src/components/rowpanels/RowPanelBlock.tsx +139 -0
  261. package/src/components/rowpanels/RowPanelHeaders.tsx +57 -0
  262. package/src/components/rowpanels/RowPanels.tsx +77 -0
  263. package/src/components/rowpanels/headerLayout.ts +5 -0
  264. package/src/components/rowpanels/renderFeaturePanel.ts +66 -0
  265. package/src/components/rowpanels/renderRowPanel.ts +41 -0
  266. package/src/components/rowpanels/renderStrip.ts +46 -0
  267. package/src/components/tracks/TrackBlocks.tsx +3 -5
  268. package/src/components/tracks/TrackTooltipContent.tsx +156 -0
  269. package/src/components/tracks/drawTracks.ts +17 -34
  270. package/src/components/tracks/useTrackHover.ts +42 -0
  271. package/src/components/tree/CladeLabels.tsx +77 -0
  272. package/src/components/tree/TreeCanvas.tsx +2 -0
  273. package/src/components/tree/TreeCanvasBlock.tsx +8 -32
  274. package/src/components/tree/TreeOverview.tsx +106 -0
  275. package/src/components/tree/TreeRuler.tsx +11 -22
  276. package/src/components/tree/cladeBrackets.ts +73 -0
  277. package/src/components/tree/dialogs/TreeNodeInfoDialog.tsx +2 -2
  278. package/src/components/tree/renderTreeCanvas.ts +240 -20
  279. package/src/components/tree/renderTreeOverview.ts +212 -0
  280. package/src/components/tree/useTreeHover.ts +2 -4
  281. package/src/constants.ts +56 -22
  282. package/src/createPaletteMap.ts +10 -9
  283. package/src/element.ts +321 -0
  284. package/src/featureFields.ts +19 -0
  285. package/src/flatToTree.ts +1 -2
  286. package/src/ggplotPalettes.ts +60 -0
  287. package/src/hierarchy.ts +77 -9
  288. package/src/index.ts +31 -7
  289. package/src/model/DataModel.ts +2 -5
  290. package/src/model/msaModel.ts +3 -2
  291. package/src/model/treeModel.ts +42 -0
  292. package/src/model.ts +1523 -560
  293. package/src/mount.tsx +32 -0
  294. package/src/neighborJoining.ts +8 -32
  295. package/src/renderToStaticMarkup.ts +13 -24
  296. package/src/renderToSvg.tsx +335 -68
  297. package/src/rowCoordinateCalculations.ts +4 -6
  298. package/src/scales.ts +47 -0
  299. package/src/seqPosToGlobalCol.ts +2 -3
  300. package/src/sequenceLogo.ts +6 -11
  301. package/src/stripDefault.ts +7 -14
  302. package/src/types.ts +258 -45
  303. package/src/umd.ts +4 -2
  304. package/src/useCanvasAutorun.ts +5 -10
  305. package/src/useMsaSvgFigure.ts +72 -0
  306. package/src/util.ts +15 -6
  307. package/src/version.ts +1 -1
  308. package/dist/components/msa/ColumnStats.js +0 -42
  309. package/dist/components/msa/ColumnStats.js.map +0 -1
  310. package/src/components/msa/ColumnStats.tsx +0 -54
package/dist/model.js CHANGED
@@ -2,20 +2,25 @@ import { clamp, groupBy, notEmpty, sum } from '@jbrowse/core/util';
2
2
  import { openLocation } from '@jbrowse/core/util/io';
3
3
  import { ElementId, FileLocation } from '@jbrowse/core/util/types/mst';
4
4
  import { addDisposer, applySnapshot, cast, getSnapshot, isAlive, types, } from '@jbrowse/mobx-state-tree';
5
- import { colord } from 'colord';
6
5
  import { autorun, transaction } from 'mobx';
7
6
  import { generateNodeIds, gffToAnnotations, interProScanToAnnotations, parseEmfTree, parseGFF, parseMSA, parseNewick, } from 'msa-parsers';
8
7
  import { calculateBlocks } from './calculateBlocks.js';
9
8
  import { clustalXColumnColors } from './clustalX.js';
10
9
  import colorSchemes from './colorSchemes.js';
11
10
  import { columnCountsFromRows, letterOfResidueSlot } from './columnCounts.js';
11
+ import { columnStats } from './columnStats.js';
12
+ import { packDomainLanes } from './components/msa/packDomainLanes.js';
13
+ import { visibleColRange } from './components/msa/visibleColRange.js';
12
14
  import TrackBlocks from './components/tracks/TrackBlocks.js';
13
- import { defaultAllowedGappyness, defaultColWidth, defaultColorSchemeName, defaultCurrentAlignment, defaultDrawMsaLetters, defaultHeight, defaultHideGaps, defaultRowHeight, defaultScrollX, defaultScrollY, defaultScrollZoom, defaultShowDomainLegend, defaultShowDomains, defaultSubFeatureRows, defaultTreeWidth, labelReferenceFontSize, maxCellSize, maxInlineSnapshotBytes, maxNeighborJoiningRows, minColWidth, minLetterColWidth, minLetterRowHeight, minRowHeight, segmentFeatureTypes, segmentShades, } from './constants.js';
15
+ import { cladeGutterWidth } from './components/tree/cladeBrackets.js';
16
+ import { scaleBarLength } from './components/tree/scaleBar.js';
17
+ import { cladeHighlightAlpha, cladeHighlightColor, defaultAllowedGappyness, defaultColWidth, defaultColorSchemeName, defaultCurrentAlignment, defaultDrawMsaLetters, defaultFeaturePanelWidth, defaultHeight, defaultHideGaps, defaultRowHeight, defaultScrollX, defaultScrollY, defaultScrollZoom, defaultScrollZoomAxis, defaultShowDomainLegend, defaultShowDomains, defaultSubFeatureRows, defaultTreeWidth, labelReferenceFontSize, maxCellSize, maxInlineSnapshotBytes, maxNeighborJoiningRows, minColWidth, minLetterColWidth, minLetterRowHeight, minRowHeight, rowPanelHeaderHeight, rowTintAlpha, scrollZoomAxes, segmentFeatureTypes, segmentShades, treeScaleBarHeight, } from './constants.js';
14
18
  import { createPaletteMap } from './createPaletteMap.js';
15
19
  import { exportFileName } from './exportFileName.js';
20
+ import { featureField, featureName } from './featureFields.js';
16
21
  import { fetchTextWithProgress, isAbortError } from './fetchUtils.js';
17
22
  import { flatToTree } from './flatToTree.js';
18
- import { calcDepthToLeaf, clusterLayout, collapse, collapsedSubtreeMaxLength, find, forEachDescendant, hierarchy, leaves, maxLength, setBrLength, sort, sum as hierarchySum, } from './hierarchy.js';
23
+ import { calcDepthToLeaf, clusterLayout, collapse, collapsedSubtreeMaxLength, find, forEachDescendant, hierarchy, leafIndex, leaves, maxLength, mrca, nodeCoveringRows, setBrLength, sort, sum as hierarchySum, } from './hierarchy.js';
19
24
  import { measureTextCanvas } from './measureTextCanvas.js';
20
25
  import { DataModelF } from './model/DataModel.js';
21
26
  import { DialogQueueSessionMixin } from './model/DialogQueue.js';
@@ -25,10 +30,11 @@ import { calculateNeighborJoiningTree } from './neighborJoining.js';
25
30
  import { parseAsn1 } from './parseAsn1.js';
26
31
  import { calculatePropertyConservation } from './propertyConservation.js';
27
32
  import { globalColToVisibleCol, seqPosOfGlobalCol, visibleColToGlobalCol, visibleColsBefore, } from './rowCoordinateCalculations.js';
33
+ import { resolveScale } from './scales.js';
28
34
  import { buildSeqPosIndex } from './seqPosToGlobalCol.js';
29
35
  import { maxBitsFor } from './sequenceLogo.js';
30
36
  import { stripDefault } from './stripDefault.js';
31
- import { computeRowInsertions, dropBlanks, len, skipBlanks, transform, } from './util.js';
37
+ import { computeRowInsertions, dropBlanks, len, outlineColor, skipBlanks, transform, withAlpha, } from './util.js';
32
38
  import { saveAs } from './vendor/fileSaver.js';
33
39
  import { parseWuss } from './wuss.js';
34
40
  function parseTreeText(text) {
@@ -37,14 +43,141 @@ function parseTreeText(text) {
37
43
  }
38
44
  return parseNewick(text.startsWith('SEQ') ? parseEmfTree(text).tree : text);
39
45
  }
40
- // Tracks that start hidden. The sequence logo answers a narrower question than
41
- // conservation does and costs three times the vertical space, so it waits to be
42
- // asked for.
46
+ // The height each kind draws at before the user drags a divider. A text track
47
+ // is absent: it is one alignment row tall and follows rowHeight, so the zoom
48
+ // controls already size it.
49
+ export const defaultTrackHeights = {
50
+ bar: 40,
51
+ // taller than a bar track: in a 40px stack of four residues each glyph is
52
+ // too short to identify. Twice the height of the tracks above it, so it
53
+ // starts hidden
54
+ logo: 80,
55
+ arc: 50,
56
+ ruler: 20,
57
+ };
58
+ // the kinds a divider resizes. The ruler is a fixed scale, and a text track
59
+ // follows the vertical zoom.
60
+ const resizableKinds = new Set(['bar', 'logo', 'arc']);
43
61
  const defaultOffTracks = new Set(['sequence-logo', 'position-ruler']);
44
- // base-pair arcs: one color for the nested helices, one for a pseudoknot, whose
45
- // whole point is that it crosses them
62
+ // a data track carries its own height rather than its kind's, so its divider
63
+ // resizes it alone
64
+ const ownHeightKey = (id) => `own:${id}`;
65
+ // base-pair arcs: one color for nested helices, one for pseudoknots, which cross
66
+ // them
46
67
  const HELIX_ARC = '#4e79a7';
47
68
  const PSEUDOKNOT_ARC = '#e15759';
69
+ // the fill of a span under a scale that gives its value no color, such as a
70
+ // gene a `map` over gene names leaves out
71
+ const UNSCALED_FEATURE = '#d9d9d9';
72
+ // the fraction of a span a following one may cover before it takes a lane of
73
+ // its own in a `features` panel
74
+ const laneOverlap = 0.1;
75
+ // a row panel's own width, or a default: the row height, which makes a strip
76
+ // cell square, and a gene neighborhood's width for a features panel
77
+ function rowPanelWidth(panel, rowHeight) {
78
+ return (panel.width ??
79
+ (panel.kind === 'features' ? defaultFeaturePanelWidth : rowHeight));
80
+ }
81
+ // the fill and outline of every feature in a list: its own GFF `color=` first,
82
+ // then the scale an encoding resolves over one of its fields, then the
83
+ // accession palette
84
+ function featureColorMap(annotations, encoding, fillPalette) {
85
+ const strokes = new Map();
86
+ const strokeOf = (fill) => {
87
+ const hit = strokes.get(fill);
88
+ if (hit !== undefined) {
89
+ return hit;
90
+ }
91
+ const stroke = outlineColor(fill);
92
+ strokes.set(fill, stroke);
93
+ return stroke;
94
+ };
95
+ return new Map(annotations.map(annotation => {
96
+ const value = encoding
97
+ ? featureField(annotation, encoding.field)
98
+ : undefined;
99
+ const fill = annotation.color ??
100
+ (value === undefined ? undefined : encoding.colorOf(value)) ??
101
+ (encoding ? UNSCALED_FEATURE : fillPalette[annotation.accession]);
102
+ return [annotation, { fill, stroke: strokeOf(fill) }];
103
+ }));
104
+ }
105
+ // the text a label channel draws inside each span, for the features carrying
106
+ // the field it names
107
+ function featureLabelMap(annotations, field) {
108
+ const labels = new Map();
109
+ for (const annotation of annotations) {
110
+ const value = featureField(annotation, field);
111
+ if (value !== undefined) {
112
+ labels.set(annotation, value);
113
+ }
114
+ }
115
+ return labels;
116
+ }
117
+ /**
118
+ * The spans a `features` panel draws, keyed by row name and measured in the
119
+ * panel's own pixels. `column` takes the bands the overlay draws, at the
120
+ * alignment's column width. `position` packs each row's features in its own
121
+ * residue positions, shifted by an `align` transform, and maps the extent they
122
+ * cover across every row onto the panel width, so a row with no alignment
123
+ * still has an x.
124
+ */
125
+ function featurePanelSpans({ panel, width, rowHeight, colWidth, domainBands, annotationsByRow, shifts, }) {
126
+ if (panel.x === 'column') {
127
+ return new Map([...domainBands].map(([name, bands]) => [
128
+ name,
129
+ bands.map(band => ({
130
+ ...band,
131
+ xStart: band.startCol * colWidth,
132
+ xEnd: band.endCol * colWidth,
133
+ })),
134
+ ]));
135
+ }
136
+ const shifted = Object.entries(annotationsByRow).map(([name, annotations]) => {
137
+ const shift = shifts?.get(name) ?? 0;
138
+ return [
139
+ name,
140
+ annotations.map(annotation => ({
141
+ annotation,
142
+ start: annotation.start - 1 + shift,
143
+ end: annotation.end + shift,
144
+ })),
145
+ ];
146
+ });
147
+ let min = Infinity;
148
+ let max = -Infinity;
149
+ for (const [, features] of shifted) {
150
+ for (const { start, end } of features) {
151
+ min = Math.min(min, start);
152
+ max = Math.max(max, end);
153
+ }
154
+ }
155
+ // the arrowhead on the rightmost feature reaches a row height past its end,
156
+ // so the extent maps onto the panel less that much
157
+ const drawable = Math.max(1, width - rowHeight);
158
+ const scale = max > min ? drawable / (max - min) : 0;
159
+ // a lane opens where a span covers more than a tenth of the one before it,
160
+ // which keeps the genes of an operon on one lane: adjacent genes commonly
161
+ // share a few bases, and a stop codon overlapping the next start reads as a
162
+ // second lane over the whole row
163
+ return new Map(shifted.map(([name, features]) => [
164
+ name,
165
+ packDomainLanes(features.map(({ annotation, start, end }) => ({
166
+ annotation,
167
+ xStart: (start - min) * scale,
168
+ xEnd: (end - min) * scale,
169
+ startCol: start,
170
+ endCol: end - (end - start) * laneOverlap,
171
+ }))),
172
+ ]));
173
+ }
174
+ // a scale over the values a field takes across the features drawn
175
+ function resolveFeatureScale(field, scale, annotations) {
176
+ return {
177
+ field,
178
+ ...resolveScale(scale, annotations.map(a => featureField(a, field)).filter(notEmpty)),
179
+ };
180
+ }
48
181
  // a data track over this size stays in the live model but leaves the snapshot,
49
182
  // the same rule DataModel applies to an inline document
50
183
  function columnTrackSizes(tracks) {
@@ -59,17 +192,13 @@ function smallColumnTracks(tracks) {
59
192
  * The snapshot properties reset() carries across a return to the import form:
60
193
  * display preferences and layout, nothing derived from the loaded file.
61
194
  *
62
- * reset() applies a default snapshot filtered to this list, so the list is the
63
- * whole decision: a property left off it resets to its default, a visible and
64
- * benign failure. The previous shape — a hand-maintained list of things to
65
- * CLEAR — failed in the dangerous direction: a forgotten property silently
66
- * carried the previous file's state into the next one, and because node ids
67
- * are path-derived (node-0-0-1), a stale `collapsed` or `showOnly` id matched
68
- * a real node in the new tree and folded it. Downstream composed properties
69
- * (e.g. the jbrowse plugin's) are not on the list, so they reset too.
195
+ * reset() applies a default snapshot filtered to this list, so any property
196
+ * left off it resets, including downstream composed ones (e.g. the jbrowse
197
+ * plugin's). Node ids are path-derived (node-0-0-1), so a carried-over
198
+ * `collapsed` or `showOnly` id would match a real node in the next tree and
199
+ * fold it.
70
200
  *
71
- * Exported for modelReset.test.ts, which checks that everything off this list
72
- * matches a freshly created model after reset().
201
+ * Exported for modelReset.test.ts.
73
202
  */
74
203
  export const preservedOnReset = new Set([
75
204
  'id',
@@ -77,6 +206,7 @@ export const preservedOnReset = new Set([
77
206
  'height',
78
207
  'drawMsaLetters',
79
208
  'scrollZoom',
209
+ 'scrollZoomAxis',
80
210
  'bgColor',
81
211
  'colorSchemeName',
82
212
  'showColumnStats',
@@ -87,50 +217,167 @@ export const preservedOnReset = new Set([
87
217
  'showBranchLen',
88
218
  'drawTree',
89
219
  'drawNodeBubbles',
220
+ 'drawNodeLabels',
221
+ 'showTreeOverview',
222
+ 'overviewHeight',
90
223
  'autoTreeAreaWidth',
91
224
  'turnedOffTracks',
225
+ 'trackHeights',
92
226
  'hideGaps',
93
227
  'allowedGappyness',
94
228
  'subFeatureRows',
95
229
  'showDomainLegend',
96
230
  ]);
97
- // `turnedOffTracks` records the user's explicit choices only: an id is absent
98
- // until they touch that track, and then its value is whether the track is OFF.
99
- // Reading the default through this is what lets a track ship hidden without
100
- // writing an entry into every snapshot and shared URL.
101
- // A track the file itself supplies says whether it starts hidden, since only
102
- // the file knows how many of them there are: a Pfam seed carries a couple of
103
- // #=GR lines, an Rfam family one per row.
231
+ // `turnedOffTracks` holds only the user's explicit choices, so a hidden-by-default
232
+ // track writes nothing into the snapshot. A file-supplied track passes its own
233
+ // `defaultOff`, since the count varies by file: a Pfam seed has a couple of #=GR
234
+ // lines, an Rfam family one per row.
104
235
  function trackIsOff(turnedOffTracks, id, defaultOff) {
105
236
  return turnedOffTracks.get(id) ?? (defaultOff || defaultOffTracks.has(id));
106
237
  }
107
- // one array for every "nothing under the pointer", since a fresh [] is a fresh
108
- // value to every observer of it
238
+ // shared empty results, so observers don't see a fresh [] as a change
109
239
  const noDomains = [];
110
- // seqPos -> column indexes, per row, hung off the parse the rows came from so
111
- // they are collected with it. A computed would rebuild every row's index on
112
- // each miss, and rebuild all of them again whenever it was read outside a
113
- // reactive context.
240
+ const noClades = [];
241
+ /**
242
+ * The rows a clade covers and the node an `mrca` names, or undefined when the
243
+ * clade does not resolve: a tip name the tree does not have or has twice, or a
244
+ * leaf count `tips` disagrees with. `index` and `rowNamesSet` are the memoized
245
+ * passes over the tree.
246
+ */
247
+ function cladeRows(clade, root, index, rowNamesSet) {
248
+ if (clade.range) {
249
+ const [a, b] = clade.range.map(name => index.get(name) ? rowNamesSet.get(name) : undefined);
250
+ if (a === undefined || b === undefined) {
251
+ return undefined;
252
+ }
253
+ const rows = a <= b ? [a, b] : [b, a];
254
+ return rows[1] - rows[0] + 1 === clade.tips ? { rows } : undefined;
255
+ }
256
+ const node = clade.mrca ? mrca(root, clade.mrca, index) : undefined;
257
+ if (!node) {
258
+ return undefined;
259
+ }
260
+ const tips = leaves(node);
261
+ if (tips.length !== clade.tips) {
262
+ return undefined;
263
+ }
264
+ let first = Infinity;
265
+ let last = -Infinity;
266
+ for (const tip of tips) {
267
+ const row = rowNamesSet.get(tip.data.name);
268
+ if (row !== undefined) {
269
+ first = Math.min(first, row);
270
+ last = Math.max(last, row);
271
+ }
272
+ }
273
+ return first <= last
274
+ ? { rows: [first, last], nodeId: node.data.id }
275
+ : undefined;
276
+ }
277
+ /**
278
+ * Every clade that resolves, with its fill color settled, against the leaf
279
+ * order `rowNamesSet` gives. The tree panel resolves against the displayed
280
+ * rows and the overview against its own, so both take the tree they draw. A
281
+ * `range` record names no node, so `collapse` and `focus`, which need one,
282
+ * drop it.
283
+ */
284
+ function resolveClades(clades, root, rowNamesSet) {
285
+ const index = leafIndex(root);
286
+ return clades.flatMap(clade => {
287
+ const resolved = cladeRows(clade, root, index, rowNamesSet);
288
+ const seeding = clade.mark === 'collapse' || clade.mark === 'focus';
289
+ return resolved && !(seeding && resolved.nodeId === undefined)
290
+ ? [
291
+ {
292
+ ...resolved,
293
+ mark: clade.mark,
294
+ color: withAlpha(clade.color ?? cladeHighlightColor, cladeHighlightAlpha),
295
+ markColor: clade.color,
296
+ label: clade.label,
297
+ },
298
+ ]
299
+ : [];
300
+ });
301
+ }
302
+ /**
303
+ * The tree with the display transforms applied: leaf counts summed, children
304
+ * sorted by branch length, `showOnly` taken as the new root, and each
305
+ * `collapsed` clade folded. The overview builds the same tree without the
306
+ * focus, so it shows the focused subtree inside the whole.
307
+ */
308
+ function buildTreeRoot(tree, collapsed, showOnly) {
309
+ let hier = hierarchy(tree, d => d.children);
310
+ hierarchySum(hier, d => (d.children.length > 0 ? 0 : 1));
311
+ sort(hier, (a, b) => (a.data.length ?? 1) - (b.data.length ?? 1));
312
+ if (showOnly) {
313
+ const res = find(hier, n => n.data.id === showOnly);
314
+ if (res) {
315
+ hier = res;
316
+ }
317
+ }
318
+ for (const collapsedId of collapsed) {
319
+ const node = find(hier, n => n.data.id === collapsedId);
320
+ if (node) {
321
+ if (node.children) {
322
+ collapse(node);
323
+ }
324
+ else if (node.parent?.children) {
325
+ node.parent.children = node.parent.children.filter(c => c.data.id !== collapsedId);
326
+ }
327
+ }
328
+ }
329
+ return hier;
330
+ }
331
+ // the inclusive tip indices a node covers, from the row-space extent
332
+ // clusterLayout writes to xMin/xMax as tip centers
333
+ function tipRange(node) {
334
+ return [Math.round(node.xMin - 0.5), Math.round(node.xMax - 0.5)];
335
+ }
336
+ // the channels reading the feature table; every other channel reads rowData
337
+ const featureChannels = new Set([
338
+ 'featureFill',
339
+ 'featureLabel',
340
+ ]);
341
+ // seqPos -> column indexes per row, keyed on the parse so they are garbage
342
+ // collected with it. A computed would rebuild every row's index when read
343
+ // outside a reactive context.
114
344
  const seqPosIndexCache = new WeakMap();
115
- // A segment asserts a 1:1 run, so its two sides have to be the same length.
116
- // One that is not is malformed data, and the arithmetic below would answer
117
- // anyway -- with a residue that is off by however much the sides disagree. Skip
118
- // it, the same refusal an uncovered position gets.
345
+ // A segment is a 1:1 run. A segment whose sides differ in length is malformed,
346
+ // and the lookups treat it like an uncovered position.
119
347
  function sameLength(segment) {
120
348
  return (segment.rowEnd - segment.rowStart ===
121
349
  segment.structEnd - segment.structStart);
122
350
  }
123
- // Does the content need a scrollbar? fit() divides the viewport by the row or
124
- // column count and multiplies it back, so an exact fit lands a fraction of a
125
- // pixel over -- enough for a `>` to answer yes and hand the reader a minimap or
126
- // a scrollbar for half a pixel of nothing, which then shrinks the viewport and
127
- // leaves a gap.
351
+ // fit() divides the viewport by the row or column count and multiplies back, so
352
+ // an exact fit can land a fraction of a pixel over. A plain `>` would then show
353
+ // a scrollbar that shrinks the viewport and leaves a gap.
128
354
  function overflows(content, viewport) {
129
355
  return content - viewport > 0.5;
130
356
  }
131
357
  function inRanges(ranges, position) {
132
358
  return !!ranges?.some(([start, end]) => position >= start && position <= end);
133
359
  }
360
+ // the value every one of a node's children reports, or undefined where one of
361
+ // them has no value or they disagree
362
+ function sharedValue(values) {
363
+ const [first] = values;
364
+ return first !== undefined && values.every(v => v === first)
365
+ ? first
366
+ : undefined;
367
+ }
368
+ // preorder, so reversing the list puts every node after its descendants
369
+ function preorder(tree) {
370
+ const order = [];
371
+ const stack = [tree];
372
+ while (stack.length > 0) {
373
+ const node = stack.pop();
374
+ order.push(node);
375
+ for (const child of node.children) {
376
+ stack.push(child);
377
+ }
378
+ }
379
+ return order;
380
+ }
134
381
  /**
135
382
  * #stateModel MsaView
136
383
  *
@@ -166,10 +413,8 @@ function stateModelFactory() {
166
413
  /**
167
414
  * #property
168
415
  * whether the domain legend is expanded. The legend floats over the
169
- * top-right of the alignment, so on a tall panel it covers real
170
- * residues -- persisting the state is what lets a reader collapse it
171
- * and keep it collapsed, and what lets a session or a figure open with
172
- * it already out of the way.
416
+ * top-right of the alignment and covers residues, so a session or
417
+ * figure can open with it collapsed.
173
418
  */
174
419
  showDomainLegend: stripDefault(types.boolean, defaultShowDomainLegend),
175
420
  /**
@@ -198,6 +443,11 @@ function stateModelFactory() {
198
443
  * zoom in/out on plain mouse-wheel without holding ctrl
199
444
  */
200
445
  scrollZoom: stripDefault(types.boolean, defaultScrollZoom),
446
+ /**
447
+ * #property
448
+ * which cell dimensions a wheel zoom scales, while `scrollZoom` is on
449
+ */
450
+ scrollZoomAxis: stripDefault(types.enumeration('ScrollZoomAxis', [...scrollZoomAxes]), defaultScrollZoomAxis),
201
451
  /**
202
452
  * #property
203
453
  * height of the div containing the view, px
@@ -269,18 +519,25 @@ function stateModelFactory() {
269
519
  turnedOffTracks: stripDefault(types.map(types.boolean), {}),
270
520
  /**
271
521
  * #property
272
- * tracks supplied as data rather than computed from the alignment:
273
- * per-column values drawn as bars, or a per-column string drawn as a
274
- * text track. See docs/layers.md
522
+ * the height of every track one divider resizes, keyed by `heightKey`:
523
+ * the `kind` for the computed tracks, `own:<id>` for a data track. A
524
+ * key is absent until the user drags that divider, and
525
+ * `defaultTrackHeights` answers for it until then, so an untouched
526
+ * viewer adds nothing to the shared URL.
527
+ */
528
+ trackHeights: stripDefault(types.map(types.number), {}),
529
+ /**
530
+ * #property
531
+ * tracks supplied as data: per-column values drawn as bars, or a
532
+ * per-column string drawn as a text track. See docs/layers.md
275
533
  */
276
534
  columnTracks: stripDefault(types.array(types.frozen()), []),
277
535
  /**
278
536
  * #property
279
- * which residue of which structure each row's residues are, as data.
280
- * The viewer cannot infer this -- matching a row to a structure by
281
- * sequence equality fails for a tagged construct, a truncation or a
282
- * subsequence row, and fails in the direction that looks like it
283
- * worked -- so it arrives computed. See docs/layers.md
537
+ * row-to-structure residue correspondence, computed outside the viewer
538
+ * (e.g. from SIFTS). Matching by sequence equality places a tagged
539
+ * construct, a truncation or a subsequence row on the wrong residue.
540
+ * See docs/layers.md
284
541
  */
285
542
  residueMappings: stripDefault(types.array(types.frozen()), []),
286
543
  /**
@@ -296,10 +553,9 @@ function stateModelFactory() {
296
553
  /**
297
554
  * #property
298
555
  * the user's explicit hide choices per annotation accession, keyed by
299
- * accession with the value meaning "off", the same shape as
300
- * `turnedOffTracks`. An accession the user has never touched is absent
301
- * and drawn, so a file of two hundred domain types adds nothing to the
302
- * shared URL until someone filters one out
556
+ * accession with the value meaning "off", like `turnedOffTracks`. An
557
+ * untouched accession is absent and drawn, so the shared URL grows
558
+ * only with the user's filters
303
559
  */
304
560
  turnedOffFeatures: stripDefault(types.map(types.boolean), {}),
305
561
  /**
@@ -320,24 +576,53 @@ function stateModelFactory() {
320
576
  * labeled highlights in 1-based inclusive coordinates: a column span
321
577
  * `{start, end}`, a residue span `{row, start, end}` of a named row,
322
578
  * or a row set `{rows}`, each with an optional `label` and `color`.
323
- * Persists in the snapshot, so a computed answer travels in the URL.
579
+ * Persists in the snapshot and the URL.
324
580
  */
325
581
  highlights: stripDefault(types.array(types.frozen()), []),
582
+ /**
583
+ * #property
584
+ * clades of the tree with a mark drawn over them. `mrca` names tips
585
+ * whose common ancestor is the clade, or `range` its first and last
586
+ * tip in display order, and `tips` is the leaf count the producer
587
+ * measured. `mark` is `highlight`, `bracket`, `collapse` or `focus`.
588
+ * See docs/layers.md
589
+ */
590
+ clades: stripDefault(types.array(types.frozen()), []),
591
+ /**
592
+ * #property
593
+ * what the viewer's own marks read from `rowData`:
594
+ * `{channel, field, scale?}` per channel, where `channel` is
595
+ * `tipLabel` or `rowTint`. See docs/layers.md
596
+ */
597
+ encodings: stripDefault(types.array(types.frozen()), []),
598
+ /**
599
+ * #property
600
+ * panels drawn between the tree and the alignment:
601
+ * `{kind: "strip", field, scale?, width?, header?}` colors one cell
602
+ * per row from a `rowData` field, and
603
+ * `{kind: "features", x, encoding?, transform?, width?, header?}`
604
+ * draws the spans the GFF carries. See docs/layers.md
605
+ */
606
+ rowPanels: stripDefault(types.array(types.frozen()), []),
326
607
  }))
327
608
  .volatile(() => ({
328
609
  /**
329
610
  * #volatile
330
611
  */
331
612
  headerHeight: 0,
613
+ /**
614
+ * #volatile
615
+ * leaves the toolbar out, for a host drawing its own controls. Kept out
616
+ * of the snapshot so a link opened in the full app shows the toolbar.
617
+ */
618
+ hideHeader: false,
332
619
  /**
333
620
  * #volatile
334
621
  */
335
622
  status: undefined,
336
623
  /**
337
624
  * #volatile
338
- * high resolution scale factor, helps make canvas look better on hi-dpi
339
- * screens. derived from the device pixel ratio so canvases are crisp on
340
- * retina/4k displays and not needlessly oversized on standard ones
625
+ * canvas scale factor, from the device pixel ratio
341
626
  */
342
627
  highResScaleFactor: typeof window === 'undefined' ? 1 : window.devicePixelRatio,
343
628
  /**
@@ -394,40 +679,14 @@ function stateModelFactory() {
394
679
  highlightedColumns: undefined,
395
680
  /**
396
681
  * #volatile
397
- * transient highlights keyed by who asked for them. One slot cannot hold
398
- * two sources -- a structure viewer's hover and a genome view's hover
399
- * both want to point at a column, and with one slot whoever clears last
400
- * erases the other's. Keyed by owner, each source adds and removes only
401
- * its own. Not persisted: a hover is not part of the document.
682
+ * transient highlights keyed by owner, so a structure viewer's hover and
683
+ * a genome view's hover each clear only their own. Not persisted.
402
684
  */
403
685
  transientHighlights: {},
404
686
  /**
405
687
  * #volatile
406
688
  */
407
689
  minimapHeight: 56,
408
- /**
409
- * #volatile
410
- */
411
- conservationTrackHeight: 40,
412
- /**
413
- * #volatile
414
- * heights of individual `columnTracks`, by track id. A data track is
415
- * resized on its own: the shared per-kind heights below belong to the
416
- * tracks the viewer computes, and dragging a data track's handle used to
417
- * resize those instead.
418
- */
419
- columnTrackHeights: {},
420
- /**
421
- * #volatile
422
- * taller than the conservation track by default: the logo spends its
423
- * height on stacked glyphs, and a 40px stack of four residues leaves each
424
- * one too short to identify
425
- */
426
- sequenceLogoTrackHeight: 80,
427
- /**
428
- * #volatile
429
- */
430
- arcTrackHeight: 50,
431
690
  /**
432
691
  * #volatile
433
692
  */
@@ -439,33 +698,28 @@ function stateModelFactory() {
439
698
  error: undefined,
440
699
  /**
441
700
  * #volatile
442
- * load problems the view carried on through: an optional layer that did
443
- * not arrive, an overlay that did not parse. `error` is the other kind --
444
- * it replaces the view, which is right for the alignment and wrong for a
445
- * decorative file
701
+ * non-fatal load problems: an optional layer that failed to load, an
702
+ * overlay that failed to parse. `error` replaces the view and is for the
703
+ * alignment itself
446
704
  */
447
705
  warnings: [],
448
706
  /**
449
707
  * #volatile
450
- * bumped by reset(). The React error boundary above the view keeps its
451
- * caught error until it is remounted, so "Return to import form" did
452
- * nothing after a render error until this became its key
708
+ * bumped by reset(). The error boundary above the view uses it as its key,
709
+ * since the boundary keeps its caught error until remounted
453
710
  */
454
711
  resetCount: 0,
455
712
  /**
456
713
  * #volatile
457
- * set by a host that restores the loaded documents by its own means --
458
- * a jbrowse session that holds them, a page that refetches them on load.
459
- * `unshareableData` then reports nothing, since what it warns about is a
460
- * link that opens empty, and under such a host the link does not
714
+ * set by a host that restores the loaded documents itself, such as a
715
+ * jbrowse session or a page that refetches them. `unshareableData` then
716
+ * reports nothing
461
717
  */
462
718
  hostCarriesData: false,
463
719
  /**
464
720
  * #volatile
465
- * overlay annotations drawn on the alignment, whatever their source.
466
- * Every source -- InterProScan, GFF, a user upload -- converts to this
467
- * flat list before it reaches the model, so nothing downstream of here
468
- * knows which one it came from
721
+ * overlay annotations drawn on the alignment. InterProScan JSON, GFF and
722
+ * user uploads all convert to this flat list
469
723
  */
470
724
  annotations: [],
471
725
  }))
@@ -511,8 +765,8 @@ function stateModelFactory() {
511
765
  },
512
766
  /**
513
767
  * #action
514
- * high-res scale factor, tracks the device pixel ratio so canvases stay
515
- * crisp when the window moves between monitors or the browser zooms
768
+ * update the canvas scale factor when the device pixel ratio changes
769
+ * (moving between monitors, browser zoom)
516
770
  */
517
771
  setHighResScaleFactor(arg) {
518
772
  self.highResScaleFactor = arg;
@@ -533,8 +787,8 @@ function stateModelFactory() {
533
787
  },
534
788
  /**
535
789
  * #action
536
- * report something the view survived: a layer that failed to load, a
537
- * file that failed to parse
790
+ * record a non-fatal load problem: a layer that failed to load, a file
791
+ * that failed to parse
538
792
  */
539
793
  addWarning(warning) {
540
794
  self.warnings = [...self.warnings, warning];
@@ -548,7 +802,7 @@ function stateModelFactory() {
548
802
  /**
549
803
  * #action
550
804
  * declare that this host restores the loaded documents itself, which
551
- * takes down the "Not in the link" warning. See `hostCarriesData`
805
+ * hides the "Not in the link" warning. See `hostCarriesData`
552
806
  */
553
807
  setHostCarriesData(arg) {
554
808
  self.hostCarriesData = arg;
@@ -557,9 +811,9 @@ function stateModelFactory() {
557
811
  * #action
558
812
  * set mouse position (row, column) in the MSA
559
813
  *
560
- * PUBLIC API: a host drives this (and reads the `mouseCol` volatile) to
561
- * sync the alignment's hover with a view of its own -- a genome view, a
562
- * 3D structure. Keep the name and signature stable.
814
+ * Public API: a host calls this (and reads `mouseCol`) to sync hover with
815
+ * its own view, such as a genome view or 3D structure. Keep the name and
816
+ * signature stable.
563
817
  */
564
818
  setMousePos(col, row) {
565
819
  self.mouseCol = col;
@@ -569,9 +823,9 @@ function stateModelFactory() {
569
823
  * #action
570
824
  * set highlighted columns
571
825
  *
572
- * PUBLIC API: jbrowse-plugin-msaview calls this from its
573
- * afterCreateAutoruns to highlight alignment columns, and MSAViewer
574
- * passes its `highlightColumns` prop through it. Not dead code.
826
+ * Public API: jbrowse-plugin-msaview calls this from its
827
+ * afterCreateAutoruns, and MSAViewer passes its `highlightColumns` prop
828
+ * through it.
575
829
  */
576
830
  setHighlightedColumns(columns) {
577
831
  self.highlightedColumns = columns;
@@ -584,10 +838,15 @@ function stateModelFactory() {
584
838
  },
585
839
  /**
586
840
  * #action
587
- * show `highlights` on behalf of `owner`, replacing whatever that owner
588
- * showed before and leaving every other owner's alone. The object is
589
- * replaced rather than mutated so one assignment is the observable
590
- * change.
841
+ * replace the clades the viewer marks (see docs/layers.md)
842
+ */
843
+ setClades(clades) {
844
+ self.clades.replace(clades);
845
+ },
846
+ /**
847
+ * #action
848
+ * show `highlights` for `owner`, replacing that owner's previous ones and
849
+ * leaving other owners' in place
591
850
  */
592
851
  applyHighlight(owner, highlights) {
593
852
  self.transientHighlights = {
@@ -597,7 +856,7 @@ function stateModelFactory() {
597
856
  },
598
857
  /**
599
858
  * #action
600
- * drop what `owner` was showing, leaving every other owner's in place
859
+ * remove `owner`'s highlights, leaving other owners' in place
601
860
  */
602
861
  clearHighlight(owner) {
603
862
  if (owner in self.transientHighlights) {
@@ -649,10 +908,9 @@ function stateModelFactory() {
649
908
  },
650
909
  /**
651
910
  * #action
652
- * switch to another alignment of a multi-alignment file (Stockholm). The
653
- * new alignment has its own rows and its own tree, so everything naming
654
- * the old one's -- the collapsed node ids, the subtree in focus, the
655
- * reference row, the scroll position -- goes with it
911
+ * switch to another alignment of a multi-alignment file (Stockholm).
912
+ * Clears the collapsed node ids, the subtree in focus, the reference row
913
+ * and the scroll position, which all refer to the previous alignment
656
914
  */
657
915
  setCurrentAlignment(n) {
658
916
  if (n === self.currentAlignment) {
@@ -739,11 +997,10 @@ function stateModelFactory() {
739
997
  },
740
998
  /**
741
999
  * #action
742
- * keep the GFF text the way the alignment and the tree are kept, rather
743
- * than only its parsed annotations. The annotations are volatile, so a
744
- * file opened from disk used to leave no trace in the snapshot at all --
745
- * not the text, and not the filehandle, which is cleared once a blob is
746
- * read. An autorun parses this back into annotations.
1000
+ * store the GFF text in the snapshot like the alignment and tree. The
1001
+ * parsed annotations are volatile and a blob filehandle is cleared once
1002
+ * read, so the text is the only persisted copy. An autorun parses it
1003
+ * into annotations.
747
1004
  */
748
1005
  setGFF(result) {
749
1006
  self.data.setGFF(result);
@@ -772,16 +1029,14 @@ function stateModelFactory() {
772
1029
  },
773
1030
  /**
774
1031
  * #getter
775
- * whether this host brings the loaded documents back by means the
776
- * snapshot cannot see, which is what decides whether `unshareableData`
777
- * has anything to warn about.
1032
+ * whether the host restores the loaded documents outside the snapshot.
1033
+ * When true, `unshareableData` is empty.
778
1034
  *
779
- * A simple host flips the `hostCarriesData` volatile. A host whose
780
- * answer depends on how the view was opened overrides this getter in a
781
- * `.views` block of its own composed model -- jbrowse-plugin-msaview's
782
- * indexed-location views refetch from a URL the session holds, while its
783
- * data-store views really are absent from a link someone pastes
784
- * elsewhere. `unshareableData` reads it off `self`, so an override wins.
1035
+ * A simple host sets `hostCarriesData`. A host where this depends on how
1036
+ * the view was opened overrides the getter in its own composed model's
1037
+ * `.views` block; jbrowse-plugin-msaview's indexed-location views refetch
1038
+ * from a URL the session holds, while its data-store views do not.
1039
+ * `unshareableData` reads it off `self`, so an override takes effect.
785
1040
  */
786
1041
  get hostRestoresData() {
787
1042
  return self.hostCarriesData;
@@ -804,8 +1059,8 @@ function stateModelFactory() {
804
1059
  * #getter
805
1060
  */
806
1061
  get colorScheme() {
807
- // colorSchemeName is a free string (menus, snapshots, URL params); fall
808
- // back to the default rather than returning undefined on a stale name
1062
+ // colorSchemeName is a free string (menus, snapshots, URL params), so a
1063
+ // stale name falls back to the default
809
1064
  return (colorSchemes[self.colorSchemeName] ??
810
1065
  colorSchemes[defaultColorSchemeName]);
811
1066
  },
@@ -832,29 +1087,23 @@ function stateModelFactory() {
832
1087
  },
833
1088
  /**
834
1089
  * #getter
835
- * the loaded documents this view's own snapshot cannot carry, largest
836
- * first. A file opened from disk or pasted in becomes inline text, and
837
- * DataModel drops an inline document past `maxInlineSnapshotBytes`
838
- * rather than put megabytes of sequence into a session or a URL.
1090
+ * loaded documents left out of the snapshot, largest first. A file opened
1091
+ * from disk or pasted in becomes inline text, and DataModel drops an
1092
+ * inline document past `maxInlineSnapshotBytes`.
839
1093
  *
840
- * Dropping it is right. Dropping it silently is what makes a copied link
841
- * open an empty viewer, so the header says so and the standalone app
842
- * stops rewriting the address bar while this is non-empty. A document
843
- * fetched from a URL never appears here whatever its size: the snapshot
844
- * keeps the filehandle and refetches through it.
1094
+ * The header lists these, and the standalone app stops rewriting the
1095
+ * address bar while the list is non-empty, so a copied link does not
1096
+ * open an empty viewer unannounced. A document fetched from a URL never
1097
+ * appears here, since the snapshot keeps its filehandle.
845
1098
  *
846
- * Nothing is unshareable when the host restores the data by its own
847
- * means (see `hostRestoresData`) -- inside a session that reloads these
848
- * documents from somewhere the snapshot does not show, the warning is
849
- * simply wrong.
1099
+ * Empty when `hostRestoresData` is true.
850
1100
  */
851
1101
  get unshareableData() {
852
1102
  if (self.hostRestoresData) {
853
1103
  return [];
854
1104
  }
855
1105
  const { data } = self;
856
- // a data track past the limit leaves the snapshot the same way an
857
- // inline document does, and left unreported the same way too
1106
+ // data tracks past the limit also leave the snapshot
858
1107
  const trackBytes = columnTrackSizes(self.columnTracks)
859
1108
  .filter(bytes => bytes > maxInlineSnapshotBytes)
860
1109
  .reduce((a, b) => a + b, 0);
@@ -875,13 +1124,14 @@ function stateModelFactory() {
875
1124
  },
876
1125
  /**
877
1126
  * #getter
878
- * extra per-row attributes, keyed by row name. Parsed defensively: the
879
- * source is a user-supplied document (treeMetadataFilehandle, or a
880
- * session snapshot), and this computed is read by labelWidthMap on every
881
- * layout, so a malformed file would otherwise throw out of rendering and
882
- * take the whole view down over a decorative field.
1127
+ * the row table: extra fields per row, keyed by row name, which the
1128
+ * `encodings` channels read. It is stored as the JSON string
1129
+ * `data.treeMetadata`, the name that travels in existing links, so the
1130
+ * inline size limit and `treeMetadataFilehandle` cover it. labelWidthMap
1131
+ * reads it on every layout, so a malformed user-supplied file returns {}
1132
+ * instead of throwing out of rendering.
883
1133
  */
884
- get treeMetadata() {
1134
+ get rowData() {
885
1135
  const text = self.data.treeMetadata;
886
1136
  if (!text) {
887
1137
  return {};
@@ -893,10 +1143,31 @@ function stateModelFactory() {
893
1143
  : {};
894
1144
  }
895
1145
  catch (e) {
896
- console.error('failed to parse treeMetadata', e);
1146
+ console.error('failed to parse rowData', e);
897
1147
  return {};
898
1148
  }
899
1149
  },
1150
+ /**
1151
+ * #method
1152
+ * one row's fields, the single reader of the row table
1153
+ */
1154
+ rowDataOf(name) {
1155
+ return this.rowData[name];
1156
+ },
1157
+ /**
1158
+ * #getter
1159
+ * the field names the row table carries, sorted, for a producer or a UI
1160
+ * choosing one to encode
1161
+ */
1162
+ get rowFields() {
1163
+ const fields = new Set();
1164
+ for (const row of Object.values(this.rowData)) {
1165
+ for (const field of Object.keys(row ?? {})) {
1166
+ fields.add(field);
1167
+ }
1168
+ }
1169
+ return [...fields].sort((a, b) => a.localeCompare(b));
1170
+ },
900
1171
  /**
901
1172
  * #getter
902
1173
  */
@@ -942,6 +1213,33 @@ function stateModelFactory() {
942
1213
  get rowNamesSet() {
943
1214
  return new Map(this.leaves.map((leaf, index) => [leaf.data.name, index]));
944
1215
  },
1216
+ /**
1217
+ * #getter
1218
+ * `clades` resolved to the rows each one covers. The tip names resolve
1219
+ * against `tree` rather than `root`, so a clade whose ancestor the user
1220
+ * collapsed keeps its rows. One leaf pass over the tree serves every
1221
+ * clade. A `range` record names no node, so `collapse` and `focus`, which
1222
+ * need one, drop it.
1223
+ */
1224
+ get resolvedClades() {
1225
+ if (self.clades.length === 0) {
1226
+ return noClades;
1227
+ }
1228
+ return resolveClades(self.clades, hierarchy(this.tree, d => d.children), this.rowNamesSet);
1229
+ },
1230
+ /**
1231
+ * #getter
1232
+ * the pixel column reserved at the right of the tree area for the bracket
1233
+ * mark, which the tip labels and the tree itself stay clear of. Zero
1234
+ * where no clade draws a bar or a label.
1235
+ */
1236
+ get cladeGutterWidth() {
1237
+ return cladeGutterWidth({
1238
+ clades: this.resolvedClades,
1239
+ rowHeight: self.rowHeight,
1240
+ fontSize: this.fontSize,
1241
+ });
1242
+ },
945
1243
  /**
946
1244
  * #getter
947
1245
  */
@@ -974,40 +1272,128 @@ function stateModelFactory() {
974
1272
  * #getter
975
1273
  */
976
1274
  get root() {
977
- let hier = hierarchy(this.tree, d => d.children);
978
- hierarchySum(hier, d => (d.children.length > 0 ? 0 : 1));
979
- sort(hier, (a, b) => (a.data.length ?? 1) - (b.data.length ?? 1));
980
- if (self.showOnly) {
981
- const res = find(hier, n => n.data.id === self.showOnly);
982
- if (res) {
983
- hier = res;
984
- }
1275
+ return buildTreeRoot(this.tree, self.collapsed, self.showOnly);
1276
+ },
1277
+ /**
1278
+ * #getter
1279
+ * height of the band the tree overview draws in, zero when it is off
1280
+ */
1281
+ get treeOverviewHeight() {
1282
+ return self.showTreeOverview ? self.overviewHeight : 0;
1283
+ },
1284
+ /**
1285
+ * #getter
1286
+ * the whole tree laid out for the overview, or undefined when the
1287
+ * overview is off. The focus is left out, so the focused subtree draws
1288
+ * inside the whole tree, and the collapsed clades are folded, since
1289
+ * those are rows the view no longer has. `x` is in tip-index space and
1290
+ * `len` is a fraction of the root-to-tip length, so one layout serves
1291
+ * any band size.
1292
+ */
1293
+ get treeOverviewLayout() {
1294
+ if (!self.showTreeOverview) {
1295
+ return undefined;
985
1296
  }
986
- for (const collapsedId of self.collapsed) {
987
- const node = find(hier, n => n.data.id === collapsedId);
988
- if (node) {
989
- if (node.children) {
990
- collapse(node);
991
- }
992
- else if (node.parent?.children) {
993
- node.parent.children = node.parent.children.filter(c => c.data.id !== collapsedId);
994
- }
995
- }
1297
+ const root = buildTreeRoot(this.tree, self.collapsed);
1298
+ const numTips = leaves(root).length;
1299
+ clusterLayout(root, numTips, 1);
1300
+ const rootLen = Math.max(root.data.length || 0, 0);
1301
+ const extent = maxLength(root) - rootLen;
1302
+ setBrLength(root, -rootLen, extent ? 1 / extent : 0);
1303
+ return {
1304
+ root,
1305
+ numTips,
1306
+ maxDepthToLeaf: calcDepthToLeaf(root),
1307
+ showBranchLen: self.showBranchLen && extent > 0,
1308
+ };
1309
+ },
1310
+ /**
1311
+ * #getter
1312
+ * the `clades` highlights in the overview's own row space, which the
1313
+ * focus does not narrow
1314
+ */
1315
+ get treeOverviewClades() {
1316
+ const layout = this.treeOverviewLayout;
1317
+ if (!layout || self.clades.length === 0) {
1318
+ return noClades;
1319
+ }
1320
+ const rowNames = new Map(leaves(layout.root).map((leaf, index) => [leaf.data.name, index]));
1321
+ return resolveClades(self.clades, layout.root, rowNames);
1322
+ },
1323
+ /**
1324
+ * #getter
1325
+ * the inclusive tip rows the focused subtree covers in the overview,
1326
+ * which is the box drawn on it. undefined with no focus
1327
+ */
1328
+ get treeOverviewFocusRows() {
1329
+ const layout = this.treeOverviewLayout;
1330
+ if (!layout || !self.showOnly) {
1331
+ return undefined;
1332
+ }
1333
+ const node = find(layout.root, n => n.data.id === self.showOnly);
1334
+ return node ? tipRange(node) : undefined;
1335
+ },
1336
+ /**
1337
+ * #method
1338
+ * the subtree a point `y` pixels down the tree overview picks: the
1339
+ * deepest one whose tip range covers every row under that pixel, with
1340
+ * the rows it covers. A pixel stands for several tips on a large tree,
1341
+ * which is what keeps the pick off the individual tips. undefined when
1342
+ * the overview is off or the point picks the whole tree.
1343
+ */
1344
+ treeOverviewHit(y) {
1345
+ const layout = this.treeOverviewLayout;
1346
+ if (!layout) {
1347
+ return undefined;
996
1348
  }
997
- return hier;
1349
+ const { root, numTips } = layout;
1350
+ const perPixel = numTips / self.overviewHeight;
1351
+ const first = clamp(Math.floor(y * perPixel), 0, numTips - 1);
1352
+ const last = clamp(Math.ceil((y + 1) * perPixel) - 1, first, numTips - 1);
1353
+ let node = nodeCoveringRows(root, first + 0.5, last + 0.5);
1354
+ // focusing one tip leaves a single row on screen, so the pick lifts to
1355
+ // the subtree that tip sits in
1356
+ while (!node.children && node.parent) {
1357
+ node = node.parent;
1358
+ }
1359
+ return node === root
1360
+ ? undefined
1361
+ : { id: node.data.id, rows: tipRange(node) };
998
1362
  },
999
1363
  /**
1000
1364
  * #getter
1001
- * widget width minus the tree area gives the space for the MSA
1365
+ * the pixel column the row panels occupy between the tree and the
1366
+ * alignment, the sum of each record's width
1367
+ */
1368
+ get rowPanelsWidth() {
1369
+ return sum(self.rowPanels.map(p => rowPanelWidth(p, self.rowHeight)));
1370
+ },
1371
+ /**
1372
+ * #getter
1373
+ * height of the band the row panel headers draw in, which is zero with
1374
+ * no row panels and leaves the top area as it was
1375
+ */
1376
+ get rowPanelsHeaderHeight() {
1377
+ return self.rowPanels.length > 0 ? rowPanelHeaderHeight : 0;
1378
+ },
1379
+ /**
1380
+ * #getter
1381
+ * widget width minus the tree area and the row panels gives the space
1382
+ * for the MSA
1002
1383
  */
1003
1384
  get msaAreaWidth() {
1004
- return self.width - self.treeAreaWidth - self.resizeHandleWidth;
1385
+ return (self.width -
1386
+ self.treeAreaWidth -
1387
+ this.rowPanelsWidth -
1388
+ self.resizeHandleWidth);
1005
1389
  },
1006
1390
  /**
1007
1391
  * #getter
1392
+ * the right edge the tip labels end at, which is the tree area less the
1393
+ * margin and the bracket gutter
1008
1394
  */
1009
1395
  get treeAreaWidthMinusMargin() {
1010
- return self.treeAreaWidth - self.marginLeft;
1396
+ return self.treeAreaWidth - self.marginLeft - this.cladeGutterWidth;
1011
1397
  },
1012
1398
  /**
1013
1399
  * #getter
@@ -1077,10 +1463,8 @@ function stateModelFactory() {
1077
1463
  },
1078
1464
  /**
1079
1465
  * #getter
1080
- * number of rows the alignment occupies on screen. This is the leaf count,
1081
- * not `rows.length`: a tree leaf with no matching MSA row still takes up a
1082
- * row of vertical space (drawn blank), so row hit-testing and fit-to-height
1083
- * must count it.
1466
+ * number of rows on screen: the leaf count, which includes tree leaves
1467
+ * with no matching MSA row (drawn blank), unlike `rows.length`.
1084
1468
  */
1085
1469
  get numRows() {
1086
1470
  return this.leaves.length;
@@ -1088,12 +1472,8 @@ function stateModelFactory() {
1088
1472
  /**
1089
1473
  * #method
1090
1474
  * index of the global column holding each ungapped sequence position of a
1091
- * row, so seqPos -> column is a lookup rather than a scan. The domain
1092
- * overlay resolves thousands of these per redraw.
1093
- *
1094
- * Built per row, on the row asked for: the first lookup used to index
1095
- * every row in the alignment. The cache is keyed on the parse the rows
1096
- * came from, so a new alignment brings a new one.
1475
+ * row. The domain overlay resolves thousands of these per redraw. Built
1476
+ * lazily per row and cached on the parse.
1097
1477
  */
1098
1478
  seqPosIndex(rowName) {
1099
1479
  const MSA = this.MSA;
@@ -1118,10 +1498,9 @@ function stateModelFactory() {
1118
1498
  },
1119
1499
  /**
1120
1500
  * #getter
1121
- * every sequence the alignment holds, keyed by row name, whatever the
1122
- * tree currently shows. `rows` is the rows on screen; this is the rows
1123
- * that exist, and every lookup about a named row goes through it --
1124
- * collapsing a clade hides rows, it does not delete their sequence
1501
+ * every sequence in the alignment, keyed by row name, including rows a
1502
+ * collapsed clade hides. `rows` holds only the rows on screen; lookups
1503
+ * by row name use this
1125
1504
  */
1126
1505
  get rowMap() {
1127
1506
  const MSA = this.MSA;
@@ -1254,10 +1633,8 @@ function stateModelFactory() {
1254
1633
  clusterLayout(r, this.totalHeight, self.treeWidth);
1255
1634
  const max = this.rootToTipLength;
1256
1635
  const k = max ? self.treeWidth / max : 0;
1257
- // the displayed root starts at x=0 whatever branch length it carries,
1258
- // so its own length is subtracted here rather than zeroed on the parsed
1259
- // node -- `root` hands out the cached parse, and writing to it made
1260
- // showOnly shorten that branch for good
1636
+ // the displayed root starts at x=0, so subtract its length here; `root`
1637
+ // returns the cached parse, which must not be mutated
1261
1638
  setBrLength(r, -Math.max(r.data.length || 0, 0), k);
1262
1639
  // for each collapsed clade, record the pixel x-position of its farthest
1263
1640
  // tip so the renderer can draw a triangle spanning the branch-length
@@ -1293,19 +1670,16 @@ function stateModelFactory() {
1293
1670
  },
1294
1671
  /**
1295
1672
  * #getter
1296
- * x-position of the farthest tip in a phylogram, px. The layout scales
1297
- * the longest root-to-tip path onto treeWidth, so that is where it lands
1298
- * -- and 0 for a tree carrying no lengths at all, which draws as a
1299
- * cladogram instead
1673
+ * x-position of the farthest tip in a phylogram, px: treeWidth, or 0 for
1674
+ * a tree with no branch lengths (drawn as a cladogram)
1300
1675
  */
1301
1676
  get maxBranchLength() {
1302
1677
  return this.rootToTipLength ? self.treeWidth : 0;
1303
1678
  },
1304
1679
  /**
1305
1680
  * #getter
1306
- * pixels per unit of branch length in the current phylogram layout, and 0
1307
- * in cladogram mode, where the x-positions carry no length at all. The
1308
- * scale bar over the tree is drawn from it.
1681
+ * pixels per unit of branch length in the phylogram layout, 0 in
1682
+ * cladogram mode. The tree's scale bar uses it.
1309
1683
  */
1310
1684
  get pxPerBranchLength() {
1311
1685
  const max = maxLength(this.root);
@@ -1362,20 +1736,17 @@ function stateModelFactory() {
1362
1736
  * #getter
1363
1737
  */
1364
1738
  get labelWidthMap() {
1365
- const { showTreeText, leaves, treeMetadata } = self;
1366
- // gated on the same condition the renderer draws labels under, so the
1367
- // gutter labelsWidth reserves and the labels actually drawn cannot
1368
- // disagree -- and so turning labels off hands their space to the tree.
1369
- // Measured at a fixed reference size and scaled by labelWidthScale:
1370
- // re-measuring every leaf on every vertical-zoom frame cost ~200ms on a
1739
+ const { showTreeText, leaves } = self;
1740
+ // gated on the renderer's label condition, so hidden labels reserve no
1741
+ // gutter. Measured once at a reference size and scaled by
1742
+ // labelWidthScale: re-measuring per vertical-zoom frame cost ~200ms on a
1371
1743
  // 50k-leaf tree
1372
1744
  return showTreeText
1373
1745
  ? new Map(leaves.map(node => {
1374
1746
  const { name } = node.data;
1375
1747
  // `||`, matching renderTreeLabels: an empty genome falls back
1376
- // to the row name, and measuring '' would size the gutter (and
1377
- // the label's click target) to nothing
1378
- const displayName = treeMetadata[name]?.genome || name;
1748
+ // to the row name
1749
+ const displayName = self.rowDataOf(name)?.genome || name;
1379
1750
  return [
1380
1751
  name,
1381
1752
  measureTextCanvas(displayName, labelReferenceFontSize),
@@ -1392,11 +1763,9 @@ function stateModelFactory() {
1392
1763
  return self.fontSize / labelReferenceFontSize;
1393
1764
  },
1394
1765
  get labelsWidth() {
1395
- // a loop, not Math.max(...widths.values()): spreading a map of every
1396
- // leaf passes one argument per row, and the argument limit is somewhere
1397
- // around 125k -- so the bundled 230k-tip COVID tree threw
1398
- // "RangeError: Maximum call stack size exceeded" out of a getter the
1399
- // treeWidth autorun reads on load
1766
+ // a loop, not Math.max(...): spreading passes one argument per leaf,
1767
+ // and the ~125k argument limit throws RangeError on the 230k-tip COVID
1768
+ // tree
1400
1769
  let max = 0;
1401
1770
  for (const width of this.labelWidthMap.values()) {
1402
1771
  if (width > max) {
@@ -1419,9 +1788,8 @@ function stateModelFactory() {
1419
1788
  },
1420
1789
  /**
1421
1790
  * #getter
1422
- * the base pairs of the consensus secondary structure, as arcs. The WUSS
1423
- * string is collapsed through the hidden columns before it is parsed, so
1424
- * the pairs land in the same visible column space the text track does
1791
+ * the base pairs of the consensus secondary structure, as arcs, in
1792
+ * visible column space (hidden columns are removed before parsing)
1425
1793
  */
1426
1794
  get secondaryStructureArcs() {
1427
1795
  const { blanks, hideGapsEffective } = self;
@@ -1442,9 +1810,8 @@ function stateModelFactory() {
1442
1810
  const { MSA, hideGapsEffective, blanks } = self;
1443
1811
  const tracks = (MSA?.tracks ?? []).filter(t => !!t.data);
1444
1812
  if (tracks.length === 0) {
1445
- // reading rowHeight up front made every zoom frame rebuild the track
1446
- // list, and the canvases redraw on the track object they are handed
1447
- // changing
1813
+ // return before reading rowHeight, so zooming does not rebuild the
1814
+ // list and redraw every track canvas
1448
1815
  return [];
1449
1816
  }
1450
1817
  const { rowHeight } = self;
@@ -1481,11 +1848,9 @@ function stateModelFactory() {
1481
1848
  return out;
1482
1849
  };
1483
1850
  const skip = (items) => hideGapsEffective ? dropBlanks(blanks, items) : items;
1484
- // an arc names two positions rather than one per column, so it takes
1485
- // the same two steps the arrays take -- a row's residues onto columns,
1486
- // then columns onto the visible ones -- as a lookup. visibleColsBefore,
1487
- // not globalColToVisibleCol: an endpoint in a hidden column collapses
1488
- // to where that column went instead of taking the whole arc with it
1851
+ // an arc endpoint maps row residue -> column -> visible column.
1852
+ // visibleColsBefore, not globalColToVisibleCol, so an endpoint in a
1853
+ // hidden column moves to the neighboring visible one and the arc stays
1489
1854
  const resolve = (track, pos) => {
1490
1855
  const col = track.row
1491
1856
  ? self.seqPosIndex(track.row)?.[pos - 1]
@@ -1518,45 +1883,48 @@ function stateModelFactory() {
1518
1883
  }));
1519
1884
  },
1520
1885
  /**
1521
- * #getter
1886
+ * #method
1887
+ * the height a track draws at: what the user dragged its divider to,
1888
+ * then the height its snapshot asked for, then its kind's default. Only
1889
+ * a text track falls through to rowHeight, and `??` short-circuits
1890
+ * before reading it, so vertical zoom does not rebuild the other tracks
1522
1891
  */
1523
- get columnTrackModels() {
1524
- // read per kind, not up front: a text track is the only kind sized by
1525
- // the row height, and reading it here rebuilt every data track on every
1526
- // vertical zoom step
1527
- const defaultHeight = (kind) => kind === 'bar'
1528
- ? self.conservationTrackHeight
1529
- : kind === 'arc'
1530
- ? self.arcTrackHeight
1531
- : self.rowHeight;
1532
- return self.columnTracks.map(track => ({
1533
- model: {
1534
- id: track.id,
1535
- name: track.name,
1536
- kind: track.kind,
1537
- height: self.columnTrackHeights[track.id] ??
1538
- track.height ??
1539
- defaultHeight(track.kind),
1540
- // the spec has one `color`; bar and arc are separate track models
1541
- // that read it under their own name
1542
- barColor: track.color,
1543
- arcColor: track.color,
1544
- customColorScheme: track.colors,
1545
- data: this.columnTrackContent.get(track.id)?.data,
1546
- arcs: this.columnTrackContent.get(track.id)?.arcs,
1547
- },
1548
- ReactComponent: TrackBlocks,
1549
- }));
1892
+ trackHeight(kind, heightKey = kind, given) {
1893
+ return (self.trackHeights.get(heightKey) ??
1894
+ given ??
1895
+ defaultTrackHeights[kind] ??
1896
+ self.rowHeight);
1550
1897
  },
1551
1898
  /**
1552
1899
  * #getter
1553
1900
  */
1901
+ get columnTrackModels() {
1902
+ return self.columnTracks.map(track => {
1903
+ const heightKey = resizableKinds.has(track.kind)
1904
+ ? ownHeightKey(track.id)
1905
+ : undefined;
1906
+ return {
1907
+ model: {
1908
+ id: track.id,
1909
+ name: track.name,
1910
+ kind: track.kind,
1911
+ heightKey,
1912
+ height: this.trackHeight(track.kind, heightKey, track.height),
1913
+ barColor: track.color,
1914
+ arcColor: track.color,
1915
+ customColorScheme: track.colors,
1916
+ data: this.columnTrackContent.get(track.id)?.data,
1917
+ arcs: this.columnTrackContent.get(track.id)?.arcs,
1918
+ },
1919
+ ReactComponent: TrackBlocks,
1920
+ };
1921
+ });
1922
+ },
1554
1923
  /**
1555
1924
  * #getter
1556
- * the consensus secondary structure as a track, when there is one. Its
1557
- * own getter so the object keeps its identity across a zoom: the canvas
1558
- * redraws on the track it is handed changing, and rebuilding these
1559
- * alongside everything else made every zoom frame redraw every track
1925
+ * the consensus secondary structure as a track, when there is one. A
1926
+ * separate getter keeps the object stable across zoom, so its canvas
1927
+ * does not redraw
1560
1928
  */
1561
1929
  get basePairTrackModels() {
1562
1930
  const arcs = this.secondaryStructureArcs;
@@ -1567,7 +1935,8 @@ function stateModelFactory() {
1567
1935
  id: 'base-pairs',
1568
1936
  name: 'Base pairs',
1569
1937
  kind: 'arc',
1570
- height: self.arcTrackHeight,
1938
+ heightKey: 'arc',
1939
+ height: this.trackHeight('arc'),
1571
1940
  arcs,
1572
1941
  },
1573
1942
  ReactComponent: TrackBlocks,
@@ -1577,8 +1946,8 @@ function stateModelFactory() {
1577
1946
  },
1578
1947
  /**
1579
1948
  * #getter
1580
- * the tracks computed from the alignment itself, which depend on their
1581
- * own heights and on the alphabet -- and on nothing zoom changes
1949
+ * the tracks computed from the alignment; they depend on their heights
1950
+ * and the alphabet, not on zoom
1582
1951
  */
1583
1952
  get computedTrackModels() {
1584
1953
  return [
@@ -1586,7 +1955,6 @@ function stateModelFactory() {
1586
1955
  id: 'conservation',
1587
1956
  name: 'Conservation',
1588
1957
  kind: 'bar',
1589
- height: self.conservationTrackHeight,
1590
1958
  barColor: 'gray',
1591
1959
  },
1592
1960
  ...(self.sequenceType === 'amino'
@@ -1595,7 +1963,6 @@ function stateModelFactory() {
1595
1963
  id: 'property-conservation',
1596
1964
  name: 'Property conservation',
1597
1965
  kind: 'bar',
1598
- height: self.conservationTrackHeight,
1599
1966
  barColor: '#6a51a3',
1600
1967
  },
1601
1968
  ]
@@ -1604,23 +1971,32 @@ function stateModelFactory() {
1604
1971
  id: 'sequence-logo',
1605
1972
  name: 'Sequence logo',
1606
1973
  kind: 'logo',
1607
- height: self.sequenceLogoTrackHeight,
1608
1974
  },
1609
1975
  // last, so it sits against the alignment it numbers
1610
1976
  {
1611
1977
  id: 'position-ruler',
1612
1978
  name: 'Position',
1613
1979
  kind: 'ruler',
1614
- height: 20,
1615
1980
  },
1616
- ].map(model => ({ model, ReactComponent: TrackBlocks }));
1981
+ ].map(model => ({
1982
+ // every computed track of a kind shares that kind's height, so the
1983
+ // kind is its key
1984
+ model: {
1985
+ ...model,
1986
+ heightKey: resizableKinds.has(model.kind) ? model.kind : undefined,
1987
+ height: this.trackHeight(model.kind),
1988
+ },
1989
+ ReactComponent: TrackBlocks,
1990
+ }));
1617
1991
  },
1618
1992
  get tracks() {
1619
1993
  return [
1620
1994
  ...this.adapterTrackModels,
1621
1995
  ...this.basePairTrackModels,
1622
1996
  ...this.columnTrackModels,
1623
- ...this.computedTrackModels,
1997
+ // every computed track reads the alignment's columns, and a tree, a
1998
+ // GFF and a features panel draw a figure with none
1999
+ ...(self.numColumns > 0 ? this.computedTrackModels : []),
1624
2000
  ];
1625
2001
  },
1626
2002
  /**
@@ -1651,19 +2027,18 @@ function stateModelFactory() {
1651
2027
  * Convert a visible column to a row-specific sequence position (0-based).
1652
2028
  * Returns undefined if the position is a gap in the sequence.
1653
2029
  *
1654
- * PUBLIC API: this and the sibling coordinate converters
1655
- * (visibleColToGlobalCol, seqPosToVisibleCol, globalColToVisibleCol,
1656
- * seqPosToGlobalCol) are how a host translates between alignment columns
1657
- * and a row's residue positions across gaps. Keep them stable.
2030
+ * Public API, like the sibling converters (visibleColToGlobalCol,
2031
+ * seqPosToVisibleCol, globalColToVisibleCol, seqPosToGlobalCol) hosts
2032
+ * use to translate between columns and residue positions. Keep them
2033
+ * stable.
1658
2034
  *
1659
2035
  * @param rowName - The name of the row
1660
2036
  * @param visibleCol - The visible column index
1661
2037
  * @returns The sequence position (0-based), or undefined if it's a gap
1662
2038
  */
1663
2039
  visibleColToSeqPos(rowName, visibleCol) {
1664
- // a binary search of the row's index, not a scan of the row: this
1665
- // answers on every mouse move, and a 30k-column row scanned per event
1666
- // is the whole frame
2040
+ // binary search: this runs on every mouse move, and scanning a
2041
+ // 30k-column row per event takes the whole frame
1667
2042
  return seqPosOfGlobalCol(self.seqPosIndex(rowName), this.visibleColToGlobalCol(visibleCol));
1668
2043
  },
1669
2044
  /**
@@ -1697,10 +2072,9 @@ function stateModelFactory() {
1697
2072
  },
1698
2073
  /**
1699
2074
  * #method
1700
- * Convert a visible column index (what a mouse handler reports) back to a
1701
- * column of the full alignment. Hidden columns shift everything to their
1702
- * right, so a host that holds per-column data of its own has to make this
1703
- * hop before indexing it.
2075
+ * Convert a visible column index (what a mouse handler reports) to a
2076
+ * column of the full alignment. A host indexing its own per-column data
2077
+ * needs this when columns are hidden.
1704
2078
  *
1705
2079
  * @param visibleCol - The visible column index
1706
2080
  * @returns The global column index in the full MSA
@@ -1714,8 +2088,7 @@ function stateModelFactory() {
1714
2088
  /**
1715
2089
  * #method
1716
2090
  * Convert a sequence position (ungapped) to a global column index.
1717
- * Returns undefined for a row the alignment does not have -- answering
1718
- * anyway is how a mistyped or stale row name came to highlight column 0.
2091
+ * Returns undefined for a row name the alignment does not have.
1719
2092
  *
1720
2093
  * @param rowName - The name of the row
1721
2094
  * @param seqPos - The sequence position (0-based, ungapped)
@@ -1746,12 +2119,39 @@ function stateModelFactory() {
1746
2119
  ? undefined
1747
2120
  : this.globalColToVisibleCol(globalCol);
1748
2121
  },
2122
+ /**
2123
+ * #method
2124
+ * the visible columns a span covers, in highlight coordinates: `start`
2125
+ * and `end` are 1-based residues of `row`, or columns of the file
2126
+ * without it. A fractional position, as a zoom gesture reports one,
2127
+ * widens to the whole residue or column it falls in. A span entirely on
2128
+ * hidden columns, or naming a row the alignment lacks, gives undefined.
2129
+ */
2130
+ visibleSpan({ row, start: rawStart, end: rawEnd }) {
2131
+ const { blanks } = self;
2132
+ const start = Math.max(1, Math.floor(rawStart));
2133
+ const end = Math.ceil(rawEnd);
2134
+ let startGlobal = start - 1;
2135
+ let endGlobal = end - 1;
2136
+ if (row !== undefined) {
2137
+ const rowStart = this.seqPosToGlobalCol(row, start - 1);
2138
+ const rowEnd = this.seqPosToGlobalCol(row, end - 1);
2139
+ if (rowStart === undefined || rowEnd === undefined) {
2140
+ return undefined;
2141
+ }
2142
+ startGlobal = rowStart;
2143
+ endGlobal = rowEnd;
2144
+ }
2145
+ const startCol = this.globalColToVisibleCol(startGlobal) ??
2146
+ visibleColsBefore(blanks, startGlobal);
2147
+ const endCol = this.globalColToVisibleCol(endGlobal) ??
2148
+ visibleColsBefore(blanks, endGlobal) - 1;
2149
+ return startCol <= endCol ? { startCol, endCol } : undefined;
2150
+ },
1749
2151
  /**
1750
2152
  * #getter
1751
- * every reason a mapping is being ignored, so a host can say which. A
1752
- * mapping outlives the alignment it was computed for; when the two no
1753
- * longer agree the lookups have to refuse, and refusing invisibly is how
1754
- * "there is no structure here" gets confused with "this data is stale".
2153
+ * why each ignored residue mapping is ignored, so a host can tell a
2154
+ * missing structure from a mapping made against a different alignment.
1755
2155
  */
1756
2156
  get residueMappingProblems() {
1757
2157
  const problems = [];
@@ -1798,10 +2198,8 @@ function stateModelFactory() {
1798
2198
  },
1799
2199
  /**
1800
2200
  * #getter
1801
- * the mappings that still fit the loaded alignment. A row-level problem
1802
- * takes the whole mapping out; a single malformed segment takes only
1803
- * itself, since the rest of the mapping is still a claim about residues
1804
- * that exist.
2201
+ * the mappings that fit the loaded alignment. A row-level problem drops
2202
+ * the whole mapping; a malformed segment drops only that segment.
1805
2203
  */
1806
2204
  get usableResidueMappings() {
1807
2205
  const unusable = new Set(this.residueMappingProblems
@@ -1816,9 +2214,8 @@ function stateModelFactory() {
1816
2214
  },
1817
2215
  /**
1818
2216
  * #getter
1819
- * the structures the loaded alignment has usable mappings onto. A row can
1820
- * have several -- an experimental entry and a predicted model, say -- so
1821
- * a host that means a particular one has to name it.
2217
+ * the structures with usable mappings. A row can map onto several, such
2218
+ * as an experimental entry and a predicted model.
1822
2219
  */
1823
2220
  get mappedStructures() {
1824
2221
  return this.usableResidueMappings.map(m => ({
@@ -1828,18 +2225,12 @@ function stateModelFactory() {
1828
2225
  },
1829
2226
  /**
1830
2227
  * #method
1831
- * The structure residue a row residue is, or undefined. Refusing is the
1832
- * point: the guess this replaces answered every query, with a wrong
1833
- * residue when it did not know.
2228
+ * The structure residue for a row residue. Returns undefined when no
2229
+ * segment covers `seqPos`, or when the row maps onto several structures
2230
+ * and `structureId` does not pick one (see `mappedStructures`).
1834
2231
  *
1835
- * It also refuses when the answer is not unique. A row commonly maps onto
1836
- * several structures -- an experimental entry and two predicted models --
1837
- * and returning whichever came first would be the same class of wrong,
1838
- * quieter. Name one with `structureId`, or use `mappedStructures` to see
1839
- * what there is.
1840
- *
1841
- * Positions are 1-based, as `residueMappings` and `highlights` are --
1842
- * note that the column helpers above take 0-based ones.
2232
+ * Positions are 1-based, like `residueMappings` and `highlights`; the
2233
+ * column helpers above are 0-based.
1843
2234
  *
1844
2235
  * @param rowName - The alignment row
1845
2236
  * @param seqPos - Residue of that row, 1-based
@@ -1869,10 +2260,10 @@ function stateModelFactory() {
1869
2260
  },
1870
2261
  /**
1871
2262
  * #method
1872
- * The row residue a structure residue is, the same lookup backwards, and
1873
- * refusing on the same terms. `asymId` picks between mappings onto the
1874
- * same entry, which a homodimer -- two rows, two chains, one id -- always
1875
- * needs; without it such a lookup is ambiguous and gets nothing.
2263
+ * The row residue for a structure residue; the inverse of
2264
+ * `structureResidue`, returning undefined in the same cases. `asymId`
2265
+ * picks a chain when several mappings share an entry id, as in a
2266
+ * homodimer.
1876
2267
  *
1877
2268
  * @param structureId - The structure's id, as the mapping names it
1878
2269
  * @param position - Residue of that structure, 1-based label_seq_id
@@ -1901,16 +2292,31 @@ function stateModelFactory() {
1901
2292
  .views(self => ({
1902
2293
  /**
1903
2294
  * #getter
1904
- * the vertical space the alignment rows actually get: the widget height
1905
- * less everything stacked above and below them -- the header, the tracks,
1906
- * and the minimap when the columns overflow. Every consumer wants this
1907
- * same subtraction, so there is one of it: blocksY, maxScrollY, the
1908
- * vertical scrollbar and fitVertically all read it, and a second getter
1909
- * that forgot the tracks is what put the last rows out of reach.
2295
+ * the branch-length scale bar over the tree, undefined in cladogram mode
2296
+ * or when the tree area is too narrow for one
2297
+ */
2298
+ get treeScaleBar() {
2299
+ return scaleBarLength(self.pxPerBranchLength, self.treeAreaWidth - self.marginLeft * 2);
2300
+ },
2301
+ /**
2302
+ * #getter
2303
+ * the band across the top: the minimap over the alignment, the row panel
2304
+ * headers, and the tree overview stacked on the scale bar, as tall as the
2305
+ * tallest of the three
2306
+ */
2307
+ get topBandHeight() {
2308
+ return Math.max(self.showHorizontalScrollbar ? self.minimapHeight : 0, self.rowPanelsHeaderHeight, self.treeOverviewHeight +
2309
+ (this.treeScaleBar ? treeScaleBarHeight : 0));
2310
+ },
2311
+ /**
2312
+ * #getter
2313
+ * the vertical space for alignment rows: the widget height less the
2314
+ * header, the top band and the tracks. Shared by blocksY, maxScrollY, the
2315
+ * vertical scrollbar and fitVertically.
1910
2316
  */
1911
2317
  get msaAreaHeight() {
1912
2318
  return (self.height -
1913
- (self.showHorizontalScrollbar ? self.minimapHeight : 0) -
2319
+ this.topBandHeight -
1914
2320
  self.headerHeight -
1915
2321
  this.totalTrackAreaHeight);
1916
2322
  },
@@ -1922,13 +2328,12 @@ function stateModelFactory() {
1922
2328
  return sum(self.turnedOnTracks.map(r => r.model.height));
1923
2329
  },
1924
2330
  /**
1925
- * one representative annotation per accession, which is what the legend,
1926
- * the filter dialog and the palettes key off
2331
+ * one representative annotation per accession, for the legend, the
2332
+ * filter dialog and the palettes
1927
2333
  */
1928
2334
  get annotationTypes() {
1929
- // first occurrence wins. The representative supplies only the name,
1930
- // description and -- for ordinal segments -- the start that orders
1931
- // them, and those agree across an accession's instances
2335
+ // first occurrence wins; only name, description and segment start are
2336
+ // read from it
1932
2337
  const types = new Map();
1933
2338
  for (const annot of self.annotations) {
1934
2339
  if (!types.has(annot.accession)) {
@@ -1957,11 +2362,8 @@ function stateModelFactory() {
1957
2362
  * #getter
1958
2363
  */
1959
2364
  get dataInitialized() {
1960
- // truthiness, not `!== ''`: these are types.maybe, and DataModel's
1961
- // postProcessSnapshot drops a document over 50kb, so a restored session
1962
- // that inlined a large alignment comes back `undefined` here -- which
1963
- // `!== ''` reads as initialized and renders an empty view instead of
1964
- // the import form
2365
+ // truthiness, not `!== ''`: DataModel drops an inline document over
2366
+ // 50kb from the snapshot, so a restored session can hold `undefined`
1965
2367
  return !!(self.data.msa || self.data.tree) && !self.error;
1966
2368
  },
1967
2369
  /**
@@ -2008,12 +2410,20 @@ function stateModelFactory() {
2008
2410
  },
2009
2411
  /**
2010
2412
  * #getter
2011
- * most-negative allowed scrollY, keeping the last row in view rather than
2012
- * letting the whole alignment scroll off the top.
2413
+ * most-negative allowed scrollY, which keeps the last row in view
2013
2414
  */
2014
2415
  get maxScrollY() {
2015
2416
  return Math.min(-self.totalHeight + self.msaAreaHeight, 0);
2016
2417
  },
2418
+ /**
2419
+ * #getter
2420
+ * axis a wheel zoom scales, for ctrl+wheel as much as for scroll-zoom.
2421
+ * With scroll-zoom off the toolbar shows no axis, so ctrl+wheel takes
2422
+ * both.
2423
+ */
2424
+ get wheelZoomAxis() {
2425
+ return self.scrollZoom ? self.scrollZoomAxis : 'both';
2426
+ },
2017
2427
  }))
2018
2428
  .actions(self => ({
2019
2429
  /**
@@ -2028,15 +2438,19 @@ function stateModelFactory() {
2028
2438
  setScrollZoom(arg) {
2029
2439
  self.scrollZoom = arg;
2030
2440
  },
2441
+ /**
2442
+ * #action
2443
+ */
2444
+ setScrollZoomAxis(arg) {
2445
+ self.scrollZoomAxis = arg;
2446
+ },
2031
2447
  /**
2032
2448
  * #action
2033
2449
  * set hovered tree node and its descendants
2034
2450
  */
2035
2451
  setHoveredTreeNode(nodeId) {
2036
- // the tree's mousemove handler calls this on every event, and both the
2037
- // lookup and the write are expensive: `find` walks the whole hierarchy,
2038
- // and a fresh object here invalidates hoveredRowIndices and redraws the
2039
- // tree and MSA overlays. Re-hovering the same node is the common case
2452
+ // called on every tree mousemove; `find` walks the whole hierarchy and a
2453
+ // new object redraws the tree and MSA overlays
2040
2454
  if (nodeId === self.hoveredTreeNode?.nodeId) {
2041
2455
  return;
2042
2456
  }
@@ -2055,15 +2469,12 @@ function stateModelFactory() {
2055
2469
  /**
2056
2470
  * #action
2057
2471
  * Calculate a neighbor joining tree from the current MSA using BLOSUM62
2058
- * distances. Refuses above `maxNeighborJoiningRows`: the join loop is
2059
- * cubic and runs on the main thread, so 800 rows is a ten-second freeze
2060
- * with no progress and no cancel, and a tree that size wants a tool built
2061
- * for it anyway.
2472
+ * distances. Throws above `maxNeighborJoiningRows`: the join loop is
2473
+ * cubic and runs on the main thread, and 800 rows freeze the tab for ten
2474
+ * seconds with no cancel.
2062
2475
  */
2063
2476
  calculateNeighborJoiningTreeFromMSA() {
2064
- // every sequence in the alignment, not the rows on screen: a collapsed
2065
- // clade is a display state, and building the tree from what it leaves
2066
- // showing drops the sequences it hides out of the result
2477
+ // every sequence, including rows in collapsed clades
2067
2478
  const rows = [...self.rowMap];
2068
2479
  if (rows.length < 2) {
2069
2480
  throw new Error('Need at least 2 sequences to build a tree');
@@ -2075,10 +2486,9 @@ function stateModelFactory() {
2075
2486
  },
2076
2487
  /**
2077
2488
  * #action
2078
- * swap in a different tree over the same alignment. Node ids are derived
2079
- * from the path (node-0-0-1), so a `collapsed` or `showOnly` id held over
2080
- * from the old tree matches a real node in the new one and folds whatever
2081
- * happens to sit there -- the ids go with the tree they name.
2489
+ * swap in a different tree over the same alignment. Clears `collapsed`
2490
+ * and `showOnly`, since path-derived node ids (node-0-0-1) from the old
2491
+ * tree would match unrelated nodes in the new one.
2082
2492
  */
2083
2493
  replaceTree(newick) {
2084
2494
  transaction(() => {
@@ -2143,23 +2553,26 @@ function stateModelFactory() {
2143
2553
  * #action
2144
2554
  * Smoothly zoom by a continuous scaleFactor. The column under the cursor
2145
2555
  * (offsetX/offsetY, px relative to the MSA area) stays anchored
2146
- * horizontally. Vertically the anchor is biased toward the top: when the
2147
- * alignment nearly fits the viewport, snap to y=0 rather than pinning a
2148
- * random row under the cursor, with the bias fading out as the alignment
2149
- * grows taller than the viewport (where cursor-anchoring is useful).
2150
- * Drives wheel/trackpad-pinch zoom.
2151
- */
2152
- zoomToPos(scaleFactor, offsetX, offsetY) {
2556
+ * horizontally. Vertically the anchor is biased toward y=0 when the
2557
+ * alignment nearly fits the viewport, fading to cursor-anchoring as the
2558
+ * alignment grows taller than the viewport.
2559
+ * Drives wheel/trackpad-pinch zoom. `axis` holds one cell dimension
2560
+ * fixed; the held axis still re-anchors its scroll offset, since the
2561
+ * other one can change how much of the alignment fits.
2562
+ */
2563
+ zoomToPos(scaleFactor, offsetX, offsetY, axis = 'both') {
2153
2564
  transaction(() => {
2154
2565
  const colInView = (-self.scrollX + offsetX) / self.colWidth;
2155
2566
  const rowInView = (-self.scrollY + offsetY) / self.rowHeight;
2156
- self.colWidth = clamp(self.colWidth * scaleFactor, minColWidth, maxCellSize);
2157
- self.rowHeight = clamp(self.rowHeight * scaleFactor, minRowHeight, maxCellSize);
2567
+ if (axis !== 'vertical') {
2568
+ self.colWidth = clamp(self.colWidth * scaleFactor, minColWidth, maxCellSize);
2569
+ }
2570
+ if (axis !== 'horizontal') {
2571
+ self.rowHeight = clamp(self.rowHeight * scaleFactor, minRowHeight, maxCellSize);
2572
+ }
2158
2573
  self.scrollX = clamp(offsetX - colInView * self.colWidth, self.maxScrollX, 0);
2159
2574
  const anchoredScrollY = offsetY - rowInView * self.rowHeight;
2160
- // maxScrollY is -(totalHeight - visibleMsaHeight) when the alignment
2161
- // overflows, so -maxScrollY is exactly that overflow past the
2162
- // scrollable MSA viewport (0 when it fits)
2575
+ // -maxScrollY is the overflow past the viewport, 0 when it fits
2163
2576
  const overflow = Math.max(0, -self.maxScrollY);
2164
2577
  const visibleHeight = self.totalHeight - overflow;
2165
2578
  const topBias = visibleHeight > 0 ? clamp(1 - overflow / visibleHeight, 0, 1) : 1;
@@ -2181,13 +2594,11 @@ function stateModelFactory() {
2181
2594
  },
2182
2595
  /**
2183
2596
  * #action
2184
- * Set the overlay annotations (an empty list clears them). Every source
2185
- * funnels through here after its own adapter has flattened it:
2186
- * InterProScan, GFF, user uploads, NCBI CDD.
2597
+ * Set the overlay annotations (an empty list clears them). InterProScan,
2598
+ * GFF, user uploads and NCBI CDD all arrive here as Annotation[].
2187
2599
  *
2188
- * It does not touch `showDomains`. Loading used to force the overlay on,
2189
- * and since a restored snapshot loads its GFF again on the way in, a link
2190
- * shared with the overlay hidden reopened with it drawn.
2600
+ * Leaves `showDomains` alone, because a restored snapshot reloads its
2601
+ * GFF and must keep a hidden overlay hidden.
2191
2602
  */
2192
2603
  setAnnotations(annotations) {
2193
2604
  self.annotations = annotations;
@@ -2222,6 +2633,28 @@ function stateModelFactory() {
2222
2633
  setColumnTracks(tracks) {
2223
2634
  self.columnTracks.replace(tracks);
2224
2635
  },
2636
+ /**
2637
+ * #action
2638
+ * replace the row table, which the model keeps as the JSON string
2639
+ * `data.treeMetadata` (see docs/layers.md)
2640
+ */
2641
+ setRowData(rowData) {
2642
+ self.data.setTreeMetadata(JSON.stringify(rowData));
2643
+ },
2644
+ /**
2645
+ * #action
2646
+ * replace what the viewer's marks read from the row table
2647
+ */
2648
+ setEncodings(encodings) {
2649
+ self.encodings.replace(encodings);
2650
+ },
2651
+ /**
2652
+ * #action
2653
+ * replace the panels drawn between the tree and the alignment
2654
+ */
2655
+ setRowPanels(panels) {
2656
+ self.rowPanels.replace(panels);
2657
+ },
2225
2658
  /**
2226
2659
  * #action
2227
2660
  * replace the alignment<->structure correspondence (see docs/layers.md)
@@ -2233,8 +2666,6 @@ function stateModelFactory() {
2233
2666
  * #action
2234
2667
  */
2235
2668
  toggleTrack(id) {
2236
- // the stored value is "is off", so the current shown state is exactly
2237
- // what the flipped entry should hold
2238
2669
  const defaultOff = self.MSA?.tracks.find(t => t.id === id)?.defaultOff;
2239
2670
  self.turnedOffTracks.set(id, !trackIsOff(self.turnedOffTracks, id, defaultOff));
2240
2671
  },
@@ -2254,18 +2685,77 @@ function stateModelFactory() {
2254
2685
  },
2255
2686
  /**
2256
2687
  * #getter
2257
- * width of the alignment canvas itself: the msa area less the vertical
2258
- * scrollbar sitting in it. Not usable from showHorizontalScrollbar, which
2259
- * feeds msaAreaHeight -> showVerticalScrollbar and would close a cycle
2688
+ * width of the alignment canvas: the msa area less the vertical
2689
+ * scrollbar. showHorizontalScrollbar must not read it, since that feeds
2690
+ * msaAreaHeight -> showVerticalScrollbar and would form a cycle
2260
2691
  */
2261
2692
  get msaCanvasWidth() {
2262
2693
  return self.msaAreaWidth - this.verticalScrollbarWidth;
2263
2694
  },
2695
+ /**
2696
+ * #method
2697
+ * the cell at a visible column and row index, in the coordinates a host
2698
+ * writes highlights in
2699
+ */
2700
+ cellAt(visibleCol, rowIndex) {
2701
+ const column = self.visibleColToGlobalCol(visibleCol);
2702
+ const row = rowIndex === undefined ? undefined : self.leaves[rowIndex]?.data.name;
2703
+ return row === undefined
2704
+ ? { column: column + 1 }
2705
+ : {
2706
+ column: column + 1,
2707
+ row,
2708
+ residue: self.visibleColToSeqPosOneBased(row, visibleCol),
2709
+ letter: self.rowMap.get(row)?.[column],
2710
+ };
2711
+ },
2712
+ /**
2713
+ * #getter
2714
+ * the cell under the pointer. Public API: MSAViewer's onCellHover
2715
+ * reports it.
2716
+ */
2717
+ get hoveredCell() {
2718
+ const { mouseCol, mouseRow } = self;
2719
+ return mouseCol === undefined
2720
+ ? undefined
2721
+ : this.cellAt(mouseCol, mouseRow);
2722
+ },
2723
+ /**
2724
+ * #getter
2725
+ * the cell a click pinned. Public API: MSAViewer's onCellClick reports it.
2726
+ */
2727
+ get clickedCell() {
2728
+ const { mouseClickCol, mouseClickRow } = self;
2729
+ return mouseClickCol === undefined
2730
+ ? undefined
2731
+ : this.cellAt(mouseClickCol, mouseClickRow);
2732
+ },
2733
+ /**
2734
+ * #getter
2735
+ * the columns on screen. Public API: MSAViewer's onViewportChange reports
2736
+ * it.
2737
+ */
2738
+ get viewport() {
2739
+ const { scrollX, colWidth, numColumns, viewInitialized } = self;
2740
+ if (numColumns === 0 || !viewInitialized) {
2741
+ return undefined;
2742
+ }
2743
+ const { xStart, xEnd } = visibleColRange({
2744
+ offsetX: -scrollX,
2745
+ blockWidth: this.msaCanvasWidth,
2746
+ colWidth,
2747
+ });
2748
+ const last = Math.max(0, Math.min(xEnd, numColumns) - 1);
2749
+ return {
2750
+ startColumn: self.visibleColToGlobalCol(Math.min(xStart, last)) + 1,
2751
+ endColumn: self.visibleColToGlobalCol(last) + 1,
2752
+ };
2753
+ },
2264
2754
  /**
2265
2755
  * #getter
2266
2756
  * ordinal segment types (exons etc.), ordered by sequence position so
2267
- * exon-1..exon-14 read left-to-right; colored by alternating shade and
2268
- * labeled by number rather than each getting a distinct hue + legend row
2757
+ * exon-1..exon-14 run left-to-right; colored by alternating shade and
2758
+ * labeled by number, with no legend row
2269
2759
  */
2270
2760
  get segmentDomainTypes() {
2271
2761
  return [...self.annotationTypes.values()]
@@ -2291,9 +2781,38 @@ function stateModelFactory() {
2291
2781
  get strokePalette() {
2292
2782
  return transform(this.fillPalette, ([key, val]) => [
2293
2783
  key,
2294
- colord(val).darken(0.1).toHex(),
2784
+ outlineColor(val),
2295
2785
  ]);
2296
2786
  },
2787
+ /**
2788
+ * #getter
2789
+ * the encoding coloring the overlay's spans, undefined when none does,
2790
+ * which leaves each span the color its accession takes in `fillPalette`
2791
+ */
2792
+ get featureFillEncoding() {
2793
+ return this.resolvedEncodings.find(e => e.channel === 'featureFill');
2794
+ },
2795
+ /**
2796
+ * #getter
2797
+ * the fill and outline of every feature's span: its own GFF `color=`
2798
+ * first, then the `featureFill` scale, then the accession palette.
2799
+ * Computed once per change of the features, the encodings or the palette
2800
+ */
2801
+ get featureColors() {
2802
+ return featureColorMap(self.filteredAnnotations, this.featureFillEncoding, this.fillPalette);
2803
+ },
2804
+ /**
2805
+ * #getter
2806
+ * the text the `featureLabel` channel draws inside each span, undefined
2807
+ * when no encoding names the channel. A data channel, so it draws
2808
+ * whether or not the residue letters do
2809
+ */
2810
+ get featureLabels() {
2811
+ const encoding = this.resolvedEncodings.find(e => e.channel === 'featureLabel');
2812
+ return encoding
2813
+ ? featureLabelMap(self.filteredAnnotations, encoding.field)
2814
+ : undefined;
2815
+ },
2297
2816
  /**
2298
2817
  * #getter
2299
2818
  * accession -> number drawn on each segment band: the trailing number of
@@ -2308,24 +2827,92 @@ function stateModelFactory() {
2308
2827
  /**
2309
2828
  * #getter
2310
2829
  * the domain types currently drawn on the alignment (filtered-on), shared
2311
- * by the on-screen legend and the SVG export legend. Ordinal segments
2312
- * (exons) are excluded — they read as a numbered gene model, not a color
2313
- * key — so this is the categorical types ordered by sequence position
2830
+ * by the on-screen legend and the SVG export legend: the categorical types
2831
+ * ordered by sequence position. Ordinal segments (exons) are numbered on
2832
+ * the band instead
2314
2833
  */
2315
2834
  get visibleDomainTypes() {
2316
2835
  return this.categoricalDomainTypes
2317
2836
  .filter(d => !self.turnedOffFeatures.get(d.accession))
2318
2837
  .toSorted((a, b) => a.start - b.start);
2319
2838
  },
2839
+ /**
2840
+ * #getter
2841
+ * the categorical color keys drawn for this view, shared by the on-screen
2842
+ * legend overlay and the SVG export's reserved column. The domain overlay
2843
+ * produces the first, listing the `featureFill` scale where an encoding
2844
+ * names one. Every field a row-table encoding or a row panel reads
2845
+ * produces one more, so two channels over one field, or two strips over
2846
+ * it, list that field once. A strip's `legend` names the title it lists
2847
+ * under, so strips over eight fields with one set of colors list one
2848
+ * legend between them
2849
+ */
2850
+ get legends() {
2851
+ const { featureFillEncoding, fillPalette, visibleDomainTypes } = this;
2852
+ const byKey = new Map();
2853
+ // the accession palette keys on no field, so it takes a key of its own
2854
+ const add = (field, entries, id) => {
2855
+ if (entries.length === 0) {
2856
+ return;
2857
+ }
2858
+ const key = field === undefined ? 'domains' : `field:${field}`;
2859
+ const legend = byKey.get(key);
2860
+ if (legend) {
2861
+ const seen = new Set(legend.entries.map(e => e.id));
2862
+ legend.entries.push(...entries.filter(e => !seen.has(e.id)));
2863
+ }
2864
+ else {
2865
+ byKey.set(key, {
2866
+ id: id ?? (field === undefined ? 'domains' : `rowData-${field}`),
2867
+ title: field ?? 'Domains',
2868
+ entries: [...entries],
2869
+ });
2870
+ }
2871
+ };
2872
+ // the overlay draws the domain key; with no columns it draws nothing,
2873
+ // and a features panel taking the same colors lists them instead
2874
+ if (self.actuallyShowDomains && self.numColumns > 0) {
2875
+ add(featureFillEncoding?.field, featureFillEncoding
2876
+ ? featureFillEncoding.legend
2877
+ : visibleDomainTypes.map(d => ({
2878
+ id: d.accession,
2879
+ label: d.name,
2880
+ color: fillPalette[d.accession],
2881
+ })), 'domains');
2882
+ }
2883
+ for (const { channel, field, legend } of this.resolvedEncodings) {
2884
+ if (!featureChannels.has(channel)) {
2885
+ add(field, legend);
2886
+ }
2887
+ }
2888
+ for (const { legendTitle, legend } of this.resolvedRowPanels) {
2889
+ add(legendTitle, legend);
2890
+ }
2891
+ return [...byKey.values()];
2892
+ },
2893
+ /**
2894
+ * #getter
2895
+ * whether the overlay marks each domain with a bar under its row instead
2896
+ * of filling the row behind the letters. Letter-color mode hands the
2897
+ * background to the color scheme, so a filled box would paint over it and
2898
+ * leave the setting with nothing to show. Sub-row layout already stacks
2899
+ * the boxes clear of the letters, and with the letters too small to draw
2900
+ * the filled box is the only thing left to read.
2901
+ */
2902
+ get domainUnderline() {
2903
+ return (self.actuallyShowDomains &&
2904
+ !self.bgColor &&
2905
+ !self.subFeatureRows &&
2906
+ self.showMsaLetters);
2907
+ },
2320
2908
  /**
2321
2909
  * #getter
2322
2910
  * every filtered-on annotation resolved to the visible column span it is
2323
2911
  * drawn across, keyed by row name. Each row is ordered longest-first so a
2324
- * short domain nested inside a long one draws on top of it rather than
2325
- * under it. Resolving these once here rather than inside each canvas
2326
- * block removes a per-feature, per-block sequence position conversion
2327
- * from every redraw, and gives the letter renderer the band colors it
2328
- * needs to keep residues readable on top of the boxes.
2912
+ * nested short domain draws on top, and each band carries the lane the
2913
+ * sub-row layout puts it in. Resolved once here instead of per canvas
2914
+ * block per redraw; the letter renderer also reads the band colors to
2915
+ * pick legible letter colors.
2329
2916
  */
2330
2917
  get domainBands() {
2331
2918
  const { blanks } = self;
@@ -2334,14 +2921,11 @@ function stateModelFactory() {
2334
2921
  const rowBands = annotations
2335
2922
  .toSorted((a, b) => len(b) - len(a))
2336
2923
  .map(annotation => {
2337
- // annotation positions are 1-based and inclusive. Both ends count
2338
- // the visible columns in front of a global column, so endCol is
2339
- // the exclusive column after the last residue's own column --
2340
- // the band stops there rather than stretching across a following
2341
- // gap run -- and a residue whose column is itself hidden
2342
- // collapses onto the neighbouring boundary instead of dropping
2343
- // the band. A band whose every column is hidden spans nothing
2344
- // and is left out, as is one naming a row the alignment lacks.
2924
+ // annotation positions are 1-based and inclusive. endCol is
2925
+ // exclusive, one past the last residue's column, so the band does
2926
+ // not extend over a following gap run. An endpoint in a hidden
2927
+ // column moves to the neighboring boundary. Bands with no visible
2928
+ // columns, or naming a missing row, are dropped.
2345
2929
  const start = self.seqPosToGlobalCol(name, annotation.start - 1);
2346
2930
  const end = self.seqPosToGlobalCol(name, annotation.end - 1);
2347
2931
  if (start === undefined || end === undefined) {
@@ -2354,11 +2938,10 @@ function stateModelFactory() {
2354
2938
  : undefined;
2355
2939
  })
2356
2940
  .filter(notEmpty)
2357
- // numbered after the drop, so a band that resolved to nothing does
2358
- // not leave an empty sub-row behind it
2941
+ // numbered after filtering, so a dropped band leaves no gap
2359
2942
  .map((band, stackIndex) => ({ ...band, stackIndex }));
2360
2943
  if (rowBands.length > 0) {
2361
- bands.set(name, rowBands);
2944
+ bands.set(name, packDomainLanes(rowBands));
2362
2945
  }
2363
2946
  }
2364
2947
  return bands;
@@ -2388,9 +2971,6 @@ function stateModelFactory() {
2388
2971
  const hits = (this.domainBands.get(name) ?? [])
2389
2972
  .filter(b => mouseCol >= b.startCol && mouseCol < b.endCol)
2390
2973
  .map(b => b.annotation);
2391
- // the shared empty array, so moving the mouse across an alignment with
2392
- // no annotations does not hand every canvas block a new value to
2393
- // re-render on
2394
2974
  return hits.length > 0 ? hits : noDomains;
2395
2975
  },
2396
2976
  /**
@@ -2407,8 +2987,7 @@ function stateModelFactory() {
2407
2987
  * #getter
2408
2988
  * row indices highlighted by the current tree hover (a hovered internal
2409
2989
  * node highlights every tip below it). Shared by the tree and MSA overlay
2410
- * canvases so they cannot disagree, and resolved through the memoized
2411
- * name->index map rather than rebuilding a lookup on each mouse move.
2990
+ * canvases, via the memoized name->index map.
2412
2991
  */
2413
2992
  get hoveredRowIndices() {
2414
2993
  const { hoveredTreeNode, rowNamesSet } = self;
@@ -2421,8 +3000,8 @@ function stateModelFactory() {
2421
3000
  /**
2422
3001
  * #getter
2423
3002
  * contiguous runs of `highlightedColumns`, so a run of highlighted columns
2424
- * draws as one bordered band. Computed here because the overlay canvas
2425
- * redraws on every mouse move while the highlight itself rarely changes.
3003
+ * draws as one bordered band. Memoized because the overlay canvas redraws
3004
+ * on every mouse move.
2426
3005
  */
2427
3006
  get highlightedColumnRuns() {
2428
3007
  const { highlightedColumns } = self;
@@ -2446,13 +3025,8 @@ function stateModelFactory() {
2446
3025
  * is dropped. Row names that match no row are ignored.
2447
3026
  */
2448
3027
  get resolvedHighlights() {
2449
- const { blanks, rowNamesSet, transientHighlights } = self;
2450
- const toVisible = (globalCol) => {
2451
- const visible = self.globalColToVisibleCol(globalCol);
2452
- return visible ?? visibleColsBefore(blanks, globalCol);
2453
- };
2454
- // the document's own highlights first, then what each owner is showing
2455
- // right now, so a hover draws over a persisted band rather than under it
3028
+ const { rowNamesSet, transientHighlights } = self;
3029
+ // persisted highlights first, so transient ones draw on top
2456
3030
  const all = [
2457
3031
  ...self.highlights,
2458
3032
  ...Object.values(transientHighlights).flat(),
@@ -2468,70 +3042,238 @@ function stateModelFactory() {
2468
3042
  if (start === undefined || end === undefined) {
2469
3043
  return [];
2470
3044
  }
2471
- let startGlobal = start - 1;
2472
- let endGlobal = end - 1;
2473
- if (row !== undefined) {
2474
- const rowStart = self.seqPosToGlobalCol(row, start - 1);
2475
- const rowEnd = self.seqPosToGlobalCol(row, end - 1);
2476
- if (rowStart === undefined || rowEnd === undefined) {
2477
- return [];
3045
+ const span = self.visibleSpan({ row, start, end });
3046
+ return span ? [{ ...base, ...span, rowIndices: [] }] : [];
3047
+ });
3048
+ },
3049
+ /**
3050
+ * #method
3051
+ * per-column summary statistics: consensus residue and its identity
3052
+ * fraction, both conservation scores, gap fraction, and the sorted non-gap
3053
+ * residue distribution. undefined past the end of the alignment or for an
3054
+ * all-gap column.
3055
+ */
3056
+ columnStatsAt(col) {
3057
+ const { colStats, conservation, propertyConservation } = self;
3058
+ return columnStats({
3059
+ col,
3060
+ colStats,
3061
+ conservation,
3062
+ propertyConservation,
3063
+ });
3064
+ },
3065
+ /**
3066
+ * #getter
3067
+ * `columnStatsAt` for the hovered column, undefined when nothing is
3068
+ * hovered
3069
+ */
3070
+ get mouseOverColumnStats() {
3071
+ const { mouseCol, colStats, conservation, propertyConservation } = self;
3072
+ return mouseCol === undefined
3073
+ ? undefined
3074
+ : columnStats({
3075
+ col: mouseCol,
3076
+ colStats,
3077
+ conservation,
3078
+ propertyConservation,
3079
+ });
3080
+ },
3081
+ /**
3082
+ * #method
3083
+ */
3084
+ getRowData(name) {
3085
+ return {
3086
+ data: self.MSA?.getRowData(name),
3087
+ rowData: self.rowDataOf(name),
3088
+ };
3089
+ },
3090
+ /**
3091
+ * #getter
3092
+ * each encoding with its scale resolved against the values its field
3093
+ * takes: a feature channel reads them across the features drawn, every
3094
+ * other channel across the row table. Resolved once per change of that
3095
+ * table or the encodings, never per row per frame.
3096
+ */
3097
+ get resolvedEncodings() {
3098
+ const rows = Object.values(self.rowData);
3099
+ const features = self.filteredAnnotations;
3100
+ return self.encodings.map(encoding => ({
3101
+ ...encoding,
3102
+ ...resolveScale(encoding.scale, featureChannels.has(encoding.channel)
3103
+ ? features
3104
+ .map(a => featureField(a, encoding.field))
3105
+ .filter(notEmpty)
3106
+ : rows.map(row => row?.[encoding.field]).filter(notEmpty)),
3107
+ }));
3108
+ },
3109
+ /**
3110
+ * #getter
3111
+ * each row panel with its scale resolved against the values its field
3112
+ * takes across the row table, giving the color per row name, the pixel
3113
+ * column it draws in, and the entries its legend lists. Resolved once
3114
+ * per change of that table or the panels, never per block per frame.
3115
+ */
3116
+ get resolvedRowPanels() {
3117
+ const rows = Object.entries(self.rowData);
3118
+ const { fillPalette, featureFillEncoding, featureLabels } = this;
3119
+ const annotations = self.filteredAnnotations;
3120
+ let offsetX = 0;
3121
+ return self.rowPanels.map((panel, index) => {
3122
+ const width = rowPanelWidth(panel, self.rowHeight);
3123
+ const base = { id: `rowpanel-${index}`, width, offsetX };
3124
+ offsetX += width;
3125
+ if (panel.kind === 'features') {
3126
+ const color = panel.encoding?.color;
3127
+ const encoding = color
3128
+ ? resolveFeatureScale(color.field, color.scale, annotations)
3129
+ : featureFillEncoding;
3130
+ const label = panel.encoding?.label;
3131
+ const align = panel.transform?.find(t => t.type === 'align');
3132
+ return {
3133
+ ...base,
3134
+ kind: panel.kind,
3135
+ x: panel.x,
3136
+ header: panel.header ?? '',
3137
+ field: encoding?.field,
3138
+ legendTitle: encoding?.field,
3139
+ spans: featurePanelSpans({
3140
+ panel,
3141
+ width,
3142
+ rowHeight: self.rowHeight,
3143
+ colWidth: self.colWidth,
3144
+ domainBands: this.domainBands,
3145
+ annotationsByRow: self.annotationsByRow,
3146
+ shifts: align
3147
+ ? this.featureAlignShifts.get(align.on)
3148
+ : undefined,
3149
+ }),
3150
+ colors: featureColorMap(annotations, encoding, fillPalette),
3151
+ labels: label
3152
+ ? featureLabelMap(annotations, label)
3153
+ : featureLabels,
3154
+ legend: encoding?.legend ??
3155
+ this.visibleDomainTypes.map(d => ({
3156
+ id: d.accession,
3157
+ label: d.name,
3158
+ color: fillPalette[d.accession],
3159
+ })),
3160
+ };
3161
+ }
3162
+ const { colorOf, legend } = resolveScale(panel.scale, rows.map(([, row]) => row?.[panel.field]).filter(notEmpty));
3163
+ const colors = new Map();
3164
+ for (const [name, row] of rows) {
3165
+ const value = row?.[panel.field];
3166
+ const color = value === undefined ? undefined : colorOf(value);
3167
+ if (color) {
3168
+ colors.set(name, color);
2478
3169
  }
2479
- startGlobal = rowStart;
2480
- endGlobal = rowEnd;
2481
3170
  }
2482
- const startCol = toVisible(startGlobal);
2483
- const endVisible = self.globalColToVisibleCol(endGlobal);
2484
- const endCol = endVisible ?? visibleColsBefore(blanks, endGlobal) - 1;
2485
- return startCol <= endCol
2486
- ? [{ ...base, startCol, endCol, rowIndices: [] }]
2487
- : [];
3171
+ return {
3172
+ ...base,
3173
+ kind: panel.kind,
3174
+ field: panel.field,
3175
+ header: panel.header ?? panel.field,
3176
+ legendTitle: panel.legend ?? panel.field,
3177
+ colors,
3178
+ legend,
3179
+ };
2488
3180
  });
2489
3181
  },
2490
3182
  /**
2491
3183
  * #getter
2492
- * per-column summary statistics for the hovered column: consensus residue
2493
- * and its identity fraction, conservation score, gap fraction, and the
2494
- * sorted non-gap residue distribution. undefined when nothing is hovered.
3184
+ * the shift an `align` transform gives each row, keyed by the feature
3185
+ * name it aligns on: the offset putting the first feature of that name
3186
+ * at zero. A row carrying no such feature is absent, and keeps its own
3187
+ * origin.
3188
+ */
3189
+ get featureAlignShifts() {
3190
+ const names = new Set(self.rowPanels.flatMap(panel => panel.kind === 'features' && panel.x === 'position'
3191
+ ? (panel.transform ?? [])
3192
+ .filter(t => t.type === 'align')
3193
+ .map(t => t.on)
3194
+ : []));
3195
+ return new Map([...names].map(on => [
3196
+ on,
3197
+ new Map(Object.entries(self.annotationsByRow)
3198
+ .map(([name, annotations]) => {
3199
+ const hit = annotations.find(a => featureName(a) === on);
3200
+ return hit ? [name, 1 - hit.start] : undefined;
3201
+ })
3202
+ .filter(notEmpty)),
3203
+ ]));
3204
+ },
3205
+ /**
3206
+ * #getter
3207
+ * the color the `tipLabel` channel gives each row, by row name. Undefined
3208
+ * when no encoding names the channel, which leaves the labels the theme's
3209
+ * text color.
2495
3210
  */
2496
- get mouseOverColumnStats() {
2497
- const { mouseCol } = self;
2498
- if (mouseCol === undefined) {
3211
+ get tipLabelColors() {
3212
+ const encoding = this.resolvedEncodings.find(e => e.channel === 'tipLabel');
3213
+ if (!encoding) {
2499
3214
  return undefined;
2500
3215
  }
2501
- const { colStats } = self;
2502
- if (mouseCol >= colStats.numColumns) {
2503
- return undefined;
3216
+ const colors = new Map();
3217
+ for (const [name, row] of Object.entries(self.rowData)) {
3218
+ const value = row?.[encoding.field];
3219
+ const color = value === undefined ? undefined : encoding.colorOf(value);
3220
+ if (color) {
3221
+ colors.set(name, color);
3222
+ }
2504
3223
  }
2505
- const total = colStats.total(mouseCol);
2506
- if (!total) {
3224
+ return colors;
3225
+ },
3226
+ /**
3227
+ * #getter
3228
+ * the wash the `rowTint` channel draws over each row, indexed by row, or
3229
+ * undefined when no encoding names the channel. The overlay draws these,
3230
+ * so a tint stays out of the raster tile cache and its keys.
3231
+ */
3232
+ get rowTints() {
3233
+ const encoding = this.resolvedEncodings.find(e => e.channel === 'rowTint');
3234
+ if (!encoding) {
2507
3235
  return undefined;
2508
3236
  }
2509
- const gaps = colStats.gapCount(mouseCol);
2510
- const distribution = colStats
2511
- .residueEntries(mouseCol)
2512
- .sort((a, b) => b[1] - a[1]);
2513
- const consensus = distribution[0];
2514
- return {
2515
- col: mouseCol,
2516
- total,
2517
- gaps,
2518
- gapFraction: gaps / total,
2519
- conservation: self.conservation[mouseCol] ?? 0,
2520
- propertyConservation: self.propertyConservation[mouseCol],
2521
- consensusLetter: consensus?.[0] ?? '',
2522
- consensusCount: consensus?.[1] ?? 0,
2523
- consensusFraction: consensus ? consensus[1] / total : 0,
2524
- distribution,
2525
- };
3237
+ return self.rowNames.map(name => {
3238
+ const value = self.rowDataOf(name)?.[encoding.field];
3239
+ const color = value === undefined ? undefined : encoding.colorOf(value);
3240
+ if (!color) {
3241
+ return undefined;
3242
+ }
3243
+ return withAlpha(color, rowTintAlpha);
3244
+ });
2526
3245
  },
2527
3246
  /**
2528
- * #method
3247
+ * #getter
3248
+ * the color the `branch` channel gives each tree edge, by the node id at
3249
+ * the edge's far end, or undefined when no encoding names the channel. A
3250
+ * node takes the field value its tips agree on, so a clade of one value
3251
+ * colors down from where it splits off, and a node whose tips disagree or
3252
+ * whose value has no color is absent and draws in the default color.
3253
+ *
3254
+ * The pass runs over the whole tree, never `root`, so a collapsed or
3255
+ * focused clade keeps the color the full tree gives it.
2529
3256
  */
2530
- getRowData(name) {
2531
- return {
2532
- data: self.MSA?.getRowData(name),
2533
- treeMetadata: self.treeMetadata[name],
2534
- };
3257
+ get branchColors() {
3258
+ const encoding = this.resolvedEncodings.find(e => e.channel === 'branch');
3259
+ if (!encoding) {
3260
+ return undefined;
3261
+ }
3262
+ const order = preorder(self.tree);
3263
+ const values = new Map();
3264
+ const colors = new Map();
3265
+ for (let i = order.length - 1; i >= 0; i--) {
3266
+ const node = order[i];
3267
+ const value = node.children.length > 0
3268
+ ? sharedValue(node.children.map(child => values.get(child)))
3269
+ : self.rowDataOf(node.name)?.[encoding.field];
3270
+ values.set(node, value);
3271
+ const color = value === undefined ? undefined : encoding.colorOf(value);
3272
+ if (color) {
3273
+ colors.set(node.id, color);
3274
+ }
3275
+ }
3276
+ return colors;
2535
3277
  },
2536
3278
  }))
2537
3279
  .actions(self => ({
@@ -2544,33 +3286,33 @@ function stateModelFactory() {
2544
3286
  /**
2545
3287
  * #action
2546
3288
  */
2547
- setConservationTrackHeight(arg) {
2548
- self.conservationTrackHeight = arg;
3289
+ setHideHeader(arg) {
3290
+ self.hideHeader = arg;
2549
3291
  },
2550
3292
  /**
2551
3293
  * #action
3294
+ * focus the subtree a click `y` pixels down the tree overview lands on.
3295
+ * A click inside the box already drawn there clears the focus, the way
3296
+ * clicking the focused branch again does.
2552
3297
  */
2553
- setColumnTrackHeight(id, height) {
2554
- self.columnTrackHeights = { ...self.columnTrackHeights, [id]: height };
3298
+ treeOverviewClick(y) {
3299
+ const hit = self.treeOverviewHit(y);
3300
+ const focus = self.treeOverviewFocusRows;
3301
+ const inside = !!focus && !!hit && hit.rows[0] >= focus[0] && hit.rows[1] <= focus[1];
3302
+ self.setShowOnly(inside || !hit ? undefined : hit.id);
2555
3303
  },
2556
3304
  /**
2557
3305
  * #action
3306
+ * resize every track sharing a `heightKey`; see `trackHeights`
2558
3307
  */
2559
- setSequenceLogoTrackHeight(arg) {
2560
- self.sequenceLogoTrackHeight = arg;
3308
+ setTrackHeight(heightKey, height) {
3309
+ self.trackHeights.set(heightKey, height);
2561
3310
  },
2562
3311
  /**
2563
3312
  * #action
2564
- */
2565
- setArcTrackHeight(arg) {
2566
- self.arcTrackHeight = arg;
2567
- },
2568
- /**
2569
- * #action
2570
- * Return to the import form: every property off `preservedOnReset`
2571
- * (data, filehandles, collapsed/showOnly, zoom, scroll, ...) goes back
2572
- * to its default, then the file-derived volatiles applySnapshot cannot
2573
- * reach are cleared by hand.
3313
+ * Return to the import form: reset every property not in
3314
+ * `preservedOnReset` to its default, then clear the file-derived
3315
+ * volatiles applySnapshot does not touch.
2574
3316
  */
2575
3317
  reset() {
2576
3318
  self.resetCount++;
@@ -2596,8 +3338,8 @@ function stateModelFactory() {
2596
3338
  },
2597
3339
  /**
2598
3340
  * #action
2599
- * draw this annotation type, or stop drawing it. Only the "stop" is
2600
- * recorded -- see `turnedOffFeatures`
3341
+ * show or hide an annotation type. Only hidden types are recorded; see
3342
+ * `turnedOffFeatures`
2601
3343
  */
2602
3344
  setFilter(accession, shown) {
2603
3345
  if (shown) {
@@ -2611,12 +3353,8 @@ function stateModelFactory() {
2611
3353
  * #action
2612
3354
  */
2613
3355
  fit() {
2614
- // Each direction's viewport depends on the other's result: fitting the
2615
- // rows while the columns still overflow measures against a height the
2616
- // minimap is taking, and fitting the columns while the rows still
2617
- // overflow measures against a width the vertical scrollbar is taking.
2618
- // A second pass measures against the geometry the first pass produced,
2619
- // which is the one the reader ends up looking at.
3356
+ // two passes: each direction's viewport depends on whether the other
3357
+ // overflows (the minimap takes height, the vertical scrollbar width)
2620
3358
  transaction(() => {
2621
3359
  for (let pass = 0; pass < 2; pass++) {
2622
3360
  this.fitHorizontally();
@@ -2633,29 +3371,64 @@ function stateModelFactory() {
2633
3371
  }
2634
3372
  self.scrollY = 0;
2635
3373
  },
3374
+ /**
3375
+ * #action
3376
+ * zoom and scroll so a span fills the alignment's width, in highlight
3377
+ * coordinates (see visibleSpan). Does nothing before the viewer knows
3378
+ * its width, or for a span that resolves to no visible column.
3379
+ */
3380
+ zoomToRegion(region) {
3381
+ const span = self.visibleSpan(region);
3382
+ if (!span || !self.viewInitialized) {
3383
+ return;
3384
+ }
3385
+ transaction(() => {
3386
+ self.colWidth = clamp(self.msaCanvasWidth / (span.endCol - span.startCol + 1), minColWidth, maxCellSize);
3387
+ self.scrollX = clamp(-span.startCol * self.colWidth, self.maxScrollX, 0);
3388
+ });
3389
+ },
2636
3390
  /**
2637
3391
  * #action
2638
3392
  */
2639
3393
  fitHorizontally() {
2640
3394
  if (self.numColumns > 0) {
2641
- // fitting to msaAreaWidth instead left the last ~20px of columns off
2642
- // the right edge -- and short of the width that shows a minimap, so
2643
- // nothing on screen said they were there
3395
+ // msaCanvasWidth excludes the vertical scrollbar's 20px
2644
3396
  self.colWidth = clamp(self.msaCanvasWidth / self.numColumns, minColWidth, maxCellSize);
2645
3397
  }
2646
3398
  self.scrollX = 0;
2647
3399
  },
2648
3400
  afterCreate() {
2649
- // seed the highlighted-columns overlay from the declarative property so
2650
- // a shared snapshot/URL opens with those columns highlighted (the
2651
- // volatile highlightedColumns can later be driven by genome-hover sync)
2652
3401
  if (self.highlightColumns?.length) {
2653
3402
  self.setHighlightedColumns(self.highlightColumns);
2654
3403
  }
2655
- // track the live device pixel ratio so canvas backing stores re-scale
2656
- // when the window moves between monitors or the browser zooms. The
2657
- // matchMedia query is pinned to the current ratio, so each change
2658
- // re-registers against the new one to keep tracking further moves.
3404
+ // The `collapse` and `focus` clade marks seed the collapsed list and
3405
+ // the subtree in focus, which the tree, `hideGapsEffective` and the
3406
+ // alignment all read. The tree arrives with the model for inline data
3407
+ // and later for a filehandle, so the seeding waits for it and then runs
3408
+ // once: expanding a seeded clade sticks, and the record collapses it
3409
+ // again only on reload.
3410
+ let cladesSeeded = false;
3411
+ addDisposer(self, autorun(() => {
3412
+ if (cladesSeeded ||
3413
+ !self.dataInitialized ||
3414
+ self.clades.length === 0) {
3415
+ return;
3416
+ }
3417
+ cladesSeeded = true;
3418
+ for (const { mark, nodeId } of self.resolvedClades) {
3419
+ if (nodeId === undefined) {
3420
+ continue;
3421
+ }
3422
+ if (mark === 'collapse' && !self.collapsed.includes(nodeId)) {
3423
+ self.toggleCollapsed(nodeId);
3424
+ }
3425
+ else if (mark === 'focus') {
3426
+ self.setShowOnly(nodeId);
3427
+ }
3428
+ }
3429
+ }));
3430
+ // the matchMedia query is pinned to the current device pixel ratio, so
3431
+ // each change re-registers against the new one
2659
3432
  if (typeof window !== 'undefined' &&
2660
3433
  typeof window.matchMedia === 'function') {
2661
3434
  const query = () => window.matchMedia(`(resolution: ${window.devicePixelRatio}dppx)`);
@@ -2675,25 +3448,17 @@ function stateModelFactory() {
2675
3448
  * Fetch a filehandle whenever it changes, and hand the text to
2676
3449
  * `onLoad`.
2677
3450
  *
2678
- * Every loader carries a generation guard: the filehandle can change
2679
- * mid-fetch (a second file picked while the first is still in flight),
2680
- * and the slower earlier request must not clobber the data, status, or
2681
- * loading flag belonging to the newer one. A superseded or cleared
2682
- * request is also aborted, rather than left downloading a file nothing
2683
- * is waiting for, and it gives back the status line it was writing --
2684
- * a reset() mid-download used to leave "Downloading file" and a Cancel
2685
- * button behind on the import form.
3451
+ * A generation guard keeps a slower superseded request from overwriting
3452
+ * the newer one's data, status or loading flag. A superseded or cleared
3453
+ * request is aborted and clears its status line.
2686
3454
  *
2687
- * `clearFilehandle` serves two purposes for the loaders that pass it.
2688
- * A local file has no URL to refetch from, so the handle is dropped
2689
- * once its bytes are in the model; and a fetch the user cancels drops
2690
- * it too, returning the view to the import form rather than leaving a
2691
- * stuck spinner.
3455
+ * `clearFilehandle` runs after a local file loads, since a blob has no
3456
+ * URL to refetch, and when the user cancels, which returns the view to
3457
+ * the import form.
2692
3458
  *
2693
- * `what` names the layer in a failure message. An optional layer
2694
- * (annotations, row metadata) that fails to load is a warning: it is
2695
- * not worth replacing an alignment the reader is looking at with an
2696
- * error screen over a decorative file.
3459
+ * `what` names the layer in a failure message. An `optional` layer
3460
+ * (annotations, row metadata) that fails adds a warning instead of an
3461
+ * error.
2697
3462
  */
2698
3463
  const loadOnFilehandleChange = ({ what, getFilehandle, onLoad, setLoading, clearFilehandle, optional = false, }) => {
2699
3464
  let generation = 0;
@@ -2772,8 +3537,7 @@ function stateModelFactory() {
2772
3537
  self.setTreeFilehandle(undefined);
2773
3538
  },
2774
3539
  });
2775
- // treeMetadata is decorative and has no import-form step of its own, so
2776
- // it keeps no loading flag and nothing to return to on cancel
3540
+ // treeMetadata has no import-form step, so no loading flag or cancel
2777
3541
  loadOnFilehandleChange({
2778
3542
  what: 'row metadata',
2779
3543
  optional: true,
@@ -2782,11 +3546,8 @@ function stateModelFactory() {
2782
3546
  self.setTreeMetadata(text);
2783
3547
  },
2784
3548
  });
2785
- // autorun parses inline gff text from data.gff. Text that goes away
2786
- // takes its annotations with it -- setData with a new alignment and no
2787
- // gff used to leave the previous file's annotations drawn over it --
2788
- // while annotations a host set directly are left alone, which is why
2789
- // this tracks what it applied instead of reading the current list
3549
+ // parses data.gff into annotations. Clearing the text clears only the
3550
+ // annotations this autorun applied, not ones a host set directly
2790
3551
  let appliedGFF = false;
2791
3552
  addDisposer(self, autorun(() => {
2792
3553
  const gffText = self.data.gff;
@@ -2796,8 +3557,6 @@ function stateModelFactory() {
2796
3557
  appliedGFF = true;
2797
3558
  }
2798
3559
  catch (e) {
2799
- // a malformed overlay is not worth replacing the alignment
2800
- // with an error screen
2801
3560
  console.error(e);
2802
3561
  self.addWarning(`The annotations did not parse: ${e}`);
2803
3562
  }
@@ -2807,9 +3566,7 @@ function stateModelFactory() {
2807
3566
  self.setAnnotations([]);
2808
3567
  }
2809
3568
  }));
2810
- // gffFilehandle carries overlay annotations. It loads into data.gff and
2811
- // the autorun above parses it, so there is one parse path whether the
2812
- // text arrived from a file or from a snapshot
3569
+ // gffFilehandle loads into data.gff, which the autorun above parses
2813
3570
  loadOnFilehandleChange({
2814
3571
  what: 'annotations',
2815
3572
  optional: true,
@@ -2834,19 +3591,12 @@ function stateModelFactory() {
2834
3591
  self.setMSAFilehandle(undefined);
2835
3592
  },
2836
3593
  });
2837
- // Keep the parse chain warm: reading self.columns transitively holds
2838
- // self.MSA (parseMSA) computed alive, so it is parsed once per data
2839
- // change rather than re-parsed on every non-reactive access. Do not
2840
- // remove.
3594
+ // Keep computeds alive that are read outside reactions, so they are not
3595
+ // recomputed on every access: self.columns (and through it the
3596
+ // parseMSA result), and the column statistics that dynamic color
3597
+ // schemes and the mousemove-driven hover tooltip read.
2841
3598
  // xref solution https://github.com/mobxjs/mobx/issues/266#issuecomment-222007278
2842
3599
  // xref problem https://github.com/GMOD/react-msaview/issues/75
2843
- //
2844
- // The column statistics are held for the same reason whenever something
2845
- // reads them off the reactive path: dynamic color schemes, and the hover
2846
- // tooltip, which is read from a mousemove handler. Without this the
2847
- // tooltip's cost depends on whether some visible track happens to be
2848
- // observing them, so closing the conservation track would silently turn
2849
- // every mouse move into a full-alignment recount.
2850
3600
  addDisposer(self, autorun(() => {
2851
3601
  if (self.colorSchemeName.includes('dynamic')) {
2852
3602
  // eslint-disable-next-line @typescript-eslint/no-unused-expressions
@@ -2864,25 +3614,20 @@ function stateModelFactory() {
2864
3614
  // eslint-disable-next-line @typescript-eslint/no-unused-expressions
2865
3615
  self.columns;
2866
3616
  }));
2867
- // autorun: when autoTreeAreaWidth is set and no tree is drawn, shrink the
2868
- // tree area to fit the row labels rather than padding it to the fixed
2869
- // default. Gated on noTree/!drawTree so it never fights the treeWidth sync
2870
- // below (treeAreaWidth here depends only on labelsWidth, not treeWidth).
3617
+ // with autoTreeAreaWidth and no tree drawn, size the tree area to the
3618
+ // labels. Gated on noTree/!drawTree so it does not loop with the
3619
+ // treeWidth autorun below
2871
3620
  addDisposer(self, autorun(() => {
2872
3621
  if (self.autoTreeAreaWidth &&
2873
3622
  (self.noTree || !self.drawTree) &&
2874
3623
  self.labelsWidth) {
2875
- self.setTreeAreaWidth(self.labelsWidth + self.marginLeft + 12);
3624
+ self.setTreeAreaWidth(self.labelsWidth + self.marginLeft + 12 + self.cladeGutterWidth);
2876
3625
  }
2877
3626
  }));
2878
- // treeWidth trails the tree area, less whatever the labels take out of
2879
- // it. A width that arrived with the snapshot is left alone until the
2880
- // tree area itself moves: a host that opens a view with a narrow tree
2881
- // beside wide labels -- jbrowse-plugin-msaview does, at treeWidth 100
2882
- // in a 200px area -- had its value overwritten on the first frame, and
2883
- // a restored session came back re-derived rather than as it was left.
2884
- // A getter cannot do this: labelsWidth is measured off the leaves,
2885
- // which are laid out against treeWidth.
3627
+ // treeWidth follows the tree area less the labels. A non-default
3628
+ // snapshot treeWidth (jbrowse-plugin-msaview opens at 100 in a 200px
3629
+ // area) is kept until the tree area changes. Not a getter, because
3630
+ // labelsWidth is measured off leaves laid out against treeWidth.
2886
3631
  let pinnedAreaWidth = self.treeWidth === defaultTreeWidth ? undefined : self.treeAreaWidth;
2887
3632
  addDisposer(self, autorun(() => {
2888
3633
  const areaWidth = self.treeAreaWidth;
@@ -2891,14 +3636,17 @@ function stateModelFactory() {
2891
3636
  return;
2892
3637
  }
2893
3638
  pinnedAreaWidth = undefined;
2894
- self.setTreeWidth(Math.max(50, areaWidth - labelsWidth - 10 - self.marginLeft));
3639
+ self.setTreeWidth(Math.max(50, areaWidth -
3640
+ labelsWidth -
3641
+ 10 -
3642
+ self.marginLeft -
3643
+ self.cladeGutterWidth));
2895
3644
  }));
2896
3645
  },
2897
3646
  }))
2898
3647
  .postProcessSnapshot(({ data, columnTracks, ...rest }) => ({
2899
- // per-property defaults are stripped by the stripDefault helper; the only thing
2900
- // it can't express is this cross-field rule: drop inline tree/msa/metadata
2901
- // when a sibling filehandle can refetch them, keeping sessions/URLs small
3648
+ // stripDefault handles per-property defaults; this drops inline documents
3649
+ // whose filehandle can refetch them
2902
3650
  ...rest,
2903
3651
  ...smallColumnTracks(columnTracks),
2904
3652
  data: {