react-msaview 3.0.2 → 3.1.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.
- package/bundle/index.js +46 -32
- package/dist/components/MSAPanel/MSABlock.js +1 -0
- package/dist/components/MSAPanel/MSABlock.js.map +1 -1
- package/dist/components/MSAPanel/renderMSABlock.d.ts +4 -1
- package/dist/components/MSAPanel/renderMSABlock.js +8 -6
- package/dist/components/MSAPanel/renderMSABlock.js.map +1 -1
- package/dist/components/MSAPanel/renderMSAMouseover.js +0 -1
- package/dist/components/MSAPanel/renderMSAMouseover.js.map +1 -1
- package/dist/components/TreePanel/TreeCanvasBlock.js +0 -1
- package/dist/components/TreePanel/TreeCanvasBlock.js.map +1 -1
- package/dist/components/TreePanel/renderTreeCanvas.d.ts +13 -8
- package/dist/components/TreePanel/renderTreeCanvas.js +43 -17
- package/dist/components/TreePanel/renderTreeCanvas.js.map +1 -1
- package/dist/components/ZoomControls.js +12 -13
- package/dist/components/ZoomControls.js.map +1 -1
- package/dist/model.d.ts +28 -33
- package/dist/model.js +11 -0
- package/dist/model.js.map +1 -1
- package/dist/renderToSvg.d.ts +5 -0
- package/dist/renderToSvg.js +49 -0
- package/dist/renderToSvg.js.map +1 -0
- package/dist/util.js +2 -0
- package/dist/util.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +4 -1
- package/src/components/MSAPanel/MSABlock.tsx +1 -0
- package/src/components/MSAPanel/renderMSABlock.ts +13 -5
- package/src/components/MSAPanel/renderMSAMouseover.ts +0 -1
- package/src/components/TreePanel/TreeCanvasBlock.tsx +0 -1
- package/src/components/TreePanel/renderTreeCanvas.ts +53 -17
- package/src/components/ZoomControls.tsx +12 -13
- package/src/declare.d.ts +1 -0
- package/src/model.ts +12 -0
- package/src/renderToSvg.tsx +71 -0
- package/src/util.ts +3 -0
- package/src/version.ts +1 -1
package/src/model.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { Instance, cast, types, addDisposer, SnapshotIn } from 'mobx-state-tree'
|
|
|
4
4
|
import { hierarchy, cluster, HierarchyNode } from 'd3-hierarchy'
|
|
5
5
|
import { ascending } from 'd3-array'
|
|
6
6
|
import Stockholm from 'stockholm-js'
|
|
7
|
+
import { saveAs } from 'file-saver'
|
|
7
8
|
// jbrowse
|
|
8
9
|
import { FileLocation, ElementId } from '@jbrowse/core/util/types/mst'
|
|
9
10
|
import { FileLocation as FileLocationType } from '@jbrowse/core/util/types'
|
|
@@ -33,6 +34,8 @@ import colorSchemes from './colorSchemes'
|
|
|
33
34
|
import { UniprotTrack } from './UniprotTrack'
|
|
34
35
|
import { StructureModel } from './StructureModel'
|
|
35
36
|
import { DialogQueueSessionMixin } from './DialogQueue'
|
|
37
|
+
import { renderToSvg } from './renderToSvg'
|
|
38
|
+
import { Theme } from '@mui/material'
|
|
36
39
|
|
|
37
40
|
export interface RowDetails {
|
|
38
41
|
[key: string]: unknown
|
|
@@ -970,6 +973,7 @@ const model = types
|
|
|
970
973
|
* #action
|
|
971
974
|
*/
|
|
972
975
|
setScrollX(n: number) {
|
|
976
|
+
console.log({ n })
|
|
973
977
|
self.scrollX = clamp(
|
|
974
978
|
-(self.numColumns * self.colWidth) + (self.msaAreaWidth - 100),
|
|
975
979
|
n,
|
|
@@ -1227,6 +1231,14 @@ const model = types
|
|
|
1227
1231
|
},
|
|
1228
1232
|
}))
|
|
1229
1233
|
.actions(self => ({
|
|
1234
|
+
/**
|
|
1235
|
+
* #action
|
|
1236
|
+
*/
|
|
1237
|
+
async exportSVG(opts: { theme: Theme }) {
|
|
1238
|
+
const html = await renderToSvg(self as MsaViewModel, opts)
|
|
1239
|
+
const blob = new Blob([html], { type: 'image/svg+xml' })
|
|
1240
|
+
saveAs(blob, 'image.svg')
|
|
1241
|
+
},
|
|
1230
1242
|
/**
|
|
1231
1243
|
* #action
|
|
1232
1244
|
* internal, used for drawing to canvas
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { createRoot } from 'react-dom/client'
|
|
3
|
+
import { when } from 'mobx'
|
|
4
|
+
import { renderToStaticMarkup } from '@jbrowse/core/util'
|
|
5
|
+
import { Theme } from '@mui/material'
|
|
6
|
+
|
|
7
|
+
// locals
|
|
8
|
+
import { MsaViewModel } from './model'
|
|
9
|
+
import { renderTreeCanvas } from './components/TreePanel/renderTreeCanvas'
|
|
10
|
+
import { renderBlock } from './components/MSAPanel/renderMSABlock'
|
|
11
|
+
import { colorContrast } from './util'
|
|
12
|
+
|
|
13
|
+
// render LGV to SVG
|
|
14
|
+
export async function renderToSvg(model: MsaViewModel, opts: { theme: Theme }) {
|
|
15
|
+
await when(() => !!model.initialized)
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
17
|
+
const { width, height, scrollX, scrollY, colorScheme, treeAreaWidth } = model
|
|
18
|
+
const { theme } = opts
|
|
19
|
+
|
|
20
|
+
const { Context } = await import('svgcanvas')
|
|
21
|
+
const ctx1 = Context(width, height)
|
|
22
|
+
const ctx2 = Context(width, height)
|
|
23
|
+
const contrastScheme = colorContrast(colorScheme, theme)
|
|
24
|
+
renderTreeCanvas({
|
|
25
|
+
model,
|
|
26
|
+
offsetY: scrollY,
|
|
27
|
+
ctx: ctx1,
|
|
28
|
+
theme,
|
|
29
|
+
blockSizeYOverride: height,
|
|
30
|
+
highResScaleFactorOverride: 1,
|
|
31
|
+
})
|
|
32
|
+
renderBlock({
|
|
33
|
+
model,
|
|
34
|
+
offsetY: scrollY,
|
|
35
|
+
offsetX: -scrollX,
|
|
36
|
+
contrastScheme,
|
|
37
|
+
ctx: ctx2,
|
|
38
|
+
blockSizeXOverride: width - treeAreaWidth,
|
|
39
|
+
blockSizeYOverride: height,
|
|
40
|
+
highResScaleFactorOverride: 1,
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
const clipId = 'tree'
|
|
44
|
+
// the xlink namespace is used for rendering <image> tag
|
|
45
|
+
return renderToStaticMarkup(
|
|
46
|
+
<svg
|
|
47
|
+
width={width}
|
|
48
|
+
height={height}
|
|
49
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
50
|
+
xmlnsXlink="http://www.w3.org/1999/xlink"
|
|
51
|
+
viewBox={[0, 0, width, height].toString()}
|
|
52
|
+
>
|
|
53
|
+
<defs>
|
|
54
|
+
<clipPath id={clipId}>
|
|
55
|
+
<rect x={0} y={0} width={treeAreaWidth} height={height} />
|
|
56
|
+
</clipPath>
|
|
57
|
+
</defs>
|
|
58
|
+
<g
|
|
59
|
+
clipPath={`url(#${clipId})`}
|
|
60
|
+
/* eslint-disable-next-line react/no-danger */
|
|
61
|
+
dangerouslySetInnerHTML={{ __html: ctx1.getSvg().innerHTML }}
|
|
62
|
+
/>
|
|
63
|
+
<g
|
|
64
|
+
transform={`translate(${treeAreaWidth} 0)`}
|
|
65
|
+
/* eslint-disable-next-line react/no-danger */
|
|
66
|
+
dangerouslySetInnerHTML={{ __html: ctx2.getSvg().innerHTML }}
|
|
67
|
+
/>
|
|
68
|
+
</svg>,
|
|
69
|
+
createRoot,
|
|
70
|
+
)
|
|
71
|
+
}
|
package/src/util.ts
CHANGED
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '3.0
|
|
1
|
+
export const version = '3.1.0'
|