@pie-lib/charting 5.48.0-mui-update.0 → 5.50.0-mui-update.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 (44) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/lib/axes.js +1 -1
  3. package/lib/axes.js.map +1 -1
  4. package/lib/bars/common/bars.js +9 -15
  5. package/lib/bars/common/bars.js.map +1 -1
  6. package/lib/chart-setup.js +1 -1
  7. package/lib/chart-setup.js.map +1 -1
  8. package/lib/chart.js +1 -4
  9. package/lib/chart.js.map +1 -1
  10. package/lib/common/drag-handle.js +2 -5
  11. package/lib/common/drag-handle.js.map +1 -1
  12. package/lib/grid.js +2 -5
  13. package/lib/grid.js.map +1 -1
  14. package/lib/line/common/line.js +2 -3
  15. package/lib/line/common/line.js.map +1 -1
  16. package/lib/line/line-cross.js +2 -2
  17. package/lib/line/line-cross.js.map +1 -1
  18. package/lib/line/line-dot.js +1 -5
  19. package/lib/line/line-dot.js.map +1 -1
  20. package/lib/plot/common/plot.js +2 -3
  21. package/lib/plot/common/plot.js.map +1 -1
  22. package/lib/plot/dot.js +1 -1
  23. package/lib/plot/dot.js.map +1 -1
  24. package/lib/plot/line.js +2 -2
  25. package/lib/plot/line.js.map +1 -1
  26. package/lib/tool-menu.js +1 -5
  27. package/lib/tool-menu.js.map +1 -1
  28. package/lib/utils.js +11 -9
  29. package/lib/utils.js.map +1 -1
  30. package/package.json +13 -13
  31. package/src/axes.jsx +1 -1
  32. package/src/bars/common/bars.jsx +36 -49
  33. package/src/chart-setup.jsx +1 -1
  34. package/src/chart.jsx +1 -2
  35. package/src/common/drag-handle.jsx +0 -3
  36. package/src/grid.jsx +3 -3
  37. package/src/line/common/line.jsx +2 -3
  38. package/src/line/line-cross.js +2 -2
  39. package/src/line/line-dot.js +3 -27
  40. package/src/plot/common/plot.jsx +2 -3
  41. package/src/plot/dot.js +1 -1
  42. package/src/plot/line.js +2 -2
  43. package/src/tool-menu.jsx +10 -11
  44. package/src/utils.js +13 -9
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
- import { Group } from '@vx/group';
4
- import { Bar as VxBar } from '@vx/shape';
3
+ import { Group } from '@visx/group';
4
+ import { Bar as VisxBar } from '@visx/shape';
5
5
  import { styled } from '@mui/material/styles';
6
6
  import debug from 'debug';
7
7
 
@@ -51,7 +51,7 @@ const calculateFillColor = (isHovered, barColor, index, hoverHistogramColors, al
51
51
  return barColor || null;
52
52
  };
53
53
 
54
- const StyledVxBar = styled(VxBar)(() => ({
54
+ const StyledVisxBar = styled(VisxBar)(() => ({
55
55
  fill: color.defaults.TERTIARY,
56
56
  }));
57
57
 
@@ -91,17 +91,14 @@ export class RawBar extends React.Component {
91
91
  }
92
92
 
93
93
  handleMouseMove = (e) => {
94
- // Update mouse position
95
94
  this.mouseX = e.clientX;
96
95
  this.mouseY = e.clientY;
97
- // Check if the mouse is inside the <g> element
98
96
  const isMouseInside = this.isMouseInsideSvgElement();
99
97
  this.setState({ isHovered: isMouseInside });
100
98
  };
101
99
 
102
100
  isMouseInsideSvgElement = () => {
103
101
  const gBoundingBox = this.gRef.getBoundingClientRect();
104
- // Check if the mouse position is within the bounding box
105
102
  return (
106
103
  this.mouseX >= gBoundingBox.left &&
107
104
  this.mouseX <= gBoundingBox.right &&
@@ -110,13 +107,8 @@ export class RawBar extends React.Component {
110
107
  );
111
108
  };
112
109
 
113
- handleMouseEnter = () => {
114
- this.setState({ isHovered: true });
115
- };
116
-
117
- handleMouseLeave = () => {
118
- this.setState({ isHovered: false });
119
- };
110
+ handleMouseEnter = () => this.setState({ isHovered: true });
111
+ handleMouseLeave = () => this.setState({ isHovered: false });
120
112
 
121
113
  setDragValue = (dragValue) => this.setState({ dragValue });
122
114
 
@@ -163,7 +155,6 @@ export class RawBar extends React.Component {
163
155
  const rawY = range.max - v;
164
156
  const yy = range.max - rawY;
165
157
  const correctValue = correctData ? correctData.find((d) => d.label === label) : null;
166
- log('label:', label, 'barX:', barX, 'v: ', v, 'barHeight:', barHeight, 'barWidth: ', barWidth);
167
158
 
168
159
  const Component = interactive ? DraggableHandle : DragHandle;
169
160
  const isHistogram = !!barColor;
@@ -176,46 +167,43 @@ export class RawBar extends React.Component {
176
167
  onTouchStart={this.handleMouseEnter}
177
168
  onTouchEnd={this.handleMouseLeave}
178
169
  >
179
- <StyledVxBar
170
+ <StyledVisxBar
180
171
  x={barX}
181
172
  y={scale.y(yy)}
182
173
  width={barWidth}
183
174
  height={barHeight}
184
175
  style={{ fill: fillColor }}
185
176
  />
186
- {correctness &&
187
- correctness.value === 'incorrect' &&
188
- (() => {
189
- const correctVal = parseFloat(correctValue && correctValue.value);
190
- if (isNaN(correctVal)) return null;
191
- const correctPxHeight = scale.y(range.max - correctVal);
192
- const actualPxHeight = barHeight;
193
- const diffPx = Math.abs(correctPxHeight - actualPxHeight);
194
- const yDiff = scale.y(correctVal);
195
- const indicatorBarColor = correctPxHeight > actualPxHeight ? color.borderGray() : color.defaults.WHITE;
196
- const yToRender = correctPxHeight > actualPxHeight ? yDiff : yDiff - diffPx;
177
+ {correctness && correctness.value === 'incorrect' && (() => {
178
+ const correctVal = parseFloat(correctValue && correctValue.value);
179
+ if (isNaN(correctVal)) return null;
180
+ const correctPxHeight = scale.y(range.max - correctVal);
181
+ const actualPxHeight = barHeight;
182
+ const diffPx = Math.abs(correctPxHeight - actualPxHeight);
183
+ const yDiff = scale.y(correctVal);
184
+ const indicatorBarColor = correctPxHeight > actualPxHeight ? color.borderGray() : color.defaults.WHITE;
185
+ const yToRender = correctPxHeight > actualPxHeight ? yDiff : yDiff - diffPx;
197
186
 
198
- return (
199
- <>
200
- <StyledVxBar
201
- x={barX + 2} // add 2px for the stroke (the dashed border)
202
- y={yToRender}
203
- width={barWidth - 4} // substract 4px for the total stroke
204
- height={diffPx}
205
- style={{
206
- stroke: indicatorBarColor,
207
- strokeWidth: 2,
208
- strokeDasharray: '5,2',
209
- fill: 'none',
210
- }}
211
- />
212
- {/* adjust the position based on whether it's a histogram or not, because the histogram does not have space for the icon on the side */}
213
- <foreignObject x={barX + barWidth - (isHistogram ? 24 : 14)} y={yDiff - 12} width={24} height={24}>
214
- <CorrectCheckIcon dashColor={indicatorBarColor} />
215
- </foreignObject>
216
- </>
217
- );
218
- })()}
187
+ return (
188
+ <>
189
+ <StyledVisxBar
190
+ x={barX + 2}
191
+ y={yToRender}
192
+ width={barWidth - 4}
193
+ height={diffPx}
194
+ style={{ stroke: indicatorBarColor, strokeWidth: 2, strokeDasharray: '5,2', fill: 'none' }}
195
+ />
196
+ <foreignObject
197
+ x={barX + barWidth - (isHistogram ? 24 : 14)}
198
+ y={yDiff - 12}
199
+ width={24}
200
+ height={24}
201
+ >
202
+ <CorrectCheckIcon dashColor={indicatorBarColor} />
203
+ </foreignObject>
204
+ </>
205
+ );
206
+ })()}
219
207
  <Component
220
208
  x={barX}
221
209
  y={v}
@@ -266,8 +254,7 @@ export class Bars extends React.Component {
266
254
  correctness={d.correctness}
267
255
  correctData={correctData}
268
256
  barColor={
269
- histogram &&
270
- (histogramColors[index] ? histogramColors[index] : histogramColors[index % histogramColors.length])
257
+ histogram && (histogramColors[index] ? histogramColors[index] : histogramColors[index % histogramColors.length])
271
258
  }
272
259
  />
273
260
  ))}
@@ -198,7 +198,7 @@ const ConfigureChartPanel = (props) => {
198
198
  // check if current chart values are invalid for given range step/max
199
199
  const outOfRange = isOutOfRange(model.data, range) || isOutOfRange(model.correctAnswer.data, range);
200
200
 
201
- if (outOfRange && JSON.stringify(e) !== '{}') {
201
+ if (outOfRange && e?.target) {
202
202
  setOpen(true);
203
203
  } else {
204
204
  onChange({ ...model, range });
package/src/chart.jsx CHANGED
@@ -212,7 +212,6 @@ export class Chart extends React.Component {
212
212
 
213
213
  render() {
214
214
  const {
215
- className,
216
215
  domain = {},
217
216
  range = {},
218
217
  chartingOptions,
@@ -280,7 +279,7 @@ export class Chart extends React.Component {
280
279
  }
281
280
 
282
281
  return (
283
- <StyledChartContainer className={className}>
282
+ <StyledChartContainer>
284
283
  <Root
285
284
  title={title}
286
285
  onChangeTitle={onChangeTitle}
@@ -47,7 +47,6 @@ const RawDragHandle = ({
47
47
  y,
48
48
  width,
49
49
  graphProps,
50
- className,
51
50
  interactive,
52
51
  defineChart,
53
52
  isHovered,
@@ -71,7 +70,6 @@ const RawDragHandle = ({
71
70
  rx={width / 2}
72
71
  // the drag icon has a 22px fixed r value, so the ry value is 3 times that in order to cover all the area
73
72
  ry={66}
74
- className={className}
75
73
  {...rest}
76
74
  />
77
75
  )}
@@ -107,7 +105,6 @@ RawDragHandle.propTypes = {
107
105
  y: PropTypes.number.isRequired,
108
106
  width: PropTypes.number,
109
107
  graphProps: types.GraphPropsType.isRequired,
110
- className: PropTypes.string,
111
108
  interactive: PropTypes.bool,
112
109
  isHovered: PropTypes.bool,
113
110
  correctness: PropTypes.shape({
package/src/grid.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 { GridRows, GridColumns } from '@vx/grid';
4
+ import { GridRows, GridColumns } from '@visx/grid';
5
5
 
6
6
  import { types } from '@pie-lib/plot';
7
7
  import { color } from '@pie-lib/render-ui';
@@ -22,7 +22,7 @@ export class Grid extends React.Component {
22
22
  static defaultProps = {};
23
23
 
24
24
  render() {
25
- const { className, graphProps, xBand, rowTickValues, columnTickValues } = this.props;
25
+ const { graphProps, xBand, rowTickValues, columnTickValues } = this.props;
26
26
  const { scale = {}, size = {}, range = {} } = graphProps || {};
27
27
  const { step = 0, labelStep = 0 } = range;
28
28
  const highlightNonLabel = step && labelStep && step < labelStep;
@@ -40,7 +40,7 @@ export class Grid extends React.Component {
40
40
  );
41
41
 
42
42
  return (
43
- <StyledGridGroup className={className}>
43
+ <StyledGridGroup>
44
44
  <GridRows
45
45
  scale={scale.y}
46
46
  width={size.width}
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
- import { Group } from '@vx/group';
3
- import { LinePath } from '@vx/shape';
2
+ import { Group } from '@visx/group';
3
+ import { LinePath } from '@visx/shape';
4
4
  import PropTypes from 'prop-types';
5
5
  import { types } from '@pie-lib/plot';
6
6
  import DraggableHandle, { DragHandle } from './drag-handle';
@@ -89,7 +89,6 @@ export class RawLine extends React.Component {
89
89
  const { scale } = graphProps;
90
90
  const lineToUse = dragging ? lineState : getData(data, graphProps.domain);
91
91
 
92
- console.log('defineChart', lineToUse);
93
92
  return (
94
93
  <React.Fragment>
95
94
  <StyledLinePath
@@ -1,7 +1,7 @@
1
1
  import React, { useState } from 'react';
2
2
  import PropTypes from 'prop-types';
3
- import { LinePath } from '@vx/shape';
4
- import { Group } from '@vx/group';
3
+ import { LinePath } from '@visx/shape';
4
+ import { Group } from '@visx/group';
5
5
  import { styled } from '@mui/material/styles';
6
6
 
7
7
  import { color } from '@pie-lib/render-ui';
@@ -8,10 +8,7 @@ import { dataToXBand } from '../utils';
8
8
  import RawLine from './common/line';
9
9
  import { CorrectnessIndicator, SmallCorrectPointIndicator } from '../common/correctness-indicators';
10
10
 
11
-
12
- const StyledHandle = styled('circle')(({ correctness, interactive }) => ({
13
- }));
14
-
11
+ const StyledHandle = styled('circle')(({ correctness, interactive }) => ({}));
15
12
 
16
13
  const StyledTransparentHandle = styled('circle')(() => ({
17
14
  height: '20px',
@@ -20,18 +17,7 @@ const StyledTransparentHandle = styled('circle')(() => ({
20
17
  pointerEvents: 'auto', // allow drag events
21
18
  }));
22
19
 
23
- const DraggableComponent = ({
24
- scale,
25
- x,
26
- y,
27
- className,
28
- r,
29
- correctness,
30
- interactive,
31
- correctData,
32
- label,
33
- ...rest
34
- }) => {
20
+ const DraggableComponent = ({ scale, x, y, r, correctness, interactive, correctData, label, ...rest }) => {
35
21
  const [isHovered, setIsHovered] = React.useState(false);
36
22
  const allowRolloverEvent = !correctness && interactive;
37
23
 
@@ -46,7 +32,6 @@ const DraggableComponent = ({
46
32
  cx={scale.x(x)}
47
33
  cy={scale.y(y)}
48
34
  r={r * 3}
49
- className={className}
50
35
  onMouseEnter={() => setIsHovered(true)}
51
36
  onMouseLeave={() => setIsHovered(false)}
52
37
  {...rest}
@@ -55,20 +40,12 @@ const DraggableComponent = ({
55
40
  cx={scale.x(x)}
56
41
  cy={scale.y(y)}
57
42
  r={r}
58
- className={className}
59
43
  correctness={correctness}
60
44
  interactive={interactive}
61
45
  {...rest}
62
46
  />
63
47
  {/* show correctness indicators */}
64
- <CorrectnessIndicator
65
- scale={scale}
66
- x={x}
67
- y={y}
68
- r={r}
69
- correctness={correctness}
70
- interactive={interactive}
71
- />
48
+ <CorrectnessIndicator scale={scale} x={x} y={y} r={r} correctness={correctness} interactive={interactive} />
72
49
 
73
50
  {/* show correct point if answer was incorrect */}
74
51
  <SmallCorrectPointIndicator
@@ -101,7 +78,6 @@ DraggableComponent.propTypes = {
101
78
  x: PropTypes.number,
102
79
  y: PropTypes.number,
103
80
  r: PropTypes.number,
104
- className: PropTypes.string,
105
81
  correctness: PropTypes.shape({
106
82
  value: PropTypes.string,
107
83
  label: PropTypes.string,
@@ -1,9 +1,8 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
- import classNames from 'classnames';
4
3
  import Check from '@mui/icons-material/Check';
5
4
  import { styled } from '@mui/material/styles';
6
- import { Group } from '@vx/group';
5
+ import { Group } from '@visx/group';
7
6
  import debug from 'debug';
8
7
 
9
8
  import { types } from '@pie-lib/plot';
@@ -82,7 +81,7 @@ export class RawPlot extends React.Component {
82
81
  return (
83
82
  <foreignObject x={barX + barWidth / 2 - ICON_SIZE / 2} y={iconY} width={ICON_SIZE} height={ICON_SIZE}>
84
83
  <Check
85
- className={classNames('correctnessIcon', 'correctIcon', 'smallIcon')}
84
+ className="correctnessIcon correctIcon smallIcon"
86
85
  title={correctness.label}
87
86
  />
88
87
  </foreignObject>
package/src/plot/dot.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
- import { Circle } from '@vx/shape';
3
+ import { Circle } from '@visx/shape';
4
4
 
5
5
  import { types } from '@pie-lib/plot';
6
6
  import { dataToXBand } from '../utils';
package/src/plot/line.js CHANGED
@@ -1,7 +1,7 @@
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';
3
+ import { LinePath } from '@visx/shape';
4
+ import { Group } from '@visx/group';
5
5
  import { styled } from '@mui/material/styles';
6
6
 
7
7
  import { types } from '@pie-lib/plot';
package/src/tool-menu.jsx CHANGED
@@ -1,6 +1,5 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
- import classNames from 'classnames';
4
3
  import { color } from '@pie-lib/render-ui';
5
4
 
6
5
  import { styled } from '@mui/material/styles';
@@ -19,12 +18,13 @@ const StyledMiniButton = styled(Button)(({ theme, selected, disabled }) => ({
19
18
  color: color.primaryDark(),
20
19
  },
21
20
  }),
22
- ...(!selected && !disabled && {
23
- '& span': {
24
- color: color.primary(),
25
- },
26
- backgroundColor: color.background(),
27
- }),
21
+ ...(!selected &&
22
+ !disabled && {
23
+ '& span': {
24
+ color: color.primary(),
25
+ },
26
+ backgroundColor: color.background(),
27
+ }),
28
28
  ...(disabled && {
29
29
  '& span': {
30
30
  color: color.primary(),
@@ -34,14 +34,14 @@ const StyledMiniButton = styled(Button)(({ theme, selected, disabled }) => ({
34
34
  }));
35
35
 
36
36
  export const MiniButton = (props) => {
37
- const { disabled, className, selected, value, onClick } = props;
37
+ const { disabled, selected, value, onClick } = props;
38
+
38
39
  return (
39
40
  <StyledMiniButton
40
41
  size="small"
41
42
  disabled={disabled}
42
43
  selected={selected}
43
44
  color={selected ? 'secondary' : 'default'}
44
- className={className}
45
45
  value={value}
46
46
  key={value}
47
47
  variant="outlined"
@@ -54,7 +54,6 @@ export const MiniButton = (props) => {
54
54
  MiniButton.propTypes = {
55
55
  disabled: PropTypes.bool,
56
56
  className: PropTypes.string,
57
- disabledClassName: PropTypes.string,
58
57
  selected: PropTypes.bool,
59
58
  value: PropTypes.string,
60
59
  onClick: PropTypes.func,
@@ -74,7 +73,7 @@ export class ToolMenu extends React.Component {
74
73
  const { className, disabled, addCategory, language } = this.props;
75
74
 
76
75
  return (
77
- <div className={classNames(className)}>
76
+ <div className={className}>
78
77
  {!disabled && (
79
78
  <MiniButton value={translator.t('charting.addCategory', { lng: language })} onClick={addCategory} />
80
79
  )}
package/src/utils.js CHANGED
@@ -1,4 +1,4 @@
1
- import { scaleBand, scalePoint } from '@vx/scale';
1
+ import { scaleBand, scalePoint } from '@visx/scale';
2
2
  import { utils } from '@pie-lib/plot';
3
3
 
4
4
  export const tickCount = utils.tickCount;
@@ -8,39 +8,43 @@ export const point = utils.point;
8
8
  export const bandKey = (d, index) => `${index}-${d.label || '-'}`;
9
9
 
10
10
  export const dataToXBand = (scaleX, data, width, type) => {
11
+ const chartWidth = width || 400; // fallback
12
+ const domain = data && data.length ? data.map(bandKey) : ['default'];
13
+
11
14
  switch (type) {
12
15
  case 'bar':
13
16
  case 'dotPlot':
14
17
  case 'linePlot':
15
18
  return scaleBand({
16
- rangeRound: [0, width],
17
- domain: data && data.map(bandKey),
19
+ range: [0, chartWidth],
20
+ domain,
18
21
  padding: 0.2,
19
22
  });
20
23
 
21
24
  case 'histogram':
22
25
  return scaleBand({
23
- rangeRound: [0, width],
24
- domain: data && data.map(bandKey),
26
+ range: [0, chartWidth],
27
+ domain,
25
28
  padding: 0,
26
29
  });
27
30
 
28
31
  case 'lineCross':
29
32
  case 'lineDot':
30
33
  return scalePoint({
31
- domain: data && data.map(bandKey),
32
- rangeRound: [0, width],
34
+ domain,
35
+ range: [0, chartWidth],
33
36
  });
34
37
 
35
38
  default:
36
39
  return scaleBand({
37
- range: [0, width],
38
- domain: data && data.map(bandKey),
40
+ range: [0, chartWidth],
41
+ domain,
39
42
  padding: 0,
40
43
  });
41
44
  }
42
45
  };
43
46
 
47
+
44
48
  export const getTickValues = (prop = {}) => {
45
49
  const tickValues = [];
46
50
  let tickVal = prop.min;