@pie-element/charting 12.2.2-beta.6 → 12.2.2-beta.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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["_react","_interopRequireDefault","require","_client","_pieConfigureEvents","_debug","_configure","_defaults","_mathRendering","log","debug","GraphLinesConfigure","HTMLElement","constructor","_root","_model","createDefaultModel","_configuration","defaultValues","configuration","model","m","_render","c","newConfiguration","language","enabled","languageChoices","options","length","value","settings","find","option","push","label","onModelChanged","dispatchEvent","ModelUpdatedEvent","onConfigurationChanged","config","insertImage","handler","InsertImageEvent","onDeleteImage","src","done","DeleteImageEvent","insertSound","InsertSoundEvent","onDeleteSound","DeleteSoundEvent","el","React","createElement","Configure","bind","imageSupport","add","delete","uploadSoundSupport","createRoot","render","queueMicrotask","renderMath","connectedCallback","disconnectedCallback","unmount","exports","default","_defineProperty2"],"sources":["../src/index.js"],"sourcesContent":["import React from 'react';\nimport { createRoot } from 'react-dom/client';\nimport {\n ModelUpdatedEvent,\n DeleteImageEvent,\n InsertImageEvent,\n InsertSoundEvent,\n DeleteSoundEvent,\n} from '@pie-framework/pie-configure-events';\nimport debug from 'debug';\nimport Configure from './configure';\nimport defaultValues from './defaults';\nimport { renderMath } from '@pie-lib/math-rendering';\n\nconst log = debug('pie-elements:graphing:configure');\n\nexport default class GraphLinesConfigure extends HTMLElement {\n static createDefaultModel = (model = {}) => ({ ...defaultValues.model, ...model });\n\n constructor() {\n super();\n this._root = null;\n this._model = GraphLinesConfigure.createDefaultModel();\n this._configuration = defaultValues.configuration;\n }\n\n set model(m) {\n this._model = GraphLinesConfigure.createDefaultModel(m);\n this._render();\n }\n\n set configuration(c) {\n const newConfiguration = {\n ...defaultValues.configuration,\n ...c,\n };\n\n this._configuration = newConfiguration;\n\n // if language:enabled is true, then the corresponding default item model should include a language value;\n // if it is false, then the language field should be omitted from the item model.\n // if a default item model includes a language value (e.g., en_US) and the corresponding authoring view settings have language:settings = true,\n // then (a) language:enabled should also be true, and (b) that default language value should be represented in languageChoices[] (as a key).\n if (newConfiguration?.language?.enabled) {\n if (newConfiguration?.languageChoices?.options?.length) {\n this._model.language = newConfiguration?.languageChoices.options[0].value;\n }\n } else if (newConfiguration.language.settings && this._model.language) {\n this._configuration.language.enabled = true;\n\n if (!this._configuration.languageChoices.options || !this._configuration.languageChoices.options.length) {\n this._configuration.languageChoices.options = [];\n }\n\n // check if the language is already included in the languageChoices.options array\n // and if not, then add it.\n if (!this._configuration.languageChoices.options.find((option) => option.value === this._model.language)) {\n this._configuration.languageChoices.options.push({\n value: this._model.language,\n label: this._model.language,\n });\n }\n } else {\n delete this._model.language;\n }\n\n this._render();\n }\n\n onModelChanged(model) {\n this._model = model;\n this._render();\n\n log('[onModelChanged]: ', this._model);\n\n this.dispatchEvent(new ModelUpdatedEvent(this._model));\n }\n\n onConfigurationChanged(config) {\n this._configuration = config;\n this._render();\n }\n\n insertImage(handler) {\n this.dispatchEvent(new InsertImageEvent(handler));\n }\n\n onDeleteImage(src, done) {\n this.dispatchEvent(new DeleteImageEvent(src, done));\n }\n\n insertSound(handler) {\n this.dispatchEvent(new InsertSoundEvent(handler));\n }\n\n onDeleteSound(src, done) {\n this.dispatchEvent(new DeleteSoundEvent(src, done));\n }\n\n _render() {\n if (this._model) {\n const el = React.createElement(Configure, {\n onModelChanged: this.onModelChanged.bind(this),\n onConfigurationChanged: this.onConfigurationChanged.bind(this),\n model: this._model,\n configuration: this._configuration,\n imageSupport: {\n add: this.insertImage.bind(this),\n delete: this.onDeleteImage.bind(this),\n },\n uploadSoundSupport: {\n add: this.insertSound.bind(this),\n delete: this.onDeleteSound.bind(this),\n },\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 connectedCallback() {\n this._render();\n }\n\n disconnectedCallback() {\n if (this._root) {\n this._root.unmount();\n this._root = null;\n }\n }\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,CAAC/C,KAAK,CAACgD,MAAM,CAACV,EAAE,CAAC;MACrBW,cAAc,CAAC,MAAM;QACnB,IAAAC,yBAAU,EAAC,IAAI,CAAC;MAClB,CAAC,CAAC;IACJ;EACF;EAEAC,iBAAiBA,CAAA,EAAG;IAClB,IAAI,CAAC3C,OAAO,CAAC,CAAC;EAChB;EAEA4C,oBAAoBA,CAAA,EAAG;IACrB,IAAI,IAAI,CAACpD,KAAK,EAAE;MACd,IAAI,CAACA,KAAK,CAACqD,OAAO,CAAC,CAAC;MACpB,IAAI,CAACrD,KAAK,GAAG,IAAI;IACnB;EACF;AACF;AAACsD,OAAA,CAAAC,OAAA,GAAA1D,mBAAA;AAAA,IAAA2D,gBAAA,CAAAD,OAAA,EAxHoB1D,mBAAmB,wBACV,CAACS,KAAK,GAAG,CAAC,CAAC,MAAM;EAAE,GAAGF,iBAAa,CAACE,KAAK;EAAE,GAAGA;AAAM,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getLabelValues = exports.getGridValues = exports.applyConstraints = exports.VALID_LABEL_VALUES = void 0;
7
+ var _lodashEs = require("lodash-es");
8
+ // this file is almost duplicated from graphing/configure/src/utils.js; the same logic must be used in charting
9
+
10
+ const VALID_GRID_VALUES = [0.01, 0.02, 0.04, 0.05, 0.0625, 0.1, 0.125, 0.2, 0.25, 0.5, 1, 2, 3, 4, 5, 8, 10, 12, 15, 20, 40, 50, 64, 100, 500, 1000];
11
+
12
+ // same as VALID_GRID_VALUES but next values are excluded: 0.04, 0.0625, 0.125, 3, 4, 8, 12, 15, 40, 64
13
+ const PREFERRED_VALID_GRID_VALUES = [0.01, 0.02, 0.05, 0.1, 0.2, 0.25, 0.5, 1, 2, 5, 10, 20, 50, 100, 500, 1000];
14
+ const VALID_LABEL_VALUES = exports.VALID_LABEL_VALUES = {
15
+ 0.01: [0, 0.01, 0.02, 0.04, 0.05, 0.1],
16
+ 0.02: [0, 0.02, 0.04, 0.1],
17
+ 0.04: [0, 0.04, 0.08, 0.16, 0.2],
18
+ 0.05: [0, 0.05, 0.1, 0.2, 0.25],
19
+ 0.0625: [0, 0.0625, 0.125, 0.25, 0.5],
20
+ 0.1: [0, 0.1, 0.2, 0.4, 0.5, 1],
21
+ 0.125: [0, 0.125, 0.25, 0.5, 1],
22
+ 0.2: [0, 0.2, 0.5, 0.1],
23
+ 0.25: [0, 0.25, 0.5, 1, 2],
24
+ 0.5: [0, 0.5, 1, 2],
25
+ 1: [0, 1, 2, 4, 5, 10],
26
+ 2: [0, 2, 4, 8, 10],
27
+ 3: [0, 3, 6, 12, 15],
28
+ 4: [0, 4, 8, 16, 20],
29
+ 5: [0, 5, 10, 20, 25],
30
+ 8: [0, 8, 16, 32, 40, 64],
31
+ 10: [0, 10, 20, 40, 50, 100],
32
+ 12: [0, 12, 24],
33
+ 15: [0, 15, 30, 60],
34
+ 20: [0, 20, 40, 80, 100],
35
+ 40: [0, 40, 80, 160, 200],
36
+ 50: [0, 50, 100, 200, 250],
37
+ 64: [0, 64, 128],
38
+ 100: [0, 100, 200, 400, 500],
39
+ 500: [0, 500, 1000, 2500],
40
+ 1000: [0, 1000, 2000, 4000, 5000]
41
+ };
42
+ const getGridValues = (axis, size, prefferedValues = false) => {
43
+ const minValue = 10 * (axis.max - axis.min) / size;
44
+ const maxValue = minValue * 10;
45
+
46
+ // if preferred values should be used enforce all values to be used if the axis step
47
+ // is included in all supported values and not included in preferred values
48
+ const useAllValues = prefferedValues && !PREFERRED_VALID_GRID_VALUES.includes(axis.step) && VALID_GRID_VALUES.includes(axis.step);
49
+ const values = !prefferedValues || useAllValues ? VALID_GRID_VALUES : PREFERRED_VALID_GRID_VALUES;
50
+ return values.filter(value => value >= minValue && value <= maxValue);
51
+ };
52
+ exports.getGridValues = getGridValues;
53
+ const getLabelValues = value => VALID_LABEL_VALUES[value] || [];
54
+ exports.getLabelValues = getLabelValues;
55
+ const applyConstraints = (axis, size, oldGridValues, oldLabelValues) => {
56
+ const gridValues = getGridValues(axis, size);
57
+ let labelValues = getLabelValues(axis.step || 1);
58
+ if (!(0, _lodashEs.isEqual)(oldGridValues, gridValues) && !gridValues.includes(axis.step)) {
59
+ const preferredValues = getGridValues(axis, size, true);
60
+ const lowestValue = preferredValues[0] || 1;
61
+ axis.step = lowestValue;
62
+ labelValues = getLabelValues(lowestValue);
63
+ if (!labelValues.includes(axis.labelStep)) {
64
+ axis.labelStep = lowestValue;
65
+ }
66
+ return {
67
+ gridValues,
68
+ labelValues
69
+ };
70
+ }
71
+ if (!(0, _lodashEs.isEqual)(oldLabelValues, labelValues) && !labelValues.includes(axis.labelStep)) {
72
+ axis.labelStep = axis.step;
73
+ }
74
+ return {
75
+ gridValues,
76
+ labelValues
77
+ };
78
+ };
79
+ exports.applyConstraints = applyConstraints;
80
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","names":["_lodashEs","require","VALID_GRID_VALUES","PREFERRED_VALID_GRID_VALUES","VALID_LABEL_VALUES","exports","getGridValues","axis","size","prefferedValues","minValue","max","min","maxValue","useAllValues","includes","step","values","filter","value","getLabelValues","applyConstraints","oldGridValues","oldLabelValues","gridValues","labelValues","isEqual","preferredValues","lowestValue","labelStep"],"sources":["../src/utils.js"],"sourcesContent":["// this file is almost duplicated from graphing/configure/src/utils.js; the same logic must be used in charting\nimport { isEqual } from 'lodash-es';\n\nconst VALID_GRID_VALUES = [\n 0.01, 0.02, 0.04, 0.05, 0.0625, 0.1, 0.125, 0.2, 0.25, 0.5, 1, 2, 3, 4, 5, 8, 10, 12, 15, 20, 40, 50, 64, 100, 500,\n 1000,\n];\n\n// same as VALID_GRID_VALUES but next values are excluded: 0.04, 0.0625, 0.125, 3, 4, 8, 12, 15, 40, 64\nconst PREFERRED_VALID_GRID_VALUES = [0.01, 0.02, 0.05, 0.1, 0.2, 0.25, 0.5, 1, 2, 5, 10, 20, 50, 100, 500, 1000];\n\nexport const VALID_LABEL_VALUES = {\n 0.01: [0, 0.01, 0.02, 0.04, 0.05, 0.1],\n 0.02: [0, 0.02, 0.04, 0.1],\n 0.04: [0, 0.04, 0.08, 0.16, 0.2],\n 0.05: [0, 0.05, 0.1, 0.2, 0.25],\n 0.0625: [0, 0.0625, 0.125, 0.25, 0.5],\n 0.1: [0, 0.1, 0.2, 0.4, 0.5, 1],\n 0.125: [0, 0.125, 0.25, 0.5, 1],\n 0.2: [0, 0.2, 0.5, 0.1],\n 0.25: [0, 0.25, 0.5, 1, 2],\n 0.5: [0, 0.5, 1, 2],\n 1: [0, 1, 2, 4, 5, 10],\n 2: [0, 2, 4, 8, 10],\n 3: [0, 3, 6, 12, 15],\n 4: [0, 4, 8, 16, 20],\n 5: [0, 5, 10, 20, 25],\n 8: [0, 8, 16, 32, 40, 64],\n 10: [0, 10, 20, 40, 50, 100],\n 12: [0, 12, 24],\n 15: [0, 15, 30, 60],\n 20: [0, 20, 40, 80, 100],\n 40: [0, 40, 80, 160, 200],\n 50: [0, 50, 100, 200, 250],\n 64: [0, 64, 128],\n 100: [0, 100, 200, 400, 500],\n 500: [0, 500, 1000, 2500],\n 1000: [0, 1000, 2000, 4000, 5000],\n};\n\nexport const getGridValues = (axis, size, prefferedValues = false) => {\n const minValue = (10 * (axis.max - axis.min)) / size;\n const maxValue = minValue * 10;\n\n // if preferred values should be used enforce all values to be used if the axis step\n // is included in all supported values and not included in preferred values\n const useAllValues =\n prefferedValues && !PREFERRED_VALID_GRID_VALUES.includes(axis.step) && VALID_GRID_VALUES.includes(axis.step);\n const values = !prefferedValues || useAllValues ? VALID_GRID_VALUES : PREFERRED_VALID_GRID_VALUES;\n\n return values.filter((value) => value >= minValue && value <= maxValue);\n};\n\nexport const getLabelValues = (value) => VALID_LABEL_VALUES[value] || [];\n\nexport const applyConstraints = (axis, size, oldGridValues, oldLabelValues) => {\n const gridValues = getGridValues(axis, size);\n let labelValues = getLabelValues(axis.step || 1);\n\n if (!isEqual(oldGridValues, gridValues) && !gridValues.includes(axis.step)) {\n const preferredValues = getGridValues(axis, size, true);\n const lowestValue = preferredValues[0] || 1;\n\n axis.step = lowestValue;\n labelValues = getLabelValues(lowestValue);\n\n if (!labelValues.includes(axis.labelStep)) {\n axis.labelStep = lowestValue;\n }\n\n return { gridValues, labelValues };\n }\n\n if (!isEqual(oldLabelValues, labelValues) && !labelValues.includes(axis.labelStep)) {\n axis.labelStep = axis.step;\n }\n\n return { gridValues, labelValues };\n};\n"],"mappings":";;;;;;AACA,IAAAA,SAAA,GAAAC,OAAA;AADA;;AAGA,MAAMC,iBAAiB,GAAG,CACxB,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,EAClH,IAAI,CACL;;AAED;AACA,MAAMC,2BAA2B,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC;AAEzG,MAAMC,kBAAkB,GAAAC,OAAA,CAAAD,kBAAA,GAAG;EAChC,IAAI,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,CAAC;EACtC,IAAI,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,CAAC;EAC1B,IAAI,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EA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pC,CAAC;AAACpB,OAAA,CAAAgB,gBAAA,GAAAA,gBAAA","ignoreList":[]}
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pie-element/charting-configure",
3
3
  "private": true,
4
- "version": "11.4.0-beta.12",
4
+ "version": "11.4.0-beta.13",
5
5
  "description": "",
6
6
  "main": "lib/index.js",
7
7
  "module": "src/index.js",
@@ -12,9 +12,9 @@
12
12
  "@mui/icons-material": "^7.3.4",
13
13
  "@mui/material": "^7.3.4",
14
14
  "@pie-framework/pie-configure-events": "^1.3.0",
15
- "@pie-lib/charting": "7.0.22-beta.1",
16
- "@pie-lib/config-ui": "13.0.22-beta.1",
17
- "@pie-lib/editable-html-tip-tap": "2.1.20-beta.1",
15
+ "@pie-lib/charting": "7.0.22-beta.2",
16
+ "@pie-lib/config-ui": "13.0.22-beta.2",
17
+ "@pie-lib/editable-html-tip-tap": "2.1.20-beta.2",
18
18
  "@pie-lib/math-rendering": "5.1.0",
19
19
  "@pie-lib/render-ui": "6.1.3",
20
20
  "debug": "^4.1.1",
@@ -3,6 +3,10 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [8.4.0-beta.13](https://github.com/pie-framework/pie-elements/compare/@pie-element/charting-controller@8.4.0-beta.12...@pie-element/charting-controller@8.4.0-beta.13) (2026-09-24)
7
+
8
+ **Note:** Version bump only for package @pie-element/charting-controller
9
+
6
10
  # [8.4.0-beta.12](https://github.com/pie-framework/pie-elements/compare/@pie-element/charting-controller@8.4.0-beta.11...@pie-element/charting-controller@8.4.0-beta.12) (2026-09-24)
7
11
 
8
12
  **Note:** Version bump only for package @pie-element/charting-controller
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ /**
8
+ * NOTE: There's no functionality described for graphTitle,
9
+ * rationale, scoringType, studentInstructions, teacherInstructions
10
+ * so there's no implementation (they are only added in model)
11
+ */
12
+ var _default = exports.default = {
13
+ addCategoryEnabled: true,
14
+ changeAddCategoryEnabled: false,
15
+ changeEditableEnabled: false,
16
+ changeInteractiveEnabled: false,
17
+ chartType: 'lineCross',
18
+ correctAnswer: {},
19
+ data: [],
20
+ domain: {},
21
+ graph: {
22
+ width: 480,
23
+ height: 480
24
+ },
25
+ prompt: '',
26
+ promptEnabled: true,
27
+ range: {
28
+ label: '',
29
+ max: 1,
30
+ min: 0,
31
+ labelStep: 1
32
+ },
33
+ rationale: '',
34
+ rationaleEnabled: true,
35
+ scoringType: 'all or nothing',
36
+ studentInstructionsEnabled: true,
37
+ studentNewCategoryDefaultLabel: 'New Category',
38
+ teacherInstructions: '',
39
+ teacherInstructionsEnabled: true,
40
+ title: ''
41
+ };
42
+ //# sourceMappingURL=defaults.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defaults.js","names":["_default","exports","default","addCategoryEnabled","changeAddCategoryEnabled","changeEditableEnabled","changeInteractiveEnabled","chartType","correctAnswer","data","domain","graph","width","height","prompt","promptEnabled","range","label","max","min","labelStep","rationale","rationaleEnabled","scoringType","studentInstructionsEnabled","studentNewCategoryDefaultLabel","teacherInstructions","teacherInstructionsEnabled","title"],"sources":["../src/defaults.js"],"sourcesContent":["/**\n * NOTE: There's no functionality described for graphTitle,\n * rationale, scoringType, studentInstructions, teacherInstructions\n * so there's no implementation (they are only added in model)\n */\n\nexport default {\n addCategoryEnabled: true,\n changeAddCategoryEnabled: false,\n changeEditableEnabled: false,\n changeInteractiveEnabled: false,\n chartType: 'lineCross',\n correctAnswer: {},\n data: [],\n domain: {},\n graph: { width: 480, height: 480 },\n prompt: '',\n promptEnabled: true,\n range: { label: '', max: 1, min: 0, labelStep: 1 },\n rationale: '',\n rationaleEnabled: true,\n scoringType: 'all or nothing',\n studentInstructionsEnabled: true,\n studentNewCategoryDefaultLabel: 'New Category',\n teacherInstructions: '',\n teacherInstructionsEnabled: true,\n title: '',\n};\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AAJA,IAAAA,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAMe;EACbC,kBAAkB,EAAE,IAAI;EACxBC,wBAAwB,EAAE,KAAK;EAC/BC,qBAAqB,EAAE,KAAK;EAC5BC,wBAAwB,EAAE,KAAK;EAC/BC,SAAS,EAAE,WAAW;EACtBC,aAAa,EAAE,CAAC,CAAC;EACjBC,IAAI,EAAE,EAAE;EACRC,MAAM,EAAE,CAAC,CAAC;EACVC,KAAK,EAAE;IAAEC,KAAK,EAAE,GAAG;IAAEC,MAAM,EAAE;EAAI,CAAC;EAClCC,MAAM,EAAE,EAAE;EACVC,aAAa,EAAE,IAAI;EACnBC,KAAK,EAAE;IAAEC,KAAK,EAAE,EAAE;IAAEC,GAAG,EAAE,CAAC;IAAEC,GAAG,EAAE,CAAC;IAAEC,SAAS,EAAE;EAAE,CAAC;EAClDC,SAAS,EAAE,EAAE;EACbC,gBAAgB,EAAE,IAAI;EACtBC,WAAW,EAAE,gBAAgB;EAC7BC,0BAA0B,EAAE,IAAI;EAChCC,8BAA8B,EAAE,cAAc;EAC9CC,mBAAmB,EAAE,EAAE;EACvBC,0BAA0B,EAAE,IAAI;EAChCC,KAAK,EAAE;AACT,CAAC","ignoreList":[]}
@@ -0,0 +1,434 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.getScore = exports.getLogTrace = exports.filterCategories = exports.createCorrectResponseSession = exports.checkLabelsEquality = void 0;
8
+ exports.model = model;
9
+ exports.normalize = void 0;
10
+ exports.outcome = outcome;
11
+ exports.validate = exports.setCorrectness = void 0;
12
+ var _debug = _interopRequireDefault(require("debug"));
13
+ var _lodashEs = require("lodash-es");
14
+ var _defaults = _interopRequireDefault(require("./defaults"));
15
+ var _controllerUtils = require("@pie-lib/controller-utils");
16
+ const log = (0, _debug.default)('@pie-element:graphing:controller');
17
+ const lowerCase = string => (string || '').toLowerCase();
18
+ const checkLabelsEquality = (givenAnswerLabel, correctAnswerLabel) => lowerCase(givenAnswerLabel) === lowerCase(correctAnswerLabel);
19
+ exports.checkLabelsEquality = checkLabelsEquality;
20
+ const setCorrectness = (answers, partialScoring) => answers ? answers.map(answer => ({
21
+ ...answer,
22
+ correctness: {
23
+ value: partialScoring ? 'incorrect' : 'correct',
24
+ label: partialScoring ? 'incorrect' : 'correct'
25
+ }
26
+ })) : [];
27
+ exports.setCorrectness = setCorrectness;
28
+ const normalize = question => ({
29
+ ..._defaults.default,
30
+ ...question
31
+ });
32
+ exports.normalize = normalize;
33
+ const getScore = (question, session, env = {}) => {
34
+ const {
35
+ correctAnswer,
36
+ data: initialData = [],
37
+ scoringType
38
+ } = question;
39
+ let correctResponses = [];
40
+ const isPartialScoring = _controllerUtils.partialScoring.enabled({
41
+ partialScoring: scoringType !== undefined ? scoringType === 'partial scoring' : scoringType
42
+ }, env);
43
+ const {
44
+ data: correctAnswers = []
45
+ } = correctAnswer || {};
46
+ const defaultAnswers = filterCategories(initialData);
47
+ let answers = setCorrectness(session && session.answer || defaultAnswers, isPartialScoring);
48
+ let result = 0;
49
+ if (isPartialScoring) {
50
+ // if score type is "partial scoring"
51
+ // maxScore is calculated based on the correct response
52
+ // score is calculated based on the given response
53
+ let maxScore = 0;
54
+ let score = 0;
55
+ const scoreForLabelAndValueEditable = (answer, corrAnswer) => {
56
+ const {
57
+ value,
58
+ label,
59
+ index
60
+ } = answer;
61
+ const valueIsCorrect = value === corrAnswer.value;
62
+ const labelIsCorrect = checkLabelsEquality(label, corrAnswer.label);
63
+ maxScore += 2;
64
+ if (valueIsCorrect) {
65
+ score += 1;
66
+ answer.correctness.value = 'correct';
67
+ }
68
+ if (labelIsCorrect) {
69
+ score += 1;
70
+ answer.correctness.label = 'correct';
71
+ }
72
+ if (valueIsCorrect && labelIsCorrect) {
73
+ correctResponses.push({
74
+ label: label,
75
+ index: index
76
+ });
77
+ }
78
+ };
79
+
80
+ // if given answer has more categories than the correct answers, the "extra" will be ignored
81
+ correctAnswers.forEach((corrAnswer, index) => {
82
+ const defaultAnswer = defaultAnswers[index];
83
+ const answer = answers[index];
84
+
85
+ // if there is a corresponding category at the same position in the given answer
86
+ if (answer) {
87
+ // if there is a corresponding category at the same position in the default answer
88
+ if (defaultAnswer) {
89
+ // if category's label (in default answer) was not editable
90
+ // it means that this category values only one point (only the value can be changed)
91
+ if (!defaultAnswer.editable && answer.interactive) {
92
+ maxScore += 1;
93
+ if (answer.value === corrAnswer.value) {
94
+ score += 1;
95
+ answer.correctness.value = 'correct';
96
+ correctResponses.push({
97
+ label: answer.label,
98
+ index: index
99
+ });
100
+ }
101
+ answer.correctness.label = 'correct';
102
+
103
+ // if category's label (in default answer) was editable
104
+ // it means that this category values 2 points (both label and value can be changed)
105
+ } else if (defaultAnswer.editable && answer.interactive) {
106
+ scoreForLabelAndValueEditable(answer, corrAnswer);
107
+ } else if (!answer.interactive) {
108
+ answer.correctness.value = 'correct';
109
+ answer.correctness.label = 'correct';
110
+ correctResponses.push({
111
+ label: answer.label,
112
+ index: index
113
+ });
114
+ }
115
+ } else {
116
+ // if there is not a corresponding category at the same position in the default answer
117
+ scoreForLabelAndValueEditable(answer, corrAnswer);
118
+ }
119
+ } else {
120
+ // if there is not a corresponding category at the same position in the given answer
121
+ // it means that the given answer has less categories than the correct answer
122
+ maxScore += 2;
123
+ }
124
+ });
125
+ result = maxScore ? score / maxScore : 0;
126
+ } else {
127
+ // all-or-nothing scoring: overall score is 1 only if lengths and all values/labels match
128
+ result = correctAnswers.length === answers.length ? 1 : 0;
129
+
130
+ // regardless of overall result, mark each answer individually for user feedback
131
+ answers = answers.map((answer, index) => {
132
+ const correctAnswer = correctAnswers[index];
133
+ const valueIsCorrect = correctAnswer ? answer.value === correctAnswer.value : false;
134
+ const labelIsCorrect = correctAnswer ? lowerCase(answer.label) === lowerCase(correctAnswer.label) : false;
135
+ if (!valueIsCorrect || !labelIsCorrect) {
136
+ result = 0;
137
+ }
138
+ if (valueIsCorrect && labelIsCorrect) {
139
+ correctResponses.push({
140
+ label: answer.label,
141
+ index
142
+ });
143
+ }
144
+ return {
145
+ ...answer,
146
+ correctness: {
147
+ value: valueIsCorrect ? 'correct' : 'incorrect',
148
+ label: labelIsCorrect ? 'correct' : 'incorrect'
149
+ }
150
+ };
151
+ });
152
+ }
153
+ const score = {
154
+ score: parseFloat(result.toFixed(2)),
155
+ answers
156
+ };
157
+ if (env.extraProps && env.extraProps.correctResponseEnabled) {
158
+ score.correctResponses = correctResponses;
159
+ }
160
+ return score;
161
+ };
162
+
163
+ /**
164
+ * Generates detailed trace log for scoring evaluation
165
+ * @param {Object} model - the question model
166
+ * @param {Object} session - the student session
167
+ * @param {Object} env - the environment
168
+ * @returns {Array} traceLog - array of trace messages
169
+ */
170
+ exports.getScore = getScore;
171
+ const getLogTrace = (model, session, env) => {
172
+ const traceLog = [];
173
+ const {
174
+ correctAnswer,
175
+ data: initialData = [],
176
+ scoringType
177
+ } = model || {};
178
+ const {
179
+ data: correctAnswers = []
180
+ } = correctAnswer || {};
181
+ const studentAnswers = session && session.answer || [];
182
+ const isPartialScoring = _controllerUtils.partialScoring.enabled({
183
+ partialScoring: scoringType !== undefined ? scoringType === 'partial scoring' : scoringType
184
+ }, env);
185
+ const defaultAnswers = filterCategories(initialData);
186
+ const answers = studentAnswers.length > 0 ? filterCategories(studentAnswers) : defaultAnswers;
187
+ if (!studentAnswers.length) {
188
+ traceLog.push(`Student did not modify the chart. Initial chart is scored.`);
189
+ }
190
+ correctAnswers.forEach((correct, index) => {
191
+ const initial = defaultAnswers[index];
192
+ const student = answers[index];
193
+ if (!student) {
194
+ traceLog.push(`Category ${index + 1}: missing (expected value '${correct.value}', label '${correct.label}').`);
195
+ return;
196
+ }
197
+ const valueCorrect = student.value === correct.value;
198
+ const labelCorrect = checkLabelsEquality(student.label, correct.label);
199
+ if (!student.interactive) {
200
+ traceLog.push(`Category ${index + 1}: non-interactive category treated as correct.`);
201
+ return;
202
+ }
203
+ if (studentAnswers.length > 0) {
204
+ const valueChanged = initial ? student.value !== initial.value : true;
205
+ const labelChanged = initial ? !checkLabelsEquality(student.label, initial.label) : true;
206
+ if (!valueChanged && !labelChanged) {
207
+ if (valueCorrect && labelCorrect) {
208
+ traceLog.push(`Category ${index + 1}: unchanged from initial value and correct.`);
209
+ } else {
210
+ traceLog.push(`Category ${index + 1}: unchanged from initial value but incorrect.`);
211
+ }
212
+ return;
213
+ }
214
+ const parts = [];
215
+ if (valueChanged) {
216
+ parts.push(`value ${valueCorrect ? 'correct' : 'incorrect'}`);
217
+ }
218
+ if (labelChanged) {
219
+ parts.push(`label ${labelCorrect ? 'correct' : 'incorrect'}`);
220
+ }
221
+ traceLog.push(`Category ${index + 1}: modified - ${parts.join(', ')}.`);
222
+ } else {
223
+ if (valueCorrect && labelCorrect) {
224
+ traceLog.push(`Category ${index + 1}: initial values are correct.`);
225
+ } else if (valueCorrect) {
226
+ traceLog.push(`Category ${index + 1}: initial value correct, label incorrect.`);
227
+ } else if (labelCorrect) {
228
+ traceLog.push(`Category ${index + 1}: initial value incorrect, label correct.`);
229
+ } else {
230
+ traceLog.push(`Category ${index + 1}: initial value and label incorrect.`);
231
+ }
232
+ }
233
+ });
234
+ if (answers.length > correctAnswers.length) {
235
+ const extra = answers.length - correctAnswers.length;
236
+ traceLog.push(`${extra} extra category(ies) provided beyond expected number.`);
237
+ }
238
+ if (isPartialScoring) {
239
+ traceLog.push('Score calculated using partial scoring.');
240
+ traceLog.push('Student receives credit for each correct value and label independently.');
241
+ } else {
242
+ traceLog.push('Score calculated using all-or-nothing scoring.');
243
+ traceLog.push('Student must match all category values and labels exactly for full credit.');
244
+ }
245
+ const scoreObject = getScore(model, session, env);
246
+ traceLog.push(`Score: ${scoreObject.score}.`);
247
+ return traceLog;
248
+ };
249
+
250
+ // eslint-disable-next-line no-unused-vars
251
+ exports.getLogTrace = getLogTrace;
252
+ const filterCategories = categories => categories ? categories.map(({
253
+ deletable,
254
+ ...rest
255
+ }) => rest) : [];
256
+ exports.filterCategories = filterCategories;
257
+ function model(question, session, env) {
258
+ return new Promise(resolve => {
259
+ const normalizedQuestion = normalize(question);
260
+ const {
261
+ addCategoryEnabled,
262
+ chartType,
263
+ data,
264
+ domain,
265
+ graph,
266
+ prompt,
267
+ promptEnabled,
268
+ range,
269
+ rationale,
270
+ title,
271
+ rationaleEnabled,
272
+ teacherInstructions,
273
+ teacherInstructionsEnabled,
274
+ correctAnswer,
275
+ scoringType,
276
+ studentNewCategoryDefaultLabel,
277
+ language,
278
+ extraCSSRules
279
+ } = normalizedQuestion;
280
+ const correctInfo = {
281
+ correctness: 'incorrect',
282
+ score: '0%'
283
+ };
284
+ const base = {
285
+ addCategoryEnabled,
286
+ chartType,
287
+ data: filterCategories(data),
288
+ domain,
289
+ graph,
290
+ prompt: promptEnabled ? prompt : null,
291
+ range,
292
+ rationale,
293
+ title,
294
+ size: graph,
295
+ showToggle: false,
296
+ correctness: correctInfo,
297
+ disabled: env.mode !== 'gather',
298
+ scoringType,
299
+ studentNewCategoryDefaultLabel,
300
+ language,
301
+ env,
302
+ extraCSSRules
303
+ };
304
+ const scoreObject = getScore(normalizedQuestion, session, env);
305
+ const answers = filterCategories(scoreObject.answers);
306
+ if (env.mode === 'view') {
307
+ // eslint-disable-next-line no-unused-vars
308
+ base.correctedAnswer = answers.map(({
309
+ correctness,
310
+ ...rest
311
+ }) => {
312
+ return {
313
+ ...rest,
314
+ interactive: false
315
+ };
316
+ });
317
+ base.addCategoryEnabled = false;
318
+ }
319
+ if (env.mode === 'evaluate') {
320
+ base.correctedAnswer = answers;
321
+ base.correctAnswer = correctAnswer;
322
+ base.showToggle = !!correctAnswer?.data?.length && scoreObject.score !== 1;
323
+ base.addCategoryEnabled = false;
324
+ base.showKeyLegend = true;
325
+ }
326
+ if (env.role === 'instructor' && (env.mode === 'view' || env.mode === 'evaluate')) {
327
+ base.rationale = rationaleEnabled ? rationale : null;
328
+ base.teacherInstructions = teacherInstructionsEnabled ? teacherInstructions : null;
329
+ } else {
330
+ base.rationale = null;
331
+ base.teacherInstructions = null;
332
+ }
333
+ log('base: ', base);
334
+ resolve(base);
335
+ });
336
+ }
337
+ function outcome(model, session, env) {
338
+ return new Promise(resolve => {
339
+ const traceLog = getLogTrace(model, session, env);
340
+ const scoreObject = getScore(model, session, env);
341
+ const result = {
342
+ score: scoreObject.score,
343
+ empty: !session || (0, _lodashEs.isEmpty)(session),
344
+ traceLog
345
+ };
346
+ if (env.extraProps && env.extraProps.correctResponseEnabled) {
347
+ result.extraProps = {
348
+ correctResponse: scoreObject.correctResponses
349
+ };
350
+ }
351
+ resolve(result);
352
+ });
353
+ }
354
+ const createCorrectResponseSession = (question, env) => {
355
+ return new Promise(resolve => {
356
+ if (env.mode !== 'evaluate' && env.role === 'instructor') {
357
+ const {
358
+ correctAnswer
359
+ } = question;
360
+ let answers = correctAnswer && correctAnswer.data;
361
+
362
+ // for IBX preview mode
363
+ if (env.mode === 'gather') {
364
+ const {
365
+ data
366
+ } = question;
367
+ answers = (correctAnswer && correctAnswer.data || []).map((answer, index) => {
368
+ return {
369
+ ...data[index],
370
+ ...answer
371
+ };
372
+ });
373
+ }
374
+ resolve({
375
+ answer: answers,
376
+ id: '1'
377
+ });
378
+ } else {
379
+ return resolve(null);
380
+ }
381
+ });
382
+ };
383
+
384
+ // remove all html tags
385
+ exports.createCorrectResponseSession = createCorrectResponseSession;
386
+ const getInnerText = html => (html || '').replaceAll(/<[^>]*>/g, '');
387
+
388
+ // remove all html tags except img, iframe and source tag for audio
389
+ const getContent = html => (html || '').replace(/(<(?!img|iframe|source)([^>]+)>)/gi, '');
390
+ const validate = (model = {}, config = {}) => {
391
+ const {
392
+ correctAnswer,
393
+ data
394
+ } = model || {};
395
+ const {
396
+ data: correctData
397
+ } = correctAnswer || {};
398
+ const categories = correctData || [];
399
+ const errors = {};
400
+ const correctAnswerErrors = {};
401
+ const categoryErrors = {};
402
+ ['teacherInstructions', 'prompt', 'rationale'].forEach(field => {
403
+ if (config[field]?.required && !getContent(model[field])) {
404
+ errors[field] = 'This field is required.';
405
+ }
406
+ });
407
+ categories.forEach((category, index) => {
408
+ const {
409
+ label
410
+ } = category;
411
+ if (!getInnerText(label)) {
412
+ categoryErrors[index] = 'Content should not be empty. ';
413
+ } else {
414
+ const identicalAnswer = categories.some((c, i) => c.label === label && index !== i);
415
+ if (identicalAnswer) {
416
+ categoryErrors[index] = 'Category names should be unique. ';
417
+ }
418
+ }
419
+ });
420
+ if (categories.length < 1 || categories.length > 20) {
421
+ correctAnswerErrors.categoriesError = 'The correct answer should include between 1 and 20 categories.';
422
+ } else if ((0, _lodashEs.isEqual)(data.map(category => (0, _lodashEs.pick)(category, 'value', 'label')), correctData.map(category => (0, _lodashEs.pick)(category, 'value', 'label')))) {
423
+ correctAnswerErrors.identicalError = 'Correct answer should not be identical to the chart’s initial state';
424
+ }
425
+ if (!(0, _lodashEs.isEmpty)(categoryErrors)) {
426
+ errors.categoryErrors = categoryErrors;
427
+ }
428
+ if (!(0, _lodashEs.isEmpty)(correctAnswerErrors)) {
429
+ errors.correctAnswerErrors = correctAnswerErrors;
430
+ }
431
+ return errors;
432
+ };
433
+ exports.validate = validate;
434
+ //# sourceMappingURL=index.js.map