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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. /**
  2. * @license Highcharts JS v9.1.1 (2021-06-04)
  3. *
  4. * Plugin for displaying a message when there is no data visible in chart.
  5. *
  6. * (c) 2010-2021 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/Renderer/HTML/AST.js'], _modules['Core/Chart/Chart.js'], _modules['Core/DefaultOptions.js'], _modules['Core/Color/Palette.js'], _modules['Core/Utilities.js']], function (AST, Chart, D, palette, U) {
  33. /* *
  34. *
  35. * Plugin for displaying a message when there is no data visible in chart.
  36. *
  37. * (c) 2010-2021 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 getOptions = D.getOptions;
  47. var addEvent = U.addEvent,
  48. extend = U.extend;
  49. var chartPrototype = 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: palette.neutralColor60
  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.renderer) { // Meaning chart is not destroyed
  168. if (!chart.noDataLabel) {
  169. chart.noDataLabel = chart.renderer
  170. .label(text, 0, 0, void 0, void 0, void 0, noDataOptions.useHTML, void 0, 'no-data')
  171. .add();
  172. }
  173. if (!chart.styledMode) {
  174. chart.noDataLabel
  175. .attr(AST.filterUserAttributes(noDataOptions.attr || {}))
  176. .css(noDataOptions.style || {});
  177. }
  178. chart.noDataLabel.align(extend(chart.noDataLabel.getBBox(), noDataOptions.position || {}), false, 'plotBox');
  179. }
  180. };
  181. /**
  182. * Hide no-data message.
  183. *
  184. * @private
  185. * @function Highcharts.Chart#hideNoData
  186. * @return {void}
  187. * @requires modules/no-data-to-display
  188. */
  189. chartPrototype.hideNoData = function () {
  190. var chart = this;
  191. if (chart.noDataLabel) {
  192. chart.noDataLabel = chart.noDataLabel.destroy();
  193. }
  194. };
  195. /**
  196. * Returns true if there are data points within the plot area now.
  197. *
  198. * @private
  199. * @function Highcharts.Chart#hasData
  200. * @return {boolean|undefined}
  201. * True, if there are data points.
  202. * @requires modules/no-data-to-display
  203. */
  204. chartPrototype.hasData = function () {
  205. var chart = this,
  206. series = chart.series || [],
  207. i = series.length;
  208. while (i--) {
  209. if (series[i].hasData() && !series[i].options.isInternal) {
  210. return true;
  211. }
  212. }
  213. return chart.loadingShown; // #4588
  214. };
  215. /* eslint-disable no-invalid-this */
  216. // Add event listener to handle automatic show or hide no-data message.
  217. addEvent(Chart, 'render', function handleNoData() {
  218. if (this.hasData()) {
  219. this.hideNoData();
  220. }
  221. else {
  222. this.showNoData();
  223. }
  224. });
  225. });
  226. _registerModule(_modules, 'masters/modules/no-data-to-display.src.js', [], function () {
  227. });
  228. }));