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

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