import * as React from 'react'; import { ProteinChainSpec } from './ProteinChainView'; import { observer } from 'mobx-react'; import { observable, computed, makeObservable } from 'mobx'; import _ from 'lodash'; type ProteinChainProps = ProteinChainSpec & { positionToX: (pos: number) => number; y: number; height: number; uniqueHitZoneClassName: string; highlighted?: boolean; }; @observer export default class ProteinChain extends React.Component< ProteinChainProps, {} > { constructor(props: any) { super(props); makeObservable(this); } @computed get segmentsAndGaps(): { gap: boolean; start: number; end: number; }[] { const ret = []; const sortedGaps = _.sortBy(this.props.gaps, gap => gap.start); if (sortedGaps.length === 0) { ret.push({ gap: false, start: this.props.start, end: this.props.end, }); } else { if (sortedGaps[0].start > this.props.start) { ret.push({ gap: false, start: this.props.start, end: sortedGaps[0].start, }); } ret.push({ gap: true, start: sortedGaps[0].start, end: sortedGaps[0].end, }); for (let i = 1; i < sortedGaps.length; i++) { ret.push({ gap: false, start: sortedGaps[i - 1].end, end: sortedGaps[i].start, }); ret.push({ gap: true, start: sortedGaps[i].start, end: sortedGaps[i].end, }); } const lastGap = sortedGaps[sortedGaps.length - 1]; if (lastGap.end < this.props.end) { ret.push({ gap: false, start: lastGap.end, end: this.props.end, }); } } return ret; } render() { return ( {this.segmentsAndGaps.map(obj => { if (obj.gap) { return ( ); } else { return ( ); } })} ); } }