@pie-lib/graphing 3.2.0-next.9 → 4.0.1

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 (56) hide show
  1. package/CHANGELOG.md +133 -0
  2. package/lib/axis/axes.js +35 -33
  3. package/lib/axis/axes.js.map +1 -1
  4. package/lib/graph-with-controls.js +1 -1
  5. package/lib/graph-with-controls.js.map +1 -1
  6. package/lib/graph.js +14 -0
  7. package/lib/graph.js.map +1 -1
  8. package/lib/grid-setup.js +8 -0
  9. package/lib/grid-setup.js.map +1 -1
  10. package/lib/toggle-bar.js +5 -1
  11. package/lib/toggle-bar.js.map +1 -1
  12. package/lib/tools/circle/component.js +1 -1
  13. package/lib/tools/circle/component.js.map +1 -1
  14. package/lib/tools/line/component.js +30 -15
  15. package/lib/tools/line/component.js.map +1 -1
  16. package/lib/tools/point/component.js +24 -14
  17. package/lib/tools/point/component.js.map +1 -1
  18. package/lib/tools/polygon/line.js +2 -1
  19. package/lib/tools/polygon/line.js.map +1 -1
  20. package/lib/tools/polygon/polygon.js +7 -9
  21. package/lib/tools/polygon/polygon.js.map +1 -1
  22. package/lib/tools/ray/component.js +14 -2
  23. package/lib/tools/ray/component.js.map +1 -1
  24. package/lib/tools/segment/component.js +21 -8
  25. package/lib/tools/segment/component.js.map +1 -1
  26. package/lib/tools/shared/arrow-head.js +2 -2
  27. package/lib/tools/shared/arrow-head.js.map +1 -1
  28. package/lib/tools/shared/line/index.js +6 -3
  29. package/lib/tools/shared/line/index.js.map +1 -1
  30. package/lib/tools/shared/line/line-path.js +2 -1
  31. package/lib/tools/shared/line/line-path.js.map +1 -1
  32. package/lib/tools/shared/point/index.js +6 -0
  33. package/lib/tools/shared/point/index.js.map +1 -1
  34. package/lib/tools/shared/styles.js +5 -2
  35. package/lib/tools/shared/styles.js.map +1 -1
  36. package/lib/undo-redo.js +3 -0
  37. package/lib/undo-redo.js.map +1 -1
  38. package/package.json +8 -8
  39. package/src/axis/axes.jsx +9 -7
  40. package/src/graph-with-controls.jsx +1 -1
  41. package/src/graph.jsx +17 -0
  42. package/src/grid-setup.jsx +10 -0
  43. package/src/toggle-bar.jsx +4 -0
  44. package/src/tools/circle/component.jsx +1 -1
  45. package/src/tools/line/component.jsx +36 -14
  46. package/src/tools/point/component.jsx +11 -4
  47. package/src/tools/polygon/line.jsx +2 -1
  48. package/src/tools/polygon/polygon.jsx +9 -8
  49. package/src/tools/ray/component.jsx +12 -1
  50. package/src/tools/segment/component.jsx +15 -12
  51. package/src/tools/shared/arrow-head.jsx +2 -2
  52. package/src/tools/shared/line/index.jsx +7 -3
  53. package/src/tools/shared/line/line-path.jsx +2 -1
  54. package/src/tools/shared/point/index.jsx +6 -0
  55. package/src/tools/shared/styles.js +3 -1
  56. package/src/undo-redo.jsx +3 -0
@@ -118,6 +118,15 @@ const AxisConfig = (props) => {
118
118
  const { axisLabel = {}, min = {}, max = {} } = displayedFields;
119
119
  const activePlugins = ['bold', 'italic', 'underline', 'strikethrough'];
120
120
 
121
+ const onKeyDown = (event) => {
122
+ if (event.key === 'Enter') {
123
+ // prevent adding new lines - cancelling event
124
+ return true;
125
+ }
126
+
127
+ return false;
128
+ };
129
+
121
130
  return (
122
131
  <ColumnView>
123
132
  {displayHeader && (
@@ -159,6 +168,7 @@ const AxisConfig = (props) => {
159
168
  onChange={(value) => onChange('axisLabel', value)}
160
169
  markup={label || ''}
161
170
  charactersLimit={5}
171
+ onKeyDown={onKeyDown}
162
172
  activePlugins={activePlugins}
163
173
  />
164
174
  </AxisLabel>
@@ -17,6 +17,10 @@ const StyledMiniButton = styled(Button, {
17
17
  })(({ selected, disabled }) => ({
18
18
  color: color.text(),
19
19
  backgroundColor: color.background(),
20
+ border: `1px solid ${color.buttonBorder()}`,
21
+ '&:hover': {
22
+ backgroundColor: color.buttonHoverBg(),
23
+ },
20
24
  ...(selected && {
21
25
  border: `1px solid ${color.secondary()}`,
22
26
  }),
@@ -240,7 +240,7 @@ export class RawBaseCircle extends React.Component {
240
240
  // MUI v5 styled() replaces withStyles
241
241
  const StyledBgCircle = styled(BgCircle)(() => ({
242
242
  '&.outerLine': {
243
- fill: 'rgba(0,0,0,0)',
243
+ fill: color.transparent(),
244
244
  stroke: color.defaults.BLACK,
245
245
  strokeWidth: 4,
246
246
  '&:hover': {
@@ -7,18 +7,29 @@ import { ArrowMarker, genUid } from '../shared/arrow-head';
7
7
  import { getAdjustedGraphLimits, thinnerShapesNeeded } from '../../utils';
8
8
  import { styled } from '@mui/material/styles';
9
9
 
10
- const StyledArrowedLineRoot = styled('g')(({ theme }) => ({
11
- line: styles.line(theme),
12
- enabledArrow: styles.arrow(theme),
13
- disabledArrow: styles.disabledArrow(theme),
14
- disabled: styles.disabled(theme),
15
- disabledSecondary: styles.disabledSecondary(theme),
16
- correct: styles.correct(theme, 'stroke'),
17
- correctArrow: styles.correct(theme),
18
- incorrect: styles.incorrect(theme, 'stroke'),
19
- incorrectArrow: styles.incorrect(theme),
20
- missing: styles.missing(theme, 'stroke'),
21
- missingArrow: styles.missing(theme),
10
+ const StyledArrowedLineRoot = styled('g')(({ theme, disabled, correctness }) => ({
11
+ '& line:not(.hit-area)': {
12
+ ...styles.line(theme),
13
+ ...(disabled && styles.disabledSecondary(theme)),
14
+ ...(correctness === 'correct' && styles.correct(theme, 'stroke')),
15
+ ...(correctness === 'incorrect' && styles.incorrect(theme, 'stroke')),
16
+ ...(correctness === 'missing' && styles.missing(theme, 'stroke')),
17
+ },
18
+ '& .enabledArrow': {
19
+ ...styles.arrow(theme),
20
+ },
21
+ '& .disabledArrow': {
22
+ ...styles.disabledArrow(theme),
23
+ },
24
+ '& .correctArrow': {
25
+ ...styles.correct(theme),
26
+ },
27
+ '& .incorrectArrow': {
28
+ ...styles.incorrect(theme),
29
+ },
30
+ '& .missingArrow': {
31
+ ...styles.missing(theme),
32
+ },
22
33
  }));
23
34
 
24
35
  export const ArrowedLine = (props) => {
@@ -31,7 +42,7 @@ export const ArrowedLine = (props) => {
31
42
  const finalMarkerId = propMarkerId || markerId;
32
43
 
33
44
  return (
34
- <StyledArrowedLineRoot>
45
+ <StyledArrowedLineRoot disabled={disabled} correctness={correctness}>
35
46
  <defs>
36
47
  <ArrowMarker
37
48
  size={thinnerShapesNeeded(graphProps) ? 4 : 5}
@@ -41,12 +52,23 @@ export const ArrowedLine = (props) => {
41
52
  )}
42
53
  />
43
54
  </defs>
55
+ {/* Transparent wider line captures pointer events (+2px each side) */}
44
56
  <line
45
57
  x1={scale.x(eFrom.x)}
46
58
  y1={scale.y(eFrom.y)}
47
59
  x2={scale.x(eTo.x)}
48
60
  y2={scale.y(eTo.y)}
49
- className={classNames('line', disabled && 'disabledSecondary', correctness, className)}
61
+ className="hit-area"
62
+ stroke="transparent"
63
+ strokeWidth={7}
64
+ style={{ cursor: 'pointer', pointerEvents: 'stroke' }}
65
+ />
66
+ <line
67
+ x1={scale.x(eFrom.x)}
68
+ y1={scale.y(eFrom.y)}
69
+ x2={scale.x(eTo.x)}
70
+ y2={scale.y(eTo.y)}
71
+ className={className}
50
72
  markerEnd={`url(#${finalMarkerId}-${suffix})`}
51
73
  markerStart={`url(#${finalMarkerId}-${suffix})`}
52
74
  {...rest}
@@ -25,21 +25,24 @@ export class Point extends React.Component {
25
25
  };
26
26
 
27
27
  startDrag = () => {
28
+ const { onDragStart } = this.props;
28
29
  const update = { ...this.props.mark };
29
30
 
30
31
  if (update.label === '') {
31
32
  delete update.label;
32
33
  }
33
34
  this.setState({ mark: update });
35
+ if (onDragStart) onDragStart();
34
36
  };
35
37
 
36
38
  stopDrag = () => {
37
- const { onChange } = this.props;
39
+ const { onChange, onDragStop } = this.props;
38
40
  const mark = { ...this.state.mark };
39
41
  this.setState({ mark: undefined }, () => {
40
42
  if (!isEqual(this.props.mark, mark)) {
41
43
  onChange(this.props.mark, mark);
42
44
  }
45
+ if (onDragStop) onDragStop();
43
46
  });
44
47
  };
45
48
 
@@ -70,9 +73,13 @@ export class Point extends React.Component {
70
73
 
71
74
  onChange(mark, { label: '', ...mark });
72
75
 
73
- if (this.input) {
74
- this.input.focus();
75
- }
76
+ // MarkLabel is only rendered after the parent re-renders with the new label prop,
77
+ // so we defer focus until after that render cycle completes.
78
+ setTimeout(() => {
79
+ if (this.input) {
80
+ this.input.focus();
81
+ }
82
+ }, 0);
76
83
  };
77
84
 
78
85
  render() {
@@ -7,9 +7,10 @@ import * as utils from '../../utils';
7
7
  import { correct, disabled, incorrect, missing } from '../shared/styles';
8
8
 
9
9
  const StyledLine = styled('line')(({ disabled: isDisabled, correctness }) => ({
10
- strokeWidth: 3,
10
+ strokeWidth: 7,
11
11
  transition: 'stroke-width 200ms ease-in, stroke 200ms ease-in',
12
12
  stroke: 'transparent',
13
+ pointerEvents: 'stroke',
13
14
  '&:hover': {
14
15
  strokeWidth: 4,
15
16
  stroke: color.defaults.BLACK,
@@ -2,15 +2,16 @@ import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import { alpha, styled } from '@mui/material/styles';
4
4
  import { gridDraggable, types } from '@pie-lib/plot';
5
- import * as utils from '../../utils';
6
5
  import { color } from '@pie-lib/render-ui';
7
- import { correct, disabled, incorrect, missing } from '../shared/styles';
8
6
 
9
- const StyledPolygon = styled('polygon')(({ theme, disabled: isDisabled, correctness }) => ({
10
- fill: alpha(theme.palette.primary.light, 0.2),
7
+ import * as utils from '../../utils';
8
+ import { correct, disabledSecondary, incorrect, missing, graphingShapeFill } from '../shared/styles';
9
+
10
+ const StyledPolygon = styled('polygon')(({ disabled: isDisabled, correctness }) => ({
11
+ fill: alpha(graphingShapeFill(), 0.2),
11
12
  strokeWidth: 2,
12
13
  stroke: color.defaults.BLACK,
13
- ...(isDisabled && disabled('stroke')),
14
+ ...(isDisabled && disabledSecondary('stroke')),
14
15
  ...(correctness === 'correct' && correct('stroke')),
15
16
  ...(correctness === 'incorrect' && incorrect('stroke')),
16
17
  ...(correctness === 'missing' && {
@@ -19,12 +20,12 @@ const StyledPolygon = styled('polygon')(({ theme, disabled: isDisabled, correctn
19
20
  }),
20
21
  }));
21
22
 
22
- const StyledPolyline = styled('polyline')(({ theme, disabled: isDisabled, correctness }) => ({
23
- fill: alpha(theme.palette.primary.light, 0.0),
23
+ const StyledPolyline = styled('polyline')(({ disabled: isDisabled, correctness }) => ({
24
+ fill: alpha(graphingShapeFill(), 0.0),
24
25
  strokeWidth: 2,
25
26
  stroke: color.defaults.BLACK,
26
27
  pointerEvents: 'none',
27
- ...(isDisabled && disabled('stroke')),
28
+ ...(isDisabled && disabledSecondary('stroke')),
28
29
  ...(correctness === 'correct' && correct('stroke')),
29
30
  ...(correctness === 'incorrect' && incorrect('stroke')),
30
31
  ...(correctness === 'missing' && {
@@ -8,7 +8,7 @@ import { getAdjustedGraphLimits, thinnerShapesNeeded } from '../../utils';
8
8
  import { styled } from '@mui/material/styles';
9
9
 
10
10
  const StyledRayRoot = styled('g')(({ theme, disabled, correctness }) => ({
11
- '& line': {
11
+ '& line:not(.hit-area)': {
12
12
  ...styles.line(theme),
13
13
  ...(disabled && styles.disabledSecondary(theme)),
14
14
  ...(correctness === 'correct' && styles.correct(theme, 'stroke')),
@@ -52,6 +52,17 @@ export const RayLine = (props) => {
52
52
  )}
53
53
  />
54
54
  </defs>
55
+ {/* Transparent wider line captures pointer events (+2px each side) */}
56
+ <line
57
+ x1={scale.x(from.x)}
58
+ y1={scale.y(from.y)}
59
+ x2={scale.x(aToB.x)}
60
+ y2={scale.y(aToB.y)}
61
+ className="hit-area"
62
+ stroke="transparent"
63
+ strokeWidth={7}
64
+ style={{ cursor: 'pointer', pointerEvents: 'stroke' }}
65
+ />
55
66
  <line
56
67
  x1={scale.x(from.x)}
57
68
  y1={scale.y(from.y)}
@@ -18,20 +18,23 @@ const StyledLineRoot = styled('line')(({ theme, disabled, correctness }) => ({
18
18
  export const Line = (props) => {
19
19
  const { className, correctness, disabled, graphProps, from, to, ...rest } = props;
20
20
  const { scale } = graphProps;
21
+ const x1 = scale.x(from.x);
22
+ const y1 = scale.y(from.y);
23
+ const x2 = scale.x(to.x);
24
+ const y2 = scale.y(to.y);
21
25
 
22
26
  return (
23
- <StyledLineRoot
24
- stroke="green"
25
- strokeWidth={6}
26
- x1={scale.x(from.x)}
27
- y1={scale.y(from.y)}
28
- x2={scale.x(to.x)}
29
- y2={scale.y(to.y)}
30
- className={className}
31
- disabled={disabled}
32
- correctness={correctness}
33
- {...rest}
34
- />
27
+ <g>
28
+ {/* Transparent wider line captures pointer events (+2px each side) */}
29
+ <line x1={x1} y1={y1} x2={x2} y2={y2} stroke="transparent" strokeWidth={7} style={{ cursor: 'pointer', pointerEvents: 'stroke' }} />
30
+ <StyledLineRoot
31
+ x1={x1} y1={y1} x2={x2} y2={y2}
32
+ className={className}
33
+ disabled={disabled}
34
+ correctness={correctness}
35
+ {...rest}
36
+ />
37
+ </g>
35
38
  );
36
39
  };
37
40
 
@@ -6,7 +6,7 @@ import { color } from '@pie-lib/render-ui';
6
6
  const StyledArrowHead = styled('polygon')(({ disabled, correctness }) => ({
7
7
  fill: color.defaults.BLACK,
8
8
  ...(disabled && {
9
- fill: color.disabled(),
9
+ fill: color.disabledSecondary(),
10
10
  }),
11
11
  ...(correctness === 'correct' && {
12
12
  fill: color.correctWithIcon(),
@@ -23,7 +23,7 @@ const StyledMarker = styled('marker')(({ disabled, correctness }) => ({
23
23
  '& polygon': {
24
24
  fill: color.defaults.BLACK,
25
25
  ...(disabled && {
26
- fill: color.disabled(),
26
+ fill: color.disabledSecondary(),
27
27
  }),
28
28
  ...(correctness === 'correct' && {
29
29
  fill: color.correctWithIcon(),
@@ -89,10 +89,14 @@ export const lineToolComponent = (Component) => {
89
89
  this.state = {};
90
90
  }
91
91
 
92
- startDrag = () => this.setState({ mark: { ...this.props.mark } });
92
+ startDrag = () => {
93
+ const { onDragStart } = this.props;
94
+ this.setState({ mark: { ...this.props.mark } });
95
+ if (onDragStart) onDragStart();
96
+ };
93
97
 
94
98
  stopDrag = () => {
95
- const { onChange, mark } = this.props;
99
+ const { onChange, mark, onDragStop } = this.props;
96
100
  const update = { ...this.state.mark };
97
101
 
98
102
  this.setState({ mark: undefined }, () => {
@@ -107,6 +111,7 @@ export const lineToolComponent = (Component) => {
107
111
  if (!isEqual(mark, update) && !shouldNotChange) {
108
112
  onChange(mark, update);
109
113
  }
114
+ if (onDragStop) onDragStop();
110
115
  });
111
116
  };
112
117
 
@@ -303,7 +308,6 @@ export const lineBase = (Comp, opts) => {
303
308
 
304
309
  if (!labelModeEnabled) {
305
310
  onClick(point || data);
306
- return;
307
311
  }
308
312
 
309
313
  if (disabled) {
@@ -29,10 +29,11 @@ const StyledDrawLine = styled(vx.LinePath)(({ disabled: isDisabled, correctness
29
29
  }));
30
30
 
31
31
  const StyledLine = styled(vx.LinePath)(({ theme, disabled: isDisabled, correctness, isDragging }) => ({
32
- strokeWidth: 3,
32
+ strokeWidth: 7,
33
33
  fill: 'none',
34
34
  transition: 'stroke-width 200ms ease-in, stroke 200ms ease-in',
35
35
  stroke: 'transparent',
36
+ pointerEvents: 'stroke',
36
37
  '&:hover': dragging(theme),
37
38
  ...(isDragging && dragging(theme)),
38
39
  ...(isDisabled && {
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
2
  import { styled } from '@mui/material/styles';
3
3
  import { gridDraggable } from '@pie-lib/plot';
4
+ import { color } from '@pie-lib/render-ui';
4
5
  import * as utils from '../../../utils';
5
6
  import { RawBp } from './base-point';
6
7
  import { RawArrow } from './arrow-point';
@@ -27,6 +28,11 @@ const PointStyle = styled('g')(() => ({
27
28
  '& circle, & polygon': {
28
29
  cursor: 'pointer',
29
30
  },
31
+ '&[disabled]': {
32
+ '& circle, & polygon': {
33
+ fill: color.disabledSecondary(),
34
+ },
35
+ },
30
36
  }));
31
37
 
32
38
  export const BasePoint = gridDraggable(opts)((props) => (
@@ -1,7 +1,9 @@
1
1
  import { color } from '@pie-lib/render-ui';
2
2
 
3
+ export const graphingShapeFill = () => color.visualElementsColors.SHAPES_FILL_COLOR;
4
+
3
5
  export const disabled = (key = 'fill') => ({
4
- [key]: color.disabled(),
6
+ [key]: color.disabledSecondary(), // this is needed to match previous disabled color for backward compatibility
5
7
  pointerEvents: 'none',
6
8
  });
7
9
 
package/src/undo-redo.jsx CHANGED
@@ -15,6 +15,9 @@ const StyledButton = styled(Button)(({ theme }) => ({
15
15
  '&:not(:last-of-type)': {
16
16
  marginRight: theme.spacing(0.5),
17
17
  },
18
+ '&:hover': {
19
+ backgroundColor: color.buttonHoverBg(),
20
+ },
18
21
  }));
19
22
 
20
23
  export class UndoRedo extends React.Component {