current-date-indicator.src.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /**
  2. * @license Highcharts JS v7.0.2 (2019-01-17)
  3. * CurrentDateIndicator
  4. *
  5. * (c) 2010-2019 Lars A. V. Cabrera
  6. *
  7. * License: www.highcharts.com/license
  8. */
  9. 'use strict';
  10. (function (factory) {
  11. if (typeof module === 'object' && module.exports) {
  12. factory['default'] = factory;
  13. module.exports = factory;
  14. } else if (typeof define === 'function' && define.amd) {
  15. define(function () {
  16. return factory;
  17. });
  18. } else {
  19. factory(typeof Highcharts !== 'undefined' ? Highcharts : undefined);
  20. }
  21. }(function (Highcharts) {
  22. (function (H) {
  23. /* *
  24. *
  25. * (c) 2016-2019 Highsoft AS
  26. *
  27. * Author: Lars A. V. Cabrera
  28. *
  29. * License: www.highcharts.com/license
  30. *
  31. * */
  32. var addEvent = H.addEvent,
  33. Axis = H.Axis,
  34. PlotLineOrBand = H.PlotLineOrBand,
  35. merge = H.merge;
  36. var defaultConfig = {
  37. /**
  38. * Show an indicator on the axis for the current date and time. Can be a
  39. * boolean or a configuration object similar to
  40. * [xAxis.plotLines](#xAxis.plotLines).
  41. *
  42. * @sample gantt/current-date-indicator/demo
  43. * Current date indicator enabled
  44. * @sample gantt/current-date-indicator/object-config
  45. * Current date indicator with custom options
  46. *
  47. * @type {boolean|*}
  48. * @default true
  49. * @extends xAxis.plotLines
  50. * @excluding value
  51. * @product gantt
  52. * @apioption xAxis.currentDateIndicator
  53. */
  54. currentDateIndicator: true,
  55. color: '#ccd6eb',
  56. width: 2,
  57. label: {
  58. format: '%a, %b %d %Y, %H:%M',
  59. formatter: undefined,
  60. rotation: 0,
  61. style: {
  62. fontSize: '10px'
  63. }
  64. }
  65. };
  66. addEvent(Axis, 'afterSetOptions', function () {
  67. var options = this.options,
  68. cdiOptions = options.currentDateIndicator;
  69. if (cdiOptions) {
  70. if (typeof cdiOptions === 'object') {
  71. // Ignore formatter if custom format is defined
  72. if (cdiOptions.label && cdiOptions.label.format) {
  73. cdiOptions.label.formatter = undefined;
  74. }
  75. cdiOptions = merge(defaultConfig, cdiOptions);
  76. } else {
  77. cdiOptions = merge(defaultConfig);
  78. }
  79. cdiOptions.value = new Date();
  80. if (!options.plotLines) {
  81. options.plotLines = [];
  82. }
  83. options.plotLines.push(cdiOptions);
  84. }
  85. });
  86. addEvent(PlotLineOrBand, 'render', function () {
  87. var options = this.options,
  88. format,
  89. formatter;
  90. if (options.currentDateIndicator && options.label) {
  91. format = options.label.format;
  92. formatter = options.label.formatter;
  93. options.value = new Date();
  94. if (typeof formatter === 'function') {
  95. options.label.text = formatter(this);
  96. } else {
  97. options.label.text = H.dateFormat(format, new Date());
  98. }
  99. // If the label already exists, update its text
  100. if (this.label) {
  101. this.label.attr({
  102. text: options.label.text
  103. });
  104. }
  105. }
  106. });
  107. }(Highcharts));
  108. return (function () {
  109. }());
  110. }));