From 92023f8b8783c7293fd09400ce36a8f56706ae71 Mon Sep 17 00:00:00 2001 From: Colin Date: Wed, 13 Nov 2024 02:51:40 -0500 Subject: [PATCH] Reduce calculations on change height --- .../alignments/src/BamAdapter/BamAdapter.ts | 1 - .../src/LinearSNPCoverageDisplay/model.ts | 61 +++--- .../wiggle/src/LinearWiggleDisplay/model.ts | 132 +++++++------ .../src/MultiLinearWiggleDisplay/model.ts | 182 +++++++++--------- .../wiggle/src/quantitativeStatsAutorun.ts | 8 +- 5 files changed, 209 insertions(+), 175 deletions(-) diff --git a/plugins/alignments/src/BamAdapter/BamAdapter.ts b/plugins/alignments/src/BamAdapter/BamAdapter.ts index 3c03fb05eb..33788a5c3f 100644 --- a/plugins/alignments/src/BamAdapter/BamAdapter.ts +++ b/plugins/alignments/src/BamAdapter/BamAdapter.ts @@ -207,7 +207,6 @@ export default class BamAdapter extends BaseFeatureDataAdapter { if (tagFilter) { const readVal = record.tags[tagFilter.tag] const filterVal = tagFilter.value - console.log({ readVal, filterVal }) if ( filterVal === '*' ? readVal === undefined diff --git a/plugins/alignments/src/LinearSNPCoverageDisplay/model.ts b/plugins/alignments/src/LinearSNPCoverageDisplay/model.ts index b70f15fdaa..3a987b8c9c 100644 --- a/plugins/alignments/src/LinearSNPCoverageDisplay/model.ts +++ b/plugins/alignments/src/LinearSNPCoverageDisplay/model.ts @@ -135,7 +135,7 @@ function stateModelFactory( }, })) .views(self => { - const { renderProps: superRenderProps } = self + const { adapterProps: superAdapterProps } = self return { /** * #getter @@ -196,36 +196,16 @@ function stateModelFactory( ) }, - /** - * #getter - */ - get renderReady() { - const superProps = superRenderProps() - return !superProps.notReady && self.modificationsReady - }, - - /** - * #getter - */ - get ready() { - return this.renderReady - }, - /** * #method */ - renderProps() { - const superProps = superRenderProps() - const { filters, colorBy, filterBy, visibleModifications } = self + adapterProps() { + const superProps = superAdapterProps() + const { filters, filterBy } = self return { ...superProps, - notReady: !this.ready, filters, - colorBy, filterBy, - visibleModifications: Object.fromEntries( - visibleModifications.toJSON(), - ), } }, } @@ -288,8 +268,39 @@ function stateModelFactory( })) .views(self => { - const { trackMenuItems: superTrackMenuItems } = self + const { + renderProps: superRenderProps, + trackMenuItems: superTrackMenuItems, + } = self return { + /** + * #getter + */ + get renderReady() { + const superProps = superRenderProps() + return !superProps.notReady && self.modificationsReady + }, + + /** + * #getter + */ + get ready() { + return this.renderReady + }, + /** + * #method + */ + renderProps() { + const { colorBy, visibleModifications } = self + return { + ...superRenderProps(), + notReady: !this.ready, + colorBy, + visibleModifications: Object.fromEntries( + visibleModifications.toJSON(), + ), + } + }, /** * #getter */ diff --git a/plugins/wiggle/src/LinearWiggleDisplay/model.ts b/plugins/wiggle/src/LinearWiggleDisplay/model.ts index b502b7c6fe..0ffd02604b 100644 --- a/plugins/wiggle/src/LinearWiggleDisplay/model.ts +++ b/plugins/wiggle/src/LinearWiggleDisplay/model.ts @@ -71,61 +71,33 @@ function stateModelFactory( } return rendererType }, - })) - - .views(self => ({ - /** - * #getter - */ - get ticks() { - const { scaleType, domain, height } = self - const minimalTicks = getConf(self, 'minimalTicks') - const inverted = getConf(self, 'inverted') - const range = [height - YSCALEBAR_LABEL_OFFSET, YSCALEBAR_LABEL_OFFSET] - if (!domain) { - return undefined - } - const scale = getScale({ - scaleType, - domain, - range, - inverted, - }) - const ticks = axisPropsFromTickScale(scale, 4) - return height < 100 || minimalTicks - ? { ...ticks, values: domain } - : ticks - }, /** * #getter */ - get quantitativeStatsReleventToCurrentZoom() { + get quantitativeStatsRelevantToCurrentZoom() { const view = getContainingView(self) as LinearGenomeViewModel return self.stats?.currStatsBpPerPx === view.bpPerPx }, })) + .views(self => { const { renderProps: superRenderProps } = self return { /** * #method */ - renderProps() { + adapterProps() { const superProps = superRenderProps() - const { filters, ticks, height, resolution, scaleOpts } = self + const { filters, resolution, scaleOpts } = self return { ...superProps, - notReady: - superProps.notReady || - !self.quantitativeStatsReleventToCurrentZoom, + rpcDriverName: self.rpcDriverName, displayModel: self, config: self.rendererConfig, displayCrossHatches: self.displayCrossHatchesSetting, scaleOpts, resolution, - height, - ticks, filters, } }, @@ -133,36 +105,78 @@ function stateModelFactory( /** * #getter */ - get needsScalebar() { - const { rendererTypeName: type } = self - return type === 'XYPlotRenderer' || type === 'LinePlotRenderer' - }, - /** - * #getter - */ - get fillSetting() { - if (self.filled) { - return 0 - } else if (self.minSize === 1) { - return 1 - } else { - return 2 + get ticks() { + const { scaleType, domain, height } = self + const minimalTicks = getConf(self, 'minimalTicks') + const inverted = getConf(self, 'inverted') + const range = [ + height - YSCALEBAR_LABEL_OFFSET, + YSCALEBAR_LABEL_OFFSET, + ] + if (!domain) { + return undefined } - }, - /** - * #getter - */ - get quantitativeStatsReady() { - const view = getContainingView(self) as LinearGenomeViewModel - return ( - view.initialized && - self.featureDensityStatsReady && - !self.regionTooLarge && - !self.error - ) + const scale = getScale({ + scaleType, + domain, + range, + inverted, + }) + const ticks = axisPropsFromTickScale(scale, 4) + return height < 100 || minimalTicks + ? { ...ticks, values: domain } + : ticks }, } }) + .views(self => ({ + /** + * #method + */ + renderProps() { + const { ticks, height } = self + const superProps = self.adapterProps() + return { + ...self.adapterProps(), + notReady: + superProps.notReady || !self.quantitativeStatsRelevantToCurrentZoom, + height, + ticks, + } + }, + + /** + * #getter + */ + get needsScalebar() { + const { rendererTypeName: type } = self + return type === 'XYPlotRenderer' || type === 'LinePlotRenderer' + }, + /** + * #getter + */ + get fillSetting() { + if (self.filled) { + return 0 + } else if (self.minSize === 1) { + return 1 + } else { + return 2 + } + }, + /** + * #getter + */ + get quantitativeStatsReady() { + const view = getContainingView(self) as LinearGenomeViewModel + return ( + view.initialized && + self.featureDensityStatsReady && + !self.regionTooLarge && + !self.error + ) + }, + })) .views(self => { const { trackMenuItems: superTrackMenuItems } = self const hasRenderings = getConf(self, 'defaultRendering') diff --git a/plugins/wiggle/src/MultiLinearWiggleDisplay/model.ts b/plugins/wiggle/src/MultiLinearWiggleDisplay/model.ts index daeb624359..cdf142aafe 100644 --- a/plugins/wiggle/src/MultiLinearWiggleDisplay/model.ts +++ b/plugins/wiggle/src/MultiLinearWiggleDisplay/model.ts @@ -258,119 +258,129 @@ export function stateModelFactory( ) }, })) - .views(self => ({ - /** - * #getter - */ - get ticks() { - const { scaleType, domain, isMultiRow, rowHeight, useMinimalTicks } = - self - - if (!domain) { - return undefined - } - - const offset = isMultiRow ? 0 : YSCALEBAR_LABEL_OFFSET - const ticks = axisPropsFromTickScale( - getScale({ - scaleType, - domain, - range: [rowHeight - offset, offset], - inverted: getConf(self, 'inverted') as boolean, - }), - 4, - ) - return useMinimalTicks ? { ...ticks, values: domain } : ticks - }, - - /** - * #getter - */ - get colors() { - return [ - 'red', - 'blue', - 'green', - 'orange', - 'purple', - 'cyan', - 'pink', - 'darkblue', - 'darkred', - 'pink', - ] - }, - })) .views(self => { const { renderProps: superRenderProps } = self return { /** * #method */ - renderProps() { + adapterProps() { const superProps = superRenderProps() - const { - displayCrossHatches, - filters, - height, - resolution, - rpcDriverName, - scaleOpts, - stats, - sources, - ticks, - rendererConfig: config, - } = self return { ...superProps, - notReady: superProps.notReady || !sources || !stats, displayModel: self, - config, - displayCrossHatches, - filters, - height, - resolution, - rpcDriverName, - scaleOpts, - sources, - ticks, - onMouseMove: (_: unknown, f: Feature) => { - self.setFeatureUnderMouse(f) - }, - onMouseLeave: () => { - self.setFeatureUnderMouse(undefined) - }, + config: self.rendererConfig, + filters: self.filters, + resolution: self.resolution, + rpcDriverName: self.rpcDriverName, + sources: self.sources, } }, - /** * #getter */ - get hasResolution() { - return self.adapterCapabilities.includes('hasResolution') + get ticks() { + const { scaleType, domain, isMultiRow, rowHeight, useMinimalTicks } = + self + + if (!domain) { + return undefined + } + + const offset = isMultiRow ? 0 : YSCALEBAR_LABEL_OFFSET + const ticks = axisPropsFromTickScale( + getScale({ + scaleType, + domain, + range: [rowHeight - offset, offset], + inverted: getConf(self, 'inverted') as boolean, + }), + 4, + ) + return useMinimalTicks ? { ...ticks, values: domain } : ticks }, /** * #getter */ - get hasGlobalStats() { - return self.adapterCapabilities.includes('hasGlobalStats') + get colors() { + return [ + 'red', + 'blue', + 'green', + 'orange', + 'purple', + 'cyan', + 'pink', + 'darkblue', + 'darkred', + 'pink', + ] }, - /** * #getter */ - get fillSetting() { - if (self.filled) { - return 0 - } else if (self.minSize === 1) { - return 1 - } else { - return 2 - } + get quantitativeStatsRelevantToCurrentZoom() { + const view = getContainingView(self) as LinearGenomeViewModel + return self.stats?.currStatsBpPerPx === view.bpPerPx }, } }) + .views(self => ({ + /** + * #method + */ + renderProps() { + const superProps = self.adapterProps() + return { + ...superProps, + notReady: + superProps.notReady || + !self.sources || + !self.quantitativeStatsRelevantToCurrentZoom, + displayModel: self, + rpcDriverName: self.rpcDriverName, + displayCrossHatches: self.displayCrossHatches, + height: self.height, + ticks: self.ticks, + stats: self.stats, + scaleOpts: self.scaleOpts, + onMouseMove: (_: unknown, f: Feature) => { + self.setFeatureUnderMouse(f) + }, + onMouseLeave: () => { + self.setFeatureUnderMouse(undefined) + }, + } + }, + + /** + * #getter + */ + get hasResolution() { + return self.adapterCapabilities.includes('hasResolution') + }, + + /** + * #getter + */ + get hasGlobalStats() { + return self.adapterCapabilities.includes('hasGlobalStats') + }, + + /** + * #getter + */ + get fillSetting() { + if (self.filled) { + return 0 + } else if (self.minSize === 1) { + return 1 + } else { + return 2 + } + }, + })) .views(self => { const { trackMenuItems: superTrackMenuItems } = self const hasRenderings = getConf(self, 'defaultRendering') diff --git a/plugins/wiggle/src/quantitativeStatsAutorun.ts b/plugins/wiggle/src/quantitativeStatsAutorun.ts index 8b2fa6e16d..edd5ef83e4 100644 --- a/plugins/wiggle/src/quantitativeStatsAutorun.ts +++ b/plugins/wiggle/src/quantitativeStatsAutorun.ts @@ -1,4 +1,6 @@ import { autorun } from 'mobx' +import { addDisposer, isAlive } from 'mobx-state-tree' +// jbrowse import { isAbortException, getSession, @@ -6,8 +8,6 @@ import { } from '@jbrowse/core/util' import { QuantitativeStats } from '@jbrowse/core/util/stats' import { getRpcSessionId } from '@jbrowse/core/util/tracks' -import { addDisposer, isAlive } from 'mobx-state-tree' - import { LinearGenomeViewModel } from '@jbrowse/plugin-linear-genome-view' import { AnyConfigurationModel, getConf } from '@jbrowse/core/configuration' @@ -21,7 +21,7 @@ export function quantitativeStatsAutorun(self: { stats: QuantitativeStats, statsRegion: string, ) => void - renderProps: () => Record + adapterProps: () => Record configuration: AnyConfigurationModel adapterConfig: AnyConfigurationModel autoscaleType: string @@ -45,7 +45,7 @@ export function quantitativeStatsAutorun(self: { signal: aborter.signal, filters: [], currStatsBpPerPx: view.bpPerPx, - ...self.renderProps(), + ...self.adapterProps(), }) if (isAlive(self)) {