Skip to content

Commit

Permalink
fix: fix the bug that grid callback return null did not work. Closed #…
Browse files Browse the repository at this point in the history
  • Loading branch information
simaQ committed Dec 5, 2018
1 parent abbdfd9 commit 717f2bf
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 6 deletions.
6 changes: 1 addition & 5 deletions src/chart/controller/axis.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,7 @@ class AxisController {
Util.each(ticks, (tick, index) => {
if (Util.isFunction(label)) {
const executedLabel = label(tick.text, index, count);
if (executedLabel) {
labelCfg = Util.mix({}, Global._defaultAxis.label, executedLabel);
} else {
labelCfg = null;
}
labelCfg = executedLabel ? Util.mix({}, Global._defaultAxis.label, executedLabel) : null;
}
if (labelCfg) {
const textStyle = {};
Expand Down
3 changes: 2 additions & 1 deletion src/component/axis/abstract.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ class Abastract {
Util.each(gridPoints, function(subPoints, index) {
if (Util.isFunction(grid)) {
const tick = ticks[index] || {};
gridCfg = Util.mix({}, Global._defaultAxis.grid, grid(tick.text, index, count));
const executedGrid = grid(tick.text, index, count);
gridCfg = executedGrid ? Util.mix({}, Global._defaultAxis.grid, executedGrid) : null;
}

if (gridCfg) {
Expand Down
56 changes: 56 additions & 0 deletions test/bug/issue-437-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
const expect = require('chai').expect;
const F2 = require('../../src/core');
require('../../src/geom/line');
require('../../src/coord/polar');
require('../../src/component/axis/circle');

const canvas = document.createElement('canvas');
canvas.width = 300;
canvas.height = 300;
canvas.id = 'issue437';
canvas.style.position = 'fixed';
canvas.style.top = 0;
canvas.style.left = 0;
document.body.appendChild(canvas);

describe('Issue 437', () => {
it('Issue 437', () => {
const data = [
{ year: '1951 年', sales: 30 },
{ year: '1952 年', sales: 10 },
{ year: '1956 年', sales: 45 },
{ year: '1957 年', sales: 23 },
{ year: '1958 年', sales: 17 }
];
const chart = new F2.Chart({
id: 'issue437',
pixelRatio: window.devicePixelRatio
});

chart.source(data);
chart.coord('polar');
chart.axis('year', false);
chart.axis('sales', {
line: null, // 为了测试方便,将干扰因素去除
label: null,
grid(text) {
if (text === '30') {
return {
type: 'arc'
};
}
return null;
}
});

chart.line()
.position('year*sales')
.size(4);
chart.render();

const axisController = chart.get('axisController');
const children = axisController.backPlot.get('children');
expect(children.length).to.equal(1); // grid 存储在 backPlot 图层中
expect(children[0]._id).to.equal('axis-y0-grid-30');
});
});

0 comments on commit 717f2bf

Please sign in to comment.