@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
@@ -0,0 +1,55 @@
1
+ import React from 'react';
2
+ import classNames from 'classnames';
3
+ import Check from '@material-ui/icons/Check';
4
+ import Close from '@material-ui/icons/Close';
5
+
6
+ export const CorrectnessIndicator = ({ scale, x, y, classes, r, correctness, interactive }) => {
7
+ if (!correctness || !interactive) return null;
8
+ const cx = scale ? scale.x(x) : x;
9
+ const cy = scale ? scale.y(y) : y;
10
+ const isCorrect = correctness.value === 'correct';
11
+ const iconClass = isCorrect ? classes.correctIcon : classes.incorrectIcon;
12
+
13
+ // the icon is 16px + 2px padding + 1px border, so total size is 22px
14
+ return (
15
+ <foreignObject x={cx - 11} y={cy - 11} width={22} height={22}>
16
+ {isCorrect ? (
17
+ <Check className={classNames(classes.correctnessIcon, iconClass)} title={correctness.label} />
18
+ ) : (
19
+ <Close className={classNames(classes.correctnessIcon, iconClass)} title={correctness.label} />
20
+ )}
21
+ </foreignObject>
22
+ );
23
+ };
24
+
25
+ export const SmallCorrectPointIndicator = ({ scale, x, r, correctness, classes, correctData, label }) => {
26
+ if (correctness && correctness.value === 'incorrect') {
27
+ const correctVal = parseFloat(correctData.find((d) => d.label === label)?.value);
28
+ if (isNaN(correctVal)) return null;
29
+ const correctPxY = scale.y(correctVal);
30
+ const yToRender = correctPxY - 7.5;
31
+ const xToRender = scale.x(x) - 7.5;
32
+
33
+ // small circle has 10px font + 2px padding + 1px border, so total size is 15px
34
+ return (
35
+ <foreignObject x={xToRender} y={yToRender} width={15} height={15}>
36
+ <Check
37
+ className={classNames(classes.correctnessIcon, classes.correctIcon, classes.smallIcon)}
38
+ title={correctness.label}
39
+ />
40
+ </foreignObject>
41
+ );
42
+ }
43
+
44
+ return null;
45
+ };
46
+
47
+ export const TickCorrectnessIndicator = ({ classes, correctness, interactive }) => {
48
+ if (!correctness || !interactive) return null;
49
+
50
+ return correctness.value === 'correct' ? (
51
+ <Check className={classNames(classes.correctnessIcon, classes.correctIcon)} title={correctness.label} />
52
+ ) : (
53
+ <Close className={classNames(classes.correctnessIcon, classes.incorrectIcon)} title={correctness.label} />
54
+ );
55
+ };
@@ -2,8 +2,11 @@ import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import classNames from 'classnames';
4
4
  import { withStyles } from '@material-ui/core/styles';
5
+ import Check from '@material-ui/icons/Check';
6
+ import Close from '@material-ui/icons/Close';
7
+
5
8
  import { gridDraggable, utils, types } from '@pie-lib/plot';
6
- import { color } from '@pie-lib/render-ui';
9
+ import { color as enumColor } from '@pie-lib/render-ui';
7
10
  import { correct, incorrect, disabled } from './styles';
8
11
  import { getScale } from '../utils';
9
12
  import DragIcon from './drag-icon';
@@ -20,21 +23,28 @@ const RawDragHandle = ({
20
23
  isHovered,
21
24
  correctness,
22
25
  color,
26
+ isPlot,
23
27
  ...rest
24
28
  }) => {
25
29
  const { scale } = graphProps;
26
30
  const scaleValue = getScale(width)?.scale;
27
31
 
28
32
  return (
29
- <svg x={x} y={scale.y(y) - 10} width={width} overflow="visible">
30
- {isHovered && !correctness && interactive && <DragIcon width={width} scaleValue={scaleValue} color={color} />}
31
- <circle
32
- cx={width / 2}
33
- cy={10}
34
- r={width / 2}
35
- className={classNames(classes.transparentHandle, className)}
36
- {...rest}
37
- />
33
+ <svg x={x} y={scale.y(y) - 10} width={width} overflow="visible" className={classes.svgOverflowVisible}>
34
+ {isHovered && !correctness && interactive && (
35
+ <DragIcon width={width} scaleValue={scaleValue} color={enumColor.defaults.BORDER_GRAY} classes={classes} />
36
+ )}
37
+ {interactive && !correctness && (
38
+ <ellipse
39
+ cx={width / 2}
40
+ cy={10}
41
+ rx={width / 2}
42
+ // the drag icon has a 22px fixed r value, so the ry value is 3 times that in order to cover all the area
43
+ ry={66}
44
+ className={classNames(classes.transparentHandle, className)}
45
+ {...rest}
46
+ />
47
+ )}
38
48
 
39
49
  <defs>
40
50
  <filter id="bottomShadow" x="0" y="0" width="140%" height="140%">
@@ -49,20 +59,14 @@ const RawDragHandle = ({
49
59
  </filter>
50
60
  </defs>
51
61
 
52
- {correctness && (
53
- <rect
54
- y={10}
55
- width={width}
56
- filter="url(#bottomShadow)"
57
- className={classNames(
58
- classes.handle,
59
- 'handle',
60
- className,
61
- !interactive && 'non-interactive',
62
- interactive && correctness && correctness.value,
62
+ {correctness && interactive && !isPlot && (
63
+ <foreignObject x={width / 2 - 14} y={0} width={40} height={40}>
64
+ {correctness.value === 'correct' ? (
65
+ <Check className={classNames(classes.correctnessIcon, classes.correctIcon)} title={correctness.label} />
66
+ ) : (
67
+ <Close className={classNames(classes.correctnessIcon, classes.incorrectIcon)} title={correctness.label} />
63
68
  )}
64
- {...rest}
65
- />
69
+ </foreignObject>
66
70
  )}
67
71
  </svg>
68
72
  );
@@ -84,7 +88,7 @@ RawDragHandle.propTypes = {
84
88
  color: PropTypes.string,
85
89
  };
86
90
 
87
- export const DragHandle = withStyles(() => ({
91
+ export const DragHandle = withStyles((theme) => ({
88
92
  handle: {
89
93
  height: '10px',
90
94
  fill: 'transparent',
@@ -94,7 +98,6 @@ export const DragHandle = withStyles(() => ({
94
98
  '&.non-interactive': disabled('fill'),
95
99
  },
96
100
  transparentHandle: {
97
- height: '20px',
98
101
  fill: 'transparent',
99
102
  clipPath: 'polygon(50% 0%, 100% 0%, 100% 50%, 0% 50%, 0% 0%)',
100
103
  },
@@ -102,7 +105,7 @@ export const DragHandle = withStyles(() => ({
102
105
  height: 30,
103
106
  '&:hover': {
104
107
  '& .handle': {
105
- fill: color.secondaryDark(),
108
+ fill: enumColor.secondaryDark(),
106
109
  height: '16px',
107
110
  },
108
111
  },
@@ -110,6 +113,25 @@ export const DragHandle = withStyles(() => ({
110
113
  '&.incorrect': incorrect('fill'),
111
114
  '&.correct': correct('fill'),
112
115
  },
116
+ svgOverflowVisible: {
117
+ overflow: 'visible !important',
118
+ },
119
+ correctIcon: {
120
+ backgroundColor: enumColor.correct(),
121
+ },
122
+ incorrectIcon: {
123
+ backgroundColor: enumColor.incorrectWithIcon(),
124
+ },
125
+ correctnessIcon: {
126
+ borderRadius: theme.spacing.unit * 2,
127
+ color: enumColor.defaults.WHITE,
128
+ fontSize: '16px',
129
+ padding: '2px',
130
+ border: `4px solid ${enumColor.defaults.WHITE}`,
131
+ width: '16px',
132
+ height: '16px',
133
+ boxSizing: 'unset', // to override the default border-box in IBX
134
+ },
113
135
  }))(RawDragHandle);
114
136
 
115
137
  export const D = gridDraggable({
@@ -1,33 +1,18 @@
1
1
  import React from 'react';
2
2
  import { getAdjustedX, getScale } from '../utils';
3
3
 
4
- const DragIcon = ({ width, scaleValue, color }) => (
4
+ const DragIcon = ({ width, scaleValue, color, classes }) => (
5
5
  <svg
6
6
  x={getAdjustedX(width, scaleValue)}
7
7
  y={getScale(width)?.deltay}
8
8
  color={color}
9
+ width={width}
10
+ height={width}
9
11
  overflow="visible"
10
- filter="url(#svgDropShadow)"
12
+ viewBox={`0 0 ${width} ${width}`}
13
+ className={classes.svgOverflowVisible}
11
14
  >
12
- <defs>
13
- <filter id="svgDropShadow" x="-20%" y="-20%" width="140%" height="140%">
14
- <feGaussianBlur in="SourceAlpha" stdDeviation="3" />
15
- <feOffset dx="0" dy="5" result="offsetblur" />
16
- <feFlood floodColor="#00000033" />
17
- <feComposite in2="offsetblur" operator="in" />
18
- <feMerge>
19
- <feMergeNode />
20
- <feMergeNode in="SourceGraphic" />
21
- </feMerge>
22
- </filter>
23
- </defs>
24
- <g
25
- xmlns="http://www.w3.org/2000/svg"
26
- filter="url(#filter0_d_2312_1804)"
27
- fill="currentColor"
28
- stroke="currentColor"
29
- transform={`scale(${scaleValue})`}
30
- >
15
+ <g xmlns="http://www.w3.org/2000/svg" fill="currentColor" stroke="currentColor" transform={`scale(${scaleValue})`}>
31
16
  <circle cx="28.5" cy="23.5" r="22" fill="white" stroke="currentColor" />
32
17
  <path
33
18
  d="M33.5 21.25H23.4609C22.7578 21.25 22.4062 20.4297 22.9141 19.9219L27.9141 14.9219C28.2266 14.6094 28.7344 14.6094 29.0469 14.9219L34.0469 19.9219C34.5547 20.4297 34.2031 21.25 33.5 21.25Z"
package/src/grid.jsx CHANGED
@@ -2,8 +2,8 @@ import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import { withStyles } from '@material-ui/core/styles';
4
4
  import classNames from 'classnames';
5
+ import { GridRows, GridColumns } from '@vx/grid';
5
6
 
6
- import { Grid as VxGrid } from '@vx/grid';
7
7
  import { types } from '@pie-lib/plot';
8
8
  import { color } from '@pie-lib/render-ui';
9
9
 
@@ -21,19 +21,44 @@ export class Grid extends React.Component {
21
21
 
22
22
  render() {
23
23
  const { classes, className, graphProps, xBand, rowTickValues, columnTickValues } = this.props;
24
- const { scale = {}, size = {} } = graphProps || {};
24
+ const { scale = {}, size = {}, range = {} } = graphProps || {};
25
+ const { step = 0, labelStep = 0 } = range;
26
+ const highlightNonLabel = step && labelStep && step < labelStep;
27
+ // if highlightNonLabel is true, we need to separate the unlabled lines in order to render them in a different color
28
+ const { unlabeledLines, labeledLines } = (rowTickValues || []).reduce(
29
+ (acc, value) => {
30
+ if (highlightNonLabel && value % labelStep !== 0) {
31
+ acc.unlabeledLines.push(value);
32
+ } else {
33
+ acc.labeledLines.push(value);
34
+ }
35
+ return acc;
36
+ },
37
+ { unlabeledLines: [], labeledLines: [] },
38
+ );
25
39
 
26
40
  return (
27
- <VxGrid
28
- xScale={xBand}
29
- yScale={scale.y}
30
- className={classNames(classes.grid, className)}
31
- width={size.width}
32
- height={size.height}
33
- xOffset={xBand.bandwidth() / 2}
34
- rowTickValues={rowTickValues}
35
- columnTickValues={columnTickValues}
36
- />
41
+ <g className={classNames(classes.grid, className)}>
42
+ <GridRows
43
+ scale={scale.y}
44
+ width={size.width}
45
+ tickValues={unlabeledLines}
46
+ lineStyle={{
47
+ stroke: color.fadedPrimary(),
48
+ strokeWidth: 1,
49
+ }}
50
+ />
51
+ <GridRows
52
+ scale={scale.y}
53
+ width={size.width}
54
+ tickValues={labeledLines}
55
+ lineStyle={{
56
+ stroke: color.visualElementsColors.GRIDLINES_COLOR,
57
+ strokeWidth: 1,
58
+ }}
59
+ />
60
+ <GridColumns scale={xBand} height={size.height} offset={xBand.bandwidth() / 2} tickValues={columnTickValues} />
61
+ </g>
37
62
  );
38
63
  }
39
64
  }
package/src/index.js CHANGED
@@ -2,5 +2,6 @@ import Chart from './chart';
2
2
  import chartTypes from './chart-types';
3
3
  import ConfigureChartPanel from './chart-setup';
4
4
  import ChartType from './chart-type';
5
+ import KeyLegend from './key-legend';
5
6
 
6
- export { Chart, chartTypes, ChartType, ConfigureChartPanel };
7
+ export { Chart, chartTypes, ChartType, ConfigureChartPanel, KeyLegend };
@@ -0,0 +1,75 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { withStyles } from '@material-ui/core/styles';
4
+ import Check from '@material-ui/icons/Check';
5
+ import Close from '@material-ui/icons/Close';
6
+ import { color } from '@pie-lib/render-ui';
7
+ import Translator from '@pie-lib/translator';
8
+
9
+ const styles = (theme) => ({
10
+ container: {
11
+ backgroundColor: color.defaults.WHITE,
12
+ padding: theme.spacing.unit * 2,
13
+ width: '355px',
14
+ boxShadow: 'inset 0px 1px 5px 0px #9297A6',
15
+ display: 'flex',
16
+ flexDirection: 'column',
17
+ gap: '16px',
18
+ },
19
+ row: {
20
+ display: 'flex',
21
+ alignItems: 'center',
22
+ gap: '12px',
23
+ },
24
+ title: {
25
+ fontSize: theme.typography.h6.fontSize,
26
+ fontWeight: '700',
27
+ },
28
+ smallText: {
29
+ marginLeft: '2px',
30
+ },
31
+ correctIcon: {
32
+ backgroundColor: color.correct(),
33
+ borderRadius: theme.spacing.unit * 2,
34
+ color: color.defaults.WHITE,
35
+ },
36
+ incorrectIcon: {
37
+ backgroundColor: color.incorrectWithIcon(),
38
+ borderRadius: theme.spacing.unit * 2,
39
+ color: color.defaults.WHITE,
40
+ },
41
+
42
+ lastRow: {
43
+ marginLeft: '3px',
44
+ display: 'flex',
45
+ alignItems: 'center',
46
+ gap: '12px',
47
+ },
48
+ });
49
+
50
+ const { translator } = Translator;
51
+
52
+ const KeyLegend = ({ classes, language }) => (
53
+ <div className={classes.container}>
54
+ <div className={classes.title}>Key</div>
55
+ <div className={classes.row}>
56
+ <Close className={classes.incorrectIcon} />
57
+ <div className={classes.text}>{translator.t('charting.keyLegend.incorrectAnswer', { lng: language })}</div>
58
+ </div>
59
+ <div className={classes.row}>
60
+ <Check className={classes.correctIcon} />
61
+ <div className={classes.text}>{translator.t('charting.keyLegend.correctAnswer', { lng: language })}</div>
62
+ </div>
63
+ <div className={classes.lastRow}>
64
+ <Check className={classes.correctIcon} fontSize={'small'} />
65
+ <div className={classes.smallText}>{translator.t('charting.keyLegend.correctKeyAnswer', { lng: language })}</div>
66
+ </div>
67
+ </div>
68
+ );
69
+
70
+ KeyLegend.propTypes = {
71
+ classes: PropTypes.object.isRequired,
72
+ language: PropTypes.string,
73
+ };
74
+
75
+ export default withStyles(styles)(KeyLegend);
@@ -0,0 +1,45 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`LineChart snapshot renders 1`] = `
4
+ <Line
5
+ CustomDraggableComponent={[Function]}
6
+ className="className"
7
+ classes={Object {}}
8
+ graphProps={
9
+ Object {
10
+ "domain": Object {
11
+ "max": 1,
12
+ "min": 0,
13
+ "step": 1,
14
+ },
15
+ "range": Object {
16
+ "max": 1,
17
+ "min": 0,
18
+ "step": 1,
19
+ },
20
+ "scale": Object {
21
+ "x": [MockFunction],
22
+ "y": [MockFunction],
23
+ },
24
+ "size": Object {
25
+ "height": 400,
26
+ "width": 400,
27
+ },
28
+ "snap": Object {
29
+ "x": [MockFunction],
30
+ "y": [MockFunction],
31
+ },
32
+ }
33
+ }
34
+ xBand={[Function]}
35
+ />
36
+ `;
37
+
38
+ exports[`LineChart snapshot renders without graphProps 1`] = `
39
+ <Line
40
+ CustomDraggableComponent={[Function]}
41
+ className="className"
42
+ classes={Object {}}
43
+ xBand={[Function]}
44
+ />
45
+ `;
@@ -0,0 +1,45 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`LineChart snapshot renders 1`] = `
4
+ <Line
5
+ CustomDraggableComponent={[Function]}
6
+ className="className"
7
+ classes={Object {}}
8
+ graphProps={
9
+ Object {
10
+ "domain": Object {
11
+ "max": 1,
12
+ "min": 0,
13
+ "step": 1,
14
+ },
15
+ "range": Object {
16
+ "max": 1,
17
+ "min": 0,
18
+ "step": 1,
19
+ },
20
+ "scale": Object {
21
+ "x": [MockFunction],
22
+ "y": [MockFunction],
23
+ },
24
+ "size": Object {
25
+ "height": 400,
26
+ "width": 400,
27
+ },
28
+ "snap": Object {
29
+ "x": [MockFunction],
30
+ "y": [MockFunction],
31
+ },
32
+ }
33
+ }
34
+ xBand={[Function]}
35
+ />
36
+ `;
37
+
38
+ exports[`LineChart snapshot renders without graphProps 1`] = `
39
+ <Line
40
+ CustomDraggableComponent={[Function]}
41
+ className="className"
42
+ classes={Object {}}
43
+ xBand={[Function]}
44
+ />
45
+ `;
@@ -0,0 +1,38 @@
1
+ import { shallow } from 'enzyme';
2
+ import React from 'react';
3
+ import Line, { LineCross as LineChart } from '../line-cross';
4
+ import { graphProps } from './utils';
5
+ import { Bar as BarChart } from '../../bars/bar';
6
+
7
+ describe('LineChart', () => {
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(<LineChart {...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 = Line();
31
+
32
+ expect(chart).toEqual({
33
+ type: 'lineCross',
34
+ Component: LineChart,
35
+ name: 'Line Cross',
36
+ });
37
+ });
38
+ });
@@ -0,0 +1,38 @@
1
+ import { shallow } from 'enzyme';
2
+ import React from 'react';
3
+ import Line, { LineDot as LineChart } from '../line-dot';
4
+ import { graphProps } from './utils';
5
+ import { Bar as BarChart } from '../../bars/bar';
6
+
7
+ describe('LineChart', () => {
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(<LineChart {...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 = Line();
31
+
32
+ expect(chart).toEqual({
33
+ type: 'lineDot',
34
+ Component: LineChart,
35
+ name: 'Line Dot',
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,49 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`BasePoint snapshot renders 1`] = `
4
+ <RawDragHandle
5
+ className="className"
6
+ classes={
7
+ Object {
8
+ "correctIcon": "RawDragHandle-correctIcon-5",
9
+ "correctnessIcon": "RawDragHandle-correctnessIcon-7",
10
+ "disabledPoint": "RawDragHandle-disabledPoint-4",
11
+ "handle": "RawDragHandle-handle-1",
12
+ "incorrectIcon": "RawDragHandle-incorrectIcon-6",
13
+ "line": "RawDragHandle-line-3",
14
+ "smallIcon": "RawDragHandle-smallIcon-8",
15
+ "transparentHandle": "RawDragHandle-transparentHandle-2",
16
+ }
17
+ }
18
+ graphProps={
19
+ Object {
20
+ "domain": Object {
21
+ "max": 1,
22
+ "min": 0,
23
+ "step": 1,
24
+ },
25
+ "range": Object {
26
+ "max": 1,
27
+ "min": 0,
28
+ "step": 1,
29
+ },
30
+ "scale": Object {
31
+ "x": [MockFunction],
32
+ "y": [MockFunction],
33
+ },
34
+ "size": Object {
35
+ "height": 400,
36
+ "width": 400,
37
+ },
38
+ "snap": Object {
39
+ "x": [MockFunction],
40
+ "y": [MockFunction],
41
+ },
42
+ }
43
+ }
44
+ onChange={[MockFunction]}
45
+ width={100}
46
+ x={0}
47
+ y={0}
48
+ />
49
+ `;