index.tsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import React from 'react';
  2. import OuterRect from '../OuterRect';
  3. import SvgShapeElement from '../SvgShapeElement';
  4. import { rectCalc, parsePositionForBackend } from '../../helpers/position';
  5. import { AnnotationContainer } from '../../global/otherStyled';
  6. const Shape: React.FC<AnnotationElementPropsType> = ({
  7. id,
  8. obj_type,
  9. obj_attr: {
  10. bdcolor = '',
  11. fcolor = '',
  12. bdwidth = 0,
  13. transparency = 0,
  14. ftransparency = 0,
  15. position,
  16. },
  17. scale,
  18. viewport,
  19. isCollapse,
  20. onUpdate,
  21. }: AnnotationElementPropsType) => {
  22. const annotRect = rectCalc(position as PositionType, viewport.height, scale);
  23. const handleScaleOrMove = ({
  24. top,
  25. left,
  26. width = 0,
  27. height = 0,
  28. }: CoordType): void => {
  29. const newPosition = {
  30. top,
  31. left,
  32. bottom: top + (height || annotRect.height),
  33. right: left + (width || annotRect.width),
  34. };
  35. onUpdate({
  36. position: parsePositionForBackend(
  37. obj_type,
  38. newPosition,
  39. viewport.height,
  40. scale,
  41. ),
  42. });
  43. };
  44. return (
  45. <>
  46. <AnnotationContainer
  47. id={id}
  48. top={`${annotRect.top}px`}
  49. left={`${annotRect.left}px`}
  50. width={`${annotRect.width}px`}
  51. height={`${annotRect.height}px`}
  52. >
  53. <SvgShapeElement
  54. shape={obj_type}
  55. width={annotRect.width}
  56. height={annotRect.height}
  57. bdcolor={bdcolor}
  58. transparency={transparency}
  59. bdwidth={bdwidth * scale}
  60. fcolor={fcolor}
  61. ftransparency={ftransparency}
  62. />
  63. </AnnotationContainer>
  64. {!isCollapse ? (
  65. <OuterRect
  66. top={annotRect.top}
  67. left={annotRect.left}
  68. width={annotRect.width}
  69. height={annotRect.height}
  70. onMove={handleScaleOrMove}
  71. onScale={handleScaleOrMove}
  72. />
  73. ) : (
  74. ''
  75. )}
  76. </>
  77. );
  78. };
  79. export default Shape;