diff --git a/package-lock.json b/package-lock.json index a9d2245..f4c13df 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,6 +5,7 @@ "requires": true, "packages": { "": { + "name": "starter", "version": "0.1.0", "dependencies": { "@juggle/resize-observer": "^3.3.1", diff --git a/src/components/_shared/BezierArrow/ArrowHead.tsx b/src/components/_shared/BezierArrow/ArrowHead.tsx index 34d2fa0..a52ff4b 100644 --- a/src/components/_shared/BezierArrow/ArrowHead.tsx +++ b/src/components/_shared/BezierArrow/ArrowHead.tsx @@ -1,23 +1,49 @@ +import { number } from 'prop-types'; import React from 'react'; const LARGE_VALUE = 100000; interface Props { curvePath: string; - coords: [number, number]; + coordsforArrow: [number, number][]; rotation?: number; length?: number; } +let x_coord_plus: number; +let y_coord_plus: number; +let new_curvepath: string; + +function ArrowHead({ curvePath, coordsforArrow, rotation = 30, length = 10 }: Props) { + /*we calculate the inclination between bezierhandle and end of arrow to get for any x also y*/ + const inclination=((coordsforArrow[1][1]-coordsforArrow[0][1])/(coordsforArrow[1][0]-coordsforArrow[0][0])) + if(!isFinite(inclination)){ + x_coord_plus=0 + y_coord_plus=length +}else{ + x_coord_plus = inclination === 0 ? length : Math.sqrt(Math.pow(length, 2)/(1+Math.pow(inclination, 2))); + y_coord_plus = inclination === 0 ? 0 : x_coord_plus*inclination +} + /* as the above calculation involves a sqrt we have to add negative and positive inclination as possibilities*/ +if (coordsforArrow[0][0] - {[1, -1].map((direction) => ( + {[-1,0,1].map((direction) => ( ))} diff --git a/src/components/_shared/BezierArrow/BezierArrow.tsx b/src/components/_shared/BezierArrow/BezierArrow.tsx index 29b3dc0..1de6c7c 100644 --- a/src/components/_shared/BezierArrow/BezierArrow.tsx +++ b/src/components/_shared/BezierArrow/BezierArrow.tsx @@ -12,8 +12,10 @@ interface Props { endCoords: [number, number]; startBezierHandle: [number, number]; endBezierHandle: [number, number]; + }; drawArrowHead?: boolean; + /** Draw arrow heads on one end (`"start"` or `"end"`) or on both ends (`"both"`) */ arrowHeadAnchor?: 'start' | 'end' | 'both'; arrowHeadLength?: number; @@ -30,6 +32,8 @@ function BezierArrow({ className = '', }: Props) { const curve = constructCurve(coords); + + const invertCurve = constructCurve({ startCoords: coords.endCoords, endCoords: coords.startCoords, @@ -46,7 +50,7 @@ function BezierArrow({ {drawArrowHead && ['start', 'both'].includes(arrowHeadAnchor) && ( @@ -54,7 +58,7 @@ function BezierArrow({ {drawArrowHead && ['end', 'both'].includes(arrowHeadAnchor) && ( diff --git a/src/components/_shared/BezierArrow/BezierArrowEditor.tsx b/src/components/_shared/BezierArrow/BezierArrowEditor.tsx index 874bfc2..abbdad8 100644 --- a/src/components/_shared/BezierArrow/BezierArrowEditor.tsx +++ b/src/components/_shared/BezierArrow/BezierArrowEditor.tsx @@ -71,7 +71,7 @@ function BezierArrowEditor({ initialStartCoords = [10, 10], initialEndCoords = [60, 60], initialStartBezierHandle = [10, 40], - initialEndBezierHandle = [20, 60], + initialEndBezierHandle = [60, 10], drawArrowHead = true, arrowHeadAnchor = 'end', arrowHeadLength = 10, diff --git a/src/pages/index.tsx b/src/pages/index.tsx index aa340c4..35555ee 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -1,6 +1,10 @@ import Link from 'next/link'; import React from 'react'; +import { useRef } from 'react'; +import { args } from 'react'; + +import BezierArrowEditor from 'components/_shared/BezierArrow/BezierArrowEditor'; function Index() { const PAGES = [ { url: '/graphic', title: 'Example of a complete graphic (Header+Chart)' }, @@ -8,20 +12,20 @@ function Index() { { url: '/map', title: 'Map example' }, ]; + + + const WIDTH = 400; + const HEIGHT = 120; + + const canvasRef = useRef(); + return ( - <> - Example pages: -
    - {PAGES.map(({ url, title }) => ( -
  • - - {title} - -
  • - ))} -
- + + + + ); } + export default Index;