@khanacademy/perseus 19.1.5 → 19.1.7
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/components/graph.d.ts +0 -1
- package/dist/components/graphie.d.ts +0 -1
- package/dist/es/index.js +319 -212
- package/dist/es/index.js.map +1 -1
- package/dist/index.js +338 -222
- package/dist/index.js.map +1 -1
- package/dist/interactive2/movable-point.d.ts +195 -1
- package/dist/interactive2/movable.d.ts +1 -1
- package/dist/interactive2/types.d.ts +4 -2
- package/dist/interactive2.d.ts +2 -1
- package/dist/server-item-renderer.d.ts +2 -2
- package/dist/util/graphie.d.ts +12 -2
- package/dist/widgets/expression.d.ts +6 -6
- package/package.json +11 -8
- package/.babelrc.js +0 -8
- package/.eslintrc.js +0 -12
- package/CHANGELOG.md +0 -1432
- package/src/__stories__/article-renderer.stories.tsx +0 -100
- package/src/__stories__/hints-renderer.stories.tsx +0 -55
- package/src/__stories__/server-item-renderer.stories.tsx +0 -44
- package/src/__testdata__/article-renderer.testdata.ts +0 -212
- package/src/__testdata__/graphie.testdata.ts +0 -51
- package/src/__testdata__/renderer.testdata.ts +0 -274
- package/src/__testdata__/server-item-renderer.testdata.ts +0 -171
- package/src/__tests__/__snapshots__/perseus-markdown.test.ts.snap +0 -507
- package/src/__tests__/__snapshots__/renderer.test.tsx.snap +0 -525
- package/src/__tests__/__snapshots__/server-item-renderer.test.tsx.snap +0 -285
- package/src/__tests__/a11y.test.ts +0 -303
- package/src/__tests__/article-renderer.test.tsx +0 -130
- package/src/__tests__/error-boundary.test.tsx +0 -76
- package/src/__tests__/extract-perseus-data.test.ts +0 -1027
- package/src/__tests__/init.test.ts +0 -10
- package/src/__tests__/jipt-paragraphs.test.ts +0 -32
- package/src/__tests__/mock-asset-loading-widget.tsx +0 -53
- package/src/__tests__/mock-widget.tsx +0 -33
- package/src/__tests__/perseus-markdown.test.ts +0 -764
- package/src/__tests__/renderability.test.ts +0 -480
- package/src/__tests__/renderer-api.test.tsx +0 -302
- package/src/__tests__/renderer.test.tsx +0 -1816
- package/src/__tests__/server-item-renderer.test.tsx +0 -582
- package/src/__tests__/test-items/image-item.ts +0 -24
- package/src/__tests__/test-items/input-number-1-item.ts +0 -26
- package/src/__tests__/test-items/input-number-2-item.ts +0 -38
- package/src/__tests__/test-items/table-item.ts +0 -29
- package/src/__tests__/tex-wrangler.test.ts +0 -82
- package/src/__tests__/util.test.ts +0 -40
- package/src/__tests__/widget-container.test.tsx +0 -126
- package/src/__tests__/widgets.test.ts +0 -91
- package/src/a11y.ts +0 -45
- package/src/all-widgets.ts +0 -9
- package/src/article-renderer.tsx +0 -237
- package/src/asset-context.ts +0 -30
- package/src/basic-widgets.ts +0 -16
- package/src/components/__stories__/button-group.stories.tsx +0 -55
- package/src/components/__stories__/fixed-to-responsive.stories.tsx +0 -141
- package/src/components/__stories__/graph.stories.tsx +0 -28
- package/src/components/__stories__/graphie.stories.tsx +0 -33
- package/src/components/__stories__/hud.stories.tsx +0 -35
- package/src/components/__stories__/icon.stories.tsx +0 -63
- package/src/components/__stories__/image-loader.stories.tsx +0 -63
- package/src/components/__stories__/info-tip.stories.tsx +0 -31
- package/src/components/__stories__/inline-icon.stories.tsx +0 -40
- package/src/components/__stories__/input-with-examples.stories.tsx +0 -53
- package/src/components/__stories__/lint.stories.tsx +0 -86
- package/src/components/__stories__/math-input.stories.tsx +0 -43
- package/src/components/__stories__/math-output.stories.tsx +0 -23
- package/src/components/__stories__/multi-button-group.stories.tsx +0 -66
- package/src/components/__stories__/number-input.stories.tsx +0 -41
- package/src/components/__stories__/prop-check-box.stories.tsx +0 -65
- package/src/components/__stories__/range-input.stories.tsx +0 -29
- package/src/components/__stories__/simple-keypad-input.stories.tsx +0 -27
- package/src/components/__stories__/sortable.stories.tsx +0 -77
- package/src/components/__stories__/stub-tag-editor.stories.tsx +0 -45
- package/src/components/__stories__/svg-image.stories.tsx +0 -74
- package/src/components/__stories__/tex.stories.tsx +0 -23
- package/src/components/__stories__/text-input.stories.tsx +0 -33
- package/src/components/__stories__/text-list-editor.stories.tsx +0 -32
- package/src/components/__stories__/tooltip.stories.tsx +0 -52
- package/src/components/__stories__/zoomable-tex.stories.tsx +0 -41
- package/src/components/__stories__/zoomable.stories.tsx +0 -49
- package/src/components/__testdata__/sorter.testdata.ts +0 -19
- package/src/components/__tests__/__snapshots__/sortable.test.tsx.snap +0 -163
- package/src/components/__tests__/__snapshots__/sorter.test.tsx.snap +0 -265
- package/src/components/__tests__/math-input.test.tsx +0 -147
- package/src/components/__tests__/number-input.test.tsx +0 -128
- package/src/components/__tests__/sortable.test.tsx +0 -269
- package/src/components/__tests__/sorter.test.tsx +0 -114
- package/src/components/__tests__/zoomable.test.tsx +0 -399
- package/src/components/button-group.tsx +0 -130
- package/src/components/constants.ts +0 -14
- package/src/components/fixed-to-responsive.tsx +0 -169
- package/src/components/graph.tsx +0 -444
- package/src/components/graphie-classes.ts +0 -153
- package/src/components/graphie-movables.ts +0 -338
- package/src/components/graphie.tsx +0 -400
- package/src/components/highlighting/highlightable-content.tsx +0 -240
- package/src/components/highlighting/highlights.ts +0 -207
- package/src/components/highlighting/ranges.ts +0 -304
- package/src/components/highlighting/types.ts +0 -73
- package/src/components/highlighting/ui/highlight-renderer.tsx +0 -172
- package/src/components/highlighting/ui/highlight-set-renderer.tsx +0 -185
- package/src/components/highlighting/ui/highlight-tooltip.tsx +0 -141
- package/src/components/highlighting/ui/highlighting-ui.tsx +0 -143
- package/src/components/highlighting/ui/selection-tracker.tsx +0 -186
- package/src/components/highlighting/ui/types.ts +0 -21
- package/src/components/highlighting/ui/util.ts +0 -165
- package/src/components/highlighting/word-indexer.tsx +0 -152
- package/src/components/hud.tsx +0 -167
- package/src/components/icon.tsx +0 -141
- package/src/components/image-loader.tsx +0 -177
- package/src/components/info-tip/info-tip.tsx +0 -144
- package/src/components/info-tip.tsx +0 -39
- package/src/components/inline-icon.tsx +0 -60
- package/src/components/input-with-examples.tsx +0 -249
- package/src/components/lint.tsx +0 -459
- package/src/components/math-input.tsx +0 -474
- package/src/components/math-output.tsx +0 -134
- package/src/components/multi-button-group.tsx +0 -135
- package/src/components/number-input.tsx +0 -249
- package/src/components/prop-check-box.tsx +0 -79
- package/src/components/range-input.tsx +0 -60
- package/src/components/simple-keypad-input.tsx +0 -88
- package/src/components/sortable.tsx +0 -958
- package/src/components/stub-tag-editor.tsx +0 -53
- package/src/components/svg-image.tsx +0 -779
- package/src/components/tex.tsx +0 -67
- package/src/components/text-input.tsx +0 -129
- package/src/components/text-list-editor.tsx +0 -166
- package/src/components/tooltip.tsx +0 -410
- package/src/components/visibility-observer/__stories__/visibility-observer.stories.tsx +0 -141
- package/src/components/visibility-observer/create-visibility-observer.ts +0 -108
- package/src/components/visibility-observer/get-scroll-parent.ts +0 -46
- package/src/components/visibility-observer/visibility-observer.tsx +0 -124
- package/src/components/zoomable-tex.tsx +0 -78
- package/src/components/zoomable.tsx +0 -304
- package/src/components.ts +0 -15
- package/src/definition-context.tsx +0 -59
- package/src/dependencies.ts +0 -40
- package/src/error-boundary.tsx +0 -70
- package/src/extra-widgets.ts +0 -75
- package/src/hint-renderer.tsx +0 -151
- package/src/hints-renderer.tsx +0 -372
- package/src/icon-paths.ts +0 -119
- package/src/index.ts +0 -171
- package/src/init.ts +0 -56
- package/src/interaction-tracker.ts +0 -62
- package/src/interactive2/__tests__/movable-mock.ts +0 -55
- package/src/interactive2/__tests__/movable-point.test.ts +0 -144
- package/src/interactive2/interactive-util.test.ts +0 -93
- package/src/interactive2/interactive-util.ts +0 -159
- package/src/interactive2/movable-helper-methods.ts +0 -166
- package/src/interactive2/movable-line-options.ts +0 -419
- package/src/interactive2/movable-line.ts +0 -307
- package/src/interactive2/movable-point-options.ts +0 -224
- package/src/interactive2/movable-point.tsx +0 -585
- package/src/interactive2/movable-polygon-options.ts +0 -389
- package/src/interactive2/movable-polygon.ts +0 -360
- package/src/interactive2/movable.test.ts +0 -249
- package/src/interactive2/movable.ts +0 -437
- package/src/interactive2/objective_.ts +0 -79
- package/src/interactive2/types.ts +0 -17
- package/src/interactive2/wrapped-defaults.ts +0 -87
- package/src/interactive2/wrapped-ellipse.ts +0 -94
- package/src/interactive2/wrapped-line.ts +0 -116
- package/src/interactive2/wrapped-path.ts +0 -51
- package/src/interactive2.ts +0 -70
- package/src/item-version.ts +0 -10
- package/src/jipt-paragraphs.ts +0 -49
- package/src/jquery.mobile.vmouse.js +0 -545
- package/src/loading-context.ts +0 -21
- package/src/logging/log.test.ts +0 -39
- package/src/logging/log.ts +0 -97
- package/src/mixins/__tests__/widget-prop-denylist.test.ts +0 -21
- package/src/mixins/changeable.ts +0 -133
- package/src/mixins/editor-jsonify.ts +0 -13
- package/src/mixins/widget-jsonify-deprecated.ts +0 -23
- package/src/mixins/widget-prop-denylist.ts +0 -48
- package/src/multi-items/__stories__/multi-renderer.stories.tsx +0 -83
- package/src/multi-items/__testdata__/multi-renderer.testdata.ts +0 -172
- package/src/multi-items/__tests__/__snapshots__/multi-renderer.test.tsx.snap +0 -1164
- package/src/multi-items/__tests__/items.test.ts +0 -240
- package/src/multi-items/__tests__/multi-renderer.test.tsx +0 -914
- package/src/multi-items/__tests__/prop-type-builders.test.ts +0 -133
- package/src/multi-items/__tests__/shapes.test.ts +0 -43
- package/src/multi-items/__tests__/trees.test.ts +0 -317
- package/src/multi-items/item-types.ts +0 -56
- package/src/multi-items/items.ts +0 -176
- package/src/multi-items/multi-renderer.tsx +0 -569
- package/src/multi-items/prop-type-builders.ts +0 -106
- package/src/multi-items/shape-types.ts +0 -52
- package/src/multi-items/shapes.ts +0 -52
- package/src/multi-items/tree-types.ts +0 -47
- package/src/multi-items/trees.ts +0 -360
- package/src/multi-items.ts +0 -75
- package/src/perseus-api.tsx +0 -188
- package/src/perseus-env.ts +0 -27
- package/src/perseus-error.ts +0 -17
- package/src/perseus-markdown.tsx +0 -405
- package/src/perseus-types.ts +0 -1366
- package/src/perseus-version.ts +0 -9
- package/src/question-paragraph.tsx +0 -34
- package/src/renderability.ts +0 -109
- package/src/renderer.tsx +0 -2000
- package/src/server-item-renderer.tsx +0 -495
- package/src/sigfigs.ts +0 -490
- package/src/styles/articles.less +0 -749
- package/src/styles/constants.ts +0 -94
- package/src/styles/global-constants.ts +0 -343
- package/src/styles/global-styles.ts +0 -306
- package/src/styles/khan-exercise.css +0 -1468
- package/src/styles/media-queries.ts +0 -47
- package/src/styles/perseus-renderer.less +0 -732
- package/src/styles/shared.ts +0 -130
- package/src/styles/util.less +0 -47
- package/src/styles/variables.boostrap.less +0 -277
- package/src/styles/variables.less +0 -56
- package/src/styles/variables.shared.less +0 -340
- package/src/styles/widgets/categorizer.less +0 -38
- package/src/styles/widgets/dropdown.less +0 -3
- package/src/styles/widgets/expression.less +0 -65
- package/src/styles/widgets/graded-group.less +0 -36
- package/src/styles/widgets/grapher.less +0 -12
- package/src/styles/widgets/group.less +0 -19
- package/src/styles/widgets/image.less +0 -54
- package/src/styles/widgets/interactive-graph.less +0 -64
- package/src/styles/widgets/label-image.less +0 -57
- package/src/styles/widgets/matcher.less +0 -8
- package/src/styles/widgets/matrix.less +0 -126
- package/src/styles/widgets/measurer.less +0 -20
- package/src/styles/widgets/orderer.less +0 -98
- package/src/styles/widgets/passage.less +0 -154
- package/src/styles/widgets/plotter.less +0 -31
- package/src/styles/widgets/radio.less +0 -58
- package/src/styles/widgets/reaction-diagram.less +0 -35
- package/src/styles/widgets/sequence.less +0 -5
- package/src/styles/widgets/sortable.less +0 -113
- package/src/styles/widgets/table.less +0 -57
- package/src/styles/widgets/unit.less +0 -15
- package/src/tex-wrangler.ts +0 -182
- package/src/translation-linter.ts +0 -126
- package/src/traversal.ts +0 -138
- package/src/types.ts +0 -513
- package/src/util/a11y.ts +0 -23
- package/src/util/answer-types.test.ts +0 -114
- package/src/util/answer-types.ts +0 -876
- package/src/util/colors.ts +0 -93
- package/src/util/drawing-transform.test.ts +0 -67
- package/src/util/drawing-transform.ts +0 -102
- package/src/util/extract-perseus-data.ts +0 -539
- package/src/util/fix-passage-refs.ts +0 -121
- package/src/util/geometry.test.ts +0 -75
- package/src/util/geometry.ts +0 -312
- package/src/util/graph-bounds.ts +0 -23
- package/src/util/graph-utils.ts +0 -15
- package/src/util/graphie.test.ts +0 -1277
- package/src/util/graphie.ts +0 -1576
- package/src/util/interactive.ts +0 -4174
- package/src/util/interval.ts +0 -4
- package/src/util/katex-preprocess.ts +0 -14
- package/src/util/math.test.ts +0 -11
- package/src/util/math.ts +0 -294
- package/src/util/mobile-native-utils.test.ts +0 -22
- package/src/util/mobile-native-utils.ts +0 -12
- package/src/util/parse-perseus-json.test.ts +0 -10
- package/src/util/parse-perseus-json.ts +0 -13
- package/src/util/react-render.tsx +0 -27
- package/src/util/register-all-widgets-for-testing.ts +0 -13
- package/src/util/scroll-utils.ts +0 -155
- package/src/util/sizing-utils.ts +0 -46
- package/src/util/tex.ts +0 -73
- package/src/util/url-utils.ts +0 -34
- package/src/util.graphie.test.ts +0 -45
- package/src/util.graphie.ts +0 -59
- package/src/util.ts +0 -966
- package/src/version.ts +0 -10
- package/src/widget-container.tsx +0 -199
- package/src/widgets/__stories__/categorizer.stories.tsx +0 -14
- package/src/widgets/__stories__/cs-program.stories.tsx +0 -14
- package/src/widgets/__stories__/definition.stories.tsx +0 -114
- package/src/widgets/__stories__/dropdown.stories.tsx +0 -14
- package/src/widgets/__stories__/explanation.stories.tsx +0 -18
- package/src/widgets/__stories__/expression.stories.tsx +0 -145
- package/src/widgets/__stories__/graded-group-set.stories.tsx +0 -31
- package/src/widgets/__stories__/graded-group.stories.tsx +0 -31
- package/src/widgets/__stories__/grapher.stories.tsx +0 -46
- package/src/widgets/__stories__/group.stories.tsx +0 -14
- package/src/widgets/__stories__/iframe.stories.tsx +0 -14
- package/src/widgets/__stories__/image.stories.tsx +0 -85
- package/src/widgets/__stories__/input-number.stories.tsx +0 -101
- package/src/widgets/__stories__/interaction.stories.tsx +0 -14
- package/src/widgets/__stories__/interactive-graph.stories.tsx +0 -60
- package/src/widgets/__stories__/label-image.stories.tsx +0 -130
- package/src/widgets/__stories__/matcher.stories.tsx +0 -14
- package/src/widgets/__stories__/matrix.stories.tsx +0 -14
- package/src/widgets/__stories__/number-line.stories.tsx +0 -14
- package/src/widgets/__stories__/numeric-input.stories.tsx +0 -105
- package/src/widgets/__stories__/orderer.stories.tsx +0 -18
- package/src/widgets/__stories__/passage-ref.stories.tsx +0 -33
- package/src/widgets/__stories__/passage.stories.tsx +0 -39
- package/src/widgets/__stories__/plotter.stories.tsx +0 -27
- package/src/widgets/__stories__/radio.stories.tsx +0 -86
- package/src/widgets/__stories__/random-widgets.stories.tsx +0 -59
- package/src/widgets/__stories__/sorter.stories.tsx +0 -14
- package/src/widgets/__stories__/test-keypad-context-wrapper.tsx +0 -66
- package/src/widgets/__stories__/unit.stories.tsx +0 -28
- package/src/widgets/__stories__/video-transcript-link.stories.tsx +0 -23
- package/src/widgets/__stories__/video.stories.tsx +0 -22
- package/src/widgets/__testdata__/base-radio.testdata.ts +0 -21
- package/src/widgets/__testdata__/categorizer.testdata.ts +0 -89
- package/src/widgets/__testdata__/cs-program.testdata.ts +0 -27
- package/src/widgets/__testdata__/dropdown.testdata.ts +0 -71
- package/src/widgets/__testdata__/explanation.testdata.ts +0 -85
- package/src/widgets/__testdata__/expression.testdata.ts +0 -198
- package/src/widgets/__testdata__/graded-group-set.testdata.ts +0 -356
- package/src/widgets/__testdata__/graded-group.testdata.ts +0 -77
- package/src/widgets/__testdata__/grapher.testdata.ts +0 -374
- package/src/widgets/__testdata__/group.testdata.ts +0 -153
- package/src/widgets/__testdata__/iframe.testdata.ts +0 -35
- package/src/widgets/__testdata__/image.testdata.ts +0 -36
- package/src/widgets/__testdata__/input-number.testdata.ts +0 -72
- package/src/widgets/__testdata__/interaction.testdata.ts +0 -262
- package/src/widgets/__testdata__/interactive-graph-random.testdata.ts +0 -269
- package/src/widgets/__testdata__/interactive-graph.testdata.ts +0 -644
- package/src/widgets/__testdata__/label-image.testdata.ts +0 -308
- package/src/widgets/__testdata__/matcher.testdata.ts +0 -33
- package/src/widgets/__testdata__/matrix.testdata.ts +0 -28
- package/src/widgets/__testdata__/number-line.testdata.ts +0 -30
- package/src/widgets/__testdata__/numeric-input.testdata.ts +0 -265
- package/src/widgets/__testdata__/orderer.testdata.ts +0 -123
- package/src/widgets/__testdata__/passage-ref.testdata.ts +0 -101
- package/src/widgets/__testdata__/passage.testdata.ts +0 -95
- package/src/widgets/__testdata__/plotter.testdata.ts +0 -36
- package/src/widgets/__testdata__/radio.testdata.ts +0 -324
- package/src/widgets/__testdata__/randomizers.ts +0 -51
- package/src/widgets/__testdata__/sorter.testdata.ts +0 -19
- package/src/widgets/__testdata__/video.testdata.ts +0 -61
- package/src/widgets/__tests__/__snapshots__/categorizer.test.ts.snap +0 -940
- package/src/widgets/__tests__/__snapshots__/cs-program.test.ts.snap +0 -67
- package/src/widgets/__tests__/__snapshots__/definition.test.ts.snap +0 -97
- package/src/widgets/__tests__/__snapshots__/dropdown.test.ts.snap +0 -133
- package/src/widgets/__tests__/__snapshots__/explanation.test.ts.snap +0 -425
- package/src/widgets/__tests__/__snapshots__/graded-group-set-jipt.test.ts.snap +0 -729
- package/src/widgets/__tests__/__snapshots__/graded-group-set.test.ts.snap +0 -339
- package/src/widgets/__tests__/__snapshots__/graded-group.test.ts.snap +0 -801
- package/src/widgets/__tests__/__snapshots__/grapher.test.ts.snap +0 -2673
- package/src/widgets/__tests__/__snapshots__/group.test.tsx.snap +0 -1211
- package/src/widgets/__tests__/__snapshots__/iframe.test.ts.snap +0 -61
- package/src/widgets/__tests__/__snapshots__/image.test.ts.snap +0 -378
- package/src/widgets/__tests__/__snapshots__/input-number.test.ts.snap +0 -495
- package/src/widgets/__tests__/__snapshots__/interaction.test.ts.snap +0 -292
- package/src/widgets/__tests__/__snapshots__/interactive-graph.test.ts.snap +0 -2889
- package/src/widgets/__tests__/__snapshots__/matcher.test.tsx.snap +0 -883
- package/src/widgets/__tests__/__snapshots__/matrix.test.ts.snap +0 -514
- package/src/widgets/__tests__/__snapshots__/number-line.test.ts.snap +0 -814
- package/src/widgets/__tests__/__snapshots__/numeric-input.test.ts.snap +0 -470
- package/src/widgets/__tests__/__snapshots__/orderer.test.ts.snap +0 -243
- package/src/widgets/__tests__/__snapshots__/passage-ref.test.ts.snap +0 -434
- package/src/widgets/__tests__/__snapshots__/passage.test.tsx.snap +0 -1956
- package/src/widgets/__tests__/__snapshots__/plotter.test.tsx.snap +0 -827
- package/src/widgets/__tests__/__snapshots__/radio.test.ts.snap +0 -4237
- package/src/widgets/__tests__/__snapshots__/unit.test.tsx.snap +0 -20
- package/src/widgets/__tests__/__snapshots__/video.test.ts.snap +0 -153
- package/src/widgets/__tests__/categorizer.test.ts +0 -203
- package/src/widgets/__tests__/cs-program.test.ts +0 -43
- package/src/widgets/__tests__/definition.test.ts +0 -136
- package/src/widgets/__tests__/dropdown.test.ts +0 -105
- package/src/widgets/__tests__/explanation.test.ts +0 -198
- package/src/widgets/__tests__/expression-mobile.test.tsx +0 -363
- package/src/widgets/__tests__/expression.test.tsx +0 -484
- package/src/widgets/__tests__/graded-group-set-jipt.test.ts +0 -30
- package/src/widgets/__tests__/graded-group-set.test.ts +0 -288
- package/src/widgets/__tests__/graded-group.test.ts +0 -232
- package/src/widgets/__tests__/grapher.cypress.ts +0 -576
- package/src/widgets/__tests__/grapher.test.ts +0 -33
- package/src/widgets/__tests__/group.test.tsx +0 -510
- package/src/widgets/__tests__/iframe.test.ts +0 -45
- package/src/widgets/__tests__/image.test.ts +0 -62
- package/src/widgets/__tests__/input-number.test.ts +0 -354
- package/src/widgets/__tests__/interaction.test.ts +0 -31
- package/src/widgets/__tests__/interactive-graph.cypress.ts +0 -815
- package/src/widgets/__tests__/interactive-graph.test.ts +0 -106
- package/src/widgets/__tests__/matcher.test.tsx +0 -176
- package/src/widgets/__tests__/matrix.test.ts +0 -82
- package/src/widgets/__tests__/number-line.test.ts +0 -79
- package/src/widgets/__tests__/numeric-input.test.ts +0 -575
- package/src/widgets/__tests__/orderer.test.ts +0 -73
- package/src/widgets/__tests__/passage-ref.test.ts +0 -168
- package/src/widgets/__tests__/passage.test.tsx +0 -224
- package/src/widgets/__tests__/plotter.test.tsx +0 -69
- package/src/widgets/__tests__/radio/base-radio.test.tsx +0 -470
- package/src/widgets/__tests__/radio/choice-icon.test.tsx +0 -90
- package/src/widgets/__tests__/radio/choice.test.tsx +0 -310
- package/src/widgets/__tests__/radio/focus-ring.test.tsx +0 -22
- package/src/widgets/__tests__/radio/option-status.test.tsx +0 -77
- package/src/widgets/__tests__/radio.test.ts +0 -807
- package/src/widgets/__tests__/randomizers.test.ts +0 -53
- package/src/widgets/__tests__/renderQuestion.tsx +0 -101
- package/src/widgets/__tests__/unit.test.tsx +0 -168
- package/src/widgets/__tests__/video.test.ts +0 -69
- package/src/widgets/categorizer.tsx +0 -344
- package/src/widgets/cs-program.tsx +0 -227
- package/src/widgets/definition.tsx +0 -121
- package/src/widgets/deprecated-standin/__stories__/deprecated-standin.stories.tsx +0 -30
- package/src/widgets/deprecated-standin/__tests__/__snapshots__/deprecated-standin.test.ts.snap +0 -70
- package/src/widgets/deprecated-standin/__tests__/deprecated-standin.test.ts +0 -93
- package/src/widgets/deprecated-standin/index.tsx +0 -58
- package/src/widgets/dropdown.tsx +0 -142
- package/src/widgets/explanation.tsx +0 -317
- package/src/widgets/expression.tsx +0 -707
- package/src/widgets/graded-group-answer-bar.tsx +0 -142
- package/src/widgets/graded-group-set.tsx +0 -338
- package/src/widgets/graded-group.tsx +0 -471
- package/src/widgets/grapher/util.tsx +0 -799
- package/src/widgets/grapher.tsx +0 -660
- package/src/widgets/group.tsx +0 -195
- package/src/widgets/iframe.tsx +0 -195
- package/src/widgets/image.tsx +0 -312
- package/src/widgets/input-number.tsx +0 -412
- package/src/widgets/interaction/arrow-picker.tsx +0 -38
- package/src/widgets/interaction/color-picker.tsx +0 -69
- package/src/widgets/interaction/dash-picker.tsx +0 -45
- package/src/widgets/interaction/element-container.tsx +0 -100
- package/src/widgets/interaction.tsx +0 -826
- package/src/widgets/interactive-graph.tsx +0 -2597
- package/src/widgets/label-image/__stories__/answer-choices.stories.tsx +0 -91
- package/src/widgets/label-image/__stories__/answer-pill.stories.tsx +0 -62
- package/src/widgets/label-image/__stories__/marker.stories.tsx +0 -171
- package/src/widgets/label-image/__tests__/answer-pill.test.tsx +0 -75
- package/src/widgets/label-image/__tests__/hide-answers-toggle.test.tsx +0 -39
- package/src/widgets/label-image/answer-choices.tsx +0 -88
- package/src/widgets/label-image/answer-pill.tsx +0 -103
- package/src/widgets/label-image/hide-answers-toggle.tsx +0 -40
- package/src/widgets/label-image/marker.tsx +0 -268
- package/src/widgets/label-image/strings.ts +0 -5
- package/src/widgets/label-image/types.ts +0 -27
- package/src/widgets/label-image.test.ts +0 -928
- package/src/widgets/label-image.tsx +0 -819
- package/src/widgets/lights-puzzle.tsx +0 -359
- package/src/widgets/matcher.tsx +0 -298
- package/src/widgets/matrix.tsx +0 -634
- package/src/widgets/measurer.tsx +0 -222
- package/src/widgets/molecule/__tests__/layout.test.ts +0 -162
- package/src/widgets/molecule/__tests__/parser.test.ts +0 -155
- package/src/widgets/molecule/molecule-drawing.ts +0 -173
- package/src/widgets/molecule/molecule-layout.ts +0 -362
- package/src/widgets/molecule/smiles-parser.ts +0 -296
- package/src/widgets/molecule.tsx +0 -172
- package/src/widgets/number-line.tsx +0 -862
- package/src/widgets/numeric-input.tsx +0 -576
- package/src/widgets/orderer.tsx +0 -786
- package/src/widgets/passage/__tests__/passage-markdown.test.ts +0 -376
- package/src/widgets/passage/passage-markdown.tsx +0 -475
- package/src/widgets/passage-ref-target.tsx +0 -76
- package/src/widgets/passage-ref.tsx +0 -213
- package/src/widgets/passage.tsx +0 -582
- package/src/widgets/plotter.tsx +0 -1194
- package/src/widgets/radio/__stories__/base-radio.stories.tsx +0 -196
- package/src/widgets/radio/__stories__/choice-icon.stories.tsx +0 -166
- package/src/widgets/radio/__stories__/choice-none-above.stories.tsx +0 -40
- package/src/widgets/radio/__stories__/choice.stories.tsx +0 -137
- package/src/widgets/radio/__stories__/focus-ring.stories.tsx +0 -43
- package/src/widgets/radio/__stories__/option-status.stories.tsx +0 -103
- package/src/widgets/radio/base-radio.tsx +0 -511
- package/src/widgets/radio/choice-a11y-text.ts +0 -61
- package/src/widgets/radio/choice-icon/choice-icon.tsx +0 -218
- package/src/widgets/radio/choice-icon/cross-out-line.tsx +0 -51
- package/src/widgets/radio/choice-icon/shared-styles.ts +0 -15
- package/src/widgets/radio/choice-none-above.tsx +0 -56
- package/src/widgets/radio/choice.jsx.fixture.ts +0 -45
- package/src/widgets/radio/choice.tsx +0 -359
- package/src/widgets/radio/focus-ring.tsx +0 -57
- package/src/widgets/radio/option-status.tsx +0 -98
- package/src/widgets/radio/util.test.ts +0 -18
- package/src/widgets/radio/util.ts +0 -31
- package/src/widgets/radio/widget.tsx +0 -520
- package/src/widgets/radio.ts +0 -157
- package/src/widgets/reaction-diagram.tsx +0 -144
- package/src/widgets/sequence.tsx +0 -142
- package/src/widgets/simulator.tsx +0 -829
- package/src/widgets/sorter.tsx +0 -155
- package/src/widgets/table.tsx +0 -393
- package/src/widgets/unit.tsx +0 -374
- package/src/widgets/video-transcript-link.test.tsx +0 -213
- package/src/widgets/video-transcript-link.tsx +0 -84
- package/src/widgets/video.tsx +0 -135
- package/src/widgets.ts +0 -489
- package/src/zoom.ts +0 -555
- package/tsconfig-build.json +0 -26
- package/tsconfig-build.tsbuildinfo +0 -1
package/src/widgets/plotter.tsx
DELETED
|
@@ -1,1194 +0,0 @@
|
|
|
1
|
-
/* eslint-disable react/no-unsafe */
|
|
2
|
-
import * as i18n from "@khanacademy/wonder-blocks-i18n";
|
|
3
|
-
import $ from "jquery";
|
|
4
|
-
import * as React from "react";
|
|
5
|
-
import ReactDOM from "react-dom";
|
|
6
|
-
import _ from "underscore";
|
|
7
|
-
|
|
8
|
-
import Interactive2 from "../interactive2";
|
|
9
|
-
import WrappedLine from "../interactive2/wrapped-line";
|
|
10
|
-
import {ClassNames as ApiClassNames} from "../perseus-api";
|
|
11
|
-
import Util from "../util";
|
|
12
|
-
import KhanColors from "../util/colors";
|
|
13
|
-
import GraphUtils from "../util/graph-utils";
|
|
14
|
-
import KhanMath from "../util/math";
|
|
15
|
-
|
|
16
|
-
import type {PerseusPlotterWidgetOptions} from "../perseus-types";
|
|
17
|
-
import type {WidgetExports, WidgetProps} from "../types";
|
|
18
|
-
|
|
19
|
-
const {deepEq} = Util;
|
|
20
|
-
|
|
21
|
-
type Rubric = PerseusPlotterWidgetOptions;
|
|
22
|
-
type RenderProps = PerseusPlotterWidgetOptions;
|
|
23
|
-
|
|
24
|
-
type Props = WidgetProps<RenderProps, Rubric> & {
|
|
25
|
-
labelInterval: NonNullable<PerseusPlotterWidgetOptions["labelInterval"]>;
|
|
26
|
-
picSize: NonNullable<PerseusPlotterWidgetOptions["picSize"]>;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
type DefaultProps = {
|
|
30
|
-
type: Props["type"];
|
|
31
|
-
labels: Props["labels"];
|
|
32
|
-
categories: Props["categories"];
|
|
33
|
-
scaleY: Props["scaleY"];
|
|
34
|
-
maxY: Props["maxY"];
|
|
35
|
-
snapsPerLine: Props["snapsPerLine"];
|
|
36
|
-
picSize: Props["picSize"];
|
|
37
|
-
picBoxHeight: Props["picBoxHeight"];
|
|
38
|
-
picUrl: Props["picUrl"];
|
|
39
|
-
plotDimensions: Props["plotDimensions"];
|
|
40
|
-
labelInterval: Props["labelInterval"];
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
type State = {
|
|
44
|
-
values: ReadonlyArray<number>;
|
|
45
|
-
categoryHeights: Record<string, number>;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
export class Plotter extends React.Component<Props, State> {
|
|
49
|
-
// @ts-expect-error - TS2564 - Property 'shouldSetupGraphie' has no initializer and is not definitely assigned in the constructor.
|
|
50
|
-
shouldSetupGraphie: boolean;
|
|
51
|
-
_isMounted = false;
|
|
52
|
-
horizHairline: any;
|
|
53
|
-
hairlineRange: any;
|
|
54
|
-
graphie: any;
|
|
55
|
-
|
|
56
|
-
static defaultProps: DefaultProps = {
|
|
57
|
-
type: "bar",
|
|
58
|
-
labels: ["", ""],
|
|
59
|
-
categories: [""],
|
|
60
|
-
|
|
61
|
-
scaleY: 1,
|
|
62
|
-
maxY: 10,
|
|
63
|
-
snapsPerLine: 2,
|
|
64
|
-
|
|
65
|
-
picSize: 40,
|
|
66
|
-
picBoxHeight: 48,
|
|
67
|
-
picUrl: "",
|
|
68
|
-
|
|
69
|
-
plotDimensions: [380, 300],
|
|
70
|
-
labelInterval: 1,
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
state: State = {
|
|
74
|
-
values: this.props.starting || [1],
|
|
75
|
-
|
|
76
|
-
// The measured rendered height of category strings. Used to calculate
|
|
77
|
-
// bottom padding of plot, to prevent categories from overlapping the
|
|
78
|
-
// bottom label.
|
|
79
|
-
categoryHeights: {},
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
componentDidMount() {
|
|
83
|
-
this._isMounted = true;
|
|
84
|
-
|
|
85
|
-
this.setupGraphie(this.state);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
UNSAFE_componentWillReceiveProps(nextProps: Props) {
|
|
89
|
-
const props = [
|
|
90
|
-
"type",
|
|
91
|
-
"labels",
|
|
92
|
-
"categories",
|
|
93
|
-
"scaleY",
|
|
94
|
-
"maxY",
|
|
95
|
-
"snapsPerLine",
|
|
96
|
-
"picUrl",
|
|
97
|
-
"labelInterval",
|
|
98
|
-
"static",
|
|
99
|
-
];
|
|
100
|
-
|
|
101
|
-
this.shouldSetupGraphie = _.any(
|
|
102
|
-
props,
|
|
103
|
-
(prop) => !_.isEqual(this.props[prop], nextProps[prop]),
|
|
104
|
-
this,
|
|
105
|
-
);
|
|
106
|
-
|
|
107
|
-
if (
|
|
108
|
-
!_.isEqual(this.props.starting, nextProps.starting) &&
|
|
109
|
-
!_.isEqual(this.state.values, nextProps.starting)
|
|
110
|
-
) {
|
|
111
|
-
this.shouldSetupGraphie = true;
|
|
112
|
-
this.setState({values: nextProps.starting});
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
componentDidUpdate(prevProps: Props, prevState: State) {
|
|
117
|
-
this.shouldSetupGraphie =
|
|
118
|
-
this.shouldSetupGraphie ||
|
|
119
|
-
!_.isEqual(this.state.categoryHeights, prevState.categoryHeights);
|
|
120
|
-
|
|
121
|
-
if (this.shouldSetupGraphie) {
|
|
122
|
-
this.setupGraphie(prevState);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
componentWillUnmount() {
|
|
127
|
-
this._isMounted = false;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
DOT_PLOT_POINT_SIZE: () => number = () => {
|
|
131
|
-
return this.props.apiOptions.isMobile ? 6 : 4;
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
DOT_PLOT_POINT_PADDING: () => number = () => {
|
|
135
|
-
return 8;
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
DOT_TICK_POINT_SIZE: () => number = () => {
|
|
139
|
-
return 2;
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
setupGraphie: (arg1: any) => void = (prevState) => {
|
|
143
|
-
const self = this;
|
|
144
|
-
self.shouldSetupGraphie = false;
|
|
145
|
-
const graphieDiv = ReactDOM.findDOMNode(self.refs.graphieDiv);
|
|
146
|
-
// @ts-expect-error - TS2769 - No overload matches this call. | TS2339 - Property 'empty' does not exist on type 'JQueryStatic'.
|
|
147
|
-
$(graphieDiv).empty();
|
|
148
|
-
// @ts-expect-error - Argument of type 'Element | Text | null' is not assignable to parameter of type 'HTMLElement'.
|
|
149
|
-
const graphie = GraphUtils.createGraphie(graphieDiv);
|
|
150
|
-
|
|
151
|
-
// TODO(jakesandlund): It's not the react way to hang
|
|
152
|
-
// something off the component object, but since graphie
|
|
153
|
-
// is outside React, it makes it easier to do this.
|
|
154
|
-
self.graphie = graphie;
|
|
155
|
-
self.graphie.pics = [];
|
|
156
|
-
self.graphie.dotTicks = [];
|
|
157
|
-
|
|
158
|
-
const isBar = self.props.type === "bar";
|
|
159
|
-
const isLine = self.props.type === "line";
|
|
160
|
-
const isPic = self.props.type === "pic";
|
|
161
|
-
const isHistogram = self.props.type === "histogram";
|
|
162
|
-
const isDotplot = self.props.type === "dotplot";
|
|
163
|
-
|
|
164
|
-
const isTiledPlot = isPic || isDotplot;
|
|
165
|
-
|
|
166
|
-
const config: Record<string, any> = {};
|
|
167
|
-
const c = config; // c for short
|
|
168
|
-
|
|
169
|
-
const isMobile = this.props.apiOptions.isMobile;
|
|
170
|
-
|
|
171
|
-
c.graph = {
|
|
172
|
-
lines: [],
|
|
173
|
-
bars: [],
|
|
174
|
-
points: [],
|
|
175
|
-
dividers: [],
|
|
176
|
-
};
|
|
177
|
-
c.scaleY = self.props.scaleY;
|
|
178
|
-
c.dimX = self.props.categories.length;
|
|
179
|
-
const plotDimensions = isMobile
|
|
180
|
-
? [288, 336]
|
|
181
|
-
: self.props.plotDimensions;
|
|
182
|
-
if (isLine) {
|
|
183
|
-
// Subtracting 0.2 makes line have equal padding on each side
|
|
184
|
-
c.dimX += isMobile ? -0.2 : 1;
|
|
185
|
-
} else if (isHistogram) {
|
|
186
|
-
c.barPad = 0;
|
|
187
|
-
c.barWidth = 1;
|
|
188
|
-
} else if (isBar) {
|
|
189
|
-
c.barPad = isMobile ? 0.08 : 0.15;
|
|
190
|
-
c.barWidth = 1 - 2 * c.barPad;
|
|
191
|
-
c.dimX += (isMobile ? -2 : 2) * c.barPad;
|
|
192
|
-
} else if (isTiledPlot) {
|
|
193
|
-
c.picBoxHeight = self.props.picBoxHeight;
|
|
194
|
-
c.picBoxWidthPx = plotDimensions[0] / self.props.categories.length;
|
|
195
|
-
const picPadAllWidth = plotDimensions[0] - c.dimX * c.picBoxWidthPx;
|
|
196
|
-
c.picPad = picPadAllWidth / (2 * c.dimX + 2);
|
|
197
|
-
const picFullWidth = c.picBoxWidthPx + 2 * c.picPad;
|
|
198
|
-
|
|
199
|
-
// Convert from px to "unscaled"
|
|
200
|
-
c.picPad = c.picPad / picFullWidth;
|
|
201
|
-
c.picBoxWidth = c.picBoxWidthPx / picFullWidth;
|
|
202
|
-
c.dimX += 2 * c.picPad;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
if (isDotplot) {
|
|
206
|
-
c.picBoxHeight =
|
|
207
|
-
this.DOT_PLOT_POINT_SIZE() * 2 + this.DOT_PLOT_POINT_PADDING();
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
c.dimY = Math.ceil(self.props.maxY / c.scaleY) * c.scaleY;
|
|
211
|
-
|
|
212
|
-
let padX = 25;
|
|
213
|
-
|
|
214
|
-
if ((isBar || isLine) && isMobile) {
|
|
215
|
-
padX = self.props.labels[1].length !== 0 ? 17 : 11;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
// Since dotplot doesn't have an axis along the left it looks weird
|
|
219
|
-
// with the same padding as the others
|
|
220
|
-
if (isDotplot) {
|
|
221
|
-
padX /= 2;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
if (isMobile && isTiledPlot && self.props.labels[1].length === 0) {
|
|
225
|
-
padX = 0;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
// Default vertical padding.
|
|
229
|
-
let padTop = 25;
|
|
230
|
-
let padBottom = 25 * 3;
|
|
231
|
-
|
|
232
|
-
// TODO(michaelpolyak): Handle other plot types: Dot, Histogram, Line.
|
|
233
|
-
if (isMobile && (isBar || isTiledPlot)) {
|
|
234
|
-
const maxCategoryHeight = Math.max(
|
|
235
|
-
0,
|
|
236
|
-
...Object.values(self.state.categoryHeights),
|
|
237
|
-
);
|
|
238
|
-
|
|
239
|
-
if (maxCategoryHeight) {
|
|
240
|
-
// Account for bottom label position, height.
|
|
241
|
-
let offsetY = 25;
|
|
242
|
-
|
|
243
|
-
if (isTiledPlot) {
|
|
244
|
-
// Tiled plot categories have additional spacing.
|
|
245
|
-
offsetY += 10;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
padBottom = offsetY + maxCategoryHeight;
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
if (isMobile) {
|
|
253
|
-
c.scale = [
|
|
254
|
-
// We multiply pad by 4 because we add 3*pad padding on the left
|
|
255
|
-
// and 1*pad on the right
|
|
256
|
-
(plotDimensions[0] - padX * 4) / c.dimX,
|
|
257
|
-
(plotDimensions[1] - (padTop + padBottom)) / c.dimY,
|
|
258
|
-
];
|
|
259
|
-
} else {
|
|
260
|
-
c.scale = _.map([c.dimX, c.dimY], function (dim, i) {
|
|
261
|
-
return plotDimensions[i] / dim;
|
|
262
|
-
});
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
if (isTiledPlot) {
|
|
266
|
-
c.scale[1] = c.picBoxHeight / c.scaleY;
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
// Transform from screen space (pixels) to plot space.
|
|
270
|
-
padX /= c.scale[0];
|
|
271
|
-
padTop /= c.scale[1];
|
|
272
|
-
padBottom /= c.scale[1];
|
|
273
|
-
|
|
274
|
-
graphie.init({
|
|
275
|
-
range: [
|
|
276
|
-
[-3 * padX, c.dimX + padX],
|
|
277
|
-
[-padBottom, c.dimY + padTop],
|
|
278
|
-
],
|
|
279
|
-
scale: c.scale,
|
|
280
|
-
isMobile: this.props.apiOptions.isMobile,
|
|
281
|
-
});
|
|
282
|
-
// @ts-expect-error - Property 'addMouseLayer' does not exist on type 'Graphie'.
|
|
283
|
-
graphie.addMouseLayer({
|
|
284
|
-
allowScratchpad: true,
|
|
285
|
-
setDrawingAreaAvailable:
|
|
286
|
-
this.props.apiOptions.setDrawingAreaAvailable,
|
|
287
|
-
});
|
|
288
|
-
|
|
289
|
-
if (!isTiledPlot) {
|
|
290
|
-
// If we have isMobile, we skip the 0 label.
|
|
291
|
-
const initialY = isMobile ? c.scaleY : 0;
|
|
292
|
-
for (let y = initialY; y <= c.dimY; y += c.scaleY) {
|
|
293
|
-
graphie.label(
|
|
294
|
-
[0, y],
|
|
295
|
-
KhanMath.roundToApprox(y, 2),
|
|
296
|
-
"left",
|
|
297
|
-
/* isTeX */ true /* for the \approx symbol */,
|
|
298
|
-
);
|
|
299
|
-
graphie.style(
|
|
300
|
-
{
|
|
301
|
-
stroke: isMobile ? "#e9ebec" : "#000",
|
|
302
|
-
strokeWidth: 1,
|
|
303
|
-
opacity: isMobile ? 1 : 0.3,
|
|
304
|
-
},
|
|
305
|
-
function () {
|
|
306
|
-
graphie.line([0, y], [c.dimX, y]);
|
|
307
|
-
},
|
|
308
|
-
);
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
if ((isBar || isLine) && isMobile && !this.props.static) {
|
|
313
|
-
self.graphie.dragPrompt = graphie
|
|
314
|
-
.label(
|
|
315
|
-
[c.dimX / 2, c.dimY / 2],
|
|
316
|
-
i18n._("Drag handles to make graph"),
|
|
317
|
-
"center",
|
|
318
|
-
false,
|
|
319
|
-
)
|
|
320
|
-
.css("font-weight", "bold")
|
|
321
|
-
.css("color", KhanColors.KA_GREEN)
|
|
322
|
-
.css("display", "none");
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
self.setupCategories(config);
|
|
326
|
-
|
|
327
|
-
if (isTiledPlot && isMobile) {
|
|
328
|
-
self.graphie.dotPrompt = graphie
|
|
329
|
-
.label(
|
|
330
|
-
[c.dimX / 2, c.dimY / 2],
|
|
331
|
-
i18n._("Tap to add points"),
|
|
332
|
-
"center",
|
|
333
|
-
false,
|
|
334
|
-
)
|
|
335
|
-
.css("font-weight", "bold")
|
|
336
|
-
.css("color", KhanColors.KA_GREEN)
|
|
337
|
-
.css("display", "none");
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
if (isTiledPlot) {
|
|
341
|
-
self.drawPicHeights(self.state.values, prevState.values);
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
graphie.style(
|
|
345
|
-
{stroke: "#000", strokeWidth: 2, opacity: 1.0},
|
|
346
|
-
function () {
|
|
347
|
-
if (isTiledPlot) {
|
|
348
|
-
if (isDotplot) {
|
|
349
|
-
// Dotplot is a subtype of tiled plot, here we only draw
|
|
350
|
-
// the x-axis
|
|
351
|
-
graphie.style(
|
|
352
|
-
{
|
|
353
|
-
stroke: isMobile ? KhanColors.GRAY_G : "#000",
|
|
354
|
-
strokeWidth: isMobile ? 1 : 2,
|
|
355
|
-
},
|
|
356
|
-
() =>
|
|
357
|
-
graphie.line(
|
|
358
|
-
[isMobile ? 0 : 0.5, 0],
|
|
359
|
-
[c.dimX - (isMobile ? 0 : 0.5), 0],
|
|
360
|
-
),
|
|
361
|
-
);
|
|
362
|
-
} else {
|
|
363
|
-
graphie.line([0, 0], [c.dimX, 0]);
|
|
364
|
-
|
|
365
|
-
// Draw the left axis for non-dotplots
|
|
366
|
-
if (self.props.labels[1].length !== 0 || !isMobile) {
|
|
367
|
-
graphie.style(
|
|
368
|
-
{
|
|
369
|
-
stroke: isMobile
|
|
370
|
-
? KhanColors.GRAY_G
|
|
371
|
-
: "#000",
|
|
372
|
-
strokeWidth: isMobile ? 1 : 2,
|
|
373
|
-
},
|
|
374
|
-
() => graphie.line([0, 0], [0, c.dimY]),
|
|
375
|
-
);
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
} else {
|
|
379
|
-
// Draw normal axes
|
|
380
|
-
graphie.style(
|
|
381
|
-
{
|
|
382
|
-
stroke: isMobile ? KhanColors.GRAY_G : "#000",
|
|
383
|
-
strokeWidth: isMobile ? 1 : 2,
|
|
384
|
-
},
|
|
385
|
-
() =>
|
|
386
|
-
graphie.line(
|
|
387
|
-
[isMobile ? -padX * 3 : 0, 0],
|
|
388
|
-
[c.dimX + (isMobile ? padX : 0), 0],
|
|
389
|
-
),
|
|
390
|
-
);
|
|
391
|
-
|
|
392
|
-
if (!((isBar || isLine) && isMobile)) {
|
|
393
|
-
graphie.style(
|
|
394
|
-
{
|
|
395
|
-
stroke: isMobile ? KhanColors.GRAY_G : "#000",
|
|
396
|
-
strokeWidth: isMobile ? 1 : 2,
|
|
397
|
-
},
|
|
398
|
-
() => graphie.line([0, 0], [0, c.dimY]),
|
|
399
|
-
);
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
},
|
|
403
|
-
);
|
|
404
|
-
|
|
405
|
-
graphie
|
|
406
|
-
.label(
|
|
407
|
-
[c.dimX / 2, isMobile ? -padBottom : -35 / c.scale[1]],
|
|
408
|
-
self.props.labels[0],
|
|
409
|
-
isMobile ? "above" : "below",
|
|
410
|
-
false,
|
|
411
|
-
)
|
|
412
|
-
.css("font-weight", "bold")
|
|
413
|
-
.css("color", isMobile && KhanColors.GRAY_F);
|
|
414
|
-
|
|
415
|
-
graphie
|
|
416
|
-
.label(
|
|
417
|
-
[(isMobile ? -35 : -60) / c.scale[0], c.dimY / 2],
|
|
418
|
-
self.props.labels[1],
|
|
419
|
-
"center",
|
|
420
|
-
false,
|
|
421
|
-
)
|
|
422
|
-
.css("font-weight", "bold")
|
|
423
|
-
.css("color", isMobile && KhanColors.GRAY_F)
|
|
424
|
-
.addClass("rotate");
|
|
425
|
-
|
|
426
|
-
if (this.props.apiOptions.isMobile) {
|
|
427
|
-
this.horizHairline = new WrappedLine(this.graphie, [0, 0], [0, 0], {
|
|
428
|
-
normalStyle: {
|
|
429
|
-
strokeWidth: 1,
|
|
430
|
-
},
|
|
431
|
-
});
|
|
432
|
-
|
|
433
|
-
this.horizHairline.attr({
|
|
434
|
-
stroke: KhanColors.INTERACTIVE,
|
|
435
|
-
});
|
|
436
|
-
this.horizHairline.hide();
|
|
437
|
-
|
|
438
|
-
this.hairlineRange = [
|
|
439
|
-
[0, c.dimX],
|
|
440
|
-
[0, c.dimY],
|
|
441
|
-
];
|
|
442
|
-
}
|
|
443
|
-
};
|
|
444
|
-
|
|
445
|
-
showHairlines: (arg1: any) => void = (point) => {
|
|
446
|
-
if (this.props.apiOptions.isMobile) {
|
|
447
|
-
// Hairlines are already initialized when the graph is loaded, so
|
|
448
|
-
// here we just move them to the updated location and make them
|
|
449
|
-
// visible.
|
|
450
|
-
this.horizHairline.moveTo(
|
|
451
|
-
[this.hairlineRange[0][0], point[1]],
|
|
452
|
-
[this.hairlineRange[0][1], point[1]],
|
|
453
|
-
);
|
|
454
|
-
|
|
455
|
-
this.horizHairline.show();
|
|
456
|
-
}
|
|
457
|
-
};
|
|
458
|
-
|
|
459
|
-
hideHairlines: () => void = () => {
|
|
460
|
-
if (this.props.apiOptions.isMobile) {
|
|
461
|
-
this.horizHairline.hide();
|
|
462
|
-
}
|
|
463
|
-
};
|
|
464
|
-
|
|
465
|
-
labelCategory: (arg1: any, arg2: any) => Promise<any> = (x, category) => {
|
|
466
|
-
const isMobile = this.props.apiOptions.isMobile;
|
|
467
|
-
|
|
468
|
-
const graphie = this.graphie;
|
|
469
|
-
category = category + "";
|
|
470
|
-
let isTeX = false;
|
|
471
|
-
const mathyCategory = category.match(/^\$(.*)\$$/);
|
|
472
|
-
if (mathyCategory) {
|
|
473
|
-
category = mathyCategory[1];
|
|
474
|
-
isTeX = true;
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
const translateX = 5;
|
|
478
|
-
const rotationDeg = 45;
|
|
479
|
-
const rotationRad = rotationDeg * (Math.PI / 180);
|
|
480
|
-
|
|
481
|
-
const labelRotation =
|
|
482
|
-
`translateX(-50%) translateX(${translateX}px) ` +
|
|
483
|
-
`translateY(-50%) rotate(-${rotationDeg}deg)`;
|
|
484
|
-
|
|
485
|
-
const shouldRotate = isMobile && !mathyCategory;
|
|
486
|
-
|
|
487
|
-
// We return a promise that will resolve to measured category height.
|
|
488
|
-
return new Promise((resolve) => {
|
|
489
|
-
graphie.style(
|
|
490
|
-
{
|
|
491
|
-
color: isMobile ? KhanColors.GRAY_G : "inherit",
|
|
492
|
-
transform: shouldRotate ? labelRotation : "none",
|
|
493
|
-
transformOrigin: "100%",
|
|
494
|
-
},
|
|
495
|
-
() => {
|
|
496
|
-
const $span = graphie.label(
|
|
497
|
-
[x, isMobile ? -0.5 : 0],
|
|
498
|
-
category,
|
|
499
|
-
"below",
|
|
500
|
-
isTeX,
|
|
501
|
-
);
|
|
502
|
-
|
|
503
|
-
const height =
|
|
504
|
-
// Additional padding is applied by style.
|
|
505
|
-
14 +
|
|
506
|
-
(shouldRotate
|
|
507
|
-
? Math.round(
|
|
508
|
-
$span.height() * Math.cos(rotationRad) +
|
|
509
|
-
($span.width() + translateX) *
|
|
510
|
-
Math.sin(rotationRad),
|
|
511
|
-
)
|
|
512
|
-
: $span.height());
|
|
513
|
-
|
|
514
|
-
resolve({category, height});
|
|
515
|
-
},
|
|
516
|
-
);
|
|
517
|
-
});
|
|
518
|
-
};
|
|
519
|
-
|
|
520
|
-
setupCategories: (arg1: any) => void = (config) => {
|
|
521
|
-
const self = this;
|
|
522
|
-
const c = config;
|
|
523
|
-
const graphie = self.graphie;
|
|
524
|
-
|
|
525
|
-
const isMobile = this.props.apiOptions.isMobile;
|
|
526
|
-
|
|
527
|
-
// The deferred measurements returned from `labelCategory`.
|
|
528
|
-
const categoryHeightPromises = [];
|
|
529
|
-
|
|
530
|
-
if (self.props.type === "histogram") {
|
|
531
|
-
// Histograms with n labels/categories have n - 1 buckets
|
|
532
|
-
_.times(self.props.categories.length - 1, function (i) {
|
|
533
|
-
self.setupBar({
|
|
534
|
-
index: i,
|
|
535
|
-
startHeight: self.state.values[i],
|
|
536
|
-
config: config,
|
|
537
|
-
isHistogram: true,
|
|
538
|
-
});
|
|
539
|
-
});
|
|
540
|
-
|
|
541
|
-
// Label categories
|
|
542
|
-
_.each(self.props.categories, function (category, i) {
|
|
543
|
-
const x = 0.5 + i * c.barWidth;
|
|
544
|
-
|
|
545
|
-
// @ts-expect-error - TS2345 - Argument of type 'Promise<any>' is not assignable to parameter of type 'never'.
|
|
546
|
-
categoryHeightPromises.push(self.labelCategory(x, category));
|
|
547
|
-
const tickHeight = 6 / c.scale[1];
|
|
548
|
-
graphie.style(
|
|
549
|
-
{
|
|
550
|
-
stroke: "#000",
|
|
551
|
-
strokeWidth: isMobile ? 1 : 2,
|
|
552
|
-
opacity: 1.0,
|
|
553
|
-
},
|
|
554
|
-
function () {
|
|
555
|
-
graphie.line([x, -tickHeight], [x, 0]);
|
|
556
|
-
},
|
|
557
|
-
);
|
|
558
|
-
});
|
|
559
|
-
} else {
|
|
560
|
-
_.each(self.props.categories, function (category, i) {
|
|
561
|
-
const startHeight = self.state.values[i];
|
|
562
|
-
let x;
|
|
563
|
-
|
|
564
|
-
if (self.props.type === "bar") {
|
|
565
|
-
x = self.setupBar({
|
|
566
|
-
index: i,
|
|
567
|
-
startHeight: startHeight,
|
|
568
|
-
config: config,
|
|
569
|
-
isHistogram: false,
|
|
570
|
-
});
|
|
571
|
-
} else if (self.props.type === "line") {
|
|
572
|
-
x = self.setupLine(i, startHeight, config);
|
|
573
|
-
} else if (self.props.type === "pic") {
|
|
574
|
-
x = self.setupPic(i, config);
|
|
575
|
-
} else if (self.props.type === "dotplot") {
|
|
576
|
-
x = self.setupDotplot(i, config);
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
let tickStart = 0;
|
|
580
|
-
let tickEnd = -6 / c.scale[1];
|
|
581
|
-
|
|
582
|
-
if (self.props.type === "dotplot" && !isMobile) {
|
|
583
|
-
tickStart = -tickEnd;
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
if (self.props.type === "dotplot") {
|
|
587
|
-
// Dotplot lets you specify to only show labels every 'n'
|
|
588
|
-
// ticks. It also looks nicer if it makes the labelled
|
|
589
|
-
// ticks a bit bigger.
|
|
590
|
-
if (
|
|
591
|
-
i % self.props.labelInterval === 0 ||
|
|
592
|
-
i === self.props.categories.length - 1
|
|
593
|
-
) {
|
|
594
|
-
categoryHeightPromises.push(
|
|
595
|
-
// @ts-expect-error - TS2345 - Argument of type 'Promise<any>' is not assignable to parameter of type 'never'.
|
|
596
|
-
self.labelCategory(x, category),
|
|
597
|
-
);
|
|
598
|
-
tickStart *= 1.5;
|
|
599
|
-
tickEnd *= 1.5;
|
|
600
|
-
}
|
|
601
|
-
} else {
|
|
602
|
-
categoryHeightPromises.push(
|
|
603
|
-
// @ts-expect-error - TS2345 - Argument of type 'Promise<any>' is not assignable to parameter of type 'never'.
|
|
604
|
-
self.labelCategory(x, category),
|
|
605
|
-
);
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
graphie.style(
|
|
609
|
-
{
|
|
610
|
-
stroke: isMobile ? KhanColors.GRAY_G : "#000",
|
|
611
|
-
strokeWidth: isMobile ? 1 : 2,
|
|
612
|
-
opacity: 1.0,
|
|
613
|
-
},
|
|
614
|
-
function () {
|
|
615
|
-
graphie.line([x, tickStart], [x, tickEnd]);
|
|
616
|
-
},
|
|
617
|
-
);
|
|
618
|
-
});
|
|
619
|
-
}
|
|
620
|
-
|
|
621
|
-
Promise.all(categoryHeightPromises).then((measurements) => {
|
|
622
|
-
if (self._isMounted) {
|
|
623
|
-
const categoryHeights: Record<string, any> = {};
|
|
624
|
-
|
|
625
|
-
measurements.forEach(
|
|
626
|
-
({category, height}) =>
|
|
627
|
-
(categoryHeights[category] = height),
|
|
628
|
-
);
|
|
629
|
-
|
|
630
|
-
self.setState({categoryHeights});
|
|
631
|
-
}
|
|
632
|
-
});
|
|
633
|
-
};
|
|
634
|
-
|
|
635
|
-
_clampValue: (arg1: number, arg2: number, arg3: number) => number = (
|
|
636
|
-
v,
|
|
637
|
-
min,
|
|
638
|
-
max,
|
|
639
|
-
) => {
|
|
640
|
-
return Math.max(Math.min(v, max), min);
|
|
641
|
-
};
|
|
642
|
-
|
|
643
|
-
_maybeShowDragPrompt: () => void = () => {
|
|
644
|
-
// The drag prompt is only added on certain types of plots.
|
|
645
|
-
if (this.graphie.dragPrompt != null) {
|
|
646
|
-
this.graphie.dragPrompt[0].style.display = "inline";
|
|
647
|
-
}
|
|
648
|
-
};
|
|
649
|
-
|
|
650
|
-
_maybeHideDragPrompt: () => void = () => {
|
|
651
|
-
// The drag prompt is only added on certain types of plots.
|
|
652
|
-
if (this.graphie.dragPrompt != null) {
|
|
653
|
-
this.graphie.dragPrompt[0].style.display = "none";
|
|
654
|
-
}
|
|
655
|
-
};
|
|
656
|
-
|
|
657
|
-
setupBar: (arg1: any) => number = (args) => {
|
|
658
|
-
const isMobile = this.props.apiOptions.isMobile;
|
|
659
|
-
|
|
660
|
-
const i = args.index;
|
|
661
|
-
const startHeight = args.startHeight;
|
|
662
|
-
const config = args.config;
|
|
663
|
-
const isHistogram = args.isHistogram;
|
|
664
|
-
|
|
665
|
-
const self = this;
|
|
666
|
-
const graphie = self.graphie;
|
|
667
|
-
const barHalfWidth = config.barWidth / 2;
|
|
668
|
-
let x;
|
|
669
|
-
if (isHistogram) {
|
|
670
|
-
x = 0.5 + i * config.barWidth + barHalfWidth;
|
|
671
|
-
} else {
|
|
672
|
-
x = (isMobile ? barHalfWidth : 0.5 + config.barPad) + i;
|
|
673
|
-
}
|
|
674
|
-
|
|
675
|
-
/**
|
|
676
|
-
* Updates the bar with given index to the given height
|
|
677
|
-
* @param i the index of the bar to update
|
|
678
|
-
* @param height the new height of the bar
|
|
679
|
-
*/
|
|
680
|
-
const scaleBar = function (i: any, height) {
|
|
681
|
-
const center = graphie.scalePoint(0);
|
|
682
|
-
|
|
683
|
-
// Scale filled bucket (bar)
|
|
684
|
-
config.graph.bars[i].scale(
|
|
685
|
-
1,
|
|
686
|
-
Math.max(isMobile ? 0.2 : 0.01, height / config.scaleY),
|
|
687
|
-
center[0],
|
|
688
|
-
center[1],
|
|
689
|
-
);
|
|
690
|
-
|
|
691
|
-
if (isHistogram) {
|
|
692
|
-
// Scale dividers between buckets
|
|
693
|
-
const leftDivider = config.graph.dividers[i - 1];
|
|
694
|
-
const rightDivider = config.graph.dividers[i];
|
|
695
|
-
|
|
696
|
-
if (leftDivider) {
|
|
697
|
-
const divHeight = Math.min(
|
|
698
|
-
self.state.values[i - 1],
|
|
699
|
-
height,
|
|
700
|
-
);
|
|
701
|
-
leftDivider.scale(
|
|
702
|
-
1,
|
|
703
|
-
Math.max(0.01, divHeight / config.scaleY),
|
|
704
|
-
center[0],
|
|
705
|
-
center[1],
|
|
706
|
-
);
|
|
707
|
-
}
|
|
708
|
-
|
|
709
|
-
if (rightDivider) {
|
|
710
|
-
const divHeight = Math.min(
|
|
711
|
-
self.state.values[i + 1],
|
|
712
|
-
height,
|
|
713
|
-
);
|
|
714
|
-
rightDivider.scale(
|
|
715
|
-
1,
|
|
716
|
-
Math.max(0.01, divHeight / config.scaleY),
|
|
717
|
-
center[0],
|
|
718
|
-
center[1],
|
|
719
|
-
);
|
|
720
|
-
}
|
|
721
|
-
}
|
|
722
|
-
};
|
|
723
|
-
|
|
724
|
-
graphie.style(
|
|
725
|
-
{
|
|
726
|
-
stroke: "none",
|
|
727
|
-
fill: isMobile ? KhanColors.BLUE_C : KhanColors.LIGHT_BLUE,
|
|
728
|
-
opacity: 1.0,
|
|
729
|
-
},
|
|
730
|
-
function () {
|
|
731
|
-
config.graph.bars[i] = graphie.path([
|
|
732
|
-
[x - barHalfWidth, 0],
|
|
733
|
-
[x - barHalfWidth, config.scaleY],
|
|
734
|
-
[x + barHalfWidth, config.scaleY],
|
|
735
|
-
[x + barHalfWidth, 0],
|
|
736
|
-
[x - barHalfWidth, 0],
|
|
737
|
-
]);
|
|
738
|
-
},
|
|
739
|
-
);
|
|
740
|
-
|
|
741
|
-
if (isHistogram) {
|
|
742
|
-
if (i > 0) {
|
|
743
|
-
// Don't draw a divider to the left of the first bucket
|
|
744
|
-
graphie.style(
|
|
745
|
-
{
|
|
746
|
-
stroke: "#000",
|
|
747
|
-
strokeWidth: 1,
|
|
748
|
-
opacity: 0.3,
|
|
749
|
-
},
|
|
750
|
-
function () {
|
|
751
|
-
config.graph.dividers.push(
|
|
752
|
-
graphie.path([
|
|
753
|
-
[x - barHalfWidth, 0],
|
|
754
|
-
[x - barHalfWidth, config.scaleY],
|
|
755
|
-
]),
|
|
756
|
-
);
|
|
757
|
-
},
|
|
758
|
-
);
|
|
759
|
-
}
|
|
760
|
-
}
|
|
761
|
-
|
|
762
|
-
if (isMobile) {
|
|
763
|
-
const snap = config.scaleY / self.props.snapsPerLine;
|
|
764
|
-
config.graph.lines[i] = Interactive2.addMaybeMobileMovablePoint(
|
|
765
|
-
this,
|
|
766
|
-
{
|
|
767
|
-
coord: [x, startHeight],
|
|
768
|
-
constraints: [
|
|
769
|
-
(coord: any, prev: any, options: any) => {
|
|
770
|
-
return [
|
|
771
|
-
x,
|
|
772
|
-
this._clampValue(
|
|
773
|
-
Math.round(coord[1] / snap) * snap,
|
|
774
|
-
0,
|
|
775
|
-
config.dimY,
|
|
776
|
-
),
|
|
777
|
-
];
|
|
778
|
-
},
|
|
779
|
-
],
|
|
780
|
-
onMoveStart: function () {
|
|
781
|
-
config.graph.bars[i].attr({
|
|
782
|
-
fill: KhanColors.INTERACTIVE,
|
|
783
|
-
});
|
|
784
|
-
},
|
|
785
|
-
onMove: function () {
|
|
786
|
-
const y = config.graph.lines[i].coord()[1];
|
|
787
|
-
|
|
788
|
-
const values = [...self.state.values];
|
|
789
|
-
values[i] = y;
|
|
790
|
-
self.setState({values: values});
|
|
791
|
-
self.changeAndTrack({values: values});
|
|
792
|
-
|
|
793
|
-
self._maybeHideDragPrompt();
|
|
794
|
-
|
|
795
|
-
scaleBar(i, y);
|
|
796
|
-
},
|
|
797
|
-
onMoveEnd: function () {
|
|
798
|
-
config.graph.bars[i].attr({
|
|
799
|
-
fill: KhanColors.BLUE_C,
|
|
800
|
-
});
|
|
801
|
-
},
|
|
802
|
-
},
|
|
803
|
-
);
|
|
804
|
-
|
|
805
|
-
// We set the z-index to 1 here so that the hairlines cover up the
|
|
806
|
-
// points
|
|
807
|
-
config.graph.lines[i].state.visibleShape.wrapper.style.zIndex = "1";
|
|
808
|
-
|
|
809
|
-
self._maybeShowDragPrompt();
|
|
810
|
-
} else {
|
|
811
|
-
config.graph.lines[i] = graphie.addMovableLineSegment({
|
|
812
|
-
coordA: [x - barHalfWidth, startHeight],
|
|
813
|
-
coordZ: [x + barHalfWidth, startHeight],
|
|
814
|
-
snapY: config.scaleY / self.props.snapsPerLine,
|
|
815
|
-
constraints: {
|
|
816
|
-
constrainX: true,
|
|
817
|
-
},
|
|
818
|
-
normalStyle: {
|
|
819
|
-
stroke: KhanColors.INTERACTIVE,
|
|
820
|
-
// Don't display graph handles in static mode
|
|
821
|
-
"stroke-width": this.props.static ? 0 : 4,
|
|
822
|
-
},
|
|
823
|
-
});
|
|
824
|
-
|
|
825
|
-
config.graph.lines[i].onMove = function (dx, dy: any) {
|
|
826
|
-
let y = this.coordA[1];
|
|
827
|
-
if (y < 0 || y > config.dimY) {
|
|
828
|
-
y = Math.min(Math.max(y, 0), config.dimY);
|
|
829
|
-
this.coordA[1] = this.coordZ[1] = y;
|
|
830
|
-
|
|
831
|
-
// Snap the line back into range.
|
|
832
|
-
this.transform();
|
|
833
|
-
}
|
|
834
|
-
|
|
835
|
-
const values = [...self.state.values];
|
|
836
|
-
values[i] = y;
|
|
837
|
-
self.setState({values: values});
|
|
838
|
-
self.changeAndTrack({values: values});
|
|
839
|
-
|
|
840
|
-
scaleBar(i, y);
|
|
841
|
-
};
|
|
842
|
-
}
|
|
843
|
-
|
|
844
|
-
scaleBar(i, startHeight);
|
|
845
|
-
return x;
|
|
846
|
-
};
|
|
847
|
-
|
|
848
|
-
/**
|
|
849
|
-
* Renders a segment of an interactive line to the plotter graph
|
|
850
|
-
* @param i the index of the point to render
|
|
851
|
-
* @param startHeight the initial height of the given point
|
|
852
|
-
* @param config the graph setup, such as scale and dimensions
|
|
853
|
-
*/
|
|
854
|
-
setupLine: (arg1: number, arg2: number, arg3: any) => number = (
|
|
855
|
-
i,
|
|
856
|
-
startHeight,
|
|
857
|
-
config,
|
|
858
|
-
) => {
|
|
859
|
-
const isMobile = this.props.apiOptions.isMobile;
|
|
860
|
-
|
|
861
|
-
const self = this;
|
|
862
|
-
const c = config;
|
|
863
|
-
const graphie = self.graphie;
|
|
864
|
-
const x = i + (isMobile ? 0.4 : 1);
|
|
865
|
-
|
|
866
|
-
if (isMobile) {
|
|
867
|
-
const snap = config.scaleY / self.props.snapsPerLine;
|
|
868
|
-
c.graph.points[i] = Interactive2.addMaybeMobileMovablePoint(this, {
|
|
869
|
-
coord: [x, startHeight],
|
|
870
|
-
constraints: [
|
|
871
|
-
(coord, prev, options: any) => {
|
|
872
|
-
return [
|
|
873
|
-
x,
|
|
874
|
-
this._clampValue(
|
|
875
|
-
Math.round(coord[1] / snap) * snap,
|
|
876
|
-
0,
|
|
877
|
-
config.dimY,
|
|
878
|
-
),
|
|
879
|
-
];
|
|
880
|
-
},
|
|
881
|
-
],
|
|
882
|
-
onMove: function () {
|
|
883
|
-
const y = c.graph.points[i].coord()[1];
|
|
884
|
-
|
|
885
|
-
const values = [...self.state.values];
|
|
886
|
-
values[i] = y;
|
|
887
|
-
self.setState({values: values});
|
|
888
|
-
self.changeAndTrack({values: values});
|
|
889
|
-
|
|
890
|
-
self._maybeHideDragPrompt();
|
|
891
|
-
},
|
|
892
|
-
});
|
|
893
|
-
|
|
894
|
-
self._maybeShowDragPrompt();
|
|
895
|
-
|
|
896
|
-
if (i > 0) {
|
|
897
|
-
c.graph.lines[i] = Interactive2.addMovableLine(graphie, {
|
|
898
|
-
points: [c.graph.points[i - 1], c.graph.points[i]],
|
|
899
|
-
// @ts-expect-error - TS2339 - Property 'constraints' does not exist on type '(graphie: any, movable: any, options: any) => void'.
|
|
900
|
-
constraints: Interactive2.MovablePoint.constraints.fixed(),
|
|
901
|
-
normalStyle: {
|
|
902
|
-
stroke: KhanColors.BLUE_C,
|
|
903
|
-
"stroke-width": 2,
|
|
904
|
-
},
|
|
905
|
-
highlightStyle: {
|
|
906
|
-
stroke: KhanColors.BLUE_C,
|
|
907
|
-
"stroke-width": 2,
|
|
908
|
-
},
|
|
909
|
-
});
|
|
910
|
-
}
|
|
911
|
-
} else {
|
|
912
|
-
c.graph.points[i] = graphie.addMovablePoint({
|
|
913
|
-
coord: [x, startHeight],
|
|
914
|
-
constraints: {
|
|
915
|
-
constrainX: true,
|
|
916
|
-
},
|
|
917
|
-
normalStyle: {
|
|
918
|
-
fill: KhanColors.INTERACTIVE,
|
|
919
|
-
stroke: KhanColors.INTERACTIVE,
|
|
920
|
-
},
|
|
921
|
-
snapY: c.scaleY / self.props.snapsPerLine,
|
|
922
|
-
});
|
|
923
|
-
c.graph.points[i].onMove = function (x, y) {
|
|
924
|
-
y = Math.min(Math.max(y, 0), c.dimY);
|
|
925
|
-
const values = [...self.state.values];
|
|
926
|
-
values[i] = y;
|
|
927
|
-
self.setState({values: values});
|
|
928
|
-
self.changeAndTrack({values: values});
|
|
929
|
-
return [x, y];
|
|
930
|
-
};
|
|
931
|
-
|
|
932
|
-
if (i > 0) {
|
|
933
|
-
c.graph.lines[i] = graphie.addMovableLineSegment({
|
|
934
|
-
pointA: c.graph.points[i - 1],
|
|
935
|
-
pointZ: c.graph.points[i],
|
|
936
|
-
constraints: {
|
|
937
|
-
fixed: true,
|
|
938
|
-
},
|
|
939
|
-
normalStyle: {
|
|
940
|
-
stroke: "#9ab8ed",
|
|
941
|
-
"stroke-width": 2,
|
|
942
|
-
},
|
|
943
|
-
});
|
|
944
|
-
}
|
|
945
|
-
}
|
|
946
|
-
|
|
947
|
-
return x;
|
|
948
|
-
};
|
|
949
|
-
|
|
950
|
-
setupDotplot: (arg1: any, arg2: any) => any = (i, config) => {
|
|
951
|
-
const graphie = this.graphie;
|
|
952
|
-
const isMobile = this.props.apiOptions.isMobile;
|
|
953
|
-
|
|
954
|
-
return this.setupTiledPlot(i, isMobile ? 0.5 : 1, config, (x, y) => {
|
|
955
|
-
return graphie.ellipse(
|
|
956
|
-
[x, y],
|
|
957
|
-
[
|
|
958
|
-
this.DOT_PLOT_POINT_SIZE() / graphie.scale[0],
|
|
959
|
-
this.DOT_PLOT_POINT_SIZE() / graphie.scale[1],
|
|
960
|
-
],
|
|
961
|
-
{
|
|
962
|
-
fill: KhanColors.INTERACTIVE,
|
|
963
|
-
stroke: KhanColors.INTERACTIVE,
|
|
964
|
-
},
|
|
965
|
-
);
|
|
966
|
-
});
|
|
967
|
-
};
|
|
968
|
-
|
|
969
|
-
setupPic: (arg1: any, arg2: any) => any = (i, config) => {
|
|
970
|
-
const graphie = this.graphie;
|
|
971
|
-
return this.setupTiledPlot(i, 0, config, (x, y) => {
|
|
972
|
-
const scaledCenter = graphie.scalePoint([x, y]);
|
|
973
|
-
const size = this.props.picSize;
|
|
974
|
-
return graphie.raphael.image(
|
|
975
|
-
this.props.picUrl,
|
|
976
|
-
scaledCenter[0] - size / 2,
|
|
977
|
-
scaledCenter[1] - size / 2,
|
|
978
|
-
size,
|
|
979
|
-
size,
|
|
980
|
-
);
|
|
981
|
-
});
|
|
982
|
-
};
|
|
983
|
-
|
|
984
|
-
setupTiledPlot: (arg1: any, arg2: any, arg3: any, arg4: any) => any = (
|
|
985
|
-
i,
|
|
986
|
-
bottomMargin,
|
|
987
|
-
config,
|
|
988
|
-
createImage,
|
|
989
|
-
) => {
|
|
990
|
-
const self = this;
|
|
991
|
-
const c = config;
|
|
992
|
-
const graphie = self.graphie;
|
|
993
|
-
const pics = graphie.pics;
|
|
994
|
-
const dotTicks = graphie.dotTicks;
|
|
995
|
-
const x = i + 0.5 + c.picPad;
|
|
996
|
-
|
|
997
|
-
// In order to make sure that manipulating the graph doesn't cause
|
|
998
|
-
// dragging, we disable touch actions for the whole mouselayer.
|
|
999
|
-
// TODO(emily): Figure out a way to turn of touch actions for only the
|
|
1000
|
-
// part of the widget that can be manipulated. Putting this style
|
|
1001
|
-
// directly on the rects below doesn't work.
|
|
1002
|
-
graphie.mouselayer.canvas.style.touchAction = "none";
|
|
1003
|
-
|
|
1004
|
-
pics[i] = [];
|
|
1005
|
-
dotTicks[i] = [];
|
|
1006
|
-
const n = Math.round(c.dimY / c.scaleY) + 1;
|
|
1007
|
-
_(n).times(function (j) {
|
|
1008
|
-
j -= 1;
|
|
1009
|
-
const midY = (j + 0.5) * c.scaleY;
|
|
1010
|
-
const leftX = x - c.picBoxWidth / 2;
|
|
1011
|
-
const topY = midY + 0.5 * c.scaleY;
|
|
1012
|
-
const coord = graphie.scalePoint([leftX, topY + bottomMargin]);
|
|
1013
|
-
const mouseRect = graphie.mouselayer.rect(
|
|
1014
|
-
coord[0],
|
|
1015
|
-
coord[1],
|
|
1016
|
-
c.picBoxWidthPx,
|
|
1017
|
-
c.picBoxHeight,
|
|
1018
|
-
);
|
|
1019
|
-
$(mouseRect[0])
|
|
1020
|
-
.css({fill: "#000", opacity: 0.0, cursor: "pointer"})
|
|
1021
|
-
.on("vmousedown", function (e) {
|
|
1022
|
-
e.preventDefault();
|
|
1023
|
-
// @ts-expect-error - TS2339 - Property 'whichPicClicked' does not exist on type 'Plotter'.
|
|
1024
|
-
self.whichPicClicked = i;
|
|
1025
|
-
self.setPicHeight(i, topY);
|
|
1026
|
-
|
|
1027
|
-
$(document).on("vmouseup.plotTile", function (e) {
|
|
1028
|
-
$(document).unbind(".plotTile");
|
|
1029
|
-
});
|
|
1030
|
-
|
|
1031
|
-
$(document).on("vmousemove.plotTile", function (e) {
|
|
1032
|
-
e.preventDefault();
|
|
1033
|
-
|
|
1034
|
-
// Reverse-engineer the initial calculation
|
|
1035
|
-
const yCoord = graphie.getMouseCoord(e)[1];
|
|
1036
|
-
const adjustedCoord = Math.floor(yCoord - bottomMargin);
|
|
1037
|
-
|
|
1038
|
-
// Calculate top coord from j value, but don't let them
|
|
1039
|
-
// go below j = -1, which is equivalent to having '0'
|
|
1040
|
-
// on the dot plot (due to weird indexing).
|
|
1041
|
-
const newJ = Math.max(
|
|
1042
|
-
-1,
|
|
1043
|
-
Math.floor(adjustedCoord / c.scaleY),
|
|
1044
|
-
);
|
|
1045
|
-
const newMidY = (newJ + 0.5) * c.scaleY;
|
|
1046
|
-
// Constrain the max Y value to max displayable Y of the
|
|
1047
|
-
// plot. Otherwise users can unintentionally select an
|
|
1048
|
-
// out-of-range value and not see that they have done so.
|
|
1049
|
-
const newTopY = Math.min(
|
|
1050
|
-
newMidY + 0.5 * c.scaleY,
|
|
1051
|
-
c.dimY,
|
|
1052
|
-
);
|
|
1053
|
-
// @ts-expect-error - TS2339 - Property 'whichPicClicked' does not exist on type 'Plotter'.
|
|
1054
|
-
self.setPicHeight(self.whichPicClicked, newTopY);
|
|
1055
|
-
});
|
|
1056
|
-
});
|
|
1057
|
-
|
|
1058
|
-
if (j < 0) {
|
|
1059
|
-
// Don't show a pic underneath the axis!
|
|
1060
|
-
return;
|
|
1061
|
-
}
|
|
1062
|
-
pics[i][j] = createImage(x, midY + bottomMargin);
|
|
1063
|
-
dotTicks[i][j] = graphie.ellipse(
|
|
1064
|
-
[x, midY + bottomMargin],
|
|
1065
|
-
[
|
|
1066
|
-
self.DOT_TICK_POINT_SIZE() / graphie.scale[0],
|
|
1067
|
-
self.DOT_TICK_POINT_SIZE() / graphie.scale[1],
|
|
1068
|
-
],
|
|
1069
|
-
{
|
|
1070
|
-
fill: "#dee1e3",
|
|
1071
|
-
stroke: "#dee1e3",
|
|
1072
|
-
},
|
|
1073
|
-
);
|
|
1074
|
-
});
|
|
1075
|
-
return x;
|
|
1076
|
-
};
|
|
1077
|
-
|
|
1078
|
-
setPicHeight: (arg1: number, arg2: number) => void = (i, y) => {
|
|
1079
|
-
const values = [...this.state.values];
|
|
1080
|
-
values[i] = y;
|
|
1081
|
-
this.drawPicHeights(values, this.state.values);
|
|
1082
|
-
this.setState({values: values});
|
|
1083
|
-
this.changeAndTrack({values: values});
|
|
1084
|
-
};
|
|
1085
|
-
|
|
1086
|
-
changeAndTrack: (arg1: any) => void = (data) => {
|
|
1087
|
-
this.props.onChange(data);
|
|
1088
|
-
this.props.trackInteraction();
|
|
1089
|
-
};
|
|
1090
|
-
|
|
1091
|
-
drawPicHeights: (arg1: any, arg2: any) => void = (values, prevValues) => {
|
|
1092
|
-
const self = this;
|
|
1093
|
-
const graphie = self.graphie;
|
|
1094
|
-
const pics = graphie.pics;
|
|
1095
|
-
|
|
1096
|
-
const isMobile = this.props.apiOptions.isMobile;
|
|
1097
|
-
|
|
1098
|
-
if (isMobile) {
|
|
1099
|
-
const shouldDisplay = values.every((v) => v === 0);
|
|
1100
|
-
graphie.dotPrompt[0].style.display = shouldDisplay
|
|
1101
|
-
? "inline"
|
|
1102
|
-
: "none";
|
|
1103
|
-
}
|
|
1104
|
-
|
|
1105
|
-
_.each(pics, function (ps, i) {
|
|
1106
|
-
_.each(ps, function (pic, j) {
|
|
1107
|
-
const y = (j + 1) * self.props.scaleY;
|
|
1108
|
-
const show = y <= values[i];
|
|
1109
|
-
|
|
1110
|
-
if (self.props.type === "dotplot") {
|
|
1111
|
-
const wasShown = y <= prevValues[i];
|
|
1112
|
-
const wasJustShown = show && !wasShown;
|
|
1113
|
-
if (wasJustShown) {
|
|
1114
|
-
pic.animate(
|
|
1115
|
-
{
|
|
1116
|
-
"stroke-width": 8,
|
|
1117
|
-
},
|
|
1118
|
-
75,
|
|
1119
|
-
() =>
|
|
1120
|
-
pic.animate(
|
|
1121
|
-
{
|
|
1122
|
-
"stroke-width": 2,
|
|
1123
|
-
},
|
|
1124
|
-
75,
|
|
1125
|
-
),
|
|
1126
|
-
);
|
|
1127
|
-
}
|
|
1128
|
-
}
|
|
1129
|
-
$(pic[0]).css({display: show ? "inline" : "none"});
|
|
1130
|
-
|
|
1131
|
-
graphie.dotTicks[i][j][0].style.display =
|
|
1132
|
-
show || !isMobile ? "none" : "inline";
|
|
1133
|
-
});
|
|
1134
|
-
});
|
|
1135
|
-
};
|
|
1136
|
-
|
|
1137
|
-
getUserInput: () => any = () => {
|
|
1138
|
-
return this.state.values;
|
|
1139
|
-
};
|
|
1140
|
-
|
|
1141
|
-
simpleValidate: (arg1: any) => any = (rubric) => {
|
|
1142
|
-
// @ts-expect-error - TS2339 - Property 'validate' does not exist on type 'typeof Plotter'.
|
|
1143
|
-
return Plotter.validate(this.getUserInput(), rubric);
|
|
1144
|
-
};
|
|
1145
|
-
|
|
1146
|
-
render(): React.ReactNode {
|
|
1147
|
-
// TODO(kevinb) actually compute the size of the graphie correctly and
|
|
1148
|
-
// make it that size so we don't have to add extra padding. The value
|
|
1149
|
-
// was determined by eye-balling the layout. :(
|
|
1150
|
-
const paddingForBottomLabel = 75;
|
|
1151
|
-
const style = {
|
|
1152
|
-
marginBottom: this.props.labels[0] ? paddingForBottomLabel : 0,
|
|
1153
|
-
} as const;
|
|
1154
|
-
|
|
1155
|
-
return (
|
|
1156
|
-
<div
|
|
1157
|
-
className={
|
|
1158
|
-
"perseus-widget-plotter graphie " +
|
|
1159
|
-
ApiClassNames.INTERACTIVE
|
|
1160
|
-
}
|
|
1161
|
-
// eslint-disable-next-line react/no-string-refs
|
|
1162
|
-
ref="graphieDiv"
|
|
1163
|
-
style={style}
|
|
1164
|
-
/>
|
|
1165
|
-
);
|
|
1166
|
-
}
|
|
1167
|
-
}
|
|
1168
|
-
|
|
1169
|
-
_.extend(Plotter, {
|
|
1170
|
-
validate: function (guess, rubric) {
|
|
1171
|
-
if (deepEq(guess, rubric.starting)) {
|
|
1172
|
-
return {
|
|
1173
|
-
type: "invalid",
|
|
1174
|
-
message: null,
|
|
1175
|
-
};
|
|
1176
|
-
}
|
|
1177
|
-
return {
|
|
1178
|
-
type: "points",
|
|
1179
|
-
earned: deepEq(guess, rubric.correct) ? 1 : 0,
|
|
1180
|
-
total: 1,
|
|
1181
|
-
message: null,
|
|
1182
|
-
};
|
|
1183
|
-
},
|
|
1184
|
-
});
|
|
1185
|
-
|
|
1186
|
-
// We don't need to change any of the original props for static mode
|
|
1187
|
-
const staticTransform = _.identity;
|
|
1188
|
-
|
|
1189
|
-
export default {
|
|
1190
|
-
name: "plotter",
|
|
1191
|
-
displayName: "Plotter",
|
|
1192
|
-
widget: Plotter,
|
|
1193
|
-
staticTransform: staticTransform,
|
|
1194
|
-
} as WidgetExports<typeof Plotter>;
|