Skip to content

Commit

Permalink
feat: 修改scale度量修改的单测
Browse files Browse the repository at this point in the history
  • Loading branch information
cycgit committed Jul 16, 2020
1 parent 0107825 commit 52dc331
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 33 deletions.
5 changes: 0 additions & 5 deletions src/chart/controller/scale.js
Expand Up @@ -189,11 +189,6 @@ class ScaleController {
const newScale = new Scale(cfg);
scales[field] = newScale;

// 兼容scale type类型为cat
if (type === 'timeCat') {
newScale.type = 'timeCat';
}

return newScale;
}

Expand Down
4 changes: 2 additions & 2 deletions test/bug/guide-html-spec.js
Expand Up @@ -39,8 +39,8 @@ describe('The position calculate of Guide.HTML', () => {
chart.render();

const guideEle = $('#guide');
expect(guideEle.position().top).to.eql(216);
expect(guideEle.position().left).to.eql(172);
expect(guideEle.position().top).to.eql(220);
expect(guideEle.position().left).to.eql(176);
const wrapper = $('#chartWrapper')[0];
document.body.removeChild(wrapper);
});
Expand Down
4 changes: 2 additions & 2 deletions test/unit/animation/detail-spec.js
Expand Up @@ -60,7 +60,7 @@ describe('Group animation', function() {
chart.render();

setTimeout(function() {
expect(Object.keys(chart.get('canvas').get('caches')).length).to.equal(26);
expect(Object.keys(chart.get('canvas').get('caches')).length).to.equal(20);
expect(chart.get('isUpdate')).to.be.undefined;

chart.scale('sold', {
Expand All @@ -74,7 +74,7 @@ describe('Group animation', function() {
]);

setTimeout(function() {
expect(Object.keys(chart.get('canvas').get('caches')).length).to.equal(18);
expect(Object.keys(chart.get('canvas').get('caches')).length).to.equal(16);
expect(chart.get('isUpdate')).to.be.true;
Chart.plugins.unregister(Animation);
document.body.removeChild(canvas);
Expand Down
10 changes: 7 additions & 3 deletions test/unit/chart/chart-spec.js
Expand Up @@ -284,7 +284,7 @@ describe('chart test', () => {
const record = { a: '2', b: 4 };
const position = chart.getPosition(record);
expect(position).to.eql({
x: 250,
x: 171.66666666666669,
y: 181.66666666666669
});
});
Expand All @@ -293,7 +293,7 @@ describe('chart test', () => {
const point = { x: 250, y: 181.66666666666669 };
const record = chart.getRecord(point);
expect(record).to.eql({
a: '2',
a: '3',
b: 4
});
});
Expand All @@ -302,7 +302,11 @@ describe('chart test', () => {
const point = { x: 250, y: 150 };
const data = chart.getSnapRecords(point);
expect(data.length).to.equal(1);
expect(data[0]._origin).to.eql({ a: '2', b: 4, c: '2' });
expect(data[0]._origin).to.eql({
a: '3',
b: 5,
c: '1'
});
});

it('clear', function() {
Expand Down
20 changes: 8 additions & 12 deletions test/unit/interaction/pan-spec.js
Expand Up @@ -69,8 +69,7 @@ describe('Pan', function() {
x: 50, y: 20
});
const xScale = chart.getXScale();
expect(snapEqual(xScale.min, 4.329738321916591)).to.be.true;
expect(snapEqual(xScale.max, 11.329738321916592)).to.be.true;
expect([ xScale.min, xScale.max ]).to.eql([ 4.364608188716922, 11.364608188716922 ]);

pan.end();
expect(pan.currentDeltaX).to.be.null;
Expand Down Expand Up @@ -133,12 +132,11 @@ describe('chart pan', function() {
const limitRange = interaction.limitRange;
expect(limitRange).to.eql({ x1: { min: 1, max: 20 } });
const xScale = chart.getXScale();
expect(snapEqual(xScale.min, 2.5710521542204545)).to.be.true;
expect(snapEqual(xScale.max, 9.571052154220455)).to.be.true;

expect([ xScale.min, xScale.max ]).to.eql([ 2.559803810091316, 9.559803810091315 ]);
const xRange = interaction.xRange;
expect(snapEqual(xRange[0], 0.08268695548528708)).to.be.true;
expect(snapEqual(xRange[1], 0.4511080081168661)).to.be.true;
expect([ xRange[0], xRange[1] ]).to.eql([ 0.08209493737322715, 0.4505159900048061 ]);

});

it('pan y axis, and field is a linear type.', function() {
Expand Down Expand Up @@ -247,8 +245,8 @@ describe('chart pan', function() {
expect(xScale.ticks.length).to.equal(8);

const xRange = interaction.xRange;
expect(snapEqual(xRange[0], 0.47368421052631576)).to.be.true;
expect(snapEqual(xRange[1], 0.7894736842105263)).to.be.true;
expect([ xRange[0], xRange[1] ]).to.eql([ 0.47368421052631576, 0.7894736842105263 ]);

});

it('pan x axis with speed and step control.', function() {
Expand Down Expand Up @@ -322,16 +320,14 @@ describe('chart pan', function() {

const hBar = chart.get('_horizontalBar');
const highlightLine = hBar.get('children')[1];
expect(snapEqual(highlightLine.attr('x1'), 119.50947008634868)).to.be.true;
expect(snapEqual(highlightLine.attr('x2'), 308.4663150185033)).to.be.true;
expect([ highlightLine.attr('x1'), highlightLine.attr('x2') ]).to.eql([ 125.65473054584703, 309.78315654553865 ]);

setTimeout(() => {
const interaction = chart._interactions.pan;
interaction._doMove(120, 0);
const hBar = chart.get('_horizontalBar');
const highlightLine = hBar.get('children')[1];
expect(snapEqual(highlightLine.attr('x1'), 50.79789011101974)).to.be.true;
expect(snapEqual(highlightLine.attr('x2'), 239.75473504317432)).to.be.true;
expect([ highlightLine.attr('x1'), highlightLine.attr('x2') ]).to.eql([ 58.69893927323191, 242.82736527292352 ]);
chart.destroy();
document.body.removeChild(canvas);
done();
Expand Down
19 changes: 10 additions & 9 deletions test/unit/interaction/pinch-spec.js
Expand Up @@ -69,8 +69,8 @@ describe('Pinch', function() {
pinch.process(eventObj);
expect(pinch.currentPinchScaling).to.equal(1.3);
const xScale = chart.getXScale();
expect(snapEqual(xScale.min, 3.2424781342743505)).to.be.true;
expect(snapEqual(xScale.max, 17.24247813427435)).to.be.true;
expect(snapEqual(xScale.min, 3.17016735058703)).to.be.true;
expect(snapEqual(xScale.max, 17.17016735058703)).to.be.true;

setTimeout(() => {
eventObj = {
Expand All @@ -92,8 +92,9 @@ describe('Pinch', function() {
};
pinch.process(eventObj);
const xScale = chart.getXScale();
expect(snapEqual(xScale.min, 2.1949082755087916)).to.be.true;
expect(snapEqual(xScale.max, 18.13336981397033)).to.be.true;

expect(xScale.min).to.equal(2.1459594373204514);
expect(xScale.max).to.equal(18.08442097578199);

pinch.end(eventObj);
expect(pinch.currentPinchScaling).to.be.null;
Expand Down Expand Up @@ -162,22 +163,22 @@ describe('chart pinch', function() {
max: 19
},
y: {
min: 2,
max: 18
min: 2.5,
max: 17.5
}
});
const xScale = chart.getXScale();
expect(xScale.min).to.equal(6.3);
expect(xScale.max).to.equal(24.8);

const yScale = chart.getYScales()[0];
expect(yScale.min).to.equal(-6.5);
expect(yScale.max).to.equal(23.1);
expect(yScale.min).to.equal(-5.574999999999999);
expect(yScale.max).to.equal(22.175);

const xRange = interaction.xRange;
const yRange = interaction.yRange;
expect(xRange).to.eql([ 0.33157894736842103, 1.305263157894737 ]);
expect(yRange).to.eql([ -0.53125, 1.31875 ]);
expect(yRange).to.eql([ -0.5383333333333333, 1.3116666666666668 ]);
});

it('pinch x axis, and x field is a cat type', function(done) {
Expand Down

0 comments on commit 52dc331

Please sign in to comment.