UNPKG

@jbrowse/plugin-wiggle

Version:

JBrowse 2 wiggle adapters, tracks, etc.

32 lines (31 loc) 1.28 kB
import { forEachWithStopTokenCheck, groupBy } from '@jbrowse/core/util'; import WiggleBaseRenderer from '../WiggleBaseRenderer'; export default class MultiXYPlotRenderer extends WiggleBaseRenderer { async draw(ctx, props) { const { stopToken, bpPerPx, sources, regions, features } = props; const region = regions[0]; const groups = groupBy(features.values(), f => f.get('source')); const height = props.height / sources.length; const width = (region.end - region.start) / bpPerPx; const { drawXY } = await import('../drawXY'); let feats = []; ctx.save(); forEachWithStopTokenCheck(sources, stopToken, source => { const { reducedFeatures } = drawXY(ctx, { ...props, features: groups[source.name] || [], height, colorCallback: () => source.color || 'blue', }); ctx.strokeStyle = 'rgba(200,200,200,0.8)'; ctx.beginPath(); ctx.moveTo(0, height); ctx.lineTo(width, height); ctx.stroke(); ctx.translate(0, height); feats = feats.concat(reducedFeatures); }); ctx.restore(); return { reducedFeatures: feats }; } }