@pie-lib/graphing 4.0.5-next.31 → 4.0.5-next.36
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/CHANGELOG.json +1 -0
- package/CHANGELOG.md +1469 -0
- package/LICENSE.md +5 -0
- package/lib/axis/arrow.js +79 -0
- package/lib/axis/arrow.js.map +1 -0
- package/lib/axis/axes.js +329 -0
- package/lib/axis/axes.js.map +1 -0
- package/lib/axis/index.js +21 -0
- package/lib/axis/index.js.map +1 -0
- package/lib/bg.js +114 -0
- package/lib/bg.js.map +1 -0
- package/lib/container/actions.js +18 -0
- package/lib/container/actions.js.map +1 -0
- package/lib/container/index.js +127 -0
- package/lib/container/index.js.map +1 -0
- package/lib/container/marks.js +22 -0
- package/lib/container/marks.js.map +1 -0
- package/lib/container/middleware.js +19 -0
- package/lib/container/middleware.js.map +1 -0
- package/lib/container/reducer.js +18 -0
- package/lib/container/reducer.js.map +1 -0
- package/lib/coordinates-label.js +79 -0
- package/lib/coordinates-label.js.map +1 -0
- package/lib/graph-with-controls.js +294 -0
- package/lib/graph-with-controls.js.map +1 -0
- package/lib/graph.js +327 -0
- package/lib/graph.js.map +1 -0
- package/lib/grid-setup.js +414 -0
- package/lib/grid-setup.js.map +1 -0
- package/lib/grid.js +131 -0
- package/lib/grid.js.map +1 -0
- package/lib/index.js +47 -0
- package/lib/index.js.map +1 -0
- package/lib/key-legend.js +201 -0
- package/lib/key-legend.js.map +1 -0
- package/lib/label-svg-icon.js +50 -0
- package/lib/label-svg-icon.js.map +1 -0
- package/lib/labels.js +243 -0
- package/lib/labels.js.map +1 -0
- package/lib/mark-label.js +285 -0
- package/lib/mark-label.js.map +1 -0
- package/lib/toggle-bar.js +252 -0
- package/lib/toggle-bar.js.map +1 -0
- package/lib/tool-menu.js +78 -0
- package/lib/tool-menu.js.map +1 -0
- package/lib/tools/absolute/component.js +29 -0
- package/lib/tools/absolute/component.js.map +1 -0
- package/lib/tools/absolute/index.js +50 -0
- package/lib/tools/absolute/index.js.map +1 -0
- package/lib/tools/circle/bg-circle.js +123 -0
- package/lib/tools/circle/bg-circle.js.map +1 -0
- package/lib/tools/circle/component.js +321 -0
- package/lib/tools/circle/component.js.map +1 -0
- package/lib/tools/circle/index.js +41 -0
- package/lib/tools/circle/index.js.map +1 -0
- package/lib/tools/exponential/component.js +28 -0
- package/lib/tools/exponential/component.js.map +1 -0
- package/lib/tools/exponential/index.js +56 -0
- package/lib/tools/exponential/index.js.map +1 -0
- package/lib/tools/index.js +86 -0
- package/lib/tools/index.js.map +1 -0
- package/lib/tools/line/component.js +97 -0
- package/lib/tools/line/component.js.map +1 -0
- package/lib/tools/line/index.js +11 -0
- package/lib/tools/line/index.js.map +1 -0
- package/lib/tools/parabola/component.js +28 -0
- package/lib/tools/parabola/component.js.map +1 -0
- package/lib/tools/parabola/index.js +50 -0
- package/lib/tools/parabola/index.js.map +1 -0
- package/lib/tools/point/component.js +148 -0
- package/lib/tools/point/component.js.map +1 -0
- package/lib/tools/point/index.js +24 -0
- package/lib/tools/point/index.js.map +1 -0
- package/lib/tools/polygon/component.js +437 -0
- package/lib/tools/polygon/component.js.map +1 -0
- package/lib/tools/polygon/index.js +89 -0
- package/lib/tools/polygon/index.js.map +1 -0
- package/lib/tools/polygon/line.js +112 -0
- package/lib/tools/polygon/line.js.map +1 -0
- package/lib/tools/polygon/polygon.js +130 -0
- package/lib/tools/polygon/polygon.js.map +1 -0
- package/lib/tools/ray/component.js +95 -0
- package/lib/tools/ray/component.js.map +1 -0
- package/lib/tools/ray/index.js +11 -0
- package/lib/tools/ray/index.js.map +1 -0
- package/lib/tools/segment/component.js +71 -0
- package/lib/tools/segment/component.js.map +1 -0
- package/lib/tools/segment/index.js +11 -0
- package/lib/tools/segment/index.js.map +1 -0
- package/lib/tools/shared/arrow-head.js +111 -0
- package/lib/tools/shared/arrow-head.js.map +1 -0
- package/lib/tools/shared/icons/CorrectSVG.js +40 -0
- package/lib/tools/shared/icons/CorrectSVG.js.map +1 -0
- package/lib/tools/shared/icons/IncorrectSVG.js +40 -0
- package/lib/tools/shared/icons/IncorrectSVG.js.map +1 -0
- package/lib/tools/shared/icons/MissingSVG.js +39 -0
- package/lib/tools/shared/icons/MissingSVG.js.map +1 -0
- package/lib/tools/shared/line/index.js +550 -0
- package/lib/tools/shared/line/index.js.map +1 -0
- package/lib/tools/shared/line/line-path.js +118 -0
- package/lib/tools/shared/line/line-path.js.map +1 -0
- package/lib/tools/shared/line/with-root-edge.js +121 -0
- package/lib/tools/shared/line/with-root-edge.js.map +1 -0
- package/lib/tools/shared/point/arrow-point.js +72 -0
- package/lib/tools/shared/point/arrow-point.js.map +1 -0
- package/lib/tools/shared/point/arrow.js +67 -0
- package/lib/tools/shared/point/arrow.js.map +1 -0
- package/lib/tools/shared/point/base-point.js +157 -0
- package/lib/tools/shared/point/base-point.js.map +1 -0
- package/lib/tools/shared/point/index.js +68 -0
- package/lib/tools/shared/point/index.js.map +1 -0
- package/lib/tools/shared/styles.js +33 -0
- package/lib/tools/shared/styles.js.map +1 -0
- package/lib/tools/shared/types.js +16 -0
- package/lib/tools/shared/types.js.map +1 -0
- package/lib/tools/sine/component.js +40 -0
- package/lib/tools/sine/component.js.map +1 -0
- package/lib/tools/sine/index.js +50 -0
- package/lib/tools/sine/index.js.map +1 -0
- package/lib/tools/vector/component.js +68 -0
- package/lib/tools/vector/component.js.map +1 -0
- package/lib/tools/vector/index.js +11 -0
- package/lib/tools/vector/index.js.map +1 -0
- package/lib/undo-redo.js +86 -0
- package/lib/undo-redo.js.map +1 -0
- package/lib/use-debounce.js +25 -0
- package/lib/use-debounce.js.map +1 -0
- package/lib/utils.js +229 -0
- package/lib/utils.js.map +1 -0
- package/package.json +33 -45
- package/src/__tests__/bg.test.jsx +250 -0
- package/src/__tests__/coordinates-label.test.jsx +243 -0
- package/src/__tests__/graph-with-controls.test.jsx +198 -0
- package/src/__tests__/graph.test.jsx +721 -0
- package/src/__tests__/grid-setup.test.jsx +645 -0
- package/src/__tests__/grid.test.jsx +22 -0
- package/src/__tests__/key-legend.test.jsx +260 -0
- package/src/__tests__/label-svg-icon.test.jsx +278 -0
- package/src/__tests__/labels.test.jsx +55 -0
- package/src/__tests__/mark-label.test.jsx +63 -0
- package/src/__tests__/toggle-bar.test.jsx +146 -0
- package/src/__tests__/tool-menu.test.jsx +115 -0
- package/src/__tests__/undo-redo.test.jsx +24 -0
- package/src/__tests__/use-debounce.test.js +21 -0
- package/src/__tests__/utils.js +41 -0
- package/src/__tests__/utils.test.js +105 -0
- package/src/axis/__tests__/arrow.test.jsx +38 -0
- package/src/axis/__tests__/axes.test.jsx +216 -0
- package/src/axis/arrow.jsx +57 -0
- package/src/axis/axes.jsx +285 -0
- package/src/axis/index.js +3 -0
- package/src/bg.jsx +96 -0
- package/src/container/__tests__/actions.test.js +105 -0
- package/src/container/__tests__/index.test.jsx +319 -0
- package/src/container/__tests__/marks.test.js +172 -0
- package/src/container/__tests__/middleware.test.js +235 -0
- package/src/container/__tests__/reducer.test.js +324 -0
- package/src/container/actions.js +8 -0
- package/src/container/index.jsx +91 -0
- package/src/container/marks.js +14 -0
- package/src/container/middleware.js +7 -0
- package/src/container/reducer.js +5 -0
- package/src/coordinates-label.jsx +63 -0
- package/src/graph-with-controls.jsx +239 -0
- package/src/graph.jsx +303 -0
- package/src/grid-setup.jsx +432 -0
- package/src/grid.jsx +133 -0
- package/src/index.js +7 -0
- package/src/key-legend.jsx +142 -0
- package/src/label-svg-icon.jsx +39 -0
- package/src/labels.jsx +207 -0
- package/src/mark-label.jsx +244 -0
- package/src/toggle-bar.jsx +224 -0
- package/src/tool-menu.jsx +49 -0
- package/src/tools/absolute/__tests__/component.test.jsx +53 -0
- package/src/tools/absolute/component.jsx +23 -0
- package/src/tools/absolute/index.js +31 -0
- package/src/tools/circle/__tests__/bg-circle.test.jsx +26 -0
- package/src/tools/circle/__tests__/component.test.jsx +494 -0
- package/src/tools/circle/__tests__/index.test.js +480 -0
- package/src/tools/circle/bg-circle.jsx +81 -0
- package/src/tools/circle/component.jsx +264 -0
- package/src/tools/circle/index.js +25 -0
- package/src/tools/exponential/__tests__/component.test.jsx +53 -0
- package/src/tools/exponential/__tests__/index.test.js +729 -0
- package/src/tools/exponential/component.jsx +23 -0
- package/src/tools/exponential/index.js +39 -0
- package/src/tools/index.js +48 -0
- package/src/tools/line/__tests__/component.test.jsx +37 -0
- package/src/tools/line/component.jsx +93 -0
- package/src/tools/line/index.js +4 -0
- package/src/tools/parabola/__tests__/component.test.jsx +48 -0
- package/src/tools/parabola/__tests__/index.test.js +470 -0
- package/src/tools/parabola/component.jsx +23 -0
- package/src/tools/parabola/index.js +31 -0
- package/src/tools/point/__tests__/component.test.jsx +349 -0
- package/src/tools/point/__tests__/index.test.js +241 -0
- package/src/tools/point/component.jsx +126 -0
- package/src/tools/point/index.js +11 -0
- package/src/tools/polygon/__tests__/component.test.jsx +471 -0
- package/src/tools/polygon/__tests__/index.test.js +294 -0
- package/src/tools/polygon/__tests__/line.test.jsx +35 -0
- package/src/tools/polygon/__tests__/polygon.test.jsx +61 -0
- package/src/tools/polygon/component.jsx +409 -0
- package/src/tools/polygon/index.js +52 -0
- package/src/tools/polygon/line.jsx +74 -0
- package/src/tools/polygon/polygon.jsx +110 -0
- package/src/tools/ray/__tests__/component.test.jsx +29 -0
- package/src/tools/ray/component.jsx +92 -0
- package/src/tools/ray/index.js +4 -0
- package/src/tools/segment/__tests__/component.test.jsx +28 -0
- package/src/tools/segment/component.jsx +65 -0
- package/src/tools/segment/index.js +4 -0
- package/src/tools/shared/__tests__/arrow-head.test.jsx +31 -0
- package/src/tools/shared/arrow-head.jsx +102 -0
- package/src/tools/shared/icons/CorrectSVG.jsx +32 -0
- package/src/tools/shared/icons/IncorrectSVG.jsx +30 -0
- package/src/tools/shared/icons/MissingSVG.jsx +31 -0
- package/src/tools/shared/line/__tests__/index.test.jsx +109 -0
- package/src/tools/shared/line/__tests__/line-path.test.jsx +53 -0
- package/src/tools/shared/line/__tests__/with-root-edge.test.jsx +73 -0
- package/src/tools/shared/line/index.jsx +487 -0
- package/src/tools/shared/line/line-path.jsx +80 -0
- package/src/tools/shared/line/with-root-edge.jsx +97 -0
- package/src/tools/shared/point/__tests__/arrow-point.test.jsx +91 -0
- package/src/tools/shared/point/__tests__/base-point.test.jsx +87 -0
- package/src/tools/shared/point/arrow-point.jsx +46 -0
- package/src/tools/shared/point/arrow.jsx +37 -0
- package/src/tools/shared/point/base-point.jsx +121 -0
- package/src/tools/shared/point/index.jsx +54 -0
- package/src/tools/shared/styles.js +27 -0
- package/src/tools/shared/types.js +10 -0
- package/src/tools/sine/__tests__/component.test.jsx +51 -0
- package/src/tools/sine/component.jsx +32 -0
- package/src/tools/sine/index.js +33 -0
- package/src/tools/vector/__tests__/component.test.jsx +25 -0
- package/src/tools/vector/component.jsx +56 -0
- package/src/tools/vector/index.js +4 -0
- package/src/undo-redo.jsx +45 -0
- package/src/use-debounce.js +13 -0
- package/src/utils.js +224 -0
- package/dist/_virtual/_rolldown/runtime.js +0 -23
- package/dist/autosize-input.d.ts +0 -10
- package/dist/autosize-input.js +0 -66
- package/dist/axis/arrow.d.ts +0 -13
- package/dist/axis/arrow.js +0 -34
- package/dist/axis/axes.d.ts +0 -132
- package/dist/axis/axes.js +0 -214
- package/dist/axis/index.d.ts +0 -10
- package/dist/bg.d.ts +0 -51
- package/dist/bg.js +0 -44
- package/dist/container/actions.d.ts +0 -15
- package/dist/container/actions.js +0 -7
- package/dist/container/index.d.ts +0 -58
- package/dist/container/index.js +0 -48
- package/dist/container/marks.d.ts +0 -10
- package/dist/container/marks.js +0 -11
- package/dist/container/middleware.d.ts +0 -10
- package/dist/container/middleware.js +0 -4
- package/dist/container/reducer.d.ts +0 -14
- package/dist/container/reducer.js +0 -7
- package/dist/coordinates-label.d.ts +0 -50
- package/dist/coordinates-label.js +0 -46
- package/dist/graph-with-controls.d.ts +0 -88
- package/dist/graph-with-controls.js +0 -154
- package/dist/graph.d.ts +0 -126
- package/dist/graph.js +0 -209
- package/dist/grid-setup.d.ts +0 -27
- package/dist/grid-setup.js +0 -307
- package/dist/grid.d.ts +0 -43
- package/dist/grid.js +0 -59
- package/dist/index.d.ts +0 -15
- package/dist/index.js +0 -7
- package/dist/key-legend.d.ts +0 -21
- package/dist/key-legend.js +0 -231
- package/dist/label-svg-icon.d.ts +0 -18
- package/dist/label-svg-icon.js +0 -42
- package/dist/labels.d.ts +0 -37
- package/dist/labels.js +0 -152
- package/dist/mark-label.d.ts +0 -58
- package/dist/mark-label.js +0 -171
- package/dist/node_modules/.bun/@visx_axis@3.12.0_f4eacebf2041cd4f/node_modules/@visx/axis/esm/axis/Axis.js +0 -101
- package/dist/node_modules/.bun/@visx_axis@3.12.0_f4eacebf2041cd4f/node_modules/@visx/axis/esm/axis/AxisRenderer.js +0 -63
- package/dist/node_modules/.bun/@visx_axis@3.12.0_f4eacebf2041cd4f/node_modules/@visx/axis/esm/axis/Ticks.js +0 -44
- package/dist/node_modules/.bun/@visx_axis@3.12.0_f4eacebf2041cd4f/node_modules/@visx/axis/esm/constants/orientation.js +0 -9
- package/dist/node_modules/.bun/@visx_axis@3.12.0_f4eacebf2041cd4f/node_modules/@visx/axis/esm/utils/createPoint.js +0 -14
- package/dist/node_modules/.bun/@visx_axis@3.12.0_f4eacebf2041cd4f/node_modules/@visx/axis/esm/utils/getAxisRangePaddingConfig.js +0 -21
- package/dist/node_modules/.bun/@visx_axis@3.12.0_f4eacebf2041cd4f/node_modules/@visx/axis/esm/utils/getLabelTransform.js +0 -16
- package/dist/node_modules/.bun/@visx_axis@3.12.0_f4eacebf2041cd4f/node_modules/@visx/axis/esm/utils/getTickFormatter.js +0 -8
- package/dist/node_modules/.bun/@visx_axis@3.12.0_f4eacebf2041cd4f/node_modules/@visx/axis/esm/utils/getTickPosition.js +0 -15
- package/dist/node_modules/.bun/@visx_curve@3.12.0/node_modules/@visx/curve/esm/index.js +0 -2
- package/dist/node_modules/.bun/@visx_grid@3.12.0_f4eacebf2041cd4f/node_modules/@visx/grid/esm/grids/Grid.js +0 -79
- package/dist/node_modules/.bun/@visx_grid@3.12.0_f4eacebf2041cd4f/node_modules/@visx/grid/esm/grids/GridColumns.js +0 -79
- package/dist/node_modules/.bun/@visx_grid@3.12.0_f4eacebf2041cd4f/node_modules/@visx/grid/esm/grids/GridRows.js +0 -79
- package/dist/node_modules/.bun/@visx_grid@3.12.0_f4eacebf2041cd4f/node_modules/@visx/grid/esm/utils/getScaleBandwidth.js +0 -6
- package/dist/node_modules/.bun/@visx_group@3.12.0_f4eacebf2041cd4f/node_modules/@visx/group/esm/Group.js +0 -50
- package/dist/node_modules/.bun/@visx_point@3.12.0/node_modules/@visx/point/esm/Point.js +0 -18
- package/dist/node_modules/.bun/@visx_scale@3.12.0/node_modules/@visx/scale/esm/utils/coerceNumber.js +0 -10
- package/dist/node_modules/.bun/@visx_scale@3.12.0/node_modules/@visx/scale/esm/utils/getTicks.js +0 -9
- package/dist/node_modules/.bun/@visx_scale@3.12.0/node_modules/@visx/scale/esm/utils/toString.js +0 -6
- package/dist/node_modules/.bun/@visx_shape@3.12.0_f4eacebf2041cd4f/node_modules/@visx/shape/esm/shapes/Line.js +0 -47
- package/dist/node_modules/.bun/@visx_shape@3.12.0_f4eacebf2041cd4f/node_modules/@visx/shape/esm/shapes/LinePath.js +0 -50
- package/dist/node_modules/.bun/@visx_shape@3.12.0_f4eacebf2041cd4f/node_modules/@visx/shape/esm/util/D3ShapeFactories.js +0 -9
- package/dist/node_modules/.bun/@visx_shape@3.12.0_f4eacebf2041cd4f/node_modules/@visx/shape/esm/util/setNumberOrNumberAccessor.js +0 -6
- package/dist/node_modules/.bun/@visx_shape@3.12.0_f4eacebf2041cd4f/node_modules/@visx/shape/lib/shapes/Line.js +0 -53
- package/dist/node_modules/.bun/@visx_text@3.12.0_f4eacebf2041cd4f/node_modules/@visx/text/esm/Text.js +0 -57
- package/dist/node_modules/.bun/@visx_text@3.12.0_f4eacebf2041cd4f/node_modules/@visx/text/esm/hooks/useText.js +0 -91
- package/dist/node_modules/.bun/@visx_text@3.12.0_f4eacebf2041cd4f/node_modules/@visx/text/esm/util/getStringWidth.js +0 -21
- package/dist/node_modules/.bun/balanced-match@0.4.2/node_modules/balanced-match/index.js +0 -32
- package/dist/node_modules/.bun/balanced-match@1.0.2/node_modules/balanced-match/index.js +0 -33
- package/dist/node_modules/.bun/classnames@2.5.1/node_modules/classnames/index.js +0 -32
- package/dist/node_modules/.bun/clsx@2.1.1/node_modules/clsx/dist/clsx.js +0 -16
- package/dist/node_modules/.bun/invariant@2.2.4/node_modules/invariant/browser.js +0 -28
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_Hash.js +0 -21
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_ListCache.js +0 -21
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_Map.js +0 -10
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_MapCache.js +0 -21
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_Symbol.js +0 -9
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_assocIndexOf.js +0 -14
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_baseGetTag.js +0 -15
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_baseIsNative.js +0 -16
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_coreJsData.js +0 -9
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_freeGlobal.js +0 -8
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_getMapData.js +0 -14
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_getNative.js +0 -15
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_getRawTag.js +0 -19
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_getValue.js +0 -11
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_hashClear.js +0 -13
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_hashDelete.js +0 -12
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_hashGet.js +0 -18
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_hashHas.js +0 -14
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_hashSet.js +0 -14
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_isKeyable.js +0 -12
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_isMasked.js +0 -16
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_listCacheClear.js +0 -11
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_listCacheDelete.js +0 -14
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_listCacheGet.js +0 -14
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_listCacheHas.js +0 -13
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_listCacheSet.js +0 -14
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_mapCacheClear.js +0 -19
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_mapCacheDelete.js +0 -14
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_mapCacheGet.js +0 -13
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_mapCacheHas.js +0 -13
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_mapCacheSet.js +0 -14
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_nativeCreate.js +0 -9
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_objectToString.js +0 -12
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_root.js +0 -10
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_toSource.js +0 -20
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/eq.js +0 -11
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/isFunction.js +0 -16
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/isObject.js +0 -12
- package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/memoize.js +0 -20
- package/dist/node_modules/.bun/math-expression-evaluator@1.4.0/node_modules/math-expression-evaluator/src/formula_evaluator.js +0 -37
- package/dist/node_modules/.bun/math-expression-evaluator@1.4.0/node_modules/math-expression-evaluator/src/lexer.js +0 -509
- package/dist/node_modules/.bun/math-expression-evaluator@1.4.0/node_modules/math-expression-evaluator/src/math_function.js +0 -108
- package/dist/node_modules/.bun/math-expression-evaluator@1.4.0/node_modules/math-expression-evaluator/src/postfix.js +0 -31
- package/dist/node_modules/.bun/math-expression-evaluator@1.4.0/node_modules/math-expression-evaluator/src/postfix_evaluator.js +0 -45
- package/dist/node_modules/.bun/react-redux@9.3.0_9e2203c65d1d5fa1/node_modules/react-redux/dist/react-redux.js +0 -471
- package/dist/node_modules/.bun/reduce-css-calc@1.3.0/node_modules/reduce-css-calc/index.js +0 -49
- package/dist/node_modules/.bun/reduce-function-call@1.0.3/node_modules/reduce-function-call/index.js +0 -34
- package/dist/node_modules/.bun/redux-undo@1.1.0/node_modules/redux-undo/dist/redux-undo.js +0 -185
- package/dist/node_modules/.bun/redux@5.0.1/node_modules/redux/dist/redux.js +0 -198
- package/dist/node_modules/.bun/use-sync-external-store@1.6.0_f4eacebf2041cd4f/node_modules/use-sync-external-store/cjs/use-sync-external-store-with-selector.development.js +0 -53
- package/dist/node_modules/.bun/use-sync-external-store@1.6.0_f4eacebf2041cd4f/node_modules/use-sync-external-store/cjs/use-sync-external-store-with-selector.production.js +0 -51
- package/dist/node_modules/.bun/use-sync-external-store@1.6.0_f4eacebf2041cd4f/node_modules/use-sync-external-store/with-selector.js +0 -10
- package/dist/toggle-bar.d.ts +0 -40
- package/dist/toggle-bar.js +0 -155
- package/dist/tool-menu.d.ts +0 -29
- package/dist/tool-menu.js +0 -41
- package/dist/tools/absolute/component.d.ts +0 -16
- package/dist/tools/absolute/component.js +0 -15
- package/dist/tools/absolute/index.d.ts +0 -20
- package/dist/tools/absolute/index.js +0 -32
- package/dist/tools/circle/bg-circle.d.ts +0 -116
- package/dist/tools/circle/bg-circle.js +0 -72
- package/dist/tools/circle/component.d.ts +0 -83
- package/dist/tools/circle/component.js +0 -195
- package/dist/tools/circle/index.d.ts +0 -20
- package/dist/tools/circle/index.js +0 -22
- package/dist/tools/exponential/component.d.ts +0 -16
- package/dist/tools/exponential/component.js +0 -14
- package/dist/tools/exponential/index.d.ts +0 -20
- package/dist/tools/exponential/index.js +0 -32
- package/dist/tools/index.d.ts +0 -27
- package/dist/tools/index.js +0 -55
- package/dist/tools/line/component.d.ts +0 -124
- package/dist/tools/line/component.js +0 -72
- package/dist/tools/line/index.d.ts +0 -13
- package/dist/tools/line/index.js +0 -6
- package/dist/tools/parabola/component.d.ts +0 -16
- package/dist/tools/parabola/component.js +0 -14
- package/dist/tools/parabola/index.d.ts +0 -20
- package/dist/tools/parabola/index.js +0 -32
- package/dist/tools/point/component.d.ts +0 -50
- package/dist/tools/point/component.js +0 -85
- package/dist/tools/point/index.d.ts +0 -15
- package/dist/tools/point/index.js +0 -13
- package/dist/tools/polygon/component.d.ts +0 -120
- package/dist/tools/polygon/component.js +0 -262
- package/dist/tools/polygon/index.d.ts +0 -19
- package/dist/tools/polygon/index.js +0 -55
- package/dist/tools/polygon/line.d.ts +0 -125
- package/dist/tools/polygon/line.js +0 -63
- package/dist/tools/polygon/polygon.d.ts +0 -122
- package/dist/tools/polygon/polygon.js +0 -74
- package/dist/tools/ray/component.d.ts +0 -101
- package/dist/tools/ray/component.js +0 -71
- package/dist/tools/ray/index.d.ts +0 -13
- package/dist/tools/ray/index.js +0 -6
- package/dist/tools/segment/component.d.ts +0 -100
- package/dist/tools/segment/component.js +0 -52
- package/dist/tools/segment/index.d.ts +0 -13
- package/dist/tools/segment/index.js +0 -6
- package/dist/tools/shared/arrow-head.d.ts +0 -51
- package/dist/tools/shared/arrow-head.js +0 -63
- package/dist/tools/shared/icons/CorrectSVG.d.ts +0 -26
- package/dist/tools/shared/icons/CorrectSVG.js +0 -29
- package/dist/tools/shared/icons/IncorrectSVG.d.ts +0 -26
- package/dist/tools/shared/icons/IncorrectSVG.js +0 -27
- package/dist/tools/shared/icons/MissingSVG.d.ts +0 -26
- package/dist/tools/shared/icons/MissingSVG.js +0 -28
- package/dist/tools/shared/line/index.d.ts +0 -245
- package/dist/tools/shared/line/index.js +0 -319
- package/dist/tools/shared/line/line-path.d.ts +0 -57
- package/dist/tools/shared/line/line-path.js +0 -71
- package/dist/tools/shared/line/with-root-edge.d.ts +0 -142
- package/dist/tools/shared/line/with-root-edge.js +0 -73
- package/dist/tools/shared/point/arrow-point.d.ts +0 -56
- package/dist/tools/shared/point/arrow-point.js +0 -41
- package/dist/tools/shared/point/arrow.d.ts +0 -45
- package/dist/tools/shared/point/arrow.js +0 -35
- package/dist/tools/shared/point/base-point.d.ts +0 -52
- package/dist/tools/shared/point/base-point.js +0 -103
- package/dist/tools/shared/point/index.d.ts +0 -216
- package/dist/tools/shared/point/index.js +0 -45
- package/dist/tools/shared/styles.d.ts +0 -29
- package/dist/tools/shared/styles.js +0 -20
- package/dist/tools/shared/types.d.ts +0 -21
- package/dist/tools/shared/types.js +0 -11
- package/dist/tools/sine/component.d.ts +0 -16
- package/dist/tools/sine/component.js +0 -22
- package/dist/tools/sine/index.d.ts +0 -20
- package/dist/tools/sine/index.js +0 -32
- package/dist/tools/vector/component.d.ts +0 -100
- package/dist/tools/vector/component.js +0 -44
- package/dist/tools/vector/index.d.ts +0 -13
- package/dist/tools/vector/index.js +0 -6
- package/dist/undo-redo.d.ts +0 -22
- package/dist/undo-redo.js +0 -47
- package/dist/use-debounce.d.ts +0 -9
- package/dist/use-debounce.js +0 -13
- package/dist/utils.d.ts +0 -61
- package/dist/utils.js +0 -75
|
@@ -0,0 +1,409 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { ToolPropTypeFields } from '../shared/types';
|
|
4
|
+
import { BasePoint } from '../shared/point';
|
|
5
|
+
import { chunk, initial, isEmpty } from 'lodash-es';
|
|
6
|
+
import debug from 'debug';
|
|
7
|
+
import Line from './line';
|
|
8
|
+
import DraggablePolygon, { Polygon } from './polygon';
|
|
9
|
+
import { types } from '@pie-lib/plot';
|
|
10
|
+
import invariant from 'invariant';
|
|
11
|
+
import ReactDOM from 'react-dom';
|
|
12
|
+
import MarkLabel from '../../mark-label';
|
|
13
|
+
import { equalPoints, getMiddleOfTwoPoints, getRightestPoints, stripEmptyLabel } from '../../utils';
|
|
14
|
+
|
|
15
|
+
const log = debug('pie-lib:graphing:polygon');
|
|
16
|
+
|
|
17
|
+
export const buildLines = (points, closed) => {
|
|
18
|
+
const expanded = points.reduce((acc, p, index) => {
|
|
19
|
+
acc.push({ ...p, index });
|
|
20
|
+
|
|
21
|
+
const isLast = index === points.length - 1;
|
|
22
|
+
const next = isLast ? 0 : index + 1;
|
|
23
|
+
|
|
24
|
+
acc.push({ ...points[next], index: next });
|
|
25
|
+
|
|
26
|
+
return acc;
|
|
27
|
+
}, []);
|
|
28
|
+
|
|
29
|
+
const all = chunk(expanded, 2).map(([from, to]) => {
|
|
30
|
+
return { from, to };
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
return closed ? all : initial(all);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const swap = (arr, ...rest) => {
|
|
37
|
+
const pairs = chunk(rest, 2);
|
|
38
|
+
|
|
39
|
+
return pairs.reduce(
|
|
40
|
+
(acc, pr) => {
|
|
41
|
+
if (pr.length === 2) {
|
|
42
|
+
let [e, replacement] = pr;
|
|
43
|
+
|
|
44
|
+
invariant(Number.isFinite(e.index), 'Index must be defined');
|
|
45
|
+
|
|
46
|
+
const index = e.index;
|
|
47
|
+
// const i = acc.findIndex(pt => pt.x === e.x && pt.y === e.y);
|
|
48
|
+
|
|
49
|
+
if (index >= 0) {
|
|
50
|
+
acc.splice(index, 1, replacement);
|
|
51
|
+
|
|
52
|
+
return acc;
|
|
53
|
+
} else {
|
|
54
|
+
return acc;
|
|
55
|
+
}
|
|
56
|
+
} else {
|
|
57
|
+
return acc;
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
[...arr],
|
|
61
|
+
);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export class RawBaseComponent extends React.Component {
|
|
65
|
+
static propTypes = {
|
|
66
|
+
classes: PropTypes.object,
|
|
67
|
+
className: PropTypes.string,
|
|
68
|
+
disabled: PropTypes.bool,
|
|
69
|
+
correctness: PropTypes.string,
|
|
70
|
+
points: PropTypes.arrayOf(types.PointType),
|
|
71
|
+
closed: PropTypes.bool,
|
|
72
|
+
coordinatesOnHover: PropTypes.bool,
|
|
73
|
+
onChange: PropTypes.func.isRequired,
|
|
74
|
+
onClosePolygon: PropTypes.func.isRequired,
|
|
75
|
+
onDragStart: PropTypes.func,
|
|
76
|
+
onDragStop: PropTypes.func,
|
|
77
|
+
onClick: PropTypes.func,
|
|
78
|
+
graphProps: types.GraphPropsType.isRequired,
|
|
79
|
+
isToolActive: PropTypes.bool,
|
|
80
|
+
middle: PropTypes.object,
|
|
81
|
+
labelNode: PropTypes.object,
|
|
82
|
+
labelModeEnabled: PropTypes.bool,
|
|
83
|
+
limitLabeling: PropTypes.bool,
|
|
84
|
+
onChangeLabelProps: PropTypes.func,
|
|
85
|
+
onSetMiddleLabel: PropTypes.func,
|
|
86
|
+
onChangeProps: PropTypes.func,
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
static defaultProps = {
|
|
90
|
+
points: [],
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
dragPoint = (index, from, to) => {
|
|
94
|
+
log('[dragPoint] from, to:', from, to);
|
|
95
|
+
const { onChange, points } = this.props;
|
|
96
|
+
const update = [...points];
|
|
97
|
+
const overlapPoint = !!(points || []).find((p) => equalPoints(p, to));
|
|
98
|
+
|
|
99
|
+
if (equalPoints(from, to) || overlapPoint) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (points[index].label) {
|
|
104
|
+
to.label = points[index].label;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
update.splice(index, 1, to);
|
|
108
|
+
onChange(update);
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
dragLine = (existing, next) => {
|
|
112
|
+
log('[dragLine]: ', existing, next);
|
|
113
|
+
const { onChange } = this.props;
|
|
114
|
+
|
|
115
|
+
if (existing.from.label) {
|
|
116
|
+
next.from.label = existing.from.label;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (existing.to.label) {
|
|
120
|
+
next.to.label = existing.to.label;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const points = swap(this.props.points, existing.from, next.from, existing.to, next.to);
|
|
124
|
+
onChange(points);
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
dragPoly = (existing, next) => {
|
|
128
|
+
log('[dragPoly] ', existing, next);
|
|
129
|
+
const { onChange } = this.props;
|
|
130
|
+
|
|
131
|
+
next.forEach((point, index) => {
|
|
132
|
+
if (existing[index].label) {
|
|
133
|
+
next[index].label = existing[index].label;
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
onChange(next);
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
close = () => {
|
|
141
|
+
const { points, onClosePolygon } = this.props;
|
|
142
|
+
log('[close] ...');
|
|
143
|
+
|
|
144
|
+
if (points.length >= 3) {
|
|
145
|
+
onClosePolygon();
|
|
146
|
+
} else {
|
|
147
|
+
log('[close] - nope');
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
labelChange = (point, index) => {
|
|
152
|
+
const { points, onChangeProps } = this.props;
|
|
153
|
+
const updatedPoint = { ...point };
|
|
154
|
+
|
|
155
|
+
if (!point.label || isEmpty(point.label)) {
|
|
156
|
+
delete updatedPoint.label;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const update = [...points];
|
|
160
|
+
|
|
161
|
+
update.splice(index, 1, updatedPoint);
|
|
162
|
+
onChangeProps(update);
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
clickPoint = (point, index, data) => {
|
|
166
|
+
const {
|
|
167
|
+
closed,
|
|
168
|
+
disabled,
|
|
169
|
+
middle: currentMiddle,
|
|
170
|
+
onClick,
|
|
171
|
+
isToolActive,
|
|
172
|
+
labelModeEnabled,
|
|
173
|
+
limitLabeling,
|
|
174
|
+
onSetMiddleLabel,
|
|
175
|
+
points,
|
|
176
|
+
} = this.props;
|
|
177
|
+
|
|
178
|
+
if (labelModeEnabled) {
|
|
179
|
+
// limit labeling the points of the polygon
|
|
180
|
+
if (disabled || limitLabeling) {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (points && index === points.length) {
|
|
185
|
+
const { a, b } = getRightestPoints(points);
|
|
186
|
+
const middle = { label: '', ...point, ...getMiddleOfTwoPoints(a, b) };
|
|
187
|
+
|
|
188
|
+
onSetMiddleLabel(middle, points.map(stripEmptyLabel));
|
|
189
|
+
} else {
|
|
190
|
+
const strippedPoints = points.map(stripEmptyLabel);
|
|
191
|
+
strippedPoints.splice(index, 1, { label: '', ...point });
|
|
192
|
+
|
|
193
|
+
const strippedMiddle = currentMiddle ? stripEmptyLabel(currentMiddle) : currentMiddle;
|
|
194
|
+
onSetMiddleLabel(strippedMiddle, strippedPoints);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// defer the focus() call with setTimeout to allow the re-render to complete first.
|
|
198
|
+
setTimeout(() => {
|
|
199
|
+
if (this.input[index]) {
|
|
200
|
+
this.input[index].focus();
|
|
201
|
+
}
|
|
202
|
+
}, 0);
|
|
203
|
+
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if (isToolActive && !closed && index === 0) {
|
|
208
|
+
this.close();
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
onClick(point || data);
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
// IMPORTANT, do not remove
|
|
216
|
+
input = {};
|
|
217
|
+
|
|
218
|
+
render() {
|
|
219
|
+
const {
|
|
220
|
+
closed,
|
|
221
|
+
coordinatesOnHover,
|
|
222
|
+
correctness,
|
|
223
|
+
disabled,
|
|
224
|
+
graphProps,
|
|
225
|
+
onChangeLabelProps,
|
|
226
|
+
onDragStart,
|
|
227
|
+
onDragStop,
|
|
228
|
+
points,
|
|
229
|
+
middle,
|
|
230
|
+
labelNode,
|
|
231
|
+
labelModeEnabled,
|
|
232
|
+
} = this.props;
|
|
233
|
+
const lines = buildLines(points, closed);
|
|
234
|
+
const common = { onDragStart, onDragStop, graphProps, disabled, correctness };
|
|
235
|
+
const polygonLabelIndex = (points && points.length) || 0;
|
|
236
|
+
let polygonLabelNode = null;
|
|
237
|
+
|
|
238
|
+
if (labelNode && middle && Object.prototype.hasOwnProperty.call(middle, 'label')) {
|
|
239
|
+
polygonLabelNode = ReactDOM.createPortal(
|
|
240
|
+
<MarkLabel
|
|
241
|
+
inputRef={(r) => (this.input[polygonLabelIndex] = r)}
|
|
242
|
+
disabled={disabled || !labelModeEnabled}
|
|
243
|
+
mark={middle}
|
|
244
|
+
graphProps={graphProps}
|
|
245
|
+
onChange={(label) => onChangeLabelProps({ ...middle, label })}
|
|
246
|
+
/>,
|
|
247
|
+
labelNode,
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
return (
|
|
252
|
+
<g>
|
|
253
|
+
{closed ? (
|
|
254
|
+
<React.Fragment>
|
|
255
|
+
<DraggablePolygon
|
|
256
|
+
points={points}
|
|
257
|
+
onDrag={this.dragPoly.bind(this, points)}
|
|
258
|
+
closed={closed}
|
|
259
|
+
{...common}
|
|
260
|
+
onClick={this.clickPoint.bind(this, middle, polygonLabelIndex)}
|
|
261
|
+
/>
|
|
262
|
+
{polygonLabelNode}
|
|
263
|
+
</React.Fragment>
|
|
264
|
+
) : (
|
|
265
|
+
<Polygon points={points} graphProps={graphProps} closed={closed} />
|
|
266
|
+
)}
|
|
267
|
+
{(lines || []).map((l, index) => (
|
|
268
|
+
<Line
|
|
269
|
+
key={`line-${index}`}
|
|
270
|
+
from={l.from}
|
|
271
|
+
to={l.to}
|
|
272
|
+
onDrag={this.dragLine.bind(this, l)}
|
|
273
|
+
{...common}
|
|
274
|
+
onClick={this.clickPoint.bind(this, middle, polygonLabelIndex)}
|
|
275
|
+
/>
|
|
276
|
+
))}
|
|
277
|
+
|
|
278
|
+
{(points || []).map((p, index) => {
|
|
279
|
+
return [
|
|
280
|
+
<BasePoint
|
|
281
|
+
key={`point-${index}`}
|
|
282
|
+
coordinatesOnHover={coordinatesOnHover}
|
|
283
|
+
labelNode={labelNode}
|
|
284
|
+
x={p.x}
|
|
285
|
+
y={p.y}
|
|
286
|
+
onDrag={this.dragPoint.bind(this, index, p)}
|
|
287
|
+
{...common}
|
|
288
|
+
onClick={this.clickPoint.bind(this, p, index)}
|
|
289
|
+
/>,
|
|
290
|
+
labelNode && Object.prototype.hasOwnProperty.call(p, 'label')
|
|
291
|
+
? ReactDOM.createPortal(
|
|
292
|
+
<MarkLabel
|
|
293
|
+
inputRef={(r) => (this.input[index] = r)}
|
|
294
|
+
disabled={disabled || !labelModeEnabled}
|
|
295
|
+
mark={p}
|
|
296
|
+
graphProps={graphProps}
|
|
297
|
+
onChange={(label) => this.labelChange({ ...p, label }, index)}
|
|
298
|
+
/>,
|
|
299
|
+
labelNode,
|
|
300
|
+
)
|
|
301
|
+
: null,
|
|
302
|
+
];
|
|
303
|
+
})}
|
|
304
|
+
</g>
|
|
305
|
+
);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
export const BaseComponent = RawBaseComponent;
|
|
310
|
+
|
|
311
|
+
export default class Component extends React.Component {
|
|
312
|
+
static propTypes = {
|
|
313
|
+
...ToolPropTypeFields,
|
|
314
|
+
graphProps: types.GraphPropsType.isRequired,
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
static defaultProps = {};
|
|
318
|
+
|
|
319
|
+
constructor(props) {
|
|
320
|
+
super(props);
|
|
321
|
+
this.state = {};
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
change = (points) => {
|
|
325
|
+
const {
|
|
326
|
+
mark: { middle },
|
|
327
|
+
} = this.props;
|
|
328
|
+
const mark = { ...this.state.mark, points };
|
|
329
|
+
|
|
330
|
+
if (middle) {
|
|
331
|
+
const { a, b } = getRightestPoints(points);
|
|
332
|
+
|
|
333
|
+
mark.middle = { ...middle, ...getMiddleOfTwoPoints(a, b) };
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
this.setState({ mark });
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
changeProps = (points) => {
|
|
340
|
+
const mark = { ...this.props.mark, points };
|
|
341
|
+
|
|
342
|
+
this.props.onChange(this.props.mark, mark);
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
changeLabelProps = (point) => {
|
|
346
|
+
const { mark, onChange } = this.props;
|
|
347
|
+
const middle = { ...mark.middle, ...point };
|
|
348
|
+
|
|
349
|
+
if (!middle.label || isEmpty(middle.label)) {
|
|
350
|
+
delete middle.label;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
onChange(mark, { ...mark, middle });
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
setMiddleLabel = (middle, strippedPoints) => {
|
|
357
|
+
const { mark, onChange } = this.props;
|
|
358
|
+
const next = { ...mark, middle };
|
|
359
|
+
if (strippedPoints) {
|
|
360
|
+
next.points = strippedPoints;
|
|
361
|
+
}
|
|
362
|
+
onChange(mark, next);
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
closePolygon = () => {
|
|
366
|
+
log('[closePolygon] ...');
|
|
367
|
+
const { onComplete, mark } = this.props;
|
|
368
|
+
const update = { ...mark, closed: true };
|
|
369
|
+
|
|
370
|
+
onComplete(mark, update);
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
dragStart = () => this.setState({ mark: this.props.mark });
|
|
374
|
+
|
|
375
|
+
dragStop = () => {
|
|
376
|
+
const { onChange } = this.props;
|
|
377
|
+
const m = { ...this.state.mark };
|
|
378
|
+
|
|
379
|
+
this.setState({ mark: undefined }, () => {
|
|
380
|
+
onChange(this.props.mark, m);
|
|
381
|
+
});
|
|
382
|
+
};
|
|
383
|
+
|
|
384
|
+
render() {
|
|
385
|
+
const { coordinatesOnHover, mark, graphProps, onClick, isToolActive, labelNode, labelModeEnabled, limitLabeling } =
|
|
386
|
+
this.props;
|
|
387
|
+
const { mark: stateMark } = this.state;
|
|
388
|
+
|
|
389
|
+
return (
|
|
390
|
+
<BaseComponent
|
|
391
|
+
{...(stateMark || mark)}
|
|
392
|
+
coordinatesOnHover={coordinatesOnHover}
|
|
393
|
+
onChange={this.change}
|
|
394
|
+
onChangeLabelProps={this.changeLabelProps}
|
|
395
|
+
onSetMiddleLabel={this.setMiddleLabel}
|
|
396
|
+
onChangeProps={this.changeProps}
|
|
397
|
+
onClosePolygon={this.closePolygon}
|
|
398
|
+
onDragStart={this.dragStart}
|
|
399
|
+
onDragStop={this.dragStop}
|
|
400
|
+
onClick={onClick}
|
|
401
|
+
graphProps={graphProps}
|
|
402
|
+
isToolActive={isToolActive}
|
|
403
|
+
labelNode={labelNode}
|
|
404
|
+
labelModeEnabled={labelModeEnabled}
|
|
405
|
+
limitLabeling={limitLabeling}
|
|
406
|
+
/>
|
|
407
|
+
);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import Polygon from './component';
|
|
2
|
+
import { equalPoints } from '../../utils';
|
|
3
|
+
|
|
4
|
+
export const addPointToArray = (point, arr) => {
|
|
5
|
+
arr = arr || [];
|
|
6
|
+
|
|
7
|
+
if (arr.length === 0) {
|
|
8
|
+
return { points: [point], closed: false };
|
|
9
|
+
} else if (arr.length === 1) {
|
|
10
|
+
if (equalPoints(point, arr[0])) {
|
|
11
|
+
return { points: arr, closed: false };
|
|
12
|
+
} else {
|
|
13
|
+
return { points: [...arr, point], closed: false };
|
|
14
|
+
}
|
|
15
|
+
} else if (arr.length >= 2) {
|
|
16
|
+
const closed = equalPoints(point, arr[0]);
|
|
17
|
+
|
|
18
|
+
if (closed) {
|
|
19
|
+
return { points: arr, closed };
|
|
20
|
+
} else {
|
|
21
|
+
const hasPoint = !!arr.find((p) => equalPoints(p, point));
|
|
22
|
+
|
|
23
|
+
if (hasPoint) {
|
|
24
|
+
return { points: arr, closed: false };
|
|
25
|
+
} else {
|
|
26
|
+
return { points: [...arr, point], closed: false };
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const tool = () => ({
|
|
33
|
+
type: 'polygon',
|
|
34
|
+
Component: Polygon,
|
|
35
|
+
complete: (data, mark) => {
|
|
36
|
+
return { ...mark, building: false, closed: true };
|
|
37
|
+
},
|
|
38
|
+
addPoint: (point, mark) => {
|
|
39
|
+
if (!mark) {
|
|
40
|
+
return {
|
|
41
|
+
type: 'polygon',
|
|
42
|
+
points: [point],
|
|
43
|
+
closed: false,
|
|
44
|
+
building: true,
|
|
45
|
+
};
|
|
46
|
+
} else {
|
|
47
|
+
const { closed, points } = addPointToArray(point, mark.points);
|
|
48
|
+
|
|
49
|
+
return { ...mark, closed, points, building: !closed };
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
});
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { styled } from '@mui/material/styles';
|
|
4
|
+
import { gridDraggable, types } from '@pie-lib/plot';
|
|
5
|
+
import { color } from '@pie-lib/render-ui';
|
|
6
|
+
import * as utils from '../../utils';
|
|
7
|
+
import { correct, disabled, incorrect, missing } from '../shared/styles';
|
|
8
|
+
|
|
9
|
+
const StyledLine = styled('line')(({ disabled: isDisabled, correctness }) => ({
|
|
10
|
+
strokeWidth: 7,
|
|
11
|
+
transition: 'stroke-width 200ms ease-in, stroke 200ms ease-in',
|
|
12
|
+
stroke: 'transparent',
|
|
13
|
+
pointerEvents: 'stroke',
|
|
14
|
+
'&:hover': {
|
|
15
|
+
strokeWidth: 4,
|
|
16
|
+
stroke: color.defaults.BLACK,
|
|
17
|
+
},
|
|
18
|
+
...((isDisabled || correctness) && { pointerEvents: 'none' }),
|
|
19
|
+
}));
|
|
20
|
+
|
|
21
|
+
class RawLine extends React.Component {
|
|
22
|
+
static propTypes = {
|
|
23
|
+
className: PropTypes.string,
|
|
24
|
+
from: types.PointType,
|
|
25
|
+
to: types.PointType,
|
|
26
|
+
graphProps: types.GraphPropsType.isRequired,
|
|
27
|
+
disabled: PropTypes.bool,
|
|
28
|
+
correctness: PropTypes.string,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
static defaultProps = {
|
|
32
|
+
from: {},
|
|
33
|
+
to: {},
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
render() {
|
|
37
|
+
// eslint-disable-next-line no-unused-vars
|
|
38
|
+
const { graphProps, from, to, className, disabled, correctness, ...rest } = this.props;
|
|
39
|
+
const { scale } = graphProps;
|
|
40
|
+
return (
|
|
41
|
+
<StyledLine
|
|
42
|
+
x1={scale.x(from.x)}
|
|
43
|
+
y1={scale.y(from.y)}
|
|
44
|
+
x2={scale.x(to.x)}
|
|
45
|
+
y2={scale.y(to.y)}
|
|
46
|
+
className={className}
|
|
47
|
+
disabled={disabled}
|
|
48
|
+
correctness={correctness}
|
|
49
|
+
{...rest}
|
|
50
|
+
/>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export const Line = RawLine;
|
|
56
|
+
|
|
57
|
+
export default gridDraggable({
|
|
58
|
+
bounds: (props, { domain, range }) => {
|
|
59
|
+
const { from, to } = props;
|
|
60
|
+
const area = utils.lineToArea(from, to);
|
|
61
|
+
return utils.bounds(area, domain, range);
|
|
62
|
+
},
|
|
63
|
+
anchorPoint: (props) => {
|
|
64
|
+
const { from } = props;
|
|
65
|
+
return from;
|
|
66
|
+
},
|
|
67
|
+
fromDelta: (props, delta) => {
|
|
68
|
+
const { from, to } = props;
|
|
69
|
+
return {
|
|
70
|
+
from: utils.point(from).add(utils.point(delta)),
|
|
71
|
+
to: utils.point(to).add(utils.point(delta)),
|
|
72
|
+
};
|
|
73
|
+
},
|
|
74
|
+
})(Line);
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { alpha, styled } from '@mui/material/styles';
|
|
4
|
+
import { gridDraggable, types } from '@pie-lib/plot';
|
|
5
|
+
import { color } from '@pie-lib/render-ui';
|
|
6
|
+
|
|
7
|
+
import * as utils from '../../utils';
|
|
8
|
+
import { correct, disabledSecondary, incorrect, missing, graphingShapeFill } from '../shared/styles';
|
|
9
|
+
|
|
10
|
+
const StyledPolygon = styled('polygon')(({ disabled: isDisabled, correctness }) => ({
|
|
11
|
+
fill: alpha(graphingShapeFill(), 0.2),
|
|
12
|
+
strokeWidth: 3,
|
|
13
|
+
stroke: color.defaults.BLACK,
|
|
14
|
+
...(isDisabled && disabledSecondary('stroke')),
|
|
15
|
+
...(correctness === 'correct' && correct('stroke')),
|
|
16
|
+
...(correctness === 'incorrect' && incorrect('stroke')),
|
|
17
|
+
...(correctness === 'missing' && {
|
|
18
|
+
...missing('stroke'),
|
|
19
|
+
stroke: 'inherit',
|
|
20
|
+
}),
|
|
21
|
+
}));
|
|
22
|
+
|
|
23
|
+
const StyledPolyline = styled('polyline')(({ disabled: isDisabled, correctness }) => ({
|
|
24
|
+
fill: alpha(graphingShapeFill(), 0.0),
|
|
25
|
+
strokeWidth: 3,
|
|
26
|
+
stroke: color.defaults.BLACK,
|
|
27
|
+
pointerEvents: 'none',
|
|
28
|
+
...(isDisabled && disabledSecondary('stroke')),
|
|
29
|
+
...(correctness === 'correct' && correct('stroke')),
|
|
30
|
+
...(correctness === 'incorrect' && incorrect('stroke')),
|
|
31
|
+
...(correctness === 'missing' && {
|
|
32
|
+
...missing('stroke'),
|
|
33
|
+
stroke: 'inherit',
|
|
34
|
+
}),
|
|
35
|
+
}));
|
|
36
|
+
|
|
37
|
+
export const getPointString = (points, scale) => {
|
|
38
|
+
return (points || [])
|
|
39
|
+
.map((p) => {
|
|
40
|
+
const scaledPoint = {
|
|
41
|
+
x: scale.x(p.x),
|
|
42
|
+
y: scale.y(p.y),
|
|
43
|
+
};
|
|
44
|
+
return `${scaledPoint.x},${scaledPoint.y}`;
|
|
45
|
+
})
|
|
46
|
+
.join(' ');
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export class RawPolygon extends React.Component {
|
|
50
|
+
static propTypes = {
|
|
51
|
+
className: PropTypes.string,
|
|
52
|
+
disabled: PropTypes.bool,
|
|
53
|
+
points: PropTypes.arrayOf(types.PointType),
|
|
54
|
+
graphProps: types.GraphPropsType.isRequired,
|
|
55
|
+
closed: PropTypes.bool.isRequired,
|
|
56
|
+
correctness: PropTypes.string,
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
static defaultProps = {
|
|
60
|
+
points: [],
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
render() {
|
|
64
|
+
const { points, className, disabled, correctness, graphProps, closed, ...rest } = this.props;
|
|
65
|
+
const { scale } = graphProps;
|
|
66
|
+
|
|
67
|
+
const pointString = getPointString(points, scale);
|
|
68
|
+
|
|
69
|
+
if (closed) {
|
|
70
|
+
return (
|
|
71
|
+
<StyledPolygon
|
|
72
|
+
points={pointString}
|
|
73
|
+
className={className}
|
|
74
|
+
disabled={disabled}
|
|
75
|
+
correctness={correctness}
|
|
76
|
+
{...rest}
|
|
77
|
+
/>
|
|
78
|
+
);
|
|
79
|
+
} else {
|
|
80
|
+
return (
|
|
81
|
+
<StyledPolyline
|
|
82
|
+
points={pointString}
|
|
83
|
+
className={className}
|
|
84
|
+
disabled={disabled}
|
|
85
|
+
correctness={correctness}
|
|
86
|
+
{...rest}
|
|
87
|
+
/>
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export const Polygon = RawPolygon;
|
|
94
|
+
|
|
95
|
+
export default gridDraggable({
|
|
96
|
+
bounds: (props, { domain, range }) => {
|
|
97
|
+
const { points } = props;
|
|
98
|
+
const area = utils.polygonToArea(points);
|
|
99
|
+
return utils.bounds(area, domain, range);
|
|
100
|
+
},
|
|
101
|
+
anchorPoint: (props) => {
|
|
102
|
+
const { points } = props;
|
|
103
|
+
return points[0];
|
|
104
|
+
},
|
|
105
|
+
fromDelta: (props, delta) => {
|
|
106
|
+
const { points } = props;
|
|
107
|
+
|
|
108
|
+
return points.map((p) => utils.point(p).add(utils.point(delta)));
|
|
109
|
+
},
|
|
110
|
+
})(Polygon);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { render } from '@pie-lib/test-utils';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { RayLine } from '../component';
|
|
4
|
+
import { graphProps as getGraphProps } from '../../../__tests__/utils';
|
|
5
|
+
import { utils } from '@pie-lib/plot';
|
|
6
|
+
|
|
7
|
+
describe('RayLine', () => {
|
|
8
|
+
let onChange = jest.fn();
|
|
9
|
+
const renderComponent = (extras) => {
|
|
10
|
+
const defaults = {
|
|
11
|
+
classes: {},
|
|
12
|
+
className: 'className',
|
|
13
|
+
onChange,
|
|
14
|
+
markerId: '1',
|
|
15
|
+
graphProps: getGraphProps(),
|
|
16
|
+
from: utils.xy(0, 0),
|
|
17
|
+
to: utils.xy(1, 1),
|
|
18
|
+
};
|
|
19
|
+
const props = { ...defaults, ...extras };
|
|
20
|
+
return render(<RayLine {...props} />);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
describe('rendering', () => {
|
|
24
|
+
it('renders without crashing', () => {
|
|
25
|
+
const { container } = renderComponent();
|
|
26
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
});
|