current-date-indicator.src.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /**
  2. * @license Highcharts Gantt JS v9.1.1 (2021-06-04)
  3. *
  4. * CurrentDateIndicator
  5. *
  6. * (c) 2010-2021 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/Axis/Axis.js'], _modules['Core/Color/Palette.js'], _modules['Core/Axis/PlotLineOrBand.js'], _modules['Core/Utilities.js']], function (Axis, Palette, PlotLineOrBand, U) {
  32. /* *
  33. *
  34. * (c) 2016-2021 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 addEvent = U.addEvent,
  44. merge = U.merge,
  45. wrap = U.wrap;
  46. /**
  47. * Show an indicator on the axis for the current date and time. Can be a
  48. * boolean or a configuration object similar to
  49. * [xAxis.plotLines](#xAxis.plotLines).
  50. *
  51. * @sample gantt/current-date-indicator/demo
  52. * Current date indicator enabled
  53. * @sample gantt/current-date-indicator/object-config
  54. * Current date indicator with custom options
  55. *
  56. * @declare Highcharts.CurrentDateIndicatorOptions
  57. * @type {boolean|CurrentDateIndicatorOptions}
  58. * @default true
  59. * @extends xAxis.plotLines
  60. * @excluding value
  61. * @product gantt
  62. * @apioption xAxis.currentDateIndicator
  63. */
  64. var defaultOptions = {
  65. color: Palette.highlightColor20,
  66. width: 2,
  67. /**
  68. * @declare Highcharts.AxisCurrentDateIndicatorLabelOptions
  69. */
  70. label: {
  71. /**
  72. * Format of the label. This options is passed as the fist argument to
  73. * [dateFormat](/class-reference/Highcharts#.dateFormat) function.
  74. *
  75. * @type {string}
  76. * @default %a, %b %d %Y, %H:%M
  77. * @product gantt
  78. * @apioption xAxis.currentDateIndicator.label.format
  79. */
  80. format: '%a, %b %d %Y, %H:%M',
  81. formatter: function (value, format) {
  82. return this.axis.chart.time.dateFormat(format || '', value);
  83. },
  84. rotation: 0,
  85. /**
  86. * @type {Highcharts.CSSObject}
  87. */
  88. style: {
  89. /** @internal */
  90. fontSize: '10px'
  91. }
  92. }
  93. };
  94. /* eslint-disable no-invalid-this */
  95. addEvent(Axis, 'afterSetOptions', function () {
  96. var options = this.options,
  97. cdiOptions = options.currentDateIndicator;
  98. if (cdiOptions) {
  99. var plotLineOptions = typeof cdiOptions === 'object' ?
  100. merge(defaultOptions,
  101. cdiOptions) :
  102. merge(defaultOptions);
  103. plotLineOptions.value = Date.now();
  104. plotLineOptions.className = 'highcharts-current-date-indicator';
  105. if (!options.plotLines) {
  106. options.plotLines = [];
  107. }
  108. options.plotLines.push(plotLineOptions);
  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 &&
  122. options.className &&
  123. options.className.indexOf('highcharts-current-date-indicator') !== -1 &&
  124. options.label &&
  125. typeof options.label.formatter === 'function') {
  126. options.value = Date.now();
  127. return options.label.formatter
  128. .call(this, options.value, options.label.format);
  129. }
  130. return defaultMethod.call(this, defaultLabelOptions);
  131. });
  132. });
  133. _registerModule(_modules, 'masters/modules/current-date-indicator.src.js', [], function () {
  134. });
  135. }));