layout.d.ts 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import { Datum } from '../../types';
  2. import { center, justify, left, right } from './sankey';
  3. declare const ALIGN_METHOD: {
  4. left: typeof left;
  5. right: typeof right;
  6. center: typeof center;
  7. justify: typeof justify;
  8. };
  9. type InputNode = {
  10. readonly name: string;
  11. };
  12. type InputLink = {
  13. readonly source: number;
  14. readonly target: number;
  15. readonly value: number;
  16. };
  17. type OutputNode = {
  18. readonly name: string;
  19. readonly x0: number;
  20. readonly x1: number;
  21. readonly y0: number;
  22. readonly y1: number;
  23. readonly depth: number;
  24. readonly value: number;
  25. x: number[];
  26. y: number[];
  27. };
  28. type OutputLink = {
  29. readonly source: OutputNode;
  30. readonly target: OutputNode;
  31. readonly value: number;
  32. readonly width: number;
  33. readonly y0: number;
  34. readonly y1: number;
  35. x?: number[];
  36. y?: number[];
  37. };
  38. /**
  39. * 桑基图布局的数据结构定义
  40. */
  41. export type SankeyLayoutInputData = {
  42. readonly nodes: InputNode[];
  43. readonly links: InputLink[];
  44. };
  45. type SankeyLayoutOutputData = {
  46. readonly nodes: OutputNode[];
  47. readonly links: OutputLink[];
  48. };
  49. /**
  50. * 对齐方式的类型定义
  51. */
  52. export type NodeAlign = keyof typeof ALIGN_METHOD | ((...args: any[]) => any);
  53. /**
  54. * 节点的 depth 自定义
  55. */
  56. export type NodeDepth = (datum: Datum, maxDepth: number) => number;
  57. /**
  58. * 节点排序方法的类型定义
  59. */
  60. export type NodeSort = (a: Datum, b: Datum) => number;
  61. /**
  62. * 布局参数的定义
  63. */
  64. export type SankeyLayoutOptions = {
  65. readonly nodeId?: (node: Datum) => any;
  66. readonly nodeSort?: (a: any, b: any) => number;
  67. readonly nodeAlign?: NodeAlign;
  68. readonly nodeWidth?: number;
  69. readonly nodePadding?: number;
  70. readonly nodeDepth?: NodeDepth;
  71. };
  72. /**
  73. * 获得 align function
  74. * @param nodeAlign
  75. * @param nodeDepth
  76. */
  77. export declare function getNodeAlignFunction(nodeAlign: NodeAlign): (...args: any[]) => any;
  78. export declare function getDefaultOptions(sankeyLayoutOptions: SankeyLayoutOptions): Partial<SankeyLayoutOptions> & SankeyLayoutOptions;
  79. /**
  80. * 桑基图利用数据进行布局的函数,最终返回节点、边的位置(0 - 1 的信息)
  81. * 将会修改 data 数据
  82. * @param sankeyLayoutOptions
  83. * @param data
  84. */
  85. export declare function sankeyLayout(sankeyLayoutOptions: SankeyLayoutOptions, data: SankeyLayoutInputData): SankeyLayoutOutputData;
  86. export {};