@pie-lib/graphing-solution-set 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_virtual/_rolldown/runtime.js +23 -0
- package/dist/axis/arrow.d.ts +14 -0
- package/dist/axis/arrow.d.ts.map +1 -0
- package/dist/axis/arrow.js +34 -0
- package/dist/axis/axes.d.ts +133 -0
- package/dist/axis/axes.d.ts.map +1 -0
- package/dist/axis/axes.js +214 -0
- package/dist/axis/index.d.ts +11 -0
- package/dist/axis/index.d.ts.map +1 -0
- package/dist/bg.d.ts +52 -0
- package/dist/bg.d.ts.map +1 -0
- package/dist/bg.js +44 -0
- package/dist/container/actions.d.ts +16 -0
- package/dist/container/actions.d.ts.map +1 -0
- package/dist/container/actions.js +7 -0
- package/dist/container/index.d.ts +27 -0
- package/dist/container/index.d.ts.map +1 -0
- package/dist/container/index.js +48 -0
- package/dist/container/marks.d.ts +11 -0
- package/dist/container/marks.d.ts.map +1 -0
- package/dist/container/marks.js +11 -0
- package/dist/container/middleware.d.ts +11 -0
- package/dist/container/middleware.d.ts.map +1 -0
- package/dist/container/middleware.js +4 -0
- package/dist/container/reducer.d.ts +13 -0
- package/dist/container/reducer.d.ts.map +1 -0
- package/dist/container/reducer.js +7 -0
- package/dist/coordinates-label.d.ts +50 -0
- package/dist/coordinates-label.d.ts.map +1 -0
- package/dist/coordinates-label.js +46 -0
- package/dist/graph-with-controls.d.ts +86 -0
- package/dist/graph-with-controls.d.ts.map +1 -0
- package/dist/graph-with-controls.js +155 -0
- package/dist/graph.d.ts +120 -0
- package/dist/graph.d.ts.map +1 -0
- package/dist/graph.js +221 -0
- package/dist/grid-setup.d.ts +27 -0
- package/dist/grid-setup.d.ts.map +1 -0
- package/dist/grid-setup.js +307 -0
- package/dist/grid.d.ts +44 -0
- package/dist/grid.d.ts.map +1 -0
- package/dist/grid.js +59 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/labels.d.ts +74 -0
- package/dist/labels.d.ts.map +1 -0
- package/dist/labels.js +134 -0
- package/dist/mark-label.d.ts +50 -0
- package/dist/mark-label.d.ts.map +1 -0
- package/dist/mark-label.js +84 -0
- package/dist/node_modules/.bun/@babel_runtime@7.28.6/node_modules/@babel/runtime/helpers/esm/assertThisInitialized.js +7 -0
- package/dist/node_modules/.bun/@babel_runtime@7.28.6/node_modules/@babel/runtime/helpers/esm/defineProperty.js +12 -0
- package/dist/node_modules/.bun/@babel_runtime@7.28.6/node_modules/@babel/runtime/helpers/esm/extends.js +12 -0
- package/dist/node_modules/.bun/@babel_runtime@7.28.6/node_modules/@babel/runtime/helpers/esm/inheritsLoose.js +7 -0
- package/dist/node_modules/.bun/@babel_runtime@7.28.6/node_modules/@babel/runtime/helpers/esm/objectSpread2.js +25 -0
- package/dist/node_modules/.bun/@babel_runtime@7.28.6/node_modules/@babel/runtime/helpers/esm/objectWithoutPropertiesLoose.js +12 -0
- package/dist/node_modules/.bun/@babel_runtime@7.28.6/node_modules/@babel/runtime/helpers/esm/setPrototypeOf.js +8 -0
- package/dist/node_modules/.bun/@babel_runtime@7.28.6/node_modules/@babel/runtime/helpers/esm/toPrimitive.js +14 -0
- package/dist/node_modules/.bun/@babel_runtime@7.28.6/node_modules/@babel/runtime/helpers/esm/toPropertyKey.js +9 -0
- package/dist/node_modules/.bun/@babel_runtime@7.28.6/node_modules/@babel/runtime/helpers/esm/typeof.js +11 -0
- package/dist/node_modules/.bun/@visx_axis@3.12.0_f4eacebf2041cd4f/node_modules/@visx/axis/esm/axis/Axis.js +100 -0
- package/dist/node_modules/.bun/@visx_axis@3.12.0_f4eacebf2041cd4f/node_modules/@visx/axis/esm/axis/AxisRenderer.js +61 -0
- package/dist/node_modules/.bun/@visx_axis@3.12.0_f4eacebf2041cd4f/node_modules/@visx/axis/esm/axis/Ticks.js +42 -0
- package/dist/node_modules/.bun/@visx_axis@3.12.0_f4eacebf2041cd4f/node_modules/@visx/axis/esm/constants/orientation.js +9 -0
- package/dist/node_modules/.bun/@visx_axis@3.12.0_f4eacebf2041cd4f/node_modules/@visx/axis/esm/utils/createPoint.js +14 -0
- package/dist/node_modules/.bun/@visx_axis@3.12.0_f4eacebf2041cd4f/node_modules/@visx/axis/esm/utils/getAxisRangePaddingConfig.js +21 -0
- package/dist/node_modules/.bun/@visx_axis@3.12.0_f4eacebf2041cd4f/node_modules/@visx/axis/esm/utils/getLabelTransform.js +16 -0
- package/dist/node_modules/.bun/@visx_axis@3.12.0_f4eacebf2041cd4f/node_modules/@visx/axis/esm/utils/getTickFormatter.js +8 -0
- package/dist/node_modules/.bun/@visx_axis@3.12.0_f4eacebf2041cd4f/node_modules/@visx/axis/esm/utils/getTickPosition.js +15 -0
- package/dist/node_modules/.bun/@visx_grid@3.12.0_f4eacebf2041cd4f/node_modules/@visx/grid/esm/grids/Grid.js +78 -0
- package/dist/node_modules/.bun/@visx_grid@3.12.0_f4eacebf2041cd4f/node_modules/@visx/grid/esm/grids/GridColumns.js +79 -0
- package/dist/node_modules/.bun/@visx_grid@3.12.0_f4eacebf2041cd4f/node_modules/@visx/grid/esm/grids/GridRows.js +79 -0
- package/dist/node_modules/.bun/@visx_grid@3.12.0_f4eacebf2041cd4f/node_modules/@visx/grid/esm/utils/getScaleBandwidth.js +6 -0
- package/dist/node_modules/.bun/@visx_group@3.12.0_f4eacebf2041cd4f/node_modules/@visx/group/esm/Group.js +49 -0
- package/dist/node_modules/.bun/@visx_point@3.12.0/node_modules/@visx/point/esm/Point.js +18 -0
- package/dist/node_modules/.bun/@visx_scale@3.12.0/node_modules/@visx/scale/esm/utils/coerceNumber.js +10 -0
- package/dist/node_modules/.bun/@visx_scale@3.12.0/node_modules/@visx/scale/esm/utils/getTicks.js +9 -0
- package/dist/node_modules/.bun/@visx_scale@3.12.0/node_modules/@visx/scale/esm/utils/toString.js +6 -0
- package/dist/node_modules/.bun/@visx_shape@3.12.0_f4eacebf2041cd4f/node_modules/@visx/shape/esm/shapes/Line.js +46 -0
- package/dist/node_modules/.bun/@visx_shape@3.12.0_f4eacebf2041cd4f/node_modules/@visx/shape/lib/shapes/Line.js +52 -0
- package/dist/node_modules/.bun/@visx_text@3.12.0_f4eacebf2041cd4f/node_modules/@visx/text/esm/Text.js +57 -0
- package/dist/node_modules/.bun/@visx_text@3.12.0_f4eacebf2041cd4f/node_modules/@visx/text/esm/hooks/useText.js +91 -0
- package/dist/node_modules/.bun/@visx_text@3.12.0_f4eacebf2041cd4f/node_modules/@visx/text/esm/util/getStringWidth.js +21 -0
- package/dist/node_modules/.bun/balanced-match@0.4.2/node_modules/balanced-match/index.js +32 -0
- package/dist/node_modules/.bun/balanced-match@1.0.2/node_modules/balanced-match/index.js +33 -0
- package/dist/node_modules/.bun/hoist-non-react-statics@3.3.2/node_modules/hoist-non-react-statics/dist/hoist-non-react-statics.cjs.js +68 -0
- package/dist/node_modules/.bun/invariant@2.2.4/node_modules/invariant/browser.js +28 -0
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_Hash.js +21 -0
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_ListCache.js +21 -0
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_Map.js +10 -0
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_MapCache.js +21 -0
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_Symbol.js +9 -0
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_assocIndexOf.js +14 -0
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_baseGetTag.js +15 -0
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_baseIsNative.js +16 -0
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_coreJsData.js +9 -0
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_freeGlobal.js +8 -0
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_getMapData.js +14 -0
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_getNative.js +15 -0
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_getRawTag.js +19 -0
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_getValue.js +11 -0
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_hashClear.js +13 -0
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_hashDelete.js +12 -0
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_hashGet.js +18 -0
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_hashHas.js +14 -0
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_hashSet.js +14 -0
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_isKeyable.js +12 -0
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_isMasked.js +16 -0
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_listCacheClear.js +11 -0
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_listCacheDelete.js +14 -0
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_listCacheGet.js +14 -0
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_listCacheHas.js +13 -0
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_listCacheSet.js +14 -0
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_mapCacheClear.js +19 -0
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_mapCacheDelete.js +14 -0
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_mapCacheGet.js +13 -0
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_mapCacheHas.js +13 -0
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_mapCacheSet.js +14 -0
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_nativeCreate.js +9 -0
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_objectToString.js +12 -0
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_root.js +10 -0
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_toSource.js +20 -0
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/eq.js +11 -0
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/isFunction.js +16 -0
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/isObject.js +12 -0
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/memoize.js +20 -0
- package/dist/node_modules/.bun/math-expression-evaluator@1.4.0/node_modules/math-expression-evaluator/src/formula_evaluator.js +37 -0
- package/dist/node_modules/.bun/math-expression-evaluator@1.4.0/node_modules/math-expression-evaluator/src/lexer.js +509 -0
- package/dist/node_modules/.bun/math-expression-evaluator@1.4.0/node_modules/math-expression-evaluator/src/math_function.js +108 -0
- package/dist/node_modules/.bun/math-expression-evaluator@1.4.0/node_modules/math-expression-evaluator/src/postfix.js +31 -0
- package/dist/node_modules/.bun/math-expression-evaluator@1.4.0/node_modules/math-expression-evaluator/src/postfix_evaluator.js +45 -0
- package/dist/node_modules/.bun/react-input-autosize@2.2.2_f4eacebf2041cd4f/node_modules/react-input-autosize/lib/AutosizeInput.js +216 -0
- package/dist/node_modules/.bun/react-is@16.13.1/node_modules/react-is/cjs/react-is.development.js +82 -0
- package/dist/node_modules/.bun/react-is@16.13.1/node_modules/react-is/cjs/react-is.production.min.js +62 -0
- package/dist/node_modules/.bun/react-is@16.13.1/node_modules/react-is/index.js +10 -0
- package/dist/node_modules/.bun/react-redux@6.0.1_926323a638b43722/node_modules/react-redux/es/components/Context.js +5 -0
- package/dist/node_modules/.bun/react-redux@6.0.1_926323a638b43722/node_modules/react-redux/es/components/Provider.js +47 -0
- package/dist/node_modules/.bun/react-redux@6.0.1_926323a638b43722/node_modules/react-redux/es/components/connectAdvanced.js +95 -0
- package/dist/node_modules/.bun/react-redux@6.0.1_926323a638b43722/node_modules/react-redux/es/connect/connect.js +52 -0
- package/dist/node_modules/.bun/react-redux@6.0.1_926323a638b43722/node_modules/react-redux/es/connect/mapDispatchToProps.js +23 -0
- package/dist/node_modules/.bun/react-redux@6.0.1_926323a638b43722/node_modules/react-redux/es/connect/mapStateToProps.js +13 -0
- package/dist/node_modules/.bun/react-redux@6.0.1_926323a638b43722/node_modules/react-redux/es/connect/mergeProps.js +26 -0
- package/dist/node_modules/.bun/react-redux@6.0.1_926323a638b43722/node_modules/react-redux/es/connect/selectorFactory.js +41 -0
- package/dist/node_modules/.bun/react-redux@6.0.1_926323a638b43722/node_modules/react-redux/es/connect/verifySubselectors.js +11 -0
- package/dist/node_modules/.bun/react-redux@6.0.1_926323a638b43722/node_modules/react-redux/es/connect/wrapMapToProps.js +28 -0
- package/dist/node_modules/.bun/react-redux@6.0.1_926323a638b43722/node_modules/react-redux/es/index.js +4 -0
- package/dist/node_modules/.bun/react-redux@6.0.1_926323a638b43722/node_modules/react-redux/es/utils/isPlainObject.js +10 -0
- package/dist/node_modules/.bun/react-redux@6.0.1_926323a638b43722/node_modules/react-redux/es/utils/shallowEqual.js +15 -0
- package/dist/node_modules/.bun/react-redux@6.0.1_926323a638b43722/node_modules/react-redux/es/utils/verifyPlainObject.js +8 -0
- package/dist/node_modules/.bun/react-redux@6.0.1_926323a638b43722/node_modules/react-redux/es/utils/warning.js +9 -0
- package/dist/node_modules/.bun/reduce-css-calc@1.3.0/node_modules/reduce-css-calc/index.js +49 -0
- package/dist/node_modules/.bun/reduce-function-call@1.0.3/node_modules/reduce-function-call/index.js +34 -0
- package/dist/node_modules/.bun/redux-undo@1.1.0/node_modules/redux-undo/dist/redux-undo.js +185 -0
- package/dist/node_modules/.bun/redux@4.2.1/node_modules/redux/es/redux.js +225 -0
- package/dist/toggle-bar.d.ts +41 -0
- package/dist/toggle-bar.d.ts.map +1 -0
- package/dist/tool-menu.d.ts +22 -0
- package/dist/tool-menu.d.ts.map +1 -0
- package/dist/tool-menu.js +188 -0
- package/dist/tools/index.d.ts +18 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +12 -0
- package/dist/tools/line/component.d.ts +92 -0
- package/dist/tools/line/component.d.ts.map +1 -0
- package/dist/tools/line/component.js +58 -0
- package/dist/tools/line/index.d.ts +14 -0
- package/dist/tools/line/index.d.ts.map +1 -0
- package/dist/tools/line/index.js +6 -0
- package/dist/tools/polygon/component.d.ts +115 -0
- package/dist/tools/polygon/component.d.ts.map +1 -0
- package/dist/tools/polygon/component.js +194 -0
- package/dist/tools/polygon/index.d.ts +20 -0
- package/dist/tools/polygon/index.d.ts.map +1 -0
- package/dist/tools/polygon/index.js +55 -0
- package/dist/tools/polygon/line.d.ts +105 -0
- package/dist/tools/polygon/line.d.ts.map +1 -0
- package/dist/tools/polygon/polygon.d.ts +102 -0
- package/dist/tools/polygon/polygon.d.ts.map +1 -0
- package/dist/tools/polygon/polygon.js +62 -0
- package/dist/tools/shared/arrow-head.d.ts +43 -0
- package/dist/tools/shared/arrow-head.d.ts.map +1 -0
- package/dist/tools/shared/arrow-head.js +37 -0
- package/dist/tools/shared/line/index.d.ts +165 -0
- package/dist/tools/shared/line/index.d.ts.map +1 -0
- package/dist/tools/shared/line/index.js +320 -0
- package/dist/tools/shared/line/line-path.d.ts +58 -0
- package/dist/tools/shared/line/line-path.d.ts.map +1 -0
- package/dist/tools/shared/line/with-root-edge.d.ts +89 -0
- package/dist/tools/shared/line/with-root-edge.d.ts.map +1 -0
- package/dist/tools/shared/point/arrow-point.d.ts +58 -0
- package/dist/tools/shared/point/arrow-point.d.ts.map +1 -0
- package/dist/tools/shared/point/arrow-point.js +47 -0
- package/dist/tools/shared/point/arrow.d.ts +47 -0
- package/dist/tools/shared/point/arrow.d.ts.map +1 -0
- package/dist/tools/shared/point/arrow.js +36 -0
- package/dist/tools/shared/point/base-point.d.ts +51 -0
- package/dist/tools/shared/point/base-point.d.ts.map +1 -0
- package/dist/tools/shared/point/base-point.js +88 -0
- package/dist/tools/shared/point/index.d.ts +154 -0
- package/dist/tools/shared/point/index.d.ts.map +1 -0
- package/dist/tools/shared/point/index.js +51 -0
- package/dist/tools/shared/styles.d.ts +25 -0
- package/dist/tools/shared/styles.d.ts.map +1 -0
- package/dist/tools/shared/styles.js +17 -0
- package/dist/tools/shared/types.d.ts +16 -0
- package/dist/tools/shared/types.d.ts.map +1 -0
- package/dist/tools/shared/types.js +10 -0
- package/dist/undo-redo.d.ts +21 -0
- package/dist/undo-redo.d.ts.map +1 -0
- package/dist/undo-redo.js +33 -0
- package/dist/use-debounce.d.ts +10 -0
- package/dist/use-debounce.d.ts.map +1 -0
- package/dist/use-debounce.js +13 -0
- package/dist/utils.d.ts +59 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +72 -0
- package/package.json +64 -0
- package/src/axis/arrow.tsx +67 -0
- package/src/axis/axes.tsx +321 -0
- package/src/axis/index.ts +13 -0
- package/src/bg.tsx +106 -0
- package/src/container/actions.ts +18 -0
- package/src/container/index.tsx +95 -0
- package/src/container/marks.ts +24 -0
- package/src/container/middleware.ts +17 -0
- package/src/container/reducer.ts +15 -0
- package/src/coordinates-label.tsx +72 -0
- package/src/graph-with-controls.tsx +252 -0
- package/src/graph.tsx +343 -0
- package/src/grid-setup.tsx +470 -0
- package/src/grid.tsx +143 -0
- package/src/index.ts +17 -0
- package/src/labels.tsx +211 -0
- package/src/mark-label.tsx +135 -0
- package/src/toggle-bar.tsx +231 -0
- package/src/tool-menu.tsx +245 -0
- package/src/tools/index.ts +18 -0
- package/src/tools/line/component.tsx +87 -0
- package/src/tools/line/index.ts +14 -0
- package/src/tools/polygon/component.tsx +334 -0
- package/src/tools/polygon/index.ts +62 -0
- package/src/tools/polygon/line.tsx +90 -0
- package/src/tools/polygon/polygon.tsx +103 -0
- package/src/tools/shared/arrow-head.tsx +56 -0
- package/src/tools/shared/line/index.tsx +481 -0
- package/src/tools/shared/line/line-path.tsx +95 -0
- package/src/tools/shared/line/with-root-edge.tsx +107 -0
- package/src/tools/shared/point/arrow-point.tsx +70 -0
- package/src/tools/shared/point/arrow.tsx +50 -0
- package/src/tools/shared/point/base-point.tsx +123 -0
- package/src/tools/shared/point/index.tsx +68 -0
- package/src/tools/shared/styles.ts +30 -0
- package/src/tools/shared/types.ts +18 -0
- package/src/undo-redo.tsx +47 -0
- package/src/use-debounce.ts +23 -0
- package/src/utils.ts +240 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* @synced-from pie-lib/packages/graphing-solution-set/src/tools/shared/point/arrow-point.jsx
|
|
4
|
+
* @auto-generated
|
|
5
|
+
*
|
|
6
|
+
* This file is automatically synced from pie-elements and converted to TypeScript.
|
|
7
|
+
* Manual edits will be overwritten on next sync.
|
|
8
|
+
* To make changes, edit the upstream JavaScript file and run sync again.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import React from 'react';
|
|
12
|
+
import PropTypes from 'prop-types';
|
|
13
|
+
import classNames from 'classnames';
|
|
14
|
+
import { types } from '@pie-lib/plot';
|
|
15
|
+
import { isEqual } from 'lodash-es';
|
|
16
|
+
import { arrowDimensions, getAngleDeg } from '../../../utils.js';
|
|
17
|
+
|
|
18
|
+
export class RawArrow extends React.Component {
|
|
19
|
+
static propTypes = {
|
|
20
|
+
classes: PropTypes.object,
|
|
21
|
+
className: PropTypes.string,
|
|
22
|
+
correctness: PropTypes.string,
|
|
23
|
+
disabled: PropTypes.bool,
|
|
24
|
+
x: PropTypes.number,
|
|
25
|
+
y: PropTypes.number,
|
|
26
|
+
from: PropTypes.shape({
|
|
27
|
+
x: PropTypes.number,
|
|
28
|
+
y: PropTypes.number,
|
|
29
|
+
}).isRequired,
|
|
30
|
+
to: PropTypes.shape({
|
|
31
|
+
x: PropTypes.number,
|
|
32
|
+
y: PropTypes.number,
|
|
33
|
+
}),
|
|
34
|
+
graphProps: types.GraphPropsType.isRequired,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
static defaultProps = {
|
|
38
|
+
from: {},
|
|
39
|
+
to: {},
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
render() {
|
|
43
|
+
const { classes, className, x, y, disabled, correctness, graphProps, from, to, ...rest } = this.props;
|
|
44
|
+
// x & y are the initial coordinates for the arrow
|
|
45
|
+
// from & to are used only to calculate the angle that the arrow should be rotated with
|
|
46
|
+
|
|
47
|
+
const { scale } = graphProps;
|
|
48
|
+
const angle = getAngleDeg(from.x, from.y, to.x, to.y);
|
|
49
|
+
|
|
50
|
+
let points = '';
|
|
51
|
+
|
|
52
|
+
if (isEqual(from, to)) {
|
|
53
|
+
points = '0,0 0,0 0,0';
|
|
54
|
+
} else {
|
|
55
|
+
points = `0,0 ${arrowDimensions.vector},${arrowDimensions.vector * 2}
|
|
56
|
+
-${arrowDimensions.vector},${arrowDimensions.vector * 2}`;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<g className={classNames(classes.point, disabled && classes.disabled, classes[correctness], className)} {...rest}>
|
|
61
|
+
<polygon
|
|
62
|
+
points={points}
|
|
63
|
+
transform={`
|
|
64
|
+
translate(${scale.x(x)}, ${scale.y(y)})
|
|
65
|
+
rotate(${angle} 0 0)`}
|
|
66
|
+
/>
|
|
67
|
+
</g>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* @synced-from pie-lib/packages/graphing-solution-set/src/tools/shared/point/arrow.jsx
|
|
4
|
+
* @auto-generated
|
|
5
|
+
*
|
|
6
|
+
* This file is automatically synced from pie-elements and converted to TypeScript.
|
|
7
|
+
* Manual edits will be overwritten on next sync.
|
|
8
|
+
* To make changes, edit the upstream JavaScript file and run sync again.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import React from 'react';
|
|
12
|
+
import PropTypes from 'prop-types';
|
|
13
|
+
import classNames from 'classnames';
|
|
14
|
+
import { types } from '@pie-lib/plot';
|
|
15
|
+
import { ArrowHead } from '../arrow-head.js';
|
|
16
|
+
import { thinnerShapesNeeded } from '../../../utils.js';
|
|
17
|
+
|
|
18
|
+
export default class Arrow extends React.Component {
|
|
19
|
+
static propTypes = {
|
|
20
|
+
classes: PropTypes.object,
|
|
21
|
+
className: PropTypes.string,
|
|
22
|
+
correctness: PropTypes.string,
|
|
23
|
+
disabled: PropTypes.bool,
|
|
24
|
+
x: PropTypes.number.isRequired,
|
|
25
|
+
y: PropTypes.number.isRequired,
|
|
26
|
+
angle: PropTypes.number.isRequired,
|
|
27
|
+
graphProps: types.GraphPropsType.isRequired,
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
render() {
|
|
31
|
+
const { classes, angle, className, x, y, disabled, correctness, graphProps, ...rest } = this.props;
|
|
32
|
+
|
|
33
|
+
const size = thinnerShapesNeeded(graphProps) ? 12 : 14;
|
|
34
|
+
const { scale } = graphProps;
|
|
35
|
+
|
|
36
|
+
const scaledX = scale.x(x);
|
|
37
|
+
const scaledY = scale.y(y);
|
|
38
|
+
|
|
39
|
+
const transform = `rotate(${-angle}, ${scaledX},${scaledY})`;
|
|
40
|
+
const points = `${scaledX},${scaledY}
|
|
41
|
+
${scaledX - size},${scaledY - size / 2}
|
|
42
|
+
${scaledX - size}, ${scaledY + size / 2}`;
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<g className={classNames(classes.point, disabled && classes.disabled, classes[correctness], className)} {...rest}>
|
|
46
|
+
<ArrowHead size={size} transform={transform} points={points} />
|
|
47
|
+
</g>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* @synced-from pie-lib/packages/graphing-solution-set/src/tools/shared/point/base-point.jsx
|
|
4
|
+
* @auto-generated
|
|
5
|
+
*
|
|
6
|
+
* This file is automatically synced from pie-elements and converted to TypeScript.
|
|
7
|
+
* Manual edits will be overwritten on next sync.
|
|
8
|
+
* To make changes, edit the upstream JavaScript file and run sync again.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import React from 'react';
|
|
12
|
+
import PropTypes from 'prop-types';
|
|
13
|
+
import { types } from '@pie-lib/plot';
|
|
14
|
+
import CoordinatesLabel from '../../../coordinates-label.js';
|
|
15
|
+
import ReactDOM from 'react-dom';
|
|
16
|
+
import { thinnerShapesNeeded } from '../../../utils.js';
|
|
17
|
+
import { color } from '@pie-lib/render-ui';
|
|
18
|
+
import { styled } from '@mui/material/styles';
|
|
19
|
+
import { correct, disabled as disabledStyle, incorrect, missing } from '../styles.js';
|
|
20
|
+
|
|
21
|
+
const StyledPointGroup: any = styled('g')(({ disabled, correctness }) => ({
|
|
22
|
+
cursor: 'pointer',
|
|
23
|
+
'& circle': {
|
|
24
|
+
fill: 'currentColor',
|
|
25
|
+
},
|
|
26
|
+
...(disabled && {
|
|
27
|
+
...disabledStyle('fill'),
|
|
28
|
+
...disabledStyle('color'),
|
|
29
|
+
}),
|
|
30
|
+
...(correctness === 'correct' && {
|
|
31
|
+
...correct('fill'),
|
|
32
|
+
...correct('color'),
|
|
33
|
+
}),
|
|
34
|
+
...(correctness === 'incorrect' && {
|
|
35
|
+
...incorrect('fill'),
|
|
36
|
+
...incorrect('color'),
|
|
37
|
+
}),
|
|
38
|
+
...(correctness === 'missing' && {
|
|
39
|
+
...missing('fill'),
|
|
40
|
+
...missing('color'),
|
|
41
|
+
}),
|
|
42
|
+
}));
|
|
43
|
+
|
|
44
|
+
export class RawBp extends React.Component {
|
|
45
|
+
static propTypes = {
|
|
46
|
+
className: PropTypes.string,
|
|
47
|
+
coordinatesOnHover: PropTypes.bool,
|
|
48
|
+
correctness: PropTypes.string,
|
|
49
|
+
disabled: PropTypes.bool,
|
|
50
|
+
labelNode: PropTypes.object,
|
|
51
|
+
x: PropTypes.number,
|
|
52
|
+
y: PropTypes.number,
|
|
53
|
+
graphProps: types.GraphPropsType.isRequired,
|
|
54
|
+
onClick: PropTypes.func,
|
|
55
|
+
onTouchStart: PropTypes.func,
|
|
56
|
+
onTouchEnd: PropTypes.func,
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
constructor(props) {
|
|
60
|
+
super(props);
|
|
61
|
+
this.state = { showCoordinates: false };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
render() {
|
|
65
|
+
const {
|
|
66
|
+
className,
|
|
67
|
+
coordinatesOnHover,
|
|
68
|
+
x,
|
|
69
|
+
y,
|
|
70
|
+
disabled,
|
|
71
|
+
correctness,
|
|
72
|
+
graphProps,
|
|
73
|
+
labelNode,
|
|
74
|
+
// we need to remove style from props
|
|
75
|
+
// eslint-disable-next-line no-unused-vars,react/prop-types
|
|
76
|
+
style,
|
|
77
|
+
onClick,
|
|
78
|
+
// Refactored RawBp component by isolating onTouchStart and onTouchEnd handlers to the outer circle, resolving erratic touch event behavior.
|
|
79
|
+
// Remaining props are now applied only to the inner circle for improved event handling consistency.
|
|
80
|
+
onTouchStart,
|
|
81
|
+
onTouchEnd,
|
|
82
|
+
...rest
|
|
83
|
+
} = this.props;
|
|
84
|
+
const { showCoordinates } = this.state;
|
|
85
|
+
const { scale } = graphProps;
|
|
86
|
+
const r = thinnerShapesNeeded(graphProps) ? 5 : 7;
|
|
87
|
+
|
|
88
|
+
return (
|
|
89
|
+
<>
|
|
90
|
+
<circle
|
|
91
|
+
style={{ fill: 'transparent', cursor: 'pointer', pointerEvents: 'all' }}
|
|
92
|
+
r={r * 3}
|
|
93
|
+
cx={scale.x(x)}
|
|
94
|
+
cy={scale.y(y)}
|
|
95
|
+
onMouseEnter={() => this.setState({ showCoordinates: true })}
|
|
96
|
+
onMouseLeave={() => this.setState({ showCoordinates: false })}
|
|
97
|
+
onTouchStart={onTouchStart}
|
|
98
|
+
onTouchEnd={onTouchEnd}
|
|
99
|
+
onClick={onClick}
|
|
100
|
+
/>
|
|
101
|
+
<StyledPointGroup
|
|
102
|
+
disabled={disabled}
|
|
103
|
+
correctness={correctness}
|
|
104
|
+
className={className}
|
|
105
|
+
onMouseEnter={() => this.setState({ showCoordinates: true })}
|
|
106
|
+
onMouseLeave={() => this.setState({ showCoordinates: false })}
|
|
107
|
+
>
|
|
108
|
+
<circle
|
|
109
|
+
{...rest}
|
|
110
|
+
style={{ fill: color.defaults.BLACK, cursor: 'pointer' }}
|
|
111
|
+
r={r}
|
|
112
|
+
cx={scale.x(x)}
|
|
113
|
+
cy={scale.y(y)}
|
|
114
|
+
/>
|
|
115
|
+
{labelNode &&
|
|
116
|
+
coordinatesOnHover &&
|
|
117
|
+
showCoordinates &&
|
|
118
|
+
ReactDOM.createPortal(<CoordinatesLabel graphProps={graphProps} x={x} y={y} />, labelNode)}
|
|
119
|
+
</StyledPointGroup>
|
|
120
|
+
</>
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* @synced-from pie-lib/packages/graphing-solution-set/src/tools/shared/point/index.jsx
|
|
4
|
+
* @auto-generated
|
|
5
|
+
*
|
|
6
|
+
* This file is automatically synced from pie-elements and converted to TypeScript.
|
|
7
|
+
* Manual edits will be overwritten on next sync.
|
|
8
|
+
* To make changes, edit the upstream JavaScript file and run sync again.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import React from 'react';
|
|
12
|
+
import PropTypes from 'prop-types';
|
|
13
|
+
import { styled } from '@mui/material/styles';
|
|
14
|
+
import { gridDraggable } from '@pie-lib/plot';
|
|
15
|
+
import * as utils from '../../../utils.js';
|
|
16
|
+
import { correct, disabled, incorrect, missing } from '../styles.js';
|
|
17
|
+
import { RawBp } from './base-point.js';
|
|
18
|
+
import { RawArrow } from './arrow-point.js';
|
|
19
|
+
import { color } from '@pie-lib/render-ui';
|
|
20
|
+
import BaseArrow from './arrow.js';
|
|
21
|
+
|
|
22
|
+
const opts = {
|
|
23
|
+
bounds: (props, { domain, range }) => {
|
|
24
|
+
const { x, y } = props;
|
|
25
|
+
const area = { left: x, top: y, bottom: y, right: x };
|
|
26
|
+
|
|
27
|
+
return utils.bounds(area, domain, range);
|
|
28
|
+
},
|
|
29
|
+
anchorPoint: (props) => {
|
|
30
|
+
const { x, y } = props;
|
|
31
|
+
|
|
32
|
+
return { x, y };
|
|
33
|
+
},
|
|
34
|
+
fromDelta: (props, delta) => {
|
|
35
|
+
return utils.point(props).add(utils.point(delta));
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const StyledPointWrapper: any = styled('g', {
|
|
40
|
+
shouldForwardProp: (prop) => !['disabled', 'correctness'].includes(prop),
|
|
41
|
+
})(({ disabled: isDisabled, correctness }) => ({
|
|
42
|
+
'& circle, & polygon': {
|
|
43
|
+
cursor: 'pointer',
|
|
44
|
+
fill: color.defaults.SECONDARY,
|
|
45
|
+
...(isDisabled && disabled()),
|
|
46
|
+
...(correctness === 'correct' && correct()),
|
|
47
|
+
...(correctness === 'incorrect' && incorrect()),
|
|
48
|
+
...(correctness === 'missing' && missing()),
|
|
49
|
+
},
|
|
50
|
+
}));
|
|
51
|
+
|
|
52
|
+
const withStyledWrapper = (WrappedComponent) => {
|
|
53
|
+
const WrappedComponentWithStyles = (props) => (
|
|
54
|
+
<StyledPointWrapper disabled={props.disabled} correctness={props.correctness}>
|
|
55
|
+
<WrappedComponent {...props} />
|
|
56
|
+
</StyledPointWrapper>
|
|
57
|
+
);
|
|
58
|
+
WrappedComponentWithStyles.displayName = `withStyledWrapper(${WrappedComponent.displayName || WrappedComponent.name || 'Component'})`;
|
|
59
|
+
WrappedComponentWithStyles.propTypes = {
|
|
60
|
+
disabled: PropTypes.bool,
|
|
61
|
+
correctness: PropTypes.string,
|
|
62
|
+
};
|
|
63
|
+
return WrappedComponentWithStyles;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export const BasePoint = gridDraggable(opts)(withStyledWrapper(RawBp));
|
|
67
|
+
export const ArrowPoint = gridDraggable(opts)(withStyledWrapper(RawArrow));
|
|
68
|
+
export const Arrow = gridDraggable(opts)(withStyledWrapper(BaseArrow));
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* @synced-from pie-lib/packages/graphing-solution-set/src/tools/shared/styles.js
|
|
4
|
+
* @auto-generated
|
|
5
|
+
*
|
|
6
|
+
* This file is automatically synced from pie-elements and converted to TypeScript.
|
|
7
|
+
* Manual edits will be overwritten on next sync.
|
|
8
|
+
* To make changes, edit the upstream JavaScript file and run sync again.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { color } from '@pie-lib/render-ui';
|
|
12
|
+
|
|
13
|
+
export const disabled = (key = 'fill') => ({
|
|
14
|
+
[key]: color.disabled(),
|
|
15
|
+
pointerEvents: 'none',
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
export const correct = (key = 'fill') => ({
|
|
19
|
+
[key]: color.correct(),
|
|
20
|
+
pointerEvents: 'none',
|
|
21
|
+
});
|
|
22
|
+
export const incorrect = (key = 'fill') => ({
|
|
23
|
+
[key]: color.incorrect(),
|
|
24
|
+
pointerEvents: 'none',
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
export const missing = (key = 'fill') => ({
|
|
28
|
+
[key]: color.missing(),
|
|
29
|
+
pointerEvents: 'none',
|
|
30
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* @synced-from pie-lib/packages/graphing-solution-set/src/tools/shared/types.js
|
|
4
|
+
* @auto-generated
|
|
5
|
+
*
|
|
6
|
+
* This file is automatically synced from pie-elements and converted to TypeScript.
|
|
7
|
+
* Manual edits will be overwritten on next sync.
|
|
8
|
+
* To make changes, edit the upstream JavaScript file and run sync again.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import PropTypes from 'prop-types';
|
|
12
|
+
|
|
13
|
+
export const ToolPropTypeFields = {
|
|
14
|
+
mark: PropTypes.any,
|
|
15
|
+
onChange: PropTypes.func,
|
|
16
|
+
onDragStart: PropTypes.func,
|
|
17
|
+
onDragStop: PropTypes.func,
|
|
18
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* @synced-from pie-lib/packages/graphing-solution-set/src/undo-redo.jsx
|
|
4
|
+
* @auto-generated
|
|
5
|
+
*
|
|
6
|
+
* This file is automatically synced from pie-elements and converted to TypeScript.
|
|
7
|
+
* Manual edits will be overwritten on next sync.
|
|
8
|
+
* To make changes, edit the upstream JavaScript file and run sync again.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import React from 'react';
|
|
12
|
+
import PropTypes from 'prop-types';
|
|
13
|
+
import { styled } from '@mui/material/styles';
|
|
14
|
+
import Button from '@mui/material/Button';
|
|
15
|
+
import { color } from '@pie-lib/render-ui';
|
|
16
|
+
import Translator from '@pie-lib/translator';
|
|
17
|
+
|
|
18
|
+
const { translator } = Translator;
|
|
19
|
+
|
|
20
|
+
const StyledButton: any = styled(Button)(({ theme }) => ({
|
|
21
|
+
color: color.text(),
|
|
22
|
+
fontWeight: 'bold',
|
|
23
|
+
marginBottom: theme.spacing(0.5),
|
|
24
|
+
'&:not(:last-of-type)': {
|
|
25
|
+
marginRight: theme.spacing(0.5),
|
|
26
|
+
},
|
|
27
|
+
}));
|
|
28
|
+
|
|
29
|
+
export class UndoRedo extends React.Component {
|
|
30
|
+
static propTypes = {
|
|
31
|
+
className: PropTypes.string,
|
|
32
|
+
onReset: PropTypes.func.isRequired,
|
|
33
|
+
language: PropTypes.string,
|
|
34
|
+
};
|
|
35
|
+
static defaultProps = {};
|
|
36
|
+
|
|
37
|
+
render() {
|
|
38
|
+
const { className, onReset = false, language } = this.props;
|
|
39
|
+
return (
|
|
40
|
+
<div className={className}>
|
|
41
|
+
<StyledButton onClick={() => onReset()}>{translator.t('graphing.reset', { lng: language })}</StyledButton>
|
|
42
|
+
</div>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export default UndoRedo;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* @synced-from pie-lib/packages/graphing-solution-set/src/use-debounce.js
|
|
4
|
+
* @auto-generated
|
|
5
|
+
*
|
|
6
|
+
* This file is automatically synced from pie-elements and converted to TypeScript.
|
|
7
|
+
* Manual edits will be overwritten on next sync.
|
|
8
|
+
* To make changes, edit the upstream JavaScript file and run sync again.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { useEffect, useState } from 'react';
|
|
12
|
+
|
|
13
|
+
export const useDebounce = (value, delay) => {
|
|
14
|
+
const [debouncedValue, setDebouncedValue] = useState(value);
|
|
15
|
+
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
const handler = setTimeout(() => {
|
|
18
|
+
setDebouncedValue(value);
|
|
19
|
+
}, delay);
|
|
20
|
+
return () => clearTimeout(handler);
|
|
21
|
+
}, [value]);
|
|
22
|
+
return debouncedValue;
|
|
23
|
+
};
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* @synced-from pie-lib/packages/graphing-solution-set/src/utils.js
|
|
4
|
+
* @auto-generated
|
|
5
|
+
*
|
|
6
|
+
* This file is automatically synced from pie-elements and converted to TypeScript.
|
|
7
|
+
* Manual edits will be overwritten on next sync.
|
|
8
|
+
* To make changes, edit the upstream JavaScript file and run sync again.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { cloneDeep, head, isEmpty, isEqual, tail } from 'lodash-es';
|
|
12
|
+
import { utils } from '@pie-lib/plot';
|
|
13
|
+
import invariant from 'invariant';
|
|
14
|
+
|
|
15
|
+
export const bounds = utils.bounds;
|
|
16
|
+
export const point = utils.point;
|
|
17
|
+
|
|
18
|
+
//TODO: This can be removed?
|
|
19
|
+
export const getAngleDeg = () => 0;
|
|
20
|
+
//TODO: This can be removed?
|
|
21
|
+
export const arrowDimensions = () => 0;
|
|
22
|
+
|
|
23
|
+
export const getTickValues = (prop) => {
|
|
24
|
+
const tickValues = [];
|
|
25
|
+
let tickVal = 0;
|
|
26
|
+
|
|
27
|
+
while (tickVal >= prop.min && tickValues.indexOf(tickVal) < 0) {
|
|
28
|
+
tickValues.push(tickVal);
|
|
29
|
+
tickVal = Math.round((tickVal - prop.step) * 10000) / 10000;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
tickVal = Math.round(prop.step * 10000) / 10000;
|
|
33
|
+
|
|
34
|
+
while (tickVal <= prop.max && tickValues.indexOf(tickVal) < 0) {
|
|
35
|
+
tickValues.push(tickVal);
|
|
36
|
+
tickVal = Math.round((tickVal + prop.step) * 10000) / 10000;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// return only ticks that are inside the min-max interval
|
|
40
|
+
if (tickValues) {
|
|
41
|
+
return tickValues.filter((tV) => tV >= prop.min && tV <= prop.max);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return [];
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export const countWords = (label) => {
|
|
48
|
+
if (label == null || isEmpty(label)) {
|
|
49
|
+
return 1;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const words = label.split(' ');
|
|
53
|
+
return words.length;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
// findLongestWord is also used in plot
|
|
57
|
+
export const findLongestWord = (label) => {
|
|
58
|
+
let longestWord = (label || '')
|
|
59
|
+
.replace(/<[^>]+>/g, '')
|
|
60
|
+
.split(' ')
|
|
61
|
+
.sort((a, b) => b.length - a.length);
|
|
62
|
+
|
|
63
|
+
return longestWord[0].length;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
// amountToIncreaseWidth is also used in plot
|
|
67
|
+
export const amountToIncreaseWidth = (longestWord) => {
|
|
68
|
+
if (!longestWord) {
|
|
69
|
+
return 0;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return longestWord * 10;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export const polygonToArea = (points) => {
|
|
76
|
+
const h = head(points);
|
|
77
|
+
const area = {
|
|
78
|
+
left: h.x,
|
|
79
|
+
top: h.y,
|
|
80
|
+
bottom: h.y,
|
|
81
|
+
right: h.x,
|
|
82
|
+
};
|
|
83
|
+
return tail(points).reduce((a, p) => {
|
|
84
|
+
a.left = Math.min(a.left, p.x);
|
|
85
|
+
a.top = Math.max(a.top, p.y);
|
|
86
|
+
a.bottom = Math.min(a.bottom, p.y);
|
|
87
|
+
a.right = Math.max(a.right, p.x);
|
|
88
|
+
return a;
|
|
89
|
+
}, area);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export const lineToArea = (from, to) => pointsToArea(from, to);
|
|
93
|
+
|
|
94
|
+
export const pointsToArea = (a, b) => {
|
|
95
|
+
invariant(!!a && !!b, 'a or b is undefined');
|
|
96
|
+
const left = Math.min(a.x, b.x);
|
|
97
|
+
const top = Math.max(a.y, b.y);
|
|
98
|
+
const bottom = Math.min(a.y, b.y);
|
|
99
|
+
const right = Math.max(a.x, b.x);
|
|
100
|
+
return { left, top, bottom, right };
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
export const getRightestPoints = (points) => {
|
|
104
|
+
const sortedPoints = cloneDeep(points);
|
|
105
|
+
sortedPoints.sort((a, b) => b.x - a.x);
|
|
106
|
+
|
|
107
|
+
return { a: sortedPoints[0], b: sortedPoints[1] };
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
export const getMiddleOfTwoPoints = (a, b) => ({
|
|
111
|
+
x: (a.x + b.x) / 2,
|
|
112
|
+
y: (a.y + b.y) / 2,
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
export const roundNumber = (number) => parseFloat(number.toFixed(4));
|
|
116
|
+
|
|
117
|
+
export const sameAxes = (p1, p2) =>
|
|
118
|
+
p1 && p2 && (roundNumber(p1.x) === roundNumber(p2.x) || roundNumber(p1.y) === roundNumber(p2.y));
|
|
119
|
+
|
|
120
|
+
export const equalPoints = (p1, p2) =>
|
|
121
|
+
p1 &&
|
|
122
|
+
p2 &&
|
|
123
|
+
isEqual(
|
|
124
|
+
{
|
|
125
|
+
x: roundNumber(p1.x),
|
|
126
|
+
y: roundNumber(p1.y),
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
x: roundNumber(p2.x),
|
|
130
|
+
y: roundNumber(p2.y),
|
|
131
|
+
},
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
const getDistanceBetweenTicks = (axis, size) => {
|
|
135
|
+
const { min, max, step } = axis;
|
|
136
|
+
const nbOfTicks = (max - min) / step;
|
|
137
|
+
|
|
138
|
+
return size / nbOfTicks;
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
export const thinnerShapesNeeded = (graphProps) => {
|
|
142
|
+
const {
|
|
143
|
+
domain,
|
|
144
|
+
range,
|
|
145
|
+
size: { width, height },
|
|
146
|
+
} = graphProps;
|
|
147
|
+
|
|
148
|
+
// 14 is the default width of a point
|
|
149
|
+
return getDistanceBetweenTicks(domain, width) < 14 || getDistanceBetweenTicks(range, height) < 14;
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
export const getAdjustedGraphLimits = (graphProps) => {
|
|
153
|
+
const {
|
|
154
|
+
domain,
|
|
155
|
+
range,
|
|
156
|
+
size: { width, height },
|
|
157
|
+
} = graphProps;
|
|
158
|
+
const domainTicksDistance = getDistanceBetweenTicks(domain, width);
|
|
159
|
+
const rangeTicksDistance = getDistanceBetweenTicks(range, height);
|
|
160
|
+
|
|
161
|
+
// 15 is the distance required for the arrow to extend the graph
|
|
162
|
+
const domainPadding = domain.step / (domainTicksDistance / 15);
|
|
163
|
+
const rangePadding = range.step / (rangeTicksDistance / 15);
|
|
164
|
+
|
|
165
|
+
return {
|
|
166
|
+
domain: {
|
|
167
|
+
min: domain.min - domainPadding,
|
|
168
|
+
max: domain.max + domainPadding,
|
|
169
|
+
},
|
|
170
|
+
range: {
|
|
171
|
+
min: range.min - rangePadding,
|
|
172
|
+
max: range.max + rangePadding,
|
|
173
|
+
},
|
|
174
|
+
};
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
const sortPoints = (array) => (array || []).sort((a, b) => a.x - b.x || a.y - b.y);
|
|
178
|
+
|
|
179
|
+
// check colliniarity of 3 points (source: https://www.geeksforgeeks.org/program-check-three-points-collinear/)
|
|
180
|
+
const checkCollinearity = (a, b, c) => (a.x - b.x) * (c.y - b.y) === (c.x - b.x) * (a.y - b.y);
|
|
181
|
+
|
|
182
|
+
// 2 lines are overlapping if all 4 points are collinear
|
|
183
|
+
const isSameLine = (markA, markB) =>
|
|
184
|
+
checkCollinearity(markA.from, markB.from, markB.to) && checkCollinearity(markA.to, markB.from, markB.to);
|
|
185
|
+
|
|
186
|
+
export const isDuplicatedMark = (mark, marks, oldMark) => {
|
|
187
|
+
const { type, building } = mark;
|
|
188
|
+
|
|
189
|
+
if (building) {
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const filteredMarks = (marks || []).filter((m) => m.type === type && !m.building);
|
|
194
|
+
const index = filteredMarks.findIndex((m) => isEqual(m, oldMark));
|
|
195
|
+
|
|
196
|
+
if (index !== -1) {
|
|
197
|
+
filteredMarks.splice(index, 1);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const duplicated = filteredMarks.find((m) => {
|
|
201
|
+
if (type === 'line') {
|
|
202
|
+
const { from, to } = mark;
|
|
203
|
+
return (
|
|
204
|
+
(equalPoints(from, m.from) && equalPoints(to, m.to)) ||
|
|
205
|
+
(equalPoints(from, m.to) && equalPoints(to, m.from)) ||
|
|
206
|
+
(type === 'line' && isSameLine(m, mark))
|
|
207
|
+
);
|
|
208
|
+
} else if (type === 'polygon') {
|
|
209
|
+
return isEqual(sortPoints(cloneDeep(mark.points)), sortPoints(cloneDeep(m.points)));
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
return !!duplicated;
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
export const areArraysOfObjectsEqual = (array1, array2) => {
|
|
217
|
+
// Check if both arrays have the same length
|
|
218
|
+
if (array1.length !== array2.length) {
|
|
219
|
+
return false;
|
|
220
|
+
}
|
|
221
|
+
// Iterate through each object in the arrays
|
|
222
|
+
for (let i = 0; i < array1.length; i++) {
|
|
223
|
+
// Get the current objects in both arrays
|
|
224
|
+
const obj1 = array1[i];
|
|
225
|
+
const obj2 = array2[i];
|
|
226
|
+
// Check if the objects have the same number of properties
|
|
227
|
+
if (Object.keys(obj1).length !== Object.keys(obj2).length) {
|
|
228
|
+
return false;
|
|
229
|
+
}
|
|
230
|
+
// Iterate through each property in the objects
|
|
231
|
+
for (const key in obj1) {
|
|
232
|
+
// Check if the properties and their values are equal
|
|
233
|
+
if (obj1[key] !== obj2[key]) {
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
// If all objects are equal, the arrays are the same
|
|
239
|
+
return true;
|
|
240
|
+
};
|