selection.d.ts 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import type { IDocument } from '@antv/g';
  2. import type { AnimationResult } from '../animation';
  3. import type { DisplayObject, IAnimation } from '../shapes';
  4. import { Group } from '../shapes';
  5. export type _Element = DisplayObject & {
  6. __data__?: any;
  7. __toData__?: any[];
  8. __fromElements__?: DisplayObject[];
  9. __facet__?: boolean;
  10. };
  11. /**
  12. * A simple implementation of d3-selection for @antv/g.
  13. * It has the core features of d3-selection and extended ability.
  14. * Every methods of selection returns new selection if elements
  15. * are mutated(e.g. append, remove), otherwise return the selection itself(e.g. attr, style).
  16. * @see https://github.com/d3/d3-selection
  17. * @see https://github.com/antvis/g
  18. * @todo Nested selections.
  19. * @todo More useful functor.
  20. */
  21. export declare class Selection<T = any> {
  22. #private;
  23. static registry: Record<string, new () => _Element>;
  24. private _elements;
  25. private _parent;
  26. private _data;
  27. private _enter;
  28. private _exit;
  29. private _update;
  30. private _merge;
  31. private _split;
  32. private _document;
  33. private _transitions;
  34. private _facetElements;
  35. constructor(elements?: Iterable<_Element>, data?: T[] | [T, _Element[]][], parent?: _Element, document?: IDocument | null, selections?: [Selection, Selection, Selection, Selection, Selection], transitions?: Promise<void>[], updateElements?: _Element[]);
  36. selectAll(selector: string | _Element[]): Selection<T>;
  37. selectFacetAll(selector: string | _Element[]): Selection<T>;
  38. /**
  39. * @todo Replace with querySelector which has bug now.
  40. */
  41. select(selector: string | _Element): Selection<T>;
  42. append(node: string | ((data: T, i: number) => _Element)): Selection<T>;
  43. maybeAppend<T = DisplayObject>(id: string, node: string | (() => _Element)): Selection<T>;
  44. maybeAppendByClassName<T = DisplayObject>(className: any, node: string | (() => _Element)): Selection<T>;
  45. maybeAppendByName<T = DisplayObject>(name: string, node: string | (() => _Element)): Selection<T>;
  46. /**
  47. * Bind data to elements, and produce three selection:
  48. * Enter: Selection with empty elements and data to be bind to elements.
  49. * Update: Selection with elements to be updated.
  50. * Exit: Selection with elements to be removed.
  51. */
  52. data<T = any>(data: T[], id?: (d: T, index?: number) => any, groupId?: (d: T, index?: number) => any): Selection<T>;
  53. merge(other: Selection<T>): Selection<T>;
  54. createElement(type: string): _Element;
  55. /**
  56. * Apply callback for each selection(enter, update, exit)
  57. * and merge them into one selection.
  58. */
  59. join(enter?: (selection: Selection<T>) => any, update?: (selection: Selection<T>) => any, exit?: (selection: Selection<T>) => any, merge?: (selection: Selection<T>) => any, split?: (selection: Selection<T>) => any): Selection<T>;
  60. remove(): Selection<T>;
  61. each(callback: (datum: T, index: number) => any): Selection<T>;
  62. attr(key: string, value: any): Selection<T>;
  63. style(key: string, value: any, callbackable?: boolean): Selection<T>;
  64. styles(style?: Record<string, any>, callbackable?: boolean): Selection<T>;
  65. update(option: any, callbackable?: boolean): Selection<T>;
  66. /** if current stage is maybeAppend, skip update stage */
  67. maybeUpdate(option: any, callbackable?: boolean): Selection<T>;
  68. transition(callback?: (datum: T, index: number) => (null | IAnimation) | (null | IAnimation)[]): Selection<T>;
  69. on(event: string, handler: any): this;
  70. call(callback: (selection: Selection<T>, ...args: any[]) => any, ...args: any[]): Selection<T>;
  71. node<T extends _Element = _Element>(): T;
  72. nodes(): _Element[];
  73. transitions(): AnimationResult[];
  74. parent(): DisplayObject;
  75. }
  76. export declare function select<T = any>(node: DisplayObject): Selection<T>;
  77. export declare function maybeAppend<T>(parent: Group, selector: string, node: string | ((data: T, i: number) => _Element)): Selection<T>;