Skip to content

Commit c48d535

Browse files
committed
feat(v2/column): export ColumnOptions & add findGeometry helper
1 parent 07f2c6e commit c48d535

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

src/common/helper.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Chart, Geometry } from '@antv/g2';
2+
3+
/**
4+
* 在 Chart 中查找第一个指定 type 类型的 geometry
5+
* @param chart
6+
*/
7+
export function findGeometry(chart: Chart, type: string): Geometry | undefined {
8+
return chart.geometries.find((g: Geometry) => g.type === type);
9+
}

src/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ export * from './types';
66
// 折线图及类型定义
77
export { Line, LineOptions } from './plots/line';
88

9-
export { Column } from './plots/column';
9+
// 柱形图及类型定义
10+
export { Column, ColumnOptions } from './plots/column';
1011

1112
// 饼图及类型定义
1213
export { Pie, PieOptions } from './plots/pie';

src/plots/column/adaptor.ts

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
import { Geometry, Chart } from '@antv/g2';
22
import { deepMix, isFunction } from '@antv/util';
33
import { Params } from '../../core/adaptor';
4+
import { findGeometry } from '../../common/helper';
45
import { flow, pick } from '../../utils';
56
import { ColumnOptions } from './types';
67
import { AXIS_META_CONFIG_KEYS } from '../../constant';
78

8-
function findGeometry(chart: Chart): Geometry | undefined {
9-
return chart.geometries.find((g: Geometry) => g.type === 'interval');
10-
}
11-
129
/**
1310
* 字段
1411
* @param params
@@ -61,7 +58,7 @@ function axis(params: Params<ColumnOptions>): Params<ColumnOptions> {
6158
}
6259

6360
if (yAxis === false) {
64-
chart.axis(xField, false);
61+
chart.axis(yField, false);
6562
} else {
6663
chart.axis(yField, yAxis);
6764
}
@@ -92,7 +89,7 @@ function style(params: Params<ColumnOptions>): Params<ColumnOptions> {
9289
const { chart, options } = params;
9390
const { xField, yField, colorField, columnStyle } = options;
9491

95-
const geometry = findGeometry(chart);
92+
const geometry = findGeometry(chart, 'interval');
9693
if (columnStyle && geometry) {
9794
if (isFunction(columnStyle)) {
9895
geometry.style(colorField ? `${xField}*${yField}*${colorField}` : `${xField}*${yField}`, columnStyle);
@@ -111,7 +108,7 @@ function label(params: Params<ColumnOptions>): Params<ColumnOptions> {
111108
const { chart, options } = params;
112109
const { label, yField } = options;
113110

114-
const geometry = findGeometry(chart);
111+
const geometry = findGeometry(chart, 'interval');
115112

116113
if (!label) {
117114
geometry.label(false);

src/plots/line/adaptor.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function axis(params: Params<LineOptions>): Params<LineOptions> {
5959
}
6060

6161
if (yAxis === false) {
62-
chart.axis(xField, false);
62+
chart.axis(yField, false);
6363
} else {
6464
chart.axis(yField, yAxis);
6565
}

0 commit comments

Comments
 (0)