no-data-to-display.src.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /**
  2. * @license Highcharts JS v5.0.6 (2016-12-07)
  3. * Plugin for displaying a message when there is no data visible in chart.
  4. *
  5. * (c) 2010-2016 Highsoft AS
  6. * Author: Oystein Moseng
  7. *
  8. * License: www.highcharts.com/license
  9. */
  10. (function(factory) {
  11. if (typeof module === 'object' && module.exports) {
  12. module.exports = factory;
  13. } else {
  14. factory(Highcharts);
  15. }
  16. }(function(Highcharts) {
  17. (function(H) {
  18. /**
  19. * Plugin for displaying a message when there is no data visible in chart.
  20. *
  21. * (c) 2010-2016 Highsoft AS
  22. * Author: Oystein Moseng
  23. *
  24. * License: www.highcharts.com/license
  25. */
  26. 'use strict';
  27. var seriesTypes = H.seriesTypes,
  28. chartPrototype = H.Chart.prototype,
  29. defaultOptions = H.getOptions(),
  30. extend = H.extend,
  31. each = H.each;
  32. // Add language option
  33. extend(defaultOptions.lang, {
  34. noData: 'No data to display'
  35. });
  36. // Add default display options for message
  37. defaultOptions.noData = {
  38. position: {
  39. x: 0,
  40. y: 0,
  41. align: 'center',
  42. verticalAlign: 'middle'
  43. }
  44. // useHTML: false
  45. };
  46. /**
  47. * Define hasData functions for series. These return true if there are data points on this series within the plot area
  48. */
  49. function hasDataPie() {
  50. return !!this.points.length; /* != 0 */
  51. }
  52. each(['pie', 'gauge', 'waterfall', 'bubble', 'treemap'], function(type) {
  53. if (seriesTypes[type]) {
  54. seriesTypes[type].prototype.hasData = hasDataPie;
  55. }
  56. });
  57. H.Series.prototype.hasData = function() {
  58. return this.visible && this.dataMax !== undefined && this.dataMin !== undefined; // #3703
  59. };
  60. /**
  61. * Display a no-data message.
  62. *
  63. * @param {String} str An optional message to show in place of the default one
  64. */
  65. chartPrototype.showNoData = function(str) {
  66. var chart = this,
  67. options = chart.options,
  68. text = str || options.lang.noData,
  69. noDataOptions = options.noData;
  70. if (!chart.noDataLabel) {
  71. chart.noDataLabel = chart.renderer
  72. .label(
  73. text,
  74. 0,
  75. 0,
  76. null,
  77. null,
  78. null,
  79. noDataOptions.useHTML,
  80. null,
  81. 'no-data'
  82. );
  83. chart.noDataLabel.add();
  84. chart.noDataLabel.align(extend(chart.noDataLabel.getBBox(), noDataOptions.position), false, 'plotBox');
  85. }
  86. };
  87. /**
  88. * Hide no-data message
  89. */
  90. chartPrototype.hideNoData = function() {
  91. var chart = this;
  92. if (chart.noDataLabel) {
  93. chart.noDataLabel = chart.noDataLabel.destroy();
  94. }
  95. };
  96. /**
  97. * Returns true if there are data points within the plot area now
  98. */
  99. chartPrototype.hasData = function() {
  100. var chart = this,
  101. series = chart.series,
  102. i = series.length;
  103. while (i--) {
  104. if (series[i].hasData() && !series[i].options.isInternal) {
  105. return true;
  106. }
  107. }
  108. return false;
  109. };
  110. /**
  111. * Show no-data message if there is no data in sight. Otherwise, hide it.
  112. */
  113. function handleNoData() {
  114. var chart = this;
  115. if (chart.hasData()) {
  116. chart.hideNoData();
  117. } else {
  118. chart.showNoData();
  119. }
  120. }
  121. /**
  122. * Add event listener to handle automatic display of no-data message
  123. */
  124. chartPrototype.callbacks.push(function(chart) {
  125. H.addEvent(chart, 'load', handleNoData);
  126. H.addEvent(chart, 'redraw', handleNoData);
  127. });
  128. }(Highcharts));
  129. }));