Skip to content

Commit

Permalink
fix: fix the bug that axis configuration not work when data is empty. C…
Browse files Browse the repository at this point in the history
…losed #439.
  • Loading branch information
simaQ committed Dec 6, 2018
1 parent 717f2bf commit 594e4f8
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/chart/controller/scale.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class ScaleController {
let scale;
if (!data || !data.length) {
if (def && def.type) {
def.field = field;
scale = new Scale[SCALE_TYPES_MAP[def.type]](def);
} else {
scale = new Scale.Identity({
Expand Down
3 changes: 3 additions & 0 deletions test/bug/issue-437-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,8 @@ describe('Issue 437', () => {
const children = axisController.backPlot.get('children');
expect(children.length).to.equal(1); // grid 存储在 backPlot 图层中
expect(children[0]._id).to.equal('axis-y0-grid-30');

chart.destroy();
document.body.removeChild(canvas);
});
});
77 changes: 77 additions & 0 deletions test/bug/issue-438-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
const expect = require('chai').expect;
const F2 = require('../../src/core');
require('../../src/geom/line');

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

describe('Issue 438', () => {
it('Issue 438', done => {
const chart = new F2.Chart({
id: 'issue438',
pixelRatio: window.devicePixelRatio
});

chart.source([], {
name: {
type: 'cat'
},
value: {
type: 'linear',
min: 0,
max: 5,
tickInterval: 1
}
});
chart.axis('value', {
label: {
textAlign: 'center',
fill: '#777777',
fontSize: 36
},
grid: null
});
chart.axis('name', {
label: {
textAlign: 'center',
fill: '#777777',
fontSize: 36
},
line: null
});
chart.line().color('#FF790C').position('name*value');
chart.render();

const axisController = chart.get('axisController');
const labels = axisController.backPlot.get('children');
labels.forEach(label => {
expect(label.attr('fontSize')).to.equal(36);
});


setTimeout(() => {
chart.changeData([
{ name: 'a', value: '1' },
{ name: 'b', value: '1' },
{ name: 'c', value: '1' },
{ name: 'd', value: '1' },
{ name: 'e', value: '1' }
]);
const axisController = chart.get('axisController');
const labels = axisController.backPlot.get('children');
labels.forEach(label => {
expect(label.attr('fontSize')).to.equal(36);
});

chart.destroy();
document.body.removeChild(canvas);
done();
}, 300);
});
});

0 comments on commit 594e4f8

Please sign in to comment.