@pie-lib/charting 6.1.1-next.0 → 6.2.0-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/lib/actions-button.js +0 -5
  2. package/lib/actions-button.js.map +1 -1
  3. package/lib/axes.js +0 -23
  4. package/lib/axes.js.map +1 -1
  5. package/lib/bars/bar.js +0 -2
  6. package/lib/bars/bar.js.map +1 -1
  7. package/lib/bars/common/bars.js +0 -13
  8. package/lib/bars/common/bars.js.map +1 -1
  9. package/lib/bars/common/correct-check-icon.js +0 -1
  10. package/lib/bars/common/correct-check-icon.js.map +1 -1
  11. package/lib/bars/histogram.js +0 -2
  12. package/lib/bars/histogram.js.map +1 -1
  13. package/lib/chart-setup.js +0 -19
  14. package/lib/chart-setup.js.map +1 -1
  15. package/lib/chart-type.js +0 -1
  16. package/lib/chart-type.js.map +1 -1
  17. package/lib/chart-types.js +0 -1
  18. package/lib/chart-types.js.map +1 -1
  19. package/lib/chart.js +2 -18
  20. package/lib/chart.js.map +1 -1
  21. package/lib/common/correctness-indicators.js +0 -4
  22. package/lib/common/correctness-indicators.js.map +1 -1
  23. package/lib/common/drag-handle.js +0 -1
  24. package/lib/common/drag-handle.js.map +1 -1
  25. package/lib/common/drag-icon.js +0 -2
  26. package/lib/common/drag-icon.js.map +1 -1
  27. package/lib/common/styles.js +0 -1
  28. package/lib/common/styles.js.map +1 -1
  29. package/lib/grid.js +0 -4
  30. package/lib/grid.js.map +1 -1
  31. package/lib/index.js +0 -1
  32. package/lib/index.js.map +1 -1
  33. package/lib/key-legend.js +0 -1
  34. package/lib/key-legend.js.map +1 -1
  35. package/lib/line/common/drag-handle.js +0 -2
  36. package/lib/line/common/drag-handle.js.map +1 -1
  37. package/lib/line/common/line.js +2 -19
  38. package/lib/line/common/line.js.map +1 -1
  39. package/lib/line/line-cross.js +0 -16
  40. package/lib/line/line-cross.js.map +1 -1
  41. package/lib/line/line-dot.js +0 -2
  42. package/lib/line/line-dot.js.map +1 -1
  43. package/lib/mark-label.js +0 -21
  44. package/lib/mark-label.js.map +1 -1
  45. package/lib/plot/common/plot.js +0 -12
  46. package/lib/plot/common/plot.js.map +1 -1
  47. package/lib/plot/dot.js +0 -3
  48. package/lib/plot/dot.js.map +1 -1
  49. package/lib/plot/line.js +0 -3
  50. package/lib/plot/line.js.map +1 -1
  51. package/lib/tool-menu.js +0 -11
  52. package/lib/tool-menu.js.map +1 -1
  53. package/lib/utils.js +0 -12
  54. package/lib/utils.js.map +1 -1
  55. package/package.json +12 -9
  56. package/src/__tests__/actions-button.test.jsx +280 -0
  57. package/src/__tests__/axes.test.jsx +557 -16
  58. package/src/__tests__/chart-setup.test.jsx +495 -10
  59. package/src/__tests__/chart.test.jsx +1 -1
  60. package/src/__tests__/grid.test.jsx +2 -2
  61. package/src/__tests__/key-legend.test.jsx +223 -0
  62. package/src/__tests__/tool-menu.test.jsx +522 -0
  63. package/src/__tests__/utils.js +1 -1
  64. package/src/axes.jsx +10 -7
  65. package/src/bars/common/bars.jsx +32 -50
  66. package/src/chart-setup.jsx +6 -9
  67. package/src/chart-type.js +3 -6
  68. package/src/chart.jsx +2 -2
  69. package/src/common/__tests__/correctness-indicators.test.jsx +720 -0
  70. package/src/common/__tests__/drag-handle.test.jsx +0 -1
  71. package/src/common/correctness-indicators.jsx +8 -13
  72. package/src/common/drag-handle.jsx +2 -12
  73. package/src/grid.jsx +1 -1
  74. package/src/line/__tests__/line-cross.test.jsx +423 -1
  75. package/src/line/__tests__/utils.js +1 -1
  76. package/src/line/common/__tests__/drag-handle.test.jsx +1 -2
  77. package/src/line/common/drag-handle.jsx +2 -11
  78. package/src/line/common/line.jsx +2 -2
  79. package/src/line/line-cross.js +7 -13
  80. package/src/mark-label.jsx +3 -3
  81. package/src/plot/__tests__/dot.test.jsx +300 -1
  82. package/src/plot/__tests__/line.test.jsx +331 -1
  83. package/src/plot/common/plot.jsx +14 -13
  84. package/src/utils.js +0 -1
  85. package/NEXT.CHANGELOG.json +0 -16
@@ -0,0 +1,522 @@
1
+ import React from 'react';
2
+ import { fireEvent, render } from '@testing-library/react';
3
+ import { createTheme, ThemeProvider } from '@mui/material/styles';
4
+ import { MiniButton, ToolMenu } from '../tool-menu';
5
+
6
+ jest.mock('@pie-lib/translator', () => ({
7
+ __esModule: true,
8
+ default: {
9
+ translator: {
10
+ t: jest.fn((key, options) => {
11
+ const translations = {
12
+ 'charting.addCategory': 'Add Category',
13
+ };
14
+ return translations[key] || key;
15
+ }),
16
+ },
17
+ },
18
+ }));
19
+
20
+ jest.mock('@pie-lib/render-ui', () => ({
21
+ color: {
22
+ text: () => '#000000',
23
+ secondary: () => '#cccccc',
24
+ background: () => '#ffffff',
25
+ primary: () => '#0000ff',
26
+ primaryDark: () => '#000080',
27
+ disabled: () => '#f0f0f0',
28
+ },
29
+ }));
30
+
31
+ let theme;
32
+
33
+ beforeAll(() => {
34
+ theme = createTheme();
35
+ });
36
+
37
+ describe('MiniButton', () => {
38
+ const onClick = jest.fn();
39
+
40
+ beforeEach(() => {
41
+ jest.clearAllMocks();
42
+ });
43
+
44
+ const renderComponent = (extras = {}) => {
45
+ const defaults = {
46
+ value: 'Test Button',
47
+ onClick,
48
+ disabled: false,
49
+ selected: false,
50
+ };
51
+ const props = { ...defaults, ...extras };
52
+ return render(
53
+ <ThemeProvider theme={theme}>
54
+ <MiniButton {...props} />
55
+ </ThemeProvider>,
56
+ );
57
+ };
58
+
59
+ describe('rendering', () => {
60
+ it('should render with value text', () => {
61
+ const { getByText } = renderComponent({ value: 'Click Me' });
62
+ expect(getByText('Click Me')).toBeInTheDocument();
63
+ });
64
+
65
+ it('should render as a button element', () => {
66
+ const { getByRole } = renderComponent();
67
+ expect(getByRole('button')).toBeInTheDocument();
68
+ });
69
+
70
+ it('should have correct button attributes', () => {
71
+ const { getByRole } = renderComponent({ value: 'Test' });
72
+ const button = getByRole('button');
73
+ expect(button).toHaveAttribute('value', 'Test');
74
+ });
75
+
76
+ it('should render with variant outlined', () => {
77
+ const { getByRole } = renderComponent();
78
+ const button = getByRole('button');
79
+ expect(button).toHaveClass('MuiButton-outlined');
80
+ });
81
+
82
+ it('should render with size small', () => {
83
+ const { getByRole } = renderComponent();
84
+ const button = getByRole('button');
85
+ expect(button).toHaveClass('MuiButton-sizeSmall');
86
+ });
87
+ });
88
+
89
+ describe('disabled state', () => {
90
+ it('should render as disabled when disabled prop is true', () => {
91
+ const { getByRole } = renderComponent({ disabled: true });
92
+ expect(getByRole('button')).toBeDisabled();
93
+ });
94
+
95
+ it('should not render as disabled when disabled prop is false', () => {
96
+ const { getByRole } = renderComponent({ disabled: false });
97
+ expect(getByRole('button')).not.toBeDisabled();
98
+ });
99
+
100
+ it('should not trigger onClick when disabled', () => {
101
+ const { getByRole } = renderComponent({ disabled: true });
102
+ fireEvent.click(getByRole('button'));
103
+ expect(onClick).not.toHaveBeenCalled();
104
+ });
105
+ });
106
+
107
+ describe('selected state', () => {
108
+ it('should apply selected styling when selected is true', () => {
109
+ const { getByRole } = renderComponent({ selected: true });
110
+ const button = getByRole('button');
111
+ expect(button.className).toContain('MuiButton-colorSecondary');
112
+ });
113
+
114
+ it('should apply default color when selected is false', () => {
115
+ const { getByRole } = renderComponent({ selected: false });
116
+ const button = getByRole('button');
117
+ expect(button.className).toContain('MuiButton-colorDefault');
118
+ });
119
+
120
+ it('should render correctly with both selected and disabled', () => {
121
+ const { getByRole } = renderComponent({ selected: true, disabled: true });
122
+ const button = getByRole('button');
123
+ expect(button).toBeDisabled();
124
+ expect(button.className).toContain('MuiButton-colorSecondary');
125
+ });
126
+ });
127
+
128
+ describe('interactions', () => {
129
+ it('should call onClick when clicked', () => {
130
+ const { getByRole } = renderComponent();
131
+ fireEvent.click(getByRole('button'));
132
+ expect(onClick).toHaveBeenCalledTimes(1);
133
+ });
134
+
135
+ it('should call onClick with correct event when clicked', () => {
136
+ const { getByRole } = renderComponent();
137
+ const button = getByRole('button');
138
+ fireEvent.click(button);
139
+ expect(onClick).toHaveBeenCalled();
140
+ expect(onClick.mock.calls[0][0]).toBeTruthy();
141
+ });
142
+
143
+ it('should handle multiple clicks', () => {
144
+ const { getByRole } = renderComponent();
145
+ const button = getByRole('button');
146
+ fireEvent.click(button);
147
+ fireEvent.click(button);
148
+ fireEvent.click(button);
149
+ expect(onClick).toHaveBeenCalledTimes(3);
150
+ });
151
+
152
+ it('should handle rapid clicks', () => {
153
+ const { getByRole } = renderComponent();
154
+ const button = getByRole('button');
155
+ for (let i = 0; i < 10; i++) {
156
+ fireEvent.click(button);
157
+ }
158
+ expect(onClick).toHaveBeenCalledTimes(10);
159
+ });
160
+ });
161
+
162
+ describe('edge cases', () => {
163
+ it('should render with empty string value', () => {
164
+ const { getByRole } = renderComponent({ value: '' });
165
+ expect(getByRole('button')).toBeInTheDocument();
166
+ });
167
+
168
+ it('should render with undefined onClick', () => {
169
+ const { getByRole } = render(
170
+ <ThemeProvider theme={theme}>
171
+ <MiniButton value="Test" onClick={undefined} />
172
+ </ThemeProvider>,
173
+ );
174
+ expect(getByRole('button')).toBeInTheDocument();
175
+ });
176
+
177
+ it('should render with null onClick', () => {
178
+ const { getByRole } = render(
179
+ <ThemeProvider theme={theme}>
180
+ <MiniButton value="Test" onClick={null} />
181
+ </ThemeProvider>,
182
+ );
183
+ expect(getByRole('button')).toBeInTheDocument();
184
+ });
185
+
186
+ it('should render with very long value text', () => {
187
+ const longText = 'This is a very long button text that might cause layout issues';
188
+ const { getByText } = renderComponent({ value: longText });
189
+ expect(getByText(longText)).toBeInTheDocument();
190
+ });
191
+
192
+ it('should render with special characters in value', () => {
193
+ const specialText = 'Test <>&"\'';
194
+ const { getByText } = renderComponent({ value: specialText });
195
+ expect(getByText(specialText)).toBeInTheDocument();
196
+ });
197
+
198
+ it('should render with unicode characters in value', () => {
199
+ const unicodeText = 'Test 你好 🎉';
200
+ const { getByText } = renderComponent({ value: unicodeText });
201
+ expect(getByText(unicodeText)).toBeInTheDocument();
202
+ });
203
+ });
204
+
205
+ describe('className prop', () => {
206
+ it('should accept className prop without error', () => {
207
+ const { getByRole } = render(
208
+ <ThemeProvider theme={theme}>
209
+ <MiniButton value="Test" onClick={onClick} className="custom-class" />
210
+ </ThemeProvider>,
211
+ );
212
+ expect(getByRole('button')).toBeInTheDocument();
213
+ });
214
+ });
215
+ });
216
+
217
+ describe('ToolMenu', () => {
218
+ const addCategory = jest.fn();
219
+
220
+ beforeEach(() => {
221
+ jest.clearAllMocks();
222
+ });
223
+
224
+ const renderComponent = (extras = {}) => {
225
+ const defaults = {
226
+ addCategory,
227
+ disabled: false,
228
+ language: 'en',
229
+ };
230
+ const props = { ...defaults, ...extras };
231
+ return render(
232
+ <ThemeProvider theme={theme}>
233
+ <ToolMenu {...props} />
234
+ </ThemeProvider>,
235
+ );
236
+ };
237
+
238
+ describe('rendering', () => {
239
+ it('should render without crashing', () => {
240
+ const { container } = renderComponent();
241
+ expect(container).toBeInTheDocument();
242
+ });
243
+
244
+ it('should render a div container', () => {
245
+ const { container } = renderComponent();
246
+ expect(container.firstChild).toBeInstanceOf(HTMLDivElement);
247
+ });
248
+
249
+ it('should render MiniButton when not disabled', () => {
250
+ const { getByRole } = renderComponent({ disabled: false });
251
+ expect(getByRole('button')).toBeInTheDocument();
252
+ });
253
+
254
+ it('should not render MiniButton when disabled', () => {
255
+ const { queryByRole } = renderComponent({ disabled: true });
256
+ expect(queryByRole('button')).not.toBeInTheDocument();
257
+ });
258
+
259
+ it('should render translated button text', () => {
260
+ const { getByText } = renderComponent();
261
+ expect(getByText('Add Category')).toBeInTheDocument();
262
+ });
263
+
264
+ it('should use language prop for translation', () => {
265
+ const Translator = require('@pie-lib/translator').default;
266
+ const { getByRole } = renderComponent({ language: 'es' });
267
+ expect(getByRole('button')).toBeInTheDocument();
268
+ expect(Translator.translator.t).toHaveBeenCalledWith('charting.addCategory', { lng: 'es' });
269
+ });
270
+ });
271
+
272
+ describe('className prop', () => {
273
+ it('should apply custom className to container', () => {
274
+ const { container } = renderComponent({ className: 'custom-tool-menu' });
275
+ expect(container.firstChild).toHaveClass('custom-tool-menu');
276
+ });
277
+
278
+ it('should render without className', () => {
279
+ const { container } = renderComponent({ className: undefined });
280
+ expect(container.firstChild).toBeInTheDocument();
281
+ });
282
+
283
+ it('should handle empty string className', () => {
284
+ const { container } = renderComponent({ className: '' });
285
+ expect(container.firstChild).toBeInTheDocument();
286
+ });
287
+ });
288
+
289
+ describe('disabled state', () => {
290
+ it('should hide button when disabled is true', () => {
291
+ const { queryByRole } = renderComponent({ disabled: true });
292
+ expect(queryByRole('button')).not.toBeInTheDocument();
293
+ });
294
+
295
+ it('should show button when disabled is false', () => {
296
+ const { getByRole } = renderComponent({ disabled: false });
297
+ expect(getByRole('button')).toBeInTheDocument();
298
+ });
299
+
300
+ it('should show button when disabled is undefined', () => {
301
+ const { getByRole } = renderComponent({ disabled: undefined });
302
+ expect(getByRole('button')).toBeInTheDocument();
303
+ });
304
+
305
+ it('should hide button when disabled is explicitly true', () => {
306
+ const { queryByRole } = renderComponent({ disabled: true });
307
+ expect(queryByRole('button')).toBeNull();
308
+ });
309
+ });
310
+
311
+ describe('addCategory functionality', () => {
312
+ it('should call addCategory when button is clicked', () => {
313
+ const { getByRole } = renderComponent();
314
+ fireEvent.click(getByRole('button'));
315
+ expect(addCategory).toHaveBeenCalledTimes(1);
316
+ });
317
+
318
+ it('should not call addCategory when disabled', () => {
319
+ const { queryByRole } = renderComponent({ disabled: true });
320
+ expect(queryByRole('button')).not.toBeInTheDocument();
321
+ expect(addCategory).not.toHaveBeenCalled();
322
+ });
323
+
324
+ it('should handle multiple clicks on add category button', () => {
325
+ const { getByRole } = renderComponent();
326
+ const button = getByRole('button');
327
+ fireEvent.click(button);
328
+ fireEvent.click(button);
329
+ fireEvent.click(button);
330
+ expect(addCategory).toHaveBeenCalledTimes(3);
331
+ });
332
+
333
+ it('should render with undefined addCategory without crashing', () => {
334
+ const { container } = render(
335
+ <ThemeProvider theme={theme}>
336
+ <ToolMenu addCategory={undefined} language="en" />
337
+ </ThemeProvider>,
338
+ );
339
+ expect(container).toBeInTheDocument();
340
+ });
341
+ });
342
+
343
+ describe('language prop', () => {
344
+ it('should pass language to translator', () => {
345
+ const Translator = require('@pie-lib/translator').default;
346
+ renderComponent({ language: 'fr' });
347
+ expect(Translator.translator.t).toHaveBeenCalledWith('charting.addCategory', { lng: 'fr' });
348
+ });
349
+
350
+ it('should handle default english language', () => {
351
+ const Translator = require('@pie-lib/translator').default;
352
+ renderComponent({ language: 'en' });
353
+ expect(Translator.translator.t).toHaveBeenCalledWith('charting.addCategory', { lng: 'en' });
354
+ });
355
+
356
+ it('should handle undefined language', () => {
357
+ const Translator = require('@pie-lib/translator').default;
358
+ renderComponent({ language: undefined });
359
+ expect(Translator.translator.t).toHaveBeenCalledWith('charting.addCategory', { lng: undefined });
360
+ });
361
+
362
+ it('should handle empty string language', () => {
363
+ const Translator = require('@pie-lib/translator').default;
364
+ renderComponent({ language: '' });
365
+ expect(Translator.translator.t).toHaveBeenCalledWith('charting.addCategory', { lng: '' });
366
+ });
367
+
368
+ it('should handle non-standard language codes', () => {
369
+ const Translator = require('@pie-lib/translator').default;
370
+ renderComponent({ language: 'zh-CN' });
371
+ expect(Translator.translator.t).toHaveBeenCalledWith('charting.addCategory', { lng: 'zh-CN' });
372
+ });
373
+ });
374
+
375
+ describe('edge cases', () => {
376
+ it('should render with all props undefined', () => {
377
+ const { container } = render(
378
+ <ThemeProvider theme={theme}>
379
+ <ToolMenu />
380
+ </ThemeProvider>,
381
+ );
382
+ expect(container).toBeInTheDocument();
383
+ });
384
+
385
+ it('should render with null props', () => {
386
+ const { container } = render(
387
+ <ThemeProvider theme={theme}>
388
+ <ToolMenu addCategory={null} disabled={null} language={null} />
389
+ </ThemeProvider>,
390
+ );
391
+ expect(container).toBeInTheDocument();
392
+ });
393
+
394
+ it('should handle component unmounting', () => {
395
+ const { unmount } = renderComponent();
396
+ expect(() => unmount()).not.toThrow();
397
+ });
398
+
399
+ it('should handle re-rendering with different props', () => {
400
+ const { rerender, getByRole, queryByRole } = renderComponent({ disabled: false });
401
+ expect(getByRole('button')).toBeInTheDocument();
402
+
403
+ rerender(
404
+ <ThemeProvider theme={theme}>
405
+ <ToolMenu addCategory={addCategory} disabled={true} language="en" />
406
+ </ThemeProvider>,
407
+ );
408
+ expect(queryByRole('button')).not.toBeInTheDocument();
409
+
410
+ rerender(
411
+ <ThemeProvider theme={theme}>
412
+ <ToolMenu addCategory={addCategory} disabled={false} language="es" />
413
+ </ThemeProvider>,
414
+ );
415
+ expect(getByRole('button')).toBeInTheDocument();
416
+ });
417
+
418
+ it('should handle rapid prop changes', () => {
419
+ const { rerender, getByRole } = renderComponent({ disabled: false });
420
+
421
+ expect(getByRole('button')).toBeInTheDocument();
422
+
423
+ for (let i = 0; i < 10; i++) {
424
+ rerender(
425
+ <ThemeProvider theme={theme}>
426
+ <ToolMenu addCategory={addCategory} disabled={i % 2 === 0} language="en" />
427
+ </ThemeProvider>,
428
+ );
429
+ }
430
+
431
+ expect(getByRole('button')).toBeInTheDocument();
432
+ });
433
+ });
434
+
435
+ describe('component lifecycle', () => {
436
+ it('should render as class component', () => {
437
+ const { container } = renderComponent();
438
+ expect(container).toBeInTheDocument();
439
+ });
440
+
441
+ it('should handle updates correctly', () => {
442
+ const { rerender, getByRole } = renderComponent({ language: 'en' });
443
+ expect(getByRole('button')).toBeInTheDocument();
444
+
445
+ rerender(
446
+ <ThemeProvider theme={theme}>
447
+ <ToolMenu addCategory={addCategory} disabled={false} language="fr" />
448
+ </ThemeProvider>,
449
+ );
450
+ expect(getByRole('button')).toBeInTheDocument();
451
+ });
452
+
453
+ it('should cleanup properly on unmount', () => {
454
+ const { unmount } = renderComponent();
455
+ expect(() => unmount()).not.toThrow();
456
+ });
457
+ });
458
+
459
+ describe('accessibility', () => {
460
+ it('should have accessible button element', () => {
461
+ const { getByRole } = renderComponent();
462
+ const button = getByRole('button');
463
+ expect(button).toBeInTheDocument();
464
+ });
465
+
466
+ it('should have button with text content', () => {
467
+ const { getByRole } = renderComponent();
468
+ const button = getByRole('button');
469
+ expect(button).toHaveTextContent('Add Category');
470
+ });
471
+
472
+ it('should maintain button accessibility when enabled', () => {
473
+ const { getByRole } = renderComponent({ disabled: false });
474
+ const button = getByRole('button');
475
+ expect(button).not.toBeDisabled();
476
+ expect(button).toHaveTextContent('Add Category');
477
+ });
478
+ });
479
+
480
+ describe('integration', () => {
481
+ it('should work correctly with all props provided', () => {
482
+ const customAddCategory = jest.fn();
483
+ const { getByRole } = renderComponent({
484
+ addCategory: customAddCategory,
485
+ disabled: false,
486
+ language: 'de',
487
+ className: 'test-class',
488
+ });
489
+
490
+ const button = getByRole('button');
491
+ expect(button).toBeInTheDocument();
492
+
493
+ fireEvent.click(button);
494
+ expect(customAddCategory).toHaveBeenCalledTimes(1);
495
+ });
496
+
497
+ it('should toggle between enabled and disabled states', () => {
498
+ const { rerender, getByRole, queryByRole } = renderComponent({ disabled: false });
499
+ expect(getByRole('button')).toBeInTheDocument();
500
+
501
+ rerender(
502
+ <ThemeProvider theme={theme}>
503
+ <ToolMenu addCategory={addCategory} disabled={true} language="en" />
504
+ </ThemeProvider>,
505
+ );
506
+ expect(queryByRole('button')).not.toBeInTheDocument();
507
+ });
508
+
509
+ it('should handle language switching', () => {
510
+ const Translator = require('@pie-lib/translator').default;
511
+ const { rerender } = renderComponent({ language: 'en' });
512
+
513
+ rerender(
514
+ <ThemeProvider theme={theme}>
515
+ <ToolMenu addCategory={addCategory} disabled={false} language="es" />
516
+ </ThemeProvider>,
517
+ );
518
+
519
+ expect(Translator.translator.t).toHaveBeenCalledWith('charting.addCategory', { lng: 'es' });
520
+ });
521
+ });
522
+ });
@@ -1,4 +1,4 @@
1
- import { scaleLinear, scaleBand } from 'd3-scale';
1
+ import { scaleBand, scaleLinear } from 'd3-scale';
2
2
 
3
3
  export const scaleMock = () => {
4
4
  const fn = jest.fn((n) => n);
package/src/axes.jsx CHANGED
@@ -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 { AxisLeft, AxisBottom } from '@visx/axis';
4
+ import { AxisBottom, AxisLeft } from '@visx/axis';
5
5
  import Checkbox from '@mui/material/Checkbox';
6
6
 
7
7
  import { types } from '@pie-lib/plot';
@@ -10,7 +10,7 @@ import { AlertDialog } from '@pie-lib/config-ui';
10
10
  import { renderMath } from '@pie-lib/math-rendering';
11
11
 
12
12
  import { TickCorrectnessIndicator } from './common/correctness-indicators';
13
- import { bandKey, getTickValues, getRotateAngle } from './utils';
13
+ import { bandKey, getRotateAngle, getTickValues } from './utils';
14
14
  import MarkLabel from './mark-label';
15
15
 
16
16
  const StyledErrorText = styled('text')(({ theme }) => ({
@@ -194,12 +194,15 @@ export class TickComponent extends React.Component {
194
194
  const category = categories[index];
195
195
  const { editable, interactive, label, correctness } = category || {};
196
196
  const barX = xBand(bandKey({ label }, index));
197
- const longestCategory = (categories || []).reduce((a, b) => {
198
- const lengthA = a && a.label ? a.label.length : 0;
199
- const lengthB = b && b.label ? b.label.length : 0;
197
+ const longestCategory = (categories || []).reduce(
198
+ (a, b) => {
199
+ const lengthA = a && a.label ? a.label.length : 0;
200
+ const lengthB = b && b.label ? b.label.length : 0;
200
201
 
201
- return lengthA > lengthB ? a : b;
202
- }, { label: '' });
202
+ return lengthA > lengthB ? a : b;
203
+ },
204
+ { label: '' },
205
+ );
203
206
  const distinctMessages = error ? [...new Set(Object.values(error))].join(' ') : '';
204
207
 
205
208
  return (
@@ -132,18 +132,8 @@ export class RawBar extends React.Component {
132
132
  };
133
133
 
134
134
  render() {
135
- const {
136
- graphProps,
137
- value,
138
- label,
139
- xBand,
140
- index,
141
- interactive,
142
- correctness,
143
- barColor,
144
- defineChart,
145
- correctData,
146
- } = this.props;
135
+ const { graphProps, value, label, xBand, index, interactive, correctness, barColor, defineChart, correctData } =
136
+ this.props;
147
137
  const { scale, range } = graphProps;
148
138
  const { dragValue, isHovered } = this.state;
149
139
 
@@ -168,43 +158,34 @@ export class RawBar extends React.Component {
168
158
  onTouchStart={this.handleMouseEnter}
169
159
  onTouchEnd={this.handleMouseLeave}
170
160
  >
171
- <StyledVisxBar
172
- x={barX}
173
- y={scale.y(yy)}
174
- width={barWidth}
175
- height={barHeight}
176
- style={{ fill: fillColor }}
177
- />
178
- {correctness && correctness.value === 'incorrect' && (() => {
179
- const correctVal = parseFloat(correctValue && correctValue.value);
180
- if (isNaN(correctVal)) return null;
181
- const correctPxHeight = scale.y(range.max - correctVal);
182
- const actualPxHeight = barHeight;
183
- const diffPx = Math.abs(correctPxHeight - actualPxHeight);
184
- const yDiff = scale.y(correctVal);
185
- const indicatorBarColor = correctPxHeight > actualPxHeight ? color.borderGray() : color.defaults.WHITE;
186
- const yToRender = correctPxHeight > actualPxHeight ? yDiff : yDiff - diffPx;
187
-
188
- return (
189
- <>
190
- <StyledVisxBar
191
- x={barX + 2}
192
- y={yToRender}
193
- width={barWidth - 4}
194
- height={diffPx}
195
- style={{ stroke: indicatorBarColor, strokeWidth: 2, strokeDasharray: '5,2', fill: 'none' }}
196
- />
197
- <foreignObject
198
- x={barX + barWidth - (isHistogram ? 24 : 14)}
199
- y={yDiff - 12}
200
- width={24}
201
- height={24}
202
- >
203
- <CorrectCheckIcon dashColor={indicatorBarColor} />
204
- </foreignObject>
205
- </>
206
- );
207
- })()}
161
+ <StyledVisxBar x={barX} y={scale.y(yy)} width={barWidth} height={barHeight} style={{ fill: fillColor }} />
162
+ {correctness &&
163
+ correctness.value === 'incorrect' &&
164
+ (() => {
165
+ const correctVal = parseFloat(correctValue && correctValue.value);
166
+ if (isNaN(correctVal)) return null;
167
+ const correctPxHeight = scale.y(range.max - correctVal);
168
+ const actualPxHeight = barHeight;
169
+ const diffPx = Math.abs(correctPxHeight - actualPxHeight);
170
+ const yDiff = scale.y(correctVal);
171
+ const indicatorBarColor = correctPxHeight > actualPxHeight ? color.borderGray() : color.defaults.WHITE;
172
+ const yToRender = correctPxHeight > actualPxHeight ? yDiff : yDiff - diffPx;
173
+
174
+ return (
175
+ <>
176
+ <StyledVisxBar
177
+ x={barX + 2}
178
+ y={yToRender}
179
+ width={barWidth - 4}
180
+ height={diffPx}
181
+ style={{ stroke: indicatorBarColor, strokeWidth: 2, strokeDasharray: '5,2', fill: 'none' }}
182
+ />
183
+ <foreignObject x={barX + barWidth - (isHistogram ? 24 : 14)} y={yDiff - 12} width={24} height={24}>
184
+ <CorrectCheckIcon dashColor={indicatorBarColor} />
185
+ </foreignObject>
186
+ </>
187
+ );
188
+ })()}
208
189
  <Component
209
190
  x={barX}
210
191
  y={v}
@@ -255,7 +236,8 @@ export class Bars extends React.Component {
255
236
  correctness={d.correctness}
256
237
  correctData={correctData}
257
238
  barColor={
258
- histogram && (histogramColors[index] ? histogramColors[index] : histogramColors[index % histogramColors.length])
239
+ histogram &&
240
+ (histogramColors[index] ? histogramColors[index] : histogramColors[index % histogramColors.length])
259
241
  }
260
242
  />
261
243
  ))}