{"version":3,"file":"attempt_administration_chart_output.min.js","sources":["../src/attempt_administration_chart_output.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Customized output for the attempt administration chart.\n *\n * The class overrides some definitions from core/chart_output_chartjs for custom output.\n *\n * @module mod_adaptivequiz/attempt_administration_chart_output\n * @copyright 2024 Vitaly Potenko \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine([\n 'core/chart_output_chartjs',\n 'core/chartjs',\n 'mod_adaptivequiz/attempt_administration_chart_dataset_config'\n], function(\n Output,\n Chartjs,\n DatasetConfig\n) {\n\n /**\n * Used to set the color as a hex code to avoid inconsistencies from Chartjs when displaying the color with opacity specified.\n */\n const STANDARD_ERROR_LABEL_COLOR = '#ffcce0';\n\n /**\n * A filter callback for tooltip items.\n *\n * @param {Object} tooltipItem\n * @return {Boolean}\n */\n const tooltipItemsFilter = function (tooltipItem) {\n return !(tooltipItem.datasetIndex === DatasetConfig.indices.STANDARD_ERROR_MAX\n || tooltipItem.datasetIndex === DatasetConfig.indices.STANDARD_ERROR_MIN);\n };\n\n /**\n * A callback to add text after a tooltip item.\n *\n * @param {Object} tooltipItem\n * @return {String}\n */\n const afterTooltipItemLabel = function (tooltipItem) {\n // Show extra text only after the ability measure and administered difficulty items.\n if (!(tooltipItem.datasetIndex === DatasetConfig.indices.ABILITY_MEASURE\n || tooltipItem.datasetIndex === DatasetConfig.indices.ADMINISTERED_DIFFICULTY)) {\n\n return '';\n }\n\n // If this is the ability measure item.\n if (tooltipItem.datasetIndex === DatasetConfig.indices.ABILITY_MEASURE) {\n // Reach out to the standard error data.\n const stdErrorSeries = this._chart.getSeries()[DatasetConfig.indices.STANDARD_ERROR_PERCENT];\n const stdErrorValue = stdErrorSeries.getValues()[tooltipItem.dataIndex];\n\n return `${stdErrorSeries.getLabel()}: ${stdErrorValue}`;\n }\n\n // The rest case - administered difficulty item.\n\n // Reach out to the right/wrong data.\n const rightWrongSeries = this._chart.getSeries()[DatasetConfig.indices.CORRECT_WRONG_FLAG];\n const rightWrongValue = rightWrongSeries.getValues()[tooltipItem.dataIndex];\n\n return `${rightWrongSeries.getLabel()}: ${rightWrongValue}`;\n };\n\n /**\n * Returns part of the config to set up the legend.\n *\n * @return {Object}\n */\n const legendConfig = function () {\n return {\n labels: {\n generateLabels(chart) {\n let labels = Chartjs.defaults.plugins.legend.labels.generateLabels(chart);\n\n // Store the standard error label for future use.\n const stdErrorLabelText = labels.find((label) =>\n label.datasetIndex === DatasetConfig.indices.STANDARD_ERROR_PERCENT).text;\n\n // Remove everything hidden and one of the standard error labels.\n labels = labels.filter((label) =>\n !label.hidden && label.datasetIndex !== DatasetConfig.indices.STANDARD_ERROR_MIN);\n\n // Order by dataset index.\n labels.sort((label1, label2) => label1.datasetIndex - label2.datasetIndex);\n\n // Convert one of the standard error labels to a proper one.\n const stdErrorMaxIndex = labels.findIndex((label) =>\n label.datasetIndex === DatasetConfig.indices.STANDARD_ERROR_MAX);\n labels[stdErrorMaxIndex].text = stdErrorLabelText;\n labels[stdErrorMaxIndex].strokeStyle = STANDARD_ERROR_LABEL_COLOR;\n labels[stdErrorMaxIndex].fillStyle = STANDARD_ERROR_LABEL_COLOR;\n\n return labels;\n }\n },\n onClick: function () {\n return false;\n }\n };\n };\n\n /**\n * Output for the attempt administration chart.\n *\n * @class\n * @extends {module:core/chart_output_chartjs}\n */\n function AttemptAdministrationChartOutput() {\n Output.apply(this, arguments);\n }\n AttemptAdministrationChartOutput.prototype = Object.create(Output.prototype);\n\n /**\n * Overrides config definition to add more custom features.\n *\n * @protected\n * @override\n * @return {Object}\n */\n AttemptAdministrationChartOutput.prototype._makeConfig = function () {\n let config = Output.prototype._makeConfig.apply(this, arguments);\n\n // Define draw order.\n config.data.datasets[DatasetConfig.indices.ABILITY_MEASURE].order = DatasetConfig.orderWeights.ABILITY_MEASURE;\n config.data.datasets[DatasetConfig.indices.TARGET_DIFFICULTY].order = DatasetConfig.orderWeights.TARGET_DIFFICULTY;\n config.data.datasets[DatasetConfig.indices.ADMINISTERED_DIFFICULTY].order =\n DatasetConfig.orderWeights.ADMINISTERED_DIFFICULTY;\n config.data.datasets[DatasetConfig.indices.STANDARD_ERROR_MAX].order = DatasetConfig.orderWeights.STANDARD_ERROR_BORDER;\n config.data.datasets[DatasetConfig.indices.STANDARD_ERROR_MIN].order = DatasetConfig.orderWeights.STANDARD_ERROR_BORDER;\n\n // Hide lines and points for standard error min/max datasets.\n\n // In Chart.js version prior to 4.2.1 points visibility can be controlled with the 'pointRadius' property.\n config.data.datasets[DatasetConfig.indices.STANDARD_ERROR_MAX].pointRadius = 0;\n config.data.datasets[DatasetConfig.indices.STANDARD_ERROR_MIN].pointRadius = 0;\n // For Chart.js since 4.2.1.\n config.data.datasets[DatasetConfig.indices.STANDARD_ERROR_MAX].pointStyle = false;\n config.data.datasets[DatasetConfig.indices.STANDARD_ERROR_MIN].pointStyle = false;\n\n config.data.datasets[DatasetConfig.indices.STANDARD_ERROR_MAX].showLine = false;\n config.data.datasets[DatasetConfig.indices.STANDARD_ERROR_MIN].showLine = false;\n\n // Hide entire datasets with standard error percentages and right/wrong flags.\n config.data.datasets[DatasetConfig.indices.STANDARD_ERROR_PERCENT].hidden = true;\n config.data.datasets[DatasetConfig.indices.CORRECT_WRONG_FLAG].hidden = true;\n\n // Tooltip.\n config.options.plugins.tooltip.filter = tooltipItemsFilter;\n config.options.plugins.tooltip.callbacks.afterLabel = afterTooltipItemLabel.bind(this);\n config.options.plugins.tooltip.itemSort = function (tooltip1, tooltip2) {\n return tooltip1.datasetIndex - tooltip2.datasetIndex;\n };\n\n // Legend.\n config.options.plugins.legend = legendConfig();\n\n return config;\n };\n\n return AttemptAdministrationChartOutput;\n});\n"],"names":["define","Output","Chartjs","DatasetConfig","tooltipItemsFilter","tooltipItem","datasetIndex","indices","STANDARD_ERROR_MAX","STANDARD_ERROR_MIN","afterTooltipItemLabel","ABILITY_MEASURE","ADMINISTERED_DIFFICULTY","stdErrorSeries","this","_chart","getSeries","STANDARD_ERROR_PERCENT","stdErrorValue","getValues","dataIndex","getLabel","rightWrongSeries","CORRECT_WRONG_FLAG","rightWrongValue","legendConfig","labels","generateLabels","chart","defaults","plugins","legend","stdErrorLabelText","find","label","text","filter","hidden","sort","label1","label2","stdErrorMaxIndex","findIndex","strokeStyle","fillStyle","onClick","AttemptAdministrationChartOutput","apply","arguments","prototype","Object","create","_makeConfig","config","data","datasets","order","orderWeights","TARGET_DIFFICULTY","STANDARD_ERROR_BORDER","pointRadius","pointStyle","showLine","options","tooltip","callbacks","afterLabel","bind","itemSort","tooltip1","tooltip2"],"mappings":";;;;;;;;;AAwBAA,8DAAO,CACH,4BACA,eACA,iEACD,SACCC,OACAC,QACAC,qBAcMC,mBAAqB,SAAUC,qBACxBA,YAAYC,eAAiBH,cAAcI,QAAQC,oBACrDH,YAAYC,eAAiBH,cAAcI,QAAQE,qBASxDC,sBAAwB,SAAUL,gBAE9BA,YAAYC,eAAiBH,cAAcI,QAAQI,iBAClDN,YAAYC,eAAiBH,cAAcI,QAAQK,8BAE/C,MAIPP,YAAYC,eAAiBH,cAAcI,QAAQI,gBAAiB,OAE9DE,eAAiBC,KAAKC,OAAOC,YAAYb,cAAcI,QAAQU,wBAC/DC,cAAgBL,eAAeM,YAAYd,YAAYe,2BAEnDP,eAAeQ,wBAAeH,qBAMtCI,iBAAmBR,KAAKC,OAAOC,YAAYb,cAAcI,QAAQgB,oBACjEC,gBAAkBF,iBAAiBH,YAAYd,YAAYe,2BAEvDE,iBAAiBD,wBAAeG,kBAQ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