@antv/g2plot 2.4.14 → 2.4.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/dist/g2plot.min.js +3 -17
  2. package/dist/g2plot.min.js.map +1 -1
  3. package/esm/adaptor/common.d.ts +10 -0
  4. package/esm/adaptor/common.js +25 -0
  5. package/esm/adaptor/common.js.map +1 -1
  6. package/esm/adaptor/geometries/area.js +2 -1
  7. package/esm/adaptor/geometries/area.js.map +1 -1
  8. package/esm/adaptor/geometries/edge.js +2 -1
  9. package/esm/adaptor/geometries/edge.js.map +1 -1
  10. package/esm/adaptor/geometries/interval.js +9 -2
  11. package/esm/adaptor/geometries/interval.js.map +1 -1
  12. package/esm/adaptor/geometries/line.js +2 -2
  13. package/esm/adaptor/geometries/line.js.map +1 -1
  14. package/esm/adaptor/geometries/point.js +2 -1
  15. package/esm/adaptor/geometries/point.js.map +1 -1
  16. package/esm/adaptor/geometries/polygon.js +2 -1
  17. package/esm/adaptor/geometries/polygon.js.map +1 -1
  18. package/esm/adaptor/geometries/schema.js +2 -1
  19. package/esm/adaptor/geometries/schema.js.map +1 -1
  20. package/esm/adaptor/pattern.d.ts +1 -1
  21. package/esm/index.d.ts +1 -1
  22. package/esm/index.js +1 -1
  23. package/esm/index.js.map +1 -1
  24. package/esm/plots/area/adaptor.js +4 -4
  25. package/esm/plots/area/adaptor.js.map +1 -1
  26. package/esm/plots/area/index.js +2 -2
  27. package/esm/plots/area/index.js.map +1 -1
  28. package/esm/plots/area/types.d.ts +6 -0
  29. package/esm/plots/area/types.js.map +1 -1
  30. package/esm/plots/bar/adaptor.js +3 -3
  31. package/esm/plots/bar/adaptor.js.map +1 -1
  32. package/esm/plots/bar/index.js +2 -2
  33. package/esm/plots/bar/index.js.map +1 -1
  34. package/esm/plots/column/adaptor.js +4 -4
  35. package/esm/plots/column/adaptor.js.map +1 -1
  36. package/esm/plots/column/index.js +2 -2
  37. package/esm/plots/column/index.js.map +1 -1
  38. package/esm/plots/column/types.d.ts +6 -0
  39. package/esm/plots/column/types.js.map +1 -1
  40. package/esm/plots/mix/utils.d.ts +18 -17
  41. package/esm/plots/mix/utils.js.map +1 -1
  42. package/esm/plots/pie/adaptor.js +1 -1
  43. package/esm/plots/pie/adaptor.js.map +1 -1
  44. package/esm/plots/sankey/layout.js +14 -3
  45. package/esm/plots/sankey/layout.js.map +1 -1
  46. package/esm/types/common.d.ts +6 -0
  47. package/esm/types/common.js.map +1 -1
  48. package/esm/types/coordinate.d.ts +13 -0
  49. package/esm/types/coordinate.js +1 -0
  50. package/esm/types/coordinate.js.map +1 -0
  51. package/esm/utils/transform/percent.d.ts +1 -1
  52. package/esm/utils/transform/percent.js +1 -1
  53. package/esm/utils/transform/percent.js.map +1 -1
  54. package/lib/adaptor/common.d.ts +10 -0
  55. package/lib/adaptor/common.js +27 -1
  56. package/lib/adaptor/common.js.map +1 -1
  57. package/lib/adaptor/geometries/area.js +2 -1
  58. package/lib/adaptor/geometries/area.js.map +1 -1
  59. package/lib/adaptor/geometries/edge.js +2 -1
  60. package/lib/adaptor/geometries/edge.js.map +1 -1
  61. package/lib/adaptor/geometries/interval.js +9 -2
  62. package/lib/adaptor/geometries/interval.js.map +1 -1
  63. package/lib/adaptor/geometries/line.js +2 -2
  64. package/lib/adaptor/geometries/line.js.map +1 -1
  65. package/lib/adaptor/geometries/point.js +2 -1
  66. package/lib/adaptor/geometries/point.js.map +1 -1
  67. package/lib/adaptor/geometries/polygon.js +2 -1
  68. package/lib/adaptor/geometries/polygon.js.map +1 -1
  69. package/lib/adaptor/geometries/schema.js +2 -1
  70. package/lib/adaptor/geometries/schema.js.map +1 -1
  71. package/lib/adaptor/pattern.d.ts +1 -1
  72. package/lib/index.d.ts +1 -1
  73. package/lib/index.js +1 -1
  74. package/lib/index.js.map +1 -1
  75. package/lib/plots/area/adaptor.js +2 -2
  76. package/lib/plots/area/adaptor.js.map +1 -1
  77. package/lib/plots/area/index.js +1 -1
  78. package/lib/plots/area/index.js.map +1 -1
  79. package/lib/plots/area/types.d.ts +6 -0
  80. package/lib/plots/area/types.js.map +1 -1
  81. package/lib/plots/bar/adaptor.js +3 -3
  82. package/lib/plots/bar/adaptor.js.map +1 -1
  83. package/lib/plots/bar/index.js +1 -1
  84. package/lib/plots/bar/index.js.map +1 -1
  85. package/lib/plots/column/adaptor.js +2 -2
  86. package/lib/plots/column/adaptor.js.map +1 -1
  87. package/lib/plots/column/index.js +1 -1
  88. package/lib/plots/column/index.js.map +1 -1
  89. package/lib/plots/column/types.d.ts +6 -0
  90. package/lib/plots/column/types.js.map +1 -1
  91. package/lib/plots/mix/utils.d.ts +18 -17
  92. package/lib/plots/mix/utils.js.map +1 -1
  93. package/lib/plots/pie/adaptor.js +1 -1
  94. package/lib/plots/pie/adaptor.js.map +1 -1
  95. package/lib/plots/sankey/layout.js +14 -3
  96. package/lib/plots/sankey/layout.js.map +1 -1
  97. package/lib/types/common.d.ts +6 -0
  98. package/lib/types/common.js.map +1 -1
  99. package/lib/types/coordinate.d.ts +13 -0
  100. package/lib/types/coordinate.js +3 -0
  101. package/lib/types/coordinate.js.map +1 -0
  102. package/lib/utils/transform/percent.d.ts +1 -1
  103. package/lib/utils/transform/percent.js +3 -3
  104. package/lib/utils/transform/percent.js.map +1 -1
  105. package/package.json +2 -1
  106. package/src/adaptor/common.ts +28 -1
  107. package/src/adaptor/geometries/area.ts +2 -1
  108. package/src/adaptor/geometries/edge.ts +2 -1
  109. package/src/adaptor/geometries/interval.ts +9 -1
  110. package/src/adaptor/geometries/line.ts +2 -2
  111. package/src/adaptor/geometries/point.ts +2 -1
  112. package/src/adaptor/geometries/polygon.ts +2 -1
  113. package/src/adaptor/geometries/schema.ts +2 -1
  114. package/src/index.ts +1 -1
  115. package/src/plots/area/adaptor.ts +14 -3
  116. package/src/plots/area/index.ts +2 -2
  117. package/src/plots/area/types.ts +7 -0
  118. package/src/plots/bar/adaptor.ts +3 -3
  119. package/src/plots/bar/index.ts +2 -2
  120. package/src/plots/column/adaptor.ts +4 -2
  121. package/src/plots/column/index.ts +2 -2
  122. package/src/plots/column/types.ts +7 -0
  123. package/src/plots/mix/utils.ts +18 -17
  124. package/src/plots/pie/adaptor.ts +1 -1
  125. package/src/plots/sankey/layout.ts +34 -21
  126. package/src/types/common.ts +6 -0
  127. package/src/types/coordinate.ts +17 -0
  128. package/src/utils/transform/percent.ts +1 -1
  129. package/CHANGELOG.md +0 -1515
@@ -11,6 +11,7 @@ import {
11
11
  scrollbar,
12
12
  limitInPlot,
13
13
  state,
14
+ transformations,
14
15
  } from '../../adaptor/common';
15
16
  import { conversionTag } from '../../adaptor/conversion-tag';
16
17
  import { connectedArea } from '../../adaptor/connected-area';
@@ -18,7 +19,7 @@ import { interval } from '../../adaptor/geometries';
18
19
  import { pattern } from '../../adaptor/pattern';
19
20
  import { brushInteraction } from '../../adaptor/brush';
20
21
  import { flow, transformLabel, deepAssign, findGeometry, adjustYMetaByZero, pick } from '../../utils';
21
- import { getDataWhetherPecentage, getDeepPercent } from '../../utils/transform/percent';
22
+ import { getDataWhetherPercentage, getDeepPercent } from '../../utils/transform/percent';
22
23
  import { Datum } from '../../types';
23
24
  import { ColumnOptions } from './types';
24
25
 
@@ -73,7 +74,7 @@ function geometry(params: Params<ColumnOptions>): Params<ColumnOptions> {
73
74
  const percentData =
74
75
  isPercent && isGroup && isStack
75
76
  ? getDeepPercent(data, yField, [xField, groupField], yField)
76
- : getDataWhetherPecentage(data, yField, xField, yField, isPercent);
77
+ : getDataWhetherPercentage(data, yField, xField, yField, isPercent);
77
78
 
78
79
  let chartData = [];
79
80
 
@@ -292,6 +293,7 @@ export function adaptor(params: Params<ColumnOptions>, isBar = false) {
292
293
  theme, // theme 需要在 geometry 之前
293
294
  pattern('columnStyle'),
294
295
  state,
296
+ transformations('rect'),
295
297
  geometry,
296
298
  meta,
297
299
  axis,
@@ -1,6 +1,6 @@
1
1
  import { Plot } from '../../core/plot';
2
2
  import { Adaptor } from '../../core/adaptor';
3
- import { getDataWhetherPecentage } from '../../utils/transform/percent';
3
+ import { getDataWhetherPercentage } from '../../utils/transform/percent';
4
4
  import { ColumnOptions } from './types';
5
5
  import { adaptor, meta } from './adaptor';
6
6
  import { DEFAULT_OPTIONS } from './constants';
@@ -30,7 +30,7 @@ export class Column extends Plot<ColumnOptions> {
30
30
  const { yField, xField, isPercent } = this.options;
31
31
  const { chart, options } = this;
32
32
  meta({ chart, options });
33
- this.chart.changeData(getDataWhetherPecentage(data, yField, xField, yField, isPercent));
33
+ this.chart.changeData(getDataWhetherPercentage(data, yField, xField, yField, isPercent));
34
34
  }
35
35
 
36
36
  /**
@@ -3,6 +3,7 @@ import { BrushCfg, Options, StyleAttr } from '../../types';
3
3
  import { OptionWithConversionTag } from '../../adaptor/conversion-tag';
4
4
  import { OptionWithConnectedArea } from '../../adaptor/connected-area';
5
5
  import { IntervalGeometryOptions } from '../../adaptor/geometries/interval';
6
+ import { Transformations } from '../../types/coordinate';
6
7
 
7
8
  type PartialIntervalGeometryOptions = Pick<IntervalGeometryOptions, 'dodgePadding' | 'intervalPadding'>;
8
9
 
@@ -84,4 +85,10 @@ export interface ColumnOptions
84
85
  * @description 开启下钻交互,以及进行下钻交互的配置
85
86
  */
86
87
  readonly brush?: BrushCfg;
88
+
89
+ /**
90
+ * @title 坐标转换
91
+ * @description 可以对坐标系进行转换,如: reflectX, reflectY, transpose 等
92
+ */
93
+ readonly coordinate?: Transformations;
87
94
  }
@@ -31,11 +31,12 @@ import { Scatter, ScatterOptions } from '../scatter';
31
31
  import { Histogram, HistogramOptions } from '../histogram';
32
32
  import { Funnel, FunnelOptions } from '../funnel';
33
33
  import { Stock, StockOptions } from '../stock';
34
+ import { Options } from '../../types';
34
35
 
35
36
  /**
36
- * 移除 options 中的 width、height、data 设置
37
+ * 移除 options 中的 width、height 设置, 将 options 的 data 设置为可选
37
38
  */
38
- type OmitPlotOptions<T> = Omit<T, 'width' | 'height' | 'data'>;
39
+ type PlotOptions<T> = Omit<T, 'width' | 'height' | 'data'> & Partial<Pick<T extends Options ? T : never, 'data'>>;
39
40
 
40
41
  /**
41
42
  * multi-view 中的支持的 plots 类型(带 options 定义)
@@ -49,63 +50,63 @@ export type IPlotTypes =
49
50
  /**
50
51
  * plot 配置
51
52
  */
52
- readonly options: OmitPlotOptions<LineOptions>;
53
+ readonly options: PlotOptions<LineOptions>;
53
54
  }
54
55
  | {
55
56
  readonly type: 'pie';
56
- readonly options: OmitPlotOptions<PieOptions>;
57
+ readonly options: PlotOptions<PieOptions>;
57
58
  }
58
59
  | {
59
60
  readonly type: 'bar';
60
- readonly options: OmitPlotOptions<BarOptions>;
61
+ readonly options: PlotOptions<BarOptions>;
61
62
  }
62
63
  | {
63
64
  readonly type: 'column';
64
- readonly options: OmitPlotOptions<ColumnOptions>;
65
+ readonly options: PlotOptions<ColumnOptions>;
65
66
  }
66
67
  | {
67
68
  readonly type: 'area';
68
- readonly options: OmitPlotOptions<AreaOptions>;
69
+ readonly options: PlotOptions<AreaOptions>;
69
70
  }
70
71
  | {
71
72
  readonly type: 'gauge';
72
- readonly options: OmitPlotOptions<GaugeOptions>;
73
+ readonly options: PlotOptions<GaugeOptions>;
73
74
  }
74
75
  | {
75
76
  readonly type: 'tiny-line';
76
- readonly options: OmitPlotOptions<TinyLineOptions>;
77
+ readonly options: PlotOptions<TinyLineOptions>;
77
78
  }
78
79
  | {
79
80
  readonly type: 'tiny-area';
80
- readonly options: OmitPlotOptions<TinyAreaOptions>;
81
+ readonly options: PlotOptions<TinyAreaOptions>;
81
82
  }
82
83
  | {
83
84
  readonly type: 'tiny-column';
84
- readonly options: OmitPlotOptions<TinyColumnOptions>;
85
+ readonly options: PlotOptions<TinyColumnOptions>;
85
86
  }
86
87
  | {
87
88
  readonly type: 'ring-progress';
88
- readonly options: OmitPlotOptions<RingProgressOptions>;
89
+ readonly options: PlotOptions<RingProgressOptions>;
89
90
  }
90
91
  | {
91
92
  readonly type: 'progress';
92
- readonly options: OmitPlotOptions<ProgressOptions>;
93
+ readonly options: PlotOptions<ProgressOptions>;
93
94
  }
94
95
  | {
95
96
  readonly type: 'histogram';
96
- readonly options: OmitPlotOptions<HistogramOptions>;
97
+ readonly options: PlotOptions<HistogramOptions>;
97
98
  }
98
99
  | {
99
100
  readonly type: 'scatter';
100
- readonly options: OmitPlotOptions<ScatterOptions>;
101
+ readonly options: PlotOptions<ScatterOptions>;
101
102
  }
102
103
  | {
103
104
  readonly type: 'funnel';
104
- readonly options: OmitPlotOptions<FunnelOptions>;
105
+ readonly options: PlotOptions<FunnelOptions>;
105
106
  }
106
107
  | {
107
108
  readonly type: 'stock';
108
- readonly options: OmitPlotOptions<StockOptions>;
109
+ readonly options: PlotOptions<StockOptions>;
109
110
  };
110
111
 
111
112
  /**
@@ -138,7 +138,7 @@ function label(params: Params<PieOptions>): Params<PieOptions> {
138
138
  const angleScale = chart.getScaleByField(angleField);
139
139
  const percent = angleScale?.scale(value);
140
140
  return isFunction(content)
141
- ? // append pecent (number) to data, users can get origin data from `dataum._origin`
141
+ ? // append percent (number) to data, users can get origin data from `dataum._origin`
142
142
  content({ ...data, percent }, dataum, index)
143
143
  : isString(content)
144
144
  ? template(content as string, {
@@ -150,25 +150,38 @@ export function sankeyLayout(
150
150
  const layoutData: SankeyLayoutOutputData = sankeyProcessor(data);
151
151
 
152
152
  // post process (x, y), etc.
153
- layoutData.nodes.forEach((node) => {
154
- const { x0, x1, y0, y1 } = node;
155
- /* points
156
- * 3---2
157
- * | |
158
- * 0---1
159
- */
160
- node.x = [x0, x1, x1, x0];
161
- node.y = [y0, y0, y1, y1];
162
- });
163
-
164
- layoutData.links.forEach((edge) => {
165
- const { source, target } = edge;
166
- const sx = source.x1;
167
- const tx = target.x0;
168
- edge.x = [sx, sx, tx, tx];
169
- const offset = edge.width / 2;
170
- edge.y = [edge.y0 + offset, edge.y0 - offset, edge.y1 + offset, edge.y1 - offset];
171
- });
172
-
173
- return layoutData;
153
+ const nodes = layoutData.nodes
154
+ .map((node) => {
155
+ const { x0, x1, y0, y1 } = node;
156
+ /* points
157
+ * 3---2
158
+ * | |
159
+ * 0---1
160
+ */
161
+ node.x = [x0, x1, x1, x0];
162
+ node.y = [y0, y0, y1, y1];
163
+
164
+ return node;
165
+ })
166
+ .filter((node) => {
167
+ return node.name !== null;
168
+ });
169
+
170
+ const links = layoutData.links
171
+ .map((edge) => {
172
+ const { source, target } = edge;
173
+ const sx = source.x1;
174
+ const tx = target.x0;
175
+ edge.x = [sx, sx, tx, tx];
176
+ const offset = edge.width / 2;
177
+ edge.y = [edge.y0 + offset, edge.y0 - offset, edge.y1 + offset, edge.y1 - offset];
178
+
179
+ return edge;
180
+ })
181
+ .filter((edge) => {
182
+ const { source, target } = edge;
183
+ return source.name !== null && target.name !== null;
184
+ });
185
+
186
+ return { nodes, links };
174
187
  }
@@ -147,6 +147,12 @@ export type Options = {
147
147
  * @default false
148
148
  */
149
149
  readonly supportCSSTransform?: boolean;
150
+ /**
151
+ * @title 是否开启 label 延迟渲染
152
+ * @description 开启后 label 渲染会在浏览器空闲时机执行。可制定具体 number 数值,来限定 timeout 时间 (建议开启时,指定 timeout 时间)
153
+ * @default false
154
+ */
155
+ readonly useDeferredLabel?: boolean | number;
150
156
 
151
157
  /**
152
158
  * @title 数据
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Transformations of coordinate
3
+ */
4
+ export type Transformations = Array<
5
+ | {
6
+ /** send (x, y) to (-x, y) */
7
+ type: 'reflectX';
8
+ }
9
+ | {
10
+ /** send (x, y) to (x, -y) */
11
+ type: 'reflectY';
12
+ }
13
+ | {
14
+ /** send (x, y) to (y, x) */
15
+ type: 'transpose';
16
+ }
17
+ >;
@@ -85,7 +85,7 @@ export function getDeepPercent(data: Record<string, any>[], measure: string, fie
85
85
  * 获取数据,如果是百分比,进行数据转换 (适用于面积图、柱状图、条形图)
86
86
  * @param isPercent 是否百分比
87
87
  */
88
- export function getDataWhetherPecentage(
88
+ export function getDataWhetherPercentage(
89
89
  data: Record<string, any>[],
90
90
  yField: string,
91
91
  groupField: string,