@pie-lib/graphing-solution-set 2.16.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 (151) hide show
  1. package/CHANGELOG.json +1 -0
  2. package/CHANGELOG.md +16 -0
  3. package/LICENSE.md +5 -0
  4. package/NEXT.CHANGELOG.json +1 -0
  5. package/lib/__tests__/graph-with-controls.test.js +191 -0
  6. package/lib/__tests__/graph.test.js +290 -0
  7. package/lib/__tests__/grid.test.js +40 -0
  8. package/lib/__tests__/labels.test.js +59 -0
  9. package/lib/__tests__/mark-label.test.js +154 -0
  10. package/lib/__tests__/toggle-bar.test.js +54 -0
  11. package/lib/__tests__/tool-menu.test.js +43 -0
  12. package/lib/__tests__/undo-redo.test.js +42 -0
  13. package/lib/__tests__/use-debounce.test.js +28 -0
  14. package/lib/__tests__/utils.js +72 -0
  15. package/lib/__tests__/utils.test.js +133 -0
  16. package/lib/axis/__tests__/arrow.test.js +68 -0
  17. package/lib/axis/__tests__/axes.test.js +214 -0
  18. package/lib/axis/arrow.js +115 -0
  19. package/lib/axis/axes.js +415 -0
  20. package/lib/axis/index.js +26 -0
  21. package/lib/bg.js +139 -0
  22. package/lib/container/actions.js +24 -0
  23. package/lib/container/index.js +166 -0
  24. package/lib/container/marks.js +27 -0
  25. package/lib/container/middleware.js +25 -0
  26. package/lib/container/reducer.js +25 -0
  27. package/lib/coordinates-label.js +109 -0
  28. package/lib/graph-with-controls.js +372 -0
  29. package/lib/graph.js +419 -0
  30. package/lib/grid-setup.js +462 -0
  31. package/lib/grid.js +176 -0
  32. package/lib/index.js +51 -0
  33. package/lib/labels.js +299 -0
  34. package/lib/mark-label.js +208 -0
  35. package/lib/toggle-bar.js +336 -0
  36. package/lib/tool-menu.js +325 -0
  37. package/lib/tools/index.js +29 -0
  38. package/lib/tools/line/__tests__/component.test.js +56 -0
  39. package/lib/tools/line/component.js +106 -0
  40. package/lib/tools/line/index.js +16 -0
  41. package/lib/tools/polygon/__tests__/component.test.js +245 -0
  42. package/lib/tools/polygon/__tests__/index.test.js +95 -0
  43. package/lib/tools/polygon/__tests__/line.test.js +43 -0
  44. package/lib/tools/polygon/__tests__/polygon.test.js +73 -0
  45. package/lib/tools/polygon/component.js +457 -0
  46. package/lib/tools/polygon/index.js +106 -0
  47. package/lib/tools/polygon/line.js +151 -0
  48. package/lib/tools/polygon/polygon.js +171 -0
  49. package/lib/tools/shared/__tests__/arrow-head.test.js +62 -0
  50. package/lib/tools/shared/arrow-head.js +75 -0
  51. package/lib/tools/shared/line/__tests__/index.test.js +291 -0
  52. package/lib/tools/shared/line/__tests__/line-path.test.js +78 -0
  53. package/lib/tools/shared/line/__tests__/with-root-edge.test.js +122 -0
  54. package/lib/tools/shared/line/index.js +637 -0
  55. package/lib/tools/shared/line/line-path.js +145 -0
  56. package/lib/tools/shared/line/with-root-edge.js +155 -0
  57. package/lib/tools/shared/point/__tests__/arrow-point.test.js +137 -0
  58. package/lib/tools/shared/point/__tests__/base-point.test.js +134 -0
  59. package/lib/tools/shared/point/arrow-point.js +113 -0
  60. package/lib/tools/shared/point/arrow.js +96 -0
  61. package/lib/tools/shared/point/base-point.js +151 -0
  62. package/lib/tools/shared/point/index.js +94 -0
  63. package/lib/tools/shared/styles.js +49 -0
  64. package/lib/tools/shared/types.js +19 -0
  65. package/lib/undo-redo.js +107 -0
  66. package/lib/use-debounce.js +32 -0
  67. package/lib/utils.js +314 -0
  68. package/package.json +50 -0
  69. package/src/__tests__/__snapshots__/graph-with-controls.test.jsx.snap +114 -0
  70. package/src/__tests__/__snapshots__/graph.test.jsx.snap +213 -0
  71. package/src/__tests__/__snapshots__/grid.test.jsx.snap +54 -0
  72. package/src/__tests__/__snapshots__/labels.test.jsx.snap +30 -0
  73. package/src/__tests__/__snapshots__/mark-label.test.jsx.snap +37 -0
  74. package/src/__tests__/__snapshots__/toggle-bar.test.jsx.snap +7 -0
  75. package/src/__tests__/__snapshots__/tool-menu.test.jsx.snap +35 -0
  76. package/src/__tests__/__snapshots__/undo-redo.test.jsx.snap +15 -0
  77. package/src/__tests__/graph-with-controls.test.jsx +131 -0
  78. package/src/__tests__/graph.test.jsx +230 -0
  79. package/src/__tests__/grid.test.jsx +20 -0
  80. package/src/__tests__/labels.test.jsx +38 -0
  81. package/src/__tests__/mark-label.test.jsx +68 -0
  82. package/src/__tests__/toggle-bar.test.jsx +36 -0
  83. package/src/__tests__/tool-menu.test.jsx +29 -0
  84. package/src/__tests__/undo-redo.test.jsx +25 -0
  85. package/src/__tests__/use-debounce.test.js +21 -0
  86. package/src/__tests__/utils.js +38 -0
  87. package/src/__tests__/utils.test.js +151 -0
  88. package/src/axis/__tests__/__snapshots__/arrow.test.jsx.snap +33 -0
  89. package/src/axis/__tests__/__snapshots__/axes.test.jsx.snap +122 -0
  90. package/src/axis/__tests__/arrow.test.jsx +39 -0
  91. package/src/axis/__tests__/axes.test.jsx +220 -0
  92. package/src/axis/arrow.jsx +62 -0
  93. package/src/axis/axes.jsx +307 -0
  94. package/src/axis/index.js +2 -0
  95. package/src/bg.jsx +96 -0
  96. package/src/container/actions.js +8 -0
  97. package/src/container/index.jsx +86 -0
  98. package/src/container/marks.js +14 -0
  99. package/src/container/middleware.js +7 -0
  100. package/src/container/reducer.js +5 -0
  101. package/src/coordinates-label.jsx +73 -0
  102. package/src/graph-with-controls.jsx +263 -0
  103. package/src/graph.jsx +334 -0
  104. package/src/grid-setup.jsx +427 -0
  105. package/src/grid.jsx +135 -0
  106. package/src/index.js +7 -0
  107. package/src/labels.jsx +214 -0
  108. package/src/mark-label.jsx +136 -0
  109. package/src/toggle-bar.jsx +242 -0
  110. package/src/tool-menu.jsx +294 -0
  111. package/src/tools/index.js +8 -0
  112. package/src/tools/line/__tests__/__snapshots__/component.test.jsx.snap +20 -0
  113. package/src/tools/line/__tests__/component.test.jsx +36 -0
  114. package/src/tools/line/component.jsx +77 -0
  115. package/src/tools/line/index.js +4 -0
  116. package/src/tools/polygon/__tests__/__snapshots__/component.test.jsx.snap +94 -0
  117. package/src/tools/polygon/__tests__/__snapshots__/line.test.jsx.snap +44 -0
  118. package/src/tools/polygon/__tests__/__snapshots__/polygon.test.jsx.snap +53 -0
  119. package/src/tools/polygon/__tests__/component.test.jsx +214 -0
  120. package/src/tools/polygon/__tests__/index.test.js +65 -0
  121. package/src/tools/polygon/__tests__/line.test.jsx +25 -0
  122. package/src/tools/polygon/__tests__/polygon.test.jsx +44 -0
  123. package/src/tools/polygon/component.jsx +336 -0
  124. package/src/tools/polygon/index.js +52 -0
  125. package/src/tools/polygon/line.jsx +78 -0
  126. package/src/tools/polygon/polygon.jsx +101 -0
  127. package/src/tools/shared/__tests__/__snapshots__/arrow-head.test.jsx.snap +32 -0
  128. package/src/tools/shared/__tests__/arrow-head.test.jsx +34 -0
  129. package/src/tools/shared/arrow-head.jsx +46 -0
  130. package/src/tools/shared/line/__tests__/__snapshots__/index.test.jsx.snap +360 -0
  131. package/src/tools/shared/line/__tests__/__snapshots__/line-path.test.jsx.snap +57 -0
  132. package/src/tools/shared/line/__tests__/__snapshots__/with-root-edge.test.jsx.snap +63 -0
  133. package/src/tools/shared/line/__tests__/index.test.jsx +247 -0
  134. package/src/tools/shared/line/__tests__/line-path.test.jsx +53 -0
  135. package/src/tools/shared/line/__tests__/with-root-edge.test.jsx +73 -0
  136. package/src/tools/shared/line/index.jsx +473 -0
  137. package/src/tools/shared/line/line-path.jsx +88 -0
  138. package/src/tools/shared/line/with-root-edge.jsx +97 -0
  139. package/src/tools/shared/point/__tests__/__snapshots__/arrow-point.test.jsx.snap +55 -0
  140. package/src/tools/shared/point/__tests__/__snapshots__/base-point.test.jsx.snap +43 -0
  141. package/src/tools/shared/point/__tests__/arrow-point.test.jsx +87 -0
  142. package/src/tools/shared/point/__tests__/base-point.test.jsx +84 -0
  143. package/src/tools/shared/point/arrow-point.jsx +60 -0
  144. package/src/tools/shared/point/arrow.jsx +40 -0
  145. package/src/tools/shared/point/base-point.jsx +86 -0
  146. package/src/tools/shared/point/index.jsx +60 -0
  147. package/src/tools/shared/styles.js +20 -0
  148. package/src/tools/shared/types.js +8 -0
  149. package/src/undo-redo.jsx +47 -0
  150. package/src/use-debounce.js +13 -0
  151. package/src/utils.js +234 -0
@@ -0,0 +1,294 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { Typography, Button } from '@material-ui/core';
4
+ import Radio from '@material-ui/core/Radio';
5
+ import { withStyles } from '@material-ui/core/styles';
6
+
7
+ export class ToolMenu extends React.Component {
8
+ static propTypes = {
9
+ classes: PropTypes.object,
10
+ gssLineData: PropTypes.object,
11
+ disabled: PropTypes.bool,
12
+ onChange: PropTypes.func,
13
+ };
14
+
15
+ render() {
16
+ let { classes, gssLineData, disabled } = this.props;
17
+
18
+ return (
19
+ <div className={classes.selectLineRadioGroup}>
20
+ <div className={classes.radioFieldOuter}>
21
+ <div className={classes.radioFieldInner}>
22
+ <Radio
23
+ name={'select-line-radio-buttons'}
24
+ onChange={this.onChangeRadioValue}
25
+ value={'lineA'}
26
+ disabled={!!disabled}
27
+ checked={gssLineData.selectedTool === 'lineA'}
28
+ className={classes.lineTypeRadio}
29
+ />
30
+ <Typography className={classes.lineNameFont}>Line A</Typography>
31
+ </div>
32
+ <div className={classes.radioFieldButtons}>
33
+ {gssLineData.lineA.lineType === 'Solid' ? (
34
+ <Button
35
+ size={'small'}
36
+ variant={'contained'}
37
+ color={'primary'}
38
+ onClick={() => this.lineTypeChange('A', 'Solid')}
39
+ className={disabled ? classes.lineTypeButtonLeftSelectedDisabled : classes.lineTypeButtonLeftSelected}
40
+ >
41
+ &#x2714; Solid
42
+ </Button>
43
+ ) : (
44
+ <Button
45
+ size={'small'}
46
+ variant={'contained'}
47
+ disabled={!!disabled}
48
+ onClick={() => this.lineTypeChange('A', 'Solid')}
49
+ className={
50
+ disabled ? classes.lineTypeButtonLeftUnSelectedDisabled : classes.lineTypeButtonLeftUnSelected
51
+ }
52
+ >
53
+ Solid
54
+ </Button>
55
+ )}
56
+ {gssLineData.lineA.lineType === 'Dashed' ? (
57
+ <Button
58
+ size={'small'}
59
+ variant={'contained'}
60
+ color={'primary'}
61
+ onClick={() => this.lineTypeChange('A', 'Dashed')}
62
+ className={disabled ? classes.lineTypeButtonRightSelectedDisabled : classes.lineTypeButtonRightSelected}
63
+ >
64
+ &#x2714; Dashed
65
+ </Button>
66
+ ) : (
67
+ <Button
68
+ size={'small'}
69
+ variant={'contained'}
70
+ disabled={!!disabled}
71
+ onClick={() => this.lineTypeChange('A', 'Dashed')}
72
+ className={
73
+ disabled ? classes.lineTypeButtonRightUnSelectedDisabled : classes.lineTypeButtonRightUnSelected
74
+ }
75
+ >
76
+ Dashed
77
+ </Button>
78
+ )}
79
+ </div>
80
+ </div>
81
+ {gssLineData.numberOfLines === 2 ? (
82
+ <div className={classes.radioFieldOuter}>
83
+ <div className={classes.radioFieldInner}>
84
+ <Radio
85
+ name={'select-line-radio-buttons'}
86
+ onChange={this.onChangeRadioValue}
87
+ value={'lineB'}
88
+ disabled={!!disabled}
89
+ checked={gssLineData.selectedTool === 'lineB'}
90
+ className={classes.lineTypeRadio}
91
+ />
92
+ <Typography className={classes.lineNameFont}>Line B</Typography>
93
+ </div>
94
+ <div className={classes.radioFieldButtons}>
95
+ {gssLineData.lineB.lineType === 'Solid' ? (
96
+ <Button
97
+ size={'small'}
98
+ variant={'contained'}
99
+ color={'primary'}
100
+ onClick={() => this.lineTypeChange('B', 'Solid')}
101
+ className={disabled ? classes.lineTypeButtonLeftSelectedDisabled : classes.lineTypeButtonLeftSelected}
102
+ >
103
+ &#x2714; Solid
104
+ </Button>
105
+ ) : (
106
+ <Button
107
+ size={'small'}
108
+ variant={'contained'}
109
+ disabled={!!disabled}
110
+ onClick={() => this.lineTypeChange('B', 'Solid')}
111
+ className={
112
+ disabled ? classes.lineTypeButtonLeftUnSelectedDisabled : classes.lineTypeButtonLeftUnSelected
113
+ }
114
+ >
115
+ Solid
116
+ </Button>
117
+ )}
118
+ {gssLineData.lineB.lineType === 'Dashed' ? (
119
+ <Button
120
+ size={'small'}
121
+ variant={'contained'}
122
+ color={'primary'}
123
+ onClick={() => this.lineTypeChange('B', 'Dashed')}
124
+ className={
125
+ disabled ? classes.lineTypeButtonRightSelectedDisabled : classes.lineTypeButtonRightSelected
126
+ }
127
+ >
128
+ &#x2714; Dashed
129
+ </Button>
130
+ ) : (
131
+ <Button
132
+ size={'small'}
133
+ variant={'contained'}
134
+ disabled={!!disabled}
135
+ onClick={() => this.lineTypeChange('B', 'Dashed')}
136
+ className={
137
+ disabled ? classes.lineTypeButtonRightUnSelectedDisabled : classes.lineTypeButtonRightUnSelected
138
+ }
139
+ >
140
+ Dashed
141
+ </Button>
142
+ )}
143
+ </div>
144
+ </div>
145
+ ) : null}
146
+ <div className={classes.radioFieldOuter}>
147
+ <div className={classes.radioFieldInner}>
148
+ <Radio
149
+ name={'select-line-radio-buttons'}
150
+ onChange={this.onChangeRadioValue}
151
+ value={'solutionSet'}
152
+ disabled={!!disabled}
153
+ checked={gssLineData.selectedTool === 'solutionSet'}
154
+ className={classes.lineTypeRadio}
155
+ />
156
+ <Typography className={classes.lineNameFont}>Solution Set</Typography>
157
+ </div>
158
+ </div>
159
+ </div>
160
+ );
161
+ }
162
+
163
+ onChangeRadioValue = (event) => {
164
+ let { gssLineData, onChange } = this.props;
165
+ let oldSelectedTool = gssLineData.selectedTool;
166
+ gssLineData.selectedTool = event.target.value;
167
+ onChange(gssLineData, oldSelectedTool);
168
+ };
169
+
170
+ lineTypeChange = (line, type) => {
171
+ let { gssLineData, onChange } = this.props;
172
+ let oldSelectedTool = gssLineData.selectedTool;
173
+ gssLineData[`line${line}`].lineType = type;
174
+ onChange(gssLineData, oldSelectedTool);
175
+ };
176
+ }
177
+
178
+ const styles = (theme) => ({
179
+ radioButtonClass: {},
180
+ selectLineRadioGroup: {
181
+ display: 'flex',
182
+ flexWrap: 'wrap',
183
+ flexDirection: 'row',
184
+ },
185
+ radioFieldInner: {
186
+ display: 'flex',
187
+ flexWrap: 'wrap',
188
+ flexDirection: 'row',
189
+ alignItems: 'center',
190
+ },
191
+ radioFieldOuter: {
192
+ display: 'flex',
193
+ flexWrap: 'wrap',
194
+ flexDirection: 'column',
195
+ },
196
+ radioFieldButtons: {
197
+ display: 'flex',
198
+ flexWrap: 'wrap',
199
+ flexDirection: 'row',
200
+ padding: '0 .9rem',
201
+ },
202
+ lineTypeText: {
203
+ marginLeft: '.7rem',
204
+ },
205
+ lineNameFont: {
206
+ fontWeight: 'bold',
207
+ padding: '0 5px 0 0',
208
+ },
209
+ lineTypeButtonLeftSelected: {
210
+ textTransform: 'none',
211
+ border: '1px solid #3E4EB1',
212
+ borderRadius: '0',
213
+ backgroundColor: '#3E4EB1 !important',
214
+ borderTopLeftRadius: '4px',
215
+ borderBottomLeftRadius: '4px',
216
+ color: '#FFFFFF !important',
217
+ },
218
+ lineTypeButtonLeftUnSelected: {
219
+ textTransform: 'none',
220
+ border: '1px solid #3E4EB1',
221
+ borderRadius: '0',
222
+ backgroundColor: '#FFFFFF !important',
223
+ borderTopLeftRadius: '4px',
224
+ borderBottomLeftRadius: '4px',
225
+ color: '#3E4EB1 !important',
226
+ },
227
+ lineTypeButtonRightSelected: {
228
+ textTransform: 'none',
229
+ border: '1px solid #3E4EB1',
230
+ borderRadius: '0',
231
+ backgroundColor: '#3E4EB1 !important',
232
+ borderTopRightRadius: '4px',
233
+ borderBottomRightRadius: '4px',
234
+ color: '#FFFFFF !important',
235
+ },
236
+ lineTypeButtonRightUnSelected: {
237
+ textTransform: 'none',
238
+ border: '1px solid #3E4EB1',
239
+ borderRadius: '0',
240
+ backgroundColor: '#FFFFFF !important',
241
+ borderTopRightRadius: '4px',
242
+ borderBottomRightRadius: '4px',
243
+ color: '#3E4EB1 !important',
244
+ },
245
+ lineTypeRadio: {
246
+ color: '#000000 !important',
247
+ },
248
+ lineTypeButtonLeftSelectedDisabled: {
249
+ textTransform: 'none',
250
+ border: '1px solid #3E4EB1',
251
+ borderRadius: '0',
252
+ backgroundColor: '#3E4EB1 !important',
253
+ borderTopLeftRadius: '4px',
254
+ borderBottomLeftRadius: '4px',
255
+ color: '#FFFFFF !important',
256
+ cursor: 'default',
257
+ pointerEvents: 'none',
258
+ },
259
+ lineTypeButtonLeftUnSelectedDisabled: {
260
+ textTransform: 'none',
261
+ border: '1px solid #3E4EB1',
262
+ borderRadius: '0',
263
+ backgroundColor: '#FFFFFF !important',
264
+ borderTopLeftRadius: '4px',
265
+ borderBottomLeftRadius: '4px',
266
+ color: '#3E4EB1 !important',
267
+ cursor: 'default',
268
+ pointerEvents: 'none',
269
+ },
270
+ lineTypeButtonRightSelectedDisabled: {
271
+ textTransform: 'none',
272
+ border: '1px solid #3E4EB1',
273
+ borderRadius: '0',
274
+ backgroundColor: '#3E4EB1 !important',
275
+ borderTopRightRadius: '4px',
276
+ borderBottomRightRadius: '4px',
277
+ color: '#FFFFFF !important',
278
+ cursor: 'default',
279
+ pointerEvents: 'none',
280
+ },
281
+ lineTypeButtonRightUnSelectedDisabled: {
282
+ textTransform: 'none',
283
+ border: '1px solid #3E4EB1',
284
+ borderRadius: '0',
285
+ backgroundColor: '#FFFFFF !important',
286
+ borderTopRightRadius: '4px',
287
+ borderBottomRightRadius: '4px',
288
+ color: '#3E4EB1 !important',
289
+ cursor: 'default',
290
+ pointerEvents: 'none',
291
+ },
292
+ });
293
+
294
+ export default withStyles(styles)(ToolMenu);
@@ -0,0 +1,8 @@
1
+ import { tool as polygon } from './polygon';
2
+ import { tool as line } from './line';
3
+
4
+ const allTools = ['line', 'polygon'];
5
+
6
+ const toolsArr = [line(), polygon()];
7
+
8
+ export { allTools, toolsArr, line, polygon };
@@ -0,0 +1,20 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`ArrowedLine snapshot renders 1`] = `
4
+ <g>
5
+ <defs>
6
+ <ArrowMarker
7
+ className=""
8
+ id="1-enabled"
9
+ size={5}
10
+ />
11
+ </defs>
12
+ <line
13
+ className="className"
14
+ markerEnd="url(#1-enabled)"
15
+ markerId="1"
16
+ markerStart="url(#1-enabled)"
17
+ onChange={[MockFunction]}
18
+ />
19
+ </g>
20
+ `;
@@ -0,0 +1,36 @@
1
+ import { shallow } from 'enzyme';
2
+ import React from 'react';
3
+ import { ArrowedLine } from '../component';
4
+ import { graphProps as getGraphProps } from '../../../__tests__/utils';
5
+ jest.mock('@pie-lib/plot/index', () => {
6
+ const a = jest.requireActual('@pie-lib/plot/index');
7
+ return {
8
+ types: a.types,
9
+ gridDraggable: a.gridDraggable,
10
+ utils: a.utils,
11
+ trig: {
12
+ edges: jest.fn(() => jest.fn().mockReturnValue([0, 0])),
13
+ },
14
+ };
15
+ });
16
+
17
+ describe('ArrowedLine', () => {
18
+ let w;
19
+ let onChange = jest.fn();
20
+ const wrapper = (extras) => {
21
+ const defaults = {
22
+ classes: {},
23
+ className: 'className',
24
+ onChange,
25
+ markerId: '1',
26
+ graphProps: getGraphProps(),
27
+ };
28
+ const props = { ...defaults, ...extras };
29
+ return shallow(<ArrowedLine {...props} />);
30
+ };
31
+ describe('snapshot', () => {
32
+ it('renders', () => {
33
+ expect(wrapper()).toMatchSnapshot();
34
+ });
35
+ });
36
+ });
@@ -0,0 +1,77 @@
1
+ import { lineToolComponent, lineBase, styles } from '../shared/line';
2
+ import React from 'react';
3
+ import PropTypes from 'prop-types';
4
+ import { trig, types } from '@pie-lib/plot';
5
+ import classNames from 'classnames';
6
+ import { withStyles } from '@material-ui/core/styles';
7
+ import { ArrowMarker, genUid } from '../shared/arrow-head';
8
+ import { thinnerShapesNeeded, getAdjustedGraphLimits } from '../../utils';
9
+
10
+ const lineStyles = (theme) => ({
11
+ line: styles.line(theme),
12
+ dashedLine: styles.dashedLine(theme),
13
+ enabledArrow: styles.arrow(theme),
14
+ disabledArrow: styles.disabledArrow(theme),
15
+ disabled: styles.disabled(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),
22
+ });
23
+
24
+ export const ArrowedLine = (props) => {
25
+ const markerId = genUid();
26
+ const { className, classes, correctness, disabled, graphProps, fill = 'Solid', from, to, ...rest } = props;
27
+ const { scale } = graphProps;
28
+ const { domain, range } = getAdjustedGraphLimits(graphProps);
29
+ const [eFrom, eTo] = trig.edges(domain, range)(from, to);
30
+ const suffix = correctness || (disabled && 'disabled') || 'enabled';
31
+
32
+ return (
33
+ <g>
34
+ <defs>
35
+ <ArrowMarker
36
+ size={thinnerShapesNeeded(graphProps) ? 4 : 5}
37
+ id={`${props.markerId || markerId}-${suffix}`}
38
+ className={classNames(classes[`${suffix}Arrow`])}
39
+ />
40
+ </defs>
41
+ <line
42
+ x1={scale.x(eFrom.x)}
43
+ y1={scale.y(eFrom.y)}
44
+ x2={scale.x(eTo.x)}
45
+ y2={scale.y(eTo.y)}
46
+ className={classNames(
47
+ fill === 'Solid' ? classes.line : classes.dashedLine,
48
+ disabled && classes.disabled,
49
+ classes[correctness],
50
+ className,
51
+ )}
52
+ markerEnd={`url(#${props.markerId || markerId}-${suffix})`}
53
+ markerStart={`url(#${props.markerId || markerId}-${suffix})`}
54
+ {...rest}
55
+ />
56
+ </g>
57
+ );
58
+ };
59
+
60
+ ArrowedLine.propTypes = {
61
+ className: PropTypes.string,
62
+ classes: PropTypes.object,
63
+ fill: PropTypes.string,
64
+ correctness: PropTypes.string,
65
+ disabled: PropTypes.bool,
66
+ graphProps: types.GraphPropsType,
67
+ from: types.PointType,
68
+ to: types.PointType,
69
+ markerId: PropTypes.string,
70
+ };
71
+
72
+ const StyledArrowedLine = withStyles(lineStyles)(ArrowedLine);
73
+
74
+ const Line = lineBase(StyledArrowedLine);
75
+ const Component = lineToolComponent(Line);
76
+
77
+ export default Component;
@@ -0,0 +1,4 @@
1
+ import Line from './component';
2
+ import { lineTool } from '../shared/line';
3
+
4
+ export const tool = lineTool('line', Line);
@@ -0,0 +1,94 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`RawBaseComponent snapshot renders 1`] = `
4
+ <g>
5
+ <GridDraggable
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
+ isSolution={false}
33
+ onClick={[Function]}
34
+ points={Array []}
35
+ />
36
+ </g>
37
+ `;
38
+
39
+ exports[`RawBaseComponent snapshot renders with labels 1`] = `
40
+ <g>
41
+ <GridDraggable
42
+ graphProps={
43
+ Object {
44
+ "domain": Object {
45
+ "max": 1,
46
+ "min": 0,
47
+ "step": 1,
48
+ },
49
+ "range": Object {
50
+ "max": 1,
51
+ "min": 0,
52
+ "step": 1,
53
+ },
54
+ "scale": Object {
55
+ "x": [MockFunction],
56
+ "y": [MockFunction],
57
+ },
58
+ "size": Object {
59
+ "height": 400,
60
+ "width": 400,
61
+ },
62
+ "snap": Object {
63
+ "x": [MockFunction],
64
+ "y": [MockFunction],
65
+ },
66
+ }
67
+ }
68
+ isSolution={false}
69
+ onClick={[Function]}
70
+ points={
71
+ Array [
72
+ Object {
73
+ "index": 0,
74
+ "label": "A",
75
+ "x": 0,
76
+ "y": 0,
77
+ },
78
+ Object {
79
+ "index": 1,
80
+ "label": "B",
81
+ "x": 2,
82
+ "y": 2,
83
+ },
84
+ Object {
85
+ "index": 2,
86
+ "label": "C",
87
+ "x": 0,
88
+ "y": 2,
89
+ },
90
+ ]
91
+ }
92
+ />
93
+ </g>
94
+ `;
@@ -0,0 +1,44 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`Line snapshot renders 1`] = `
4
+ <RawLine
5
+ className="className"
6
+ classes={
7
+ Object {
8
+ "correct": "RawLine-correct-3",
9
+ "disabled": "RawLine-disabled-2",
10
+ "incorrect": "RawLine-incorrect-4",
11
+ "line": "RawLine-line-1",
12
+ "missing": "RawLine-missing-5",
13
+ }
14
+ }
15
+ from={Object {}}
16
+ graphProps={
17
+ Object {
18
+ "domain": Object {
19
+ "max": 1,
20
+ "min": 0,
21
+ "step": 1,
22
+ },
23
+ "range": Object {
24
+ "max": 1,
25
+ "min": 0,
26
+ "step": 1,
27
+ },
28
+ "scale": Object {
29
+ "x": [MockFunction],
30
+ "y": [MockFunction],
31
+ },
32
+ "size": Object {
33
+ "height": 400,
34
+ "width": 400,
35
+ },
36
+ "snap": Object {
37
+ "x": [MockFunction],
38
+ "y": [MockFunction],
39
+ },
40
+ }
41
+ }
42
+ to={Object {}}
43
+ />
44
+ `;
@@ -0,0 +1,53 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`Polygon snapshot renders 1`] = `
4
+ <RawPolygon
5
+ className="className"
6
+ classes={
7
+ Object {
8
+ "closed": "RawPolygon-closed-1",
9
+ "correct": "RawPolygon-correct-6",
10
+ "disabled": "RawPolygon-disabled-5",
11
+ "gssClosed": "RawPolygon-gssClosed-3",
12
+ "gssSolution": "RawPolygon-gssSolution-4",
13
+ "incorrect": "RawPolygon-incorrect-7",
14
+ "open": "RawPolygon-open-2",
15
+ }
16
+ }
17
+ closed={false}
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
+ points={
45
+ Array [
46
+ Object {
47
+ "x": 1,
48
+ "y": 1,
49
+ },
50
+ ]
51
+ }
52
+ />
53
+ `;