node.d.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { Chart } from './chart';
  2. /**
  3. * Hierarchy container.
  4. */
  5. export declare class Node<Value extends Record<string, any> = Record<string, any>, ParentValue extends Record<string, any> = Record<string, any>, ChildValue extends Record<string, any> = Record<string, any>> {
  6. parentNode: Node<ParentValue, Record<string, any>, Value>;
  7. children: Node<ChildValue, Value, Record<string, any>>[];
  8. index: number;
  9. value: Partial<Value>;
  10. type: string;
  11. constructor(value?: Partial<Value>, type?: string);
  12. /**
  13. * Apply specified transform to current value. Mount the node
  14. * to replace the original one in the tree and then return it.
  15. */
  16. map(transform?: (x: Value) => Value): this;
  17. /**
  18. * Set or get the specified attribute. It the value is specified, update
  19. * the attribute of current value and return the node. Otherwise
  20. * return the the attribute of current value.
  21. */
  22. attr<T extends Value[keyof Value]>(key: keyof Value, value?: T): T extends undefined ? T : this;
  23. /**
  24. * Create a new node and append to children nodes.
  25. */
  26. append(Ctor: new (value: Record<string, any>) => Node<ChildValue, Value>): Node<ChildValue, Value>;
  27. push(node: Node<ChildValue, Value>): this;
  28. /**
  29. * Remove current node from parentNode.
  30. */
  31. remove(): Node;
  32. getNodeByKey(key: string): Node;
  33. getNodesByType(type: string): Node[];
  34. getNodeByType(type: string): Node;
  35. /**
  36. * Apply specified callback to the node value.
  37. */
  38. call(callback: (node: this, ...params: any[]) => any, ...params: any[]): this;
  39. getRoot(): Chart;
  40. }