debugger.src.js
2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/* *
*
* (c) 2010-2019 Torstein Honsi
*
* License: www.highcharts.com/license
*
* !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
*
* */
'use strict';
import H from '../parts/Globals.js';
import U from '../parts/Utilities.js';
var isNumber = U.isNumber;
var addEvent = H.addEvent, setOptions = H.setOptions, each = H.each;
setOptions({
/**
* @optionparent chart
*/
chart: {
/**
* Whether to display errors on the chart. When `false`, the errors will
* be shown only in the console.
*
* Requires `debugger.js` module.
*
* @sample highcharts/chart/display-errors/
* Show errors on chart
*
* @since 7.0.0
*/
displayErrors: true
}
});
/* eslint-disable no-invalid-this */
addEvent(H.Chart, 'displayError', function (e) {
var chart = this, code = e.code, msg, options = chart.options.chart, renderer = chart.renderer, chartWidth, chartHeight;
if (chart.errorElements) {
each(chart.errorElements, function (el) {
if (el) {
el.destroy();
}
});
}
if (options && options.displayErrors) {
chart.errorElements = [];
msg = isNumber(code) ?
('Highcharts error #' + code + ': ' +
H.errorMessages[code].title +
H.errorMessages[code].text) :
code;
chartWidth = chart.chartWidth;
chartHeight = chart.chartHeight;
// Render red chart frame.
chart.errorElements[0] = renderer.rect(2, 2, chartWidth - 4, chartHeight - 4).attr({
'stroke-width': 4,
stroke: '#ff0000',
zIndex: 3
}).add();
// Render error message.
chart.errorElements[1] = renderer.label(msg, 0, 0, 'rect', null, null, true).css({
color: '#ffffff',
width: chartWidth - 16,
padding: 0
}).attr({
fill: '#ff0000',
width: chartWidth,
padding: 8,
zIndex: 10
}).add();
chart.errorElements[1].attr({
y: chartHeight - this.errorElements[1].getBBox().height
});
}
});
addEvent(H.Chart, 'beforeRedraw', function () {
var errorElements = this.errorElements;
if (errorElements && errorElements.length) {
each(errorElements, function (el) {
el.destroy();
});
}
this.errorElements = null;
});