@pie-lib/charting 5.15.6 → 5.15.7-next.1618

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 (109) hide show
  1. package/CHANGELOG.json +1 -581
  2. package/CHANGELOG.md +206 -38
  3. package/NEXT.CHANGELOG.json +1 -0
  4. package/lib/actions-button.js +175 -0
  5. package/lib/actions-button.js.map +1 -0
  6. package/lib/axes.js +154 -104
  7. package/lib/axes.js.map +1 -1
  8. package/lib/bars/common/bars.js +105 -19
  9. package/lib/bars/common/bars.js.map +1 -1
  10. package/lib/bars/common/correct-check-icon.js +55 -0
  11. package/lib/bars/common/correct-check-icon.js.map +1 -0
  12. package/lib/chart-type.js +4 -4
  13. package/lib/chart-type.js.map +1 -1
  14. package/lib/chart.js +96 -65
  15. package/lib/chart.js.map +1 -1
  16. package/lib/common/correctness-indicators.js +99 -0
  17. package/lib/common/correctness-indicators.js.map +1 -0
  18. package/lib/common/drag-handle.js +47 -13
  19. package/lib/common/drag-handle.js.map +1 -1
  20. package/lib/common/drag-icon.js +7 -24
  21. package/lib/common/drag-icon.js.map +1 -1
  22. package/lib/grid.js +47 -10
  23. package/lib/grid.js.map +1 -1
  24. package/lib/index.js +8 -0
  25. package/lib/index.js.map +1 -1
  26. package/lib/key-legend.js +111 -0
  27. package/lib/key-legend.js.map +1 -0
  28. package/lib/line/common/drag-handle.js +40 -18
  29. package/lib/line/common/drag-handle.js.map +1 -1
  30. package/lib/line/common/line.js +7 -8
  31. package/lib/line/common/line.js.map +1 -1
  32. package/lib/line/line-cross.js +76 -9
  33. package/lib/line/line-cross.js.map +1 -1
  34. package/lib/line/line-dot.js +58 -5
  35. package/lib/line/line-dot.js.map +1 -1
  36. package/lib/mark-label.js +40 -15
  37. package/lib/mark-label.js.map +1 -1
  38. package/lib/plot/common/plot.js +129 -16
  39. package/lib/plot/common/plot.js.map +1 -1
  40. package/lib/plot/dot.js +17 -4
  41. package/lib/plot/dot.js.map +1 -1
  42. package/lib/plot/line.js +19 -6
  43. package/lib/plot/line.js.map +1 -1
  44. package/lib/tool-menu.js +0 -4
  45. package/lib/tool-menu.js.map +1 -1
  46. package/package.json +6 -8
  47. package/src/__tests__/__snapshots__/axes.test.jsx.snap +569 -0
  48. package/src/__tests__/__snapshots__/chart-type.test.jsx.snap +14 -0
  49. package/src/__tests__/__snapshots__/chart.test.jsx.snap +595 -0
  50. package/src/__tests__/__snapshots__/grid.test.jsx.snap +72 -0
  51. package/src/__tests__/__snapshots__/mark-label.test.jsx.snap +73 -0
  52. package/src/__tests__/axes.test.jsx +141 -0
  53. package/src/__tests__/chart-setup.test.jsx +47 -0
  54. package/src/__tests__/chart-type.test.jsx +29 -0
  55. package/src/__tests__/chart.test.jsx +95 -0
  56. package/src/__tests__/grid.test.jsx +25 -0
  57. package/src/__tests__/mark-label.test.jsx +31 -0
  58. package/src/__tests__/utils.js +30 -0
  59. package/src/__tests__/utils.test.js +100 -0
  60. package/src/actions-button.jsx +110 -0
  61. package/src/axes.jsx +98 -54
  62. package/src/bars/__tests__/__snapshots__/bar.test.jsx.snap +43 -0
  63. package/src/bars/__tests__/__snapshots__/histogram.test.jsx.snap +45 -0
  64. package/src/bars/__tests__/bar.test.jsx +37 -0
  65. package/src/bars/__tests__/histogram.test.jsx +38 -0
  66. package/src/bars/__tests__/utils.js +30 -0
  67. package/src/bars/common/__tests__/__snapshots__/bars.test.jsx.snap +110 -0
  68. package/src/bars/common/__tests__/bars.test.jsx +69 -0
  69. package/src/bars/common/__tests__/utils.js +30 -0
  70. package/src/bars/common/bars.jsx +101 -14
  71. package/src/bars/common/correct-check-icon.jsx +20 -0
  72. package/src/chart-type.js +7 -3
  73. package/src/chart.jsx +53 -29
  74. package/src/common/__tests__/__snapshots__/drag-handle.test.jsx.snap +48 -0
  75. package/src/common/__tests__/drag-handle.test.jsx +88 -0
  76. package/src/common/__tests__/utils.js +30 -0
  77. package/src/common/correctness-indicators.jsx +55 -0
  78. package/src/common/drag-handle.jsx +48 -26
  79. package/src/common/drag-icon.jsx +6 -21
  80. package/src/grid.jsx +37 -12
  81. package/src/index.js +2 -1
  82. package/src/key-legend.jsx +75 -0
  83. package/src/line/__tests__/__snapshots__/line-cross.test.jsx.snap +45 -0
  84. package/src/line/__tests__/__snapshots__/line-dot.test.jsx.snap +45 -0
  85. package/src/line/__tests__/line-cross.test.jsx +38 -0
  86. package/src/line/__tests__/line-dot.test.jsx +38 -0
  87. package/src/line/__tests__/utils.js +30 -0
  88. package/src/line/common/__tests__/__snapshots__/drag-handle.test.jsx.snap +49 -0
  89. package/src/line/common/__tests__/__snapshots__/line.test.jsx.snap +143 -0
  90. package/src/line/common/__tests__/drag-handle.test.jsx +88 -0
  91. package/src/line/common/__tests__/line.test.jsx +82 -0
  92. package/src/line/common/__tests__/utils.js +30 -0
  93. package/src/line/common/drag-handle.jsx +38 -16
  94. package/src/line/common/line.jsx +4 -6
  95. package/src/line/line-cross.js +56 -4
  96. package/src/line/line-dot.js +74 -10
  97. package/src/mark-label.jsx +83 -51
  98. package/src/plot/__tests__/__snapshots__/dot.test.jsx.snap +45 -0
  99. package/src/plot/__tests__/__snapshots__/line.test.jsx.snap +45 -0
  100. package/src/plot/__tests__/dot.test.jsx +38 -0
  101. package/src/plot/__tests__/line.test.jsx +38 -0
  102. package/src/plot/__tests__/utils.js +30 -0
  103. package/src/plot/common/__tests__/__snapshots__/plot.test.jsx.snap +97 -0
  104. package/src/plot/common/__tests__/plot.test.jsx +70 -0
  105. package/src/plot/common/__tests__/utils.js +30 -0
  106. package/src/plot/common/plot.jsx +127 -10
  107. package/src/plot/dot.js +19 -3
  108. package/src/plot/line.js +18 -4
  109. package/src/tool-menu.jsx +0 -4
package/src/axes.jsx CHANGED
@@ -1,13 +1,15 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import { withStyles } from '@material-ui/core/styles';
4
+ import { AxisLeft, AxisBottom } from '@vx/axis';
5
+ import Checkbox from '@material-ui/core/Checkbox';
6
+
4
7
  import { types } from '@pie-lib/plot';
5
8
  import { color } from '@pie-lib/render-ui';
6
9
  import { AlertDialog } from '@pie-lib/config-ui';
7
- import { AxisLeft, AxisBottom } from '@vx/axis';
10
+ import { TickCorrectnessIndicator } from './common/correctness-indicators';
8
11
  import { bandKey, getTickValues, getRotateAngle } from './utils';
9
12
  import MarkLabel from './mark-label';
10
- import Checkbox from '@material-ui/core/Checkbox';
11
13
 
12
14
  export class TickComponent extends React.Component {
13
15
  static propTypes = {
@@ -24,6 +26,12 @@ export class TickComponent extends React.Component {
24
26
  };
25
27
  }
26
28
 
29
+ componentDidUpdate(prevProps) {
30
+ if (this.props.autoFocus && !prevProps.autoFocus) {
31
+ this.props.onAutoFocusUsed();
32
+ }
33
+ }
34
+
27
35
  handleAlertDialog = (open, callback) =>
28
36
  this.setState(
29
37
  {
@@ -39,14 +47,6 @@ export class TickComponent extends React.Component {
39
47
  onChangeCategory(index, { ...category, label: newLabel });
40
48
  };
41
49
 
42
- deleteCategory = (index) => {
43
- const { categories, onChange } = this.props;
44
-
45
- if (index >= 0 && categories[index]) {
46
- onChange([...categories.slice(0, index), ...categories.slice(index + 1)]);
47
- }
48
- };
49
-
50
50
  changeInteractive = (index, value) => {
51
51
  const { categories, onChangeCategory } = this.props;
52
52
  const category = categories[index];
@@ -126,6 +126,9 @@ export class TickComponent extends React.Component {
126
126
  changeInteractiveEnabled,
127
127
  changeEditableEnabled,
128
128
  error,
129
+ autoFocus,
130
+ hiddenLabelRef,
131
+ showCorrectness,
129
132
  } = this.props;
130
133
 
131
134
  if (!formattedValue) {
@@ -136,7 +139,7 @@ export class TickComponent extends React.Component {
136
139
  const { changeEditable, changeInteractive } = chartingOptions || {};
137
140
  const index = parseInt(formattedValue.split('-')[0], 10);
138
141
  const category = categories[index];
139
- const { deletable, editable, interactive, label, correctness, autoFocus, inDefineChart } = category || {};
142
+ const { editable, interactive, label, correctness } = category || {};
140
143
  const barX = xBand(bandKey({ label }, index));
141
144
  const longestCategory = (categories || []).reduce((a, b) => {
142
145
  const lengthA = a && a.label ? a.label.length : 0;
@@ -144,37 +147,30 @@ export class TickComponent extends React.Component {
144
147
 
145
148
  return lengthA > lengthB ? a : b;
146
149
  });
147
-
148
- const longestLabel = (longestCategory && longestCategory.label) || '';
149
150
  const distinctMessages = error ? [...new Set(Object.values(error))].join(' ') : '';
150
151
 
151
152
  return (
152
153
  <g>
153
154
  <foreignObject
154
155
  x={bandWidth ? barX : x - barWidth / 2}
155
- y={6}
156
+ y={18}
156
157
  width={barWidth}
157
158
  height={4}
158
159
  style={{ pointerEvents: 'none', overflow: 'visible' }}
159
160
  >
160
161
  {index === 0 && (
161
- <div
162
- id="hiddenLabel"
163
- style={{
164
- position: 'absolute',
165
- visibility: 'hidden',
166
- wordBreak: 'break-word',
167
- overflow: 'visible',
168
- maxWidth: barWidth,
169
- display: 'block',
170
- }}
171
- >
172
- {longestLabel}
173
- </div>
162
+ <MarkLabel
163
+ isHiddenLabel={true}
164
+ inputRef={hiddenLabelRef}
165
+ disabled={true}
166
+ mark={longestCategory}
167
+ graphProps={graphProps}
168
+ barWidth={barWidth}
169
+ />
174
170
  )}
175
171
 
176
172
  <MarkLabel
177
- autoFocus={inDefineChart ? defineChart && autoFocus : autoFocus}
173
+ autoFocus={defineChart && autoFocus}
178
174
  inputRef={(r) => (this.input = r)}
179
175
  disabled={!defineChart && !editable}
180
176
  mark={category}
@@ -184,6 +180,13 @@ export class TickComponent extends React.Component {
184
180
  rotate={rotate}
185
181
  correctness={correctness}
186
182
  error={error && error[index]}
183
+ limitCharacters
184
+ correctnessIndicator={
185
+ showCorrectness &&
186
+ correctness && (
187
+ <TickCorrectnessIndicator correctness={correctness} interactive={interactive} classes={classes} />
188
+ )
189
+ }
187
190
  />
188
191
  </foreignObject>
189
192
 
@@ -193,24 +196,6 @@ export class TickComponent extends React.Component {
193
196
  </text>
194
197
  )}
195
198
 
196
- {deletable && !correctness && (
197
- <line x1={x} y1={0} x2={x} y2={y + 4 + top} className={classes.dottedLine} strokeDasharray="4 2" />
198
- )}
199
-
200
- {deletable && !correctness && (
201
- <svg
202
- xmlns="http://www.w3.org/2000/svg"
203
- x={x - 8}
204
- y={y + 60 + top}
205
- width={16}
206
- height={16}
207
- viewBox="0 0 512 512"
208
- onClick={() => this.deleteCategory(index)}
209
- >
210
- <path d="M128 405.429C128 428.846 147.198 448 170.667 448h170.667C364.802 448 384 428.846 384 405.429V160H128v245.429zM416 96h-80l-26.785-32H202.786L176 96H96v32h320V96z" />
211
- </svg>
212
- )}
213
-
214
199
  {defineChart && index === 0 && (
215
200
  <svg
216
201
  x={-55}
@@ -271,6 +256,7 @@ export class TickComponent extends React.Component {
271
256
  style={{ pointerEvents: 'visible', overflow: 'visible' }}
272
257
  >
273
258
  <Checkbox
259
+ className={classes.customColor}
274
260
  style={{ position: 'fixed' }}
275
261
  checked={interactive}
276
262
  onChange={(e) => this.changeInteractive(index, e.target.checked)}
@@ -287,6 +273,7 @@ export class TickComponent extends React.Component {
287
273
  style={{ pointerEvents: 'visible', overflow: 'visible' }}
288
274
  >
289
275
  <Checkbox
276
+ className={classes.customColor}
290
277
  style={{ position: 'fixed' }}
291
278
  checked={editable}
292
279
  onChange={(e) => this.changeEditable(index, e.target.checked)}
@@ -333,6 +320,9 @@ TickComponent.propTypes = {
333
320
  chartingOptions: PropTypes.object,
334
321
  changeInteractiveEnabled: PropTypes.bool,
335
322
  changeEditableEnabled: PropTypes.bool,
323
+ autoFocus: PropTypes.bool,
324
+ onAutoFocusUsed: PropTypes.func,
325
+ showCorrectness: PropTypes.bool,
336
326
  };
337
327
 
338
328
  export class RawChartAxes extends React.Component {
@@ -352,14 +342,31 @@ export class RawChartAxes extends React.Component {
352
342
  chartingOptions: PropTypes.object,
353
343
  changeInteractiveEnabled: PropTypes.bool,
354
344
  changeEditableEnabled: PropTypes.bool,
345
+ autoFocus: PropTypes.bool,
346
+ onAutoFocusUsed: PropTypes.func,
347
+ showCorrectness: PropTypes.bool,
355
348
  };
356
349
 
357
- state = { height: 0 };
350
+ state = { height: 0, width: 0 };
358
351
 
359
352
  componentDidMount() {
360
- const height = document.getElementById('hiddenLabel') ? document.getElementById('hiddenLabel').offsetHeight : 0;
353
+ if (this.hiddenLabelRef) {
354
+ const boundingClientRect = this.hiddenLabelRef.getBoundingClientRect();
355
+ this.setState({
356
+ height: Math.floor(boundingClientRect.height),
357
+ width: Math.floor(boundingClientRect.width),
358
+ });
359
+ }
360
+ }
361
361
 
362
- this.setState({ height });
362
+ componentDidUpdate(prevProps, prevState, snapshot) {
363
+ if (this.hiddenLabelRef) {
364
+ const width = Math.floor(this.hiddenLabelRef.getBoundingClientRect().width);
365
+
366
+ if (width !== this.state.width) {
367
+ this.setState({ width });
368
+ }
369
+ }
363
370
  }
364
371
 
365
372
  render() {
@@ -377,12 +384,15 @@ export class RawChartAxes extends React.Component {
377
384
  changeInteractiveEnabled,
378
385
  changeEditableEnabled,
379
386
  theme,
387
+ autoFocus,
388
+ onAutoFocusUsed,
380
389
  error,
390
+ showCorrectness,
381
391
  } = this.props;
382
392
 
383
393
  const { axis, axisLine, tick } = classes;
384
394
  const { scale = {}, range = {}, domain = {}, size = {} } = graphProps || {};
385
- const { height } = this.state;
395
+ const { height, width } = this.state;
386
396
 
387
397
  const bottomScale = xBand && typeof xBand.rangeRound === 'function' && xBand.rangeRound([0, size.width]);
388
398
 
@@ -392,7 +402,10 @@ export class RawChartAxes extends React.Component {
392
402
 
393
403
  const rowTickValues = getTickValues({ ...range, step: range.labelStep });
394
404
  const fontSize = theme && theme.typography ? theme.typography.fontSize : 14;
395
- const rotate = getRotateAngle(fontSize, height);
405
+ // this mostly applies for labels that are not editable
406
+ const rotateBecauseOfHeight = getRotateAngle(fontSize, height);
407
+ // this applies for labels that are editable
408
+ const rotateBecauseOfWidth = width > barWidth ? 25 : 0;
396
409
 
397
410
  const getTickLabelProps = (value) => ({
398
411
  dy: 4,
@@ -401,15 +414,20 @@ export class RawChartAxes extends React.Component {
401
414
 
402
415
  const getTickComponent = (props) => {
403
416
  const properties = {
417
+ hiddenLabelRef: (ref) => {
418
+ this.hiddenLabelRef = ref;
419
+ },
404
420
  classes,
405
421
  categories,
406
422
  xBand,
407
423
  bandWidth,
408
424
  barWidth,
409
- rotate,
425
+ rotate: rotateBecauseOfHeight || rotateBecauseOfWidth,
410
426
  top,
411
427
  defineChart,
412
428
  chartingOptions,
429
+ autoFocus,
430
+ onAutoFocusUsed,
413
431
  error,
414
432
  onChangeCategory,
415
433
  changeInteractiveEnabled,
@@ -419,6 +437,7 @@ export class RawChartAxes extends React.Component {
419
437
  x: props.x,
420
438
  y: props.y,
421
439
  formattedValue: props.formattedValue,
440
+ showCorrectness,
422
441
  };
423
442
 
424
443
  return <TickComponent {...properties} />;
@@ -447,6 +466,8 @@ export class RawChartAxes extends React.Component {
447
466
  textLabelProps={() => ({ textAnchor: 'middle' })}
448
467
  tickFormat={(count) => count}
449
468
  tickComponent={getTickComponent}
469
+ autoFocus={autoFocus}
470
+ onAutoFocusUsed={onAutoFocusUsed}
450
471
  />
451
472
  </React.Fragment>
452
473
  );
@@ -460,7 +481,7 @@ const ChartAxes = withStyles(
460
481
  strokeWidth: 2,
461
482
  },
462
483
  axisLine: {
463
- stroke: color.primaryDark(),
484
+ stroke: color.visualElementsColors.AXIS_LINE_COLOR,
464
485
  strokeWidth: 2,
465
486
  },
466
487
  tick: {
@@ -468,7 +489,6 @@ const ChartAxes = withStyles(
468
489
  stroke: color.primaryDark(),
469
490
  strokeWidth: 2,
470
491
  },
471
- fill: color.primaryDark(),
472
492
  fontFamily: theme.typography.body1.fontFamily,
473
493
  fontSize: theme.typography.fontSize,
474
494
  textAnchor: 'middle',
@@ -481,6 +501,30 @@ const ChartAxes = withStyles(
481
501
  fontSize: theme.typography.fontSize - 2,
482
502
  fill: theme.palette.error.main,
483
503
  },
504
+ customColor: {
505
+ color: `${color.tertiary()} !important`,
506
+ },
507
+ correctnessIcon: {
508
+ borderRadius: theme.spacing.unit * 2,
509
+ color: color.defaults.WHITE,
510
+ fontSize: '16px',
511
+ width: '16px',
512
+ height: '16px',
513
+ padding: '2px',
514
+ border: `1px solid ${color.defaults.WHITE}`,
515
+ boxSizing: 'unset', // to override the default border-box in IBX
516
+ },
517
+ incorrectIcon: {
518
+ backgroundColor: color.incorrectWithIcon(),
519
+ },
520
+ correctIcon: {
521
+ backgroundColor: color.correct(),
522
+ },
523
+ tickContainer: {
524
+ display: 'flex',
525
+ flexDirection: 'column',
526
+ alignItems: 'center',
527
+ },
484
528
  }),
485
529
  { withTheme: true },
486
530
  )(RawChartAxes);
@@ -0,0 +1,43 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`BarChart snapshot renders 1`] = `
4
+ <Bars
5
+ className="className"
6
+ classes={Object {}}
7
+ graphProps={
8
+ Object {
9
+ "domain": Object {
10
+ "max": 1,
11
+ "min": 0,
12
+ "step": 1,
13
+ },
14
+ "range": Object {
15
+ "max": 1,
16
+ "min": 0,
17
+ "step": 1,
18
+ },
19
+ "scale": Object {
20
+ "x": [MockFunction],
21
+ "y": [MockFunction],
22
+ },
23
+ "size": Object {
24
+ "height": 400,
25
+ "width": 400,
26
+ },
27
+ "snap": Object {
28
+ "x": [MockFunction],
29
+ "y": [MockFunction],
30
+ },
31
+ }
32
+ }
33
+ xBand={[Function]}
34
+ />
35
+ `;
36
+
37
+ exports[`BarChart snapshot renders without graphProps 1`] = `
38
+ <Bars
39
+ className="className"
40
+ classes={Object {}}
41
+ xBand={[Function]}
42
+ />
43
+ `;
@@ -0,0 +1,45 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`HistogramChart snapshot renders 1`] = `
4
+ <Bars
5
+ className="className"
6
+ classes={Object {}}
7
+ graphProps={
8
+ Object {
9
+ "domain": Object {
10
+ "max": 1,
11
+ "min": 0,
12
+ "step": 1,
13
+ },
14
+ "range": Object {
15
+ "max": 1,
16
+ "min": 0,
17
+ "step": 1,
18
+ },
19
+ "scale": Object {
20
+ "x": [MockFunction],
21
+ "y": [MockFunction],
22
+ },
23
+ "size": Object {
24
+ "height": 400,
25
+ "width": 400,
26
+ },
27
+ "snap": Object {
28
+ "x": [MockFunction],
29
+ "y": [MockFunction],
30
+ },
31
+ }
32
+ }
33
+ histogram={true}
34
+ xBand={[Function]}
35
+ />
36
+ `;
37
+
38
+ exports[`HistogramChart snapshot renders without graphProps 1`] = `
39
+ <Bars
40
+ className="className"
41
+ classes={Object {}}
42
+ histogram={true}
43
+ xBand={[Function]}
44
+ />
45
+ `;
@@ -0,0 +1,37 @@
1
+ import { shallow } from 'enzyme';
2
+ import React from 'react';
3
+ import Bar, { Bar as BarChart } from '../bar';
4
+ import { graphProps } from './utils';
5
+
6
+ describe('BarChart', () => {
7
+ const wrapper = (extras) => {
8
+ const defaults = {
9
+ classes: {},
10
+ className: 'className',
11
+ graphProps: graphProps(),
12
+ xBand: () => {
13
+ return {
14
+ bandwidth: () => {},
15
+ };
16
+ },
17
+ };
18
+ const props = { ...defaults, ...extras };
19
+ return shallow(<BarChart {...props} />);
20
+ };
21
+
22
+ describe('snapshot', () => {
23
+ it('renders', () => expect(wrapper()).toMatchSnapshot());
24
+
25
+ it('renders without graphProps', () => expect(wrapper({ graphProps: undefined })).toMatchSnapshot());
26
+ });
27
+
28
+ describe('component', () => {
29
+ const chart = Bar();
30
+
31
+ expect(chart).toEqual({
32
+ type: 'bar',
33
+ Component: BarChart,
34
+ name: 'Bar',
35
+ });
36
+ });
37
+ });
@@ -0,0 +1,38 @@
1
+ import { shallow } from 'enzyme';
2
+ import React from 'react';
3
+ import Histogram, { Histogram as HistogramChart } from '../histogram';
4
+ import { graphProps } from './utils';
5
+ import { Bar as BarChart } from '../bar';
6
+
7
+ describe('HistogramChart', () => {
8
+ const wrapper = (extras) => {
9
+ const defaults = {
10
+ classes: {},
11
+ className: 'className',
12
+ graphProps: graphProps(),
13
+ xBand: () => {
14
+ return {
15
+ bandwidth: () => {},
16
+ };
17
+ },
18
+ };
19
+ const props = { ...defaults, ...extras };
20
+ return shallow(<HistogramChart {...props} />);
21
+ };
22
+
23
+ describe('snapshot', () => {
24
+ it('renders', () => expect(wrapper()).toMatchSnapshot());
25
+
26
+ it('renders without graphProps', () => expect(wrapper({ graphProps: undefined })).toMatchSnapshot());
27
+ });
28
+
29
+ describe('component', () => {
30
+ const chart = Histogram();
31
+
32
+ expect(chart).toEqual({
33
+ type: 'histogram',
34
+ Component: HistogramChart,
35
+ name: 'Histogram',
36
+ });
37
+ });
38
+ });
@@ -0,0 +1,30 @@
1
+ export const scaleMock = () => {
2
+ const fn = jest.fn((n) => n);
3
+ fn.invert = jest.fn((n) => n);
4
+ return fn;
5
+ };
6
+
7
+ export const graphProps = (dmin = 0, dmax = 1, rmin = 0, rmax = 1) => ({
8
+ scale: {
9
+ x: scaleMock(),
10
+ y: scaleMock(),
11
+ },
12
+ snap: {
13
+ x: jest.fn((n) => n),
14
+ y: jest.fn((n) => n),
15
+ },
16
+ domain: {
17
+ min: dmin,
18
+ max: dmax,
19
+ step: 1,
20
+ },
21
+ range: {
22
+ min: rmin,
23
+ max: rmax,
24
+ step: 1,
25
+ },
26
+ size: {
27
+ width: 400,
28
+ height: 400,
29
+ },
30
+ });
@@ -0,0 +1,110 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`Bars snapshot renders 1`] = `
4
+ <t>
5
+ <WithStyles(RawBar)
6
+ graphProps={
7
+ Object {
8
+ "domain": Object {
9
+ "max": 1,
10
+ "min": 0,
11
+ "step": 1,
12
+ },
13
+ "range": Object {
14
+ "max": 1,
15
+ "min": 0,
16
+ "step": 1,
17
+ },
18
+ "scale": Object {
19
+ "x": [MockFunction],
20
+ "y": [MockFunction],
21
+ },
22
+ "size": Object {
23
+ "height": 400,
24
+ "width": 400,
25
+ },
26
+ "snap": Object {
27
+ "x": [MockFunction],
28
+ "y": [MockFunction],
29
+ },
30
+ }
31
+ }
32
+ index={0}
33
+ key="bar-0-0-0"
34
+ label="0"
35
+ onChangeCategory={[Function]}
36
+ value={0}
37
+ xBand={[Function]}
38
+ />
39
+ </t>
40
+ `;
41
+
42
+ exports[`RawBar snapshot renders 1`] = `
43
+ <g
44
+ onMouseEnter={[Function]}
45
+ onMouseLeave={[Function]}
46
+ onTouchEnd={[Function]}
47
+ onTouchStart={[Function]}
48
+ >
49
+ <P
50
+ height={NaN}
51
+ style={
52
+ Object {
53
+ "fill": null,
54
+ }
55
+ }
56
+ y={NaN}
57
+ />
58
+ <WithStyles(RawDragHandle)
59
+ color={null}
60
+ graphProps={
61
+ Object {
62
+ "domain": Object {
63
+ "max": 1,
64
+ "min": 0,
65
+ "step": 1,
66
+ },
67
+ "range": Object {
68
+ "max": 1,
69
+ "min": 0,
70
+ "step": 1,
71
+ },
72
+ "scale": Object {
73
+ "x": [MockFunction],
74
+ "y": [MockFunction] {
75
+ "calls": Array [
76
+ Array [
77
+ NaN,
78
+ ],
79
+ Array [
80
+ NaN,
81
+ ],
82
+ ],
83
+ "results": Array [
84
+ Object {
85
+ "type": "return",
86
+ "value": NaN,
87
+ },
88
+ Object {
89
+ "type": "return",
90
+ "value": NaN,
91
+ },
92
+ ],
93
+ },
94
+ },
95
+ "size": Object {
96
+ "height": 400,
97
+ "width": 400,
98
+ },
99
+ "snap": Object {
100
+ "x": [MockFunction],
101
+ "y": [MockFunction],
102
+ },
103
+ }
104
+ }
105
+ isHovered={false}
106
+ onDrag={[Function]}
107
+ onDragStop={[Function]}
108
+ />
109
+ </g>
110
+ `;
@@ -0,0 +1,69 @@
1
+ import { shallow } from 'enzyme';
2
+ import React from 'react';
3
+ import Bars, { RawBar } from '../bars';
4
+ import { graphProps } from './utils';
5
+
6
+ describe('Bars', () => {
7
+ const xBand = () => {};
8
+ xBand.bandwidth = () => {};
9
+ const onChange = jest.fn();
10
+
11
+ const wrapper = (extras) => {
12
+ const defaults = {
13
+ classes: {},
14
+ className: 'className',
15
+ graphProps: graphProps(),
16
+ xBand,
17
+ onChange,
18
+ data: [{ value: 0, label: '0' }],
19
+ };
20
+ const props = { ...defaults, ...extras };
21
+ return shallow(<Bars {...props} />);
22
+ };
23
+
24
+ describe('snapshot', () => {
25
+ it('renders', () => expect(wrapper()).toMatchSnapshot());
26
+ });
27
+ });
28
+
29
+ describe('RawBar', () => {
30
+ const xBand = () => {};
31
+ xBand.bandwidth = () => {};
32
+ const onChangeCategory = jest.fn();
33
+
34
+ const wrapper = (extras) => {
35
+ const defaults = {
36
+ classes: {},
37
+ className: 'className',
38
+ graphProps: graphProps(),
39
+ xBand,
40
+ onChangeCategory,
41
+ data: [],
42
+ label: 'label',
43
+ };
44
+ const props = { ...defaults, ...extras };
45
+ return shallow(<RawBar {...props} />);
46
+ };
47
+
48
+ describe('snapshot', () => {
49
+ it('renders', () => expect(wrapper()).toMatchSnapshot());
50
+ });
51
+
52
+ describe('logic', () => {
53
+ const w = wrapper();
54
+
55
+ it('dragStop', () => {
56
+ w.instance().dragStop();
57
+
58
+ expect(onChangeCategory).not.toHaveBeenCalled();
59
+
60
+ w.instance().setState({
61
+ dragValue: 2,
62
+ });
63
+
64
+ w.instance().dragStop(0);
65
+
66
+ expect(onChangeCategory).toHaveBeenCalledWith({ label: 'label', value: 2 });
67
+ });
68
+ });
69
+ });