current-date-indicator.src.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /**
  2. * @license Highcharts Gantt JS v9.0.1 (2021-02-16)
  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/Utilities.js'], _modules['Core/Axis/PlotLineOrBand.js']], function (Axis, palette, U, PlotLineOrBand) {
  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. var defaultConfig = {
  47. /**
  48. * Show an indicator on the axis for the current date and time. Can be a
  49. * boolean or a configuration object similar to
  50. * [xAxis.plotLines](#xAxis.plotLines).
  51. *
  52. * @sample gantt/current-date-indicator/demo
  53. * Current date indicator enabled
  54. * @sample gantt/current-date-indicator/object-config
  55. * Current date indicator with custom options
  56. *
  57. * @declare Highcharts.AxisCurrentDateIndicatorOptions
  58. * @type {boolean|*}
  59. * @default true
  60. * @extends xAxis.plotLines
  61. * @excluding value
  62. * @product gantt
  63. * @apioption xAxis.currentDateIndicator
  64. */
  65. currentDateIndicator: true,
  66. color: palette.highlightColor20,
  67. width: 2,
  68. /**
  69. * @declare Highcharts.AxisCurrentDateIndicatorLabelOptions
  70. */
  71. label: {
  72. /**
  73. * Format of the label. This options is passed as the fist argument to
  74. * [dateFormat](/class-reference/Highcharts#dateFormat) function.
  75. *
  76. * @type {string}
  77. * @default %a, %b %d %Y, %H:%M
  78. * @product gantt
  79. * @apioption xAxis.currentDateIndicator.label.format
  80. */
  81. format: '%a, %b %d %Y, %H:%M',
  82. formatter: function (value, format) {
  83. return this.axis.chart.time.dateFormat(format, value);
  84. },
  85. rotation: 0,
  86. /**
  87. * @type {Highcharts.CSSObject}
  88. */
  89. style: {
  90. /** @internal */
  91. fontSize: '10px'
  92. }
  93. }
  94. };
  95. /* eslint-disable no-invalid-this */
  96. addEvent(Axis, 'afterSetOptions', function () {
  97. var options = this.options,
  98. cdiOptions = options.currentDateIndicator;
  99. if (cdiOptions) {
  100. cdiOptions = typeof cdiOptions === 'object' ?
  101. merge(defaultConfig, cdiOptions) : merge(defaultConfig);
  102. cdiOptions.value = new Date();
  103. if (!options.plotLines) {
  104. options.plotLines = [];
  105. }
  106. options.plotLines.push(cdiOptions);
  107. }
  108. });
  109. addEvent(PlotLineOrBand, 'render', function () {
  110. // If the label already exists, update its text
  111. if (this.label) {
  112. this.label.attr({
  113. text: this.getLabelText(this.options.label)
  114. });
  115. }
  116. });
  117. wrap(PlotLineOrBand.prototype, 'getLabelText', function (defaultMethod, defaultLabelOptions) {
  118. var options = this.options;
  119. if (options.currentDateIndicator && options.label &&
  120. typeof options.label.formatter === 'function') {
  121. options.value = new Date();
  122. return options.label.formatter
  123. .call(this, options.value, options.label.format);
  124. }
  125. return defaultMethod.call(this, defaultLabelOptions);
  126. });
  127. });
  128. _registerModule(_modules, 'masters/modules/current-date-indicator.src.js', [], function () {
  129. });
  130. }));