@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,481 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* @synced-from pie-lib/packages/graphing-solution-set/src/tools/shared/line/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 { cloneDeep, isEmpty, isEqual } from 'lodash-es';
|
|
13
|
+
import { BasePoint } from '../point/index.js';
|
|
14
|
+
import { gridDraggable, trig, types, utils } from '@pie-lib/plot';
|
|
15
|
+
import PropTypes from 'prop-types';
|
|
16
|
+
import { correct, disabled, incorrect, missing } from '../styles.js';
|
|
17
|
+
import ReactDOM from 'react-dom';
|
|
18
|
+
import MarkLabel from '../../../mark-label.js';
|
|
19
|
+
import { color } from '@pie-lib/render-ui';
|
|
20
|
+
import { equalPoints, getMiddleOfTwoPoints, sameAxes } from '../../../utils.js';
|
|
21
|
+
|
|
22
|
+
export const lineTool = (type, Component) => () => ({
|
|
23
|
+
type,
|
|
24
|
+
Component,
|
|
25
|
+
addPoint: (point, mark) => {
|
|
26
|
+
if (mark && equalPoints(mark.root, point)) {
|
|
27
|
+
return mark;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (!mark) {
|
|
31
|
+
return {
|
|
32
|
+
type,
|
|
33
|
+
building: true,
|
|
34
|
+
from: point,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (equalPoints(point, mark.from)) {
|
|
39
|
+
return { ...mark };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return { ...mark, building: false, to: point };
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
export const lineToolComponent = (Component) => {
|
|
47
|
+
return class LineToolComponent extends React.Component {
|
|
48
|
+
static propTypes = {
|
|
49
|
+
...types.ToolPropTypeFields,
|
|
50
|
+
graphProps: types.GraphPropsType.isRequired,
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
constructor(props) {
|
|
54
|
+
super(props);
|
|
55
|
+
this.state = {};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
startDrag = () => this.setState({ mark: { ...this.props.mark } });
|
|
59
|
+
|
|
60
|
+
stopDrag: any = () => {
|
|
61
|
+
const { onChange, mark } = this.props;
|
|
62
|
+
const update = { ...this.state.mark };
|
|
63
|
+
|
|
64
|
+
this.setState({ mark: undefined }, () => {
|
|
65
|
+
const { type } = update;
|
|
66
|
+
let shouldNotChange =
|
|
67
|
+
type &&
|
|
68
|
+
(type === 'parabola' || type === 'sine' || type === 'absolute' || type === 'exponential') &&
|
|
69
|
+
sameAxes(update.from, update.to);
|
|
70
|
+
if (!shouldNotChange && type && type === 'exponential' && update.from && update.to) {
|
|
71
|
+
shouldNotChange = update.from.y === 0 || update.to.y === 0 || update.from.y * update.to.y < 0;
|
|
72
|
+
}
|
|
73
|
+
if (!isEqual(mark, update) && !shouldNotChange) {
|
|
74
|
+
onChange(mark, update);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
changeMark: any = ({ from, to, middle }) => {
|
|
80
|
+
let mark = { ...this.state.mark, from, to };
|
|
81
|
+
|
|
82
|
+
if (middle) {
|
|
83
|
+
mark = { ...mark, middle };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
this.setState({ mark });
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
changeMarkProps: any = ({ from, to, middle }) => {
|
|
90
|
+
const { onChange, mark } = this.props;
|
|
91
|
+
let update = { ...mark, ...this.state.mark };
|
|
92
|
+
|
|
93
|
+
if (from) {
|
|
94
|
+
update = { ...update, from };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (to) {
|
|
98
|
+
update = { ...update, to };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (middle) {
|
|
102
|
+
update = { ...update, middle };
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (!isEqual(mark, update)) {
|
|
106
|
+
onChange(mark, update);
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
render() {
|
|
111
|
+
const { graphProps, onClick, labelNode, labelModeEnabled, coordinatesOnHover, gssLineData } = this.props;
|
|
112
|
+
const mark = this.state.mark ? this.state.mark : this.props.mark;
|
|
113
|
+
|
|
114
|
+
const from = cloneDeep(mark.from);
|
|
115
|
+
const to = cloneDeep(mark.to);
|
|
116
|
+
const middle = cloneDeep(mark.middle);
|
|
117
|
+
|
|
118
|
+
// SET DISABLED
|
|
119
|
+
// if it's a background mark, we need to force disable it
|
|
120
|
+
if (from && mark.isBackground) {
|
|
121
|
+
from.disabled = true;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (to && mark.isBackground) {
|
|
125
|
+
to.disabled = true;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (middle && mark.isBackground) {
|
|
129
|
+
middle.disabled = true;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return (
|
|
133
|
+
<Component
|
|
134
|
+
disabled={mark.disabled}
|
|
135
|
+
coordinatesOnHover={coordinatesOnHover}
|
|
136
|
+
correctness={mark.correctness}
|
|
137
|
+
from={from}
|
|
138
|
+
to={to}
|
|
139
|
+
middle={middle}
|
|
140
|
+
graphProps={graphProps}
|
|
141
|
+
fill={mark && mark.fill}
|
|
142
|
+
gssLineData={gssLineData}
|
|
143
|
+
onChange={this.changeMark}
|
|
144
|
+
changeMarkProps={this.changeMarkProps}
|
|
145
|
+
onClick={onClick}
|
|
146
|
+
onDragStart={this.startDrag}
|
|
147
|
+
onDragStop={this.stopDrag}
|
|
148
|
+
labelNode={labelNode}
|
|
149
|
+
labelModeEnabled={labelModeEnabled}
|
|
150
|
+
/>
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
const dragOpts = () => ({
|
|
157
|
+
bounds: (props, { domain, range }) => {
|
|
158
|
+
const area = utils.lineToArea(props.from, props.to);
|
|
159
|
+
return utils.bounds(area, domain, range);
|
|
160
|
+
},
|
|
161
|
+
anchorPoint: (props) => {
|
|
162
|
+
const { from } = props;
|
|
163
|
+
return from;
|
|
164
|
+
},
|
|
165
|
+
fromDelta: (props, delta) => {
|
|
166
|
+
const { from, to } = props;
|
|
167
|
+
return {
|
|
168
|
+
from: utils.point(from).add(utils.point(delta)),
|
|
169
|
+
to: utils.point(to).add(utils.point(delta)),
|
|
170
|
+
};
|
|
171
|
+
},
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
export const lineBase = (Comp, opts) => {
|
|
175
|
+
const DraggableComp = gridDraggable(dragOpts())(Comp);
|
|
176
|
+
|
|
177
|
+
const FromPoint = opts && opts.from ? opts.from : BasePoint;
|
|
178
|
+
const ToPoint = opts && opts.to ? opts.to : BasePoint;
|
|
179
|
+
|
|
180
|
+
class LineBase extends React.Component {
|
|
181
|
+
static propTypes = {
|
|
182
|
+
coordinatesOnHover: PropTypes.bool,
|
|
183
|
+
graphProps: types.GraphPropsType,
|
|
184
|
+
from: types.PointType,
|
|
185
|
+
to: types.PointType,
|
|
186
|
+
middle: types.PointType,
|
|
187
|
+
onChange: PropTypes.func,
|
|
188
|
+
onDragStart: PropTypes.func,
|
|
189
|
+
onDragStop: PropTypes.func,
|
|
190
|
+
onClick: PropTypes.func,
|
|
191
|
+
correctness: PropTypes.string,
|
|
192
|
+
fill: PropTypes.string,
|
|
193
|
+
gssLineData: PropTypes.object,
|
|
194
|
+
disabled: PropTypes.bool,
|
|
195
|
+
labelNode: PropTypes.object,
|
|
196
|
+
labelModeEnabled: PropTypes.bool,
|
|
197
|
+
changeMarkProps: PropTypes.func,
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
onChangePoint: any = (point) => {
|
|
201
|
+
const { middle, onChange } = this.props;
|
|
202
|
+
const { from, to } = point;
|
|
203
|
+
|
|
204
|
+
// because point.from.label and point.to.label can be different
|
|
205
|
+
if (!equalPoints(from, to)) {
|
|
206
|
+
if (middle) {
|
|
207
|
+
point.middle = { ...middle, ...getMiddleOfTwoPoints(from, to) };
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
onChange(point);
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
dragComp = ({ from: draggedFrom, to: draggedTo }) => {
|
|
215
|
+
const { from, to, onChange, middle } = this.props;
|
|
216
|
+
|
|
217
|
+
if (from.label) {
|
|
218
|
+
draggedFrom.label = from.label;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (to.label) {
|
|
222
|
+
draggedTo.label = to.label;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const updated = { from: draggedFrom, to: draggedTo };
|
|
226
|
+
|
|
227
|
+
if (middle) {
|
|
228
|
+
updated.middle = { ...middle, ...getMiddleOfTwoPoints(draggedFrom, draggedTo) };
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
onChange(updated);
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
dragFrom: any = (draggedFrom) => {
|
|
235
|
+
const { from, to } = this.props;
|
|
236
|
+
|
|
237
|
+
if (from.label) {
|
|
238
|
+
draggedFrom.label = from.label;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
if (!equalPoints(draggedFrom, to)) {
|
|
242
|
+
this.onChangePoint({ from: draggedFrom, to: to });
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
dragTo: any = (draggedTo) => {
|
|
247
|
+
const { from, to } = this.props;
|
|
248
|
+
|
|
249
|
+
if (to.label) {
|
|
250
|
+
draggedTo.label = to.label;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
if (!equalPoints(from, draggedTo)) {
|
|
254
|
+
this.onChangePoint({ from: from, to: draggedTo });
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
labelChange: any = (point, type) => {
|
|
259
|
+
const { changeMarkProps } = this.props;
|
|
260
|
+
const update = { ...point };
|
|
261
|
+
|
|
262
|
+
if (!point.label || isEmpty(point.label)) {
|
|
263
|
+
delete update.label;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
changeMarkProps({ [type]: update });
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
clickPoint: any = (point, type, data) => {
|
|
270
|
+
const { changeMarkProps, disabled, from, to, labelModeEnabled, onClick } = this.props;
|
|
271
|
+
|
|
272
|
+
if (!labelModeEnabled) {
|
|
273
|
+
onClick(point || data);
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
if (disabled) {
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
if (type === 'middle' && !point && from && to) {
|
|
282
|
+
point = { ...point, ...getMiddleOfTwoPoints(from, to) };
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
changeMarkProps({ from, to, [type]: { label: '', ...point } });
|
|
286
|
+
|
|
287
|
+
if (this.input[type]) {
|
|
288
|
+
this.input[type].focus();
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
// IMPORTANT, do not remove
|
|
293
|
+
input = {};
|
|
294
|
+
|
|
295
|
+
render() {
|
|
296
|
+
const {
|
|
297
|
+
coordinatesOnHover,
|
|
298
|
+
graphProps,
|
|
299
|
+
fill,
|
|
300
|
+
gssLineData,
|
|
301
|
+
onDragStart,
|
|
302
|
+
onDragStop,
|
|
303
|
+
from,
|
|
304
|
+
to,
|
|
305
|
+
middle,
|
|
306
|
+
disabled,
|
|
307
|
+
correctness,
|
|
308
|
+
onClick,
|
|
309
|
+
labelNode,
|
|
310
|
+
labelModeEnabled,
|
|
311
|
+
} = this.props;
|
|
312
|
+
let common = { graphProps, fill, onDragStart, onDragStop, disabled, correctness, onClick };
|
|
313
|
+
if (gssLineData && gssLineData.selectedTool === 'solutionSet') {
|
|
314
|
+
//removing dragging option for line if solution set is clicked.
|
|
315
|
+
common = { graphProps, fill, disabled, correctness, onClick };
|
|
316
|
+
}
|
|
317
|
+
const angle = to ? trig.toDegrees(trig.angle(from, to)) : 0;
|
|
318
|
+
|
|
319
|
+
let fromLabelNode = null;
|
|
320
|
+
let toLabelNode = null;
|
|
321
|
+
let lineLabelNode = null;
|
|
322
|
+
|
|
323
|
+
if (labelNode) {
|
|
324
|
+
if (from && Object.prototype.hasOwnProperty.call(from, 'label')) {
|
|
325
|
+
fromLabelNode = ReactDOM.createPortal(
|
|
326
|
+
<MarkLabel
|
|
327
|
+
inputRef={(r) => (this.input.from = r)}
|
|
328
|
+
disabled={!labelModeEnabled}
|
|
329
|
+
mark={from}
|
|
330
|
+
graphProps={graphProps}
|
|
331
|
+
onChange={(label) => this.labelChange({ ...from, label }, 'from')}
|
|
332
|
+
/>,
|
|
333
|
+
labelNode,
|
|
334
|
+
);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
if (to && Object.prototype.hasOwnProperty.call(to, 'label')) {
|
|
338
|
+
toLabelNode = ReactDOM.createPortal(
|
|
339
|
+
<MarkLabel
|
|
340
|
+
inputRef={(r) => (this.input.to = r)}
|
|
341
|
+
disabled={!labelModeEnabled}
|
|
342
|
+
mark={to}
|
|
343
|
+
graphProps={graphProps}
|
|
344
|
+
onChange={(label) => this.labelChange({ ...to, label }, 'to')}
|
|
345
|
+
/>,
|
|
346
|
+
labelNode,
|
|
347
|
+
);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
if (middle && Object.prototype.hasOwnProperty.call(middle, 'label')) {
|
|
351
|
+
lineLabelNode = ReactDOM.createPortal(
|
|
352
|
+
<MarkLabel
|
|
353
|
+
inputRef={(r) => (this.input.middle = r)}
|
|
354
|
+
disabled={!labelModeEnabled}
|
|
355
|
+
mark={middle}
|
|
356
|
+
graphProps={graphProps}
|
|
357
|
+
onChange={(label) => this.labelChange({ ...middle, label }, 'middle')}
|
|
358
|
+
/>,
|
|
359
|
+
labelNode,
|
|
360
|
+
);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
if (gssLineData && gssLineData.selectedTool === 'solutionSet') {
|
|
364
|
+
//removing dragging feature of line and point if solution set is true.
|
|
365
|
+
return (
|
|
366
|
+
<g>
|
|
367
|
+
{to && <DraggableComp from={from} to={to} middle={middle} {...common} />}
|
|
368
|
+
{lineLabelNode}
|
|
369
|
+
|
|
370
|
+
<FromPoint
|
|
371
|
+
x={from.x}
|
|
372
|
+
y={from.y}
|
|
373
|
+
labelNode={labelNode}
|
|
374
|
+
coordinatesOnHover={coordinatesOnHover}
|
|
375
|
+
{...common}
|
|
376
|
+
/>
|
|
377
|
+
{fromLabelNode}
|
|
378
|
+
|
|
379
|
+
{to && (
|
|
380
|
+
<ToPoint
|
|
381
|
+
x={to.x}
|
|
382
|
+
y={to.y}
|
|
383
|
+
angle={angle} //angle + 45}
|
|
384
|
+
labelNode={labelNode}
|
|
385
|
+
coordinatesOnHover={coordinatesOnHover}
|
|
386
|
+
{...common}
|
|
387
|
+
/>
|
|
388
|
+
)}
|
|
389
|
+
{toLabelNode}
|
|
390
|
+
</g>
|
|
391
|
+
);
|
|
392
|
+
} else {
|
|
393
|
+
return (
|
|
394
|
+
<g>
|
|
395
|
+
{to && (
|
|
396
|
+
<DraggableComp
|
|
397
|
+
from={from}
|
|
398
|
+
to={to}
|
|
399
|
+
middle={middle}
|
|
400
|
+
onDrag={this.dragComp}
|
|
401
|
+
{...common}
|
|
402
|
+
onClick={(data) => this.clickPoint(middle, 'middle', data)}
|
|
403
|
+
/>
|
|
404
|
+
)}
|
|
405
|
+
{lineLabelNode}
|
|
406
|
+
|
|
407
|
+
<FromPoint
|
|
408
|
+
x={from.x}
|
|
409
|
+
y={from.y}
|
|
410
|
+
labelNode={labelNode}
|
|
411
|
+
coordinatesOnHover={coordinatesOnHover}
|
|
412
|
+
onDrag={this.dragFrom}
|
|
413
|
+
{...common}
|
|
414
|
+
onClick={(data) => this.clickPoint(from, 'from', data)}
|
|
415
|
+
/>
|
|
416
|
+
{fromLabelNode}
|
|
417
|
+
|
|
418
|
+
{to && (
|
|
419
|
+
<ToPoint
|
|
420
|
+
x={to.x}
|
|
421
|
+
y={to.y}
|
|
422
|
+
angle={angle} //angle + 45}
|
|
423
|
+
labelNode={labelNode}
|
|
424
|
+
coordinatesOnHover={coordinatesOnHover}
|
|
425
|
+
onDrag={this.dragTo}
|
|
426
|
+
{...common}
|
|
427
|
+
onClick={(data) => this.clickPoint(to, 'to', data)}
|
|
428
|
+
/>
|
|
429
|
+
)}
|
|
430
|
+
{toLabelNode}
|
|
431
|
+
</g>
|
|
432
|
+
);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
return LineBase;
|
|
438
|
+
};
|
|
439
|
+
|
|
440
|
+
export const styles = {
|
|
441
|
+
line: () => ({
|
|
442
|
+
fill: 'transparent',
|
|
443
|
+
stroke: color.defaults.BLACK,
|
|
444
|
+
strokeWidth: 4,
|
|
445
|
+
transition: 'stroke 200ms ease-in, stroke-width 200ms ease-in',
|
|
446
|
+
'&:hover': {
|
|
447
|
+
strokeWidth: 6,
|
|
448
|
+
stroke: color.defaults.BLACK,
|
|
449
|
+
},
|
|
450
|
+
}),
|
|
451
|
+
dashedLine: () => ({
|
|
452
|
+
fill: 'transparent',
|
|
453
|
+
stroke: color.defaults.BLACK,
|
|
454
|
+
strokeWidth: 4,
|
|
455
|
+
transition: 'stroke 200ms ease-in, stroke-width 200ms ease-in',
|
|
456
|
+
'&:hover': {
|
|
457
|
+
strokeWidth: 6,
|
|
458
|
+
stroke: color.defaults.BLACK,
|
|
459
|
+
},
|
|
460
|
+
strokeDasharray: '3,3',
|
|
461
|
+
}),
|
|
462
|
+
arrow: () => ({
|
|
463
|
+
fill: color.defaults.SECONDARY,
|
|
464
|
+
}),
|
|
465
|
+
disabledArrow: () => ({
|
|
466
|
+
...disabled(),
|
|
467
|
+
}),
|
|
468
|
+
disabled: () => ({
|
|
469
|
+
...disabled('stroke'),
|
|
470
|
+
strokeWidth: 2,
|
|
471
|
+
}),
|
|
472
|
+
correct: (theme, key) => ({
|
|
473
|
+
...correct(key),
|
|
474
|
+
}),
|
|
475
|
+
incorrect: (theme, key) => ({
|
|
476
|
+
...incorrect(key),
|
|
477
|
+
}),
|
|
478
|
+
missing: (theme, key) => ({
|
|
479
|
+
...missing(key),
|
|
480
|
+
}),
|
|
481
|
+
};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* @synced-from pie-lib/packages/graphing-solution-set/src/tools/shared/line/line-path.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 { types } from '@pie-lib/plot';
|
|
15
|
+
import { correct, disabled, incorrect, missing } from '../styles.js';
|
|
16
|
+
import * as vx from '@visx/shape';
|
|
17
|
+
import { color } from '@pie-lib/render-ui';
|
|
18
|
+
|
|
19
|
+
const dragging = () => ({
|
|
20
|
+
strokeWidth: 7,
|
|
21
|
+
stroke: color.defaults.BLACK,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const StyledDrawLine: any = styled(vx.LinePath, {
|
|
25
|
+
shouldForwardProp: (prop) => !['disabled', 'correctness'].includes(prop),
|
|
26
|
+
})(({ disabled: isDisabled, correctness }) => ({
|
|
27
|
+
fill: 'none',
|
|
28
|
+
strokeWidth: 2,
|
|
29
|
+
stroke: color.secondaryLight(),
|
|
30
|
+
...(isDisabled && {
|
|
31
|
+
...disabled('stroke'),
|
|
32
|
+
strokeWidth: 2,
|
|
33
|
+
}),
|
|
34
|
+
...(correctness === 'correct' && correct('stroke')),
|
|
35
|
+
...(correctness === 'incorrect' && incorrect('stroke')),
|
|
36
|
+
...(correctness === 'missing' && missing('stroke')),
|
|
37
|
+
}));
|
|
38
|
+
|
|
39
|
+
const StyledInteractionLine: any = styled(vx.LinePath, {
|
|
40
|
+
shouldForwardProp: (prop) => !['disabled', 'correctness', 'isDragging'].includes(prop),
|
|
41
|
+
})(({ disabled: isDisabled, correctness, isDragging }) => ({
|
|
42
|
+
strokeWidth: 6,
|
|
43
|
+
fill: 'none',
|
|
44
|
+
transition: 'stroke-width 200ms ease-in, stroke 200ms ease-in',
|
|
45
|
+
stroke: 'transparent',
|
|
46
|
+
'&:hover': dragging(),
|
|
47
|
+
...(isDragging && dragging()),
|
|
48
|
+
...(isDisabled && {
|
|
49
|
+
...disabled('stroke'),
|
|
50
|
+
strokeWidth: 2,
|
|
51
|
+
}),
|
|
52
|
+
...(correctness === 'correct' && correct('stroke')),
|
|
53
|
+
...(correctness === 'incorrect' && incorrect('stroke')),
|
|
54
|
+
...(correctness === 'missing' && missing('stroke')),
|
|
55
|
+
}));
|
|
56
|
+
|
|
57
|
+
export class RawLinePath extends React.Component {
|
|
58
|
+
static propTypes = {
|
|
59
|
+
className: PropTypes.string,
|
|
60
|
+
data: PropTypes.arrayOf(PropTypes.arrayOf(PropTypes.number)),
|
|
61
|
+
graphProps: types.GraphPropsType.isRequired,
|
|
62
|
+
disabled: PropTypes.bool,
|
|
63
|
+
correctness: PropTypes.string,
|
|
64
|
+
from: types.PointType,
|
|
65
|
+
to: types.PointType,
|
|
66
|
+
isDragging: PropTypes.bool,
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
static defaultProps = {
|
|
70
|
+
from: {},
|
|
71
|
+
to: {},
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
render() {
|
|
75
|
+
/* eslint-disable no-unused-vars */
|
|
76
|
+
const { data, className, disabled, correctness, from, to, graphProps, isDragging, ...rest } = this.props;
|
|
77
|
+
/* eslint-enable */
|
|
78
|
+
|
|
79
|
+
return (
|
|
80
|
+
<React.Fragment>
|
|
81
|
+
<StyledDrawLine data={data} disabled={disabled} correctness={correctness} className={className} {...rest} />
|
|
82
|
+
<StyledInteractionLine
|
|
83
|
+
data={data}
|
|
84
|
+
isDragging={isDragging}
|
|
85
|
+
disabled={disabled}
|
|
86
|
+
correctness={correctness}
|
|
87
|
+
className={className}
|
|
88
|
+
{...rest}
|
|
89
|
+
/>
|
|
90
|
+
</React.Fragment>
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export const LinePath = RawLinePath;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* @synced-from pie-lib/packages/graphing-solution-set/src/tools/shared/line/with-root-edge.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 { LinePath } from './line-path.js';
|
|
15
|
+
import { curveMonotoneX } from '@visx/curve';
|
|
16
|
+
import { lineBase, lineToolComponent } from './index.js';
|
|
17
|
+
|
|
18
|
+
const toRootEdge = (m) => {
|
|
19
|
+
const out = { ...m };
|
|
20
|
+
out.root = { ...m.from };
|
|
21
|
+
out.edge = m.to ? { ...m.to } : undefined;
|
|
22
|
+
delete out.from;
|
|
23
|
+
delete out.to;
|
|
24
|
+
return out;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const toFromTo = (m) => {
|
|
28
|
+
const out = { ...m };
|
|
29
|
+
out.from = { ...m.root };
|
|
30
|
+
out.to = m.edge ? { ...m.edge } : undefined;
|
|
31
|
+
delete out.root;
|
|
32
|
+
delete out.edge;
|
|
33
|
+
return out;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const rootEdgeToFromToWrapper = (BaseComp) => {
|
|
37
|
+
const Wrapper = (props) => {
|
|
38
|
+
const m = toFromTo(props.mark);
|
|
39
|
+
|
|
40
|
+
const onChange = (current, next) => {
|
|
41
|
+
props.onChange(toRootEdge(current), toRootEdge(next));
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
return <BaseComp {...props} mark={m} onChange={onChange} />;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
Wrapper.propTypes = {
|
|
48
|
+
onChange: PropTypes.func,
|
|
49
|
+
mark: PropTypes.object,
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
return Wrapper;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export const rootEdgeComponent = (RootEdgeComp) => {
|
|
56
|
+
const BaseComponent = lineToolComponent(RootEdgeComp);
|
|
57
|
+
return rootEdgeToFromToWrapper(BaseComponent);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const withPointsGenerationLinePath = (getPoints) => {
|
|
61
|
+
const LinePathComponent = (props) => {
|
|
62
|
+
const { graphProps, from, to, onClick, onDragStart, onDragStop, onChange, disabled, correctness, ...rest } = props;
|
|
63
|
+
|
|
64
|
+
const { dataPoints, enableCurve = true } = getPoints({
|
|
65
|
+
graphProps: props.graphProps,
|
|
66
|
+
root: from,
|
|
67
|
+
edge: to,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const raw = dataPoints.map((d) => [graphProps.scale.x(d.x), graphProps.scale.y(d.y)]);
|
|
71
|
+
|
|
72
|
+
const common = {
|
|
73
|
+
onClick,
|
|
74
|
+
graphProps,
|
|
75
|
+
onDragStart,
|
|
76
|
+
onDragStop,
|
|
77
|
+
onChange,
|
|
78
|
+
disabled,
|
|
79
|
+
correctness,
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
if (!enableCurve) {
|
|
83
|
+
return <LinePath data={raw} from={from} to={to} {...common} {...rest} />;
|
|
84
|
+
} else {
|
|
85
|
+
return <LinePath data={raw} from={from} to={to} curve={curveMonotoneX} {...common} {...rest} />;
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
LinePathComponent.propTypes = {
|
|
90
|
+
graphProps: types.GraphPropsType.isRequired,
|
|
91
|
+
from: types.PointType.isRequired,
|
|
92
|
+
to: types.PointType,
|
|
93
|
+
onClick: PropTypes.func,
|
|
94
|
+
onDragStart: PropTypes.func,
|
|
95
|
+
onDragStop: PropTypes.func,
|
|
96
|
+
onChange: PropTypes.func,
|
|
97
|
+
disabled: PropTypes.bool,
|
|
98
|
+
correctness: PropTypes.string,
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
return LinePathComponent;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
export const withRootEdge = (getPoints) => {
|
|
105
|
+
const LinePathComp = withPointsGenerationLinePath(getPoints);
|
|
106
|
+
return lineBase(LinePathComp);
|
|
107
|
+
};
|