UNPKG

@jbrowse/plugin-linear-genome-view

Version:

JBrowse 2 linear genome view

64 lines (63 loc) 3.89 kB
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime"; import { Fragment } from 'react'; import { createJBrowseTheme } from '@jbrowse/core/ui'; import { ReactRendering, getContainingView, getSession, } from '@jbrowse/core/util'; import CompositeMap from '@jbrowse/core/util/compositeMap'; import SVGLegend from "./SVGLegend.js"; import { collectLayoutsFromRenderings, deduplicateFeatureLabels, } from "./components/util.js"; import { SvgFloatingLabels } from "./models/SvgFloatingLabels.js"; import BlockState, { renderBlockData, } from "./models/serverSideRenderedBlock.js"; import { getId } from "./models/util.js"; import { ErrorBox } from "../LinearGenomeView/SVGErrorBox.js"; export async function renderBaseLinearDisplaySvg(self, opts) { const { height, id } = self; const { overrideHeight } = opts; const view = getContainingView(self); const { offsetPx: viewOffsetPx, roundedDynamicBlocks, width } = view; if (self.error) { return _jsx(ErrorBox, { error: self.error, width: width, height: height }); } const renderings = await Promise.all(roundedDynamicBlocks.map(async (block) => { const blockState = BlockState.create({ key: block.key, region: block, }); const cannotBeRenderedReason = self.regionCannotBeRenderedText(block) || self.regionCannotBeRendered(block); if (cannotBeRenderedReason) { return [ block, { reactElement: (_jsxs(_Fragment, { children: [_jsx("rect", { x: 0, y: 0, width: width, height: 20, fill: "#aaa" }), _jsx("text", { x: 0, y: 15, children: cannotBeRenderedReason })] })), }, ]; } const { rpcManager, renderArgs, renderProps, renderingProps, rendererType, } = renderBlockData(blockState, self); return [ block, await rendererType.renderInClient(rpcManager, { ...renderArgs, ...renderProps, renderingProps, exportSVG: opts, theme: opts.theme || renderProps.theme, }), ]; })); const layoutMaps = collectLayoutsFromRenderings(renderings); const layoutFeatures = new CompositeMap(layoutMaps); const { assemblyManager } = getSession(self); const { offsetPx, bpPerPx } = view; const assemblyName = view.assemblyNames[0]; const assembly = assemblyName ? assemblyManager.get(assemblyName) : undefined; const featureLabels = deduplicateFeatureLabels(layoutFeatures, view, assembly, bpPerPx); const labelsClipId = getId(id, 'labels'); const theme = createJBrowseTheme(opts.theme); const legendItems = self.showLegend ? self.legendItems(theme) : []; return (_jsxs(_Fragment, { children: [renderings.map(([block, rendering], index) => { const { offsetPx, widthPx } = block; const offset = offsetPx - viewOffsetPx; const clipid = getId(id, index); return (_jsxs(Fragment, { children: [_jsx("defs", { children: _jsx("clipPath", { id: clipid, children: _jsx("rect", { x: 0, y: 0, width: widthPx, height: overrideHeight || height }) }) }), _jsx("g", { transform: `translate(${offset} 0)`, children: _jsx("g", { clipPath: `url(#${clipid})`, children: _jsx(ReactRendering, { rendering: rendering }) }) })] }, `frag-${index}`)); }), _jsx("defs", { children: _jsx("clipPath", { id: labelsClipId, children: _jsx("rect", { x: 0, y: 0, width: width, height: overrideHeight || height }) }) }), _jsx("g", { clipPath: `url(#${labelsClipId})`, children: _jsx(SvgFloatingLabels, { featureLabels: featureLabels, offsetPx: offsetPx, viewWidth: width }) }), legendItems.length > 0 ? (_jsx(SVGLegend, { items: legendItems, width: width, legendAreaWidth: opts.legendWidth })) : null] })); }