react-msaview 3.1.3 → 3.1.4

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 (73) hide show
  1. package/bundle/index.js +5 -5
  2. package/dist/DialogQueue.js +2 -4
  3. package/dist/DialogQueue.js.map +1 -1
  4. package/dist/UniprotTrack.js +1 -1
  5. package/dist/UniprotTrack.js.map +1 -1
  6. package/dist/components/BoxTrackBlock.js +3 -4
  7. package/dist/components/BoxTrackBlock.js.map +1 -1
  8. package/dist/components/ImportForm/util.js +1 -0
  9. package/dist/components/ImportForm/util.js.map +1 -1
  10. package/dist/components/Loading.d.ts +6 -0
  11. package/dist/components/Loading.js +12 -0
  12. package/dist/components/Loading.js.map +1 -0
  13. package/dist/components/MSAPanel/MSABlock.js +3 -3
  14. package/dist/components/MSAPanel/MSABlock.js.map +1 -1
  15. package/dist/components/MSAPanel/MSAMouseoverCanvas.js +7 -9
  16. package/dist/components/MSAPanel/MSAMouseoverCanvas.js.map +1 -1
  17. package/dist/components/MSAPanel/index.js +1 -1
  18. package/dist/components/MSAPanel/index.js.map +1 -1
  19. package/dist/components/MSAPanel/renderMSABlock.d.ts +3 -1
  20. package/dist/components/MSAPanel/renderMSABlock.js +10 -10
  21. package/dist/components/MSAPanel/renderMSABlock.js.map +1 -1
  22. package/dist/components/MSAPanel/renderMSAMouseover.js +5 -8
  23. package/dist/components/MSAPanel/renderMSAMouseover.js.map +1 -1
  24. package/dist/components/MSAView.js +20 -16
  25. package/dist/components/MSAView.js.map +1 -1
  26. package/dist/components/TextTrack.js +1 -1
  27. package/dist/components/TextTrack.js.map +1 -1
  28. package/dist/components/TreePanel/TreeCanvasBlock.js +11 -13
  29. package/dist/components/TreePanel/TreeCanvasBlock.js.map +1 -1
  30. package/dist/components/TreePanel/TreeNodeMenu.js +4 -6
  31. package/dist/components/TreePanel/TreeNodeMenu.js.map +1 -1
  32. package/dist/components/TreePanel/renderTreeCanvas.js +12 -13
  33. package/dist/components/TreePanel/renderTreeCanvas.js.map +1 -1
  34. package/dist/index.d.ts +1 -1
  35. package/dist/index.js +1 -1
  36. package/dist/layout.js +5 -0
  37. package/dist/layout.js.map +1 -1
  38. package/dist/measureTextCanvas.d.ts +1 -0
  39. package/dist/measureTextCanvas.js +13 -0
  40. package/dist/measureTextCanvas.js.map +1 -0
  41. package/dist/model.d.ts +51 -52
  42. package/dist/model.js +20 -40
  43. package/dist/model.js.map +1 -1
  44. package/dist/parseNewick.js +1 -2
  45. package/dist/parseNewick.js.map +1 -1
  46. package/dist/parsers/ClustalMSA.js +3 -4
  47. package/dist/parsers/ClustalMSA.js.map +1 -1
  48. package/dist/parsers/FastaMSA.js +3 -4
  49. package/dist/parsers/FastaMSA.js.map +1 -1
  50. package/dist/parsers/StockholmMSA.js +13 -19
  51. package/dist/parsers/StockholmMSA.js.map +1 -1
  52. package/dist/renderToSvg.js +1 -0
  53. package/dist/renderToSvg.js.map +1 -1
  54. package/dist/util.js +7 -4
  55. package/dist/util.js.map +1 -1
  56. package/dist/version.d.ts +1 -1
  57. package/dist/version.js +1 -1
  58. package/package.json +1 -1
  59. package/src/components/ImportForm/util.ts +1 -0
  60. package/src/components/Loading.tsx +27 -0
  61. package/src/components/MSAPanel/MSABlock.tsx +2 -1
  62. package/src/components/MSAPanel/MSAMouseoverCanvas.tsx +6 -6
  63. package/src/components/MSAPanel/index.tsx +2 -2
  64. package/src/components/MSAPanel/renderMSABlock.ts +10 -1
  65. package/src/components/MSAPanel/renderMSAMouseover.ts +3 -17
  66. package/src/components/MSAView.tsx +28 -30
  67. package/src/components/TreePanel/TreeCanvasBlock.tsx +5 -6
  68. package/src/components/TreePanel/renderTreeCanvas.ts +4 -6
  69. package/src/index.ts +1 -1
  70. package/src/measureTextCanvas.ts +14 -0
  71. package/src/model.ts +4 -11
  72. package/src/renderToSvg.tsx +1 -0
  73. package/src/version.ts +1 -1
@@ -10,8 +10,6 @@ export function renderMouseover({
10
10
  const {
11
11
  mouseCol,
12
12
  colWidth,
13
- treeAreaWidth,
14
- resizeHandleWidth,
15
13
  width,
16
14
  height,
17
15
  rowHeight,
@@ -20,31 +18,19 @@ export function renderMouseover({
20
18
  mouseRow,
21
19
  // @ts-expect-error
22
20
  mouseCol2,
23
- minimapHeight,
24
- totalTrackAreaHeight,
25
21
  } = model
26
22
  ctx.resetTransform()
27
23
  ctx.clearRect(0, 0, width, height)
28
-
29
24
  if (mouseCol !== undefined) {
30
25
  ctx.fillStyle = 'rgba(0,0,0,0.15)'
31
- const x =
32
- (mouseCol - 1) * colWidth + scrollX + treeAreaWidth + resizeHandleWidth
33
-
34
- ctx.fillRect(x, minimapHeight, colWidth, height)
26
+ ctx.fillRect((mouseCol - 1) * colWidth + scrollX, 0, colWidth, height)
35
27
  }
36
-
37
28
  if (mouseRow !== undefined) {
38
29
  ctx.fillStyle = 'rgba(0,0,0,0.15)'
39
- const y =
40
- mouseRow * rowHeight + scrollY + minimapHeight + totalTrackAreaHeight
41
- ctx.fillRect(treeAreaWidth + resizeHandleWidth, y, width, rowHeight)
30
+ ctx.fillRect(0, mouseRow * rowHeight + scrollY, width, rowHeight)
42
31
  }
43
32
  if (mouseCol2 !== undefined) {
44
33
  ctx.fillStyle = 'rgba(255,255,0,0.2)'
45
- const x =
46
- (mouseCol2 - 1) * colWidth + scrollX + treeAreaWidth + resizeHandleWidth
47
-
48
- ctx.fillRect(x, 0, colWidth, height)
34
+ ctx.fillRect((mouseCol2 - 1) * colWidth + scrollX, 0, colWidth, height)
49
35
  }
50
36
  }
@@ -1,10 +1,7 @@
1
1
  import React, { Suspense } from 'react'
2
-
3
2
  import { observer } from 'mobx-react'
4
- import { Typography } from '@mui/material'
5
3
 
6
4
  // locals
7
- import ImportForm from './ImportForm'
8
5
  import TreeRuler from './TreePanel/TreeRuler'
9
6
  import Header from './Header'
10
7
  import Track from './Track'
@@ -14,43 +11,44 @@ import MSAPanel from './MSAPanel'
14
11
  import TreePanel from './TreePanel'
15
12
  import Minimap from './Minimap'
16
13
 
17
- const MSAView = observer(function ({ model }: { model: MsaViewModel }) {
18
- const { done, initialized } = model
14
+ function TopArea({ model }: { model: MsaViewModel }) {
15
+ return (
16
+ <div style={{ display: 'flex' }}>
17
+ <TreeRuler model={model} />
18
+ <Minimap model={model} />
19
+ </div>
20
+ )
21
+ }
22
+ function MainArea({ model }: { model: MsaViewModel }) {
23
+ return (
24
+ <div style={{ display: 'flex' }}>
25
+ <TreePanel model={model} />
26
+ <VerticalResizeHandle model={model} />
27
+ <MSAPanel model={model} />
28
+ </div>
29
+ )
30
+ }
19
31
 
32
+ const View = observer(function ({ model }: { model: MsaViewModel }) {
33
+ const { turnedOnTracks } = model
20
34
  return (
21
- <div>
22
- {!initialized ? (
23
- <ImportForm model={model} />
24
- ) : !done ? (
25
- <Typography variant="h4">Loading...</Typography>
26
- ) : (
27
- <MSAView2 model={model} />
28
- )}
35
+ <div style={{ paddingLeft: 20, position: 'relative' }}>
36
+ <TopArea model={model} />
37
+ {turnedOnTracks?.map(track => (
38
+ <Track key={track.model.id} model={model} track={track} />
39
+ ))}
40
+ <MainArea model={model} />
29
41
  </div>
30
42
  )
31
43
  })
32
44
 
33
- const MSAView2 = observer(function ({ model }: { model: MsaViewModel }) {
34
- const { height, turnedOnTracks, DialogComponent, DialogProps } = model
45
+ const MSAView = observer(function ({ model }: { model: MsaViewModel }) {
46
+ const { height, DialogComponent, DialogProps } = model
35
47
  return (
36
48
  <div>
37
49
  <div style={{ height, overflow: 'hidden' }}>
38
50
  <Header model={model} />
39
- <div style={{ position: 'relative' }}>
40
- <div style={{ display: 'flex' }}>
41
- <TreeRuler model={model} />
42
- <Minimap model={model} />
43
- </div>
44
- {turnedOnTracks?.map(track => (
45
- <Track key={track.model.id} model={model} track={track} />
46
- ))}
47
-
48
- <div style={{ display: 'flex' }}>
49
- <TreePanel model={model} />
50
- <VerticalResizeHandle model={model} />
51
- <MSAPanel model={model} />
52
- </div>
53
- </div>
51
+ <View model={model} />
54
52
  </div>
55
53
  <HorizontalResizeHandle model={model} />
56
54
 
@@ -42,8 +42,7 @@ const TreeCanvasBlock = observer(function ({
42
42
  const [toggleNodeMenu, setToggleNodeMenu] = useState<TooltipData>()
43
43
  const [hoverElt, setHoverElt] = useState<ClickEntry>()
44
44
 
45
- const { scrollY, treeAreaWidth, margin, blockSize, highResScaleFactor } =
46
- model
45
+ const { scrollY, treeAreaWidth, blockSize, highResScaleFactor } = model
47
46
 
48
47
  const width = treeAreaWidth + padding
49
48
  const height = blockSize
@@ -83,7 +82,7 @@ const TreeCanvasBlock = observer(function ({
83
82
 
84
83
  ctx.resetTransform()
85
84
  ctx.clearRect(0, 0, treeAreaWidth + padding, blockSize)
86
- ctx.translate(margin.left, -offsetY)
85
+ ctx.translate(0, -offsetY)
87
86
 
88
87
  if (hoverElt) {
89
88
  const { minX, maxX, minY, maxY } = hoverElt
@@ -91,10 +90,10 @@ const TreeCanvasBlock = observer(function ({
91
90
  ctx.fillStyle = 'rgba(0,0,0,0.1)'
92
91
  ctx.fillRect(minX, minY, maxX - minX, maxY - minY)
93
92
  }
94
- }, [hoverElt, margin.left, offsetY, blockSize, treeAreaWidth])
93
+ }, [hoverElt, offsetY, blockSize, treeAreaWidth])
95
94
 
96
95
  function hoverBranchClickMap(event: React.MouseEvent) {
97
- const x = event.nativeEvent.offsetX - margin.left
96
+ const x = event.nativeEvent.offsetX
98
97
  const y = event.nativeEvent.offsetY
99
98
 
100
99
  const [entry] = clickMap.current.search({
@@ -110,7 +109,7 @@ const TreeCanvasBlock = observer(function ({
110
109
  }
111
110
 
112
111
  function hoverNameClickMap(event: React.MouseEvent) {
113
- const x = event.nativeEvent.offsetX - margin.left
112
+ const x = event.nativeEvent.offsetX
114
113
  const y = event.nativeEvent.offsetY
115
114
  const [entry] = clickMap.current.search({
116
115
  minX: x,
@@ -133,7 +133,6 @@ export function renderTreeLabels({
133
133
  drawTree,
134
134
  structures,
135
135
  treeAreaWidth,
136
- margin,
137
136
  noTree,
138
137
  } = model
139
138
  const by = blockSizeYOverride || blockSize
@@ -179,7 +178,7 @@ export function renderTreeLabels({
179
178
  })
180
179
  } else if (labelsAlignRight) {
181
180
  const smallPadding = 2
182
- const offset = treeAreaWidth - smallPadding - margin.left
181
+ const offset = treeAreaWidth - smallPadding
183
182
  if (drawTree && !noTree) {
184
183
  const { width } = ctx.measureText(displayName)
185
184
  ctx.moveTo(xp + radius + 2, y)
@@ -188,8 +187,8 @@ export function renderTreeLabels({
188
187
  }
189
188
  ctx.fillText(displayName, offset, yp)
190
189
  clickMap?.insert({
191
- minX: treeAreaWidth - margin.left - width,
192
- maxX: treeAreaWidth - margin.left,
190
+ minX: treeAreaWidth - width,
191
+ maxX: treeAreaWidth,
193
192
  minY: yp - height,
194
193
  maxY: yp,
195
194
  name,
@@ -235,7 +234,6 @@ export function renderTreeCanvas({
235
234
  drawNodeBubbles,
236
235
  treeWidth,
237
236
  highResScaleFactor,
238
- margin,
239
237
  blockSize,
240
238
  fontSize,
241
239
  rowHeight,
@@ -254,7 +252,7 @@ export function renderTreeCanvas({
254
252
  nref < 0 ? -Infinity : highResScaleFactorOverride || highResScaleFactor
255
253
  ctx.scale(k, k)
256
254
  ctx.clearRect(0, 0, treeWidth + padding, by)
257
- ctx.translate(margin.left, -offsetY)
255
+ ctx.translate(0, -offsetY)
258
256
 
259
257
  const font = ctx.font
260
258
  ctx.font = font.replace(/\d+px/, `${fontSize}px`)
package/src/index.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { default as MSAView } from './components/MSAView'
1
+ export { default as MSAView } from './components/Loading'
2
2
  export { default as MSAModel, type MsaViewModel } from './model'
@@ -0,0 +1,14 @@
1
+ let canvasHandle: HTMLCanvasElement | undefined
2
+
3
+ export default function measureTextCanvas(text: string, fontSize: number) {
4
+ if (!canvasHandle) {
5
+ canvasHandle = document.createElement('canvas')
6
+ }
7
+
8
+ const ctx = canvasHandle.getContext('2d')
9
+ if (!ctx) {
10
+ throw new Error('no canvas context')
11
+ }
12
+ ctx.font = ctx.font.replace(/\d+px/, `${fontSize}px`)
13
+ return ctx.measureText(text).width
14
+ }
package/src/model.ts CHANGED
@@ -9,7 +9,7 @@ import { saveAs } from 'file-saver'
9
9
  import { FileLocation, ElementId } from '@jbrowse/core/util/types/mst'
10
10
  import { FileLocation as FileLocationType } from '@jbrowse/core/util/types'
11
11
  import { openLocation } from '@jbrowse/core/util/io'
12
- import { measureText, notEmpty, sum } from '@jbrowse/core/util'
12
+ import { notEmpty, sum } from '@jbrowse/core/util'
13
13
  import BaseViewModel from '@jbrowse/core/pluggableElementTypes/models/BaseViewModel'
14
14
 
15
15
  // locals
@@ -37,6 +37,7 @@ import { DialogQueueSessionMixin } from './DialogQueue'
37
37
  import { renderToSvg } from './renderToSvg'
38
38
  import { Theme } from '@mui/material'
39
39
  import { blocksX, blocksY } from './calculateBlocks'
40
+ import measureTextCanvas from './measureTextCanvas'
40
41
 
41
42
  export interface RowDetails {
42
43
  [key: string]: unknown
@@ -337,14 +338,6 @@ const model = types
337
338
  */
338
339
  error: undefined as unknown,
339
340
 
340
- /**
341
- * #volatile
342
- */
343
- margin: {
344
- left: 20,
345
- top: 20,
346
- },
347
-
348
341
  /**
349
342
  * #volatile
350
343
  */
@@ -1009,7 +1002,7 @@ const model = types
1009
1002
  if (rowHeight > 5) {
1010
1003
  for (const node of hierarchy.leaves()) {
1011
1004
  x = Math.max(
1012
- measureText(
1005
+ measureTextCanvas(
1013
1006
  treeMetadata[node.data.name]?.genome || node.data.name,
1014
1007
  fontSize,
1015
1008
  ),
@@ -1293,7 +1286,7 @@ const model = types
1293
1286
  autorun(async () => {
1294
1287
  if (self.treeWidthMatchesArea) {
1295
1288
  self.setTreeWidth(
1296
- Math.max(50, self.treeAreaWidth - self.labelsWidth - 20),
1289
+ Math.max(50, self.treeAreaWidth - self.labelsWidth - 10),
1297
1290
  )
1298
1291
  }
1299
1292
  }),
@@ -141,6 +141,7 @@ function CoreRendering({
141
141
  })
142
142
  renderMSABlock({
143
143
  model,
144
+ theme,
144
145
  offsetY,
145
146
  offsetX,
146
147
  contrastScheme,
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '3.1.3'
1
+ export const version = '3.1.4'