Skip to content

Commit

Permalink
fix(axis): 修复转置极坐标无法配置坐标轴的问题。Closed #1744
Browse files Browse the repository at this point in the history
  • Loading branch information
simaQ committed Mar 20, 2020
1 parent b1dff91 commit 74e1e22
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/chart/controller/axis.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { deepMix, each, get, map, mix } from '@antv/util';
import { deepMix, each, get, map, mix, isUndefined } from '@antv/util';
import { COMPONENT_TYPE, DIRECTION, LAYER } from '../../constant';
import { CircleAxis, CircleGrid, IGroup, LineAxis, LineGrid, Scale } from '../../dependents';
import { AxisCfg, AxisOption, ComponentOption } from '../../interface';
Expand Down Expand Up @@ -220,7 +220,7 @@ export default class Axis extends Controller<Option> {
updatedCache.set(gridId, grid);
}
}
} else if (coordinate.isPolar && !coordinate.isTransposed) {
} else if (coordinate.isPolar) {
// 1. do axis update
let axis = this.cache.get(axisId);
// 存在则更新
Expand Down Expand Up @@ -313,7 +313,7 @@ export default class Axis extends Controller<Option> {
updatedCache.set(gridId, grid);
}
}
} else if (coordinate.isPolar && !coordinate.isTransposed) {
} else if (coordinate.isPolar) {
// 1. do axis update
let axis = this.cache.get(axisId);
// 存在则更新
Expand Down Expand Up @@ -389,7 +389,11 @@ export default class Axis extends Controller<Option> {
if (grid) {
this.cache.set(gridId, grid);
}
} else if (coordinate.isPolar && !coordinate.isTransposed) {
} else if (coordinate.isPolar) {
if (coordinate.isTransposed && isUndefined(xAxisOption)) {
// 默认对于转置的极坐标不绘制坐标轴
return;
}
// axis
const axis = this.createCircleAxis(scale, xAxisOption, layer, direction, dim);
this.cache.set(axisId, axis);
Expand Down Expand Up @@ -440,7 +444,11 @@ export default class Axis extends Controller<Option> {
if (grid) {
this.cache.set(gridId, grid);
}
} else if (coordinate.isPolar && !coordinate.isTransposed) {
} else if (coordinate.isPolar) {
if (coordinate.isTransposed && isUndefined(yAxisOption)) {
// 默认对于转置的极坐标不绘制坐标轴
return;
}
// axis
// @ts-ignore
const axis = this.createLineAxis(scale, yAxisOption, layer, 'radius', dim);
Expand Down
45 changes: 45 additions & 0 deletions tests/bugs/1744-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { Chart } from '../../src';
import { createDiv } from '../util/dom';
import { COMPONENT_TYPE } from '../../src/constant';

describe('1744', () => {
const data = [
{ question: '问题 1', percent: 0.21 },
{ question: '问题 2', percent: 0.4 },
{ question: '问题 3', percent: 0.49 },
{ question: '问题 4', percent: 0.52 },
{ question: '问题 5', percent: 0.53 },
{ question: '问题 6', percent: 0.84 },
{ question: '问题 7', percent: 1.0 },
{ question: '问题 8', percent: 1.2 },
];

const chart = new Chart({
container: createDiv(),
width: 400,
height: 300,
});

chart.data(data);
chart.coordinate('polar', { innerRadius: 0.1 }).transpose();

chart
.interval()
.position('question*percent')
.color('percent', '#BAE7FF-#1890FF-#0050B3');
chart.render();

it('Not render by default', () => {
const axes = chart.getComponents().filter((co) => co.type === COMPONENT_TYPE.AXIS);
expect(axes.length).toBe(0);
});

it('But can be opened by chart.axis()', () => {
chart.axis('question', true);
chart.axis('percent', true);

chart.render(true);
const axes = chart.getComponents().filter((co) => co.type === COMPONENT_TYPE.AXIS);
expect(axes.length).toBe(2);
});
});

0 comments on commit 74e1e22

Please sign in to comment.