debugger.src.js 2.5 KB

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