import React from 'react'; import { v4 as uuidv4 } from 'uuid'; import Outer from '../OuterRectForLine'; import { parsePositionForBackend } from '../../helpers/position'; import { AnnotationContainer } from '../../global/otherStyled'; const Note: React.SFC = ({ id, obj_type, obj_attr, scale, viewport, isCollapse, onUpdate, }: AnnotationElementPropsType) => { const { bdcolor = '', bdwidth = 0, transparency = 0, position, is_arrow, } = obj_attr; const uuid = uuidv4(); const getActualPoint = ( { start, end }: LinePositionType, h: number, s: number, ): LinePositionType => { const x1 = start.x * scale; const y1 = h - start.y * s; const x2 = end.x * scale; const y2 = h - end.y * s; return { start: { x: x1, y: y1, }, end: { x: x2, y: y2, }, }; }; const pointCalc = ( { start, end }: LinePositionType, borderWidth: number, ): LinePositionType => ({ start: { x: start.x + borderWidth, y: start.y + borderWidth, }, end: { x: end.x + borderWidth, y: end.y + borderWidth, }, }); const rectCalc = ( { start, end }: LinePositionType, h: number, s: number, ): HTMLCoordinateType => { const startY = h - start.y * s; const endY = h - end.y * s; return { top: startY > endY ? endY : startY, left: start.x > end.x ? end.x * s : start.x * s, width: Math.abs((end.x - start.x) * s), height: Math.abs(endY - startY), }; }; const actualbdwidth = bdwidth * scale; const annotRect = rectCalc( position as LinePositionType, viewport.height, scale, ); const { start, end } = getActualPoint( position as LinePositionType, viewport.height, scale, ); const { start: completeStart, end: completeEnd } = pointCalc( { start, end } as LinePositionType, actualbdwidth, ); const actualWidth = annotRect.width + actualbdwidth + 15; const actualHeight = annotRect.height + actualbdwidth + 15; const handleMove = ({ start: moveStart, end: moveEnd, }: LinePositionType): void => { const newPosition = { start: { x: moveStart.x, y: moveStart.y, }, end: { x: moveEnd.x, y: moveEnd.y, }, }; onUpdate({ position: parsePositionForBackend( obj_type, newPosition, viewport.height, scale, ), }); }; return ( <> {is_arrow ? ( ) : null} {!isCollapse ? ( ) : ( '' )} ); }; export default Note;