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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /**
  2. * @license Highcharts JS v8.0.0 (2019-12-10)
  3. *
  4. * Plugin for displaying a message when there is no data visible in chart.
  5. *
  6. * (c) 2010-2019 Highsoft AS
  7. * Author: Oystein Moseng
  8. *
  9. * License: www.highcharts.com/license
  10. */
  11. 'use strict';
  12. (function (factory) {
  13. if (typeof module === 'object' && module.exports) {
  14. factory['default'] = factory;
  15. module.exports = factory;
  16. } else if (typeof define === 'function' && define.amd) {
  17. define('highcharts/modules/no-data-to-display', ['highcharts'], function (Highcharts) {
  18. factory(Highcharts);
  19. factory.Highcharts = Highcharts;
  20. return factory;
  21. });
  22. } else {
  23. factory(typeof Highcharts !== 'undefined' ? Highcharts : undefined);
  24. }
  25. }(function (Highcharts) {
  26. var _modules = Highcharts ? Highcharts._modules : {};
  27. function _registerModule(obj, path, args, fn) {
  28. if (!obj.hasOwnProperty(path)) {
  29. obj[path] = fn.apply(null, args);
  30. }
  31. }
  32. _registerModule(_modules, 'modules/no-data-to-display.src.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js']], function (H, U) {
  33. /* *
  34. *
  35. * Plugin for displaying a message when there is no data visible in chart.
  36. *
  37. * (c) 2010-2019 Highsoft AS
  38. *
  39. * Author: Oystein Moseng
  40. *
  41. * License: www.highcharts.com/license
  42. *
  43. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  44. *
  45. * */
  46. var extend = U.extend;
  47. var chartPrototype = H.Chart.prototype, defaultOptions = H.getOptions();
  48. // Add language option
  49. extend(defaultOptions.lang,
  50. /**
  51. * @optionparent lang
  52. */
  53. {
  54. /**
  55. * The text to display when the chart contains no data.
  56. *
  57. * @see [noData](#noData)
  58. *
  59. * @sample highcharts/no-data-to-display/no-data-line
  60. * No-data text
  61. *
  62. * @since 3.0.8
  63. * @product highcharts highstock
  64. * @requires modules/no-data-to-display
  65. */
  66. noData: 'No data to display'
  67. });
  68. // Add default display options for message
  69. /**
  70. * Options for displaying a message like "No data to display".
  71. * This feature requires the file no-data-to-display.js to be loaded in the
  72. * page. The actual text to display is set in the lang.noData option.
  73. *
  74. * @sample highcharts/no-data-to-display/no-data-line
  75. * Line chart with no-data module
  76. * @sample highcharts/no-data-to-display/no-data-pie
  77. * Pie chart with no-data module
  78. *
  79. * @product highcharts highstock gantt
  80. * @requires modules/no-data-to-display
  81. * @optionparent noData
  82. */
  83. defaultOptions.noData = {
  84. /**
  85. * An object of additional SVG attributes for the no-data label.
  86. *
  87. * @type {Highcharts.SVGAttributes}
  88. * @since 3.0.8
  89. * @product highcharts highstock gantt
  90. * @apioption noData.attr
  91. */
  92. attr: {
  93. zIndex: 1
  94. },
  95. /**
  96. * Whether to insert the label as HTML, or as pseudo-HTML rendered with
  97. * SVG.
  98. *
  99. * @type {boolean}
  100. * @default false
  101. * @since 4.1.10
  102. * @product highcharts highstock gantt
  103. * @apioption noData.useHTML
  104. */
  105. /**
  106. * The position of the no-data label, relative to the plot area.
  107. *
  108. * @type {Highcharts.AlignObject}
  109. * @since 3.0.8
  110. */
  111. position: {
  112. /**
  113. * Horizontal offset of the label, in pixels.
  114. */
  115. x: 0,
  116. /**
  117. * Vertical offset of the label, in pixels.
  118. */
  119. y: 0,
  120. /**
  121. * Horizontal alignment of the label.
  122. *
  123. * @type {Highcharts.AlignValue}
  124. */
  125. align: 'center',
  126. /**
  127. * Vertical alignment of the label.
  128. *
  129. * @type {Highcharts.VerticalAlignValue}
  130. */
  131. verticalAlign: 'middle'
  132. },
  133. /**
  134. * CSS styles for the no-data label.
  135. *
  136. * @sample highcharts/no-data-to-display/no-data-line
  137. * Styled no-data text
  138. *
  139. * @type {Highcharts.CSSObject}
  140. */
  141. style: {
  142. /** @ignore */
  143. fontWeight: 'bold',
  144. /** @ignore */
  145. fontSize: '12px',
  146. /** @ignore */
  147. color: '#666666'
  148. }
  149. };
  150. /**
  151. * Display a no-data message.
  152. * @private
  153. * @function Highcharts.Chart#showNoData
  154. * @param {string} [str]
  155. * An optional message to show in place of the default one
  156. * @return {void}
  157. * @requires modules/no-data-to-display
  158. */
  159. chartPrototype.showNoData = function (str) {
  160. var chart = this, options = chart.options, text = str || (options && options.lang.noData), noDataOptions = options && options.noData;
  161. if (!chart.noDataLabel && chart.renderer) {
  162. chart.noDataLabel = chart.renderer
  163. .label(text, 0, 0, null, null, null, noDataOptions.useHTML, null, 'no-data');
  164. if (!chart.styledMode) {
  165. chart.noDataLabel
  166. .attr(noDataOptions.attr)
  167. .css(noDataOptions.style);
  168. }
  169. chart.noDataLabel.add();
  170. chart.noDataLabel.align(extend(chart.noDataLabel.getBBox(), noDataOptions.position), false, 'plotBox');
  171. }
  172. };
  173. /**
  174. * Hide no-data message.
  175. *
  176. * @private
  177. * @function Highcharts.Chart#hideNoData
  178. * @return {void}
  179. * @requires modules/no-data-to-display
  180. */
  181. chartPrototype.hideNoData = function () {
  182. var chart = this;
  183. if (chart.noDataLabel) {
  184. chart.noDataLabel = chart.noDataLabel.destroy();
  185. }
  186. };
  187. /**
  188. * Returns true if there are data points within the plot area now.
  189. *
  190. * @private
  191. * @function Highcharts.Chart#hasData
  192. * @return {boolean|undefined}
  193. * True, if there are data points.
  194. * @requires modules/no-data-to-display
  195. */
  196. chartPrototype.hasData = function () {
  197. var chart = this, series = chart.series || [], i = series.length;
  198. while (i--) {
  199. if (series[i].hasData() && !series[i].options.isInternal) {
  200. return true;
  201. }
  202. }
  203. return chart.loadingShown; // #4588
  204. };
  205. /* eslint-disable no-invalid-this */
  206. // Add event listener to handle automatic show or hide no-data message.
  207. H.addEvent(H.Chart, 'render', function handleNoData() {
  208. if (this.hasData()) {
  209. this.hideNoData();
  210. }
  211. else {
  212. this.showNoData();
  213. }
  214. });
  215. });
  216. _registerModule(_modules, 'masters/modules/no-data-to-display.src.js', [], function () {
  217. });
  218. }));