@pie-element/fraction-model 6.2.2-beta.4 → 6.2.2-beta.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/configure/CHANGELOG.md +8 -0
- package/configure/package.json +3 -3
- package/controller/CHANGELOG.md +8 -0
- package/controller/package.json +1 -1
- package/package.json +3 -3
- 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 -164
- 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/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/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 -92
- package/lib/index.js.map +0 -1
- package/lib/main.js +0 -203
- package/lib/main.js.map +0 -1
package/controller/lib/index.js
DELETED
|
@@ -1,215 +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.validate = exports.outcome = exports.model = exports.getResponseCorrectness = exports.createDefaultModel = exports.createCorrectResponseSession = void 0;
|
|
8
|
-
var _lodashEs = require("lodash-es");
|
|
9
|
-
var _defaults = _interopRequireDefault(require("./defaults"));
|
|
10
|
-
/*
|
|
11
|
-
* Function to check the correctness of the response
|
|
12
|
-
* @param {model} model contains the model object
|
|
13
|
-
* @param {answers} answers contains the answers object
|
|
14
|
-
* @param {env} env contains the environment object
|
|
15
|
-
* @returns {string} returns the correctness of the response
|
|
16
|
-
* */
|
|
17
|
-
const getResponseCorrectness = (model, answers, env = {}) => {
|
|
18
|
-
let correct;
|
|
19
|
-
if (model.allowedStudentConfig) {
|
|
20
|
-
correct = !!(answers.partsPerModel === model.partsPerModel && partialFillCheck(answers.response, model.partsPerModel) && numeratorCheck(model.correctResponse, answers.response));
|
|
21
|
-
} else {
|
|
22
|
-
correct = !!(partialFillCheck(answers.response, model.partsPerModel) && numeratorCheck(model.correctResponse, answers.response));
|
|
23
|
-
}
|
|
24
|
-
return correct ? 'correct' : 'incorrect';
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
/*
|
|
28
|
-
* Function to get the correctness of the response
|
|
29
|
-
* @param {question} question contains the question object
|
|
30
|
-
* @param {env} env contains the environment object
|
|
31
|
-
* @param {answers} answers contains the answers object
|
|
32
|
-
* @returns {string} returns the correctness
|
|
33
|
-
* */
|
|
34
|
-
exports.getResponseCorrectness = getResponseCorrectness;
|
|
35
|
-
const getCorrectness = (question, env, answers = {}) => {
|
|
36
|
-
if (env.mode === 'evaluate') {
|
|
37
|
-
return getResponseCorrectness(question, answers, env);
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
/*
|
|
42
|
-
* Function to get the outcome score
|
|
43
|
-
* @param {question} question contains the question object
|
|
44
|
-
* @param {env} env contains the environment object
|
|
45
|
-
* @param {answers} answers contains the answers object
|
|
46
|
-
* @returns {number} returns the score
|
|
47
|
-
* */
|
|
48
|
-
const getOutComeScore = (question, env, answers = {}) => {
|
|
49
|
-
const correctness = getCorrectness(question, env, answers);
|
|
50
|
-
return correctness === 'correct' ? 1 : 0;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
/*
|
|
54
|
-
* Function to check outcome of the session
|
|
55
|
-
* @param {model} model contains the model object
|
|
56
|
-
* @param {session} session contains the session object
|
|
57
|
-
* @param {env} env contains the environment object
|
|
58
|
-
* @returns {Promise} returns the score
|
|
59
|
-
*/
|
|
60
|
-
const outcome = (model, session, env) => new Promise(resolve => {
|
|
61
|
-
if (!session || (0, _lodashEs.isEmpty)(session)) {
|
|
62
|
-
resolve({
|
|
63
|
-
score: 0,
|
|
64
|
-
empty: true
|
|
65
|
-
});
|
|
66
|
-
} else {
|
|
67
|
-
if (env.mode !== 'evaluate') {
|
|
68
|
-
resolve({
|
|
69
|
-
score: undefined,
|
|
70
|
-
completed: undefined
|
|
71
|
-
});
|
|
72
|
-
} else {
|
|
73
|
-
resolve({
|
|
74
|
-
score: getOutComeScore(model, env, session.answers)
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
/*
|
|
81
|
-
* Function to check if the numerator of the response matches the numerator of the correct response
|
|
82
|
-
* @param {correctResponse} correctResponse contains the correct response object
|
|
83
|
-
* @param {response} response contains the response object
|
|
84
|
-
* @returns {boolean} returns true if the numerators match
|
|
85
|
-
* */
|
|
86
|
-
exports.outcome = outcome;
|
|
87
|
-
const numeratorCheck = (correctResponse, response) => {
|
|
88
|
-
let correctNumerator = 0;
|
|
89
|
-
let responseNumerator = 0;
|
|
90
|
-
for (let i = 0; i < correctResponse.length; i++) {
|
|
91
|
-
correctNumerator += correctResponse[i].value;
|
|
92
|
-
}
|
|
93
|
-
for (let i = 0; i < response.length; i++) {
|
|
94
|
-
responseNumerator += response[i].value;
|
|
95
|
-
}
|
|
96
|
-
return correctNumerator === responseNumerator;
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
/*
|
|
100
|
-
* Function to check if the response contains more than one partially-filled model
|
|
101
|
-
* @param {response} response contains the response object
|
|
102
|
-
* @param {partsPerModel} partsPerModel contains the number of parts per model
|
|
103
|
-
* */
|
|
104
|
-
const partialFillCheck = (response, partsPerModel) => {
|
|
105
|
-
if (response.length > 0) {
|
|
106
|
-
let partialModelCount = 0;
|
|
107
|
-
response.forEach(selection => {
|
|
108
|
-
if (selection.value !== partsPerModel) {
|
|
109
|
-
partialModelCount++;
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
return partialModelCount <= 1;
|
|
113
|
-
} else {
|
|
114
|
-
return false;
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
/*
|
|
119
|
-
* Function to create a default model
|
|
120
|
-
* @param {model} model contains the model object
|
|
121
|
-
* */
|
|
122
|
-
const createDefaultModel = (model = {}) => ({
|
|
123
|
-
..._defaults.default.model,
|
|
124
|
-
...model
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
/*
|
|
128
|
-
* Return the model object
|
|
129
|
-
* */
|
|
130
|
-
exports.createDefaultModel = createDefaultModel;
|
|
131
|
-
const model = (question, session, env) => {
|
|
132
|
-
return new Promise(resolve => {
|
|
133
|
-
session = session || {};
|
|
134
|
-
const model = createDefaultModel(question);
|
|
135
|
-
let correctness, score;
|
|
136
|
-
if ((!session || (0, _lodashEs.isEmpty)(session)) && env.mode === 'evaluate') {
|
|
137
|
-
correctness = 'unanswered';
|
|
138
|
-
score = '0%';
|
|
139
|
-
} else {
|
|
140
|
-
correctness = getCorrectness(model, env, session && session.answers);
|
|
141
|
-
score = `${getOutComeScore(model, env, session && session.answers) * 100}%`;
|
|
142
|
-
}
|
|
143
|
-
const correctInfo = {
|
|
144
|
-
score,
|
|
145
|
-
correctness
|
|
146
|
-
};
|
|
147
|
-
const out = {
|
|
148
|
-
env,
|
|
149
|
-
...model,
|
|
150
|
-
view: env.mode === 'view' || env.mode === 'evaluate'
|
|
151
|
-
};
|
|
152
|
-
if (env.mode === 'evaluate') {
|
|
153
|
-
Object.assign(out, {
|
|
154
|
-
correctness: correctInfo
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
resolve(out);
|
|
158
|
-
});
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
/*
|
|
162
|
-
* Function to create a correct response session
|
|
163
|
-
* @param {model} model contains the model object
|
|
164
|
-
* @param {env} env contains the environment object
|
|
165
|
-
* @returns {Promise} returns the correct response session
|
|
166
|
-
* */
|
|
167
|
-
exports.model = model;
|
|
168
|
-
const createCorrectResponseSession = (model, env) => {
|
|
169
|
-
return new Promise(resolve => {
|
|
170
|
-
if (env.mode !== 'evaluate' && env.role === 'instructor') {
|
|
171
|
-
const {
|
|
172
|
-
correctResponse,
|
|
173
|
-
maxModelSelected,
|
|
174
|
-
partsPerModel
|
|
175
|
-
} = model;
|
|
176
|
-
resolve({
|
|
177
|
-
answers: {
|
|
178
|
-
response: correctResponse,
|
|
179
|
-
noOfModel: maxModelSelected,
|
|
180
|
-
partsPerModel
|
|
181
|
-
},
|
|
182
|
-
id: '1'
|
|
183
|
-
});
|
|
184
|
-
} else {
|
|
185
|
-
resolve(null);
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
/*
|
|
191
|
-
* Function to validate the model
|
|
192
|
-
* @param {model} model contains the model object
|
|
193
|
-
* @param {config} config contains the config object
|
|
194
|
-
* */
|
|
195
|
-
exports.createCorrectResponseSession = createCorrectResponseSession;
|
|
196
|
-
const validate = (model = {}, config = {}) => {
|
|
197
|
-
const errors = {};
|
|
198
|
-
if (model.correctResponse.length === 0) {
|
|
199
|
-
errors.correctResponse = 'To save the item, at least one section must be marked as correct.';
|
|
200
|
-
}
|
|
201
|
-
if (model.correctResponse.length > 0) {
|
|
202
|
-
let partialModelCount = 0;
|
|
203
|
-
model.correctResponse.forEach(selection => {
|
|
204
|
-
if (selection.value !== model.partsPerModel) {
|
|
205
|
-
partialModelCount++;
|
|
206
|
-
}
|
|
207
|
-
});
|
|
208
|
-
if (partialModelCount > 1) {
|
|
209
|
-
errors.correctResponse = 'The correct answer should include no more than one partially-filled model';
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
return errors;
|
|
213
|
-
};
|
|
214
|
-
exports.validate = validate;
|
|
215
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_lodashEs","require","_defaults","_interopRequireDefault","getResponseCorrectness","model","answers","env","correct","allowedStudentConfig","partsPerModel","partialFillCheck","response","numeratorCheck","correctResponse","exports","getCorrectness","question","mode","getOutComeScore","correctness","outcome","session","Promise","resolve","isEmpty","score","empty","undefined","completed","correctNumerator","responseNumerator","i","length","value","partialModelCount","forEach","selection","createDefaultModel","defaults","correctInfo","out","view","Object","assign","createCorrectResponseSession","role","maxModelSelected","noOfModel","id","validate","config","errors"],"sources":["../src/index.js"],"sourcesContent":["import { isEmpty } from 'lodash-es';\nimport defaults from './defaults';\n\n/*\n * Function to check the correctness of the response\n * @param {model} model contains the model object\n * @param {answers} answers contains the answers object\n * @param {env} env contains the environment object\n * @returns {string} returns the correctness of the response\n * */\nexport const getResponseCorrectness = (model, answers, env = {}) => {\n let correct;\n if (model.allowedStudentConfig) {\n correct = !!(\n answers.partsPerModel === model.partsPerModel &&\n partialFillCheck(answers.response, model.partsPerModel) &&\n numeratorCheck(model.correctResponse, answers.response)\n );\n } else {\n correct = !!(\n partialFillCheck(answers.response, model.partsPerModel) && numeratorCheck(model.correctResponse, answers.response)\n );\n }\n return correct ? 'correct' : 'incorrect';\n};\n\n/*\n * Function to get the correctness of the response\n * @param {question} question contains the question object\n * @param {env} env contains the environment object\n * @param {answers} answers contains the answers object\n * @returns {string} returns the correctness\n * */\nconst getCorrectness = (question, env, answers = {}) => {\n if (env.mode === 'evaluate') {\n return getResponseCorrectness(question, answers, env);\n }\n};\n\n/*\n * Function to get the outcome score\n * @param {question} question contains the question object\n * @param {env} env contains the environment object\n * @param {answers} answers contains the answers object\n * @returns {number} returns the score\n * */\nconst getOutComeScore = (question, env, answers = {}) => {\n const correctness = getCorrectness(question, env, answers);\n return correctness === 'correct' ? 1 : 0;\n};\n\n/*\n * Function to check outcome of the session\n * @param {model} model contains the model object\n * @param {session} session contains the session object\n * @param {env} env contains the environment object\n * @returns {Promise} returns the score\n */\nexport const outcome = (model, session, env) =>\n new Promise((resolve) => {\n if (!session || isEmpty(session)) {\n resolve({ score: 0, empty: true });\n } else {\n if (env.mode !== 'evaluate') {\n resolve({ score: undefined, completed: undefined });\n } else {\n resolve({ score: getOutComeScore(model, env, session.answers) });\n }\n }\n });\n\n/*\n * Function to check if the numerator of the response matches the numerator of the correct response\n * @param {correctResponse} correctResponse contains the correct response object\n * @param {response} response contains the response object\n * @returns {boolean} returns true if the numerators match\n * */\nconst numeratorCheck = (correctResponse, response) => {\n let correctNumerator = 0;\n let responseNumerator = 0;\n for (let i = 0; i < correctResponse.length; i++) {\n correctNumerator += correctResponse[i].value;\n }\n for (let i = 0; i < response.length; i++) {\n responseNumerator += response[i].value;\n }\n return correctNumerator === responseNumerator;\n};\n\n/*\n * Function to check if the response contains more than one partially-filled model\n * @param {response} response contains the response object\n * @param {partsPerModel} partsPerModel contains the number of parts per model\n * */\nconst partialFillCheck = (response, partsPerModel) => {\n if (response.length > 0) {\n let partialModelCount = 0;\n response.forEach((selection) => {\n if (selection.value !== partsPerModel) {\n partialModelCount++;\n }\n });\n return partialModelCount <= 1;\n } else {\n return false;\n }\n};\n\n/*\n * Function to create a default model\n * @param {model} model contains the model object\n * */\nexport const createDefaultModel = (model = {}) => ({\n ...defaults.model,\n ...model,\n});\n\n/*\n * Return the model object\n * */\nexport const model = (question, session, env) => {\n return new Promise((resolve) => {\n session = session || {};\n const model = createDefaultModel(question);\n let correctness, score;\n if ((!session || isEmpty(session)) && env.mode === 'evaluate') {\n correctness = 'unanswered';\n score = '0%';\n } else {\n correctness = getCorrectness(model, env, session && session.answers);\n score = `${getOutComeScore(model, env, session && session.answers) * 100}%`;\n }\n const correctInfo = {\n score,\n correctness,\n };\n const out = {\n env,\n ...model,\n view: env.mode === 'view' || env.mode === 'evaluate',\n };\n if (env.mode === 'evaluate') {\n Object.assign(out, {\n correctness: correctInfo,\n });\n }\n resolve(out);\n });\n};\n\n/*\n * Function to create a correct response session\n * @param {model} model contains the model object\n * @param {env} env contains the environment object\n * @returns {Promise} returns the correct response session\n * */\nexport const createCorrectResponseSession = (model, env) => {\n return new Promise((resolve) => {\n if (env.mode !== 'evaluate' && env.role === 'instructor') {\n const { correctResponse, maxModelSelected, partsPerModel } = model;\n resolve({\n answers: {\n response: correctResponse,\n noOfModel: maxModelSelected,\n partsPerModel,\n },\n id: '1',\n });\n } else {\n resolve(null);\n }\n });\n};\n\n/*\n * Function to validate the model\n * @param {model} model contains the model object\n * @param {config} config contains the config object\n * */\nexport const validate = (model = {}, config = {}) => {\n const errors = {};\n if (model.correctResponse.length === 0) {\n errors.correctResponse = 'To save the item, at least one section must be marked as correct.';\n }\n if (model.correctResponse.length > 0) {\n let partialModelCount = 0;\n model.correctResponse.forEach((selection) => {\n if (selection.value !== model.partsPerModel) {\n partialModelCount++;\n }\n });\n if (partialModelCount > 1) {\n errors.correctResponse = 'The correct answer should include no more than one partially-filled model';\n }\n }\n return errors;\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,SAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAC,sBAAA,CAAAF,OAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMG,sBAAsB,GAAGA,CAACC,KAAK,EAAEC,OAAO,EAAEC,GAAG,GAAG,CAAC,CAAC,KAAK;EAClE,IAAIC,OAAO;EACX,IAAIH,KAAK,CAACI,oBAAoB,EAAE;IAC9BD,OAAO,GAAG,CAAC,EACTF,OAAO,CAACI,aAAa,KAAKL,KAAK,CAACK,aAAa,IAC7CC,gBAAgB,CAACL,OAAO,CAACM,QAAQ,EAAEP,KAAK,CAACK,aAAa,CAAC,IACvDG,cAAc,CAACR,KAAK,CAACS,eAAe,EAAER,OAAO,CAACM,QAAQ,CAAC,CACxD;EACH,CAAC,MAAM;IACLJ,OAAO,GAAG,CAAC,EACTG,gBAAgB,CAACL,OAAO,CAACM,Q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CAAAmC,QAAA,GAAAA,QAAA","ignoreList":[]}
|
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 AnswerFra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C/B,UAAU;MAACiC,OAAO,EAAE;IAA0B,GAAC,iBAEpC,CAAC,eACb9C,MAAA,CAAA2B,OAAA,CAAAiB,aAAA,CAAC7B,eAAe;MACdgC,EAAE,EAAC,yBAAyB;MAC5BC,UAAU,EAAE;QAAEV,GAAG,EAAE,CAAC;QAAEC,GAAG,EAAE;MAAE,CAAE;MAC/BU,IAAI,EAAC,yBAAyB;MAC9BC,QAAQ,EAAE,IAAI,CAACC,aAAa,CAAC,eAAe,CAAE;MAC9CC,IAAI,EAAC,QAAQ;MACbC,OAAO,EAAC,UAAU;MAClBV,QAAQ,EAAEA,QAAS;MACnBb,KAAK,EAAEY,WAAW,GAAGT,KAAK,CAACsB,aAAa,GAAGpB,OAAO,CAACoB;IAAc,CAClE,CACI,CACI,CAEZ,CAAC;EAEV;AACF;AAACC,OAAA,CAAAnC,cAAA,GAAAA,cAAA;AAAA,IAAAK,gBAAA,CAAAC,OAAA,EAvEYN,cAAc,eACN;EACjBY,KAAK,EAAEwB,kBAAS,CAACC,MAAM,CAACC,UAAU;EAClChB,QAAQ,EAAEc,kBAAS,CAACG,IAAI,CAACD,UAAU;EACnCjB,WAAW,EAAEe,kBAAS,CAACG,IAAI,CAACD,UAAU;EACtCzB,cAAc,EAAEuB,kBAAS,CAACI,IAAI,CAACF,UAAU;EACzCxB,OAAO,EAAEsB,kBAAS,CAACC,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
|