UNPKG

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