Skip to content

Commit 59c58fd

Browse files
committed
Misc
1 parent b950e85 commit 59c58fd

4 files changed

Lines changed: 23 additions & 28 deletions

File tree

src/LinearMafDisplay/components/Sidebar/SvgWrapper.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ const SvgWrapper = observer(function ({
3737

3838
if (highlightedRowNames) {
3939
ctx.fillStyle = 'rgba(255,165,0,0.2)'
40+
const halfRowHeight = rowHeight / 2
4041
for (const name of highlightedRowNames) {
4142
const leaf = leafMap.get(name)
4243
if (leaf) {
43-
const y = leaf.x!
44-
ctx.fillRect(0, y - rowHeight / 2, sidebarWidth, rowHeight)
44+
ctx.fillRect(0, leaf.x! - halfRowHeight, sidebarWidth, rowHeight)
4545
}
4646
}
4747
}

src/LinearMafDisplay/components/Sidebar/Tree.tsx

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import React from 'react'
1+
import React, { useCallback } from 'react'
22

33
import { observer } from 'mobx-react'
44

55
import type { LinearMafDisplayModel } from '../../stateModel'
6+
import type { HierarchyNode } from 'd3-hierarchy'
7+
import type { NodeWithIdsAndLength } from '../../types'
68

79
const Tree = observer(function ({ model }: { model: LinearMafDisplayModel }) {
810
const {
@@ -16,6 +18,17 @@ const Tree = observer(function ({ model }: { model: LinearMafDisplayModel }) {
1618
nodeDescendantNames,
1719
} = model
1820

21+
const clearHighlight = useCallback(() => {
22+
model.setHighlightedRowNames(undefined)
23+
}, [model])
24+
25+
const makeMouseEnterHandler = useCallback(
26+
(node: HierarchyNode<NodeWithIdsAndLength>) => () => {
27+
model.setHighlightedRowNames(nodeDescendantNames.get(node))
28+
},
29+
[model, nodeDescendantNames],
30+
)
31+
1932
return (
2033
<>
2134
{hierarchy
@@ -38,14 +51,8 @@ const Tree = observer(function ({ model }: { model: LinearMafDisplayModel }) {
3851
x2={sx}
3952
y2={ty}
4053
style={{ pointerEvents: 'all', cursor: 'pointer' }}
41-
onMouseEnter={() => {
42-
model.setHighlightedRowNames(
43-
nodeDescendantNames.get(source),
44-
)
45-
}}
46-
onMouseLeave={() => {
47-
model.setHighlightedRowNames(undefined)
48-
}}
54+
onMouseEnter={makeMouseEnterHandler(source)}
55+
onMouseLeave={clearHighlight}
4956
/>
5057
<line
5158
stroke="black"
@@ -54,14 +61,8 @@ const Tree = observer(function ({ model }: { model: LinearMafDisplayModel }) {
5461
x2={tx}
5562
y2={ty}
5663
style={{ pointerEvents: 'all', cursor: 'pointer' }}
57-
onMouseEnter={() => {
58-
model.setHighlightedRowNames(
59-
nodeDescendantNames.get(target),
60-
)
61-
}}
62-
onMouseLeave={() => {
63-
model.setHighlightedRowNames(undefined)
64-
}}
64+
onMouseEnter={makeMouseEnterHandler(target)}
65+
onMouseLeave={clearHighlight}
6566
/>
6667
</React.Fragment>
6768
)

src/LinearMafRenderer/components/LinearMafRendering.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,6 @@ const LinearMafRendering = observer(function (props: {
5858
displayModel.setHoveredInfo?.(undefined)
5959
displayModel.setHighlightedRowNames?.(undefined)
6060
}}
61-
onMouseOut={() => {
62-
displayModel.setHoveredInfo?.(undefined)
63-
displayModel.setHighlightedRowNames?.(undefined)
64-
}}
6561
style={{
6662
overflow: 'visible',
6763
position: 'relative',

src/LinearMafRenderer/rendering/spatialIndex.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,10 @@ export function shouldAddToSpatialIndex(
2727
// Zoom-aware distance threshold: scale threshold based on zoom level
2828
// At high zoom (small bpPerPx), use smaller threshold for more precision
2929
// At low zoom (large bpPerPx), use larger threshold to reduce index size
30-
const dynamicThreshold = Math.max(
31-
MIN_X_DISTANCE,
32-
context.bpPerPx * MIN_X_DISTANCE,
30+
return (
31+
Math.abs(xPos - context.lastInsertedX) >
32+
MIN_X_DISTANCE * Math.max(1, context.bpPerPx)
3333
)
34-
35-
return Math.abs(xPos - context.lastInsertedX) > dynamicThreshold
3634
}
3735

3836
export function addToSpatialIndex(

0 commit comments

Comments
 (0)