@pie-lib/charting 5.15.7-next.0 → 5.17.0-beta.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 (132) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/NEXT.CHANGELOG.json +1 -0
  3. package/lib/__tests__/axes.test.js +181 -0
  4. package/lib/__tests__/chart-setup.test.js +58 -0
  5. package/lib/__tests__/chart-type.test.js +42 -0
  6. package/lib/__tests__/chart.test.js +108 -0
  7. package/lib/__tests__/grid.test.js +48 -0
  8. package/lib/__tests__/mark-label.test.js +57 -0
  9. package/lib/__tests__/utils.js +56 -0
  10. package/lib/__tests__/utils.test.js +197 -0
  11. package/lib/axes.js +75 -30
  12. package/lib/bars/__tests__/bar.test.js +62 -0
  13. package/lib/bars/__tests__/histogram.test.js +64 -0
  14. package/lib/bars/__tests__/utils.js +56 -0
  15. package/lib/bars/bar.js +1 -1
  16. package/lib/bars/common/__tests__/bars.test.js +100 -0
  17. package/lib/bars/common/__tests__/utils.js +56 -0
  18. package/lib/bars/common/bars.js +36 -2
  19. package/lib/bars/histogram.js +1 -1
  20. package/lib/chart-setup.js +1 -1
  21. package/lib/chart-type.js +5 -5
  22. package/lib/chart-types.js +3 -3
  23. package/lib/chart.js +26 -11
  24. package/lib/common/__tests__/drag-handle.test.js +134 -0
  25. package/lib/common/__tests__/utils.js +56 -0
  26. package/lib/common/drag-handle.js +12 -6
  27. package/lib/common/drag-icon.js +8 -25
  28. package/lib/common/styles.js +1 -1
  29. package/lib/grid.js +1 -1
  30. package/lib/index.js +1 -1
  31. package/lib/line/__tests__/line-cross.test.js +64 -0
  32. package/lib/line/__tests__/line-dot.test.js +64 -0
  33. package/lib/line/__tests__/utils.js +56 -0
  34. package/lib/line/common/__tests__/drag-handle.test.js +134 -0
  35. package/lib/line/common/__tests__/line.test.js +128 -0
  36. package/lib/line/common/__tests__/utils.js +56 -0
  37. package/lib/line/common/drag-handle.js +10 -5
  38. package/lib/line/common/line.js +1 -1
  39. package/lib/line/line-cross.js +17 -6
  40. package/lib/line/line-dot.js +11 -3
  41. package/lib/mark-label.js +21 -12
  42. package/lib/plot/__tests__/dot.test.js +64 -0
  43. package/lib/plot/__tests__/line.test.js +64 -0
  44. package/lib/plot/__tests__/utils.js +56 -0
  45. package/lib/plot/common/__tests__/plot.test.js +103 -0
  46. package/lib/plot/common/__tests__/utils.js +56 -0
  47. package/lib/plot/common/plot.js +4 -2
  48. package/lib/plot/dot.js +2 -2
  49. package/lib/plot/line.js +2 -2
  50. package/lib/tool-menu.js +1 -5
  51. package/lib/utils.js +1 -1
  52. package/package.json +4 -4
  53. package/src/__tests__/__snapshots__/axes.test.jsx.snap +564 -0
  54. package/src/__tests__/__snapshots__/chart-type.test.jsx.snap +14 -0
  55. package/src/__tests__/__snapshots__/chart.test.jsx.snap +610 -0
  56. package/src/__tests__/__snapshots__/grid.test.jsx.snap +28 -0
  57. package/src/__tests__/__snapshots__/mark-label.test.jsx.snap +67 -0
  58. package/src/__tests__/axes.test.jsx +146 -0
  59. package/src/__tests__/chart-setup.test.jsx +47 -0
  60. package/src/__tests__/chart-type.test.jsx +29 -0
  61. package/src/__tests__/chart.test.jsx +87 -0
  62. package/src/__tests__/grid.test.jsx +25 -0
  63. package/src/__tests__/mark-label.test.jsx +31 -0
  64. package/src/__tests__/utils.js +30 -0
  65. package/src/__tests__/utils.test.js +100 -0
  66. package/src/axes.jsx +59 -23
  67. package/src/bars/__tests__/__snapshots__/bar.test.jsx.snap +43 -0
  68. package/src/bars/__tests__/__snapshots__/histogram.test.jsx.snap +45 -0
  69. package/src/bars/__tests__/bar.test.jsx +37 -0
  70. package/src/bars/__tests__/histogram.test.jsx +38 -0
  71. package/src/bars/__tests__/utils.js +30 -0
  72. package/src/bars/common/__tests__/__snapshots__/bars.test.jsx.snap +110 -0
  73. package/src/bars/common/__tests__/bars.test.jsx +69 -0
  74. package/src/bars/common/__tests__/utils.js +30 -0
  75. package/src/bars/common/bars.jsx +37 -1
  76. package/src/chart-type.js +7 -3
  77. package/src/chart-types.js +2 -2
  78. package/src/chart.jsx +15 -5
  79. package/src/common/__tests__/__snapshots__/drag-handle.test.jsx.snap +45 -0
  80. package/src/common/__tests__/drag-handle.test.jsx +88 -0
  81. package/src/common/__tests__/utils.js +30 -0
  82. package/src/common/drag-handle.jsx +18 -10
  83. package/src/common/drag-icon.jsx +6 -21
  84. package/src/line/__tests__/__snapshots__/line-cross.test.jsx.snap +45 -0
  85. package/src/line/__tests__/__snapshots__/line-dot.test.jsx.snap +45 -0
  86. package/src/line/__tests__/line-cross.test.jsx +38 -0
  87. package/src/line/__tests__/line-dot.test.jsx +38 -0
  88. package/src/line/__tests__/utils.js +30 -0
  89. package/src/line/common/__tests__/__snapshots__/drag-handle.test.jsx.snap +44 -0
  90. package/src/line/common/__tests__/__snapshots__/line.test.jsx.snap +141 -0
  91. package/src/line/common/__tests__/drag-handle.test.jsx +88 -0
  92. package/src/line/common/__tests__/line.test.jsx +82 -0
  93. package/src/line/common/__tests__/utils.js +30 -0
  94. package/src/line/common/drag-handle.jsx +9 -4
  95. package/src/line/line-cross.js +4 -1
  96. package/src/line/line-dot.js +17 -7
  97. package/src/mark-label.jsx +19 -7
  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 +96 -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 +6 -1
  107. package/src/plot/dot.js +1 -1
  108. package/src/plot/line.js +1 -1
  109. package/src/tool-menu.jsx +0 -4
  110. package/lib/axes.js.map +0 -1
  111. package/lib/bars/bar.js.map +0 -1
  112. package/lib/bars/common/bars.js.map +0 -1
  113. package/lib/bars/histogram.js.map +0 -1
  114. package/lib/chart-setup.js.map +0 -1
  115. package/lib/chart-type.js.map +0 -1
  116. package/lib/chart-types.js.map +0 -1
  117. package/lib/chart.js.map +0 -1
  118. package/lib/common/drag-handle.js.map +0 -1
  119. package/lib/common/drag-icon.js.map +0 -1
  120. package/lib/common/styles.js.map +0 -1
  121. package/lib/grid.js.map +0 -1
  122. package/lib/index.js.map +0 -1
  123. package/lib/line/common/drag-handle.js.map +0 -1
  124. package/lib/line/common/line.js.map +0 -1
  125. package/lib/line/line-cross.js.map +0 -1
  126. package/lib/line/line-dot.js.map +0 -1
  127. package/lib/mark-label.js.map +0 -1
  128. package/lib/plot/common/plot.js.map +0 -1
  129. package/lib/plot/dot.js.map +0 -1
  130. package/lib/plot/line.js.map +0 -1
  131. package/lib/tool-menu.js.map +0 -1
  132. package/lib/utils.js.map +0 -1
@@ -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
+ });
@@ -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
+ });
@@ -72,8 +72,38 @@ export class RawBar extends React.Component {
72
72
  dragValue: undefined,
73
73
  isHovered: false,
74
74
  };
75
+ this.mouseX = 0;
76
+ this.mouseY = 0;
75
77
  }
76
78
 
79
+ componentDidMount() {
80
+ window.addEventListener('mousemove', this.handleMouseMove);
81
+ }
82
+
83
+ componentWillUnmount() {
84
+ window.removeEventListener('mousemove', this.handleMouseMove);
85
+ }
86
+
87
+ handleMouseMove = (e) => {
88
+ // Update mouse position
89
+ this.mouseX = e.clientX;
90
+ this.mouseY = e.clientY;
91
+ // Check if the mouse is inside the <g> element
92
+ const isMouseInside = this.isMouseInsideSvgElement();
93
+ this.setState({ isHovered: isMouseInside });
94
+ };
95
+
96
+ isMouseInsideSvgElement = () => {
97
+ const gBoundingBox = this.gRef.getBoundingClientRect();
98
+ // Check if the mouse position is within the bounding box
99
+ return (
100
+ this.mouseX >= gBoundingBox.left &&
101
+ this.mouseX <= gBoundingBox.right &&
102
+ this.mouseY >= gBoundingBox.top &&
103
+ this.mouseY <= gBoundingBox.bottom
104
+ );
105
+ };
106
+
77
107
  handleMouseEnter = () => {
78
108
  this.setState({ isHovered: true });
79
109
  };
@@ -130,7 +160,13 @@ export class RawBar extends React.Component {
130
160
  const Component = interactive ? DraggableHandle : DragHandle;
131
161
 
132
162
  return (
133
- <g onMouseEnter={this.handleMouseEnter} onMouseLeave={this.handleMouseLeave}>
163
+ <g
164
+ ref={(ref) => (this.gRef = ref)}
165
+ onMouseEnter={this.handleMouseEnter}
166
+ onMouseLeave={this.handleMouseLeave}
167
+ onTouchStart={this.handleMouseEnter}
168
+ onTouchEnd={this.handleMouseLeave}
169
+ >
134
170
  <VxBar
135
171
  x={barX}
136
172
  y={scale.y(yy)}
package/src/chart-type.js CHANGED
@@ -16,11 +16,15 @@ const ChartType = withStyles(() => ({
16
16
  }))(({ onChange, value, classes, availableChartTypes, chartTypeLabel }) => (
17
17
  <div className={classes.chartType}>
18
18
  <FormControl variant={'outlined'} className={classes.chartType}>
19
- <InputLabel htmlFor="type-helper" className={classes.chartTypeLabel}>
19
+ <InputLabel id="type-helper-label" className={classes.chartTypeLabel}>
20
20
  {chartTypeLabel}
21
21
  </InputLabel>
22
-
23
- <Select value={value} onChange={onChange} labelWidth={75} input={<OutlinedInput name="type" id="type-helper" />}>
22
+ <Select
23
+ labelId="type-helper-label"
24
+ value={value}
25
+ onChange={onChange}
26
+ input={<OutlinedInput labelWidth={75} name="type" />}
27
+ >
24
28
  {availableChartTypes?.histogram && <MenuItem value={'histogram'}>{availableChartTypes.histogram}</MenuItem>}
25
29
  {availableChartTypes?.bar && <MenuItem value={'bar'}>{availableChartTypes.bar}</MenuItem>}
26
30
  {availableChartTypes?.lineDot && <MenuItem value={'lineDot'}>{availableChartTypes.lineDot}</MenuItem>}
@@ -2,7 +2,7 @@ import Bar from './bars/bar';
2
2
  import Histogram from './bars/histogram';
3
3
  import LineDot from './line/line-dot';
4
4
  import LineCross from './line/line-cross';
5
- import DotPlot from './plot/dot';
6
- import LinePlot from './plot/line';
5
+ import DotPlot from '@pie-lib/plot/dot';
6
+ import LinePlot from '@pie-lib/plot/line';
7
7
 
8
8
  export default { Bar, Histogram, LineDot, DotPlot, LinePlot, LineCross };
package/src/chart.jsx CHANGED
@@ -70,6 +70,8 @@ export class Chart extends React.Component {
70
70
  changeInteractiveEnabled: PropTypes.bool,
71
71
  changeEditableEnabled: PropTypes.bool,
72
72
  language: PropTypes.string,
73
+ mathMlOptions: PropTypes.object,
74
+ labelsCharactersLimit: PropTypes.number,
73
75
  };
74
76
 
75
77
  static defaultProps = {
@@ -88,6 +90,7 @@ export class Chart extends React.Component {
88
90
  chartTypes.DotPlot(),
89
91
  chartTypes.LinePlot(),
90
92
  ],
93
+ autoFocus: false,
91
94
  };
92
95
 
93
96
  generateMaskId() {
@@ -156,11 +159,11 @@ export class Chart extends React.Component {
156
159
  },
157
160
  });
158
161
  } else {
162
+ this.setState({ autoFocus: true });
159
163
  onDataChange([
160
164
  ...data,
161
165
  {
162
166
  inDefineChart: defineChart,
163
- autoFocus: true,
164
167
  label: categoryDefaultLabel || translator.t('charting.newLabel', { lng: language }),
165
168
  value: 0,
166
169
  deletable: true,
@@ -182,6 +185,10 @@ export class Chart extends React.Component {
182
185
  : [];
183
186
  };
184
187
 
188
+ resetAutoFocus = () => {
189
+ this.setState({ autoFocus: false });
190
+ };
191
+
185
192
  render() {
186
193
  const {
187
194
  classes,
@@ -202,6 +209,7 @@ export class Chart extends React.Component {
202
209
  error,
203
210
  mathMlOptions = {},
204
211
  language,
212
+ labelsCharactersLimit,
205
213
  } = this.props;
206
214
  let { chartType } = this.props;
207
215
 
@@ -269,10 +277,13 @@ export class Chart extends React.Component {
269
277
  showPixelGuides={showPixelGuides}
270
278
  rootRef={(r) => (this.rootNode = r)}
271
279
  mathMlOptions={mathMlOptions}
280
+ labelsCharactersLimit={labelsCharactersLimit}
272
281
  {...rootCommon}
273
282
  >
274
283
  <ChartGrid {...common} xBand={xBand} rowTickValues={horizontalLines} columnTickValues={verticalLines} />
275
284
  <ChartAxes
285
+ autoFocus={this.state.autoFocus}
286
+ onAutoFocusUsed={this.resetAutoFocus}
276
287
  {...common}
277
288
  defineChart={defineChart}
278
289
  categories={categories}
@@ -321,10 +332,9 @@ const styles = (theme) => ({
321
332
  justifyContent: 'space-between',
322
333
  padding: theme.spacing.unit,
323
334
  backgroundColor: color.primaryLight(),
324
- borderTop: `solid 1px ${color.primaryDark()}`,
325
- borderBottom: `solid 0px ${color.primaryDark()}`,
326
- borderLeft: `solid 1px ${color.primaryDark()}`,
327
- borderRight: `solid 1px ${color.primaryDark()}`,
335
+ '& button': {
336
+ fontSize: theme.typography.fontSize,
337
+ },
328
338
  },
329
339
  svg: {
330
340
  overflow: 'visible',
@@ -0,0 +1,45 @@
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
+ "handle": "RawDragHandle-handle-1",
9
+ "handleContainer": "RawDragHandle-handleContainer-3",
10
+ "svgOverflowVisible": "RawDragHandle-svgOverflowVisible-4",
11
+ "transparentHandle": "RawDragHandle-transparentHandle-2",
12
+ }
13
+ }
14
+ graphProps={
15
+ Object {
16
+ "domain": Object {
17
+ "max": 1,
18
+ "min": 0,
19
+ "step": 1,
20
+ },
21
+ "range": Object {
22
+ "max": 1,
23
+ "min": 0,
24
+ "step": 1,
25
+ },
26
+ "scale": Object {
27
+ "x": [MockFunction],
28
+ "y": [MockFunction],
29
+ },
30
+ "size": Object {
31
+ "height": 400,
32
+ "width": 400,
33
+ },
34
+ "snap": Object {
35
+ "x": [MockFunction],
36
+ "y": [MockFunction],
37
+ },
38
+ }
39
+ }
40
+ onChange={[MockFunction]}
41
+ width={100}
42
+ x={0}
43
+ y={0}
44
+ />
45
+ `;
@@ -0,0 +1,88 @@
1
+ import { shallow } from 'enzyme/build';
2
+ import React from 'react';
3
+ import DragHandle from '../drag-handle';
4
+ import { gridDraggable } from '@pie-lib/plot';
5
+ import { graphProps } from './utils';
6
+ import { bounds } from '../../utils';
7
+
8
+ jest.mock('../../utils', () => {
9
+ const { point } = jest.requireActual('../../utils');
10
+ return {
11
+ bounds: jest.fn(),
12
+ point,
13
+ };
14
+ });
15
+
16
+ jest.mock('@pie-lib/plot', () => {
17
+ const { types, utils } = jest.requireActual('@pie-lib/plot');
18
+ return {
19
+ gridDraggable: jest.fn((opts) => (Comp) => Comp),
20
+ types,
21
+ utils,
22
+ };
23
+ });
24
+
25
+ describe('BasePoint', () => {
26
+ let w;
27
+ let onChange = jest.fn();
28
+ const wrapper = (extras) => {
29
+ const defaults = {
30
+ classes: {},
31
+ className: 'className',
32
+ onChange,
33
+ graphProps: graphProps(),
34
+ x: 0,
35
+ y: 0,
36
+ width: 100,
37
+ };
38
+ const props = { ...defaults, ...extras };
39
+ return shallow(<DragHandle {...props} />);
40
+ };
41
+
42
+ describe('snapshot', () => {
43
+ it('renders', () => {
44
+ w = wrapper();
45
+ expect(w).toMatchSnapshot();
46
+ });
47
+ });
48
+ describe('gridDraggable options', () => {
49
+ let opts;
50
+ let domain;
51
+ let range;
52
+ beforeEach(() => {
53
+ domain = {
54
+ min: 0,
55
+ max: 1,
56
+ step: 1,
57
+ };
58
+ range = {
59
+ min: 0,
60
+ max: 1,
61
+ step: 1,
62
+ };
63
+ const w = wrapper();
64
+ opts = gridDraggable.mock.calls[0][0];
65
+ });
66
+
67
+ describe('bounds', () => {
68
+ it('calls utils.bounds with area', () => {
69
+ const result = opts.bounds({ x: 0, y: 0 }, { domain, range });
70
+
71
+ expect(result).toEqual({ left: 0, top: 1, bottom: 0, right: 1 });
72
+ });
73
+ });
74
+ describe('anchorPoint', () => {
75
+ it('returns x/y', () => {
76
+ const result = opts.anchorPoint({ x: 0, y: 0 });
77
+ expect(result).toEqual({ x: 0, y: 0 });
78
+ });
79
+ });
80
+
81
+ describe('fromDelta', () => {
82
+ it('returns y coordinate of a new point from the x/y + delta', () => {
83
+ const result = opts.fromDelta({ x: -1, y: 0 }, { x: 1, y: 3 });
84
+ expect(result).toEqual(3);
85
+ });
86
+ });
87
+ });
88
+ });