react-msaview 8.4.1 → 9.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.
- package/bundle/index.js +66 -66
- package/bundle/index.js.map +4 -4
- package/dist/components/MSAView.js +2 -2
- package/dist/components/MSAView.js.map +1 -1
- package/dist/components/MSAViewer.d.ts +1 -3
- package/dist/components/MSAViewer.js +1 -2
- package/dist/components/MSAViewer.js.map +1 -1
- package/dist/components/ResizeHandles.js +1 -1
- package/dist/components/ResizeHandles.js.map +1 -1
- package/dist/components/Track.js +1 -1
- package/dist/components/Track.js.map +1 -1
- package/dist/components/dialogs/ExportSVGDialog.js +2 -2
- package/dist/components/dialogs/ExportSVGDialog.js.map +1 -1
- package/dist/components/header/settingsMenuItems.js +4 -1
- package/dist/components/header/settingsMenuItems.js.map +1 -1
- package/dist/components/tree/CladeLabels.js +3 -3
- package/dist/components/tree/CladeLabels.js.map +1 -1
- package/dist/components/tree/TreeCanvas.js +4 -4
- package/dist/components/tree/TreeCanvas.js.map +1 -1
- package/dist/components/tree/TreeCanvasBlock.js +4 -4
- package/dist/components/tree/TreeCanvasBlock.js.map +1 -1
- package/dist/components/tree/TreeOverview.js +10 -5
- package/dist/components/tree/TreeOverview.js.map +1 -1
- package/dist/components/tree/TreePanel.js +6 -2
- package/dist/components/tree/TreePanel.js.map +1 -1
- package/dist/components/tree/TreeRuler.js +2 -2
- package/dist/components/tree/TreeRuler.js.map +1 -1
- package/dist/components/tree/cladeBrackets.d.ts +8 -10
- package/dist/components/tree/cladeBrackets.js +7 -6
- package/dist/components/tree/cladeBrackets.js.map +1 -1
- package/dist/components/tree/clickMap.d.ts +2 -0
- package/dist/components/tree/clickMap.js.map +1 -1
- package/dist/components/tree/ellipsize.d.ts +8 -0
- package/dist/components/tree/ellipsize.js +20 -0
- package/dist/components/tree/ellipsize.js.map +1 -0
- package/dist/components/tree/renderTreeCanvas.js +30 -26
- package/dist/components/tree/renderTreeCanvas.js.map +1 -1
- package/dist/components/tree/renderTreeMouseover.js +1 -1
- package/dist/components/tree/renderTreeMouseover.js.map +1 -1
- package/dist/constants.d.ts +6 -3
- package/dist/constants.js +16 -6
- package/dist/constants.js.map +1 -1
- package/dist/measureTextCanvas.js +2 -2
- package/dist/measureTextCanvas.js.map +1 -1
- package/dist/model/treeModel.d.ts +14 -20
- package/dist/model/treeModel.js +16 -23
- package/dist/model/treeModel.js.map +1 -1
- package/dist/model.d.ts +72 -37
- package/dist/model.js +108 -100
- package/dist/model.js.map +1 -1
- package/dist/renderToSvg.js +24 -22
- package/dist/renderToSvg.js.map +1 -1
- package/dist/svgTestUtil.d.ts +36 -28
- package/dist/tipLabels.d.ts +8 -0
- package/dist/tipLabels.js +46 -0
- package/dist/tipLabels.js.map +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +3 -3
- package/src/components/MSAView.tsx +2 -2
- package/src/components/MSAViewer.tsx +1 -5
- package/src/components/ResizeHandles.tsx +1 -1
- package/src/components/Track.tsx +1 -1
- package/src/components/dialogs/ExportSVGDialog.tsx +2 -2
- package/src/components/header/settingsMenuItems.ts +8 -0
- package/src/components/tree/CladeLabels.tsx +3 -3
- package/src/components/tree/TreeCanvas.tsx +10 -4
- package/src/components/tree/TreeCanvasBlock.tsx +4 -4
- package/src/components/tree/TreeOverview.tsx +10 -5
- package/src/components/tree/TreePanel.tsx +8 -2
- package/src/components/tree/TreeRuler.tsx +7 -3
- package/src/components/tree/cladeBrackets.ts +10 -17
- package/src/components/tree/clickMap.ts +2 -0
- package/src/components/tree/ellipsize.ts +24 -0
- package/src/components/tree/renderTreeCanvas.ts +42 -30
- package/src/components/tree/renderTreeMouseover.ts +1 -1
- package/src/constants.ts +17 -6
- package/src/measureTextCanvas.ts +2 -2
- package/src/model/treeModel.ts +17 -27
- package/src/model.ts +129 -124
- package/src/renderToSvg.tsx +24 -22
- package/src/tipLabels.ts +51 -0
- package/src/version.ts +1 -1
|
@@ -24,14 +24,14 @@ const CladeLabels = observer(function ({ model }: { model: MsaViewModel }) {
|
|
|
24
24
|
resolvedClades,
|
|
25
25
|
cladeGutterWidth,
|
|
26
26
|
rowHeight,
|
|
27
|
-
|
|
27
|
+
effectiveTreeAreaWidth,
|
|
28
28
|
fontSize,
|
|
29
29
|
} = model
|
|
30
30
|
const theme = useTheme()
|
|
31
31
|
if (cladeGutterWidth === 0) {
|
|
32
32
|
return null
|
|
33
33
|
}
|
|
34
|
-
const gutterLeft =
|
|
34
|
+
const gutterLeft = effectiveTreeAreaWidth - cladeGutterWidth
|
|
35
35
|
return (
|
|
36
36
|
<>
|
|
37
37
|
{resolvedClades.map((clade, index) => {
|
|
@@ -49,7 +49,7 @@ const CladeLabels = observer(function ({ model }: { model: MsaViewModel }) {
|
|
|
49
49
|
position: 'absolute',
|
|
50
50
|
left,
|
|
51
51
|
top: rows[0] * rowHeight,
|
|
52
|
-
width:
|
|
52
|
+
width: effectiveTreeAreaWidth - left - bracketGap,
|
|
53
53
|
height: cladeHeight(clade, rowHeight),
|
|
54
54
|
display: 'flex',
|
|
55
55
|
alignItems: 'center',
|
|
@@ -13,7 +13,13 @@ import type { MsaViewModel } from '../../model.ts'
|
|
|
13
13
|
|
|
14
14
|
const TreeCanvas = observer(function ({ model }: { model: MsaViewModel }) {
|
|
15
15
|
const ref = useRef<HTMLDivElement>(null)
|
|
16
|
-
const {
|
|
16
|
+
const {
|
|
17
|
+
height,
|
|
18
|
+
blocksY,
|
|
19
|
+
effectiveTreeAreaWidth,
|
|
20
|
+
scrollY,
|
|
21
|
+
highResScaleFactor,
|
|
22
|
+
} = model
|
|
17
23
|
const onScrollY = useCallback(
|
|
18
24
|
(d: number) => {
|
|
19
25
|
model.doScrollY(d)
|
|
@@ -22,7 +28,7 @@ const TreeCanvas = observer(function ({ model }: { model: MsaViewModel }) {
|
|
|
22
28
|
)
|
|
23
29
|
const { onMouseDown, onMouseUp } = useWheelScroll({ ref, onScrollY })
|
|
24
30
|
|
|
25
|
-
const canvasWidth =
|
|
31
|
+
const canvasWidth = effectiveTreeAreaWidth * highResScaleFactor
|
|
26
32
|
const canvasHeight = height * highResScaleFactor
|
|
27
33
|
const mouseoverRef = useCanvasAutorun({
|
|
28
34
|
draw: ctx => {
|
|
@@ -43,7 +49,7 @@ const TreeCanvas = observer(function ({ model }: { model: MsaViewModel }) {
|
|
|
43
49
|
style={{
|
|
44
50
|
height,
|
|
45
51
|
position: 'relative',
|
|
46
|
-
width:
|
|
52
|
+
width: effectiveTreeAreaWidth,
|
|
47
53
|
}}
|
|
48
54
|
>
|
|
49
55
|
{/* one transform for the whole block set, matching MSACanvas: the tree
|
|
@@ -70,7 +76,7 @@ const TreeCanvas = observer(function ({ model }: { model: MsaViewModel }) {
|
|
|
70
76
|
position: 'absolute',
|
|
71
77
|
top: 0,
|
|
72
78
|
left: 0,
|
|
73
|
-
width:
|
|
79
|
+
width: effectiveTreeAreaWidth,
|
|
74
80
|
height,
|
|
75
81
|
zIndex: 1000,
|
|
76
82
|
pointerEvents: 'none',
|
|
@@ -37,9 +37,9 @@ const TreeCanvasBlock = observer(function ({
|
|
|
37
37
|
)
|
|
38
38
|
const hovered = anchor?.value
|
|
39
39
|
|
|
40
|
-
const {
|
|
41
|
-
// TreePanel clips to
|
|
42
|
-
const width =
|
|
40
|
+
const { effectiveTreeAreaWidth, blockSize, highResScaleFactor } = model
|
|
41
|
+
// TreePanel clips to the tree area, so a wider canvas is wasted backing store
|
|
42
|
+
const width = effectiveTreeAreaWidth
|
|
43
43
|
const height = blockSize
|
|
44
44
|
|
|
45
45
|
const canvasWidth = width * highResScaleFactor
|
|
@@ -121,7 +121,7 @@ const TreeCanvasBlock = observer(function ({
|
|
|
121
121
|
|
|
122
122
|
{anchor ? (
|
|
123
123
|
<BaseTooltip clientPoint={anchor.clientPoint}>
|
|
124
|
-
{anchor.value.name}
|
|
124
|
+
{anchor.value.label ?? anchor.value.name}
|
|
125
125
|
</BaseTooltip>
|
|
126
126
|
) : null}
|
|
127
127
|
</>
|
|
@@ -21,10 +21,10 @@ import type { MsaViewModel } from '../../model.ts'
|
|
|
21
21
|
* moving across it costs are a blit and two boxes.
|
|
22
22
|
*/
|
|
23
23
|
const TreeOverview = observer(function ({ model }: { model: MsaViewModel }) {
|
|
24
|
-
const {
|
|
24
|
+
const { effectiveTreeAreaWidth, overviewHeight, highResScaleFactor } = model
|
|
25
25
|
const theme = useTheme()
|
|
26
26
|
const [hover, setHover] = useState<{ id: string; rows: [number, number] }>()
|
|
27
|
-
const width = Math.round(
|
|
27
|
+
const width = Math.round(effectiveTreeAreaWidth * highResScaleFactor)
|
|
28
28
|
const height = Math.round(overviewHeight * highResScaleFactor)
|
|
29
29
|
|
|
30
30
|
const ref = useCanvasAutorun({
|
|
@@ -34,12 +34,17 @@ const TreeOverview = observer(function ({ model }: { model: MsaViewModel }) {
|
|
|
34
34
|
const image = treeOverviewImage({
|
|
35
35
|
model,
|
|
36
36
|
theme,
|
|
37
|
-
width:
|
|
37
|
+
width: effectiveTreeAreaWidth,
|
|
38
38
|
height: overviewHeight,
|
|
39
39
|
scale: highResScaleFactor,
|
|
40
40
|
})
|
|
41
41
|
ctx.scale(highResScaleFactor, highResScaleFactor)
|
|
42
|
-
const box = {
|
|
42
|
+
const box = {
|
|
43
|
+
model,
|
|
44
|
+
ctx,
|
|
45
|
+
width: effectiveTreeAreaWidth,
|
|
46
|
+
height: overviewHeight,
|
|
47
|
+
}
|
|
43
48
|
if (image) {
|
|
44
49
|
ctx.drawImage(
|
|
45
50
|
image,
|
|
@@ -86,7 +91,7 @@ const TreeOverview = observer(function ({ model }: { model: MsaViewModel }) {
|
|
|
86
91
|
display: 'block',
|
|
87
92
|
flexShrink: 0,
|
|
88
93
|
cursor: 'pointer',
|
|
89
|
-
width:
|
|
94
|
+
width: effectiveTreeAreaWidth,
|
|
90
95
|
height: overviewHeight,
|
|
91
96
|
}}
|
|
92
97
|
onMouseMove={event => {
|
|
@@ -7,9 +7,15 @@ import TreeCanvas from './TreeCanvas.tsx'
|
|
|
7
7
|
import type { MsaViewModel } from '../../model.ts'
|
|
8
8
|
|
|
9
9
|
const TreePanel = observer(function ({ model }: { model: MsaViewModel }) {
|
|
10
|
-
const {
|
|
10
|
+
const { effectiveTreeAreaWidth } = model
|
|
11
11
|
return (
|
|
12
|
-
<div
|
|
12
|
+
<div
|
|
13
|
+
style={{
|
|
14
|
+
overflow: 'hidden',
|
|
15
|
+
flexShrink: 0,
|
|
16
|
+
width: effectiveTreeAreaWidth,
|
|
17
|
+
}}
|
|
18
|
+
>
|
|
13
19
|
<TreeCanvas model={model} />
|
|
14
20
|
</div>
|
|
15
21
|
)
|
|
@@ -13,13 +13,17 @@ import type { MsaViewModel } from '../../model.ts'
|
|
|
13
13
|
// scale bar: without one the branch lengths are drawn to a scale nothing
|
|
14
14
|
// states.
|
|
15
15
|
const TreeRuler = observer(({ model }: { model: MsaViewModel }) => {
|
|
16
|
-
const {
|
|
16
|
+
const { effectiveTreeAreaWidth, marginLeft, treeScaleBar: bar } = model
|
|
17
17
|
const theme = useTheme()
|
|
18
18
|
|
|
19
19
|
return (
|
|
20
|
-
<div style={{ flexShrink: 0, width:
|
|
20
|
+
<div style={{ flexShrink: 0, width: effectiveTreeAreaWidth }}>
|
|
21
21
|
{bar ? (
|
|
22
|
-
<svg
|
|
22
|
+
<svg
|
|
23
|
+
width={effectiveTreeAreaWidth}
|
|
24
|
+
height={h}
|
|
25
|
+
style={{ display: 'block' }}
|
|
26
|
+
>
|
|
23
27
|
<ScaleBarSVG
|
|
24
28
|
bar={bar}
|
|
25
29
|
marginLeft={marginLeft}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { labelFitFontSize } from '../../constants.ts'
|
|
1
2
|
import { measureTextCanvas } from '../../measureTextCanvas.ts'
|
|
2
3
|
|
|
3
|
-
import type { ResolvedClade } from '../../types.ts'
|
|
4
|
+
import type { Clade, ResolvedClade } from '../../types.ts'
|
|
4
5
|
|
|
5
6
|
// The bar of the bracket mark and the space around it, in px.
|
|
6
7
|
export const bracketBarWidth = 3
|
|
@@ -11,7 +12,7 @@ export const bracketGap = 4
|
|
|
11
12
|
export const maxCladeGutterWidth = 140
|
|
12
13
|
|
|
13
14
|
/** whether a clade draws in the gutter: a bracket, or a highlight with a label */
|
|
14
|
-
export function cladeInGutter(clade:
|
|
15
|
+
export function cladeInGutter(clade: Pick<Clade, 'mark' | 'label'>) {
|
|
15
16
|
return (
|
|
16
17
|
clade.mark === 'bracket' || (clade.mark === 'highlight' && !!clade.label)
|
|
17
18
|
)
|
|
@@ -35,7 +36,7 @@ export function cladeLabelHorizontal(
|
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
/** the px between the left edge of the gutter and the label's own column */
|
|
38
|
-
export function cladeLabelOffset(clade:
|
|
39
|
+
export function cladeLabelOffset(clade: Pick<Clade, 'mark'>) {
|
|
39
40
|
return clade.mark === 'bracket'
|
|
40
41
|
? bracketGap + bracketBarWidth + bracketGap
|
|
41
42
|
: bracketGap
|
|
@@ -43,27 +44,19 @@ export function cladeLabelOffset(clade: ResolvedClade) {
|
|
|
43
44
|
|
|
44
45
|
/**
|
|
45
46
|
* The gutter the bracket mark needs at the right of the tree area: the bar plus
|
|
46
|
-
* the widest label
|
|
47
|
-
* most maxCladeGutterWidth.
|
|
47
|
+
* the widest label read across at labelFitFontSize, zero where no clade draws
|
|
48
|
+
* there, and at most maxCladeGutterWidth. The records size it, so a zoom, a
|
|
49
|
+
* collapse or a focus leaves it as it is, and a renderer clips a label that
|
|
50
|
+
* outgrows it.
|
|
48
51
|
*/
|
|
49
|
-
export function cladeGutterWidth({
|
|
50
|
-
clades,
|
|
51
|
-
rowHeight,
|
|
52
|
-
fontSize,
|
|
53
|
-
}: {
|
|
54
|
-
clades: ResolvedClade[]
|
|
55
|
-
rowHeight: number
|
|
56
|
-
fontSize: number
|
|
57
|
-
}) {
|
|
52
|
+
export function cladeGutterWidth(clades: Pick<Clade, 'mark' | 'label'>[]) {
|
|
58
53
|
let widest = 0
|
|
59
54
|
for (const clade of clades) {
|
|
60
55
|
if (!cladeInGutter(clade)) {
|
|
61
56
|
continue
|
|
62
57
|
}
|
|
63
58
|
const text = clade.label
|
|
64
|
-
?
|
|
65
|
-
? measureTextCanvas(clade.label, fontSize)
|
|
66
|
-
: fontSize
|
|
59
|
+
? measureTextCanvas(clade.label, labelFitFontSize)
|
|
67
60
|
: 0
|
|
68
61
|
widest = Math.max(widest, cladeLabelOffset(clade) + text + bracketGap)
|
|
69
62
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const ellipsis = '…'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* the longest prefix of `text`, plus an ellipsis, that measures at most
|
|
5
|
+
* `room` px
|
|
6
|
+
*/
|
|
7
|
+
export function ellipsize(
|
|
8
|
+
measure: (text: string) => number,
|
|
9
|
+
text: string,
|
|
10
|
+
room: number,
|
|
11
|
+
) {
|
|
12
|
+
const width = measure(text)
|
|
13
|
+
if (width <= room) {
|
|
14
|
+
return { text, width }
|
|
15
|
+
}
|
|
16
|
+
for (let n = Math.floor((text.length * room) / width); n > 0; n--) {
|
|
17
|
+
const truncated = text.slice(0, n).trimEnd() + ellipsis
|
|
18
|
+
const truncatedWidth = measure(truncated)
|
|
19
|
+
if (truncatedWidth <= room) {
|
|
20
|
+
return { text: truncated, width: truncatedWidth }
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return { text: '', width: 0 }
|
|
24
|
+
}
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
} from '../msa/renderHighlights.ts'
|
|
9
9
|
import { referenceColor } from '../overlayColors.ts'
|
|
10
10
|
import { bracketBarWidth, bracketGap } from './cladeBrackets.ts'
|
|
11
|
+
import { ellipsize } from './ellipsize.ts'
|
|
11
12
|
|
|
12
13
|
import type { HierarchyNode } from '../../hierarchy.ts'
|
|
13
14
|
import type { MsaViewModel } from '../../model.ts'
|
|
@@ -382,9 +383,8 @@ function renderTreeLabels({
|
|
|
382
383
|
treeAreaWidthMinusMargin,
|
|
383
384
|
marginLeft,
|
|
384
385
|
noTree,
|
|
385
|
-
labelWidthMap,
|
|
386
|
-
labelWidthScale,
|
|
387
386
|
} = model
|
|
387
|
+
const treeDrawn = drawTree && !noTree
|
|
388
388
|
const by = blockSizeYOverride ?? blockSize
|
|
389
389
|
// labels only exist for leaves, which are laid out top to bottom, so take the
|
|
390
390
|
// same slice the MSA renderer uses instead of walking every tip per block
|
|
@@ -412,22 +412,22 @@ function renderTreeLabels({
|
|
|
412
412
|
// fontSize/4 below the row center, the baseline the alignment letters
|
|
413
413
|
// share
|
|
414
414
|
const yp = y + fontSize / 4
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
const width
|
|
422
|
-
measured === undefined
|
|
423
|
-
? ctx.measureText(displayName).width
|
|
424
|
-
: measured * labelWidthScale
|
|
415
|
+
const xp = treeDrawn
|
|
416
|
+
? (getNodeX(node, showBranchLen, tipX, maxDepthToLeaf) ?? 0)
|
|
417
|
+
: 0
|
|
418
|
+
const fit = (room: number) =>
|
|
419
|
+
ellipsize(text => ctx.measureText(text).width, displayName, room)
|
|
420
|
+
// a label cut to nothing still gets a click box the font size wide
|
|
421
|
+
const boxWidth = (width: number) => Math.max(width, fontSize)
|
|
425
422
|
|
|
426
423
|
ctx.fillStyle = tipLabelColors?.get(name) ?? theme.palette.text.primary
|
|
427
424
|
if (labelsAlignRight) {
|
|
428
425
|
const smallPadding = 2
|
|
429
426
|
const offset = treeAreaWidthMinusMargin - smallPadding
|
|
430
|
-
|
|
427
|
+
const { text, width } = fit(
|
|
428
|
+
offset - (treeDrawn ? xp + radius + 2 + smallPadding : 0),
|
|
429
|
+
)
|
|
430
|
+
if (treeDrawn) {
|
|
431
431
|
// beginPath is load-bearing: without it every leader line re-strokes
|
|
432
432
|
// all the ones before it, which is quadratic in the label count
|
|
433
433
|
ctx.beginPath()
|
|
@@ -435,28 +435,31 @@ function renderTreeLabels({
|
|
|
435
435
|
ctx.lineTo(offset - smallPadding - width, y)
|
|
436
436
|
ctx.stroke()
|
|
437
437
|
}
|
|
438
|
-
ctx.fillText(
|
|
438
|
+
ctx.fillText(text, offset, yp)
|
|
439
439
|
// everything here is drawn under translate(marginLeft), so the click box
|
|
440
440
|
// has to be the text's own right edge in that same space -- taking
|
|
441
|
-
//
|
|
441
|
+
// the tree area width instead put the target smallPadding off the label
|
|
442
442
|
const labelRight = offset + marginLeft
|
|
443
443
|
clickMap?.insert({
|
|
444
|
-
minX: labelRight - width,
|
|
444
|
+
minX: labelRight - boxWidth(width),
|
|
445
445
|
maxX: labelRight,
|
|
446
446
|
minY: yp - emHeight,
|
|
447
447
|
maxY: yp,
|
|
448
448
|
name,
|
|
449
|
+
label: displayName,
|
|
449
450
|
id,
|
|
450
451
|
})
|
|
451
452
|
} else {
|
|
452
|
-
const labelX =
|
|
453
|
-
|
|
453
|
+
const labelX = treeDrawn ? xp + d : 2
|
|
454
|
+
const { text, width } = fit(treeAreaWidthMinusMargin - labelX)
|
|
455
|
+
ctx.fillText(text, labelX, yp)
|
|
454
456
|
clickMap?.insert({
|
|
455
457
|
minX: labelX + marginLeft,
|
|
456
|
-
maxX: labelX + width + marginLeft,
|
|
458
|
+
maxX: labelX + boxWidth(width) + marginLeft,
|
|
457
459
|
minY: yp - emHeight,
|
|
458
460
|
maxY: yp,
|
|
459
461
|
name,
|
|
462
|
+
label: displayName,
|
|
460
463
|
id,
|
|
461
464
|
})
|
|
462
465
|
}
|
|
@@ -502,12 +505,12 @@ function renderCladeHighlights({
|
|
|
502
505
|
hierarchy,
|
|
503
506
|
showBranchLenEffective: showBranchLen,
|
|
504
507
|
rowHeight,
|
|
505
|
-
|
|
508
|
+
effectiveTreeAreaWidth,
|
|
506
509
|
marginLeft,
|
|
507
510
|
blockSize,
|
|
508
511
|
} = model
|
|
509
512
|
const by = blockSizeYOverride ?? blockSize
|
|
510
|
-
const right =
|
|
513
|
+
const right = effectiveTreeAreaWidth - marginLeft
|
|
511
514
|
for (const { rows, color, mark } of resolvedClades) {
|
|
512
515
|
if (mark !== 'highlight') {
|
|
513
516
|
continue
|
|
@@ -548,7 +551,7 @@ function renderCladeBrackets({
|
|
|
548
551
|
resolvedClades,
|
|
549
552
|
cladeGutterWidth,
|
|
550
553
|
rowHeight,
|
|
551
|
-
|
|
554
|
+
effectiveTreeAreaWidth,
|
|
552
555
|
marginLeft,
|
|
553
556
|
blockSize,
|
|
554
557
|
} = model
|
|
@@ -557,7 +560,7 @@ function renderCladeBrackets({
|
|
|
557
560
|
}
|
|
558
561
|
const by = blockSizeYOverride ?? blockSize
|
|
559
562
|
const x =
|
|
560
|
-
|
|
563
|
+
effectiveTreeAreaWidth -
|
|
561
564
|
marginLeft -
|
|
562
565
|
cladeGutterWidth +
|
|
563
566
|
bracketGap +
|
|
@@ -600,7 +603,7 @@ function renderRowHighlights({
|
|
|
600
603
|
rowTints,
|
|
601
604
|
referenceRowIndex,
|
|
602
605
|
rowHeight,
|
|
603
|
-
|
|
606
|
+
effectiveTreeAreaWidth,
|
|
604
607
|
marginLeft,
|
|
605
608
|
blockSize,
|
|
606
609
|
} = model
|
|
@@ -608,7 +611,12 @@ function renderRowHighlights({
|
|
|
608
611
|
const pad = blockPad(model)
|
|
609
612
|
const placed: LabelBox[] = []
|
|
610
613
|
const fillRow = (index: number) => {
|
|
611
|
-
ctx.fillRect(
|
|
614
|
+
ctx.fillRect(
|
|
615
|
+
-marginLeft,
|
|
616
|
+
index * rowHeight,
|
|
617
|
+
effectiveTreeAreaWidth,
|
|
618
|
+
rowHeight,
|
|
619
|
+
)
|
|
612
620
|
}
|
|
613
621
|
if (rowTints) {
|
|
614
622
|
const top = Math.max(0, Math.floor((offsetY - pad) / rowHeight))
|
|
@@ -647,8 +655,8 @@ function renderRowHighlights({
|
|
|
647
655
|
label,
|
|
648
656
|
x: -marginLeft + 2,
|
|
649
657
|
y: first * rowHeight,
|
|
650
|
-
spanWidth:
|
|
651
|
-
bounds: { min: -marginLeft, max:
|
|
658
|
+
spanWidth: effectiveTreeAreaWidth,
|
|
659
|
+
bounds: { min: -marginLeft, max: effectiveTreeAreaWidth - marginLeft },
|
|
652
660
|
placed,
|
|
653
661
|
})
|
|
654
662
|
}
|
|
@@ -698,14 +706,18 @@ export function renderTreeCanvas({
|
|
|
698
706
|
|
|
699
707
|
// memoized on the model and shared across the tree/bubble/label passes (and
|
|
700
708
|
// across all tree blocks) rather than re-traversing the hierarchy in each
|
|
701
|
-
const {
|
|
702
|
-
|
|
709
|
+
const {
|
|
710
|
+
maxBranchLength,
|
|
711
|
+
maxDepthToLeaf,
|
|
712
|
+
showBranchLenEffective,
|
|
713
|
+
effectiveTreeWidth,
|
|
714
|
+
} = model
|
|
703
715
|
// pixel x of the tips. A phylogram scales branch lengths so the longest
|
|
704
716
|
// root-to-tip path lands at maxBranchLength; a cladogram ignores lengths and
|
|
705
717
|
// spreads topological depth across the whole tree area instead. Reusing
|
|
706
718
|
// maxBranchLength for the cladogram would pin every node to x=0 for a tree
|
|
707
719
|
// with no branch lengths -- which is exactly what forces cladogram mode.
|
|
708
|
-
const tipX = showBranchLenEffective ? maxBranchLength :
|
|
720
|
+
const tipX = showBranchLenEffective ? maxBranchLength : effectiveTreeWidth
|
|
709
721
|
// built once for all three passes: each of them asks about a different node on
|
|
710
722
|
// every block of every redraw, and `collapsed` is a list
|
|
711
723
|
const collapsedSet = new Set(model.collapsed)
|
package/src/constants.ts
CHANGED
|
@@ -55,9 +55,14 @@ export const minLetterColWidth = 5
|
|
|
55
55
|
// sub-row band or a features panel over small rows
|
|
56
56
|
export const minFeatureLabelHeight = 9
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
export function fontSizeFor(rowHeight: number) {
|
|
59
|
+
return Math.min(Math.max(6, rowHeight - 3), 18)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// The fitted tree area measures the tip labels and the clade labels at the
|
|
63
|
+
// font a default row draws, so a vertical zoom leaves the alignment in place.
|
|
64
|
+
// A larger font ellipsizes the labels.
|
|
65
|
+
export const labelFitFontSize = fontSizeFor(defaultRowHeight)
|
|
61
66
|
|
|
62
67
|
// Zoom limits, px per cell. maxCellSize caps both smooth zoom and the stepwise
|
|
63
68
|
// zoom-in buttons (which otherwise grow unbounded). minColWidth/minRowHeight are
|
|
@@ -74,8 +79,14 @@ export const defaultShowColumnStats = true
|
|
|
74
79
|
// Tree model defaults
|
|
75
80
|
export const defaultDrawLabels = true
|
|
76
81
|
export const defaultLabelsAlignRight = false
|
|
77
|
-
|
|
78
|
-
|
|
82
|
+
// The fitted tree area gives the tree pxPerTreeDepth per level of its depth,
|
|
83
|
+
// between minTreeWidth and maxFitTreeWidth, beside the widest label, and takes
|
|
84
|
+
// at most maxTreeAreaShare of a view with an alignment. Where the share binds,
|
|
85
|
+
// the tree keeps minTreeWidth and the labels ellipsize.
|
|
86
|
+
export const minTreeWidth = 70
|
|
87
|
+
export const maxFitTreeWidth = 160
|
|
88
|
+
export const pxPerTreeDepth = 10
|
|
89
|
+
export const maxTreeAreaShare = 0.3
|
|
79
90
|
export const defaultShowBranchLen = true
|
|
80
91
|
export const treeOrders = [
|
|
81
92
|
'branchLength',
|
|
@@ -93,7 +104,7 @@ export const defaultOverviewHeight = 120
|
|
|
93
104
|
// Neighbor joining does not run above this many rows. The distance matrix is
|
|
94
105
|
// O(n^2*L) and the join loop O(n^3), both on the main thread with no progress
|
|
95
106
|
// and no cancel: 400 rows measured 1.5s, 800 rows 10s, and 1600 would be about
|
|
96
|
-
// seventy. See agent-docs/
|
|
107
|
+
// seventy. See agent-docs/reference/neighbor-joining-scaling.md.
|
|
97
108
|
export const maxNeighborJoiningRows = 500
|
|
98
109
|
|
|
99
110
|
// The opacity a `rowTint` encoding draws its scale's color at, so the residues
|
package/src/measureTextCanvas.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { setFontSize } from './setFontSize.ts'
|
|
2
2
|
|
|
3
|
-
// Cached across calls
|
|
4
|
-
//
|
|
3
|
+
// Cached across calls, since both createElement and getContext are far more
|
|
4
|
+
// expensive than measureText.
|
|
5
5
|
// `null` records that this environment has no 2d context, so the lookup is not
|
|
6
6
|
// retried on every label.
|
|
7
7
|
let ctxHandle: CanvasRenderingContext2D | null | undefined
|
package/src/model/treeModel.ts
CHANGED
|
@@ -10,8 +10,6 @@ import {
|
|
|
10
10
|
defaultShowBranchLen,
|
|
11
11
|
defaultTreeOrder,
|
|
12
12
|
defaultShowTreeOverview,
|
|
13
|
-
defaultTreeAreaWidth,
|
|
14
|
-
defaultTreeWidth,
|
|
15
13
|
treeOrders,
|
|
16
14
|
} from '../constants.ts'
|
|
17
15
|
import { stripDefault } from '../stripDefault.ts'
|
|
@@ -36,16 +34,19 @@ export function TreeModelF() {
|
|
|
36
34
|
|
|
37
35
|
/**
|
|
38
36
|
* #property
|
|
39
|
-
* width of the area the tree
|
|
37
|
+
* width of the area the tree and its labels draw in, px. Undefined fits
|
|
38
|
+
* the area to the labels and the tree; `effectiveTreeAreaWidth` reads
|
|
39
|
+
* the width either way
|
|
40
40
|
*/
|
|
41
|
-
treeAreaWidth:
|
|
41
|
+
treeAreaWidth: types.maybe(types.number),
|
|
42
42
|
|
|
43
43
|
/**
|
|
44
44
|
* #property
|
|
45
|
-
* width of the tree within the
|
|
46
|
-
*
|
|
45
|
+
* width of the tree within the tree area, px. Undefined gives the tree
|
|
46
|
+
* the area less the labels; `effectiveTreeWidth` reads the width either
|
|
47
|
+
* way
|
|
47
48
|
*/
|
|
48
|
-
treeWidth:
|
|
49
|
+
treeWidth: types.maybe(types.number),
|
|
49
50
|
|
|
50
51
|
/**
|
|
51
52
|
* #property
|
|
@@ -97,29 +98,24 @@ export function TreeModelF() {
|
|
|
97
98
|
* height of the tree overview band, px
|
|
98
99
|
*/
|
|
99
100
|
overviewHeight: stripDefault(types.number, defaultOverviewHeight),
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* #property
|
|
103
|
-
* auto-size treeAreaWidth to fit the row labels (plus the tree, if drawn)
|
|
104
|
-
* instead of using a fixed width. useful when there is no tree, so the
|
|
105
|
-
* label gutter isn't padded out to the default 400px
|
|
106
|
-
*/
|
|
107
|
-
autoTreeAreaWidth: stripDefault(types.boolean, false),
|
|
108
101
|
})
|
|
109
102
|
.actions(self => ({
|
|
110
103
|
/**
|
|
111
104
|
* #action
|
|
112
|
-
* set tree area width
|
|
105
|
+
* set the tree area width, px, or undefined to fit it to the labels and
|
|
106
|
+
* the tree. The tree then fills the area less the labels
|
|
113
107
|
*/
|
|
114
|
-
setTreeAreaWidth(n: number) {
|
|
115
|
-
self.treeAreaWidth = Math.round(n)
|
|
108
|
+
setTreeAreaWidth(n: number | undefined) {
|
|
109
|
+
self.treeAreaWidth = n === undefined ? undefined : Math.round(n)
|
|
110
|
+
self.treeWidth = undefined
|
|
116
111
|
},
|
|
117
112
|
/**
|
|
118
113
|
* #action
|
|
119
|
-
* set tree width
|
|
114
|
+
* set the tree width, px, or undefined to fill the tree area less the
|
|
115
|
+
* labels
|
|
120
116
|
*/
|
|
121
|
-
setTreeWidth(n: number) {
|
|
122
|
-
self.treeWidth = Math.round(n)
|
|
117
|
+
setTreeWidth(n: number | undefined) {
|
|
118
|
+
self.treeWidth = n === undefined ? undefined : Math.round(n)
|
|
123
119
|
},
|
|
124
120
|
|
|
125
121
|
/**
|
|
@@ -134,12 +130,6 @@ export function TreeModelF() {
|
|
|
134
130
|
setDrawTree(arg: boolean) {
|
|
135
131
|
self.drawTree = arg
|
|
136
132
|
},
|
|
137
|
-
/**
|
|
138
|
-
* #action
|
|
139
|
-
*/
|
|
140
|
-
setAutoTreeAreaWidth(arg: boolean) {
|
|
141
|
-
self.autoTreeAreaWidth = arg
|
|
142
|
-
},
|
|
143
133
|
|
|
144
134
|
/**
|
|
145
135
|
* #action
|