current-date-indicator.src.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /**
  2. * @license Highcharts Gantt JS v8.1.2 (2020-06-16)
  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, 'parts-gantt/CurrentDateIndicator.js', [_modules['parts/Globals.js'], _modules['parts/Options.js'], _modules['parts/Utilities.js'], _modules['parts/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, merge = U.merge, wrap = U.wrap;
  45. var Axis = H.Axis;
  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: '#ccd6eb',
  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 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, cdiOptions = options.currentDateIndicator;
  98. if (cdiOptions) {
  99. cdiOptions = typeof cdiOptions === 'object' ?
  100. merge(defaultConfig, cdiOptions) : merge(defaultConfig);
  101. cdiOptions.value = new Date();
  102. if (!options.plotLines) {
  103. options.plotLines = [];
  104. }
  105. options.plotLines.push(cdiOptions);
  106. }
  107. });
  108. addEvent(PlotLineOrBand, 'render', function () {
  109. // If the label already exists, update its text
  110. if (this.label) {
  111. this.label.attr({
  112. text: this.getLabelText(this.options.label)
  113. });
  114. }
  115. });
  116. wrap(PlotLineOrBand.prototype, 'getLabelText', function (defaultMethod, defaultLabelOptions) {
  117. var options = this.options;
  118. if (options.currentDateIndicator && options.label &&
  119. typeof options.label.formatter === 'function') {
  120. options.value = new Date();
  121. return options.label.formatter
  122. .call(this, options.value, options.label.format);
  123. }
  124. return defaultMethod.call(this, defaultLabelOptions);
  125. });
  126. });
  127. _registerModule(_modules, 'masters/modules/current-date-indicator.src.js', [], function () {
  128. });
  129. }));