jbrowse-plugin-graphgenomeviewer 8.0.0 → 8.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. package/dist/chunks/{AddTrackWorkflow-KT6Z6PSW.js → AddTrackWorkflow-RJSOQZYQ.js} +2 -2
  2. package/dist/chunks/{ChooseSamplesDialog-YUH6SVEZ.js → ChooseSamplesDialog-LO7FKFSS.js} +2 -2
  3. package/dist/chunks/{ChooseWalksDialog-2QJKRASB.js → ChooseWalksDialog-JJSOVCEU.js} +2 -2
  4. package/dist/chunks/{GbzBaseSyntenyAdapter-NPEXW3Z3.js → GbzBaseSyntenyAdapter-EGNUOKB2.js} +2 -2
  5. package/dist/chunks/{GbzBaseSyntenyAdapter-NPEXW3Z3.js.map → GbzBaseSyntenyAdapter-EGNUOKB2.js.map} +1 -1
  6. package/dist/chunks/{GraphGenomeView-5LYF6LMA.js → GraphGenomeView-667ZUNDI.js} +2 -2
  7. package/dist/chunks/{GraphTrackSettingsDialog-T5YKMIPH.js → GraphTrackSettingsDialog-7M3Q635V.js} +2 -2
  8. package/dist/chunks/{GraphTrackSettingsDialog-T5YKMIPH.js.map → GraphTrackSettingsDialog-7M3Q635V.js.map} +1 -1
  9. package/dist/chunks/{HighlightColorDialog-UGAQFACU.js → HighlightColorDialog-4F34Q4PY.js} +2 -2
  10. package/dist/chunks/LinearGraphDisplay-BAEMS5WG.js +2 -0
  11. package/dist/chunks/LinearGraphDisplay-BAEMS5WG.js.map +7 -0
  12. package/dist/chunks/{MinigraphBubbleAdapter-D57ZFMKV.js → MinigraphBubbleAdapter-G25V6MZL.js} +2 -2
  13. package/dist/chunks/{RgfaTabixAdapter-HN2NLJJW.js → RgfaTabixAdapter-JPTUWO2Z.js} +2 -2
  14. package/dist/chunks/{WalkFormsAdapter-ESCQSNEJ.js → WalkFormsAdapter-PBN7BJZW.js} +2 -2
  15. package/dist/chunks/{WalkTabixSyntenyAdapter-62PJZBRP.js → WalkTabixSyntenyAdapter-27WDE5JF.js} +2 -2
  16. package/dist/chunks/{chunk-SVLBMU6I.js → chunk-2PNGGCQJ.js} +2 -2
  17. package/dist/chunks/{chunk-SVLBMU6I.js.map → chunk-2PNGGCQJ.js.map} +1 -1
  18. package/dist/chunks/{chunk-2VKDQF54.js → chunk-2V75YPTT.js} +2 -2
  19. package/dist/chunks/{chunk-2VKDQF54.js.map → chunk-2V75YPTT.js.map} +3 -3
  20. package/dist/chunks/chunk-3EQNVA3F.js +4 -0
  21. package/dist/chunks/{chunk-H53NTUCD.js.map → chunk-3EQNVA3F.js.map} +4 -4
  22. package/dist/chunks/{chunk-ON465L7Z.js → chunk-5RHNR3TH.js} +1 -1
  23. package/dist/chunks/{chunk-ON465L7Z.js.map → chunk-5RHNR3TH.js.map} +1 -1
  24. package/dist/chunks/{chunk-LR45N54F.js → chunk-CBKSPAUI.js} +2 -2
  25. package/dist/chunks/{chunk-VCYF5E2N.js → chunk-CJAV55QB.js} +1 -1
  26. package/dist/chunks/{chunk-VCYF5E2N.js.map → chunk-CJAV55QB.js.map} +1 -1
  27. package/dist/chunks/{chunk-DKUKQR3S.js → chunk-DG3E6BSX.js} +2 -2
  28. package/dist/chunks/{chunk-ZKCMVSD4.js → chunk-FY7X6253.js} +2 -2
  29. package/dist/chunks/{chunk-ZKCMVSD4.js.map → chunk-FY7X6253.js.map} +1 -1
  30. package/dist/chunks/chunk-HLAQQI6G.js +2 -0
  31. package/dist/chunks/chunk-HLAQQI6G.js.map +7 -0
  32. package/dist/chunks/{chunk-NE3OW4WX.js → chunk-I6F25EXY.js} +2 -2
  33. package/dist/chunks/{chunk-QGLMVXGX.js → chunk-IAXUZMOX.js} +2 -2
  34. package/dist/chunks/{chunk-QGLMVXGX.js.map → chunk-IAXUZMOX.js.map} +1 -1
  35. package/dist/chunks/{chunk-56YYNIV3.js → chunk-JMRW3IGK.js} +2 -2
  36. package/dist/chunks/{chunk-56YYNIV3.js.map → chunk-JMRW3IGK.js.map} +1 -1
  37. package/dist/chunks/chunk-JOYKGTDE.js +4 -0
  38. package/dist/chunks/chunk-JOYKGTDE.js.map +7 -0
  39. package/dist/chunks/chunk-NIEZKWQV.js +2 -0
  40. package/dist/chunks/{chunk-YU7T5WOQ.js.map → chunk-NIEZKWQV.js.map} +2 -2
  41. package/dist/chunks/chunk-NLS74JSZ.js +2 -0
  42. package/dist/chunks/{chunk-26SCNTI3.js.map → chunk-NLS74JSZ.js.map} +1 -1
  43. package/dist/chunks/{chunk-A4YQH3PN.js → chunk-O5FDMVL3.js} +2 -2
  44. package/dist/chunks/chunk-Q7QC2EQU.js +2 -0
  45. package/dist/chunks/chunk-RHYBJCA4.js +2 -0
  46. package/dist/chunks/chunk-RHYBJCA4.js.map +7 -0
  47. package/dist/chunks/chunk-X7YIGIYW.js +2 -0
  48. package/dist/chunks/{chunk-YXN7J6LG.js.map → chunk-X7YIGIYW.js.map} +4 -4
  49. package/dist/chunks/chunk-XB5KC2EZ.js +2 -0
  50. package/dist/chunks/{chunk-JSWEU5QG.js.map → chunk-XB5KC2EZ.js.map} +2 -2
  51. package/dist/chunks/chunk-XWCLYB5C.js +2 -0
  52. package/dist/chunks/{chunk-KQ6JJDJC.js.map → chunk-XWCLYB5C.js.map} +4 -4
  53. package/dist/chunks/{chunk-SD7WGQ6Y.js → chunk-ZGTG74GE.js} +3 -3
  54. package/dist/chunks/{chunk-SD7WGQ6Y.js.map → chunk-ZGTG74GE.js.map} +2 -2
  55. package/dist/chunks/renderSvg-YNA5VK6A.js +2 -0
  56. package/dist/chunks/renderSvg-YNA5VK6A.js.map +7 -0
  57. package/dist/jbrowse-plugin-graphgenomeviewer.esm.js +4 -4
  58. package/dist/jbrowse-plugin-graphgenomeviewer.esm.js.map +4 -4
  59. package/package.json +2 -2
  60. package/src/GraphGenomeView/components/GraphCanvas.test.tsx +1 -1
  61. package/src/GraphGenomeView/components/GraphCanvas.tsx +66 -18
  62. package/src/GraphGenomeView/components/Legend.tsx +81 -34
  63. package/src/GraphGenomeView/components/LegendSwatch.tsx +13 -30
  64. package/src/GraphGenomeView/components/PaneSvg.tsx +79 -22
  65. package/src/GraphGenomeView/components/SettingsMenu.tsx +1 -1
  66. package/src/GraphGenomeView/components/legendStyles.ts +13 -1
  67. package/src/GraphGenomeView/legendSections.test.ts +131 -2
  68. package/src/GraphGenomeView/legendSections.ts +220 -42
  69. package/src/GraphGenomeView/model.test.ts +7 -8
  70. package/src/GraphGenomeView/pane/fitViews.ts +6 -57
  71. package/src/GraphGenomeView/pane/graphViews.ts +23 -1
  72. package/src/GraphGenomeView/pane/launchActions.ts +1 -1
  73. package/src/LinearGraphDisplay/LinearGraphDisplay.test.ts +19 -1
  74. package/src/LinearGraphDisplay/components/LinearGraphDisplay.tsx +6 -6
  75. package/src/LinearGraphDisplay/model.ts +9 -10
  76. package/src/RgfaTabixAdapter/walkFiles.test.ts +36 -0
  77. package/src/RgfaTabixAdapter/walkReader.ts +22 -7
  78. package/src/version.ts +1 -1
  79. package/dist/chunks/LinearGraphDisplay-YTSXFZED.js +0 -2
  80. package/dist/chunks/LinearGraphDisplay-YTSXFZED.js.map +0 -7
  81. package/dist/chunks/chunk-26SCNTI3.js +0 -2
  82. package/dist/chunks/chunk-AZ3YVI3P.js +0 -2
  83. package/dist/chunks/chunk-H53NTUCD.js +0 -4
  84. package/dist/chunks/chunk-JSWEU5QG.js +0 -2
  85. package/dist/chunks/chunk-JYTZO52E.js +0 -2
  86. package/dist/chunks/chunk-JYTZO52E.js.map +0 -7
  87. package/dist/chunks/chunk-KQ6JJDJC.js +0 -2
  88. package/dist/chunks/chunk-KUT6FNKO.js +0 -4
  89. package/dist/chunks/chunk-KUT6FNKO.js.map +0 -7
  90. package/dist/chunks/chunk-LJAPKX5Y.js +0 -2
  91. package/dist/chunks/chunk-LJAPKX5Y.js.map +0 -7
  92. package/dist/chunks/chunk-YU7T5WOQ.js +0 -2
  93. package/dist/chunks/chunk-YXN7J6LG.js +0 -2
  94. package/dist/chunks/renderSvg-3KAQCRFY.js +0 -2
  95. package/dist/chunks/renderSvg-3KAQCRFY.js.map +0 -7
  96. package/src/LinearGraphDisplay/components/GraphStatusChrome.test.tsx +0 -182
  97. package/src/LinearGraphDisplay/components/GraphStatusChrome.tsx +0 -158
  98. /package/dist/chunks/{AddTrackWorkflow-KT6Z6PSW.js.map → AddTrackWorkflow-RJSOQZYQ.js.map} +0 -0
  99. /package/dist/chunks/{ChooseSamplesDialog-YUH6SVEZ.js.map → ChooseSamplesDialog-LO7FKFSS.js.map} +0 -0
  100. /package/dist/chunks/{ChooseWalksDialog-2QJKRASB.js.map → ChooseWalksDialog-JJSOVCEU.js.map} +0 -0
  101. /package/dist/chunks/{GraphGenomeView-5LYF6LMA.js.map → GraphGenomeView-667ZUNDI.js.map} +0 -0
  102. /package/dist/chunks/{HighlightColorDialog-UGAQFACU.js.map → HighlightColorDialog-4F34Q4PY.js.map} +0 -0
  103. /package/dist/chunks/{MinigraphBubbleAdapter-D57ZFMKV.js.map → MinigraphBubbleAdapter-G25V6MZL.js.map} +0 -0
  104. /package/dist/chunks/{RgfaTabixAdapter-HN2NLJJW.js.map → RgfaTabixAdapter-JPTUWO2Z.js.map} +0 -0
  105. /package/dist/chunks/{WalkFormsAdapter-ESCQSNEJ.js.map → WalkFormsAdapter-PBN7BJZW.js.map} +0 -0
  106. /package/dist/chunks/{WalkTabixSyntenyAdapter-62PJZBRP.js.map → WalkTabixSyntenyAdapter-27WDE5JF.js.map} +0 -0
  107. /package/dist/chunks/{chunk-LR45N54F.js.map → chunk-CBKSPAUI.js.map} +0 -0
  108. /package/dist/chunks/{chunk-DKUKQR3S.js.map → chunk-DG3E6BSX.js.map} +0 -0
  109. /package/dist/chunks/{chunk-NE3OW4WX.js.map → chunk-I6F25EXY.js.map} +0 -0
  110. /package/dist/chunks/{chunk-A4YQH3PN.js.map → chunk-O5FDMVL3.js.map} +0 -0
  111. /package/dist/chunks/{chunk-AZ3YVI3P.js.map → chunk-Q7QC2EQU.js.map} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jbrowse-plugin-graphgenomeviewer",
3
- "version": "8.0.0",
3
+ "version": "8.0.2",
4
4
  "description": "JBrowse 2 graph genome (pangenome) view: rGFA reference-anchored layouts, the Bandage force-directed engine, and haplotype lanes read from a gbz-base database",
5
5
  "license": "GPL-3.0-or-later",
6
6
  "repository": {
@@ -40,7 +40,7 @@
40
40
  "@emotion/react": "^11.14.0",
41
41
  "@emotion/styled": "^11.14.1",
42
42
  "@eslint/js": "^10.0.1",
43
- "@jbrowse/bandage-core": "^12.0.0",
43
+ "@jbrowse/bandage-core": "^12.0.2",
44
44
  "@jbrowse/cli": "^4.3.0",
45
45
  "@jbrowse/mobx-state-tree": "^6.10.0",
46
46
  "@jbrowse/plugin-linear-genome-view": "5.0.0-beta.18",
@@ -40,7 +40,7 @@ beforeEach(() => {
40
40
  vi.spyOn(HTMLElement.prototype, 'offsetWidth', 'get').mockImplementation(
41
41
  () => size.width,
42
42
  )
43
- vi.spyOn(HTMLElement.prototype, 'offsetHeight', 'get').mockImplementation(
43
+ vi.spyOn(Element.prototype, 'scrollHeight', 'get').mockImplementation(
44
44
  () => size.height,
45
45
  )
46
46
  vi.stubGlobal(
@@ -26,6 +26,7 @@ import { PAPER_CSS } from '../pane/paneBase'
26
26
  import { createGraphRenderer } from '../renderer/GraphRenderer'
27
27
 
28
28
  import type { GraphPaneModel } from '../model'
29
+ import type { CanvasHandle } from '@jbrowse/display-kit/DisplayChromeBase'
29
30
 
30
31
  const wrapperStyle = { position: 'relative' as const }
31
32
 
@@ -125,7 +126,8 @@ const legendStackStyle = {
125
126
  display: 'flex',
126
127
  flexDirection: 'column' as const,
127
128
  borderRadius: 3,
128
- overflow: 'hidden' as const,
129
+ overflowX: 'hidden' as const,
130
+ overflowY: 'auto' as const,
129
131
  zIndex: 4,
130
132
  }
131
133
 
@@ -166,15 +168,20 @@ export const Legends = observer(function Legends({
166
168
  if (!el || !atRest) {
167
169
  return
168
170
  }
169
- // the last callback can land after the track is closed
171
+ // the last callback can land after the track is closed. scrollHeight is
172
+ // the whole key, even where the pane caps it to scroll, so the pane
173
+ // still grows to show it all when it can.
170
174
  const measure = () => {
171
175
  if (isAlive(model) && model.legendAtRest) {
172
- model.setLegendSize({ width: el.offsetWidth, height: el.offsetHeight })
176
+ model.setLegendSize({ width: el.offsetWidth, height: el.scrollHeight })
173
177
  }
174
178
  }
175
179
  measure()
176
180
  const observer = new ResizeObserver(measure)
177
181
  observer.observe(el)
182
+ if (el.firstElementChild) {
183
+ observer.observe(el.firstElementChild)
184
+ }
178
185
  return () => {
179
186
  observer.disconnect()
180
187
  }
@@ -185,6 +192,8 @@ export const Legends = observer(function Legends({
185
192
  style={{
186
193
  ...legendStackStyle,
187
194
  top: LEGEND_INSET_PX + model.referenceStripZonePx,
195
+ maxHeight:
196
+ model.canvasHeight - 2 * LEGEND_INSET_PX - model.referenceStripZonePx,
188
197
  }}
189
198
  >
190
199
  <LegendPanel model={model} />
@@ -247,23 +256,27 @@ const GraphSizeLabels = observer(function GraphSizeLabels({
247
256
  )
248
257
  })
249
258
 
250
- // `ownChrome` false for a pane inside a track, whose controls, loading state
251
- // and errors are the track's. A hosted pane whose x the host places takes no pan or wheel of its
252
- // own: those are the linear view's, as on any other track. One drawing its
253
- // own coordinates inside a track keeps them, and keeps them from the view.
254
- const GraphCanvas = observer(function GraphCanvas({
259
+ type PaneCanvas = Pick<CanvasHandle, 'canvasRef' | 'canvas'>
260
+
261
+ interface OwnChrome {
262
+ renderError: unknown
263
+ retryRender: () => void
264
+ }
265
+
266
+ // `ownChrome` absent for a pane inside a track, whose controls, loading
267
+ // state and errors are the track's `DisplayChrome`. A hosted pane whose x the
268
+ // host places takes no pan or wheel of its own: those are the linear view's,
269
+ // as on any other track. One drawing its own coordinates inside a track keeps
270
+ // them, and keeps them from the view.
271
+ const GraphCanvasBody = observer(function GraphCanvasBody({
255
272
  model,
256
- ownChrome = true,
273
+ handle: { canvasRef, canvas },
274
+ ownChrome,
257
275
  }: {
258
276
  model: GraphPaneModel
259
- ownChrome?: boolean
277
+ handle: PaneCanvas
278
+ ownChrome?: OwnChrome
260
279
  }) {
261
- const {
262
- canvasRef,
263
- canvas,
264
- error: renderError,
265
- retry: retryRender,
266
- } = useRenderingBackend(createGraphRenderer, model)
267
280
  const {
268
281
  handlers,
269
282
  canvasStyle,
@@ -367,8 +380,11 @@ const GraphCanvas = observer(function GraphCanvas({
367
380
  onClose={closeContextMenu}
368
381
  />
369
382
 
370
- {renderError ? (
371
- <ErrorBanner error={renderError} onReset={retryRender} />
383
+ {ownChrome?.renderError ? (
384
+ <ErrorBanner
385
+ error={ownChrome.renderError}
386
+ onReset={ownChrome.retryRender}
387
+ />
372
388
  ) : null}
373
389
 
374
390
  {ownChrome && model.error ? (
@@ -387,4 +403,36 @@ const GraphCanvas = observer(function GraphCanvas({
387
403
  )
388
404
  })
389
405
 
406
+ const StandaloneGraphCanvas = observer(function StandaloneGraphCanvas({
407
+ model,
408
+ }: {
409
+ model: GraphPaneModel
410
+ }) {
411
+ const { canvasRef, canvas, error, retry } = useRenderingBackend(
412
+ createGraphRenderer,
413
+ model,
414
+ )
415
+ return (
416
+ <GraphCanvasBody
417
+ model={model}
418
+ handle={{ canvasRef, canvas }}
419
+ ownChrome={{ renderError: error, retryRender: retry }}
420
+ />
421
+ )
422
+ })
423
+
424
+ const GraphCanvas = observer(function GraphCanvas({
425
+ model,
426
+ handle,
427
+ }: {
428
+ model: GraphPaneModel
429
+ handle?: PaneCanvas
430
+ }) {
431
+ return handle ? (
432
+ <GraphCanvasBody model={model} handle={handle} />
433
+ ) : (
434
+ <StandaloneGraphCanvas model={model} />
435
+ )
436
+ })
437
+
390
438
  export default GraphCanvas
@@ -1,31 +1,52 @@
1
+ import { Fragment } from 'react'
1
2
  import type { ReactNode } from 'react'
2
3
 
3
4
  import { observer } from 'mobx-react'
4
5
 
5
6
  import { LegendSwatchView } from './LegendSwatch'
6
- import { legendBoxStyle, legendNoteStyle, legendRowStyle } from './legendStyles'
7
- import { legendSections } from '../legendSections'
7
+ import {
8
+ HEADING_GAP_PX,
9
+ legendBoxStyle,
10
+ legendHeadingStyle,
11
+ legendNoteStyle,
12
+ legendRowStyle,
13
+ } from './legendStyles'
14
+ import { legendSections, rowPitch, swatchColumn } from '../legendSections'
8
15
 
9
16
  import type { LegendRow } from '../legendSections'
10
17
  import type { GraphPaneModel } from '../model'
11
18
 
12
- // One row: its swatch then its words, or a note with neither. `at`, where
13
- // the hovered node sits on a walk, stands in for the line under it.
19
+ // One row: its swatch then its words, or a note with neither.
20
+ // `at`, where the hovered node sits on a walk, stands in for the line under
21
+ // it. A `column` centres the swatch in a slot that wide and indents the line
22
+ // under to the words.
14
23
  export function LegendRowView({
15
24
  row,
16
25
  at,
17
26
  hint,
18
27
  after,
28
+ column,
19
29
  }: {
20
30
  row: LegendRow
21
31
  at?: string
22
32
  hint?: string
23
33
  after?: ReactNode
34
+ column?: number
24
35
  }) {
36
+ const indent = column === undefined ? undefined : { paddingLeft: column + 5 }
25
37
  return row.swatch ? (
26
38
  <div title={[row.title, hint].filter(Boolean).join(' · ') || undefined}>
27
39
  <div style={legendRowStyle}>
28
- <LegendSwatchView swatch={row.swatch} />
40
+ <span
41
+ style={{
42
+ display: 'flex',
43
+ flex: 'none',
44
+ justifyContent: 'center',
45
+ width: column,
46
+ }}
47
+ >
48
+ <LegendSwatchView swatch={row.swatch} />
49
+ </span>
29
50
  <span>
30
51
  {row.strong ? <strong>{row.strong}</strong> : null}
31
52
  {row.label}
@@ -33,9 +54,11 @@ export function LegendRowView({
33
54
  {after}
34
55
  </div>
35
56
  {at ? (
36
- <div data-testid="graph-walk-at">{at}</div>
57
+ <div style={indent} data-testid="graph-walk-at">
58
+ {at}
59
+ </div>
37
60
  ) : row.under ? (
38
- <div>{row.under}</div>
61
+ <div style={indent}>{row.under}</div>
39
62
  ) : null}
40
63
  </div>
41
64
  ) : (
@@ -53,39 +76,63 @@ const closeStyle = {
53
76
  textDecoration: 'underline',
54
77
  }
55
78
 
56
- // Every key the drawing needs, a section each
79
+ // Every key the drawing needs in one box, a section each, every line at one
80
+ // pitch
57
81
  export const LegendPanel = observer(function LegendPanel({
58
82
  model,
59
83
  }: {
60
84
  model: GraphPaneModel
61
85
  }) {
86
+ const sections = legendSections(model)
87
+ if (sections.length === 0) {
88
+ return null
89
+ }
90
+ const rows = sections.flatMap(section => section.rows)
91
+ const pitch = rowPitch(rows)
92
+ const column = swatchColumn(rows)
62
93
  return (
63
- <>
64
- {legendSections(model).map(({ testid, rows }) => (
65
- <div key={testid} style={legendBoxStyle} data-testid={testid}>
66
- {rows.map(row => (
67
- <LegendRowView
68
- key={row.key}
69
- row={row}
70
- at={row.walk ? model.hoveredOn(row.walk) : undefined}
71
- after={
72
- row.closesBubble ? (
73
- <button
74
- type="button"
75
- style={closeStyle}
76
- data-testid="graph-close-bubble"
77
- onClick={() => {
78
- model.closeBubbles()
79
- }}
80
- >
81
- close
82
- </button>
83
- ) : null
84
- }
85
- />
86
- ))}
87
- </div>
94
+ <div style={{ ...legendBoxStyle, lineHeight: `${pitch}px` }}>
95
+ {sections.map(({ testid, rows, heading, spaced }, i) => (
96
+ <Fragment key={testid}>
97
+ {heading ? (
98
+ <div
99
+ style={{
100
+ ...legendHeadingStyle,
101
+ paddingTop: i === 0 ? 0 : HEADING_GAP_PX,
102
+ }}
103
+ >
104
+ {heading}
105
+ </div>
106
+ ) : null}
107
+ <div
108
+ data-testid={testid}
109
+ style={spaced ? { paddingTop: HEADING_GAP_PX } : undefined}
110
+ >
111
+ {rows.map(row => (
112
+ <LegendRowView
113
+ key={row.key}
114
+ row={row}
115
+ column={column}
116
+ at={row.walk ? model.hoveredOn(row.walk) : undefined}
117
+ after={
118
+ row.closesBubble ? (
119
+ <button
120
+ type="button"
121
+ style={closeStyle}
122
+ data-testid="graph-close-bubble"
123
+ onClick={() => {
124
+ model.closeBubbles()
125
+ }}
126
+ >
127
+ close
128
+ </button>
129
+ ) : null
130
+ }
131
+ />
132
+ ))}
133
+ </div>
134
+ </Fragment>
88
135
  ))}
89
- </>
136
+ </div>
90
137
  )
91
138
  })
@@ -1,10 +1,12 @@
1
1
  import { rulerInk } from '@jbrowse/bandage-core/tubeMap/axis'
2
2
 
3
3
  import { useSvgId } from './ElTree'
4
- import { SWATCH_PX, swatchWidth } from '../legendSections'
4
+ import { SWATCH_PX, bandPx, swatchHeight, swatchWidth } from '../legendSections'
5
5
 
6
6
  import type { LegendSwatch, Stop } from '../legendSections'
7
7
 
8
+ const EDGE_INK = 'rgba(0, 0, 0, 0.28)'
9
+
8
10
  function Gradient({
9
11
  id,
10
12
  x,
@@ -13,6 +15,7 @@ function Gradient({
13
15
  width,
14
16
  height,
15
17
  square,
18
+ edged,
16
19
  }: {
17
20
  id: string
18
21
  x: number
@@ -21,15 +24,19 @@ function Gradient({
21
24
  width: number
22
25
  height: number
23
26
  square?: boolean
27
+ edged?: boolean
24
28
  }) {
29
+ // an edge's stroke sits half inside, so the chip keeps its size
30
+ const inset = edged ? 0.5 : 0
25
31
  const rect = (fill: string) => (
26
32
  <rect
27
- x={x}
28
- y={y}
29
- width={width}
30
- height={height}
33
+ x={x + inset}
34
+ y={y + inset}
35
+ width={width - inset * 2}
36
+ height={height - inset * 2}
31
37
  rx={square ? 0 : 2}
32
38
  fill={fill}
39
+ stroke={edged ? EDGE_INK : undefined}
33
40
  />
34
41
  )
35
42
  return stops.length > 1 ? (
@@ -48,31 +55,6 @@ function Gradient({
48
55
  )
49
56
  }
50
57
 
51
- const bandPx = (bands: readonly unknown[]) => (bands.length > 1 ? 3 : 4)
52
-
53
- function swatchHeight(swatch: LegendSwatch) {
54
- switch (swatch.kind) {
55
- case 'fill':
56
- return swatch.height ?? 8
57
- case 'bands':
58
- return bandPx(swatch.bands) * swatch.bands.length
59
- case 'line':
60
- return 3
61
- case 'halo':
62
- case 'overhang':
63
- return 10
64
- case 'outline':
65
- case 'tick':
66
- return swatch.height
67
- case 'glyph':
68
- return 15
69
- case 'bracket':
70
- return 7
71
- case 'blank':
72
- return 0
73
- }
74
- }
75
-
76
58
  // A row's swatch with its left edge at x, centred on the row's text 5 px
77
59
  // above the baseline
78
60
  export function SvgSwatch({
@@ -97,6 +79,7 @@ export function SvgSwatch({
97
79
  width={swatchWidth(swatch)}
98
80
  height={height}
99
81
  square={swatch.square}
82
+ edged={swatch.edged}
100
83
  />
101
84
  )
102
85
  }
@@ -12,9 +12,12 @@ import { SvgSwatch } from './LegendSwatch'
12
12
  import { paintReferenceStrip } from './ReferenceStripOverlay'
13
13
  import { paintTubeMap } from './TubeMapOverlay'
14
14
  import WalkRowsOverlay from './WalkRowsOverlay'
15
+ import { HEADING_GAP_PX, HEADING_INK } from './legendStyles'
15
16
  import {
16
17
  facetKeyRows,
17
18
  legendSections,
19
+ rowPitch,
20
+ swatchColumn,
18
21
  swatchWidth,
19
22
  walkKeyRow,
20
23
  } from '../legendSections'
@@ -85,14 +88,50 @@ interface KeyRow {
85
88
  draw: (left: number) => React.ReactNode
86
89
  }
87
90
 
91
+ // A group's name in small capitals, a gap below the rows before it
92
+ function svgHeading(
93
+ heading: string,
94
+ key: string,
95
+ pitch: number,
96
+ first: boolean,
97
+ ): KeyRow {
98
+ const gap = first ? 0 : HEADING_GAP_PX
99
+ const text = heading.toUpperCase()
100
+ return {
101
+ key,
102
+ width: text.length * LABEL_CHAR_PX,
103
+ height: pitch + gap,
104
+ draw: left => (
105
+ <text
106
+ key={key}
107
+ fontFamily="sans-serif"
108
+ fontSize={9.5}
109
+ fontWeight={600}
110
+ letterSpacing="0.06em"
111
+ x={left}
112
+ y={gap}
113
+ fill={HEADING_INK}
114
+ >
115
+ {text}
116
+ </text>
117
+ ),
118
+ }
119
+ }
120
+
88
121
  // A legend row as the screen lays it out: its swatch, then its words, the
89
- // line under it if any; a note is grey words alone
90
- function svgRow(row: LegendRow, id: string): KeyRow {
122
+ // line under it if any; a note is grey words alone. A `column` is the slot
123
+ // every swatch of the key is centred in.
124
+ function svgRow(
125
+ row: LegendRow,
126
+ id: string,
127
+ pitch = ROW_PX,
128
+ column?: number,
129
+ ): KeyRow {
91
130
  if (!row.swatch) {
92
131
  return {
93
132
  key: row.key,
94
133
  width: row.label.length * LABEL_CHAR_PX,
95
- height: ROW_PX,
134
+ height: pitch,
96
135
  draw: left => (
97
136
  <text key={row.key} {...FONT} x={left} y={0} fill="#666">
98
137
  {row.label}
@@ -101,24 +140,29 @@ function svgRow(row: LegendRow, id: string): KeyRow {
101
140
  }
102
141
  }
103
142
  const swatch = row.swatch
104
- const sw = swatchWidth(swatch)
143
+ const sw = column ?? swatchWidth(swatch)
144
+ const indent = column === undefined ? 0 : column + 5
105
145
  const words = (row.strong ?? '') + row.label
106
146
  return {
107
147
  key: row.key,
108
148
  width: Math.max(
109
149
  sw + 5 + words.length * LABEL_CHAR_PX,
110
- (row.under?.length ?? 0) * LABEL_CHAR_PX,
150
+ indent + (row.under?.length ?? 0) * LABEL_CHAR_PX,
111
151
  ),
112
- height: row.under ? ROW_PX * 2 : ROW_PX,
152
+ height: row.under ? pitch * 2 : pitch,
113
153
  draw: left => (
114
154
  <g key={row.key} {...FONT}>
115
- <SvgSwatch swatch={swatch} x={left} id={id} />
155
+ <SvgSwatch
156
+ swatch={swatch}
157
+ x={left + (sw - swatchWidth(swatch)) / 2}
158
+ id={id}
159
+ />
116
160
  <text x={left + sw + 5} y={0}>
117
161
  {row.strong ? <tspan fontWeight="bold">{row.strong}</tspan> : null}
118
162
  {row.label}
119
163
  </text>
120
164
  {row.under ? (
121
- <text x={left} y={ROW_PX}>
165
+ <text x={left + indent} y={pitch}>
122
166
  {row.under}
123
167
  </text>
124
168
  ) : null}
@@ -135,29 +179,43 @@ function Keys({
135
179
  model: GraphPaneModel
136
180
  idPrefix: string
137
181
  }) {
138
- const sections = legendSections(model).map(({ testid, rows }) =>
139
- rows.map((row, i) => svgRow(row, `${idPrefix}-${testid}-${i}`)),
140
- )
182
+ const sections = legendSections(model)
141
183
  if (sections.length === 0) {
142
184
  return null
143
185
  }
186
+ const all = sections.flatMap(section => section.rows)
187
+ const pitch = rowPitch(all)
188
+ const column = swatchColumn(all)
189
+ const rows = sections.flatMap(({ testid, rows, heading, spaced }, s) => [
190
+ ...(heading
191
+ ? [svgHeading(heading, `${testid}-heading`, pitch, s === 0)]
192
+ : []),
193
+ ...(spaced
194
+ ? [
195
+ {
196
+ key: `${testid}-gap`,
197
+ width: 0,
198
+ height: HEADING_GAP_PX,
199
+ draw: () => null,
200
+ },
201
+ ]
202
+ : []),
203
+ ...rows.map((row, i) =>
204
+ svgRow(row, `${idPrefix}-${testid}-${i}`, pitch, column),
205
+ ),
206
+ ])
144
207
  const pad = 6
145
- const rows = sections.flat()
146
208
  const boxWidth =
147
209
  rows.reduce((max, r) => Math.max(max, r.width), -Infinity) + pad * 2
148
- const boxHeight =
149
- rows.reduce((sum, r) => sum + r.height, 0) + sections.length * pad
210
+ const boxHeight = rows.reduce((sum, r) => sum + r.height, 0) + pad
150
211
  const right = model.paneWidth - LEGEND_INSET_PX
151
212
  const left = right - boxWidth + pad
152
213
  const top = LEGEND_INSET_PX + model.referenceStripZonePx
153
214
  const placed: { row: KeyRow; y: number }[] = []
154
- let y = top + 12 - pad / 2
155
- for (const section of sections) {
156
- y += pad
157
- for (const row of section) {
158
- placed.push({ row, y })
159
- y += row.height
160
- }
215
+ let y = top + pad / 2 + pitch / 2 + 4
216
+ for (const row of rows) {
217
+ placed.push({ row, y })
218
+ y += row.height
161
219
  }
162
220
  return (
163
221
  <g data-testid="graph-svg-keys">
@@ -168,7 +226,6 @@ function Keys({
168
226
  height={boxHeight}
169
227
  rx={3}
170
228
  fill="#fff"
171
- fillOpacity={0.82}
172
229
  />
173
230
  {placed.map(({ row, y }) => (
174
231
  <g key={row.key} transform={`translate(0 ${y})`}>
@@ -29,7 +29,7 @@ const SettingsMenu = observer(function SettingsMenu({
29
29
  : []),
30
30
  ...model.layoutOptionMenuItems({ repeat: false }),
31
31
  {
32
- label: 'Show...',
32
+ label: 'Show',
33
33
  icon: VisibilityIcon,
34
34
  subMenu: [
35
35
  ...model.showMenuItems(),
@@ -1,7 +1,7 @@
1
1
  // A key's section of the legend panel, and one row in it: a swatch beside its
2
2
  // words
3
3
  export const legendBoxStyle = {
4
- background: 'rgba(255,255,255,0.82)',
4
+ background: '#fff',
5
5
  padding: '3px 6px',
6
6
  fontSize: 11,
7
7
  lineHeight: '15px',
@@ -12,3 +12,15 @@ export const legendRowStyle = { display: 'flex', alignItems: 'center', gap: 5 }
12
12
 
13
13
  // A line with no swatch, such as what the drawing folded away
14
14
  export const legendNoteStyle = { color: '#666' }
15
+
16
+ export const HEADING_INK = '#6b7479'
17
+ export const HEADING_GAP_PX = 4
18
+
19
+ // A group's name over its rows, set apart by a gap unless it opens the key
20
+ export const legendHeadingStyle = {
21
+ color: HEADING_INK,
22
+ fontSize: 9.5,
23
+ fontWeight: 600,
24
+ letterSpacing: '0.06em',
25
+ textTransform: 'uppercase' as const,
26
+ }