Skip to content

Commit

Permalink
Misc
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Nov 23, 2024
1 parent 4c59558 commit 18babc1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
3 changes: 2 additions & 1 deletion plugins/wiggle/src/XYPlotRenderer/XYPlotRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default class XYPlotRenderer extends WiggleBaseRenderer {
ctx: CanvasRenderingContext2D,
props: RenderArgsDeserializedWithFeatures,
) {
const { features, config } = props
const { stopToken, features, config } = props

// the adjusted height takes into account YSCALEBAR_LABEL_OFFSET from the
// wiggle display, and makes the height of the actual drawn area add
Expand All @@ -30,6 +30,7 @@ export default class XYPlotRenderer extends WiggleBaseRenderer {
readConfObject(config, 'color', { feature }),
offset: YSCALEBAR_LABEL_OFFSET,
features: [...features.values()],
stopToken,
})
}
}
29 changes: 29 additions & 0 deletions plugins/wiggle/src/drawXY.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { clamp, featureSpanPx, Feature, Region } from '@jbrowse/core/util'

// locals
import { fillRectCtx, getOrigin, getScale, ScaleOpts } from './util'
import { checkStopToken } from '@jbrowse/core/util/stopToken'

function lighten(color: Colord, amount: number) {
const hslColor = color.toHsl()
Expand All @@ -30,6 +31,7 @@ const clipHeight = 2
export function drawXY(
ctx: CanvasRenderingContext2D,
props: {
stopToken?: string
features: Map<string, Feature> | Feature[]
bpPerPx: number
regions: Region[]
Expand Down Expand Up @@ -83,13 +85,20 @@ export function drawXY(
const reducedFeatures = []
const crossingOrigin = niceMin < pivotValue && niceMax > pivotValue

let start = performance.now()

// we handle whiskers separately to render max row, min row, and avg in three
// passes. this reduces subpixel rendering issues. note: for stylistic
// reasons, clipping indicator is only drawn for score, not min/max score
if (summaryScoreMode === 'whiskers') {
let lastCol: string | undefined
let lastMix: string | undefined
start = performance.now()
for (const feature of features.values()) {
if (performance.now() - start > 400) {
checkStopToken()
start = performance.now()
}
const [leftPx, rightPx] = featureSpanPx(feature, region, bpPerPx)
if (feature.get('summary')) {
const w = Math.max(rightPx - leftPx + fudgeFactor, minSize)
Expand All @@ -106,7 +115,12 @@ export function drawXY(
}
lastMix = undefined
lastCol = undefined
start = performance.now()
for (const feature of features.values()) {
if (performance.now() - start > 400) {
checkStopToken()
start = performance.now()
}
const [leftPx, rightPx] = featureSpanPx(feature, region, bpPerPx)
const score = feature.get('score')
const max = feature.get('maxScore')
Expand All @@ -133,7 +147,12 @@ export function drawXY(
}
lastMix = undefined
lastCol = undefined
start = performance.now()
for (const feature of features.values()) {
if (performance.now() - start > 400) {
checkStopToken()
start = performance.now()
}
const [leftPx, rightPx] = featureSpanPx(feature, region, bpPerPx)

if (feature.get('summary')) {
Expand All @@ -151,7 +170,12 @@ export function drawXY(
}
}
} else {
start = performance.now()
for (const feature of features.values()) {
if (performance.now() - start > 400) {
checkStopToken()
start = performance.now()
}
const [leftPx, rightPx] = featureSpanPx(feature, region, bpPerPx)

// create reduced features, avoiding multiple features per px
Expand Down Expand Up @@ -183,7 +207,12 @@ export function drawXY(
ctx.save()
if (hasClipping) {
ctx.fillStyle = clipColor
start = performance.now()
for (const feature of features.values()) {
if (performance.now() - start > 400) {
checkStopToken()
start = performance.now()
}
const [leftPx, rightPx] = featureSpanPx(feature, region, bpPerPx)
const w = rightPx - leftPx + fudgeFactor
const score = feature.get('score')
Expand Down

0 comments on commit 18babc1

Please sign in to comment.