@pie-lib/graphing 3.1.0-next.5 → 3.1.1-next.1

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.
Files changed (114) hide show
  1. package/NEXT.CHANGELOG.json +16 -1
  2. package/lib/axis/axes.js.map +1 -1
  3. package/lib/axis/index.js.map +1 -1
  4. package/lib/bg.js +9 -6
  5. package/lib/bg.js.map +1 -1
  6. package/lib/container/index.js +4 -4
  7. package/lib/container/index.js.map +1 -1
  8. package/lib/coordinates-label.js.map +1 -1
  9. package/lib/graph-with-controls.js +3 -4
  10. package/lib/graph-with-controls.js.map +1 -1
  11. package/lib/graph.js +8 -9
  12. package/lib/graph.js.map +1 -1
  13. package/lib/grid-setup.js.map +1 -1
  14. package/lib/key-legend.js +1 -1
  15. package/lib/key-legend.js.map +1 -1
  16. package/lib/mark-label.js.map +1 -1
  17. package/lib/toggle-bar.js.map +1 -1
  18. package/lib/tools/absolute/component.js.map +1 -1
  19. package/lib/tools/circle/bg-circle.js.map +1 -1
  20. package/lib/tools/circle/component.js +2 -2
  21. package/lib/tools/circle/component.js.map +1 -1
  22. package/lib/tools/exponential/component.js.map +1 -1
  23. package/lib/tools/line/component.js.map +1 -1
  24. package/lib/tools/parabola/component.js.map +1 -1
  25. package/lib/tools/point/component.js +3 -4
  26. package/lib/tools/point/component.js.map +1 -1
  27. package/lib/tools/polygon/component.js +5 -7
  28. package/lib/tools/polygon/component.js.map +1 -1
  29. package/lib/tools/polygon/line.js.map +1 -1
  30. package/lib/tools/polygon/polygon.js.map +1 -1
  31. package/lib/tools/ray/component.js.map +1 -1
  32. package/lib/tools/segment/component.js.map +1 -1
  33. package/lib/tools/shared/arrow-head.js.map +1 -1
  34. package/lib/tools/shared/line/index.js +7 -9
  35. package/lib/tools/shared/line/index.js.map +1 -1
  36. package/lib/tools/shared/line/line-path.js.map +1 -1
  37. package/lib/tools/shared/point/arrow-point.js.map +1 -1
  38. package/lib/tools/sine/component.js.map +1 -1
  39. package/lib/tools/vector/component.js.map +1 -1
  40. package/lib/undo-redo.js.map +1 -1
  41. package/lib/use-debounce.js.map +1 -1
  42. package/lib/utils.js +9 -13
  43. package/lib/utils.js.map +1 -1
  44. package/package.json +14 -14
  45. package/src/__tests__/bg.test.jsx +250 -0
  46. package/src/__tests__/coordinates-label.test.jsx +243 -0
  47. package/src/__tests__/graph-with-controls.test.jsx +46 -12
  48. package/src/__tests__/graph.test.jsx +560 -5
  49. package/src/__tests__/grid-setup.test.jsx +645 -0
  50. package/src/__tests__/grid.test.jsx +1 -1
  51. package/src/__tests__/key-legend.test.jsx +260 -0
  52. package/src/__tests__/label-svg-icon.test.jsx +278 -0
  53. package/src/__tests__/mark-label.test.jsx +1 -1
  54. package/src/__tests__/toggle-bar.test.jsx +38 -3
  55. package/src/__tests__/tool-menu.test.jsx +38 -1
  56. package/src/__tests__/use-debounce.test.js +1 -1
  57. package/src/__tests__/utils.test.js +15 -61
  58. package/src/axis/__tests__/axes.test.jsx +1 -1
  59. package/src/axis/axes.jsx +7 -21
  60. package/src/axis/index.js +1 -0
  61. package/src/bg.jsx +5 -5
  62. package/src/container/__tests__/actions.test.js +105 -0
  63. package/src/container/__tests__/index.test.jsx +319 -0
  64. package/src/container/__tests__/marks.test.js +172 -0
  65. package/src/container/__tests__/middleware.test.js +235 -0
  66. package/src/container/__tests__/reducer.test.js +324 -0
  67. package/src/container/index.jsx +2 -3
  68. package/src/coordinates-label.jsx +1 -7
  69. package/src/graph-with-controls.jsx +8 -6
  70. package/src/graph.jsx +2 -3
  71. package/src/grid-setup.jsx +1 -1
  72. package/src/key-legend.jsx +2 -1
  73. package/src/mark-label.jsx +7 -24
  74. package/src/toggle-bar.jsx +8 -1
  75. package/src/tools/absolute/__tests__/component.test.jsx +1 -2
  76. package/src/tools/absolute/component.jsx +2 -2
  77. package/src/tools/circle/__tests__/component.test.jsx +438 -0
  78. package/src/tools/circle/__tests__/index.test.js +480 -0
  79. package/src/tools/circle/bg-circle.jsx +2 -2
  80. package/src/tools/circle/component.jsx +10 -12
  81. package/src/tools/exponential/__tests__/component.test.jsx +0 -1
  82. package/src/tools/exponential/__tests__/index.test.js +729 -0
  83. package/src/tools/exponential/component.jsx +1 -1
  84. package/src/tools/line/__tests__/component.test.jsx +1 -0
  85. package/src/tools/line/component.jsx +4 -11
  86. package/src/tools/parabola/__tests__/component.test.jsx +0 -1
  87. package/src/tools/parabola/__tests__/index.test.js +470 -0
  88. package/src/tools/parabola/component.jsx +1 -1
  89. package/src/tools/point/__tests__/component.test.jsx +310 -2
  90. package/src/tools/point/__tests__/index.test.js +241 -0
  91. package/src/tools/point/component.jsx +1 -2
  92. package/src/tools/polygon/__tests__/component.test.jsx +391 -2
  93. package/src/tools/polygon/__tests__/index.test.js +237 -8
  94. package/src/tools/polygon/__tests__/line.test.jsx +13 -0
  95. package/src/tools/polygon/__tests__/polygon.test.jsx +19 -1
  96. package/src/tools/polygon/component.jsx +4 -14
  97. package/src/tools/polygon/line.jsx +1 -1
  98. package/src/tools/polygon/polygon.jsx +1 -1
  99. package/src/tools/ray/__tests__/component.test.jsx +1 -0
  100. package/src/tools/ray/component.jsx +3 -5
  101. package/src/tools/segment/__tests__/component.test.jsx +1 -0
  102. package/src/tools/segment/component.jsx +1 -1
  103. package/src/tools/shared/arrow-head.jsx +11 -6
  104. package/src/tools/shared/line/__tests__/index.test.jsx +1 -1
  105. package/src/tools/shared/line/__tests__/line-path.test.jsx +3 -3
  106. package/src/tools/shared/line/__tests__/with-root-edge.test.jsx +2 -2
  107. package/src/tools/shared/line/index.jsx +4 -6
  108. package/src/tools/shared/line/line-path.jsx +2 -8
  109. package/src/tools/shared/point/arrow-point.jsx +2 -5
  110. package/src/tools/sine/component.jsx +2 -2
  111. package/src/tools/vector/component.jsx +1 -1
  112. package/src/undo-redo.jsx +3 -9
  113. package/src/use-debounce.js +1 -1
  114. package/src/utils.js +1 -5
@@ -18,5 +18,18 @@ describe('Line', () => {
18
18
  const { container } = renderComponent();
19
19
  expect(container.firstChild).toBeInTheDocument();
20
20
  });
21
+
22
+ it('renders with from and to points', () => {
23
+ const { container } = renderComponent({
24
+ from: { x: 0, y: 0 },
25
+ to: { x: 5, y: 5 },
26
+ });
27
+ expect(container.firstChild).toBeInTheDocument();
28
+ });
29
+
30
+ it('renders with className', () => {
31
+ const { container } = renderComponent({ className: 'custom-line' });
32
+ expect(container.firstChild).toBeInTheDocument();
33
+ });
21
34
  });
22
35
  });
@@ -1,6 +1,6 @@
1
1
  import { render } from '@pie-lib/test-utils';
2
2
  import React from 'react';
3
- import { Polygon, getPointString } from '../polygon';
3
+ import { getPointString, Polygon } from '../polygon';
4
4
  import { graphProps } from '../../../__tests__/utils';
5
5
 
6
6
  const xy = (x, y) => ({ x, y });
@@ -22,6 +22,24 @@ describe('Polygon', () => {
22
22
  const { container } = renderComponent({ points: [{ x: 1, y: 1 }] });
23
23
  expect(container.firstChild).toBeInTheDocument();
24
24
  });
25
+
26
+ it('renders multiple points', () => {
27
+ const points = [xy(0, 0), xy(1, 1), xy(2, 0)];
28
+ const { container } = renderComponent({ points });
29
+ expect(container.firstChild).toBeInTheDocument();
30
+ });
31
+
32
+ it('renders closed polygon', () => {
33
+ const points = [xy(0, 0), xy(1, 1), xy(2, 0)];
34
+ const { container } = renderComponent({ points, closed: true });
35
+ expect(container.firstChild).toBeInTheDocument();
36
+ });
37
+
38
+ it('renders open polygon', () => {
39
+ const points = [xy(0, 0), xy(1, 1)];
40
+ const { container } = renderComponent({ points, closed: false });
41
+ expect(container.firstChild).toBeInTheDocument();
42
+ });
25
43
  });
26
44
  });
27
45
 
@@ -2,8 +2,7 @@ import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import { ToolPropTypeFields } from '../shared/types';
4
4
  import { BasePoint } from '../shared/point';
5
- import chunk from 'lodash/chunk';
6
- import initial from 'lodash/initial';
5
+ import { chunk, initial, isEmpty } from 'lodash-es';
7
6
  import debug from 'debug';
8
7
  import Line from './line';
9
8
  import DraggablePolygon, { Polygon } from './polygon';
@@ -11,8 +10,7 @@ import { types } from '@pie-lib/plot';
11
10
  import invariant from 'invariant';
12
11
  import ReactDOM from 'react-dom';
13
12
  import MarkLabel from '../../mark-label';
14
- import isEmpty from 'lodash/isEmpty';
15
- import { getMiddleOfTwoPoints, getRightestPoints, equalPoints } from '../../utils';
13
+ import { equalPoints, getMiddleOfTwoPoints, getRightestPoints } from '../../utils';
16
14
 
17
15
  const log = debug('pie-lib:graphing:polygon');
18
16
 
@@ -366,16 +364,8 @@ export default class Component extends React.Component {
366
364
  };
367
365
 
368
366
  render() {
369
- const {
370
- coordinatesOnHover,
371
- mark,
372
- graphProps,
373
- onClick,
374
- isToolActive,
375
- labelNode,
376
- labelModeEnabled,
377
- limitLabeling,
378
- } = this.props;
367
+ const { coordinatesOnHover, mark, graphProps, onClick, isToolActive, labelNode, labelModeEnabled, limitLabeling } =
368
+ this.props;
379
369
  const { mark: stateMark } = this.state;
380
370
 
381
371
  return (
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import { styled } from '@mui/material/styles';
4
- import { types, gridDraggable } from '@pie-lib/plot';
4
+ import { gridDraggable, types } from '@pie-lib/plot';
5
5
  import { color } from '@pie-lib/render-ui';
6
6
  import * as utils from '../../utils';
7
7
  import { correct, disabled, incorrect, missing } from '../shared/styles';
@@ -64,7 +64,7 @@ export class RawPolygon extends React.Component {
64
64
  const { scale } = graphProps;
65
65
 
66
66
  const pointString = getPointString(points, scale);
67
-
67
+
68
68
  if (closed) {
69
69
  return (
70
70
  <StyledPolygon
@@ -3,6 +3,7 @@ import React from 'react';
3
3
  import { RayLine } from '../component';
4
4
  import { graphProps as getGraphProps } from '../../../__tests__/utils';
5
5
  import { utils } from '@pie-lib/plot';
6
+
6
7
  describe('RayLine', () => {
7
8
  let onChange = jest.fn();
8
9
  const renderComponent = (extras) => {
@@ -1,10 +1,10 @@
1
- import { lineToolComponent, lineBase, styles } from '../shared/line';
1
+ import { lineBase, lineToolComponent, styles } from '../shared/line';
2
2
  import React from 'react';
3
3
  import PropTypes from 'prop-types';
4
4
  import { ArrowMarker, genUid } from '../shared/arrow-head';
5
5
  import { trig, types } from '@pie-lib/plot';
6
6
  import classNames from 'classnames';
7
- import { thinnerShapesNeeded, getAdjustedGraphLimits } from '../../utils';
7
+ import { getAdjustedGraphLimits, thinnerShapesNeeded } from '../../utils';
8
8
  import { styled } from '@mui/material/styles';
9
9
 
10
10
  const StyledRayRoot = styled('g')(({ theme, disabled, correctness }) => ({
@@ -48,9 +48,7 @@ export const RayLine = (props) => {
48
48
  size={thinnerShapesNeeded(graphProps) ? 4 : 5}
49
49
  id={`${finalMarkerId}-${suffix}`}
50
50
  className={classNames(
51
- suffix === 'enabled' ? 'enabledArrow' :
52
- suffix === 'disabled' ? 'disabledArrow' :
53
- `${suffix}Arrow`
51
+ suffix === 'enabled' ? 'enabledArrow' : suffix === 'disabled' ? 'disabledArrow' : `${suffix}Arrow`,
54
52
  )}
55
53
  />
56
54
  </defs>
@@ -3,6 +3,7 @@ import React from 'react';
3
3
  import { Line } from '../component';
4
4
  import { graphProps as getGraphProps } from '../../../__tests__/utils';
5
5
  import { utils } from '@pie-lib/plot';
6
+
6
7
  const { xy } = utils;
7
8
  describe('Line', () => {
8
9
  let onChange = jest.fn();
@@ -1,4 +1,4 @@
1
- import { lineToolComponent, lineBase, styles } from '../shared/line';
1
+ import { lineBase, lineToolComponent, styles } from '../shared/line';
2
2
  import React from 'react';
3
3
  import PropTypes from 'prop-types';
4
4
  import { types } from '@pie-lib/plot';
@@ -38,8 +38,8 @@ const StyledMarker = styled('marker')(({ disabled, correctness }) => ({
38
38
  }));
39
39
 
40
40
  export const ArrowHead = ({ size, transform, points, disabled, correctness }) => (
41
- <StyledArrowHead
42
- points={points || `0,0 ${size},${size / 2} 0,${size}`}
41
+ <StyledArrowHead
42
+ points={points || `0,0 ${size},${size / 2} 0,${size}`}
43
43
  transform={transform}
44
44
  disabled={disabled}
45
45
  correctness={correctness}
@@ -64,10 +64,15 @@ export const genUid = () => {
64
64
  export const ArrowMarker = ({ id, size, className, disabled, correctness }) => {
65
65
  // Parse styling info from className if provided (for backward compatibility)
66
66
  const isDisabled = disabled || className?.includes('disabled');
67
- const parsedCorrectness = correctness ||
68
- (className?.includes('incorrect') ? 'incorrect' :
69
- className?.includes('correct') ? 'correct' :
70
- className?.includes('missing') ? 'missing' : null);
67
+ const parsedCorrectness =
68
+ correctness ||
69
+ (className?.includes('incorrect')
70
+ ? 'incorrect'
71
+ : className?.includes('correct')
72
+ ? 'correct'
73
+ : className?.includes('missing')
74
+ ? 'missing'
75
+ : null);
71
76
 
72
77
  return (
73
78
  <StyledMarker
@@ -1,4 +1,4 @@
1
- import { lineTool, lineToolComponent, lineBase } from '../index';
1
+ import { lineBase, lineTool, lineToolComponent } from '../index';
2
2
  import { utils } from '@pie-lib/plot';
3
3
  import { render } from '@pie-lib/test-utils';
4
4
  import React from 'react';
@@ -1,11 +1,11 @@
1
1
  import { render } from '@pie-lib/test-utils';
2
2
  import React from 'react';
3
3
  import { graphProps as getGraphProps } from '../../../../__tests__/utils';
4
- import { gridDraggable, utils } from '@pie-lib/plot';
5
- const { xy } = utils;
6
-
4
+ import { utils } from '@pie-lib/plot';
7
5
  import * as lineUtils from '../../../../utils';
8
6
 
7
+ const { xy } = utils;
8
+
9
9
  const { bounds, pointsToArea } = lineUtils;
10
10
  jest.mock('../../../../utils', () => {
11
11
  const a = jest.requireActual('../../../../utils');
@@ -1,9 +1,9 @@
1
1
  import { render } from '@pie-lib/test-utils';
2
2
  import React from 'react';
3
- import { rootEdgeComponent, withRootEdge, rootEdgeToFromToWrapper } from '../with-root-edge';
3
+ import { rootEdgeComponent, rootEdgeToFromToWrapper } from '../with-root-edge';
4
4
  import { graphProps as getGraphProps } from '../../../../__tests__/utils';
5
5
  import { utils } from '@pie-lib/plot';
6
- import { lineToolComponent, LineToolMockComponent } from '../index';
6
+
7
7
  const { xy } = utils;
8
8
  jest.mock('../index', () => {
9
9
  const out = {
@@ -1,15 +1,13 @@
1
1
  import React from 'react';
2
- import isEqual from 'lodash/isEqual';
3
- import cloneDeep from 'lodash/cloneDeep';
2
+ import { cloneDeep, isEmpty, isEqual } from 'lodash-es';
4
3
  import { BasePoint } from '../point';
5
- import { types, utils, gridDraggable, trig } from '@pie-lib/plot';
4
+ import { gridDraggable, trig, types, utils } from '@pie-lib/plot';
6
5
  import PropTypes from 'prop-types';
7
- import { disabled, disabledSecondary, correct, incorrect, missing } from '../styles';
6
+ import { correct, disabled, disabledSecondary, incorrect, missing } from '../styles';
8
7
  import ReactDOM from 'react-dom';
9
8
  import MarkLabel from '../../../mark-label';
10
- import isEmpty from 'lodash/isEmpty';
11
9
  import { color } from '@pie-lib/render-ui';
12
- import { getMiddleOfTwoPoints, equalPoints, sameAxes } from '../../../utils';
10
+ import { equalPoints, getMiddleOfTwoPoints, sameAxes } from '../../../utils';
13
11
  import { styled } from '@mui/material/styles';
14
12
 
15
13
  const StyledLineGroup = styled('g')(({ disabled, correctness }) => ({
@@ -2,7 +2,7 @@ import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import { styled } from '@mui/material/styles';
4
4
  import { types } from '@pie-lib/plot';
5
- import { disabled, correct, incorrect, missing, disabledSecondary } from '../styles';
5
+ import { correct, disabled, disabledSecondary, incorrect, missing } from '../styles';
6
6
  import * as vx from '@visx/shape';
7
7
  import { color } from '@pie-lib/render-ui';
8
8
 
@@ -72,13 +72,7 @@ export class RawLinePath extends React.Component {
72
72
 
73
73
  return (
74
74
  <React.Fragment>
75
- <StyledDrawLine
76
- data={data}
77
- className={className}
78
- disabled={disabled}
79
- correctness={correctness}
80
- {...rest}
81
- />
75
+ <StyledDrawLine data={data} className={className} disabled={disabled} correctness={correctness} {...rest} />
82
76
  <StyledLine
83
77
  data={data}
84
78
  className={className}
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import { types } from '@pie-lib/plot';
4
- import { getAngleDeg, arrowDimensions } from '../../../utils';
4
+ import { arrowDimensions, getAngleDeg } from '../../../utils';
5
5
 
6
6
  export class RawArrow extends React.Component {
7
7
  static propTypes = {
@@ -39,10 +39,7 @@ export class RawArrow extends React.Component {
39
39
 
40
40
  return (
41
41
  <g className={className} {...rest}>
42
- <polygon
43
- points={points}
44
- transform={`translate(${scale.x(x)}, ${scale.y(y)}) rotate(${angle} 0 0)`}
45
- />
42
+ <polygon points={points} transform={`translate(${scale.x(x)}, ${scale.y(y)}) rotate(${angle} 0 0)`} />
46
43
  </g>
47
44
  );
48
45
  }
@@ -1,6 +1,6 @@
1
1
  import debug from 'debug';
2
- import { sinY, buildDataPoints, getAmplitudeAndFreq, FREQ_DIVIDER } from '@pie-lib/graphing-utils';
3
- import { withRootEdge, rootEdgeComponent } from '../shared/line/with-root-edge';
2
+ import { buildDataPoints, FREQ_DIVIDER, getAmplitudeAndFreq, sinY } from '@pie-lib/graphing-utils';
3
+ import { rootEdgeComponent, withRootEdge } from '../shared/line/with-root-edge';
4
4
 
5
5
  const log = debug('pie-lib:graphing:sine');
6
6
 
@@ -1,4 +1,4 @@
1
- import { lineToolComponent, lineBase, styles } from '../shared/line';
1
+ import { lineBase, lineToolComponent, styles } from '../shared/line';
2
2
  import { Arrow } from '../shared/point';
3
3
  import React from 'react';
4
4
  import PropTypes from 'prop-types';
package/src/undo-redo.jsx CHANGED
@@ -31,15 +31,9 @@ export class UndoRedo extends React.Component {
31
31
  const { className, onUndo, onRedo, onReset, language } = this.props;
32
32
  return (
33
33
  <div className={classNames(className)}>
34
- <StyledButton onClick={() => onUndo(true)}>
35
- {translator.t('common:undo', { lng: language })}
36
- </StyledButton>
37
- <StyledButton onClick={() => onRedo(true)}>
38
- {translator.t('graphing.redo', { lng: language })}
39
- </StyledButton>
40
- <StyledButton onClick={() => onReset()}>
41
- {translator.t('graphing.reset', { lng: language })}
42
- </StyledButton>
34
+ <StyledButton onClick={() => onUndo(true)}>{translator.t('common:undo', { lng: language })}</StyledButton>
35
+ <StyledButton onClick={() => onRedo(true)}>{translator.t('graphing.redo', { lng: language })}</StyledButton>
36
+ <StyledButton onClick={() => onReset()}>{translator.t('graphing.reset', { lng: language })}</StyledButton>
43
37
  </div>
44
38
  );
45
39
  }
@@ -1,4 +1,4 @@
1
- import { useState, useEffect } from 'react';
1
+ import { useEffect, useState } from 'react';
2
2
 
3
3
  export const useDebounce = (value, delay) => {
4
4
  const [debouncedValue, setDebouncedValue] = useState(value);
package/src/utils.js CHANGED
@@ -1,10 +1,6 @@
1
- import head from 'lodash/head';
2
- import tail from 'lodash/tail';
3
1
  import { utils } from '@pie-lib/plot';
4
2
  import invariant from 'invariant';
5
- import isEqual from 'lodash/isEqual';
6
- import isEmpty from 'lodash/isEmpty';
7
- import cloneDeep from 'lodash/cloneDeep';
3
+ import { cloneDeep, head, isEmpty, isEqual, tail } from 'lodash-es';
8
4
 
9
5
  export const tickCount = utils.tickCount;
10
6
  export const bounds = utils.bounds;