Skip to content

Commit 3a1406c

Browse files
author
羽熙
committed
fix(v2/bar): set catogery as xField
1 parent 186db35 commit 3a1406c

File tree

5 files changed

+30
-26
lines changed

5 files changed

+30
-26
lines changed

__tests__/unit/plots/bar/axis-spec.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ describe('bar axis', () => {
2727
expect(geometry.scales.sales.formatter).toBe(formatter);
2828
});
2929

30-
it('xAxis', () => {
30+
it('yAxis', () => {
3131
const bar = new Bar(createDiv(), {
3232
width: 400,
3333
height: 300,
3434
data: salesByArea,
35-
xField: 'sales',
36-
yField: 'area',
37-
xAxis: {
35+
xField: 'area',
36+
yField: 'sales',
37+
yAxis: {
3838
minLimit: 10000,
3939
nice: true,
4040
},
@@ -57,9 +57,9 @@ describe('bar axis', () => {
5757
width: 400,
5858
height: 300,
5959
data: salesByArea,
60-
xField: 'sales',
61-
yField: 'area',
62-
yAxis: {
60+
xField: 'area',
61+
yField: 'sales',
62+
xAxis: {
6363
label: {
6464
rotate: -Math.PI / 6,
6565
},

__tests__/unit/plots/bar/index-spec.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ describe('bar', () => {
88
width: 400,
99
height: 300,
1010
data: salesByArea,
11-
xField: 'sales',
12-
yField: 'area',
11+
xField: 'area',
12+
yField: 'sales',
1313
});
1414

1515
bar.render();
@@ -32,8 +32,8 @@ describe('bar', () => {
3232
width: 400,
3333
height: 300,
3434
data: salesByArea,
35-
xField: 'sales',
36-
yField: 'area',
35+
xField: 'area',
36+
yField: 'sales',
3737
colorField: 'area',
3838
});
3939

@@ -52,8 +52,8 @@ describe('bar', () => {
5252
width: 400,
5353
height: 300,
5454
data: salesByArea,
55-
xField: 'sales',
56-
yField: 'area',
55+
xField: 'area',
56+
yField: 'sales',
5757
colorField: 'area',
5858
color: palette,
5959
});

__tests__/unit/plots/bar/label-spec.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ describe('bar label', () => {
88
width: 400,
99
height: 300,
1010
data: salesByArea,
11-
xField: 'sales',
12-
yField: 'area',
11+
xField: 'area',
12+
yField: 'sales',
1313
meta: {
1414
sales: {
1515
nice: true,
@@ -41,8 +41,8 @@ describe('bar label', () => {
4141
width: 400,
4242
height: 300,
4343
data: salesByArea,
44-
xField: 'sales',
45-
yField: 'area',
44+
xField: 'area',
45+
yField: 'sales',
4646
meta: {
4747
sales: {
4848
nice: true,
@@ -67,8 +67,8 @@ describe('bar label', () => {
6767
width: 400,
6868
height: 300,
6969
data: salesByArea,
70-
xField: 'sales',
71-
yField: 'area',
70+
xField: 'area',
71+
yField: 'sales',
7272
meta: {
7373
sales: {
7474
nice: true,

__tests__/unit/plots/bar/style-spec.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ describe('bar style', () => {
88
width: 400,
99
height: 300,
1010
data: salesByArea,
11-
xField: 'sales',
12-
yField: 'area',
11+
xField: 'area',
12+
yField: 'sales',
1313
meta: {
1414
sales: {
1515
nice: true,
@@ -35,8 +35,8 @@ describe('bar style', () => {
3535
width: 400,
3636
height: 300,
3737
data: salesByArea,
38-
xField: 'sales',
39-
yField: 'area',
38+
xField: 'area',
39+
yField: 'sales',
4040
meta: {
4141
sales: {
4242
nice: true,

src/plots/bar/adaptor.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@ function field(params: Params<BarOptions>): Params<BarOptions> {
1515
const { data, xField, yField, colorField, color } = options;
1616

1717
chart.data(data);
18+
19+
// transpose column to bar
1820
chart.coordinate().transpose();
19-
const geometry = chart.interval().position(`${yField}*${xField}`);
21+
22+
// category as xField
23+
const geometry = chart.interval().position(`${xField}*${yField}`);
2024

2125
if (colorField) {
2226
geometry.color(colorField, color);
@@ -107,7 +111,7 @@ function style(params: Params<BarOptions>): Params<BarOptions> {
107111
*/
108112
function label(params: Params<BarOptions>): Params<BarOptions> {
109113
const { chart, options } = params;
110-
const { label, xField } = options;
114+
const { label, yField } = options;
111115

112116
const geometry = findGeometry(chart, 'interval');
113117

@@ -116,7 +120,7 @@ function label(params: Params<BarOptions>): Params<BarOptions> {
116120
} else {
117121
const { callback, ...cfg } = label;
118122
geometry.label({
119-
fields: [xField],
123+
fields: [yField],
120124
callback,
121125
cfg,
122126
});

0 commit comments

Comments
 (0)