Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 186... Línea 186...
186
     * @protected
186
     * @protected
187
     * @return {Object} The axis config.
187
     * @return {Object} The axis config.
188
     */
188
     */
189
    Output.prototype._makeConfig = function() {
189
    Output.prototype._makeConfig = function() {
190
        var charType = this._getChartType();
190
        var charType = this._getChartType();
-
 
191
        var labels = this._cleanData(this._chart.getLabels());
191
        var config = {
192
        var config = {
192
            type: charType,
193
            type: charType,
193
            data: {
194
            data: {
-
 
195
                // If the label is longer than 25 characters, truncate it and add an
-
 
196
                // ellipsis to avoid breaking the chart.
194
                labels: this._cleanData(this._chart.getLabels()),
197
                labels: labels.map((label) => {
-
 
198
                    return label.length > 25 ? `${label.substring(0, 25)}...` : label;
-
 
199
                }),
195
                datasets: this._makeDatasetsConfig()
200
                datasets: this._makeDatasetsConfig()
196
            },
201
            },
197
            options: {
202
            options: {
-
 
203
                locale: document.documentElement.getAttribute('lang'),
198
                responsive: true,
204
                responsive: true,
199
                maintainAspectRatio: false,
205
                maintainAspectRatio: false,
200
                plugins: {
206
                plugins: {
201
                    title: {
207
                    title: {
202
                        display: this._chart.getTitle() !== null,
208
                        display: this._chart.getTitle() !== null,
Línea 219... Línea 225...
219
 
225
 
220
        this._chart.getXAxes().forEach(function(axis, i) {
226
        this._chart.getXAxes().forEach(function(axis, i) {
Línea 221... Línea 227...
221
            var axisLabels = axis.getLabels();
227
            var axisLabels = axis.getLabels();
222
 
-
 
223
            config.options.scales = config.options.scales || {};
228
 
Línea 224... Línea 229...
224
            config.options.scales.x = config.options.scales.x || {};
229
            config.options.scales = config.options.scales || {};
225
            config.options.scales.x[i] = this._makeAxisConfig(axis, 'x', i);
230
            config.options.scales.x = this._makeAxisConfig(axis, 'x', i);
226
 
231
 
227
            if (axisLabels !== null) {
232
            if (axisLabels !== null) {
228
                config.options.scales.x[i].ticks.callback = function(value, index) {
233
                config.options.scales.x.ticks.callback = function(value, index) {
229
                    return axisLabels[index] || '';
234
                    return axisLabels[index] || '';
230
                };
235
                };
Línea 231... Línea 236...
231
            }
236
            }
232
            config.options.scales.x.stacked = this._isStacked();
237
            config.options.scales.x.stacked = this._isStacked();
Línea 233... Línea 238...
233
        }.bind(this));
238
        }.bind(this));
234
 
-
 
235
        this._chart.getYAxes().forEach(function(axis, i) {
239
 
Línea 236... Línea 240...
236
            var axisLabels = axis.getLabels();
240
        this._chart.getYAxes().forEach(function(axis, i) {
237
 
241
            var axisLabels = axis.getLabels();
238
            config.options.scales = config.options.scales || {};
242
 
239
            config.options.scales.y = config.options.scales.yAxes || {};
243
            config.options.scales = config.options.scales || {};
240
            config.options.scales.y[i] = this._makeAxisConfig(axis, 'y', i);
244
            config.options.scales.y = this._makeAxisConfig(axis, 'y', i);
241
 
245
 
242
            if (axisLabels !== null) {
246
            if (axisLabels !== null) {
Línea 243... Línea 247...
243
                config.options.scales.y[i].ticks.callback = function(value) {
247
                config.options.scales.y.ticks.callback = function(value) {
244
                    return axisLabels[parseInt(value, 10)] || '';
248
                    return axisLabels[parseInt(value, 10)] || '';
-
 
249
                };
-
 
250
            }
-
 
251
            config.options.scales.y.stacked = this._isStacked();
-
 
252
        }.bind(this));
-
 
253
 
-
 
254
        config.options.plugins.tooltip = {
245
                };
255
            callbacks: {
246
            }
256
                title: (ctx) => {
247
            config.options.scales.y.stacked = this._isStacked();
257
                    // Add line breaks to the tooltip title to prevent the tooltip from cutting
Línea 248... Línea 258...
248
        }.bind(this));
258
                    // off if the title has a character count that overlaps the width of the chart.
Línea 296... Línea 306...
296
     * @protected
306
     * @protected
297
     */
307
     */
298
    Output.prototype._makeTooltip = function(tooltipItem) {
308
    Output.prototype._makeTooltip = function(tooltipItem) {
Línea 299... Línea 309...
299
 
309
 
-
 
310
        // Get series and chart data to rebuild the tooltip and add labels.
300
        // Get series and chart data to rebuild the tooltip and add labels.
311
        const formatter = new Intl.NumberFormat(this._config.options.locale);
301
        var series = this._chart.getSeries()[tooltipItem.datasetIndex];
312
        var series = this._chart.getSeries()[tooltipItem.datasetIndex];
302
        var serieLabel = series.getLabel();
313
        var serieLabel = series.getLabel();
303
        var chartData = tooltipItem.dataset.data;
314
        var chartData = tooltipItem.dataset.data;
Línea 304... Línea 315...
304
        var tooltipData = chartData[tooltipItem.dataIndex];
315
        var tooltipData = formatter.format(chartData[tooltipItem.dataIndex]);
305
 
316
 
Línea 306... Línea 317...
306
        // Build default tooltip.
317
        // Build default tooltip.