@pie-element/fraction-model 6.1.1 → 6.1.2-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/configure.js +2 -0
- package/controller.js +1 -0
- package/dist/author/card-bar.d.ts +20 -0
- package/dist/author/card-bar.js +40 -0
- package/dist/author/defaults.d.ts +113 -0
- package/dist/author/defaults.js +84 -0
- package/dist/author/index.d.ts +44 -0
- package/dist/author/index.js +88 -0
- package/dist/author/main.d.ts +25 -0
- package/dist/author/main.js +156 -0
- package/dist/author/model-options.d.ts +32 -0
- package/dist/author/model-options.js +85 -0
- package/dist/author/number-text-field.d.ts +15 -0
- package/dist/author/number-text-field.js +24 -0
- package/dist/browser/author/index.js +37287 -0
- package/dist/browser/author/index.js.map +1 -0
- package/dist/browser/controller/index.js +78 -0
- package/dist/browser/controller/index.js.map +1 -0
- package/dist/browser/delivery/index.js +2 -0
- package/dist/browser/delivery-BSG67wbh.js +28213 -0
- package/dist/browser/delivery-BSG67wbh.js.map +1 -0
- package/dist/browser/fraction-model.css +2 -0
- package/dist/browser/isEmpty-Cj-5W3cl.js +16 -0
- package/dist/browser/isEmpty-Cj-5W3cl.js.map +1 -0
- package/dist/browser/isTypedArray-yL07_GBh.js +171 -0
- package/dist/browser/isTypedArray-yL07_GBh.js.map +1 -0
- package/dist/controller/defaults.d.ts +21 -0
- package/dist/controller/defaults.js +13 -0
- package/dist/controller/index.d.ts +23 -0
- package/dist/controller/index.js +68 -0
- package/dist/delivery/answer-fraction.d.ts +27 -0
- package/dist/delivery/answer-fraction.js +69 -0
- package/dist/delivery/fraction-model-chart.d.ts +11 -0
- package/dist/delivery/fraction-model-chart.js +154 -0
- package/dist/delivery/index.d.ts +22 -0
- package/dist/delivery/index.js +54 -0
- package/dist/delivery/main.d.ts +38 -0
- package/dist/delivery/main.js +136 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.iife.d.ts +8 -0
- package/dist/index.iife.js +179 -0
- package/dist/index.js +2 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_DataView.js +6 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_Hash.js +16 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_ListCache.js +16 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_Map.js +6 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_MapCache.js +16 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_Promise.js +6 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_Set.js +6 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_Stack.js +14 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_Symbol.js +5 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_Uint8Array.js +5 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_WeakMap.js +6 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_arrayEach.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_arrayFilter.js +10 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_arrayLikeKeys.js +15 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_arrayPush.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_assignValue.js +10 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_assocIndexOf.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseAssign.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseAssignIn.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseAssignValue.js +12 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseClone.js +57 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseCreate.js +14 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseGetAllKeys.js +9 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseGetTag.js +10 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseIsArguments.js +9 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseIsMap.js +9 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseIsNative.js +11 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseIsSet.js +9 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseIsTypedArray.js +11 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseKeys.js +12 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseKeysIn.js +13 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseTimes.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseUnary.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_cloneArrayBuffer.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_cloneBuffer.js +10 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_cloneDataView.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_cloneRegExp.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_cloneSymbol.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_cloneTypedArray.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_copyArray.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_copyObject.js +14 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_copySymbols.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_copySymbolsIn.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_coreJsData.js +5 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_defineProperty.js +10 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_freeGlobal.js +4 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_getAllKeys.js +9 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_getAllKeysIn.js +9 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_getMapData.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_getNative.js +9 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_getPrototype.js +5 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_getRawTag.js +14 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_getSymbols.js +10 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_getSymbolsIn.js +11 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_getTag.js +23 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_getValue.js +6 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_hashClear.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_hashDelete.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_hashGet.js +13 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_hashHas.js +9 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_hashSet.js +9 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_initCloneArray.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_initCloneByTag.js +33 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_initCloneObject.js +9 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_isIndex.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_isKeyable.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_isMasked.js +11 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_isPrototype.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_listCacheClear.js +6 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_listCacheDelete.js +9 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_listCacheGet.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_listCacheHas.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_listCacheSet.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_mapCacheClear.js +13 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_mapCacheDelete.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_mapCacheGet.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_mapCacheHas.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_mapCacheSet.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_nativeCreate.js +5 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_nativeKeys.js +5 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_nativeKeysIn.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_nodeUtil.js +9 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_objectToString.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_overArg.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_root.js +5 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_stackClear.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_stackDelete.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_stackGet.js +6 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_stackHas.js +6 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_stackSet.js +16 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_toSource.js +15 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/cloneDeep.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/eq.js +6 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/isArguments.js +10 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/isArray.js +4 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/isArrayLike.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/isBuffer.js +6 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/isEmpty.js +21 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/isFunction.js +11 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/isLength.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/isMap.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/isObject.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/isObjectLike.js +6 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/isSet.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/isTypedArray.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/keys.js +9 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/keysIn.js +9 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/stubArray.js +6 -0
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/stubFalse.js +6 -0
- package/package.json +77 -17
- package/CHANGELOG.json +0 -1
- package/CHANGELOG.md +0 -588
- package/LICENSE.md +0 -5
- package/README.md +0 -18
- package/configure/CHANGELOG.json +0 -1
- package/configure/CHANGELOG.md +0 -553
- package/configure/lib/card-bar.js +0 -57
- package/configure/lib/card-bar.js.map +0 -1
- package/configure/lib/defaults.js +0 -114
- package/configure/lib/defaults.js.map +0 -1
- package/configure/lib/index.js +0 -163
- package/configure/lib/index.js.map +0 -1
- package/configure/lib/main.js +0 -253
- package/configure/lib/main.js.map +0 -1
- package/configure/lib/model-options.js +0 -144
- package/configure/lib/model-options.js.map +0 -1
- package/configure/lib/number-text-field.js +0 -47
- package/configure/lib/number-text-field.js.map +0 -1
- package/configure/package.json +0 -24
- package/controller/CHANGELOG.json +0 -1
- package/controller/CHANGELOG.md +0 -480
- package/controller/lib/defaults.js +0 -20
- package/controller/lib/defaults.js.map +0 -1
- package/controller/lib/index.js +0 -215
- package/controller/lib/index.js.map +0 -1
- package/controller/package.json +0 -15
- package/docs/config-schema.json +0 -1796
- package/docs/config-schema.json.md +0 -1318
- package/docs/demo/config.js +0 -8
- package/docs/demo/generate.js +0 -6
- package/docs/demo/index.html +0 -1
- package/docs/demo/session.js +0 -6
- package/docs/pie-schema.json +0 -873
- package/docs/pie-schema.json.md +0 -639
- package/lib/answer-fraction.js +0 -109
- package/lib/answer-fraction.js.map +0 -1
- package/lib/fraction-model-chart.js +0 -279
- package/lib/fraction-model-chart.js.map +0 -1
- package/lib/index.js +0 -91
- package/lib/index.js.map +0 -1
- package/lib/main.js +0 -203
- package/lib/main.js.map +0 -1
package/lib/answer-fraction.js
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.default = exports.AnswerFraction = void 0;
|
|
8
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
-
var _react = _interopRequireDefault(require("react"));
|
|
10
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
-
var _styles = require("@mui/material/styles");
|
|
12
|
-
var _material = require("@mui/material");
|
|
13
|
-
const GroupInline = (0, _styles.styled)('div')({
|
|
14
|
-
alignItems: 'center',
|
|
15
|
-
display: 'flex',
|
|
16
|
-
gap: '20px'
|
|
17
|
-
});
|
|
18
|
-
const Group = (0, _styles.styled)('div')({
|
|
19
|
-
margin: '12px 0'
|
|
20
|
-
});
|
|
21
|
-
const InputLabel = (0, _styles.styled)('label')({
|
|
22
|
-
display: 'block',
|
|
23
|
-
marginBottom: '4px'
|
|
24
|
-
});
|
|
25
|
-
const StyledTextField = (0, _styles.styled)(_material.TextField)({
|
|
26
|
-
width: '120px',
|
|
27
|
-
maxHeight: '40px',
|
|
28
|
-
'& [class^="MuiInputBase-root"]': {
|
|
29
|
-
height: 40,
|
|
30
|
-
fontSize: '14px'
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
class AnswerFraction extends _react.default.Component {
|
|
34
|
-
constructor(...args) {
|
|
35
|
-
super(...args);
|
|
36
|
-
/**
|
|
37
|
-
* Function to trigger when value change from number selection
|
|
38
|
-
* @param {string} key contains event change object
|
|
39
|
-
* @returns updated answer change object
|
|
40
|
-
*/
|
|
41
|
-
(0, _defineProperty2.default)(this, "onValueChange", key => event => {
|
|
42
|
-
let value = parseInt(event?.target?.value);
|
|
43
|
-
const {
|
|
44
|
-
model,
|
|
45
|
-
onAnswerChange,
|
|
46
|
-
answers
|
|
47
|
-
} = this.props;
|
|
48
|
-
const newAnswers = {
|
|
49
|
-
...answers
|
|
50
|
-
};
|
|
51
|
-
const min = 1;
|
|
52
|
-
const max = key === 'noOfModel' ? model.maxModelSelected : 9;
|
|
53
|
-
if (value > max) {
|
|
54
|
-
value = max;
|
|
55
|
-
} else if (value < min) {
|
|
56
|
-
value = min;
|
|
57
|
-
}
|
|
58
|
-
newAnswers[key] = value;
|
|
59
|
-
onAnswerChange(newAnswers);
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
render() {
|
|
63
|
-
const {
|
|
64
|
-
model,
|
|
65
|
-
showCorrect,
|
|
66
|
-
answers,
|
|
67
|
-
disabled
|
|
68
|
-
} = this.props;
|
|
69
|
-
return /*#__PURE__*/_react.default.createElement("div", null, model.allowedStudentConfig && /*#__PURE__*/_react.default.createElement(GroupInline, null, /*#__PURE__*/_react.default.createElement(Group, null, /*#__PURE__*/_react.default.createElement(InputLabel, {
|
|
70
|
-
htmlFor: 'preview_number-of-models'
|
|
71
|
-
}, "Number of Models"), /*#__PURE__*/_react.default.createElement(StyledTextField, {
|
|
72
|
-
id: "preview_number-of-models",
|
|
73
|
-
inputProps: {
|
|
74
|
-
min: 1,
|
|
75
|
-
max: model.maxModelSelected
|
|
76
|
-
},
|
|
77
|
-
name: "preview_number-of-models",
|
|
78
|
-
onChange: this.onValueChange('noOfModel'),
|
|
79
|
-
type: "number",
|
|
80
|
-
variant: "outlined",
|
|
81
|
-
disabled: disabled,
|
|
82
|
-
value: showCorrect ? model.maxModelSelected : answers.noOfModel
|
|
83
|
-
})), /*#__PURE__*/_react.default.createElement(Group, null, /*#__PURE__*/_react.default.createElement(InputLabel, {
|
|
84
|
-
htmlFor: 'preview_parts-per-model'
|
|
85
|
-
}, "Parts per Model"), /*#__PURE__*/_react.default.createElement(StyledTextField, {
|
|
86
|
-
id: "preview_parts-per-model",
|
|
87
|
-
inputProps: {
|
|
88
|
-
min: 1,
|
|
89
|
-
max: 9
|
|
90
|
-
},
|
|
91
|
-
name: "preview_parts-per-model",
|
|
92
|
-
onChange: this.onValueChange('partsPerModel'),
|
|
93
|
-
type: "number",
|
|
94
|
-
variant: "outlined",
|
|
95
|
-
disabled: disabled,
|
|
96
|
-
value: showCorrect ? model.partsPerModel : answers.partsPerModel
|
|
97
|
-
}))));
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
exports.AnswerFraction = AnswerFraction;
|
|
101
|
-
(0, _defineProperty2.default)(AnswerFraction, "propTypes", {
|
|
102
|
-
model: _propTypes.default.object.isRequired,
|
|
103
|
-
disabled: _propTypes.default.bool.isRequired,
|
|
104
|
-
showCorrect: _propTypes.default.bool.isRequired,
|
|
105
|
-
onAnswerChange: _propTypes.default.func.isRequired,
|
|
106
|
-
answers: _propTypes.default.object.isRequired
|
|
107
|
-
});
|
|
108
|
-
var _default = exports.default = AnswerFraction;
|
|
109
|
-
//# sourceMappingURL=answer-fraction.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"answer-fraction.js","names":["_react","_interopRequireDefault","require","_propTypes","_styles","_material","GroupInline","styled","alignItems","display","gap","Group","margin","InputLabel","marginBottom","StyledTextField","TextField","width","maxHeight","height","fontSize","AnswerFraction","React","Component","constructor","args","_defineProperty2","default","key","event","value","parseInt","target","model","onAnswerChange","answers","props","newAnswers","min","max","maxModelSelected","render","showCorrect","disabled","createElement","allowedStudentConfig","htmlFor","id","inputProps","name","onChange","onValueChange","type","variant","noOfModel","partsPerModel","exports","PropTypes","object","isRequired","bool","func","_default"],"sources":["../src/answer-fraction.jsx"],"sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { styled } from '@mui/material/styles';\nimport { TextField } from '@mui/material';\n\nconst GroupInline = styled('div')({\n alignItems: 'center',\n display: 'flex',\n gap: '20px',\n});\n\nconst Group = styled('div')({\n margin: '12px 0',\n});\n\nconst InputLabel = styled('label')({\n display: 'block',\n marginBottom: '4px',\n});\n\nconst StyledTextField = styled(TextField)({\n width: '120px',\n maxHeight: '40px',\n '& [class^=\"MuiInputBase-root\"]': {\n height: 40,\n fontSize: '14px',\n },\n});\n\nexport class AnswerFraction extends React.Component {\n static propTypes = {\n model: PropTypes.object.isRequired,\n disabled: PropTypes.bool.isRequired,\n showCorrect: PropTypes.bool.isRequired,\n onAnswerChange: PropTypes.func.isRequired,\n answers: PropTypes.object.isRequired,\n };\n\n /**\n * Function to trigger when value change from number selection\n * @param {string} key contains event change object\n * @returns updated answer change object\n */\n onValueChange = (key) => (event) => {\n let value = parseInt(event?.target?.value);\n const { model, onAnswerChange, answers } = this.props;\n const newAnswers = { ...answers };\n const min = 1;\n const max = (key === 'noOfModel') ? model.maxModelSelected : 9;\n if(value > max) {\n value = max;\n } else if(value < min) {\n value = min;\n }\n newAnswers[key] = value;\n onAnswerChange(newAnswers);\n };\n\n render() {\n const { model, showCorrect, answers, disabled } = this.props;\n\n return (\n <div>\n {model.allowedStudentConfig && (\n <GroupInline>\n <Group>\n <InputLabel htmlFor={'preview_number-of-models'}>\n Number of Models\n </InputLabel>\n <StyledTextField\n id=\"preview_number-of-models\"\n inputProps={{ min: 1, max: model.maxModelSelected }}\n name=\"preview_number-of-models\"\n onChange={this.onValueChange('noOfModel')}\n type=\"number\"\n variant=\"outlined\"\n disabled={disabled}\n value={showCorrect ? model.maxModelSelected : answers.noOfModel}\n />\n </Group>\n <Group>\n <InputLabel htmlFor={'preview_parts-per-model'}>\n Parts per Model\n </InputLabel>\n <StyledTextField\n id=\"preview_parts-per-model\"\n inputProps={{ min: 1, max: 9 }}\n name=\"preview_parts-per-model\"\n onChange={this.onValueChange('partsPerModel')}\n type=\"number\"\n variant=\"outlined\"\n disabled={disabled}\n value={showCorrect ? model.partsPerModel : answers.partsPerModel}\n />\n </Group>\n </GroupInline>\n )}\n </div>\n );\n }\n}\n\nexport default AnswerFraction;\n"],"mappings":";;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,UAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,SAAA,GAAAH,OAAA;AAEA,MAAMI,WAAW,GAAG,IAAAC,cAAM,EAAC,KAAK,CAAC,CAAC;EAChCC,UAAU,EAAE,QAAQ;EACpBC,OAAO,EAAE,MAAM;EACfC,GAAG,EAAE;AACP,CAAC,CAAC;AAEF,MAAMC,KAAK,GAAG,IAAAJ,cAAM,EAAC,KAAK,CAAC,CAAC;EAC1BK,MAAM,EAAE;AACV,CAAC,CAAC;AAEF,MAAMC,UAAU,GAAG,IAAAN,cAAM,EAAC,OAAO,CAAC,CAAC;EACjCE,OAAO,EAAE,OAAO;EAChBK,YAAY,EAAE;AAChB,CAAC,CAAC;AAEF,MAAMC,eAAe,GAAG,IAAAR,cAAM,EAACS,mBAAS,CAAC,CAAC;EACxCC,KAAK,EAAE,OAAO;EACdC,SAAS,EAAE,MAAM;EACjB,gCAAgC,EAAE;IAChCC,MAAM,EAAE,EAAE;IACVC,QAAQ,EAAE;EACZ;AACF,CAAC,CAAC;AAEK,MAAMC,cAAc,SAASC,cAAK,CAACC,SAAS,CAAC;EAAAC,YAAA,GAAAC,IAAA;IAAA,SAAAA,IA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,MAAM,CAACC;AAC5B,CAAC;AAAA,IAAAG,QAAA,GAAAN,OAAA,CAAA7B,OAAA,GAkEYN,cAAc","ignoreList":[]}
|
|
@@ -1,279 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
-
var _recharts = require("recharts");
|
|
9
|
-
var _styles = require("@mui/material/styles");
|
|
10
|
-
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
11
|
-
const PieChartParentDiv = (0, _styles.styled)('div')({
|
|
12
|
-
display: 'grid',
|
|
13
|
-
gridTemplateColumns: '200px 200px 200px',
|
|
14
|
-
gap: '10px',
|
|
15
|
-
padding: '5px 0'
|
|
16
|
-
});
|
|
17
|
-
const BarChartParentDiv = (0, _styles.styled)('div')({
|
|
18
|
-
display: 'grid',
|
|
19
|
-
gridTemplateColumns: '200px 200px 200px',
|
|
20
|
-
gap: '20px',
|
|
21
|
-
padding: '10px 0'
|
|
22
|
-
});
|
|
23
|
-
const StyledPieChart = (0, _styles.styled)(_recharts.PieChart)({
|
|
24
|
-
'& .recharts-pie-sector': {
|
|
25
|
-
outline: 'none !important',
|
|
26
|
-
'&:focus': {
|
|
27
|
-
outline: 'none !important'
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
const FractionModelChart = props => {
|
|
32
|
-
/*
|
|
33
|
-
* Function to handle click event on chart
|
|
34
|
-
* @param chartIndex: index of the chart
|
|
35
|
-
* @param sectorIndex: index of the sector
|
|
36
|
-
* */
|
|
37
|
-
const handleChartClick = (chartIndex, sectorIndex) => {
|
|
38
|
-
if (typeof sectorIndex === 'string') {
|
|
39
|
-
sectorIndex = parseInt(sectorIndex);
|
|
40
|
-
}
|
|
41
|
-
const existingIndex = clickedIndexArray.findIndex(item => item.id === chartIndex);
|
|
42
|
-
let newClickedIndexArray;
|
|
43
|
-
if (existingIndex >= 0) {
|
|
44
|
-
const currentItem = clickedIndexArray[existingIndex];
|
|
45
|
-
if (currentItem.value === sectorIndex) {
|
|
46
|
-
newClickedIndexArray = clickedIndexArray.filter((_, index) => index !== existingIndex);
|
|
47
|
-
} else {
|
|
48
|
-
newClickedIndexArray = [...clickedIndexArray.slice(0, existingIndex), {
|
|
49
|
-
id: chartIndex,
|
|
50
|
-
value: sectorIndex
|
|
51
|
-
}, ...clickedIndexArray.slice(existingIndex + 1)];
|
|
52
|
-
}
|
|
53
|
-
} else {
|
|
54
|
-
newClickedIndexArray = [...clickedIndexArray, {
|
|
55
|
-
id: chartIndex,
|
|
56
|
-
value: sectorIndex
|
|
57
|
-
}];
|
|
58
|
-
}
|
|
59
|
-
onChange(newClickedIndexArray);
|
|
60
|
-
setClickedIndexArray(newClickedIndexArray);
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
/*
|
|
64
|
-
* Function to handle mouse enter event on chart
|
|
65
|
-
* @param chartIndex: index of the chart
|
|
66
|
-
* @param sectorIndex: index of the sector
|
|
67
|
-
* */
|
|
68
|
-
const handleChartMouseEnter = (chartIndex, sectorIndex) => {
|
|
69
|
-
setHoveredIndex(chartIndex + '-' + sectorIndex);
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
/*
|
|
73
|
-
* Function to handle mouse leave event on chart
|
|
74
|
-
* */
|
|
75
|
-
const handleChartMouseLeave = () => {
|
|
76
|
-
setHoveredIndex(null);
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
/*
|
|
80
|
-
* Function to get fill color for sector
|
|
81
|
-
* @param hoveredIndex: hovered index
|
|
82
|
-
* @param selection: selected index
|
|
83
|
-
* */
|
|
84
|
-
const getSectorFill = (hoveredIndex, selection) => {
|
|
85
|
-
const [selectionId, selectionValue] = selection.split('-').map(Number);
|
|
86
|
-
// Check for a matching clicked item
|
|
87
|
-
const clickedItem = clickedIndexArray.find(item => item.id === selectionId);
|
|
88
|
-
if (clickedItem && selectionValue <= clickedItem.value) {
|
|
89
|
-
return 'rgb(60, 73, 150, 0.6)';
|
|
90
|
-
}
|
|
91
|
-
// Check for a matching hovered index
|
|
92
|
-
if (hoveredIndex) {
|
|
93
|
-
const [hoveredId, hoveredValue] = hoveredIndex.split('-').map(Number);
|
|
94
|
-
if (hoveredId === selectionId && hoveredValue >= selectionValue) {
|
|
95
|
-
return 'rgb(0, 0, 0, 0.25)';
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
return '#FFFFFF';
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
/*
|
|
102
|
-
* Function to render label for pie chart
|
|
103
|
-
* @param props: properties of the label
|
|
104
|
-
* */
|
|
105
|
-
const renderCustomizedLabelForPie = props => {
|
|
106
|
-
const {
|
|
107
|
-
cx,
|
|
108
|
-
cy,
|
|
109
|
-
midAngle,
|
|
110
|
-
outerRadius,
|
|
111
|
-
index
|
|
112
|
-
} = props;
|
|
113
|
-
const RADIAN = Math.PI / 180;
|
|
114
|
-
// const radius = outerRadius * 0.5; //If you want to show label inside the pie
|
|
115
|
-
const radius = outerRadius * 1.13;
|
|
116
|
-
const x = cx + radius * Math.cos(-midAngle * RADIAN);
|
|
117
|
-
const y = cy + radius * Math.sin(-midAngle * RADIAN);
|
|
118
|
-
return /*#__PURE__*/_react.default.createElement("text", {
|
|
119
|
-
x: x,
|
|
120
|
-
y: y,
|
|
121
|
-
fill: "#000000",
|
|
122
|
-
textAnchor: x > cx ? 'start' : 'end',
|
|
123
|
-
dominantBaseline: "central"
|
|
124
|
-
}, `${(index + 1).toFixed(0)}`);
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
/*
|
|
128
|
-
* Function to create and return component for bar chart
|
|
129
|
-
* */
|
|
130
|
-
const barWithBorder = () => {
|
|
131
|
-
return props => {
|
|
132
|
-
const {
|
|
133
|
-
fill,
|
|
134
|
-
x,
|
|
135
|
-
y,
|
|
136
|
-
width,
|
|
137
|
-
height
|
|
138
|
-
} = props;
|
|
139
|
-
return /*#__PURE__*/_react.default.createElement("g", null, /*#__PURE__*/_react.default.createElement("rect", {
|
|
140
|
-
x: x,
|
|
141
|
-
y: y,
|
|
142
|
-
width: width,
|
|
143
|
-
height: height,
|
|
144
|
-
stroke: '#000000',
|
|
145
|
-
fill: fill
|
|
146
|
-
}));
|
|
147
|
-
};
|
|
148
|
-
};
|
|
149
|
-
const {
|
|
150
|
-
value = [],
|
|
151
|
-
modelType = 'bar',
|
|
152
|
-
noOfModels = 0,
|
|
153
|
-
partsPerModel = 0,
|
|
154
|
-
showLabel = false,
|
|
155
|
-
disabled = false,
|
|
156
|
-
onChange
|
|
157
|
-
} = props;
|
|
158
|
-
const [hoveredIndex, setHoveredIndex] = (0, _react.useState)(null);
|
|
159
|
-
const [clickedIndexArray, setClickedIndexArray] = (0, _react.useState)(value);
|
|
160
|
-
|
|
161
|
-
/*
|
|
162
|
-
* Function to create and return bar fraction model
|
|
163
|
-
* */
|
|
164
|
-
const getBarFractionModel = () => {
|
|
165
|
-
const parentData = [];
|
|
166
|
-
// Generate data for bar chart
|
|
167
|
-
for (let i = 1; i < noOfModels + 1; i++) {
|
|
168
|
-
const data = [{
|
|
169
|
-
name: i
|
|
170
|
-
}];
|
|
171
|
-
for (let j = 1; j < partsPerModel + 1; j++) {
|
|
172
|
-
data[0][`${j}`] = 1;
|
|
173
|
-
}
|
|
174
|
-
parentData.push(data);
|
|
175
|
-
}
|
|
176
|
-
let barItems = [];
|
|
177
|
-
parentData.forEach((data, chartIndex) => {
|
|
178
|
-
barItems.push(/*#__PURE__*/_react.default.createElement(_recharts.BarChart, {
|
|
179
|
-
width: 200,
|
|
180
|
-
height: 30 * partsPerModel,
|
|
181
|
-
data: data,
|
|
182
|
-
key: `bar-chart-${chartIndex + 1}`
|
|
183
|
-
}, /*#__PURE__*/_react.default.createElement(_recharts.YAxis, {
|
|
184
|
-
hide: true,
|
|
185
|
-
type: "number",
|
|
186
|
-
domain: [0, partsPerModel]
|
|
187
|
-
}), Object.keys(data[0]).map((key, index) => {
|
|
188
|
-
if (key !== 'name') {
|
|
189
|
-
return /*#__PURE__*/_react.default.createElement(_recharts.Bar, {
|
|
190
|
-
dataKey: key,
|
|
191
|
-
stackId: "a",
|
|
192
|
-
key: `bar-${chartIndex + 1}-${index + 1}`,
|
|
193
|
-
onClick: disabled ? null : () => handleChartClick(chartIndex + 1, key),
|
|
194
|
-
onMouseEnter: disabled ? null : () => handleChartMouseEnter(chartIndex + 1, key),
|
|
195
|
-
onMouseLeave: disabled ? null : () => handleChartMouseLeave(chartIndex + 1, key),
|
|
196
|
-
shape: barWithBorder(),
|
|
197
|
-
isAnimationActive: false,
|
|
198
|
-
fill: getSectorFill(hoveredIndex, `${chartIndex + 1}-${key}`)
|
|
199
|
-
}, showLabel && /*#__PURE__*/_react.default.createElement(_recharts.LabelList, {
|
|
200
|
-
position: "left",
|
|
201
|
-
fill: "#000000"
|
|
202
|
-
}));
|
|
203
|
-
}
|
|
204
|
-
})));
|
|
205
|
-
});
|
|
206
|
-
return /*#__PURE__*/_react.default.createElement(BarChartParentDiv, null, barItems);
|
|
207
|
-
};
|
|
208
|
-
const pieChartRef = (0, _react.useRef)(null);
|
|
209
|
-
|
|
210
|
-
/*
|
|
211
|
-
* Function to create and return pie fraction model
|
|
212
|
-
* */
|
|
213
|
-
const getPieFractionModel = () => {
|
|
214
|
-
const parentData = [];
|
|
215
|
-
// Generate data for pie chart
|
|
216
|
-
for (let i = 1; i < noOfModels + 1; i++) {
|
|
217
|
-
const data = Array.from({
|
|
218
|
-
length: partsPerModel
|
|
219
|
-
}, (_, index) => ({
|
|
220
|
-
name: `${index + 1}`,
|
|
221
|
-
value: 1
|
|
222
|
-
}));
|
|
223
|
-
parentData.push(data);
|
|
224
|
-
}
|
|
225
|
-
let pieItems = [];
|
|
226
|
-
parentData.forEach((data, chartIndex) => {
|
|
227
|
-
pieItems.push(/*#__PURE__*/_react.default.createElement(StyledPieChart, {
|
|
228
|
-
width: 200,
|
|
229
|
-
height: 200,
|
|
230
|
-
key: `pie-chart-${chartIndex}`
|
|
231
|
-
}, /*#__PURE__*/_react.default.createElement(_recharts.Pie, {
|
|
232
|
-
data: data,
|
|
233
|
-
key: `pie-${chartIndex + 1}`,
|
|
234
|
-
fill: "#FFFFFF",
|
|
235
|
-
stroke: "#000000",
|
|
236
|
-
dataKey: "value",
|
|
237
|
-
startAngle: 90,
|
|
238
|
-
endAngle: -270,
|
|
239
|
-
isAnimationActive: false,
|
|
240
|
-
labelLine: false,
|
|
241
|
-
label: showLabel && renderCustomizedLabelForPie
|
|
242
|
-
}, data.map((entry, sectorIndex) => /*#__PURE__*/_react.default.createElement(_recharts.Cell, {
|
|
243
|
-
key: `${chartIndex + 1}-${sectorIndex + 1}`,
|
|
244
|
-
onClick: disabled ? null : () => handleChartClick(chartIndex + 1, sectorIndex + 1),
|
|
245
|
-
onMouseEnter: disabled ? null : () => handleChartMouseEnter(chartIndex + 1, sectorIndex + 1),
|
|
246
|
-
onMouseLeave: disabled ? null : () => handleChartMouseLeave(chartIndex + 1, sectorIndex + 1),
|
|
247
|
-
fill: getSectorFill(hoveredIndex, `${chartIndex + 1}-${sectorIndex + 1}`),
|
|
248
|
-
style: {
|
|
249
|
-
outline: 'none',
|
|
250
|
-
cursor: disabled ? 'default' : 'pointer'
|
|
251
|
-
}
|
|
252
|
-
})))));
|
|
253
|
-
});
|
|
254
|
-
return /*#__PURE__*/_react.default.createElement(PieChartParentDiv, {
|
|
255
|
-
ref: pieChartRef
|
|
256
|
-
}, pieItems);
|
|
257
|
-
};
|
|
258
|
-
|
|
259
|
-
//Render bar or pie models as per model type
|
|
260
|
-
if (modelType === 'bar') {
|
|
261
|
-
return getBarFractionModel();
|
|
262
|
-
} else if (modelType === 'pie') {
|
|
263
|
-
//Remove the last sector line of pie chart if parts per model is 1
|
|
264
|
-
(0, _react.useEffect)(() => {
|
|
265
|
-
if (pieChartRef?.current && partsPerModel === 1) {
|
|
266
|
-
const paths = pieChartRef.current.querySelectorAll('path');
|
|
267
|
-
if (paths.length > 0) {
|
|
268
|
-
paths.forEach(path => {
|
|
269
|
-
let d = path.getAttribute('d');
|
|
270
|
-
path.setAttribute('d', d.replaceAll('L 100,100', ''));
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
}, []);
|
|
275
|
-
return getPieFractionModel();
|
|
276
|
-
}
|
|
277
|
-
};
|
|
278
|
-
var _default = exports.default = FractionModelChart;
|
|
279
|
-
//# sourceMappingURL=fraction-model-chart.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fraction-model-chart.js","names":["_react","_interopRequireWildcard","require","_recharts","_styles","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","PieChartParentDiv","styled","display","gridTemplateColumns","gap","padding","BarChartParentDiv","StyledPieChart","PieChart","outline","FractionModelChart","props","handleChartClick","chartIndex","sectorIndex","parseInt","existingIndex","clickedIndexArray","findIndex","item","id","newClickedIndexArray","currentItem","value","filter","_","index","slice","onChange","setClickedIndexArray","handleChartMouseEnter","setHoveredIndex","handleChartMouseLeave","getSectorFill","hoveredIndex","selection","selectionId","selectionValue","split","map","Number","clickedItem","find","hoveredId","hoveredValue","renderCustomizedLabelForPie","cx","cy","midAngle","outerRadius","RADIAN","Math","PI","radius","x","cos","y","sin","createElement","fill","textAnchor","dominantBaseline","toFixed","barWithBorder","width","height","stroke","modelType","noOfModels","partsPerModel","showLabel","disabled","useState","getBarFractionModel","parentData","data","name","j","push","barItems","forEach","BarChart","key","YAxis","hide","type","domain","keys","Bar","dataKey","stackId","onClick","onMouseEnter","onMouseLeave","shape","isAnimationActive","LabelList","position","pieChartRef","useRef","getPieFractionModel","Array","from","length","pieItems","Pie","startAngle","endAngle","labelLine","label","entry","Cell","style","cursor","ref","useEffect","current","paths","querySelectorAll","path","d","getAttribute","setAttribute","replaceAll","_default","exports"],"sources":["../src/fraction-model-chart.jsx"],"sourcesContent":["import React, { useState, useEffect, useRef } from 'react';\nimport { Bar, BarChart, Cell, LabelList, Pie, PieChart, YAxis } from 'recharts';\nimport { styled } from '@mui/material/styles';\n\nconst PieChartParentDiv = styled('div')({\n display: 'grid',\n gridTemplateColumns: '200px 200px 200px',\n gap: '10px',\n padding: '5px 0',\n});\n\nconst BarChartParentDiv = styled('div')({\n display: 'grid',\n gridTemplateColumns: '200px 200px 200px',\n gap: '20px',\n padding: '10px 0',\n});\n\nconst StyledPieChart = styled(PieChart)({\n '& .recharts-pie-sector': {\n outline: 'none !important',\n '&:focus': {\n outline: 'none !important',\n },\n },\n});\n\nconst FractionModelChart = (props) => {\n /*\n * Function to handle click event on chart\n * @param chartIndex: index of the chart\n * @param sectorIndex: index of the sector\n * */\n const handleChartClick = (chartIndex, sectorIndex) => {\n if (typeof sectorIndex === 'string') {\n sectorIndex = parseInt(sectorIndex);\n }\n const existingIndex = clickedIndexArray.findIndex((item) => item.id === chartIndex);\n let newClickedIndexArray;\n if (existingIndex >= 0) {\n const currentItem = clickedIndexArray[existingIndex];\n if (currentItem.value === sectorIndex) {\n newClickedIndexArray = clickedIndexArray.filter((_, index) => index !== existingIndex);\n } else {\n newClickedIndexArray = [\n ...clickedIndexArray.slice(0, existingIndex),\n { id: chartIndex, value: sectorIndex },\n ...clickedIndexArray.slice(existingIndex + 1),\n ];\n }\n } else {\n newClickedIndexArray = [...clickedIndexArray, { id: chartIndex, value: sectorIndex }];\n }\n onChange(newClickedIndexArray);\n setClickedIndexArray(newClickedIndexArray);\n };\n\n /*\n * Function to handle mouse enter event on chart\n * @param chartIndex: index of the chart\n * @param sectorIndex: index of the sector\n * */\n const handleChartMouseEnter = (chartIndex, sectorIndex) => {\n setHoveredIndex(chartIndex + '-' + sectorIndex);\n };\n\n /*\n * Function to handle mouse leave event on chart\n * */\n const handleChartMouseLeave = () => {\n setHoveredIndex(null);\n };\n\n /*\n * Function to get fill color for sector\n * @param hoveredIndex: hovered index\n * @param selection: selected index\n * */\n const getSectorFill = (hoveredIndex, selection) => {\n const [selectionId, selectionValue] = selection.split('-').map(Number);\n // Check for a matching clicked item\n const clickedItem = clickedIndexArray.find((item) => item.id === selectionId);\n if (clickedItem && selectionValue <= clickedItem.value) {\n return 'rgb(60, 73, 150, 0.6)';\n }\n // Check for a matching hovered index\n if (hoveredIndex) {\n const [hoveredId, hoveredValue] = hoveredIndex.split('-').map(Number);\n if (hoveredId === selectionId && hoveredValue >= selectionValue) {\n return 'rgb(0, 0, 0, 0.25)';\n }\n }\n return '#FFFFFF';\n };\n\n /*\n * Function to render label for pie chart\n * @param props: properties of the label\n * */\n const renderCustomizedLabelForPie = (props) => {\n const { cx, cy, midAngle, outerRadius, index } = props;\n const RADIAN = Math.PI / 180;\n // const radius = outerRadius * 0.5; //If you want to show label inside the pie\n const radius = outerRadius * 1.13;\n const x = cx + radius * Math.cos(-midAngle * RADIAN);\n const y = cy + radius * Math.sin(-midAngle * RADIAN);\n return (\n <text x={x} y={y} fill=\"#000000\" textAnchor={x > cx ? 'start' : 'end'} dominantBaseline=\"central\">\n {`${(index + 1).toFixed(0)}`}\n </text>\n );\n };\n\n /*\n * Function to create and return component for bar chart\n * */\n const barWithBorder = () => {\n return (props) => {\n const { fill, x, y, width, height } = props;\n return (\n <g>\n <rect x={x} y={y} width={width} height={height} stroke={'#000000'} fill={fill} />\n </g>\n );\n };\n };\n\n const {\n value = [],\n modelType = 'bar',\n noOfModels = 0,\n partsPerModel = 0,\n showLabel = false,\n disabled = false,\n onChange,\n } = props;\n const [hoveredIndex, setHoveredIndex] = useState(null);\n const [clickedIndexArray, setClickedIndexArray] = useState(value);\n\n /*\n * Function to create and return bar fraction model\n * */\n const getBarFractionModel = () => {\n const parentData = [];\n // Generate data for bar chart\n for (let i = 1; i < noOfModels + 1; i++) {\n const data = [{ name: i }];\n for (let j = 1; j < partsPerModel + 1; j++) {\n data[0][`${j}`] = 1;\n }\n parentData.push(data);\n }\n let barItems = [];\n parentData.forEach((data, chartIndex) => {\n barItems.push(\n <BarChart width={200} height={30 * partsPerModel} data={data} key={`bar-chart-${chartIndex + 1}`}>\n <YAxis hide={true} type=\"number\" domain={[0, partsPerModel]} />\n {Object.keys(data[0]).map((key, index) => {\n if (key !== 'name') {\n return (\n <Bar\n dataKey={key}\n stackId=\"a\"\n key={`bar-${chartIndex + 1}-${index + 1}`}\n onClick={disabled ? null : () => handleChartClick(chartIndex + 1, key)}\n onMouseEnter={disabled ? null : () => handleChartMouseEnter(chartIndex + 1, key)}\n onMouseLeave={disabled ? null : () => handleChartMouseLeave(chartIndex + 1, key)}\n shape={barWithBorder()}\n isAnimationActive={false}\n fill={getSectorFill(hoveredIndex, `${chartIndex + 1}-${key}`)}\n >\n {showLabel && <LabelList position=\"left\" fill=\"#000000\" />}\n </Bar>\n );\n }\n })}\n </BarChart>,\n );\n });\n return <BarChartParentDiv>{barItems}</BarChartParentDiv>;\n };\n\n const pieChartRef = useRef(null);\n \n /*\n * Function to create and return pie fraction model\n * */\n const getPieFractionModel = () => {\n const parentData = [];\n // Generate data for pie chart\n for (let i = 1; i < noOfModels + 1; i++) {\n const data = Array.from({ length: partsPerModel }, (_, index) => ({\n name: `${index + 1}`,\n value: 1,\n }));\n parentData.push(data);\n }\n let pieItems = [];\n parentData.forEach((data, chartIndex) => {\n pieItems.push(\n <StyledPieChart width={200} height={200} key={`pie-chart-${chartIndex}`}>\n <Pie\n data={data}\n key={`pie-${chartIndex + 1}`}\n fill=\"#FFFFFF\"\n stroke=\"#000000\"\n dataKey=\"value\"\n startAngle={90}\n endAngle={-270}\n isAnimationActive={false}\n labelLine={false}\n label={showLabel && renderCustomizedLabelForPie}\n >\n {data.map((entry, sectorIndex) => (\n <Cell\n key={`${chartIndex + 1}-${sectorIndex + 1}`}\n onClick={disabled ? null : () => handleChartClick(chartIndex + 1, sectorIndex + 1)}\n onMouseEnter={disabled ? null : () => handleChartMouseEnter(chartIndex + 1, sectorIndex + 1)}\n onMouseLeave={disabled ? null : () => handleChartMouseLeave(chartIndex + 1, sectorIndex + 1)}\n fill={getSectorFill(hoveredIndex, `${chartIndex + 1}-${sectorIndex + 1}`)}\n style={{ outline: 'none', cursor: disabled ? 'default' : 'pointer' }}\n />\n ))}\n </Pie>\n </StyledPieChart>,\n );\n });\n return <PieChartParentDiv ref={pieChartRef}>{pieItems}</PieChartParentDiv>;\n };\n\n //Render bar or pie models as per model type\n if (modelType === 'bar') {\n return getBarFractionModel();\n } else if (modelType === 'pie') {\n //Remove the last sector line of pie chart if parts per model is 1\n useEffect(() => {\n if (pieChartRef?.current && partsPerModel === 1){\n const paths = pieChartRef.current.querySelectorAll('path');\n if (paths.length > 0) {\n paths.forEach((path) => {\n let d = path.getAttribute('d');\n path.setAttribute('d', d.replaceAll('L 100,100', ''));\n });\n }\n }\n }, []);\n return getPieFractionModel();\n }\n};\n\nexport default FractionModelChart;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AAA8C,SAAAD,wBAAAI,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAN,uBAAA,YAAAA,CAAAI,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,U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AAC,EAAE,EAAE,CAAC;IACN,OAAOvB,mBAAmB,CAAC,CAAC;EAC9B;AACF,CAAC;AAAC,IAAAwB,QAAA,GAAAC,OAAA,CAAAtI,OAAA,GAEamB,kBAAkB","ignoreList":[]}
|
package/lib/index.js
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
Object.defineProperty(exports, "FractionModelChart", {
|
|
8
|
-
enumerable: true,
|
|
9
|
-
get: function () {
|
|
10
|
-
return _fractionModelChart.default;
|
|
11
|
-
}
|
|
12
|
-
});
|
|
13
|
-
exports.default = void 0;
|
|
14
|
-
var _react = _interopRequireDefault(require("react"));
|
|
15
|
-
var _client = require("react-dom/client");
|
|
16
|
-
var _piePlayerEvents = require("@pie-framework/pie-player-events");
|
|
17
|
-
var _main = _interopRequireDefault(require("./main"));
|
|
18
|
-
var _lodashEs = require("lodash-es");
|
|
19
|
-
var _mathRendering = require("@pie-lib/math-rendering");
|
|
20
|
-
var _fractionModelChart = _interopRequireDefault(require("./fraction-model-chart"));
|
|
21
|
-
// Export FractionModelChart for use in configure
|
|
22
|
-
|
|
23
|
-
class FractionModel extends HTMLElement {
|
|
24
|
-
constructor() {
|
|
25
|
-
super();
|
|
26
|
-
this._root = null;
|
|
27
|
-
}
|
|
28
|
-
set model(m) {
|
|
29
|
-
this._model = m;
|
|
30
|
-
this._render();
|
|
31
|
-
}
|
|
32
|
-
get model() {
|
|
33
|
-
return this._model;
|
|
34
|
-
}
|
|
35
|
-
set session(s) {
|
|
36
|
-
this._session = s;
|
|
37
|
-
this._render();
|
|
38
|
-
}
|
|
39
|
-
get session() {
|
|
40
|
-
return this._session;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/*
|
|
44
|
-
* Method to check if student answered the question
|
|
45
|
-
* @param {session} session contains the session object
|
|
46
|
-
* @param {model} model contains the model object
|
|
47
|
-
* */
|
|
48
|
-
isSessionComplete(session, model) {
|
|
49
|
-
const answers = session && session.answers;
|
|
50
|
-
const configComplete = model.allowedStudentConfig ? answers.noOfModel > 0 && answers.partsPerModel > 0 : true;
|
|
51
|
-
const responseComplete = Array.isArray(answers.response) && answers.response.length > 0;
|
|
52
|
-
return configComplete && responseComplete;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/*
|
|
56
|
-
* Session change event handler
|
|
57
|
-
* @param {session} session contains the session object
|
|
58
|
-
* */
|
|
59
|
-
onSessionChange(session) {
|
|
60
|
-
this._session.answers = session && session.answers;
|
|
61
|
-
const complete = this.isSessionComplete(this._session, this._model);
|
|
62
|
-
this.dispatchEvent(new _piePlayerEvents.SessionChangedEvent(this.tagName.toLowerCase(), complete));
|
|
63
|
-
}
|
|
64
|
-
connectedCallback() {
|
|
65
|
-
this._render();
|
|
66
|
-
}
|
|
67
|
-
_render() {
|
|
68
|
-
if (this._model && this._session) {
|
|
69
|
-
let model = (0, _lodashEs.cloneDeep)(this._model);
|
|
70
|
-
const el = /*#__PURE__*/_react.default.createElement(_main.default, {
|
|
71
|
-
model,
|
|
72
|
-
session: this._session,
|
|
73
|
-
onSessionChange: this.onSessionChange.bind(this)
|
|
74
|
-
});
|
|
75
|
-
if (!this._root) {
|
|
76
|
-
this._root = (0, _client.createRoot)(this);
|
|
77
|
-
}
|
|
78
|
-
this._root.render(el);
|
|
79
|
-
queueMicrotask(() => {
|
|
80
|
-
(0, _mathRendering.renderMath)(this);
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
disconnectedCallback() {
|
|
85
|
-
if (this._root) {
|
|
86
|
-
this._root.unmount();
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
exports.default = FractionModel;
|
|
91
|
-
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_react","_interopRequireDefault","require","_client","_piePlayerEvents","_main","_lodashEs","_mathRendering","_fractionModelChart","FractionModel","HTMLElement","constructor","_root","model","m","_model","_render","session","s","_session","isSessionComplete","answers","configComplete","allowedStudentConfig","noOfModel","partsPerModel","responseComplete","Array","isArray","response","length","onSessionChange","complete","dispatchEvent","SessionChangedEvent","tagName","toLowerCase","connectedCallback","cloneDeep","el","React","createElement","Main","bind","createRoot","render","queueMicrotask","renderMath","disconnectedCallback","unmount","exports","default"],"sources":["../src/index.js"],"sourcesContent":["import React from 'react';\nimport { createRoot } from 'react-dom/client';\nimport { SessionChangedEvent } from '@pie-framework/pie-player-events';\nimport Main from './main';\nimport { cloneDeep } from 'lodash-es';\nimport { renderMath } from '@pie-lib/math-rendering';\nimport FractionModelChart from './fraction-model-chart';\n\n// Export FractionModelChart for use in configure\nexport { FractionModelChart };\n\nexport default class FractionModel extends HTMLElement {\n constructor() {\n super();\n this._root = null;\n }\n\n set model(m) {\n this._model = m;\n this._render();\n }\n\n get model() {\n return this._model;\n }\n\n set session(s) {\n this._session = s;\n this._render();\n }\n\n get session() {\n return this._session;\n }\n\n /*\n * Method to check if student answered the question\n * @param {session} session contains the session object\n * @param {model} model contains the model object\n * */\n isSessionComplete(session, model) {\n const answers = session && session.answers;\n const configComplete = model.allowedStudentConfig ? answers.noOfModel > 0 && answers.partsPerModel > 0 : true;\n const responseComplete = Array.isArray(answers.response) && answers.response.length > 0;\n return configComplete && responseComplete;\n }\n\n /*\n * Session change event handler\n * @param {session} session contains the session object\n * */\n onSessionChange(session) {\n this._session.answers = session && session.answers;\n const complete = this.isSessionComplete(this._session, this._model);\n this.dispatchEvent(new SessionChangedEvent(this.tagName.toLowerCase(), complete));\n }\n\n connectedCallback() {\n this._render();\n }\n\n _render() {\n if (this._model && this._session) {\n let model = cloneDeep(this._model);\n const el = React.createElement(Main, {\n model,\n session: this._session,\n onSessionChange: this.onSessionChange.bind(this),\n });\n\n if (!this._root) {\n this._root = createRoot(this);\n }\n this._root.render(el);\n queueMicrotask(() => {\n renderMath(this);\n });\n }\n }\n\n disconnectedCallback() {\n if (this._root) {\n this._root.unmount();\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,gBAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,SAAA,GAAAJ,OAAA;AACA,IAAAK,cAAA,GAAAL,OAAA;AACA,IAAAM,mBAAA,GAAAP,sBAAA,CAAAC,OAAA;AAEA;;AAGe,MAAMO,aAAa,SAASC,WAAW,CAAC;EACrDC,WAAWA,CAAA,EAAG;IACZ,KAAK,CAAC,CAAC;IACP,IAAI,CAACC,KAAK,GAAG,IAAI;EACnB;EAEA,IAAIC,KAAKA,CAACC,CAAC,EAAE;IACX,IAAI,CAACC,MAAM,GAAGD,CAAC;IACf,IAAI,CAACE,OAAO,CAAC,CAAC;EAChB;EAEA,IAAIH,KAAKA,CAAA,EAAG;IACV,OAAO,IAAI,CAACE,MAAM;EACpB;EAEA,IAAIE,OAAOA,CAACC,CAAC,EAAE;IACb,IAAI,CAACC,QAAQ,GAAGD,CAAC;IACjB,IAAI,CAACF,OAAO,CAAC,CAAC;EAChB;EAEA,IAAIC,OAAOA,CAAA,EAAG;IACZ,OAAO,IAAI,CAACE,QAAQ;EACtB;;EAEA;AACF;AACA;AACA;AACA;EACEC,iBAAiBA,CAACH,OAAO,EAAEJ,KAAK,EAAE;IAChC,MAAMQ,OAAO,GAAGJ,OAAO,IAAIA,OAAO,CAACI,OAAO;IAC1C,MAAMC,cAAc,GAAGT,KAAK,CAACU,oBAAoB,GAAGF,OAAO,CAACG,SAAS,GAAG,CAAC,IAAIH,OAAO,CAACI,aAAa,GAAG,CAAC,GAAG,IAAI;IAC7G,M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