c946e5110491784d47cd5af0dcddcee1eb6ad3021a07892d2815fca30de631a042fb87d827e8a7fef587536477bace02265eda530ef3eb16c7037a08e9eb2c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. import BoundingRect, { RectLike } from 'zrender/lib/core/BoundingRect.js';
  2. import CalendarModel from './CalendarModel.js';
  3. import GlobalModel from '../../model/Global.js';
  4. import ExtensionAPI from '../../core/ExtensionAPI.js';
  5. import { LayoutOrient, ScaleDataValue, OptionDataValueDate } from '../../util/types.js';
  6. import { ParsedModelFinder } from '../../util/model.js';
  7. import { CoordinateSystem, CoordinateSystemMaster } from '../CoordinateSystem.js';
  8. export interface CalendarParsedDateRangeInfo {
  9. range: [string, string];
  10. start: CalendarParsedDateInfo;
  11. end: CalendarParsedDateInfo;
  12. allDay: number;
  13. weeks: number;
  14. nthWeek: number;
  15. fweek: number;
  16. lweek: number;
  17. }
  18. export interface CalendarParsedDateInfo {
  19. /**
  20. * local full year, eg., '1940'
  21. */
  22. y: string;
  23. /**
  24. * local month, from '01' ot '12',
  25. */
  26. m: string;
  27. /**
  28. * local date, from '01' to '31' (if exists),
  29. */
  30. d: string;
  31. /**
  32. * It is not date.getDay(). It is the location of the cell in a week, from 0 to 6,
  33. */
  34. day: number;
  35. /**
  36. * Timestamp
  37. */
  38. time: number;
  39. /**
  40. * yyyy-MM-dd
  41. */
  42. formatedDate: string;
  43. /**
  44. * The original date object
  45. */
  46. date: Date;
  47. }
  48. export interface CalendarCellRect {
  49. contentShape: RectLike;
  50. center: number[];
  51. tl: number[];
  52. tr: number[];
  53. br: number[];
  54. bl: number[];
  55. }
  56. declare class Calendar implements CoordinateSystem, CoordinateSystemMaster {
  57. static readonly dimensions: string[];
  58. static getDimensionsInfo(): (string | {
  59. name: string;
  60. type: "time";
  61. })[];
  62. readonly type = "calendar";
  63. readonly dimensions: string[];
  64. private _model;
  65. private _rect;
  66. private _sw;
  67. private _sh;
  68. private _orient;
  69. private _firstDayOfWeek;
  70. private _rangeInfo;
  71. private _lineWidth;
  72. constructor(calendarModel: CalendarModel, ecModel: GlobalModel, api: ExtensionAPI);
  73. getDimensionsInfo: typeof Calendar.getDimensionsInfo;
  74. getRangeInfo(): CalendarParsedDateRangeInfo;
  75. getModel(): CalendarModel;
  76. getRect(): BoundingRect;
  77. getCellWidth(): number;
  78. getCellHeight(): number;
  79. getOrient(): LayoutOrient;
  80. /**
  81. * getFirstDayOfWeek
  82. *
  83. * @example
  84. * 0 : start at Sunday
  85. * 1 : start at Monday
  86. *
  87. * @return {number}
  88. */
  89. getFirstDayOfWeek(): number;
  90. /**
  91. * get date info
  92. * }
  93. */
  94. getDateInfo(date: OptionDataValueDate): CalendarParsedDateInfo;
  95. getNextNDay(date: OptionDataValueDate, n: number): CalendarParsedDateInfo;
  96. update(ecModel: GlobalModel, api: ExtensionAPI): void;
  97. /**
  98. * Convert a time data(time, value) item to (x, y) point.
  99. */
  100. dataToPoint(data: OptionDataValueDate | OptionDataValueDate[], clamp?: boolean): number[];
  101. /**
  102. * Convert a (x, y) point to time data
  103. */
  104. pointToData(point: number[]): number;
  105. /**
  106. * Convert a time date item to (x, y) four point.
  107. */
  108. dataToRect(data: OptionDataValueDate | OptionDataValueDate[], clamp?: boolean): CalendarCellRect;
  109. /**
  110. * Convert a (x, y) point to time date
  111. *
  112. * @param {Array} point point
  113. * @return {Object} date
  114. */
  115. pointToDate(point: number[]): CalendarParsedDateInfo;
  116. convertToPixel(ecModel: GlobalModel, finder: ParsedModelFinder, value: ScaleDataValue | ScaleDataValue[]): number[];
  117. convertFromPixel(ecModel: GlobalModel, finder: ParsedModelFinder, pixel: number[]): number;
  118. containPoint(point: number[]): boolean;
  119. /**
  120. * initRange
  121. * Normalize to an [start, end] array
  122. */
  123. private _initRangeOption;
  124. /**
  125. * range info
  126. *
  127. * @private
  128. * @param {Array} range range ['2017-01-01', '2017-07-08']
  129. * If range[0] > range[1], they will not be reversed.
  130. * @return {Object} obj
  131. */
  132. _getRangeInfo(range: OptionDataValueDate[]): CalendarParsedDateRangeInfo;
  133. /**
  134. * get date by nthWeeks and week day in range
  135. *
  136. * @private
  137. * @param {number} nthWeek the week
  138. * @param {number} day the week day
  139. * @param {Array} range [d1, d2]
  140. * @return {Object}
  141. */
  142. private _getDateByWeeksAndDay;
  143. static create(ecModel: GlobalModel, api: ExtensionAPI): Calendar[];
  144. }
  145. export default Calendar;