@pie-element/graphing 3.7.22 → 4.1.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.
@@ -30,7 +30,7 @@ var _utils = require("./utils");
30
30
 
31
31
  var _controllerUtils = require("@pie-lib/controller-utils");
32
32
 
33
- var _excluded = ["prompt", "promptEnabled", "graph", "answers"];
33
+ var _excluded = ["defaultTool", "prompt", "promptEnabled", "graph", "answers", "toolbarTools"];
34
34
 
35
35
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
36
36
 
@@ -193,10 +193,12 @@ function model(question, session, env) {
193
193
  var normalizedQuestion = normalize(question);
194
194
 
195
195
  var _ref5 = normalizedQuestion || {},
196
+ defaultTool = _ref5.defaultTool,
196
197
  prompt = _ref5.prompt,
197
198
  promptEnabled = _ref5.promptEnabled,
198
199
  graph = _ref5.graph,
199
200
  answers = _ref5.answers,
201
+ toolbarTools = _ref5.toolbarTools,
200
202
  questionProps = (0, _objectWithoutProperties2["default"])(_ref5, _excluded);
201
203
 
202
204
  var arrows = normalizedQuestion.arrows;
@@ -223,17 +225,25 @@ function model(question, session, env) {
223
225
  down: false
224
226
  };
225
227
  }
226
- }
228
+ } // added support for models without defaultTool defined; also used in packages/graphing/configure/src/index.js
229
+
230
+
231
+ var toolbarToolsNoLabel = (toolbarTools || []).filter(function (tool) {
232
+ return tool !== 'label';
233
+ });
234
+ var normalizedDefaultTool = defaultTool || toolbarToolsNoLabel.length && toolbarToolsNoLabel[0] || '';
227
235
 
228
236
  var base = _objectSpread(_objectSpread({}, questionProps), {}, {
229
237
  answers: answers,
238
+ arrows: arrows,
239
+ defaultTool: normalizedDefaultTool,
230
240
  disabled: env.mode !== 'gather',
231
241
  prompt: promptEnabled ? prompt : null,
232
242
  rationale: null,
233
243
  size: graph,
234
244
  showToggle: env.mode === 'evaluate' && !(0, _isEmpty["default"])(answers),
235
245
  teacherInstructions: null,
236
- arrows: arrows
246
+ toolbarTools: toolbarTools
237
247
  });
238
248
 
239
249
  if (role === 'instructor' && (mode === 'view' || mode === 'evaluate')) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.js"],"names":["log","initializeGraphMap","point","segment","line","ray","vector","polygon","circle","sine","parabola","compareMarks","mark1","mark2","type","equalMarks","getAnswerCorrected","sessionAnswers","correctAnswers","marks","reduce","correctedAnswer","answer","answerIsCorrect","find","mark","correctness","getPartialScoring","scoringType","env","pS","partialScoring","enabled","getBestAnswer","question","session","answers","questionPossibleAnswers","correctAnswer","partialScoringEnabled","possibleAnswers","Object","entries","acc","entry","possibleAnswerKey","possibleAnswer","length","correctMarks","filter","maxScore","score","bestScore","foundOneSolution","parseFloat","toFixed","Math","floor","bestScoreAnswerKey","answersCorrected","map","normalize","defaults","model","Promise","resolve","normalizedQuestion","prompt","promptEnabled","graph","questionProps","arrows","mode","role","left","right","up","down","base","disabled","rationale","size","showToggle","teacherInstructions","rationaleEnabled","teacherInstructionsEnabled","correctResponse","outcome","empty","createCorrectResponseSession","values","firstCorrectAnswer","id"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AAEA;;;;;;;;AAEA,IAAMA,GAAG,GAAG,uBAAM,kCAAN,CAAZ;;AAEA,IAAMC,kBAAkB,GAAG,SAArBA,kBAAqB;AAAA,SAAO;AAChCC,IAAAA,KAAK,EAAE,EADyB;AAEhCC,IAAAA,OAAO,EAAE,EAFuB;AAGhCC,IAAAA,IAAI,EAAE,EAH0B;AAIhCC,IAAAA,GAAG,EAAE,EAJ2B;AAKhCC,IAAAA,MAAM,EAAE,EALwB;AAMhCC,IAAAA,OAAO,EAAE,EANuB;AAOhCC,IAAAA,MAAM,EAAE,EAPwB;AAQhCC,IAAAA,IAAI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,CAACC,QAAD,EAAWC,OAAX,EAAoBN,GAApB,CAAnC;AAAA,QAAQuB,SAAR,mBAAQA,SAAR;;AAEAa,IAAAA,OAAO,CAAC;AAAEd,MAAAA,KAAK,EAAEC;AAAT,KAAD,CAAP;AACD,GAZM,CAAP;AAaD;;AAEM,IAAMqC,4BAA4B,GAAG,SAA/BA,4BAA+B,CAACvD,QAAD,EAAWL,GAAX,EAAmB;AAC7D,SAAO,IAAImC,OAAJ,CAAY,UAAAC,OAAO,EAAI;AAC5B,QAAIpC,GAAG,CAAC2C,IAAJ,KAAa,UAAb,IAA2B3C,GAAG,CAAC4C,IAAJ,KAAa,YAA5C,EAA0D;AACxD,kBAAoBvC,QAAQ,IAAI,EAAhC;AAAA,UAAQE,OAAR,SAAQA,OAAR;;AACA,UAAIjB,KAAK,GAAG,EAAZ;;AAEA,UAAIiB,OAAO,IAAIK,MAAM,CAACiD,MAAP,CAActD,OAAd,CAAf,EAAuC;AACrC,YAAMuD,kBAAkB,GAAGlD,MAAM,CAACiD,MAAP,CAActD,OAAd,EAAuB,CAAvB,KAA6B,EAAxD;AAEAjB,QAAAA,KAAK,GAAGwE,kBAAkB,CAACxE,KAAnB,IAA4B,EAApC;AACD;;AAED8C,MAAAA,OAAO,CAAC;AACN3C,QAAAA,MAAM,EAAEH,KADF;AAENyE,QAAAA,EAAE,EAAE;AAFE,OAAD,CAAP;AAID,KAdD,MAcO;AACL3B,MAAAA,OAAO,CAAC,IAAD,CAAP;AACD;AACF,GAlBM,CAAP;AAmBD,CApBM","sourcesContent":["import debug from 'debug';\n\nimport cloneDeep from 'lodash/cloneDeep';\nimport uniqWith from 'lodash/uniqWith';\nimport isEmpty from 'lodash/isEmpty';\nimport defaults from './defaults';\nimport { equalMarks, sortedAnswers } from './utils';\n\nimport { partialScoring } from '@pie-lib/controller-utils';\n\nconst log = debug('@pie-element:graphing:controller');\n\nconst initializeGraphMap = () => ({\n point: [],\n segment: [],\n line: [],\n ray: [],\n vector: [],\n polygon: [],\n circle: [],\n sine: [],\n parabola: []\n});\n\nexport const compareMarks = (mark1, mark2) => {\n // marks can be compared with equalMarks[type] function only if they have the same type;\n // if type is different, they are clearly not equal\n return !!(mark1 && mark2 && mark1.type === mark2.type && equalMarks[mark1.type] && equalMarks[mark1.type](mark1, mark2));\n};\n\nexport const getAnswerCorrected = ({ sessionAnswers, marks: correctAnswers }) => {\n sessionAnswers = sessionAnswers || [];\n correctAnswers = correctAnswers || [];\n\n return cloneDeep(sessionAnswers).reduce((correctedAnswer, answer) => {\n const answerIsCorrect = correctAnswers.find(mark => compareMarks(answer, mark));\n\n answer.correctness = answerIsCorrect ? 'correct' : 'incorrect';\n\n return [...correctedAnswer, answer];\n }, []);\n};\n\nconst getPartialScoring = ({ scoringType, env }) => {\n let pS = scoringType;\n\n // if scoringType is undefined, partialScoring should be considered undefined (not set)\n // because partialScoring.enabled is using that information\n // if it has a value, we check if it is partial scoring or dichotomous\n if (scoringType) {\n pS = scoringType === 'partial scoring';\n }\n\n return partialScoring.enabled({ partialScoring: pS }, env);\n};\n\nexport const getBestAnswer = (question, session, env = {}) => {\n // questionPossibleAnswers contains all possible answers (correct response and alternates);\n let { answers: questionPossibleAnswers = {}, scoringType } = question || {};\n let { answer } = session || {};\n\n // initialize answer if no values\n answer = answer || [];\n\n // initialize one possible answer if no values\n if (isEmpty(questionPossibleAnswers)) {\n questionPossibleAnswers = { correctAnswer: initializeGraphMap() };\n } else {\n questionPossibleAnswers = {\n correctAnswer: questionPossibleAnswers.correctAnswer,\n ...sortedAnswers(questionPossibleAnswers)\n };\n }\n\n const partialScoringEnabled = getPartialScoring({ scoringType, env });\n\n // student's answers without DUPLICATES\n const sessionAnswers = uniqWith(answer, compareMarks);\n // array of possible answers entries\n const possibleAnswers = Object.entries(questionPossibleAnswers);\n\n return possibleAnswers.reduce((acc, entry) => {\n // iterating each possible answer (main + alternates)\n const possibleAnswerKey = entry[0];\n const possibleAnswer = entry[1] || {};\n let { marks } = possibleAnswer;\n\n if (!marks || !marks.length) {\n return acc;\n }\n\n // returns array of marks, each having 'correctness' property\n const correctedAnswer = getAnswerCorrected({ sessionAnswers, marks });\n const correctMarks = correctedAnswer.filter(answer => answer.correctness === 'correct');\n\n const maxScore = marks.length;\n let score = correctMarks.length;\n\n // if extra placements\n if (correctedAnswer.length > maxScore) {\n score -= correctedAnswer.length - maxScore;\n }\n\n if (score < 0) {\n score = 0;\n }\n\n if (score / maxScore > acc.bestScore || !acc.foundOneSolution) {\n if (partialScoringEnabled) {\n acc.bestScore = parseFloat((score / maxScore).toFixed(2));\n } else {\n acc.bestScore = Math.floor(score / maxScore);\n }\n\n acc.bestScoreAnswerKey = possibleAnswerKey;\n acc.answersCorrected = correctedAnswer;\n acc.foundOneSolution = true;\n }\n\n return acc;\n }, {\n bestScore: 0,\n bestScoreAnswerKey: null,\n // initially we just suppose all the answers are incorrect\n answersCorrected: cloneDeep(sessionAnswers).map(answer => ({ ...answer, correctness: 'incorrect' })),\n foundOneSolution: false\n });\n};\n\nexport const normalize = question => ({ ...defaults, ...question });\n\nexport function model(question, session, env) {\n return new Promise(resolve => {\n const normalizedQuestion = normalize(question);\n const { prompt, promptEnabled, graph, answers, ...questionProps } = normalizedQuestion || {};\n let { arrows } = normalizedQuestion;\n const { mode, role } = env || {};\n\n // This is used for offering support for old models which have the property arrows: boolean\n // Same thing is set in authoring : packages/graphing/configure/src/configure.jsx - componentDidMount\n if (typeof arrows === 'boolean') {\n if (arrows) {\n arrows = {\n left: true,\n right: true,\n up: true,\n down: true\n };\n } else {\n arrows = {\n left: false,\n right: false,\n up: false,\n down: false\n };\n }\n }\n\n const base = {\n ...questionProps,\n answers,\n disabled: env.mode !== 'gather',\n prompt: promptEnabled ? prompt : null,\n rationale: null,\n size: graph,\n showToggle: env.mode === 'evaluate' && !isEmpty(answers),\n teacherInstructions: null,\n arrows\n };\n\n if (role === 'instructor' && (mode === 'view' || mode === 'evaluate')) {\n const { rationale, rationaleEnabled, teacherInstructions, teacherInstructionsEnabled } = normalizedQuestion || {};\n\n base.rationale = rationaleEnabled ? rationale : null;\n base.teacherInstructions = teacherInstructionsEnabled ? teacherInstructions : null;\n }\n\n if (mode === 'evaluate') {\n if (!isEmpty(answers)) {\n const { answersCorrected, bestScoreAnswerKey, bestScore } = getBestAnswer(normalizedQuestion, session, env);\n\n // array of marks from session with 'correctness' property set\n base.answersCorrected = answersCorrected;\n base.correctResponse = bestScoreAnswerKey ? (answers[bestScoreAnswerKey] || {}).marks : [];\n base.showToggle = base.showToggle && bestScore !== 1;\n } else {\n base.answersCorrected = session && session.answer || [];\n base.correctResponse = [];\n }\n }\n\n log('base: ', base);\n resolve(base);\n });\n}\n\nexport function outcome(question, session, env = {}) {\n return new Promise(resolve => {\n if (!session || isEmpty(session)) {\n resolve({ score: 0, empty: true });\n }\n\n if (env.mode !== 'evaluate' || isEmpty(question.answers)) {\n resolve({ score: 0 });\n }\n\n const { bestScore } = getBestAnswer(question, session, env);\n\n resolve({ score: bestScore });\n });\n}\n\nexport const createCorrectResponseSession = (question, env) => {\n return new Promise(resolve => {\n if (env.mode !== 'evaluate' && env.role === 'instructor') {\n const { answers } = question || {};\n let marks = [];\n\n if (answers && Object.values(answers)) {\n const firstCorrectAnswer = Object.values(answers)[0] || {};\n\n marks = firstCorrectAnswer.marks || [];\n }\n\n resolve({\n answer: marks,\n id: '1'\n });\n } else {\n resolve(null);\n }\n });\n};\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../src/index.js"],"names":["log","initializeGraphMap","point","segment","line","ray","vector","polygon","circle","sine","parabola","compareMarks","mark1","mark2","type","equalMarks","getAnswerCorrected","sessionAnswers","correctAnswers","marks","reduce","correctedAnswer","answer","answerIsCorrect","find","mark","correctness","getPartialScoring","scoringType","env","pS","partialScoring","enabled","getBestAnswer","question","session","answers","questionPossibleAnswers","correctAnswer","partialScoringEnabled","possibleAnswers","Object","entries","acc","entry","possibleAnswerKey","possibleAnswer","length","correctMarks","filter","maxScore","score","bestScore","foundOneSolution","parseFloat","toFixed","Math","floor","bestScoreAnswerKey","answersCorrected","map","normalize","defaults","model","Promise","resolve","normalizedQuestion","defaultTool","prompt","promptEnabled","graph","toolbarTools","questionProps","arrows","mode","role","left","right","up","down","toolbarToolsNoLabel","tool","normalizedDefaultTool","base","disabled","rationale","size","showToggle","teacherInstructions","rationaleEnabled","teacherInstructionsEnabled","correctResponse","outcome","empty","createCorrectResponseSession","values","firstCorrectAnswer","id"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AAEA;;;;;;;;AAEA,IAAMA,GAAG,GAAG,uBAAM,kCAAN,CAAZ;;AAEA,IAAMC,kBAAkB,GAAG,SAArBA,kBAAqB;AAAA,SAAO;AAChCC,IAAAA,KAAK,EAAE,EADyB;AAEhCC,IAAAA,OAAO,EAAE,EAFuB;AAGhCC,IAAAA,IAAI,EAAE,EAH0B;AAIhCC,IAAAA,GAAG,EAAE,EAJ2B;AAKhCC,IAAAA,MAAM,EAAE,EALwB;AAMhCC,IAAAA,OAAO,EAAE,EANuB;AAOhCC,IAAAA,MAAM,EAAE,EAPwB;AAQhCC,IAAAA,IAAI,EAAE,EAR0B;AAShCC,IAAAA,QAAQ,EAAE;AATsB,GAAP;AAAA,CAA3B;;AAYO,IAAMC,YAAY,GAAG,SAAfA,YAAe,CAACC,KAAD,EAAQC,KAAR,EAAkB;AAC5C;AACA;AACA,SAAO,CAAC,EAAED,KAAK,IAAIC,KAAT,IAAkBD,KAAK,CAACE,IAAN,KAAeD,KAAK,CAACC,IAAvC,IAA+CC,kBAAWH,KAAK,CAACE,IAAjB,CAA/C,IAAyEC,kBAAWH,KAAK,CAACE,IAAjB,EAAuBF,KAAvB,EAA8BC,KAA9B,CAA3E,CAAR;AACD,CAJM;;;;AAMA,IAAMG,kBAAkB,GAAG,SAArBA,kBAAqB,OAA+C;AAAA,MAA5CC,cAA4C,QAA5CA,cAA4C;AAAA,MAArBC,cAAqB,QAA5BC,KAA4B;AAC/EF,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AAEC;AAAT,KAAD,CAAP;AACD,GAZM,CAAP;AAaD;;AAEM,IAAM0C,4BAA4B,GAAG,SAA/BA,4BAA+B,CAAC5D,QAAD,EAAWL,GAAX,EAAmB;AAC7D,SAAO,IAAImC,OAAJ,CAAY,UAAAC,OAAO,EAAI;AAC5B,QAAIpC,GAAG,CAAC6C,IAAJ,KAAa,UAAb,IAA2B7C,GAAG,CAAC8C,IAAJ,KAAa,YAA5C,EAA0D;AACxD,kBAAoBzC,QAAQ,IAAI,EAAhC;AAAA,UAAQE,OAAR,SAAQA,OAAR;;AACA,UAAIjB,KAAK,GAAG,EAAZ;;AAEA,UAAIiB,OAAO,IAAIK,MAAM,CAACsD,MAAP,CAAc3D,OAAd,CAAf,EAAuC;AACrC,YAAM4D,kBAAkB,GAAGvD,MAAM,CAACsD,MAAP,CAAc3D,OAAd,EAAuB,CAAvB,KAA6B,EAAxD;AAEAjB,QAAAA,KAAK,GAAG6E,kBAAkB,CAAC7E,KAAnB,IAA4B,EAApC;AACD;;AAED8C,MAAAA,OAAO,CAAC;AACN3C,QAAAA,MAAM,EAAEH,KADF;AAEN8E,QAAAA,EAAE,EAAE;AAFE,OAAD,CAAP;AAID,KAdD,MAcO;AACLhC,MAAAA,OAAO,CAAC,IAAD,CAAP;AACD;AACF,GAlBM,CAAP;AAmBD,CApBM","sourcesContent":["import debug from 'debug';\n\nimport cloneDeep from 'lodash/cloneDeep';\nimport uniqWith from 'lodash/uniqWith';\nimport isEmpty from 'lodash/isEmpty';\nimport defaults from './defaults';\nimport { equalMarks, sortedAnswers } from './utils';\n\nimport { partialScoring } from '@pie-lib/controller-utils';\n\nconst log = debug('@pie-element:graphing:controller');\n\nconst initializeGraphMap = () => ({\n point: [],\n segment: [],\n line: [],\n ray: [],\n vector: [],\n polygon: [],\n circle: [],\n sine: [],\n parabola: []\n});\n\nexport const compareMarks = (mark1, mark2) => {\n // marks can be compared with equalMarks[type] function only if they have the same type;\n // if type is different, they are clearly not equal\n return !!(mark1 && mark2 && mark1.type === mark2.type && equalMarks[mark1.type] && equalMarks[mark1.type](mark1, mark2));\n};\n\nexport const getAnswerCorrected = ({ sessionAnswers, marks: correctAnswers }) => {\n sessionAnswers = sessionAnswers || [];\n correctAnswers = correctAnswers || [];\n\n return cloneDeep(sessionAnswers).reduce((correctedAnswer, answer) => {\n const answerIsCorrect = correctAnswers.find(mark => compareMarks(answer, mark));\n\n answer.correctness = answerIsCorrect ? 'correct' : 'incorrect';\n\n return [...correctedAnswer, answer];\n }, []);\n};\n\nconst getPartialScoring = ({ scoringType, env }) => {\n let pS = scoringType;\n\n // if scoringType is undefined, partialScoring should be considered undefined (not set)\n // because partialScoring.enabled is using that information\n // if it has a value, we check if it is partial scoring or dichotomous\n if (scoringType) {\n pS = scoringType === 'partial scoring';\n }\n\n return partialScoring.enabled({ partialScoring: pS }, env);\n};\n\nexport const getBestAnswer = (question, session, env = {}) => {\n // questionPossibleAnswers contains all possible answers (correct response and alternates);\n let { answers: questionPossibleAnswers = {}, scoringType } = question || {};\n let { answer } = session || {};\n\n // initialize answer if no values\n answer = answer || [];\n\n // initialize one possible answer if no values\n if (isEmpty(questionPossibleAnswers)) {\n questionPossibleAnswers = { correctAnswer: initializeGraphMap() };\n } else {\n questionPossibleAnswers = {\n correctAnswer: questionPossibleAnswers.correctAnswer,\n ...sortedAnswers(questionPossibleAnswers)\n };\n }\n\n const partialScoringEnabled = getPartialScoring({ scoringType, env });\n\n // student's answers without DUPLICATES\n const sessionAnswers = uniqWith(answer, compareMarks);\n // array of possible answers entries\n const possibleAnswers = Object.entries(questionPossibleAnswers);\n\n return possibleAnswers.reduce((acc, entry) => {\n // iterating each possible answer (main + alternates)\n const possibleAnswerKey = entry[0];\n const possibleAnswer = entry[1] || {};\n let { marks } = possibleAnswer;\n\n if (!marks || !marks.length) {\n return acc;\n }\n\n // returns array of marks, each having 'correctness' property\n const correctedAnswer = getAnswerCorrected({ sessionAnswers, marks });\n const correctMarks = correctedAnswer.filter(answer => answer.correctness === 'correct');\n\n const maxScore = marks.length;\n let score = correctMarks.length;\n\n // if extra placements\n if (correctedAnswer.length > maxScore) {\n score -= correctedAnswer.length - maxScore;\n }\n\n if (score < 0) {\n score = 0;\n }\n\n if (score / maxScore > acc.bestScore || !acc.foundOneSolution) {\n if (partialScoringEnabled) {\n acc.bestScore = parseFloat((score / maxScore).toFixed(2));\n } else {\n acc.bestScore = Math.floor(score / maxScore);\n }\n\n acc.bestScoreAnswerKey = possibleAnswerKey;\n acc.answersCorrected = correctedAnswer;\n acc.foundOneSolution = true;\n }\n\n return acc;\n }, {\n bestScore: 0,\n bestScoreAnswerKey: null,\n // initially we just suppose all the answers are incorrect\n answersCorrected: cloneDeep(sessionAnswers).map(answer => ({ ...answer, correctness: 'incorrect' })),\n foundOneSolution: false\n });\n};\n\nexport const normalize = question => ({ ...defaults, ...question });\n\nexport function model(question, session, env) {\n return new Promise(resolve => {\n const normalizedQuestion = normalize(question);\n const {\n defaultTool,\n prompt,\n promptEnabled,\n graph,\n answers,\n toolbarTools,\n ...questionProps\n } = normalizedQuestion || {};\n let { arrows } = normalizedQuestion;\n const { mode, role } = env || {};\n\n // This is used for offering support for old models which have the property arrows: boolean\n // Same thing is set in authoring : packages/graphing/configure/src/configure.jsx - componentDidMount\n if (typeof arrows === 'boolean') {\n if (arrows) {\n arrows = {\n left: true,\n right: true,\n up: true,\n down: true\n };\n } else {\n arrows = {\n left: false,\n right: false,\n up: false,\n down: false\n };\n }\n }\n\n // added support for models without defaultTool defined; also used in packages/graphing/configure/src/index.js\n const toolbarToolsNoLabel = (toolbarTools || []).filter(tool => tool !== 'label');\n const normalizedDefaultTool = defaultTool || (toolbarToolsNoLabel.length && toolbarToolsNoLabel[0]) || '';\n\n const base = {\n ...questionProps,\n answers,\n arrows,\n defaultTool: normalizedDefaultTool,\n disabled: env.mode !== 'gather',\n prompt: promptEnabled ? prompt : null,\n rationale: null,\n size: graph,\n showToggle: env.mode === 'evaluate' && !isEmpty(answers),\n teacherInstructions: null,\n toolbarTools\n };\n\n if (role === 'instructor' && (mode === 'view' || mode === 'evaluate')) {\n const { rationale, rationaleEnabled, teacherInstructions, teacherInstructionsEnabled } = normalizedQuestion || {};\n\n base.rationale = rationaleEnabled ? rationale : null;\n base.teacherInstructions = teacherInstructionsEnabled ? teacherInstructions : null;\n }\n\n if (mode === 'evaluate') {\n if (!isEmpty(answers)) {\n const { answersCorrected, bestScoreAnswerKey, bestScore } = getBestAnswer(normalizedQuestion, session, env);\n\n // array of marks from session with 'correctness' property set\n base.answersCorrected = answersCorrected;\n base.correctResponse = bestScoreAnswerKey ? (answers[bestScoreAnswerKey] || {}).marks : [];\n base.showToggle = base.showToggle && bestScore !== 1;\n } else {\n base.answersCorrected = session && session.answer || [];\n base.correctResponse = [];\n }\n }\n\n log('base: ', base);\n resolve(base);\n });\n}\n\nexport function outcome(question, session, env = {}) {\n return new Promise(resolve => {\n if (!session || isEmpty(session)) {\n resolve({ score: 0, empty: true });\n }\n\n if (env.mode !== 'evaluate' || isEmpty(question.answers)) {\n resolve({ score: 0 });\n }\n\n const { bestScore } = getBestAnswer(question, session, env);\n\n resolve({ score: bestScore });\n });\n}\n\nexport const createCorrectResponseSession = (question, env) => {\n return new Promise(resolve => {\n if (env.mode !== 'evaluate' && env.role === 'instructor') {\n const { answers } = question || {};\n let marks = [];\n\n if (answers && Object.values(answers)) {\n const firstCorrectAnswer = Object.values(answers)[0] || {};\n\n marks = firstCorrectAnswer.marks || [];\n }\n\n resolve({\n answer: marks,\n id: '1'\n });\n } else {\n resolve(null);\n }\n });\n};\n"],"file":"index.js"}
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pie-element/graphing-controller",
3
3
  "private": true,
4
- "version": "3.4.6",
4
+ "version": "4.0.0",
5
5
  "description": "",
6
6
  "main": "lib/index.js",
7
7
  "module": "src/index.js",
@@ -4,23 +4,113 @@
4
4
  "type": "object",
5
5
  "properties": {
6
6
  "authoring": {
7
- "title": "ConfigurePropWithEnabled",
7
+ "title": "AuthoringConfigProp",
8
8
  "type": "object",
9
9
  "properties": {
10
10
  "settings": {
11
- "description": "Indicates if the item has to be displayed in the Settings Panel",
11
+ "description": "Indicates if the item is displayed in the Settings Panel",
12
12
  "type": "boolean",
13
13
  "title": "settings"
14
14
  },
15
15
  "label": {
16
- "description": "Indicates the label for the item that has to be displayed in the Settings Panel",
16
+ "description": "Indicates the label for the item that is displayed in the Settings Panel",
17
17
  "type": "string",
18
18
  "title": "label"
19
19
  },
20
20
  "enabled": {
21
- "description": "Indicates the value of the item if it affects config-ui\n(eg.: if item is a switch and displaying an input on the config-ui depends on the switch value: on/off)",
21
+ "description": "Indicates if the Grid Setup Panel is displayed",
22
22
  "type": "boolean",
23
23
  "title": "enabled"
24
+ },
25
+ "includeAxesEnabled": {
26
+ "description": "Indicates if the \"includeAxes\" toggle is displayed in the Grid Setup Panel",
27
+ "type": "boolean",
28
+ "title": "includeAxesEnabled"
29
+ },
30
+ "standardGridEnabled": {
31
+ "description": "Indicates if the \"standardGrid\" toggle is displayed in the Grid Setup Panel",
32
+ "type": "boolean",
33
+ "title": "standardGridEnabled"
34
+ },
35
+ "min": {
36
+ "title": "GridPanelConfigProp",
37
+ "type": "object",
38
+ "properties": {
39
+ "label": {
40
+ "description": "Indicates the label for the item that is displayed in the Grid Setup Panel",
41
+ "type": "string",
42
+ "title": "label"
43
+ },
44
+ "enabled": {
45
+ "description": "Indicates if the item is displayed in the Grid Setup Panel",
46
+ "type": "boolean",
47
+ "title": "enabled"
48
+ }
49
+ }
50
+ },
51
+ "max": {
52
+ "title": "GridPanelConfigProp",
53
+ "type": "object",
54
+ "properties": {
55
+ "label": {
56
+ "description": "Indicates the label for the item that is displayed in the Grid Setup Panel",
57
+ "type": "string",
58
+ "title": "label"
59
+ },
60
+ "enabled": {
61
+ "description": "Indicates if the item is displayed in the Grid Setup Panel",
62
+ "type": "boolean",
63
+ "title": "enabled"
64
+ }
65
+ }
66
+ },
67
+ "axisLabel": {
68
+ "title": "GridPanelConfigProp",
69
+ "type": "object",
70
+ "properties": {
71
+ "label": {
72
+ "description": "Indicates the label for the item that is displayed in the Grid Setup Panel",
73
+ "type": "string",
74
+ "title": "label"
75
+ },
76
+ "enabled": {
77
+ "description": "Indicates if the item is displayed in the Grid Setup Panel",
78
+ "type": "boolean",
79
+ "title": "enabled"
80
+ }
81
+ }
82
+ },
83
+ "step": {
84
+ "title": "GridPanelConfigProp",
85
+ "type": "object",
86
+ "properties": {
87
+ "label": {
88
+ "description": "Indicates the label for the item that is displayed in the Grid Setup Panel",
89
+ "type": "string",
90
+ "title": "label"
91
+ },
92
+ "enabled": {
93
+ "description": "Indicates if the item is displayed in the Grid Setup Panel",
94
+ "type": "boolean",
95
+ "title": "enabled"
96
+ }
97
+ }
98
+ },
99
+ "labelStep": {
100
+ "title": "GridPanelConfigProp",
101
+ "type": "object",
102
+ "properties": {
103
+ "label": {
104
+ "description": "Indicates the label for the item that is displayed in the Grid Setup Panel",
105
+ "type": "string",
106
+ "title": "label"
107
+ },
108
+ "enabled": {
109
+ "description": "Indicates if the item is displayed in the Grid Setup Panel",
110
+ "type": "boolean",
111
+ "title": "enabled"
112
+ }
113
+ }
24
114
  }
25
115
  }
26
116
  },
@@ -84,6 +174,14 @@
84
174
  }
85
175
  }
86
176
  },
177
+ "availableTools": {
178
+ "description": "Graph toolbar tools configuration",
179
+ "type": "array",
180
+ "items": {
181
+ "type": "string"
182
+ },
183
+ "title": "availableTools"
184
+ },
87
185
  "coordinatesOnHover": {
88
186
  "title": "ConfigureProp",
89
187
  "type": "object",
@@ -285,6 +383,48 @@
285
383
  }
286
384
  }
287
385
  },
386
+ "maxImageWidth": {
387
+ "title": "ConfigureMaxImageDimensionsProp",
388
+ "type": "object",
389
+ "properties": {
390
+ "teacherInstructions": {
391
+ "description": "Indicates the max dimension for images in teacher instructions",
392
+ "type": "number",
393
+ "title": "teacherInstructions"
394
+ },
395
+ "prompt": {
396
+ "description": "Indicates the max dimension for images in prompt - this is also the default dimension for all other input fields if it's not specified",
397
+ "type": "number",
398
+ "title": "prompt"
399
+ },
400
+ "rationale": {
401
+ "description": "Indicates the max dimension for images in rationale",
402
+ "type": "number",
403
+ "title": "rationale"
404
+ }
405
+ }
406
+ },
407
+ "maxImageHeight": {
408
+ "title": "ConfigureMaxImageDimensionsProp",
409
+ "type": "object",
410
+ "properties": {
411
+ "teacherInstructions": {
412
+ "description": "Indicates the max dimension for images in teacher instructions",
413
+ "type": "number",
414
+ "title": "teacherInstructions"
415
+ },
416
+ "prompt": {
417
+ "description": "Indicates the max dimension for images in prompt - this is also the default dimension for all other input fields if it's not specified",
418
+ "type": "number",
419
+ "title": "prompt"
420
+ },
421
+ "rationale": {
422
+ "description": "Indicates the max dimension for images in rationale",
423
+ "type": "number",
424
+ "title": "rationale"
425
+ }
426
+ }
427
+ },
288
428
  "showPrompt": {
289
429
  "description": "Determines whether prompt field will be displayed or not",
290
430
  "default": true,
@@ -305,22 +445,128 @@
305
445
  }
306
446
  },
307
447
  "definitions": {
308
- "ConfigurePropWithEnabled": {
309
- "title": "ConfigurePropWithEnabled",
448
+ "AuthoringConfigProp": {
449
+ "title": "AuthoringConfigProp",
310
450
  "type": "object",
311
451
  "properties": {
312
452
  "settings": {
313
- "description": "Indicates if the item has to be displayed in the Settings Panel",
453
+ "description": "Indicates if the item is displayed in the Settings Panel",
314
454
  "type": "boolean",
315
455
  "title": "settings"
316
456
  },
317
457
  "label": {
318
- "description": "Indicates the label for the item that has to be displayed in the Settings Panel",
458
+ "description": "Indicates the label for the item that is displayed in the Settings Panel",
319
459
  "type": "string",
320
460
  "title": "label"
321
461
  },
322
462
  "enabled": {
323
- "description": "Indicates the value of the item if it affects config-ui\n(eg.: if item is a switch and displaying an input on the config-ui depends on the switch value: on/off)",
463
+ "description": "Indicates if the Grid Setup Panel is displayed",
464
+ "type": "boolean",
465
+ "title": "enabled"
466
+ },
467
+ "includeAxesEnabled": {
468
+ "description": "Indicates if the \"includeAxes\" toggle is displayed in the Grid Setup Panel",
469
+ "type": "boolean",
470
+ "title": "includeAxesEnabled"
471
+ },
472
+ "standardGridEnabled": {
473
+ "description": "Indicates if the \"standardGrid\" toggle is displayed in the Grid Setup Panel",
474
+ "type": "boolean",
475
+ "title": "standardGridEnabled"
476
+ },
477
+ "min": {
478
+ "title": "GridPanelConfigProp",
479
+ "type": "object",
480
+ "properties": {
481
+ "label": {
482
+ "description": "Indicates the label for the item that is displayed in the Grid Setup Panel",
483
+ "type": "string",
484
+ "title": "label"
485
+ },
486
+ "enabled": {
487
+ "description": "Indicates if the item is displayed in the Grid Setup Panel",
488
+ "type": "boolean",
489
+ "title": "enabled"
490
+ }
491
+ }
492
+ },
493
+ "max": {
494
+ "title": "GridPanelConfigProp",
495
+ "type": "object",
496
+ "properties": {
497
+ "label": {
498
+ "description": "Indicates the label for the item that is displayed in the Grid Setup Panel",
499
+ "type": "string",
500
+ "title": "label"
501
+ },
502
+ "enabled": {
503
+ "description": "Indicates if the item is displayed in the Grid Setup Panel",
504
+ "type": "boolean",
505
+ "title": "enabled"
506
+ }
507
+ }
508
+ },
509
+ "axisLabel": {
510
+ "title": "GridPanelConfigProp",
511
+ "type": "object",
512
+ "properties": {
513
+ "label": {
514
+ "description": "Indicates the label for the item that is displayed in the Grid Setup Panel",
515
+ "type": "string",
516
+ "title": "label"
517
+ },
518
+ "enabled": {
519
+ "description": "Indicates if the item is displayed in the Grid Setup Panel",
520
+ "type": "boolean",
521
+ "title": "enabled"
522
+ }
523
+ }
524
+ },
525
+ "step": {
526
+ "title": "GridPanelConfigProp",
527
+ "type": "object",
528
+ "properties": {
529
+ "label": {
530
+ "description": "Indicates the label for the item that is displayed in the Grid Setup Panel",
531
+ "type": "string",
532
+ "title": "label"
533
+ },
534
+ "enabled": {
535
+ "description": "Indicates if the item is displayed in the Grid Setup Panel",
536
+ "type": "boolean",
537
+ "title": "enabled"
538
+ }
539
+ }
540
+ },
541
+ "labelStep": {
542
+ "title": "GridPanelConfigProp",
543
+ "type": "object",
544
+ "properties": {
545
+ "label": {
546
+ "description": "Indicates the label for the item that is displayed in the Grid Setup Panel",
547
+ "type": "string",
548
+ "title": "label"
549
+ },
550
+ "enabled": {
551
+ "description": "Indicates if the item is displayed in the Grid Setup Panel",
552
+ "type": "boolean",
553
+ "title": "enabled"
554
+ }
555
+ }
556
+ }
557
+ }
558
+ },
559
+ "GridPanelConfigProp": {
560
+ "title": "GridPanelConfigProp",
561
+ "type": "object",
562
+ "properties": {
563
+ "label": {
564
+ "description": "Indicates the label for the item that is displayed in the Grid Setup Panel",
565
+ "type": "string",
566
+ "title": "label"
567
+ },
568
+ "enabled": {
569
+ "description": "Indicates if the item is displayed in the Grid Setup Panel",
324
570
  "type": "boolean",
325
571
  "title": "enabled"
326
572
  }
@@ -448,7 +694,49 @@
448
694
  "title": "step"
449
695
  }
450
696
  }
697
+ },
698
+ "ConfigurePropWithEnabled": {
699
+ "title": "ConfigurePropWithEnabled",
700
+ "type": "object",
701
+ "properties": {
702
+ "settings": {
703
+ "description": "Indicates if the item has to be displayed in the Settings Panel",
704
+ "type": "boolean",
705
+ "title": "settings"
706
+ },
707
+ "label": {
708
+ "description": "Indicates the label for the item that has to be displayed in the Settings Panel",
709
+ "type": "string",
710
+ "title": "label"
711
+ },
712
+ "enabled": {
713
+ "description": "Indicates the value of the item if it affects config-ui\n(eg.: if item is a switch and displaying an input on the config-ui depends on the switch value: on/off)",
714
+ "type": "boolean",
715
+ "title": "enabled"
716
+ }
717
+ }
718
+ },
719
+ "ConfigureMaxImageDimensionsProp": {
720
+ "title": "ConfigureMaxImageDimensionsProp",
721
+ "type": "object",
722
+ "properties": {
723
+ "teacherInstructions": {
724
+ "description": "Indicates the max dimension for images in teacher instructions",
725
+ "type": "number",
726
+ "title": "teacherInstructions"
727
+ },
728
+ "prompt": {
729
+ "description": "Indicates the max dimension for images in prompt - this is also the default dimension for all other input fields if it's not specified",
730
+ "type": "number",
731
+ "title": "prompt"
732
+ },
733
+ "rationale": {
734
+ "description": "Indicates the max dimension for images in rationale",
735
+ "type": "number",
736
+ "title": "rationale"
737
+ }
738
+ }
451
739
  }
452
740
  },
453
741
  "$schema": "http://json-schema.org/draft-07/schema#"
454
- }
742
+ }