dataTransform.d.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. import { DataComponent } from '../runtime';
  2. export type DataTransform = SortByTransform | SortTransform | PickTransform | RenameTransform | FoldTransform | JoinTransform | FilterDataTransform | MapTransform | SliceTransform | KDEDataTransform | VennDataTransform | CustomTransform;
  3. export type DataTransformTypes = 'sortBy' | 'sort' | 'pick' | 'rename' | 'fold' | 'join' | 'filter' | 'map' | 'slice' | 'kde' | 'venn' | 'custom' | DataComponent;
  4. export type SortByTransform = {
  5. type?: 'sortBy';
  6. /** type: [field, order]; order: true => ascend, false => descend */
  7. fields?: (string | [string, boolean?])[];
  8. };
  9. export type PickTransform = {
  10. type?: 'pick';
  11. fields?: string[];
  12. };
  13. export type RenameTransform = {
  14. type?: 'rename';
  15. [key: string]: string;
  16. };
  17. export type FilterDataTransform = {
  18. type?: 'filter';
  19. /**
  20. * The filter condition, same with [Array.prototype.filter](https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array/filter).
  21. */
  22. callback?: (v: any, idx: number, arr: any[]) => boolean;
  23. };
  24. export type SliceTransform = {
  25. type?: 'slice';
  26. /**
  27. * The start index for slice. Default is 0.
  28. */
  29. start?: number;
  30. /**
  31. * The end index for slice. Default is arr.length - 1
  32. */
  33. end?: number;
  34. };
  35. export type SortTransform = {
  36. type?: 'sort';
  37. /**
  38. * The sort comparator, same with [Array.prototype.sort](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort).
  39. */
  40. callback?: (a: any, b: any) => number;
  41. };
  42. export type FoldTransform = {
  43. type?: 'fold';
  44. /**
  45. * Set fields will be folded.
  46. */
  47. fields?: string[];
  48. /**
  49. * Fold key field, default is `key`.
  50. */
  51. key?: string;
  52. /**
  53. * Fold value field, default is `value`.
  54. */
  55. value?: string;
  56. };
  57. export type JoinTransform = {
  58. type?: 'join';
  59. /**
  60. * The dataset to be joined.
  61. */
  62. join: Record<string, any>[];
  63. /**
  64. * Join keys of 2 dataset, [k1, k2] means join on ds1.k1 === ds2.k2.
  65. */
  66. on: [string | ((d: any) => string), string | ((d: any) => string)];
  67. /**
  68. * Select fields from joined dataset.
  69. */
  70. select: string[];
  71. /**
  72. * Rename the select fields, default: keep the original name.
  73. */
  74. as?: string[];
  75. /**
  76. * When not matched, use `unknown` instead.
  77. */
  78. unknown?: any;
  79. };
  80. export type MapTransform = {
  81. type?: 'map';
  82. callback?: (d: any) => any;
  83. };
  84. export type CustomDataTransform = {
  85. type?: 'custom';
  86. callback?: (d: any) => any;
  87. };
  88. export type KDEDataTransform = {
  89. type?: 'kde';
  90. /**
  91. * Kernel Density Estimation field.
  92. */
  93. field: string;
  94. /**
  95. * Group data by fields.
  96. */
  97. groupBy: string[];
  98. /**
  99. * Generate new fieds, default: ['y', 'size']
  100. */
  101. as?: ['y', 'size'];
  102. /**
  103. * Defaults to smallest value in the array minus some threshold.
  104. */
  105. min?: number;
  106. /**
  107. * Defaults to largest value in the array plus some threshold.
  108. */
  109. max?: number;
  110. /**
  111. * Number of points to represent the pdf. Defaults to 10.
  112. */
  113. size?: number;
  114. /**
  115. * Determine how many points to the left and right does an element affect,
  116. * similar to bandwidth in kernel density estimation. Defaults to 2.
  117. */
  118. width?: number;
  119. };
  120. export type VennDataTransform = {
  121. type?: 'venn';
  122. /**
  123. * Canvas padding for 4 direction.
  124. * Default is `0`.
  125. */
  126. padding?: number;
  127. /**
  128. * Set the sets field.
  129. * Default is `sets`.
  130. */
  131. sets?: string;
  132. /**
  133. * Set the size field for each set.
  134. * Default is `size`.
  135. */
  136. size?: string;
  137. /**
  138. * Set the generated fields, includes: [key, x, y, path]
  139. */
  140. as?: [string, string];
  141. };
  142. export type CustomTransform = {
  143. type?: DataComponent;
  144. [key: string]: any;
  145. };