@khanacademy/perseus-editor 4.1.5 → 4.1.6
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.
- package/dist/es/index.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +9 -6
- package/.babelrc.js +0 -8
- package/.eslintrc.js +0 -12
- package/CHANGELOG.md +0 -1155
- package/src/README.md +0 -7
- package/src/__stories__/editor-page.stories.tsx +0 -65
- package/src/__stories__/editor.stories.tsx +0 -134
- package/src/__stories__/item-editor.stories.tsx +0 -41
- package/src/__stories__/tex-error-view.stories.tsx +0 -26
- package/src/__testdata__/input-number.testdata.ts +0 -27
- package/src/__tests__/editor.test.tsx +0 -142
- package/src/__tests__/hint-editor.test.tsx +0 -83
- package/src/__tests__/i18n.test.ts +0 -501
- package/src/__tests__/integration.test.ts +0 -5
- package/src/__tests__/item-extras-editor.test.tsx +0 -85
- package/src/__tests__/traversal.test.ts +0 -377
- package/src/all-editors.test.ts +0 -16
- package/src/all-editors.ts +0 -83
- package/src/all-widgets.ts +0 -7
- package/src/article-editor.tsx +0 -438
- package/src/components/__stories__/blur-input.stories.tsx +0 -22
- package/src/components/__stories__/section-control-button.stories.tsx +0 -26
- package/src/components/__tests__/blur-input.test.tsx +0 -67
- package/src/components/blur-input.tsx +0 -69
- package/src/components/checkbox.tsx +0 -194
- package/src/components/device-framer.tsx +0 -90
- package/src/components/drag-target.tsx +0 -87
- package/src/components/dropdown-option.tsx +0 -311
- package/src/components/form-wrapped-text-field.tsx +0 -245
- package/src/components/graph-points-count-selector.tsx +0 -31
- package/src/components/graph-settings.tsx +0 -627
- package/src/components/graph-type-selector.tsx +0 -31
- package/src/components/hover-behavior.ts +0 -177
- package/src/components/json-editor.tsx +0 -121
- package/src/components/link.ts +0 -173
- package/src/components/section-control-button.tsx +0 -53
- package/src/components/segment-count-selector.tsx +0 -27
- package/src/components/simple-button.tsx +0 -85
- package/src/components/sortable.tsx +0 -187
- package/src/components/util.ts +0 -38
- package/src/components/viewport-resizer.tsx +0 -72
- package/src/components/widget-editor.tsx +0 -222
- package/src/components/widget-select.tsx +0 -48
- package/src/diffs/__stories__/perseus-diff-wrapper.tsx +0 -11
- package/src/diffs/__stories__/structured-item-diff.stories.tsx +0 -855
- package/src/diffs/__stories__/tags-diff.stories.tsx +0 -36
- package/src/diffs/__stories__/text-diff.stories.tsx +0 -35
- package/src/diffs/__tests__/split-diff.test.ts +0 -33
- package/src/diffs/__tests__/string-array-diff.test.ts +0 -73
- package/src/diffs/__tests__/structured-item-diff.test.ts +0 -433
- package/src/diffs/__tests__/widget-diff-performer.test.ts +0 -43
- package/src/diffs/article-diff.tsx +0 -69
- package/src/diffs/item-diff.tsx +0 -76
- package/src/diffs/renderer-diff.tsx +0 -137
- package/src/diffs/split-diff.ts +0 -31
- package/src/diffs/string-array-diff.ts +0 -74
- package/src/diffs/structured-item-diff.tsx +0 -275
- package/src/diffs/tags-diff.tsx +0 -49
- package/src/diffs/text-diff.tsx +0 -193
- package/src/diffs/widget-diff-performer.ts +0 -69
- package/src/diffs/widget-diff.tsx +0 -290
- package/src/editor-page.tsx +0 -325
- package/src/editor.tsx +0 -1099
- package/src/hint-editor.tsx +0 -469
- package/src/i18n.ts +0 -140
- package/src/iframe-content-renderer.tsx +0 -188
- package/src/index.ts +0 -30
- package/src/item-editor.tsx +0 -158
- package/src/item-extras-editor.tsx +0 -230
- package/src/katex-mhchem/index.js +0 -73
- package/src/katex-mhchem/parser.js +0 -2659
- package/src/multirenderer-editor.tsx +0 -1061
- package/src/stateful-article-editor.tsx +0 -173
- package/src/stateful-editor-page.tsx +0 -88
- package/src/styles/perseus-editor.less +0 -1321
- package/src/testing-widgets.ts +0 -11
- package/src/tex-error-view.tsx +0 -90
- package/src/util/points.test.ts +0 -24
- package/src/util/points.ts +0 -13
- package/src/util/register-all-widgets-and-editors-for-testing.test.ts +0 -17
- package/src/util/register-all-widgets-and-editors-for-testing.ts +0 -17
- package/src/version.ts +0 -10
- package/src/widgets/__stories__/categorizer-editor.stories.tsx +0 -24
- package/src/widgets/__stories__/definition-editor.stories.tsx +0 -18
- package/src/widgets/__stories__/dropdown-editor.stories.tsx +0 -18
- package/src/widgets/__stories__/explanation-editor.stories.tsx +0 -18
- package/src/widgets/__stories__/expression-editor.stories.tsx +0 -122
- package/src/widgets/__stories__/image-editor.stories.tsx +0 -72
- package/src/widgets/__stories__/input-number-editor.stories.tsx +0 -18
- package/src/widgets/__stories__/interaction-editor.stories.tsx +0 -37
- package/src/widgets/__stories__/label-image-editor.stories.tsx +0 -99
- package/src/widgets/__stories__/matcher-editor.stories.tsx +0 -18
- package/src/widgets/__stories__/number-line-editor.stories.tsx +0 -18
- package/src/widgets/__stories__/numeric-input-editor.stories.tsx +0 -18
- package/src/widgets/__stories__/radio-editor.stories.tsx +0 -116
- package/src/widgets/__stories__/sorter-editor.stories.tsx +0 -18
- package/src/widgets/__tests__/categorizer-editor.test.tsx +0 -51
- package/src/widgets/__tests__/definition-editor.test.tsx +0 -41
- package/src/widgets/__tests__/dropdown-editor.test.tsx +0 -57
- package/src/widgets/__tests__/explanation-editor.test.tsx +0 -59
- package/src/widgets/__tests__/expression-editor.test.tsx +0 -403
- package/src/widgets/__tests__/input-number-editor.test.tsx +0 -128
- package/src/widgets/__tests__/matcher-editor.test.tsx +0 -47
- package/src/widgets/__tests__/number-line-editor.test.tsx +0 -144
- package/src/widgets/__tests__/numeric-input-editor.test.tsx +0 -177
- package/src/widgets/__tests__/radio-editor.test.tsx +0 -118
- package/src/widgets/__tests__/sorter-editor.test.tsx +0 -55
- package/src/widgets/categorizer-editor.tsx +0 -104
- package/src/widgets/cs-program-editor.tsx +0 -256
- package/src/widgets/definition-editor.tsx +0 -77
- package/src/widgets/deprecated-standin-editor.tsx +0 -29
- package/src/widgets/dropdown-editor.tsx +0 -211
- package/src/widgets/example-graphie-widget-editor.tsx +0 -70
- package/src/widgets/example-graphie-widget.tsx +0 -172
- package/src/widgets/example-widget-editor.tsx +0 -62
- package/src/widgets/example-widget.tsx +0 -154
- package/src/widgets/explanation-editor.tsx +0 -92
- package/src/widgets/expression-editor.tsx +0 -557
- package/src/widgets/graded-group-editor.tsx +0 -161
- package/src/widgets/graded-group-set-editor.tsx +0 -104
- package/src/widgets/grapher-editor.tsx +0 -155
- package/src/widgets/group-editor.tsx +0 -83
- package/src/widgets/iframe-editor.tsx +0 -202
- package/src/widgets/image-editor.tsx +0 -367
- package/src/widgets/input-number-editor.tsx +0 -288
- package/src/widgets/interaction-editor/constraint-editor.tsx +0 -134
- package/src/widgets/interaction-editor/function-editor.tsx +0 -108
- package/src/widgets/interaction-editor/index.ts +0 -3
- package/src/widgets/interaction-editor/interaction-editor.tsx +0 -749
- package/src/widgets/interaction-editor/label-editor.tsx +0 -87
- package/src/widgets/interaction-editor/line-editor.tsx +0 -125
- package/src/widgets/interaction-editor/mathquill-input.tsx +0 -81
- package/src/widgets/interaction-editor/movable-line-editor.tsx +0 -121
- package/src/widgets/interaction-editor/movable-point-editor.tsx +0 -89
- package/src/widgets/interaction-editor/parametric-editor.tsx +0 -117
- package/src/widgets/interaction-editor/point-editor.tsx +0 -72
- package/src/widgets/interaction-editor/rectangle-editor.tsx +0 -96
- package/src/widgets/interactive-graph-editor.tsx +0 -571
- package/src/widgets/label-image/__stories__/answer-choices.stories.tsx +0 -82
- package/src/widgets/label-image/__stories__/behavior.stories.tsx +0 -31
- package/src/widgets/label-image/__stories__/marker.stories.tsx +0 -75
- package/src/widgets/label-image/__stories__/question-markers.stories.tsx +0 -107
- package/src/widgets/label-image/__stories__/select-image.stories.tsx +0 -59
- package/src/widgets/label-image/answer-choices.tsx +0 -231
- package/src/widgets/label-image/behavior.tsx +0 -122
- package/src/widgets/label-image/marker.tsx +0 -290
- package/src/widgets/label-image/question-markers.tsx +0 -176
- package/src/widgets/label-image/select-image.tsx +0 -81
- package/src/widgets/label-image-editor.tsx +0 -252
- package/src/widgets/lights-puzzle-editor.tsx +0 -278
- package/src/widgets/matcher-editor.tsx +0 -149
- package/src/widgets/matrix-editor.tsx +0 -156
- package/src/widgets/measurer-editor.tsx +0 -253
- package/src/widgets/molecule-editor.tsx +0 -64
- package/src/widgets/number-line-editor.tsx +0 -512
- package/src/widgets/numeric-input-editor.tsx +0 -536
- package/src/widgets/orderer-editor.tsx +0 -172
- package/src/widgets/passage-editor.tsx +0 -117
- package/src/widgets/passage-ref-editor.tsx +0 -80
- package/src/widgets/passage-ref-target-editor.tsx +0 -49
- package/src/widgets/plotter-editor.tsx +0 -542
- package/src/widgets/radio/editor.tsx +0 -398
- package/src/widgets/reaction-diagram-editor.tsx +0 -131
- package/src/widgets/sequence-editor.tsx +0 -205
- package/src/widgets/simple-markdown-tester-editor.tsx +0 -86
- package/src/widgets/simple-markdown-tester.tsx +0 -92
- package/src/widgets/simulator-editor.tsx +0 -146
- package/src/widgets/sorter-editor.tsx +0 -103
- package/src/widgets/table-editor.tsx +0 -164
- package/src/widgets/unit-editor.tsx +0 -299
- package/src/widgets/video-editor.tsx +0 -73
- package/tsconfig-build.json +0 -22
- package/tsconfig-build.tsbuildinfo +0 -1
|
@@ -1,627 +0,0 @@
|
|
|
1
|
-
/* eslint-disable react/forbid-prop-types, react/no-unsafe */
|
|
2
|
-
import {
|
|
3
|
-
components,
|
|
4
|
-
interactiveSizes,
|
|
5
|
-
Changeable,
|
|
6
|
-
Dependencies,
|
|
7
|
-
KhanMath,
|
|
8
|
-
Util,
|
|
9
|
-
} from "@khanacademy/perseus";
|
|
10
|
-
import createReactClass from "create-react-class";
|
|
11
|
-
import PropTypes from "prop-types";
|
|
12
|
-
import * as React from "react";
|
|
13
|
-
import ReactDOM from "react-dom";
|
|
14
|
-
import _ from "underscore";
|
|
15
|
-
|
|
16
|
-
const {ButtonGroup, InfoTip, PropCheckBox, RangeInput} = components;
|
|
17
|
-
const {getDependencies} = Dependencies;
|
|
18
|
-
|
|
19
|
-
const defaultBackgroundImage = {
|
|
20
|
-
url: null,
|
|
21
|
-
width: 0,
|
|
22
|
-
height: 0,
|
|
23
|
-
} as const;
|
|
24
|
-
|
|
25
|
-
function numSteps(range: any, step: any) {
|
|
26
|
-
return Math.floor((range[1] - range[0]) / step);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const GraphSettings = createReactClass({
|
|
30
|
-
displayName: "GraphSettings",
|
|
31
|
-
|
|
32
|
-
propTypes: {
|
|
33
|
-
...Changeable.propTypes,
|
|
34
|
-
editableSettings: PropTypes.arrayOf(
|
|
35
|
-
PropTypes.oneOf(["canvas", "graph", "snap", "image", "measure"]),
|
|
36
|
-
),
|
|
37
|
-
box: PropTypes.arrayOf(PropTypes.number),
|
|
38
|
-
labels: PropTypes.arrayOf(PropTypes.string),
|
|
39
|
-
range: PropTypes.arrayOf(PropTypes.arrayOf(PropTypes.number)),
|
|
40
|
-
step: PropTypes.arrayOf(PropTypes.number),
|
|
41
|
-
gridStep: PropTypes.arrayOf(PropTypes.number),
|
|
42
|
-
snapStep: PropTypes.arrayOf(PropTypes.number),
|
|
43
|
-
valid: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
|
|
44
|
-
backgroundImage: PropTypes.object,
|
|
45
|
-
markings: PropTypes.oneOf(["graph", "grid", "none"]),
|
|
46
|
-
showProtractor: PropTypes.bool,
|
|
47
|
-
showRuler: PropTypes.bool,
|
|
48
|
-
showTooltips: PropTypes.bool,
|
|
49
|
-
rulerLabel: PropTypes.string,
|
|
50
|
-
rulerTicks: PropTypes.number,
|
|
51
|
-
},
|
|
52
|
-
|
|
53
|
-
getDefaultProps: function () {
|
|
54
|
-
return {
|
|
55
|
-
editableSettings: ["graph", "snap", "image", "measure"],
|
|
56
|
-
box: [
|
|
57
|
-
interactiveSizes.defaultBoxSizeSmall,
|
|
58
|
-
interactiveSizes.defaultBoxSizeSmall,
|
|
59
|
-
],
|
|
60
|
-
labels: ["x", "y"],
|
|
61
|
-
range: [
|
|
62
|
-
[-10, 10],
|
|
63
|
-
[-10, 10],
|
|
64
|
-
],
|
|
65
|
-
step: [1, 1],
|
|
66
|
-
gridStep: [1, 1],
|
|
67
|
-
snapStep: [1, 1],
|
|
68
|
-
valid: true,
|
|
69
|
-
backgroundImage: defaultBackgroundImage,
|
|
70
|
-
markings: "graph",
|
|
71
|
-
showProtractor: false,
|
|
72
|
-
showRuler: false,
|
|
73
|
-
showTooltips: false,
|
|
74
|
-
rulerLabel: "",
|
|
75
|
-
rulerTicks: 10,
|
|
76
|
-
};
|
|
77
|
-
},
|
|
78
|
-
|
|
79
|
-
getInitialState: function () {
|
|
80
|
-
return this.stateFromProps(this.props);
|
|
81
|
-
},
|
|
82
|
-
|
|
83
|
-
componentDidMount: function () {
|
|
84
|
-
// TODO(scottgrant): This is a hack to remove the deprecated call to
|
|
85
|
-
// this.isMounted() but is still considered an anti-pattern.
|
|
86
|
-
this._isMounted = true;
|
|
87
|
-
|
|
88
|
-
this.changeGraph = _.debounce(this.changeGraph, 300);
|
|
89
|
-
},
|
|
90
|
-
|
|
91
|
-
UNSAFE_componentWillReceiveProps: function (nextProps) {
|
|
92
|
-
// Make sure that state updates when switching
|
|
93
|
-
// between different items in a multi-item editor.
|
|
94
|
-
if (
|
|
95
|
-
!_.isEqual(this.props.labels, nextProps.labels) ||
|
|
96
|
-
!_.isEqual(this.props.gridStep, nextProps.gridStep) ||
|
|
97
|
-
!_.isEqual(this.props.snapStep, nextProps.snapStep) ||
|
|
98
|
-
!_.isEqual(this.props.step, nextProps.step) ||
|
|
99
|
-
!_.isEqual(this.props.range, nextProps.range) ||
|
|
100
|
-
!_.isEqual(this.props.backgroundImage, nextProps.backgroundImage)
|
|
101
|
-
) {
|
|
102
|
-
this.setState(this.stateFromProps(nextProps));
|
|
103
|
-
}
|
|
104
|
-
},
|
|
105
|
-
|
|
106
|
-
componentWillUnmount: function () {
|
|
107
|
-
this._isMounted = false;
|
|
108
|
-
},
|
|
109
|
-
|
|
110
|
-
stateFromProps: function (props) {
|
|
111
|
-
return {
|
|
112
|
-
labelsTextbox: props.labels,
|
|
113
|
-
gridStepTextbox: props.gridStep,
|
|
114
|
-
snapStepTextbox: props.snapStep,
|
|
115
|
-
stepTextbox: props.step,
|
|
116
|
-
rangeTextbox: props.range,
|
|
117
|
-
backgroundImage: _.clone(props.backgroundImage),
|
|
118
|
-
};
|
|
119
|
-
},
|
|
120
|
-
|
|
121
|
-
change(...args) {
|
|
122
|
-
return Changeable.change.apply(this, args);
|
|
123
|
-
},
|
|
124
|
-
|
|
125
|
-
// TODO(aria): Make either a wrapper for standard events to work
|
|
126
|
-
// with this.change, or make these use some TextInput/NumberInput box
|
|
127
|
-
changeRulerLabel: function (e) {
|
|
128
|
-
this.change({rulerLabel: e.target.value});
|
|
129
|
-
},
|
|
130
|
-
|
|
131
|
-
changeRulerTicks: function (e) {
|
|
132
|
-
this.change({rulerTicks: +e.target.value});
|
|
133
|
-
},
|
|
134
|
-
|
|
135
|
-
changeBackgroundUrl: function (e) {
|
|
136
|
-
// Only continue on blur or "enter"
|
|
137
|
-
if (e.type === "keypress" && e.key !== "Enter") {
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
const setUrl = (url, width: number, height: number) => {
|
|
142
|
-
const image = _.clone(this.props.backgroundImage);
|
|
143
|
-
image.url = url;
|
|
144
|
-
image.width = width;
|
|
145
|
-
image.height = height;
|
|
146
|
-
this.setState(
|
|
147
|
-
{
|
|
148
|
-
backgroundImage: image,
|
|
149
|
-
},
|
|
150
|
-
this.changeGraph,
|
|
151
|
-
);
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
// @ts-expect-error - TS2531 - Object is possibly 'null'. | TS2339 - Property 'value' does not exist on type 'Element | Text'.
|
|
155
|
-
const url = ReactDOM.findDOMNode(this.refs["bg-url"]).value; // eslint-disable-line react/no-string-refs
|
|
156
|
-
if (url) {
|
|
157
|
-
Util.getImageSize(url, (width, height) => {
|
|
158
|
-
if (this._isMounted) {
|
|
159
|
-
setUrl(url, width, height);
|
|
160
|
-
}
|
|
161
|
-
});
|
|
162
|
-
} else {
|
|
163
|
-
setUrl(null, 0, 0);
|
|
164
|
-
}
|
|
165
|
-
},
|
|
166
|
-
|
|
167
|
-
renderLabelChoices: function (choices) {
|
|
168
|
-
return _.map(choices, function (nameAndValue) {
|
|
169
|
-
return <option value={nameAndValue[1]}>{nameAndValue[0]}</option>;
|
|
170
|
-
});
|
|
171
|
-
},
|
|
172
|
-
|
|
173
|
-
validRange: function (range) {
|
|
174
|
-
const numbers = _.every(range, function (num) {
|
|
175
|
-
return _.isFinite(num);
|
|
176
|
-
});
|
|
177
|
-
if (!numbers) {
|
|
178
|
-
return "Range must be a valid number";
|
|
179
|
-
}
|
|
180
|
-
if (range[0] >= range[1]) {
|
|
181
|
-
return "Range must have a higher number on the right";
|
|
182
|
-
}
|
|
183
|
-
return true;
|
|
184
|
-
},
|
|
185
|
-
|
|
186
|
-
validateStepValue: function (settings) {
|
|
187
|
-
const {step, range, name, minTicks, maxTicks} = settings;
|
|
188
|
-
|
|
189
|
-
if (!_.isFinite(step)) {
|
|
190
|
-
return name + " must be a valid number";
|
|
191
|
-
}
|
|
192
|
-
const nSteps = numSteps(range, step);
|
|
193
|
-
if (nSteps < minTicks) {
|
|
194
|
-
return (
|
|
195
|
-
name +
|
|
196
|
-
" is too large, there must be at least " +
|
|
197
|
-
minTicks +
|
|
198
|
-
" ticks."
|
|
199
|
-
);
|
|
200
|
-
}
|
|
201
|
-
if (nSteps > maxTicks) {
|
|
202
|
-
return (
|
|
203
|
-
name +
|
|
204
|
-
" is too small, there can be at most " +
|
|
205
|
-
maxTicks +
|
|
206
|
-
" ticks."
|
|
207
|
-
);
|
|
208
|
-
}
|
|
209
|
-
return true;
|
|
210
|
-
},
|
|
211
|
-
|
|
212
|
-
validSnapStep: function (step, range) {
|
|
213
|
-
return this.validateStepValue({
|
|
214
|
-
step: step,
|
|
215
|
-
range: range,
|
|
216
|
-
name: "Snap step",
|
|
217
|
-
minTicks: 5,
|
|
218
|
-
maxTicks: 60,
|
|
219
|
-
});
|
|
220
|
-
},
|
|
221
|
-
|
|
222
|
-
validGridStep: function (step, range) {
|
|
223
|
-
return this.validateStepValue({
|
|
224
|
-
step: step,
|
|
225
|
-
range: range,
|
|
226
|
-
name: "Grid step",
|
|
227
|
-
minTicks: 3,
|
|
228
|
-
maxTicks: 60,
|
|
229
|
-
});
|
|
230
|
-
},
|
|
231
|
-
|
|
232
|
-
validStep: function (step, range) {
|
|
233
|
-
return this.validateStepValue({
|
|
234
|
-
step: step,
|
|
235
|
-
range: range,
|
|
236
|
-
name: "Step",
|
|
237
|
-
minTicks: 3,
|
|
238
|
-
maxTicks: 20,
|
|
239
|
-
});
|
|
240
|
-
},
|
|
241
|
-
|
|
242
|
-
validBackgroundImageSize: function (image) {
|
|
243
|
-
// Ignore empty images
|
|
244
|
-
if (!image.url) {
|
|
245
|
-
return true;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
const validSize = image.width <= 450 && image.height <= 450;
|
|
249
|
-
|
|
250
|
-
if (!validSize) {
|
|
251
|
-
return "Image must be smaller than 450px x 450px.";
|
|
252
|
-
}
|
|
253
|
-
return true;
|
|
254
|
-
},
|
|
255
|
-
|
|
256
|
-
validateGraphSettings: function (range, step, gridStep, snapStep, image) {
|
|
257
|
-
const self = this;
|
|
258
|
-
let msg;
|
|
259
|
-
const goodRange = _.every(range, function (range) {
|
|
260
|
-
msg = self.validRange(range);
|
|
261
|
-
return msg === true;
|
|
262
|
-
});
|
|
263
|
-
if (!goodRange) {
|
|
264
|
-
return msg;
|
|
265
|
-
}
|
|
266
|
-
const goodStep = _.every(step, function (step, i) {
|
|
267
|
-
msg = self.validStep(step, range[i]);
|
|
268
|
-
return msg === true;
|
|
269
|
-
});
|
|
270
|
-
if (!goodStep) {
|
|
271
|
-
return msg;
|
|
272
|
-
}
|
|
273
|
-
const goodGridStep = _.every(gridStep, function (gridStep, i) {
|
|
274
|
-
msg = self.validGridStep(gridStep, range[i]);
|
|
275
|
-
return msg === true;
|
|
276
|
-
});
|
|
277
|
-
if (!goodGridStep) {
|
|
278
|
-
return msg;
|
|
279
|
-
}
|
|
280
|
-
const goodSnapStep = _.every(snapStep, function (snapStep, i) {
|
|
281
|
-
msg = self.validSnapStep(snapStep, range[i]);
|
|
282
|
-
return msg === true;
|
|
283
|
-
});
|
|
284
|
-
if (!goodSnapStep) {
|
|
285
|
-
return msg;
|
|
286
|
-
}
|
|
287
|
-
const goodImageSize = this.validBackgroundImageSize(image);
|
|
288
|
-
if (goodImageSize !== true) {
|
|
289
|
-
msg = goodImageSize;
|
|
290
|
-
return msg;
|
|
291
|
-
}
|
|
292
|
-
return true;
|
|
293
|
-
},
|
|
294
|
-
|
|
295
|
-
changeLabel: function (i, e) {
|
|
296
|
-
const val = e.target.value;
|
|
297
|
-
const labels = this.state.labelsTextbox.slice();
|
|
298
|
-
labels[i] = val;
|
|
299
|
-
this.setState({labelsTextbox: labels}, this.changeGraph);
|
|
300
|
-
},
|
|
301
|
-
|
|
302
|
-
changeRange: function (i, values) {
|
|
303
|
-
const ranges = this.state.rangeTextbox.slice();
|
|
304
|
-
ranges[i] = values;
|
|
305
|
-
const step = this.state.stepTextbox.slice();
|
|
306
|
-
const gridStep = this.state.gridStepTextbox.slice();
|
|
307
|
-
const snapStep = this.state.snapStepTextbox.slice();
|
|
308
|
-
const scale = Util.scaleFromExtent(ranges[i], this.props.box[i]);
|
|
309
|
-
if (this.validRange(ranges[i]) === true) {
|
|
310
|
-
step[i] = Util.tickStepFromExtent(ranges[i], this.props.box[i]);
|
|
311
|
-
gridStep[i] = Util.gridStepFromTickStep(step[i], scale);
|
|
312
|
-
snapStep[i] = gridStep[i] / 2;
|
|
313
|
-
}
|
|
314
|
-
this.setState(
|
|
315
|
-
{
|
|
316
|
-
stepTextbox: step,
|
|
317
|
-
gridStepTextbox: gridStep,
|
|
318
|
-
snapStepTextbox: snapStep,
|
|
319
|
-
rangeTextbox: ranges,
|
|
320
|
-
},
|
|
321
|
-
this.changeGraph,
|
|
322
|
-
);
|
|
323
|
-
},
|
|
324
|
-
|
|
325
|
-
changeStep: function (step) {
|
|
326
|
-
this.setState({stepTextbox: step}, this.changeGraph);
|
|
327
|
-
},
|
|
328
|
-
|
|
329
|
-
changeSnapStep: function (snapStep) {
|
|
330
|
-
this.setState({snapStepTextbox: snapStep}, this.changeGraph);
|
|
331
|
-
},
|
|
332
|
-
|
|
333
|
-
changeGridStep: function (gridStep) {
|
|
334
|
-
this.setState(
|
|
335
|
-
{
|
|
336
|
-
gridStepTextbox: gridStep,
|
|
337
|
-
snapStepTextbox: _.map(gridStep, function (step) {
|
|
338
|
-
return step / 2;
|
|
339
|
-
}),
|
|
340
|
-
},
|
|
341
|
-
this.changeGraph,
|
|
342
|
-
);
|
|
343
|
-
},
|
|
344
|
-
|
|
345
|
-
changeGraph: function () {
|
|
346
|
-
const labels = this.state.labelsTextbox;
|
|
347
|
-
const range = _.map(this.state.rangeTextbox, function (range) {
|
|
348
|
-
return _.map(range, Number);
|
|
349
|
-
});
|
|
350
|
-
const step = _.map(this.state.stepTextbox, Number);
|
|
351
|
-
const gridStep = this.state.gridStepTextbox;
|
|
352
|
-
const snapStep = this.state.snapStepTextbox;
|
|
353
|
-
const image = this.state.backgroundImage;
|
|
354
|
-
|
|
355
|
-
// validationResult is either:
|
|
356
|
-
// true -> the settings are valid
|
|
357
|
-
// a string -> the settings are invalid, and the explanation
|
|
358
|
-
// is contained in the string
|
|
359
|
-
// TODO(aria): Refactor this to not be confusing
|
|
360
|
-
const validationResult = this.validateGraphSettings(
|
|
361
|
-
range,
|
|
362
|
-
step,
|
|
363
|
-
gridStep,
|
|
364
|
-
snapStep,
|
|
365
|
-
image,
|
|
366
|
-
);
|
|
367
|
-
|
|
368
|
-
if (validationResult === true) {
|
|
369
|
-
// either true or a string
|
|
370
|
-
this.change({
|
|
371
|
-
valid: true,
|
|
372
|
-
labels: labels,
|
|
373
|
-
range: range,
|
|
374
|
-
step: step,
|
|
375
|
-
gridStep: gridStep,
|
|
376
|
-
snapStep: snapStep,
|
|
377
|
-
backgroundImage: image,
|
|
378
|
-
});
|
|
379
|
-
} else {
|
|
380
|
-
this.change({
|
|
381
|
-
valid: validationResult, // a string message, not false
|
|
382
|
-
});
|
|
383
|
-
}
|
|
384
|
-
},
|
|
385
|
-
|
|
386
|
-
render: function () {
|
|
387
|
-
const scale = [
|
|
388
|
-
KhanMath.roundTo(
|
|
389
|
-
2,
|
|
390
|
-
Util.scaleFromExtent(this.props.range[0], this.props.box[0]),
|
|
391
|
-
),
|
|
392
|
-
KhanMath.roundTo(
|
|
393
|
-
2,
|
|
394
|
-
Util.scaleFromExtent(this.props.range[1], this.props.box[1]),
|
|
395
|
-
),
|
|
396
|
-
];
|
|
397
|
-
|
|
398
|
-
const {TeX} = getDependencies();
|
|
399
|
-
|
|
400
|
-
return (
|
|
401
|
-
<div>
|
|
402
|
-
{_.contains(this.props.editableSettings, "canvas") && (
|
|
403
|
-
<div className="graph-settings">
|
|
404
|
-
<div className="perseus-widget-row">
|
|
405
|
-
Canvas size (x,y pixels)
|
|
406
|
-
<RangeInput
|
|
407
|
-
value={this.props.box}
|
|
408
|
-
onChange={(box) => {
|
|
409
|
-
this.change({box: box});
|
|
410
|
-
}}
|
|
411
|
-
/>
|
|
412
|
-
</div>
|
|
413
|
-
<div className="perseus-widget-row">
|
|
414
|
-
Scale (px per div):{" "}
|
|
415
|
-
<TeX>{"(" + scale[0] + ", " + scale[1] + ")"}</TeX>
|
|
416
|
-
</div>
|
|
417
|
-
</div>
|
|
418
|
-
)}
|
|
419
|
-
|
|
420
|
-
{_.contains(this.props.editableSettings, "graph") && (
|
|
421
|
-
<div className="graph-settings">
|
|
422
|
-
<div className="perseus-widget-row">
|
|
423
|
-
<div className="perseus-widget-left-col">
|
|
424
|
-
{" "}
|
|
425
|
-
x Label
|
|
426
|
-
<input
|
|
427
|
-
type="text"
|
|
428
|
-
className="graph-settings-axis-label"
|
|
429
|
-
// eslint-disable-next-line react/no-string-refs
|
|
430
|
-
ref="labels-0"
|
|
431
|
-
onChange={(e) => this.changeLabel(0, e)}
|
|
432
|
-
value={this.state.labelsTextbox[0] || ""}
|
|
433
|
-
/>
|
|
434
|
-
</div>
|
|
435
|
-
<div className="perseus-widget-right-col">
|
|
436
|
-
y Label
|
|
437
|
-
<input
|
|
438
|
-
type="text"
|
|
439
|
-
className="graph-settings-axis-label"
|
|
440
|
-
// eslint-disable-next-line react/no-string-refs
|
|
441
|
-
ref="labels-1"
|
|
442
|
-
onChange={(e) => this.changeLabel(1, e)}
|
|
443
|
-
value={this.state.labelsTextbox[1] || ""}
|
|
444
|
-
/>
|
|
445
|
-
</div>
|
|
446
|
-
</div>
|
|
447
|
-
|
|
448
|
-
<div className="perseus-widget-row">
|
|
449
|
-
<div className="perseus-widget-left-col">
|
|
450
|
-
x Range
|
|
451
|
-
<RangeInput
|
|
452
|
-
value={this.state.rangeTextbox[0]}
|
|
453
|
-
onChange={(vals) =>
|
|
454
|
-
this.changeRange(0, vals)
|
|
455
|
-
}
|
|
456
|
-
/>
|
|
457
|
-
</div>
|
|
458
|
-
<div className="perseus-widget-right-col">
|
|
459
|
-
y Range
|
|
460
|
-
<RangeInput
|
|
461
|
-
value={this.state.rangeTextbox[1]}
|
|
462
|
-
onChange={(vals) =>
|
|
463
|
-
this.changeRange(1, vals)
|
|
464
|
-
}
|
|
465
|
-
/>
|
|
466
|
-
</div>
|
|
467
|
-
</div>
|
|
468
|
-
<div className="perseus-widget-row">
|
|
469
|
-
<div className="perseus-widget-left-col">
|
|
470
|
-
Tick Step
|
|
471
|
-
<RangeInput
|
|
472
|
-
value={this.state.stepTextbox}
|
|
473
|
-
onChange={this.changeStep}
|
|
474
|
-
/>
|
|
475
|
-
</div>
|
|
476
|
-
<div className="perseus-widget-right-col">
|
|
477
|
-
Grid Step
|
|
478
|
-
<RangeInput
|
|
479
|
-
value={this.state.gridStepTextbox}
|
|
480
|
-
onChange={this.changeGridStep}
|
|
481
|
-
/>
|
|
482
|
-
</div>
|
|
483
|
-
</div>
|
|
484
|
-
{_.contains(this.props.editableSettings, "snap") && (
|
|
485
|
-
<div className="perseus-widget-row">
|
|
486
|
-
<div className="perseus-widget-left-col">
|
|
487
|
-
Snap Step
|
|
488
|
-
<RangeInput
|
|
489
|
-
value={this.state.snapStepTextbox}
|
|
490
|
-
onChange={this.changeSnapStep}
|
|
491
|
-
/>
|
|
492
|
-
</div>
|
|
493
|
-
</div>
|
|
494
|
-
)}
|
|
495
|
-
<div className="perseus-widget-row">
|
|
496
|
-
<label>Markings: </label>
|
|
497
|
-
<ButtonGroup
|
|
498
|
-
value={this.props.markings}
|
|
499
|
-
allowEmpty={false}
|
|
500
|
-
buttons={[
|
|
501
|
-
{value: "graph", content: "Graph"},
|
|
502
|
-
{value: "grid", content: "Grid"},
|
|
503
|
-
{value: "none", content: "None"},
|
|
504
|
-
]}
|
|
505
|
-
onChange={this.change("markings")}
|
|
506
|
-
/>
|
|
507
|
-
</div>
|
|
508
|
-
<div className="perseus-widget-left-col">
|
|
509
|
-
<PropCheckBox
|
|
510
|
-
label="Show tooltips"
|
|
511
|
-
showTooltips={this.props.showTooltips}
|
|
512
|
-
onChange={this.change}
|
|
513
|
-
/>
|
|
514
|
-
</div>
|
|
515
|
-
</div>
|
|
516
|
-
)}
|
|
517
|
-
|
|
518
|
-
{_.contains(this.props.editableSettings, "image") && (
|
|
519
|
-
<div className="image-settings">
|
|
520
|
-
<div>Background image:</div>
|
|
521
|
-
<div>
|
|
522
|
-
Url:{" "}
|
|
523
|
-
<input
|
|
524
|
-
type="text"
|
|
525
|
-
className="graph-settings-background-url"
|
|
526
|
-
// eslint-disable-next-line react/no-string-refs
|
|
527
|
-
ref="bg-url"
|
|
528
|
-
value={this.state.backgroundImage.url || ""}
|
|
529
|
-
onChange={(e) => {
|
|
530
|
-
const image = _.clone(
|
|
531
|
-
this.props.backgroundImage,
|
|
532
|
-
);
|
|
533
|
-
image.url = e.target.value;
|
|
534
|
-
this.setState({backgroundImage: image});
|
|
535
|
-
}}
|
|
536
|
-
onKeyPress={this.changeBackgroundUrl}
|
|
537
|
-
onBlur={this.changeBackgroundUrl}
|
|
538
|
-
/>
|
|
539
|
-
<InfoTip>
|
|
540
|
-
<p>
|
|
541
|
-
Create an image in graphie, or use the "Add
|
|
542
|
-
image" function to create a background.
|
|
543
|
-
</p>
|
|
544
|
-
</InfoTip>
|
|
545
|
-
</div>
|
|
546
|
-
</div>
|
|
547
|
-
)}
|
|
548
|
-
|
|
549
|
-
{_.contains(this.props.editableSettings, "measure") && (
|
|
550
|
-
<div className="misc-settings">
|
|
551
|
-
<div className="perseus-widget-row">
|
|
552
|
-
<div className="perseus-widget-left-col">
|
|
553
|
-
<PropCheckBox
|
|
554
|
-
label="Show ruler"
|
|
555
|
-
showRuler={this.props.showRuler}
|
|
556
|
-
onChange={this.change}
|
|
557
|
-
/>
|
|
558
|
-
</div>
|
|
559
|
-
<div className="perseus-widget-right-col">
|
|
560
|
-
<PropCheckBox
|
|
561
|
-
label="Show protractor"
|
|
562
|
-
showProtractor={this.props.showProtractor}
|
|
563
|
-
onChange={this.change}
|
|
564
|
-
/>
|
|
565
|
-
</div>
|
|
566
|
-
</div>
|
|
567
|
-
{this.props.showRuler && (
|
|
568
|
-
<div>
|
|
569
|
-
<div>
|
|
570
|
-
<label>
|
|
571
|
-
{" "}
|
|
572
|
-
Ruler label:{" "}
|
|
573
|
-
<select
|
|
574
|
-
onChange={this.changeRulerLabel}
|
|
575
|
-
value={this.props.rulerLabel}
|
|
576
|
-
>
|
|
577
|
-
<option value="">None</option>
|
|
578
|
-
<optgroup label="Metric">
|
|
579
|
-
{this.renderLabelChoices([
|
|
580
|
-
["milimeters", "mm"],
|
|
581
|
-
["centimeters", "cm"],
|
|
582
|
-
["meters", "m"],
|
|
583
|
-
["kilometers", "km"],
|
|
584
|
-
])}
|
|
585
|
-
</optgroup>
|
|
586
|
-
<optgroup label="Imperial">
|
|
587
|
-
{this.renderLabelChoices([
|
|
588
|
-
["inches", "in"],
|
|
589
|
-
["feet", "ft"],
|
|
590
|
-
["yards", "yd"],
|
|
591
|
-
["miles", "mi"],
|
|
592
|
-
])}
|
|
593
|
-
</optgroup>
|
|
594
|
-
</select>
|
|
595
|
-
</label>
|
|
596
|
-
</div>
|
|
597
|
-
<div>
|
|
598
|
-
<label>
|
|
599
|
-
{" "}
|
|
600
|
-
Ruler ticks:{" "}
|
|
601
|
-
<select
|
|
602
|
-
onChange={this.changeRulerTicks}
|
|
603
|
-
value={this.props.rulerTicks}
|
|
604
|
-
>
|
|
605
|
-
{_.map(
|
|
606
|
-
[1, 2, 4, 8, 10, 16],
|
|
607
|
-
function (n) {
|
|
608
|
-
return (
|
|
609
|
-
<option value={n}>
|
|
610
|
-
{n}
|
|
611
|
-
</option>
|
|
612
|
-
);
|
|
613
|
-
},
|
|
614
|
-
)}
|
|
615
|
-
</select>
|
|
616
|
-
</label>
|
|
617
|
-
</div>
|
|
618
|
-
</div>
|
|
619
|
-
)}
|
|
620
|
-
</div>
|
|
621
|
-
)}
|
|
622
|
-
</div>
|
|
623
|
-
);
|
|
624
|
-
},
|
|
625
|
-
});
|
|
626
|
-
|
|
627
|
-
export default GraphSettings;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
|
|
3
|
-
type GraphTypeSelectorProps = {
|
|
4
|
-
graphType: string;
|
|
5
|
-
onChange: (newGraphType: string) => void;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
const GraphTypeSelector = (props: GraphTypeSelectorProps) => {
|
|
9
|
-
return (
|
|
10
|
-
<select
|
|
11
|
-
value={props.graphType}
|
|
12
|
-
onChange={(e) => {
|
|
13
|
-
const type = e.target.value;
|
|
14
|
-
props.onChange(type);
|
|
15
|
-
}}
|
|
16
|
-
>
|
|
17
|
-
<option value="linear">Linear function</option>
|
|
18
|
-
<option value="quadratic">Quadratic function</option>
|
|
19
|
-
<option value="sinusoid">Sinusoid function</option>
|
|
20
|
-
<option value="circle">Circle</option>
|
|
21
|
-
<option value="point">Point(s)</option>
|
|
22
|
-
<option value="linear-system">Linear System</option>
|
|
23
|
-
<option value="polygon">Polygon</option>
|
|
24
|
-
<option value="segment">Line Segment(s)</option>
|
|
25
|
-
<option value="ray">Ray</option>
|
|
26
|
-
<option value="angle">Angle</option>
|
|
27
|
-
</select>
|
|
28
|
-
);
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export default GraphTypeSelector;
|