@jbrowse/plugin-wiggle
Version:
JBrowse 2 wiggle adapters, tracks, etc.
43 lines (42 loc) • 1.92 kB
JavaScript
import { createStopTokenChecker, groupBy, renderToAbstractCanvas, updateStatus, } from '@jbrowse/core/util';
import { rpcResult } from '@jbrowse/core/util/librpc';
import { collectTransferables } from '@jbrowse/core/util/offscreenCanvasPonyfill';
import { drawXY } from "../drawXY.js";
import { serializeWiggleFeature } from "../util.js";
export async function renderMultiRowXYPlot(renderProps, features) {
const { sources, height, regions, bpPerPx, stopToken, statusCallback = () => { }, } = renderProps;
const region = regions[0];
const width = (region.end - region.start) / bpPerPx;
const rowHeight = height / sources.length;
const lastCheck = createStopTokenChecker(stopToken);
const { reducedFeatures, ...rest } = await updateStatus('Rendering plot', statusCallback, () => renderToAbstractCanvas(width, height, renderProps, ctx => {
const groups = groupBy(features, f => f.get('source'));
let allReducedFeatures = [];
ctx.save();
for (const source of sources) {
const { reducedFeatures: reduced } = drawXY(ctx, {
...renderProps,
features: groups[source.name] || [],
height: rowHeight,
colorCallback: () => source.color || 'blue',
lastCheck,
});
allReducedFeatures = allReducedFeatures.concat(reduced);
ctx.strokeStyle = 'rgba(200,200,200,0.8)';
ctx.beginPath();
ctx.moveTo(0, rowHeight);
ctx.lineTo(width, rowHeight);
ctx.stroke();
ctx.translate(0, rowHeight);
}
ctx.restore();
return { reducedFeatures: allReducedFeatures };
}));
const serialized = {
...rest,
features: reducedFeatures.map(serializeWiggleFeature),
height,
width,
};
return rpcResult(serialized, collectTransferables(rest));
}