group-component.d.ts 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /**
  2. * @fileoverview 使用 G.Group 的组件
  3. * @author dxq613@gmail.com
  4. */
  5. import { IElement, IGroup, IShape } from '@antv/g-base';
  6. import { BBox, GroupComponentCfg, LooseObject, Point } from '../types';
  7. import Component from './component';
  8. declare type Callback = (evt: object) => void;
  9. export declare type GroupComponentCtor<C extends GroupComponentCfg = GroupComponentCfg, T extends GroupComponent = GroupComponent> = new (cfg: C) => T;
  10. declare abstract class GroupComponent<T extends GroupComponentCfg = GroupComponentCfg> extends Component<T> {
  11. getDefaultCfg(): {
  12. container: any;
  13. /**
  14. * @private
  15. * 缓存图形的 Map
  16. */
  17. shapesMap: {};
  18. group: any;
  19. capture: boolean;
  20. /**
  21. * @private 组件或者图形是否允许注册
  22. * @type {false}
  23. */
  24. isRegister: boolean;
  25. /**
  26. * @private 是否正在更新
  27. * @type {false}
  28. */
  29. isUpdating: boolean;
  30. /**
  31. * @private
  32. * 是否初始状态,一旦 render,update 后,这个状态就变成 false, clear 后恢复
  33. */
  34. isInit: boolean;
  35. id: string;
  36. name: string;
  37. type: string;
  38. locationType: string;
  39. offsetX: number;
  40. offsetY: number;
  41. animate: boolean;
  42. updateAutoRender: boolean;
  43. animateOption: {
  44. appear: any;
  45. update: {
  46. duration: number;
  47. easing: string;
  48. };
  49. enter: {
  50. duration: number;
  51. easing: string;
  52. };
  53. leave: {
  54. duration: number;
  55. easing: string;
  56. };
  57. };
  58. events: any;
  59. defaultCfg: {}; /**
  60. * @private 组件或者图形是否允许注册
  61. * @type {false}
  62. */
  63. visible: boolean;
  64. };
  65. remove(): void;
  66. clear(): void;
  67. getChildComponentById(id: string): any;
  68. getElementById(id: string): any;
  69. getElementByLocalId(localId: any): any;
  70. getElementsByName(name: string): any[];
  71. getContainer(): IGroup;
  72. updateInner(cfg: Partial<T>): void;
  73. render(): void;
  74. show(): void;
  75. hide(): void;
  76. setCapture(capture: any): void;
  77. destroy(): void;
  78. getBBox(): BBox;
  79. getLayoutBBox(): BBox;
  80. on(evt: string, callback: Callback, once?: boolean): this;
  81. off(evt?: string, callback?: Callback): this;
  82. emit(eventName: string, eventObject: LooseObject): void;
  83. init(): void;
  84. protected getInnerLayoutBBox(): any;
  85. protected delegateEmit(eventName: string, eventObject: LooseObject): void;
  86. protected createOffScreenGroup(): any;
  87. protected applyOffset(): void;
  88. protected initGroup(): void;
  89. protected offScreenRender(): any;
  90. /**
  91. * @protected
  92. * 在组件上添加分组,主要解决 isReigeter 的问题
  93. * @param {IGroup} parent 父元素
  94. * @param {object} cfg 分组的配置项
  95. */
  96. protected addGroup(parent: IGroup, cfg: any): IGroup;
  97. /**
  98. * @protected
  99. * 在组件上添加图形,主要解决 isReigeter 的问题
  100. * @param {IGroup} parent 父元素
  101. * @param {object} cfg 分组的配置项
  102. */
  103. protected addShape(parent: IGroup, cfg: any): IShape;
  104. /**
  105. * 在组件上添加子组件
  106. *
  107. * @param parent 父元素
  108. * @param cfg 子组件配置项
  109. */
  110. protected addComponent<C extends GroupComponentCfg = GroupComponentCfg, CT extends GroupComponent = GroupComponent>(parent: IGroup, cfg: Omit<C, 'container'> & {
  111. component: GroupComponentCtor<C, CT>;
  112. }): CT;
  113. protected initEvent(): void;
  114. protected removeEvent(): void;
  115. protected getElementId(localId: string): string;
  116. protected registerElement(element: any): void;
  117. protected unregisterElement(element: any): void;
  118. protected moveElementTo(element: IElement, point: Point): void;
  119. /**
  120. * 内部的渲染
  121. * @param {IGroup} group 图形分组
  122. */
  123. protected abstract renderInner(group: IGroup): any;
  124. /**
  125. * 图形元素新出现时的动画,默认图形从透明度 0 到当前透明度
  126. * @protected
  127. * @param {string} elmentName 图形元素名称
  128. * @param {IElement} newElement 新的图形元素
  129. * @param {object} animateCfg 动画的配置项
  130. */
  131. protected addAnimation(elmentName: any, newElement: any, animateCfg: any): void;
  132. /**
  133. * 图形元素新出现时的动画,默认图形从透明度 0 到当前透明度
  134. * @protected
  135. * @param {string} elmentName 图形元素名称
  136. * @param {IElement} originElement 要删除的图形元素
  137. * @param {object} animateCfg 动画的配置项
  138. */
  139. protected removeAnimation(elementName: any, originElement: any, animateCfg: any): void;
  140. /**
  141. * 图形元素的更新动画
  142. * @param {string} elmentName 图形元素名称
  143. * @param {IElement} originElement 现有的图形元素
  144. * @param {object} newAttrs 新的图形元素
  145. * @param {object} animateCfg 动画的配置项
  146. */
  147. protected updateAnimation(elementName: any, originElement: any, newAttrs: any, animateCfg: any): void;
  148. protected updateElements(newGroup: any, originGroup: any): void;
  149. protected clearUpdateStatus(group: IGroup): void;
  150. private clearOffScreenCache;
  151. private getDelegateObject;
  152. private appendDelegateObject;
  153. private getReplaceAttrs;
  154. private registerNewGroup;
  155. private deleteElements;
  156. private removeElement;
  157. }
  158. export default GroupComponent;