Skip to content

Commit

Permalink
Remove layoutRecords concept
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Sep 25, 2024
1 parent 26dfea7 commit 7024825
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 60 deletions.
6 changes: 3 additions & 3 deletions packages/core/util/layouts/GranularRectLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,10 +507,10 @@ export default class GranularRectLayout<T> implements BaseLayout<T> {
getRectangles(): Map<string, RectTuple> {
return new Map(
[...this.rectangles.entries()].map(([id, rect]) => {
const { l, r, originalHeight, top } = rect
const { l, r, originalHeight, top, data } = rect
const t = (top || 0) * this.pitchY
const b = t + originalHeight
return [id, [l * this.pitchX, t, r * this.pitchX, b]] // left, top, right, bottom
return [id, [l * this.pitchX, t, r * this.pitchX, b, data]] // left, top, right, bottom
}),
)
}
Expand All @@ -531,7 +531,7 @@ export default class GranularRectLayout<T> implements BaseLayout<T> {
const x2 = region.end
// add +/- pitchX to avoid resolution causing errors
if (segmentsIntersect(x1, x2, y1 - this.pitchX, y2 + this.pitchX)) {
regionRectangles[id] = [y1, t, y2, b]
regionRectangles[id] = [y1, t, y2, b, rect.data]
}
}
}
Expand Down
43 changes: 0 additions & 43 deletions plugins/canvas/src/CanvasFeatureRenderer/CanvasFeatureRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,6 @@ export default class CanvasRenderer extends BoxRendererType {
this.drawRect(ctx, fRect, props)
}

if (props.exportSVG) {
postDraw({
ctx,
layoutRecords: layoutRecords,
offsetPx: 0,
...props,
})
}
return undefined
}

Expand Down Expand Up @@ -127,17 +119,6 @@ export default class CanvasRenderer extends BoxRendererType {
return {
...results,
...res,
layoutRecords: layoutRecords.map(rec => ({
label: rec.label,
description: rec.description,
l: rec.l,
t: rec.t,
f: {
start: rec.f.get('start'),
end: rec.f.get('end'),
type: rec.f.get('type'),
},
})),
features,
layout,
height,
Expand All @@ -147,30 +128,6 @@ export default class CanvasRenderer extends BoxRendererType {
}
}

export function postDraw({
ctx,
layoutRecords,
offsetPx,
regions,
}: {
ctx: CanvasRenderingContext2D
regions: {
start: number
}[]
offsetPx: number
layoutRecords: PostDrawFeatureRectWithGlyph[]
}) {
ctx.fillStyle = 'black'
ctx.font = '10px sans-serif'
layoutRecords.filter(notEmpty).forEach(record => {
record.glyph.postDraw(ctx, {
record,
regions,
offsetPx,
})
})
}

export {
type RenderArgs,
type RenderArgsSerialized,
Expand Down
13 changes: 6 additions & 7 deletions plugins/canvas/src/CanvasFeatureRenderer/FeatureGlyph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ export default abstract class FeatureGlyph {
const leftBase = region.start
const startbp = fRect.l / scale + leftBase
const endbp = (fRect.l + fRect.w) / scale + leftBase
const top = layout.addRect(feature.id(), startbp, endbp, fRect.h)
const top = layout.addRect(feature.id(), startbp, endbp, fRect.h, {
label: feature.get('name') || feature.get('id'),
})

return top === null
? null
Expand All @@ -78,12 +80,9 @@ export default abstract class FeatureGlyph {

getFeatureRectangle(viewInfo: ViewInfo, feature: Feature) {
const { region, bpPerPx } = viewInfo
const [leftPx, rightPx] = bpSpanPx(
feature.get('start'),
feature.get('end'),
region,
bpPerPx,
)
const s = feature.get('start')
const e = feature.get('end')
const [leftPx, rightPx] = bpSpanPx(s, e, region, bpPerPx)

return {
l: leftPx,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Menu } from '@jbrowse/core/ui'

import LinearBlocks from './LinearBlocks'
import { BaseLinearDisplayModel } from '../models/BaseLinearDisplayModel'
import { clamp, getContainingView } from '@jbrowse/core/util'
import { clamp, getContainingView, measureText } from '@jbrowse/core/util'
import { LinearGenomeViewModel } from '../../LinearGenomeView'

const useStyles = makeStyles()({
Expand All @@ -33,8 +33,8 @@ const FloatingLabels = observer(function ({
const { bpPerPx, offsetPx } = view
return (
<div style={{ position: 'relative' }}>
{[...model.layoutFeatures.entries()].map(([key, val]) =>
val ? (
{[...model.layoutFeatures.entries()].map(([key, val]) => {
return val ? (
<div
key={key}
style={{
Expand All @@ -43,15 +43,15 @@ const FloatingLabels = observer(function ({
left: clamp(
0,
val[0] / bpPerPx - offsetPx,
val[2] / bpPerPx - offsetPx,
val[2] / bpPerPx - offsetPx - measureText(val[4].label),
),
top: val[3] - 14,
}}
>
{key}
{val[4].label}
</div>
) : null,
)}
) : null
})}
</div>
)
})
Expand Down

0 comments on commit 7024825

Please sign in to comment.