6cfa9ac4326dc49ebabb09ec1e90b85029eead3c.svn-base 3.0 KB

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