Skip to content

Commit

Permalink
Hightlight mRNA on intron hover and tooltip fix
Browse files Browse the repository at this point in the history
  • Loading branch information
shashankbrgowda committed Oct 7, 2024
1 parent 89ccf49 commit f9a420a
Showing 1 changed file with 99 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { alpha } from '@mui/material'
import { LinearApolloDisplay } from '../stateModel'
import {
isMousePositionWithFeatureAndGlyph,
LinearApolloDisplayMouseEvents,
MousePosition,
MousePositionWithFeatureAndGlyph,
} from '../stateModel/mouseEvents'
Expand Down Expand Up @@ -291,9 +292,41 @@ function getFeatureFromLayout(
): AnnotationFeature | undefined {
const featureInThisRow: AnnotationFeature[] = featuresForRow(feature)[row]
for (const f of featureInThisRow) {
let featureObj
if (bp >= f.min && bp <= f.max && f.parent) {
return f
featureObj = f

Check warning on line 297 in packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts#L297

Added line #L297 was not covered by tests
}
if (!featureObj) {
continue

Check warning on line 300 in packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts#L300

Added line #L300 was not covered by tests
}
if (
featureObj.type === 'CDS' &&
featureObj.parent &&
featureObj.parent.type === 'mRNA'

Check warning on line 305 in packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts#L304-L305

Added lines #L304 - L305 were not covered by tests
) {
const { max, min } = featureObj
const { cdsLocations } = featureObj.parent
for (const cdsLoc of cdsLocations) {
const firstLoc = cdsLoc.at(0)
const lastLoc = cdsLoc.at(-1)

Check warning on line 311 in packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts#L307-L311

Added lines #L307 - L311 were not covered by tests

if (
firstLoc &&
firstLoc.min === min &&
lastLoc &&
lastLoc.max === max

Check warning on line 317 in packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts#L315-L317

Added lines #L315 - L317 were not covered by tests
) {
for (const loc of cdsLoc) {

Check warning on line 319 in packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts#L319

Added line #L319 was not covered by tests
if (bp >= loc.min && bp <= loc.max) {
return featureObj

Check warning on line 321 in packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts#L321

Added line #L321 was not covered by tests
}
}
break

Check warning on line 324 in packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts#L324

Added line #L324 was not covered by tests
}
}
return featureObj.parent

Check warning on line 327 in packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts#L327

Added line #L327 was not covered by tests
}
return featureObj

Check warning on line 329 in packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts#L329

Added line #L329 was not covered by tests
}
return feature
}
Expand Down Expand Up @@ -499,9 +532,73 @@ function getDraggableFeatureInfo(
return
}

function drawTooltip(
display: LinearApolloDisplayMouseEvents,
context: CanvasRenderingContext2D,

Check warning on line 537 in packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts#L537

Added line #L537 was not covered by tests
): void {
const { apolloHover, apolloRowHeight, lgv, theme } = display

Check warning on line 539 in packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts#L539

Added line #L539 was not covered by tests
if (!apolloHover) {
return

Check warning on line 541 in packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts#L541

Added line #L541 was not covered by tests
}
const { feature, topLevelFeature } = apolloHover
const position = display.getFeatureLayoutPosition(feature)

Check warning on line 544 in packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts#L543-L544

Added lines #L543 - L544 were not covered by tests
if (!position) {
return

Check warning on line 546 in packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts#L546

Added line #L546 was not covered by tests
}
const { layoutIndex, layoutRow } = position
const rowIdx = getRowForFeature(topLevelFeature, feature)
const { bpPerPx, displayedRegions, offsetPx } = lgv
const displayedRegion = displayedRegions[layoutIndex]
const { refName, reversed } = displayedRegion

Check warning on line 552 in packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts#L548-L552

Added lines #L548 - L552 were not covered by tests

let location = 'Loc: '

Check warning on line 554 in packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts#L554

Added line #L554 was not covered by tests

const { length, max, min } = feature
location += `${min + 1}${max}`

Check warning on line 557 in packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts#L556-L557

Added lines #L556 - L557 were not covered by tests

let startPx =
(lgv.bpToPx({
refName,
coord: reversed ? max : min,
regionNumber: layoutIndex,
})?.offsetPx ?? 0) - offsetPx

Check warning on line 564 in packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts#L564

Added line #L564 was not covered by tests
const top = (layoutRow + (rowIdx ?? 0)) * apolloRowHeight
const widthPx = length / bpPerPx

Check warning on line 566 in packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts#L566

Added line #L566 was not covered by tests

const featureType = `Type: ${feature.type}`
const { attributes } = feature

Check warning on line 569 in packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts#L568-L569

Added lines #L568 - L569 were not covered by tests
const featureName = attributes.get('gff_name')?.find((name) => name !== '')
const textWidth = [

Check warning on line 571 in packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts#L571

Added line #L571 was not covered by tests
context.measureText(featureType).width,
context.measureText(location).width,
]
if (featureName) {
textWidth.push(context.measureText(`Name: ${featureName}`).width)

Check warning on line 576 in packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts#L576

Added line #L576 was not covered by tests
}
const maxWidth = Math.max(...textWidth)

Check warning on line 578 in packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts#L578

Added line #L578 was not covered by tests

startPx = startPx + widthPx + 5

Check warning on line 580 in packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts#L580

Added line #L580 was not covered by tests
context.fillStyle = alpha(theme?.palette.text.primary ?? 'rgb(1, 1, 1)', 0.7)
context.fillRect(startPx, top, maxWidth + 4, textWidth.length === 3 ? 45 : 35)
context.beginPath()
context.moveTo(startPx, top)
context.lineTo(startPx - 5, top + 5)
context.lineTo(startPx, top + 10)
context.fill()

Check warning on line 587 in packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts#L583-L587

Added lines #L583 - L587 were not covered by tests
context.fillStyle = theme?.palette.background.default ?? 'rgba(255, 255, 255)'
let textTop = top + 12
context.fillText(featureType, startPx + 2, textTop)

Check warning on line 590 in packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts#L589-L590

Added lines #L589 - L590 were not covered by tests
if (featureName) {
textTop = textTop + 12
context.fillText(`Name: ${featureName}`, startPx + 2, textTop)

Check warning on line 593 in packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts#L592-L593

Added lines #L592 - L593 were not covered by tests
}
textTop = textTop + 12
context.fillText(location, startPx + 2, textTop)

Check warning on line 596 in packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts#L595-L596

Added lines #L595 - L596 were not covered by tests
}

// False positive here, none of these functions use "this"
/* eslint-disable @typescript-eslint/unbound-method */
const { drawTooltip, getContextMenuItems, onMouseLeave } = boxGlyph
const { getContextMenuItems, onMouseLeave } = boxGlyph

Check warning on line 601 in packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/GeneGlyph.ts#L601

Added line #L601 was not covered by tests
/* eslint-enable @typescript-eslint/unbound-method */

export const geneGlyph: Glyph = {
Expand Down

0 comments on commit f9a420a

Please sign in to comment.