current-date-indicator.src.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /**
  2. * @license Highcharts Gantt JS v8.2.0 (2020-08-20)
  3. *
  4. * CurrentDateIndicator
  5. *
  6. * (c) 2010-2019 Lars A. V. Cabrera
  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('highcharts/modules/current-date-indicator', ['highcharts'], function (Highcharts) {
  17. factory(Highcharts);
  18. factory.Highcharts = Highcharts;
  19. return factory;
  20. });
  21. } else {
  22. factory(typeof Highcharts !== 'undefined' ? Highcharts : undefined);
  23. }
  24. }(function (Highcharts) {
  25. var _modules = Highcharts ? Highcharts._modules : {};
  26. function _registerModule(obj, path, args, fn) {
  27. if (!obj.hasOwnProperty(path)) {
  28. obj[path] = fn.apply(null, args);
  29. }
  30. }
  31. _registerModule(_modules, 'Extensions/CurrentDateIndication.js', [_modules['Core/Globals.js'], _modules['Core/Options.js'], _modules['Core/Utilities.js'], _modules['Core/Axis/PlotLineOrBand.js']], function (H, O, U, PlotLineOrBand) {
  32. /* *
  33. *
  34. * (c) 2016-2020 Highsoft AS
  35. *
  36. * Author: Lars A. V. Cabrera
  37. *
  38. * License: www.highcharts.com/license
  39. *
  40. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  41. *
  42. * */
  43. var dateFormat = O.dateFormat;
  44. var addEvent = U.addEvent,
  45. merge = U.merge,
  46. wrap = U.wrap;
  47. var Axis = H.Axis;
  48. var defaultConfig = {
  49. /**
  50. * Show an indicator on the axis for the current date and time. Can be a
  51. * boolean or a configuration object similar to
  52. * [xAxis.plotLines](#xAxis.plotLines).
  53. *
  54. * @sample gantt/current-date-indicator/demo
  55. * Current date indicator enabled
  56. * @sample gantt/current-date-indicator/object-config
  57. * Current date indicator with custom options
  58. *
  59. * @declare Highcharts.AxisCurrentDateIndicatorOptions
  60. * @type {boolean|*}
  61. * @default true
  62. * @extends xAxis.plotLines
  63. * @excluding value
  64. * @product gantt
  65. * @apioption xAxis.currentDateIndicator
  66. */
  67. currentDateIndicator: true,
  68. color: '#ccd6eb',
  69. width: 2,
  70. /**
  71. * @declare Highcharts.AxisCurrentDateIndicatorLabelOptions
  72. */
  73. label: {
  74. /**
  75. * Format of the label. This options is passed as the fist argument to
  76. * [dateFormat](/class-reference/Highcharts#dateFormat) function.
  77. *
  78. * @type {string}
  79. * @default '%a, %b %d %Y, %H:%M'
  80. * @product gantt
  81. * @apioption xAxis.currentDateIndicator.label.format
  82. */
  83. format: '%a, %b %d %Y, %H:%M',
  84. formatter: function (value, format) {
  85. return dateFormat(format, value);
  86. },
  87. rotation: 0,
  88. /**
  89. * @type {Highcharts.CSSObject}
  90. */
  91. style: {
  92. /** @internal */
  93. fontSize: '10px'
  94. }
  95. }
  96. };
  97. /* eslint-disable no-invalid-this */
  98. addEvent(Axis, 'afterSetOptions', function () {
  99. var options = this.options,
  100. cdiOptions = options.currentDateIndicator;
  101. if (cdiOptions) {
  102. cdiOptions = typeof cdiOptions === 'object' ?
  103. merge(defaultConfig, cdiOptions) : merge(defaultConfig);
  104. cdiOptions.value = new Date();
  105. if (!options.plotLines) {
  106. options.plotLines = [];
  107. }
  108. options.plotLines.push(cdiOptions);
  109. }
  110. });
  111. addEvent(PlotLineOrBand, 'render', function () {
  112. // If the label already exists, update its text
  113. if (this.label) {
  114. this.label.attr({
  115. text: this.getLabelText(this.options.label)
  116. });
  117. }
  118. });
  119. wrap(PlotLineOrBand.prototype, 'getLabelText', function (defaultMethod, defaultLabelOptions) {
  120. var options = this.options;
  121. if (options.currentDateIndicator && options.label &&
  122. typeof options.label.formatter === 'function') {
  123. options.value = new Date();
  124. return options.label.formatter
  125. .call(this, options.value, options.label.format);
  126. }
  127. return defaultMethod.call(this, defaultLabelOptions);
  128. });
  129. });
  130. _registerModule(_modules, 'masters/modules/current-date-indicator.src.js', [], function () {
  131. });
  132. }));