@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
@@ -1,15 +1,19 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
- import { types } from '@pie-lib/plot';
4
- import { Group } from '@vx/group';
3
+ import classNames from 'classnames';
4
+ import Check from '@material-ui/icons/Check';
5
5
  import { withStyles } from '@material-ui/core/styles/index';
6
- import DraggableHandle, { DragHandle } from '../../common/drag-handle';
6
+ import { Group } from '@vx/group';
7
7
  import debug from 'debug';
8
+
9
+ import { types } from '@pie-lib/plot';
10
+ import DraggableHandle, { DragHandle } from '../../common/drag-handle';
8
11
  import { color } from '@pie-lib/render-ui';
9
12
  import { bandKey } from '../../utils';
10
13
  import { correct, incorrect } from '../../common/styles';
11
14
 
12
15
  const log = debug('pie-lib:chart:bars');
16
+ const ICON_SIZE = 16; // 10px icon + 2px padding on all sides + 1px border
13
17
 
14
18
  export class RawPlot extends React.Component {
15
19
  static propTypes = {
@@ -64,6 +68,20 @@ export class RawPlot extends React.Component {
64
68
  this.setDragValue(next);
65
69
  };
66
70
 
71
+ renderCorrectnessIcon = (barX, barWidth, correctVal, correctness, classes, scale) => (
72
+ <foreignObject
73
+ x={barX + barWidth / 2 - ICON_SIZE / 2}
74
+ y={scale.y(correctVal) + ICON_SIZE}
75
+ width={ICON_SIZE}
76
+ height={ICON_SIZE}
77
+ >
78
+ <Check
79
+ className={classNames(classes.correctnessIcon, classes.correctIcon, classes.smallIcon)}
80
+ title={correctness.label}
81
+ />
82
+ </foreignObject>
83
+ );
84
+
67
85
  render() {
68
86
  const {
69
87
  graphProps,
@@ -76,6 +94,7 @@ export class RawPlot extends React.Component {
76
94
  interactive,
77
95
  correctness,
78
96
  defineChart,
97
+ correctData,
79
98
  } = this.props;
80
99
 
81
100
  const { scale, range, size } = graphProps;
@@ -98,17 +117,25 @@ export class RawPlot extends React.Component {
98
117
  const pointHeight = size.height / max;
99
118
  const pointDiameter = (pointHeight > barWidth ? barWidth : pointHeight) * 0.8;
100
119
  const Component = interactive ? DraggableHandle : DragHandle;
120
+ const allowRolloverEvent = interactive && !correctness;
101
121
 
102
122
  return (
103
123
  <React.Fragment>
104
- <g onMouseEnter={this.handleMouseEnter} onMouseLeave={this.handleMouseLeave}>
105
- {isHovered && (
124
+ <g
125
+ onMouseEnter={this.handleMouseEnter}
126
+ onMouseLeave={this.handleMouseLeave}
127
+ onTouchStart={this.handleMouseEnter}
128
+ onTouchEnd={this.handleMouseLeave}
129
+ >
130
+ {isHovered && allowRolloverEvent && (
106
131
  <rect
107
132
  x={barX}
108
133
  y={scale.y(v)}
109
134
  width={barWidth}
110
135
  height={values?.length ? pointHeight * values.length : 0}
111
- style={{ fill: '#E5E8F5' }}
136
+ stroke={color.defaults.BORDER_GRAY}
137
+ strokeWidth={'4px'}
138
+ fill={'transparent'}
112
139
  />
113
140
  )}
114
141
  {values.map((index) =>
@@ -124,6 +151,67 @@ export class RawPlot extends React.Component {
124
151
  scale,
125
152
  }),
126
153
  )}
154
+ {correctness &&
155
+ correctness.value === 'incorrect' &&
156
+ (() => {
157
+ const correctVal = parseFloat(correctData[index] && correctData[index].value);
158
+ if (isNaN(correctVal)) return null;
159
+ const selectedVal = v;
160
+ if (selectedVal > correctVal) {
161
+ // selected is higher than correct: overlay the correct last segment
162
+ const overlayValues = [];
163
+ for (let i = 0; i < correctVal; i++) {
164
+ overlayValues.push(i);
165
+ }
166
+ const lastIndexOfOverlay = overlayValues.length - 1;
167
+ const lastOverlayValue = overlayValues[lastIndexOfOverlay];
168
+ const barX = xBand(bandKey({ label }, index));
169
+ const barWidth = xBand.bandwidth();
170
+ const pointHeight = size.height / max;
171
+ const pointDiameter = (pointHeight > barWidth ? barWidth : pointHeight) * 0.8;
172
+ return (
173
+ <>
174
+ <CustomBarElement
175
+ index={lastOverlayValue}
176
+ pointDiameter={pointDiameter + 10} // increase point diameter for dotted line
177
+ barX={barX}
178
+ barWidth={barWidth}
179
+ pointHeight={pointHeight}
180
+ label={label}
181
+ value={value}
182
+ classes={classes}
183
+ scale={scale}
184
+ dottedOverline={true}
185
+ />
186
+ {this.renderCorrectnessIcon(barX, barWidth, correctVal, correctness, classes, scale)}
187
+ </>
188
+ );
189
+ }
190
+ // selected is lower than correct, render missing segment below the correct bar
191
+ const valuesToRender = [];
192
+ for (let i = selectedVal; i < correctVal; i++) {
193
+ valuesToRender.push(i);
194
+ }
195
+ return (
196
+ <>
197
+ {valuesToRender.map((idx) =>
198
+ CustomBarElement({
199
+ index: idx,
200
+ pointDiameter,
201
+ barX,
202
+ barWidth,
203
+ pointHeight,
204
+ label,
205
+ value,
206
+ classes,
207
+ scale,
208
+ dottedOverline: true,
209
+ }),
210
+ )}
211
+ {this.renderCorrectnessIcon(barX, barWidth, correctVal, correctness, classes, scale)}
212
+ </>
213
+ );
214
+ })()}
127
215
  <Component
128
216
  x={barX}
129
217
  y={v}
@@ -136,6 +224,7 @@ export class RawPlot extends React.Component {
136
224
  isHovered={isHovered}
137
225
  defineChart={defineChart}
138
226
  color={color.primaryDark()}
227
+ isPlot
139
228
  />
140
229
  </g>
141
230
  </React.Fragment>
@@ -143,17 +232,44 @@ export class RawPlot extends React.Component {
143
232
  }
144
233
  }
145
234
 
146
- const Bar = withStyles(() => ({
235
+ const Bar = withStyles((theme) => ({
147
236
  dot: {
148
- fill: color.primaryLight(),
237
+ fill: color.visualElementsColors.PLOT_FILL_COLOR,
149
238
  '&.correct': correct('stroke'),
150
239
  '&.incorrect': incorrect('stroke'),
151
240
  },
241
+ dotColor: {
242
+ fill: color.visualElementsColors.PLOT_FILL_COLOR,
243
+ '&.correct': correct('fill'),
244
+ '&.incorrect': incorrect('fill'),
245
+ },
152
246
  line: {
153
- stroke: color.primaryLight(),
247
+ stroke: color.visualElementsColors.PLOT_FILL_COLOR,
154
248
  '&.correct': correct('stroke'),
155
249
  '&.incorrect': incorrect('stroke'),
156
250
  },
251
+ correctIcon: {
252
+ backgroundColor: color.correct(),
253
+ },
254
+ incorrectIcon: {
255
+ backgroundColor: color.incorrectWithIcon(),
256
+ },
257
+ correctnessIcon: {
258
+ borderRadius: theme.spacing.unit * 2,
259
+ color: color.defaults.WHITE,
260
+ fontSize: '16px',
261
+ width: '16px',
262
+ height: '16px',
263
+ padding: '2px',
264
+ border: `1px solid ${color.defaults.WHITE}`,
265
+ stroke: 'initial',
266
+ boxSizing: 'unset', // to override the default border-box in IBX
267
+ },
268
+ smallIcon: {
269
+ fontSize: '10px',
270
+ width: '10px',
271
+ height: '10px',
272
+ },
157
273
  }))(RawPlot);
158
274
 
159
275
  export class Plot extends React.Component {
@@ -167,7 +283,7 @@ export class Plot extends React.Component {
167
283
  };
168
284
 
169
285
  render() {
170
- const { data, graphProps, xBand, CustomBarElement, onChangeCategory, defineChart } = this.props;
286
+ const { data, graphProps, xBand, CustomBarElement, onChangeCategory, defineChart, correctData } = this.props;
171
287
 
172
288
  return (
173
289
  <Group>
@@ -184,6 +300,7 @@ export class Plot extends React.Component {
184
300
  graphProps={graphProps}
185
301
  CustomBarElement={CustomBarElement}
186
302
  correctness={d.correctness}
303
+ correctData={correctData}
187
304
  />
188
305
  ))}
189
306
  </Group>
package/src/plot/dot.js CHANGED
@@ -1,18 +1,33 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
+ import { Circle } from '@vx/shape';
4
+
3
5
  import { types } from '@pie-lib/plot';
4
6
  import { dataToXBand } from '../utils';
5
7
  import Plot from './common/plot';
6
- import { Circle } from '@vx/shape';
8
+ import { color } from '@pie-lib/render-ui';
7
9
 
8
10
  const CustomBarElement = (props) => {
9
- const { index, pointDiameter, barX, barWidth, pointHeight, label, value, classes, scale } = props;
11
+ const { index, pointDiameter, barX, barWidth, pointHeight, label, value, classes, scale, dottedOverline } = props;
10
12
 
11
13
  const r = pointDiameter / 2;
12
14
  const cx = barX + (barWidth - pointDiameter) / 2 + r;
13
15
  const cy = scale.y(index) - (pointHeight - pointDiameter) / 2 - r;
16
+ const EXTRA_PADDING = 2;
14
17
 
15
- return <Circle key={`point-${label}-${value}-${index}`} className={classes.dot} cx={cx} cy={cy} r={r} />;
18
+ return dottedOverline ? (
19
+ <Circle
20
+ key={`point-${label}-${value}-${index}`}
21
+ cx={cx}
22
+ cy={cy}
23
+ r={r + EXTRA_PADDING}
24
+ strokeDasharray="4,4"
25
+ stroke={color.defaults.BORDER_GRAY}
26
+ fill="none"
27
+ />
28
+ ) : (
29
+ <Circle key={`point-${label}-${value}-${index}`} className={classes.dot} cx={cx} cy={cy} r={r} />
30
+ );
16
31
  };
17
32
 
18
33
  CustomBarElement.propTypes = {
@@ -25,6 +40,7 @@ CustomBarElement.propTypes = {
25
40
  label: PropTypes.string,
26
41
  classes: PropTypes.object,
27
42
  scale: PropTypes.object,
43
+ dottedOverline: PropTypes.bool,
28
44
  };
29
45
 
30
46
  export class DotPlot extends React.Component {
package/src/plot/line.js CHANGED
@@ -1,18 +1,32 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
+ import { LinePath } from '@vx/shape';
4
+ import { Group } from '@vx/group';
5
+
3
6
  import { types } from '@pie-lib/plot';
4
7
  import { dataToXBand } from '../utils';
8
+ import { color } from '@pie-lib/render-ui';
5
9
  import Plot from './common/plot';
6
- import { LinePath } from '@vx/shape';
7
- import { Group } from '@vx/group';
8
10
 
9
11
  const CustomBarElement = (props) => {
10
- const { index, pointDiameter, barX, barWidth, pointHeight, label, value, classes, scale } = props;
12
+ const { index, pointDiameter, barX, barWidth, pointHeight, label, value, classes, scale, dottedOverline } = props;
11
13
 
12
14
  const x = barX + (barWidth - pointDiameter) / 2;
13
15
  const y = scale.y(index) - (pointHeight - pointDiameter) / 2;
16
+ const EXTRA_PADDING = 2;
14
17
 
15
- return (
18
+ return dottedOverline ? (
19
+ <rect
20
+ key={`point-${label}-${value}-${index}`}
21
+ x={x - EXTRA_PADDING}
22
+ y={y - pointDiameter - EXTRA_PADDING}
23
+ width={pointDiameter + EXTRA_PADDING * 2}
24
+ height={pointDiameter + EXTRA_PADDING * 2}
25
+ strokeDasharray="4,4"
26
+ stroke={color.defaults.BORDER_GRAY}
27
+ fill="none"
28
+ />
29
+ ) : (
16
30
  <Group>
17
31
  <LinePath
18
32
  data={[
package/src/tool-menu.jsx CHANGED
@@ -12,12 +12,8 @@ const { translator } = Translator;
12
12
 
13
13
  const buttonStyles = (theme) => ({
14
14
  root: {
15
- backgroundColor: color.background(),
16
15
  color: color.text(),
17
16
  border: `1px solid ${color.secondary()}`,
18
- '&:hover': {
19
- backgroundColor: color.secondaryLight(),
20
- },
21
17
  fontSize: theme.typography.fontSize,
22
18
  },
23
19
  selected: {