Skip to content

Commit

Permalink
Add feature output to svg
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Mar 19, 2024
1 parent 02ba1e7 commit 5ed37d6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
33 changes: 18 additions & 15 deletions lib/src/components/msa/renderBoxFeatureCanvasBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,26 @@ export function renderBoxFeatureCanvasBlock({
highResScaleFactorOverride?: number
blockSizeYOverride?: number
}) {
const { hierarchy, blockSize, rowHeight, highResScaleFactor } = model
const k = highResScaleFactorOverride || highResScaleFactor
const by = blockSizeYOverride || blockSize
ctx.resetTransform()
ctx.scale(k, k)
ctx.translate(-offsetX, rowHeight / 2 - offsetY)
const { hierarchy, blockSize, rowHeight, highResScaleFactor, featureMode } =
model
if (featureMode) {
const k = highResScaleFactorOverride || highResScaleFactor
const by = blockSizeYOverride || blockSize
ctx.resetTransform()
ctx.scale(k, k)
ctx.translate(-offsetX, rowHeight / 2 - offsetY)

const leaves = hierarchy.leaves()
const yStart = Math.max(0, Math.floor((offsetY - rowHeight) / rowHeight))
const yEnd = Math.max(0, Math.ceil((offsetY + by + rowHeight) / rowHeight))
const visibleLeaves = leaves.slice(yStart, yEnd)
const leaves = hierarchy.leaves()
const yStart = Math.max(0, Math.floor((offsetY - rowHeight) / rowHeight))
const yEnd = Math.max(0, Math.ceil((offsetY + by + rowHeight) / rowHeight))
const visibleLeaves = leaves.slice(yStart, yEnd)

drawTiles({
model,
ctx,
visibleLeaves,
})
drawTiles({
model,
ctx,
visibleLeaves,
})
}
}

function drawTiles({
Expand Down
10 changes: 10 additions & 0 deletions lib/src/renderToSvg.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { renderMSABlock } from './components/msa/renderMSABlock'
import { colorContrast } from './util'

import MinimapSVG from './components/minimap/MinimapSVG'
import { renderBoxFeatureCanvasBlock } from './components/msa/renderBoxFeatureCanvasBlock'

export async function renderToSvg(
model: MsaViewModel,
Expand Down Expand Up @@ -132,6 +133,14 @@ function CoreRendering({
const contrastScheme = colorContrast(colorScheme, theme)
const ctx1 = Context(width, height)
const ctx2 = Context(width, height)
renderBoxFeatureCanvasBlock({
ctx: ctx2,
offsetX,
offsetY,
model,
blockSizeYOverride: height,
highResScaleFactorOverride: 1,
})
renderTreeCanvas({
model,
offsetY,
Expand All @@ -158,6 +167,7 @@ function CoreRendering({
<rect x={0} y={0} width={treeAreaWidth} height={height} />
</clipPath>
</defs>

<g
clipPath={`url(#${clipId})`}
/* eslint-disable-next-line react/no-danger */
Expand Down

0 comments on commit 5ed37d6

Please sign in to comment.