import React, { useMemo, useRef, useEffect, useContext } from 'react'; import { v1 as uuidv1 } from 'uuid'; import { SquishMotifProps, Rect } from './types'; import { xtransform } from '../../../utils/coordinates'; import { ClipPath } from '../../clippath'; import { renderSquishMotifData } from './utils'; import { TooltipContext } from "../../tooltip/tooltipcontext"; import { svgPoint } from './../../../utils/svg'; import { DNALogo } from 'logots-react'; const SquishMotif: React.FC = props => { const tooltipContext = useContext(TooltipContext); const mouseOver = (event: React.MouseEvent, rect: Rect) => { if (props.svgRef) { const mousePosition = svgPoint(props.svgRef.current!,event) tooltipContext.setTooltip({ show: true, x: mousePosition[0] > props.width - (rect.pwm!.length*20) ? (mousePosition[0] - (rect.pwm!.length*20)) + 10: mousePosition[0] +10, y: mousePosition[1], width: (rect.pwm!.length*20), height: 150, content: ( ) }); } }; const mouseOut = () => { tooltipContext.setTooltip({ show: false, x: 0, y: 0, content: undefined, width: 0, height: 0 }); }; const uuid = useRef(uuidv1()); const x = xtransform(props.domain, props.width); const rendered: Rect[][] = useMemo( () => renderSquishMotifData(props.data!, x, props.domain), [ props.data, props.domain, props.width ] ); const renderedPeaks: Rect[][] = useMemo( () => renderSquishMotifData(props.peaks || [], x, props.domain), [ props.peaks, props.domain, props.width ] ); const height = props.rowHeight * rendered.length; const id = props.id || uuid.current.toString(); useEffect( () => { props.onHeightChanged && props.onHeightChanged(height); }, [ rendered, props.rowHeight, props.onHeightChanged ]); return ( { renderedPeaks.map( (group, i) => ( {group.map( (rect, j) => ( ))} ))} { rendered.map( (group, i) => ( {group.map( (rect, j) => ( )=> { e.persist(); if(rect.pwm) mouseOver(e,rect); }} /> ))} ))} ); } export default SquishMotif;