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

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