@pie-lib/graphing-solution-set 2.34.3-next.0 → 2.34.3-next.155

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 (142) hide show
  1. package/CHANGELOG.md +7 -78
  2. package/esm/package.json +3 -0
  3. package/lib/axis/arrow.js +19 -55
  4. package/lib/axis/arrow.js.map +1 -1
  5. package/lib/axis/axes.js +103 -193
  6. package/lib/axis/axes.js.map +1 -1
  7. package/lib/axis/index.js +1 -6
  8. package/lib/axis/index.js.map +1 -1
  9. package/lib/bg.js +21 -49
  10. package/lib/bg.js.map +1 -1
  11. package/lib/container/actions.js +2 -8
  12. package/lib/container/actions.js.map +1 -1
  13. package/lib/container/index.js +14 -60
  14. package/lib/container/index.js.map +1 -1
  15. package/lib/container/marks.js +1 -6
  16. package/lib/container/marks.js.map +1 -1
  17. package/lib/container/middleware.js +2 -8
  18. package/lib/container/middleware.js.map +1 -1
  19. package/lib/container/reducer.js +1 -8
  20. package/lib/container/reducer.js.map +1 -1
  21. package/lib/coordinates-label.js +23 -55
  22. package/lib/coordinates-label.js.map +1 -1
  23. package/lib/graph-with-controls.js +129 -203
  24. package/lib/graph-with-controls.js.map +1 -1
  25. package/lib/graph.js +61 -126
  26. package/lib/graph.js.map +1 -1
  27. package/lib/grid-setup.js +168 -224
  28. package/lib/grid-setup.js.map +1 -1
  29. package/lib/grid.js +29 -74
  30. package/lib/grid.js.map +1 -1
  31. package/lib/index.js +1 -12
  32. package/lib/index.js.map +1 -1
  33. package/lib/labels.js +84 -184
  34. package/lib/labels.js.map +1 -1
  35. package/lib/mark-label.js +39 -88
  36. package/lib/mark-label.js.map +1 -1
  37. package/lib/toggle-bar.js +155 -243
  38. package/lib/toggle-bar.js.map +1 -1
  39. package/lib/tool-menu.js +93 -200
  40. package/lib/tool-menu.js.map +1 -1
  41. package/lib/tools/index.js +2 -7
  42. package/lib/tools/index.js.map +1 -1
  43. package/lib/tools/line/component.js +48 -62
  44. package/lib/tools/line/component.js.map +1 -1
  45. package/lib/tools/line/index.js +1 -6
  46. package/lib/tools/line/index.js.map +1 -1
  47. package/lib/tools/polygon/component.js +76 -173
  48. package/lib/tools/polygon/component.js.map +1 -1
  49. package/lib/tools/polygon/index.js +6 -23
  50. package/lib/tools/polygon/index.js.map +1 -1
  51. package/lib/tools/polygon/line.js +48 -85
  52. package/lib/tools/polygon/line.js.map +1 -1
  53. package/lib/tools/polygon/polygon.js +62 -102
  54. package/lib/tools/polygon/polygon.js.map +1 -1
  55. package/lib/tools/shared/arrow-head.js +7 -20
  56. package/lib/tools/shared/arrow-head.js.map +1 -1
  57. package/lib/tools/shared/line/index.js +89 -185
  58. package/lib/tools/shared/line/index.js.map +1 -1
  59. package/lib/tools/shared/line/line-path.js +71 -95
  60. package/lib/tools/shared/line/line-path.js.map +1 -1
  61. package/lib/tools/shared/line/with-root-edge.js +22 -56
  62. package/lib/tools/shared/line/with-root-edge.js.map +1 -1
  63. package/lib/tools/shared/point/arrow-point.js +18 -45
  64. package/lib/tools/shared/point/arrow-point.js.map +1 -1
  65. package/lib/tools/shared/point/arrow.js +16 -42
  66. package/lib/tools/shared/point/arrow.js.map +1 -1
  67. package/lib/tools/shared/point/base-point.js +44 -58
  68. package/lib/tools/shared/point/base-point.js.map +1 -1
  69. package/lib/tools/shared/point/index.js +38 -52
  70. package/lib/tools/shared/point/index.js.map +1 -1
  71. package/lib/tools/shared/styles.js +8 -31
  72. package/lib/tools/shared/styles.js.map +1 -1
  73. package/lib/tools/shared/types.js +1 -5
  74. package/lib/tools/shared/types.js.map +1 -1
  75. package/lib/undo-redo.js +27 -67
  76. package/lib/undo-redo.js.map +1 -1
  77. package/lib/use-debounce.js +4 -11
  78. package/lib/use-debounce.js.map +1 -1
  79. package/lib/utils.js +56 -131
  80. package/lib/utils.js.map +1 -1
  81. package/package.json +34 -23
  82. package/src/__tests__/graph-with-controls.test.jsx +23 -10
  83. package/src/__tests__/graph.test.jsx +36 -171
  84. package/src/__tests__/grid.test.jsx +9 -6
  85. package/src/__tests__/labels.test.jsx +11 -8
  86. package/src/__tests__/mark-label.test.jsx +15 -17
  87. package/src/__tests__/toggle-bar.test.jsx +46 -17
  88. package/src/__tests__/tool-menu.test.jsx +12 -8
  89. package/src/__tests__/undo-redo.test.jsx +9 -8
  90. package/src/__tests__/utils.js +3 -0
  91. package/src/axis/__tests__/arrow.test.jsx +21 -17
  92. package/src/axis/__tests__/axes.test.jsx +117 -155
  93. package/src/axis/arrow.jsx +7 -12
  94. package/src/axis/axes.jsx +41 -51
  95. package/src/coordinates-label.jsx +13 -18
  96. package/src/graph-with-controls.jsx +90 -93
  97. package/src/grid-setup.jsx +210 -206
  98. package/src/grid.jsx +2 -4
  99. package/src/labels.jsx +83 -124
  100. package/src/mark-label.jsx +14 -25
  101. package/src/toggle-bar.jsx +135 -163
  102. package/src/tool-menu.jsx +136 -195
  103. package/src/tools/line/__tests__/component.test.jsx +7 -7
  104. package/src/tools/line/component.jsx +29 -29
  105. package/src/tools/polygon/__tests__/component.test.jsx +13 -152
  106. package/src/tools/polygon/__tests__/line.test.jsx +7 -9
  107. package/src/tools/polygon/__tests__/polygon.test.jsx +8 -8
  108. package/src/tools/polygon/component.jsx +2 -4
  109. package/src/tools/polygon/line.jsx +26 -24
  110. package/src/tools/polygon/polygon.jsx +35 -40
  111. package/src/tools/shared/__tests__/arrow-head.test.jsx +16 -17
  112. package/src/tools/shared/line/__tests__/index.test.jsx +26 -163
  113. package/src/tools/shared/line/__tests__/line-path.test.jsx +9 -9
  114. package/src/tools/shared/line/__tests__/with-root-edge.test.jsx +14 -24
  115. package/src/tools/shared/line/index.jsx +3 -3
  116. package/src/tools/shared/line/line-path.jsx +51 -48
  117. package/src/tools/shared/line/with-root-edge.jsx +1 -1
  118. package/src/tools/shared/point/__tests__/arrow-point.test.jsx +15 -11
  119. package/src/tools/shared/point/__tests__/base-point.test.jsx +14 -11
  120. package/src/tools/shared/point/base-point.jsx +33 -6
  121. package/src/tools/shared/point/index.jsx +30 -32
  122. package/src/undo-redo.jsx +16 -24
  123. package/src/__tests__/__snapshots__/graph-with-controls.test.jsx.snap +0 -114
  124. package/src/__tests__/__snapshots__/graph.test.jsx.snap +0 -213
  125. package/src/__tests__/__snapshots__/grid.test.jsx.snap +0 -54
  126. package/src/__tests__/__snapshots__/labels.test.jsx.snap +0 -30
  127. package/src/__tests__/__snapshots__/mark-label.test.jsx.snap +0 -37
  128. package/src/__tests__/__snapshots__/toggle-bar.test.jsx.snap +0 -7
  129. package/src/__tests__/__snapshots__/tool-menu.test.jsx.snap +0 -35
  130. package/src/__tests__/__snapshots__/undo-redo.test.jsx.snap +0 -15
  131. package/src/axis/__tests__/__snapshots__/arrow.test.jsx.snap +0 -33
  132. package/src/axis/__tests__/__snapshots__/axes.test.jsx.snap +0 -122
  133. package/src/tools/line/__tests__/__snapshots__/component.test.jsx.snap +0 -20
  134. package/src/tools/polygon/__tests__/__snapshots__/component.test.jsx.snap +0 -94
  135. package/src/tools/polygon/__tests__/__snapshots__/line.test.jsx.snap +0 -44
  136. package/src/tools/polygon/__tests__/__snapshots__/polygon.test.jsx.snap +0 -53
  137. package/src/tools/shared/__tests__/__snapshots__/arrow-head.test.jsx.snap +0 -32
  138. package/src/tools/shared/line/__tests__/__snapshots__/index.test.jsx.snap +0 -360
  139. package/src/tools/shared/line/__tests__/__snapshots__/line-path.test.jsx.snap +0 -57
  140. package/src/tools/shared/line/__tests__/__snapshots__/with-root-edge.test.jsx.snap +0 -63
  141. package/src/tools/shared/point/__tests__/__snapshots__/arrow-point.test.jsx.snap +0 -55
  142. package/src/tools/shared/point/__tests__/__snapshots__/base-point.test.jsx.snap +0 -43
@@ -1,13 +1,13 @@
1
- import { shallow } from 'enzyme';
1
+ import { render } from '@pie-lib/test-utils';
2
2
  import React from 'react';
3
3
  import { graphProps } from '../../__tests__/utils';
4
4
 
5
5
  import Axes, { RawXAxis, RawYAxis, firstNegativeValue, sharedValues } from '../axes';
6
6
 
7
7
  describe('RawXAxis', () => {
8
- let w;
9
8
  let onChange = jest.fn();
10
- const wrapper = (extras) => {
9
+
10
+ const renderComponent = (extras) => {
11
11
  const defaults = {
12
12
  classes: {},
13
13
  className: 'className',
@@ -19,22 +19,27 @@ describe('RawXAxis', () => {
19
19
  up: true,
20
20
  down: true,
21
21
  },
22
+ columnTicksValues: [-1, 0, 1],
23
+ skipValues: [],
24
+ distanceFromOriginToFirstNegativeY: 0,
25
+ dy: 0,
22
26
  };
23
27
  const props = { ...defaults, ...extras };
24
- return shallow(<RawXAxis {...props} />);
28
+ return render(<RawXAxis {...props} />);
25
29
  };
26
- describe('snapshot', () => {
27
- it('renders', () => {
28
- w = wrapper();
29
- expect(w).toMatchSnapshot();
30
+
31
+ describe('rendering', () => {
32
+ it('renders without crashing', () => {
33
+ const { container } = renderComponent();
34
+ expect(container.firstChild).toBeInTheDocument();
30
35
  });
31
36
  });
32
37
  });
33
38
 
34
39
  describe('RawYAxis', () => {
35
- let w;
36
40
  let onChange = jest.fn();
37
- const wrapper = (extras) => {
41
+
42
+ const renderComponent = (extras) => {
38
43
  const defaults = {
39
44
  classes: {},
40
45
  className: 'className',
@@ -46,14 +51,17 @@ describe('RawYAxis', () => {
46
51
  up: true,
47
52
  down: true,
48
53
  },
54
+ rowTickValues: [-1, 0, 1],
55
+ skipValues: [],
49
56
  };
50
57
  const props = { ...defaults, ...extras };
51
- return shallow(<RawYAxis {...props} />);
58
+ return render(<RawYAxis {...props} />);
52
59
  };
53
- describe('snapshot', () => {
54
- it('renders', () => {
55
- w = wrapper();
56
- expect(w).toMatchSnapshot();
60
+
61
+ describe('rendering', () => {
62
+ it('renders without crashing', () => {
63
+ const { container } = renderComponent();
64
+ expect(container.firstChild).toBeInTheDocument();
57
65
  });
58
66
  });
59
67
  });
@@ -61,160 +69,114 @@ describe('RawYAxis', () => {
61
69
  const customScaleMock = (distance) => {
62
70
  const fn = jest.fn((n) => n * distance);
63
71
  fn.invert = jest.fn((n) => n * distance);
72
+ fn.domain = jest.fn(() => fn);
73
+ fn.range = jest.fn(() => fn);
74
+ fn.copy = jest.fn(() => customScaleMock(distance));
64
75
  return fn;
65
76
  };
66
77
 
67
- describe.only('Axes', () => {
68
- let w;
69
- let onChange = jest.fn();
70
-
71
- const customGraphProps = {
72
- ...graphProps(),
73
- domain: {
74
- min: -2,
75
- max: 2,
76
- labelStep: 1,
77
- step: 1,
78
- },
79
- range: {
80
- min: -2,
81
- max: 2,
82
- step: 1,
83
- labelStep: 1,
84
- },
85
- scale: {
86
- x: customScaleMock(200),
87
- y: customScaleMock(150),
88
- },
89
- };
90
-
91
- const wrapper = (extras) => {
92
- const defaults = {
93
- classes: {},
94
- className: 'className',
95
- onChange,
96
- graphProps: customGraphProps,
97
- };
78
+ // Note: Instance method tests (xValues, yValues) have been removed.
79
+ // These methods are internal implementation details and should be tested through
80
+ // component rendering and integration tests that verify the axes render correctly.
98
81
 
99
- const props = { ...defaults, ...extras };
100
- return shallow(<Axes {...props} />);
101
- };
102
- describe('xValues', () => {
103
- it('renders', () => {
104
- w = wrapper();
105
- const result = w.instance().xValues();
106
- expect(result).toEqual({
107
- columnTicksValues: expect.arrayContaining([-2, -1, 0, 1, 2]),
108
- distanceFromOriginToFirstNegativeX: 150,
109
- firstNegativeX: -1,
110
- });
111
- });
112
- });
113
- describe('yValues', () => {
114
- it('renders', () => {
115
- w = wrapper();
116
- const result = w.instance().yValues();
117
- expect(result).toEqual({
118
- rowTickValues: expect.arrayContaining([-2, -1, 0, 1, 2]),
119
- distanceFromOriginToFirstNegativeY: 200,
120
- firstNegativeY: -1,
121
- });
122
- });
82
+ describe('firstNegativeValue', () => {
83
+ it('should return undefined for undefined interval', () => {
84
+ const interval = undefined;
85
+ const result = firstNegativeValue(interval);
86
+ expect(result).toEqual(undefined);
123
87
  });
124
- });
125
88
 
126
- describe('firstNegativeValue should return undefiend for undefined interval', () => {
127
- const interval = undefined;
128
- const result = firstNegativeValue(interval);
129
- expect(result).toEqual(undefined);
130
- });
131
-
132
- describe('firstNegativeValue should return undefiend for empty interval', () => {
133
- const interval = [];
134
- const result = firstNegativeValue(interval);
135
- expect(result).toEqual(undefined);
136
- });
137
-
138
- describe('firstNegativeValue should return undefined if there is no negative in interval array', () => {
139
- const interval = [1, 5, 7, 4, 5];
140
- const result = firstNegativeValue(interval);
141
- expect(result).toEqual(undefined);
142
- });
143
-
144
- describe('firstNegativeValue should return first negative number from interval', () => {
145
- const interval = [1, 5, 7, -2, 4, 5, -1];
146
- const result = firstNegativeValue(interval);
147
- expect(result).toEqual(-2);
148
- });
149
-
150
- describe('skipValue should be empty array if firstNegativeValue for one of the axes is undefined', () => {
151
- // x
152
- const intervalX = [1, 2, 3, 4, 5, 6];
153
- const firstNegativeX = firstNegativeValue(intervalX);
154
- const distanceFromOriginToFirstNegativeX = -22;
155
-
156
- // y
157
- const intervalY = [-1, -2, 1, 2, 3, 4, 5, 6];
158
- const firstNegativeY = firstNegativeValue(intervalY);
159
- const distanceFromOriginToFirstNegativeY = -22;
160
-
161
- const deltaAllowance = 5;
89
+ it('should return undefined for empty interval', () => {
90
+ const interval = [];
91
+ const result = firstNegativeValue(interval);
92
+ expect(result).toEqual(undefined);
93
+ });
162
94
 
163
- const result = sharedValues(
164
- firstNegativeX,
165
- firstNegativeY,
166
- distanceFromOriginToFirstNegativeX,
167
- distanceFromOriginToFirstNegativeY,
168
- deltaAllowance,
169
- );
95
+ it('should return undefined if there is no negative in interval array', () => {
96
+ const interval = [1, 5, 7, 4, 5];
97
+ const result = firstNegativeValue(interval);
98
+ expect(result).toEqual(undefined);
99
+ });
170
100
 
171
- expect(result).toEqual([]);
101
+ it('should return first negative number from interval', () => {
102
+ const interval = [1, 5, 7, -2, 4, 5, -1];
103
+ const result = firstNegativeValue(interval);
104
+ expect(result).toEqual(-2);
105
+ });
172
106
  });
173
107
 
174
- describe('skipValue should be empty array if firstNegativeX and firstNegativeY are equal but they do not overlap', () => {
175
- // x
176
- const intervalX = [-1, -2, 1, 2, 3, 4, 5, 6];
177
- const firstNegativeX = firstNegativeValue(intervalX);
178
- const distanceFromOriginToFirstNegativeX = -7;
179
-
180
- // y
181
- const intervalY = [-1, -2, 1, 2, 3, 4, 5, 6];
182
- const firstNegativeY = firstNegativeValue(intervalY);
183
- const distanceFromOriginToFirstNegativeY = -22;
184
-
185
- const deltaAllowance = 5;
186
-
187
- const result = sharedValues(
188
- firstNegativeX,
189
- firstNegativeY,
190
- distanceFromOriginToFirstNegativeX,
191
- distanceFromOriginToFirstNegativeY,
192
- deltaAllowance,
193
- );
108
+ describe('sharedValues', () => {
109
+ it('should be empty array if firstNegativeValue for one of the axes is undefined', () => {
110
+ // x
111
+ const intervalX = [1, 2, 3, 4, 5, 6];
112
+ const firstNegativeX = firstNegativeValue(intervalX);
113
+ const distanceFromOriginToFirstNegativeX = -22;
114
+
115
+ // y
116
+ const intervalY = [-1, -2, 1, 2, 3, 4, 5, 6];
117
+ const firstNegativeY = firstNegativeValue(intervalY);
118
+ const distanceFromOriginToFirstNegativeY = -22;
119
+
120
+ const deltaAllowance = 5;
121
+
122
+ const result = sharedValues(
123
+ firstNegativeX,
124
+ firstNegativeY,
125
+ distanceFromOriginToFirstNegativeX,
126
+ distanceFromOriginToFirstNegativeY,
127
+ deltaAllowance,
128
+ );
129
+
130
+ expect(result).toEqual([]);
131
+ });
194
132
 
195
- expect(result).toEqual([]);
196
- });
133
+ it('should be empty array if firstNegativeX and firstNegativeY are equal but they do not overlap', () => {
134
+ // x
135
+ const intervalX = [-1, -2, 1, 2, 3, 4, 5, 6];
136
+ const firstNegativeX = firstNegativeValue(intervalX);
137
+ const distanceFromOriginToFirstNegativeX = -7;
197
138
 
198
- describe('skipValue should be -1 if firstNegativeX and firstNegativeY are equal and they overlap', () => {
199
- // x
200
- const intervalX = [-1, -2, 1, 2, 3, 4, 5, 6];
201
- const firstNegativeX = firstNegativeValue(intervalX);
202
- const distanceFromOriginToFirstNegativeX = -20;
139
+ // y
140
+ const intervalY = [-1, -2, 1, 2, 3, 4, 5, 6];
141
+ const firstNegativeY = firstNegativeValue(intervalY);
142
+ const distanceFromOriginToFirstNegativeY = -22;
203
143
 
204
- // y
205
- const intervalY = [-1, -2, 1, 2, 3, 4, 5, 6];
206
- const firstNegativeY = firstNegativeValue(intervalY);
207
- const distanceFromOriginToFirstNegativeY = -22;
144
+ const deltaAllowance = 5;
208
145
 
209
- const deltaAllowance = 5;
146
+ const result = sharedValues(
147
+ firstNegativeX,
148
+ firstNegativeY,
149
+ distanceFromOriginToFirstNegativeX,
150
+ distanceFromOriginToFirstNegativeY,
151
+ deltaAllowance,
152
+ );
210
153
 
211
- const result = sharedValues(
212
- firstNegativeX,
213
- firstNegativeY,
214
- distanceFromOriginToFirstNegativeX,
215
- distanceFromOriginToFirstNegativeY,
216
- deltaAllowance,
217
- );
154
+ expect(result).toEqual([]);
155
+ });
218
156
 
219
- expect(result).toEqual([-1]);
157
+ it('should be -1 if firstNegativeX and firstNegativeY are equal and they overlap', () => {
158
+ // x
159
+ const intervalX = [-1, -2, 1, 2, 3, 4, 5, 6];
160
+ const firstNegativeX = firstNegativeValue(intervalX);
161
+ const distanceFromOriginToFirstNegativeX = -20;
162
+
163
+ // y
164
+ const intervalY = [-1, -2, 1, 2, 3, 4, 5, 6];
165
+ const firstNegativeY = firstNegativeValue(intervalY);
166
+ const distanceFromOriginToFirstNegativeY = -22;
167
+
168
+ const deltaAllowance = 5;
169
+ const dy = -20; // dy needs to be within the range for the condition to pass
170
+
171
+ const result = sharedValues(
172
+ firstNegativeX,
173
+ firstNegativeY,
174
+ distanceFromOriginToFirstNegativeX,
175
+ distanceFromOriginToFirstNegativeY,
176
+ deltaAllowance,
177
+ dy,
178
+ );
179
+
180
+ expect(result).toEqual([-1]);
181
+ });
220
182
  });
@@ -1,20 +1,16 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
 
4
- import classNames from 'classnames';
5
- import { withStyles } from '@material-ui/core/styles';
4
+ import { styled } from '@mui/material/styles';
6
5
  import { types } from '@pie-lib/plot';
7
6
 
8
- const style = (theme) => ({
9
- root: {
10
- fill: `var(--arrow-color, ${theme.palette.common.black})`,
11
- },
12
- });
7
+ const StyledPath = styled('path')(({ theme }) => ({
8
+ fill: `var(--arrow-color, ${theme.palette.common.black})`,
9
+ }));
13
10
 
14
11
  export class Arrow extends React.Component {
15
12
  render() {
16
- const { x, y, classes, className, scale } = this.props;
17
- const names = classNames(classes.root, className);
13
+ const { x, y, className, scale } = this.props;
18
14
  let direction = this.props.direction || 'left';
19
15
 
20
16
  const xv = scale.x(x);
@@ -40,7 +36,7 @@ export class Arrow extends React.Component {
40
36
  transform = getTransform(xv, yv + 15, 270);
41
37
  }
42
38
 
43
- return <path d="m 0,0 8,-5 0,10 -8,-5" transform={transform} className={names} />;
39
+ return <StyledPath d="m 0,0 8,-5 0,10 -8,-5" transform={transform} className={className} />;
44
40
  }
45
41
  }
46
42
 
@@ -48,7 +44,6 @@ Arrow.propTypes = {
48
44
  y: PropTypes.number,
49
45
  x: PropTypes.number,
50
46
  direction: PropTypes.oneOf(['left', 'right', 'up', 'down']),
51
- classes: PropTypes.object.isRequired,
52
47
  className: PropTypes.string,
53
48
  scale: types.ScaleType.isRequired,
54
49
  };
@@ -59,4 +54,4 @@ Arrow.defaultProps = {
59
54
  direction: 'left',
60
55
  };
61
56
 
62
- export default withStyles(style)(Arrow);
57
+ export default Arrow;
package/src/axis/axes.jsx CHANGED
@@ -1,9 +1,9 @@
1
1
  import React from 'react';
2
- import { Axis } from '@vx/axis';
2
+ import { Axis } from '@visx/axis';
3
3
  import { types } from '@pie-lib/plot';
4
4
  import PropTypes from 'prop-types';
5
5
  import Arrow from './arrow';
6
- import { withStyles } from '@material-ui/core';
6
+ import { styled } from '@mui/material/styles';
7
7
  import { countWords, findLongestWord, amountToIncreaseWidth, getTickValues } from '../utils';
8
8
  import { color, Readable } from '@pie-lib/render-ui';
9
9
 
@@ -21,33 +21,36 @@ const AxisDefaultProps = {
21
21
  },
22
22
  };
23
23
 
24
- const axisStyles = (theme) => ({
25
- line: {
24
+ const StyledAxesGroup = styled('g')(() => ({
25
+ '& .visx-axis-line': {
26
26
  stroke: '#8a92c0',
27
27
  strokeWidth: 4,
28
28
  },
29
- arrow: {
30
- fill: '#8a92c0',
31
- },
32
- tick: {
29
+ '& .visx-axis-tick': {
33
30
  fill: color.defaults.BLACK,
34
31
  '& > line': {
35
32
  stroke: '#8a92c0',
36
33
  },
37
34
  },
38
- labelFontSize: {
39
- fontSize: theme.typography.fontSize,
40
- },
41
- axisLabelHolder: {
42
- padding: 0,
35
+ }));
36
+
37
+ const LabelContainer = styled('div')(({ theme }) => ({
38
+ fontSize: theme.typography.fontSize,
39
+ }));
40
+
41
+ const AxisLabelHolder = styled('div')(({ theme }) => ({
42
+ padding: 0,
43
+ margin: 0,
44
+ textAlign: 'center',
45
+ '* > *': {
43
46
  margin: 0,
44
- textAlign: 'center',
45
- '* > *': {
46
- margin: 0,
47
- padding: 0,
48
- },
49
- fontSize: theme.typography.fontSize,
47
+ padding: 0,
50
48
  },
49
+ fontSize: theme.typography.fontSize,
50
+ }));
51
+
52
+ const StyledArrow = styled(Arrow)({
53
+ fill: '#8a92c0',
51
54
  });
52
55
 
53
56
  const tickLabelStyles = {
@@ -84,7 +87,6 @@ export const firstNegativeValue = (interval) => (interval || []).find((element)
84
87
  export class RawXAxis extends React.Component {
85
88
  static propTypes = {
86
89
  ...AxisPropTypes,
87
- classes: PropTypes.object,
88
90
  graphProps: types.GraphPropsType.isRequired,
89
91
  };
90
92
  static defaultProps = AxisDefaultProps;
@@ -92,7 +94,6 @@ export class RawXAxis extends React.Component {
92
94
  render() {
93
95
  const {
94
96
  includeArrows,
95
- classes,
96
97
  graphProps,
97
98
  columnTicksValues,
98
99
  skipValues,
@@ -101,12 +102,6 @@ export class RawXAxis extends React.Component {
101
102
  } = this.props;
102
103
  const { scale, domain, size, range } = graphProps || {};
103
104
 
104
- // Having 0 as a number in columnTicksValues does not make 0 to show up
105
- // so we use this trick, by defining it as a string:
106
- const tickValues =
107
- (domain.labelStep || range.labelStep) && domain.min <= 0 ? ['0', ...columnTicksValues] : columnTicksValues;
108
- // However, the '0' has to be displayed only if other tick labels (y-axis or x-axis) are displayed
109
-
110
105
  const labelProps = (label) => {
111
106
  const y = skipValues && skipValues[0] === label ? distanceFromOriginToFirstNegativeY + 4 : dy;
112
107
 
@@ -114,8 +109,8 @@ export class RawXAxis extends React.Component {
114
109
  ...tickLabelStyles,
115
110
  textAnchor: 'middle',
116
111
  y: y,
117
- dx: label === '0' ? -10 : 0,
118
- dy: label === '0' ? -7 : 0,
112
+ dx: label === 0 ? -10 : 0,
113
+ dy: label === 0 ? -7 : 0,
119
114
  };
120
115
  };
121
116
 
@@ -124,36 +119,35 @@ export class RawXAxis extends React.Component {
124
119
  const necessaryWidth = amountToIncreaseWidth(longestWord) + 2;
125
120
 
126
121
  return (
127
- <React.Fragment>
122
+ <StyledAxesGroup>
128
123
  <Axis
129
- axisLineClassName={classes.line}
130
124
  scale={scale.x}
131
125
  top={scale.y(0)}
132
126
  left={0}
133
127
  label={domain.label}
134
128
  rangePadding={8}
135
- tickClassName={classes.tick}
136
129
  tickFormat={(value) => value}
137
130
  tickLabelProps={labelProps}
138
- tickValues={tickValues}
131
+ tickValues={columnTicksValues}
132
+ hideZero={!(domain.labelStep || range.labelStep) && domain.min <= 0}
139
133
  />
140
134
  {includeArrows && includeArrows.left && (
141
- <Arrow direction="left" x={domain.min} y={0} className={classes.arrow} scale={scale} />
135
+ <StyledArrow direction="left" x={domain.min} y={0} scale={scale} />
142
136
  )}
143
137
  {includeArrows && includeArrows.right && (
144
- <Arrow direction="right" x={domain.max} y={0} className={classes.arrow} scale={scale} />
138
+ <StyledArrow direction="right" x={domain.max} y={0} scale={scale} />
145
139
  )}
146
140
  {domain.axisLabel && (
147
141
  <foreignObject x={size.width + 17} y={scale.y(0) - 9} width={necessaryWidth} height={20 * necessaryRows}>
148
- <div dangerouslySetInnerHTML={{ __html: domain.axisLabel }} className={classes.labelFontSize} />
142
+ <LabelContainer dangerouslySetInnerHTML={{ __html: domain.axisLabel }} />
149
143
  </foreignObject>
150
144
  )}
151
- </React.Fragment>
145
+ </StyledAxesGroup>
152
146
  );
153
147
  }
154
148
  }
155
149
 
156
- const XAxis = withStyles(axisStyles)(RawXAxis);
150
+ const XAxis = RawXAxis;
157
151
 
158
152
  export class RawYAxis extends React.Component {
159
153
  static propTypes = {
@@ -163,7 +157,7 @@ export class RawYAxis extends React.Component {
163
157
  static defaultProps = AxisDefaultProps;
164
158
 
165
159
  render() {
166
- const { classes, includeArrows, graphProps, skipValues, rowTickValues } = this.props;
160
+ const { includeArrows, graphProps, skipValues, rowTickValues } = this.props;
167
161
  const { scale, range, size } = graphProps || {};
168
162
 
169
163
  const necessaryWidth = range.axisLabel ? amountToIncreaseWidth(range.axisLabel.length) : 0;
@@ -171,9 +165,8 @@ export class RawYAxis extends React.Component {
171
165
  const customTickFormat = (value) => (skipValues && skipValues.indexOf(value) >= 0 ? '' : value);
172
166
 
173
167
  return (
174
- <React.Fragment>
168
+ <StyledAxesGroup>
175
169
  <Axis
176
- axisLineClassName={classes.line}
177
170
  orientation={'left'}
178
171
  scale={scale.y}
179
172
  top={0}
@@ -183,7 +176,6 @@ export class RawYAxis extends React.Component {
183
176
  labelProps={{ 'data-pie-readable': false }}
184
177
  rangePadding={8}
185
178
  tickLength={10}
186
- tickClassName={classes.tick}
187
179
  tickFormat={customTickFormat}
188
180
  tickLabelProps={(value) => {
189
181
  let digits = value.toLocaleString().replace(/[.-]/g, '').length || 1;
@@ -199,31 +191,29 @@ export class RawYAxis extends React.Component {
199
191
  tickTextAnchor={'bottom'}
200
192
  tickValues={rowTickValues}
201
193
  />
202
-
203
194
  {includeArrows && includeArrows.down && (
204
- <Arrow direction="down" x={0} y={range.min} className={classes.arrow} scale={scale} />
195
+ <StyledArrow direction="down" x={0} y={range.min} scale={scale} />
205
196
  )}
206
197
  {includeArrows && includeArrows.up && (
207
- <Arrow direction="up" x={0} y={range.max} className={classes.arrow} scale={scale} />
198
+ <StyledArrow direction="up" x={0} y={range.max} scale={scale} />
208
199
  )}
209
200
  {range.axisLabel && (
210
201
  <foreignObject x={scale.x(0) - necessaryWidth / 2} y={-33} width={necessaryWidth} height="20">
211
202
  <Readable false>
212
- <div dangerouslySetInnerHTML={{ __html: range.axisLabel }} className={classes.axisLabelHolder} />
203
+ <AxisLabelHolder dangerouslySetInnerHTML={{ __html: range.axisLabel }} />
213
204
  </Readable>
214
205
  </foreignObject>
215
206
  )}
216
- </React.Fragment>
207
+ </StyledAxesGroup>
217
208
  );
218
209
  }
219
210
  }
220
211
 
221
- const YAxis = withStyles(axisStyles)(RawYAxis);
212
+ const YAxis = RawYAxis;
222
213
 
223
214
  export default class Axes extends React.Component {
224
215
  static propTypes = {
225
216
  ...AxisPropTypes,
226
- classes: PropTypes.object,
227
217
  graphProps: types.GraphPropsType.isRequired,
228
218
  };
229
219
  static defaultProps = AxisDefaultProps;
@@ -283,7 +273,7 @@ export default class Axes extends React.Component {
283
273
 
284
274
  // each axis has to be displayed only if the domain & range include it
285
275
  return (
286
- <React.Fragment>
276
+ <StyledAxesGroup>
287
277
  {range.min <= 0 ? (
288
278
  <XAxis
289
279
  {...this.props}
@@ -301,7 +291,7 @@ export default class Axes extends React.Component {
301
291
  distanceFromOriginToFirstNegativeX={distanceFromOriginToFirstNegativeX}
302
292
  />
303
293
  ) : null}
304
- </React.Fragment>
294
+ </StyledAxesGroup>
305
295
  );
306
296
  }
307
297
  }
@@ -2,22 +2,20 @@ import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import { types } from '@pie-lib/plot';
4
4
  import { color } from '@pie-lib/render-ui';
5
- import { withStyles } from '@material-ui/core/styles';
6
- import InputBase from '@material-ui/core/InputBase';
5
+ import { styled } from '@mui/material/styles';
6
+ import InputBase from '@mui/material/InputBase';
7
7
  import { roundNumber } from './utils';
8
8
 
9
- const styles = (theme) => ({
10
- input: {
11
- fontFamily: theme.typography.fontFamily,
12
- fontSize: theme.typography.fontSize,
13
- borderRadius: '8px',
14
- background: theme.palette.common.white,
15
- color: color.defaults.BLACK,
16
- },
17
- inputLabel: {
9
+ const StyledInputBase = styled(InputBase)(({ theme }) => ({
10
+ fontFamily: theme.typography.fontFamily,
11
+ fontSize: theme.typography.fontSize,
12
+ borderRadius: '8px',
13
+ background: theme.palette.common.white,
14
+ color: color.defaults.BLACK,
15
+ '& .MuiInputBase-input': {
18
16
  padding: 0,
19
17
  },
20
- });
18
+ }));
21
19
 
22
20
  export const getLabelPosition = (graphProps, x, y, labelLength) => {
23
21
  const { scale, domain, range } = graphProps;
@@ -39,7 +37,7 @@ export const getLabelPosition = (graphProps, x, y, labelLength) => {
39
37
  };
40
38
  };
41
39
 
42
- export const CoordinatesLabel = ({ x, y, graphProps, classes }) => {
40
+ export const CoordinatesLabel = ({ x, y, graphProps }) => {
43
41
  const label = `(${roundNumber(x)}, ${roundNumber(y)})`;
44
42
  const labelLength = (label.length || 0) * 6;
45
43
  const labelPosition = getLabelPosition(graphProps, x, y, labelLength);
@@ -53,10 +51,8 @@ export const CoordinatesLabel = ({ x, y, graphProps, classes }) => {
53
51
  };
54
52
 
55
53
  return (
56
- <InputBase
54
+ <StyledInputBase
57
55
  style={style}
58
- classes={{ input: classes.inputLabel }}
59
- className={classes.input}
60
56
  value={label}
61
57
  inputProps={{ ariaLabel: 'naked' }}
62
58
  />
@@ -65,9 +61,8 @@ export const CoordinatesLabel = ({ x, y, graphProps, classes }) => {
65
61
 
66
62
  CoordinatesLabel.propTypes = {
67
63
  graphProps: types.GraphPropsType,
68
- classes: PropTypes.object,
69
64
  x: PropTypes.number,
70
65
  y: PropTypes.number,
71
66
  };
72
67
 
73
- export default withStyles(styles)(CoordinatesLabel);
68
+ export default CoordinatesLabel;