current-date-indicator.src.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /**
  2. * @license Highcharts Gantt JS v8.0.0 (2019-12-10)
  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/Utilities.js']], function (H, U) {
  32. /* *
  33. *
  34. * (c) 2016-2019 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 wrap = U.wrap;
  44. var addEvent = H.addEvent, Axis = H.Axis, PlotLineOrBand = H.PlotLineOrBand, merge = H.merge;
  45. var defaultConfig = {
  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.AxisCurrentDateIndicatorOptions
  57. * @type {boolean|*}
  58. * @default true
  59. * @extends xAxis.plotLines
  60. * @excluding value
  61. * @product gantt
  62. * @apioption xAxis.currentDateIndicator
  63. */
  64. currentDateIndicator: true,
  65. color: '#ccd6eb',
  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 H.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, cdiOptions = options.currentDateIndicator;
  97. if (cdiOptions) {
  98. cdiOptions = typeof cdiOptions === 'object' ?
  99. merge(defaultConfig, cdiOptions) : merge(defaultConfig);
  100. cdiOptions.value = new Date();
  101. if (!options.plotLines) {
  102. options.plotLines = [];
  103. }
  104. options.plotLines.push(cdiOptions);
  105. }
  106. });
  107. addEvent(PlotLineOrBand, 'render', function () {
  108. // If the label already exists, update its text
  109. if (this.label) {
  110. this.label.attr({
  111. text: this.getLabelText(this.options.label)
  112. });
  113. }
  114. });
  115. wrap(PlotLineOrBand.prototype, 'getLabelText', function (defaultMethod, defaultLabelOptions) {
  116. var options = this.options;
  117. if (options.currentDateIndicator && options.label &&
  118. typeof options.label.formatter === 'function') {
  119. options.value = new Date();
  120. return options.label.formatter
  121. .call(this, options.value, options.label.format);
  122. }
  123. return defaultMethod.call(this, defaultLabelOptions);
  124. });
  125. });
  126. _registerModule(_modules, 'masters/modules/current-date-indicator.src.js', [], function () {
  127. });
  128. }));