playAxis.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. "use strict";
  2. // import { CustomElement, CustomEvent } from '../../shapes';
  3. // import { deepMix, isNil } from '@antv/util';
  4. // import { DEFAULT_TIMELINE_STYLE } from './constants';
  5. // import { PlayAxisStyleProps, TimeData } from './types';
  6. // export type AxisStyleProps = PlayAxisStyleProps & {
  7. // x?: number;
  8. // y?: number;
  9. // data: TimeData[];
  10. // length?: number;
  11. // orientation?: string;
  12. // singleMode?: boolean;
  13. // playInterval?: number; // ms
  14. // tag?: string;
  15. // };
  16. // export const DEFAULT_STYLE: AxisStyleProps = deepMix(
  17. // {},
  18. // {
  19. // x: 0,
  20. // y: 0,
  21. // data: [],
  22. // length: 120,
  23. // orientation: 'horizontal',
  24. // selection: 0,
  25. // selectionStyle: {
  26. // fill: '#5B8FF9',
  27. // fillOpacity: 0.15,
  28. // },
  29. // loop: false,
  30. // playInterval: 1000,
  31. // },
  32. // DEFAULT_TIMELINE_STYLE.playAxis
  33. // );
  34. // export const DEFAULT_AXIS_CFG = {
  35. // // axisLine: null,
  36. // // label: {
  37. // // autoRotate: false,
  38. // // rotate: 0,
  39. // // autoHide: true,
  40. // // autoHideTickLine: false,
  41. // // autoEllipsis: true,
  42. // // minLength: 50,
  43. // // alignTick: true,
  44. // // },
  45. // };
  46. // export function normalSelection(selection: number | number[] = [], singleMode?: boolean): [number, number] {
  47. // const [s1 = 0, s2 = s1] = Array.of(selection).flat() as number[];
  48. // return singleMode ? [s1, s1] : [s1, s2];
  49. // }
  50. // export abstract class AxisBase<T extends AxisStyleProps = AxisStyleProps> extends CustomElement<T> {
  51. // protected playTimer?: any;
  52. // protected selection: [number, number] = [0, 0];
  53. // public update(cfg: Partial<AxisStyleProps> = {}) {
  54. // const newAttrs = deepMix({}, this.attributes, cfg);
  55. // if (cfg.selection) {
  56. // this.selection = normalSelection(cfg.selection, newAttrs.singleMode);
  57. // }
  58. // if (cfg.singleMode) {
  59. // this.selection = normalSelection(newAttrs.selection, cfg.singleMode);
  60. // }
  61. // const playing = this.playTimer;
  62. // playing && this.stop();
  63. // this.attr(newAttrs);
  64. // this.render();
  65. // playing && this.play();
  66. // }
  67. // public play() {
  68. // const { data: timeData, loop, singleMode, playMode } = this.style;
  69. // const maxLength = timeData.length;
  70. // let { playInterval } = this.style;
  71. // if (isNil(playInterval)) {
  72. // playInterval = DEFAULT_STYLE.playInterval;
  73. // }
  74. // if (this.playTimer) clearInterval(this.playTimer);
  75. // this.playTimer = setInterval(() => {
  76. // if (!loop && this.selection[1] >= maxLength - 1) {
  77. // this.stop(true);
  78. // return;
  79. // }
  80. // if (singleMode) {
  81. // // do something
  82. // const currentIndex = (this.selection[0] + 1) % maxLength;
  83. // this.setSelection({ start: currentIndex, end: currentIndex });
  84. // return;
  85. // }
  86. // let startIndex = this.selection[0];
  87. // let endIndex = this.selection[1];
  88. // const offset = this.selection[1] - this.selection[0];
  89. // if (endIndex >= maxLength - 1) {
  90. // if (playMode === 'increase') {
  91. // endIndex = startIndex;
  92. // } else {
  93. // startIndex = 0;
  94. // endIndex = offset;
  95. // }
  96. // } else {
  97. // if (playMode !== 'increase') {
  98. // startIndex = (startIndex + 1) % maxLength;
  99. // }
  100. // endIndex = (endIndex + 1) % maxLength;
  101. // }
  102. // this.setSelection({ start: startIndex, end: endIndex });
  103. // }, playInterval);
  104. // }
  105. // public stop(dispatchEvent?: boolean): void {
  106. // clearInterval(this.playTimer);
  107. // this.playTimer = undefined;
  108. // if (dispatchEvent) {
  109. // this.dispatchEvent(new CustomEvent('timelineStopped', { selection: this.selection }));
  110. // }
  111. // }
  112. // public prev() {
  113. // const [s1, s2] = this.selection;
  114. // const max = this.style.data.length;
  115. // let start;
  116. // let end;
  117. // if (max && this.style.singleMode) {
  118. // start = (s1 - 1 + max) % max;
  119. // end = (s1 - 1 + max) % max;
  120. // } else if (s1 === 0) {
  121. // start = max - (s2 - s1) - 1;
  122. // end = max - 1;
  123. // } else {
  124. // start = s1 - 1;
  125. // end = s2 - 1;
  126. // }
  127. // this.setSelection({ start: start ?? this.selection[0], end: end ?? this.selection[1] });
  128. // }
  129. // public next() {
  130. // const [s1, s2] = this.selection;
  131. // const max = this.style.data.length;
  132. // let start;
  133. // let end;
  134. // if (max && this.style.singleMode) {
  135. // start = (s1 + 1) % max;
  136. // end = (s1 + 1) % max;
  137. // } else if (s2 === max - 1) {
  138. // start = 0;
  139. // end = s2 - s1;
  140. // } else {
  141. // start = s1 + 1;
  142. // end = s2 + 1;
  143. // }
  144. // this.setSelection({ start: start ?? this.selection[0], end: end ?? this.selection[1] });
  145. // }
  146. // public getSelection(): [number, number] {
  147. // return this.selection;
  148. // }
  149. // protected abstract render(): void;
  150. // protected abstract setSelection(newSelection: { start?: number; end?: number }): void;
  151. // protected get orientation() {
  152. // return this.style.orientation || 'horizontal';
  153. // }
  154. // protected ifH<T>(a: T, b: T) {
  155. // if (this.orientation === 'horizontal') {
  156. // return typeof a === 'function' ? a() : a;
  157. // }
  158. // return typeof b === 'function' ? b() : b;
  159. // }
  160. // public destroy() {
  161. // super.destroy();
  162. // if (this.playTimer) clearInterval(this.playTimer);
  163. // this.playTimer = undefined;
  164. // }
  165. // }
  166. //# sourceMappingURL=playAxis.js.map