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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. /**
  2. * @license Highcharts JS v8.2.0 (2020-08-20)
  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, 'Extensions/NoDataToDisplay.js', [_modules['Core/Globals.js'], _modules['Core/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-2020 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 addEvent = U.addEvent,
  47. extend = U.extend,
  48. getOptions = U.getOptions;
  49. var chartPrototype = H.Chart.prototype,
  50. defaultOptions = getOptions();
  51. // Add language option
  52. extend(defaultOptions.lang,
  53. /**
  54. * @optionparent lang
  55. */
  56. {
  57. /**
  58. * The text to display when the chart contains no data.
  59. *
  60. * @see [noData](#noData)
  61. *
  62. * @sample highcharts/no-data-to-display/no-data-line
  63. * No-data text
  64. *
  65. * @since 3.0.8
  66. * @product highcharts highstock
  67. * @requires modules/no-data-to-display
  68. */
  69. noData: 'No data to display'
  70. });
  71. // Add default display options for message
  72. /**
  73. * Options for displaying a message like "No data to display".
  74. * This feature requires the file no-data-to-display.js to be loaded in the
  75. * page. The actual text to display is set in the lang.noData option.
  76. *
  77. * @sample highcharts/no-data-to-display/no-data-line
  78. * Line chart with no-data module
  79. * @sample highcharts/no-data-to-display/no-data-pie
  80. * Pie chart with no-data module
  81. *
  82. * @product highcharts highstock gantt
  83. * @requires modules/no-data-to-display
  84. * @optionparent noData
  85. */
  86. defaultOptions.noData = {
  87. /**
  88. * An object of additional SVG attributes for the no-data label.
  89. *
  90. * @type {Highcharts.SVGAttributes}
  91. * @since 3.0.8
  92. * @product highcharts highstock gantt
  93. * @apioption noData.attr
  94. */
  95. attr: {
  96. zIndex: 1
  97. },
  98. /**
  99. * Whether to insert the label as HTML, or as pseudo-HTML rendered with
  100. * SVG.
  101. *
  102. * @type {boolean}
  103. * @default false
  104. * @since 4.1.10
  105. * @product highcharts highstock gantt
  106. * @apioption noData.useHTML
  107. */
  108. /**
  109. * The position of the no-data label, relative to the plot area.
  110. *
  111. * @type {Highcharts.AlignObject}
  112. * @since 3.0.8
  113. */
  114. position: {
  115. /**
  116. * Horizontal offset of the label, in pixels.
  117. */
  118. x: 0,
  119. /**
  120. * Vertical offset of the label, in pixels.
  121. */
  122. y: 0,
  123. /**
  124. * Horizontal alignment of the label.
  125. *
  126. * @type {Highcharts.AlignValue}
  127. */
  128. align: 'center',
  129. /**
  130. * Vertical alignment of the label.
  131. *
  132. * @type {Highcharts.VerticalAlignValue}
  133. */
  134. verticalAlign: 'middle'
  135. },
  136. /**
  137. * CSS styles for the no-data label.
  138. *
  139. * @sample highcharts/no-data-to-display/no-data-line
  140. * Styled no-data text
  141. *
  142. * @type {Highcharts.CSSObject}
  143. */
  144. style: {
  145. /** @ignore */
  146. fontWeight: 'bold',
  147. /** @ignore */
  148. fontSize: '12px',
  149. /** @ignore */
  150. color: '#666666'
  151. }
  152. };
  153. /**
  154. * Display a no-data message.
  155. * @private
  156. * @function Highcharts.Chart#showNoData
  157. * @param {string} [str]
  158. * An optional message to show in place of the default one
  159. * @return {void}
  160. * @requires modules/no-data-to-display
  161. */
  162. chartPrototype.showNoData = function (str) {
  163. var chart = this,
  164. options = chart.options,
  165. text = str || (options && options.lang.noData),
  166. noDataOptions = options && options.noData;
  167. if (!chart.noDataLabel && chart.renderer) {
  168. chart.noDataLabel = chart.renderer
  169. .label(text, 0, 0, null, null, null, noDataOptions.useHTML, null, 'no-data');
  170. if (!chart.styledMode) {
  171. chart.noDataLabel
  172. .attr(noDataOptions.attr)
  173. .css(noDataOptions.style);
  174. }
  175. chart.noDataLabel.add();
  176. chart.noDataLabel.align(extend(chart.noDataLabel.getBBox(), noDataOptions.position), false, 'plotBox');
  177. }
  178. };
  179. /**
  180. * Hide no-data message.
  181. *
  182. * @private
  183. * @function Highcharts.Chart#hideNoData
  184. * @return {void}
  185. * @requires modules/no-data-to-display
  186. */
  187. chartPrototype.hideNoData = function () {
  188. var chart = this;
  189. if (chart.noDataLabel) {
  190. chart.noDataLabel = chart.noDataLabel.destroy();
  191. }
  192. };
  193. /**
  194. * Returns true if there are data points within the plot area now.
  195. *
  196. * @private
  197. * @function Highcharts.Chart#hasData
  198. * @return {boolean|undefined}
  199. * True, if there are data points.
  200. * @requires modules/no-data-to-display
  201. */
  202. chartPrototype.hasData = function () {
  203. var chart = this,
  204. series = chart.series || [],
  205. i = series.length;
  206. while (i--) {
  207. if (series[i].hasData() && !series[i].options.isInternal) {
  208. return true;
  209. }
  210. }
  211. return chart.loadingShown; // #4588
  212. };
  213. /* eslint-disable no-invalid-this */
  214. // Add event listener to handle automatic show or hide no-data message.
  215. addEvent(H.Chart, 'render', function handleNoData() {
  216. if (this.hasData()) {
  217. this.hideNoData();
  218. }
  219. else {
  220. this.showNoData();
  221. }
  222. });
  223. });
  224. _registerModule(_modules, 'masters/modules/no-data-to-display.src.js', [], function () {
  225. });
  226. }));