mirror of https://gitee.com/bigwinds/arangodb
GraphViewer: Test for default behaviour of zooming
This commit is contained in:
parent
e750f3f155
commit
efaf5d82aa
|
@ -12,6 +12,7 @@
|
|||
<li><a href="runnerEventDispatcher.html">Event Dispatcher</a></li>
|
||||
<li><a href="runnerEventLibrary.html">Event Library</a></li>
|
||||
<li><a href="runnerColourMapper.html">Colour Mapper</a></li>
|
||||
<li><a href="runnerZoomManager.html">Zoom Manager</a></li>
|
||||
</ul>
|
||||
</body>
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*jslint indent: 2, nomen: true, maxlen: 100, white: true plusplus: true */
|
||||
/*global beforeEach, afterEach */
|
||||
/*global beforeEach, afterEach, Jasmine */
|
||||
/*global describe, it, expect */
|
||||
/*global window, eb, loadFixtures, document */
|
||||
/*global $, _, d3*/
|
||||
|
@ -72,36 +72,231 @@
|
|||
|
||||
});
|
||||
|
||||
describe('setup correctly', function() {
|
||||
describe('setup with default values', function() {
|
||||
|
||||
var manager;
|
||||
var w,
|
||||
h,
|
||||
manager;
|
||||
|
||||
beforeEach(function() {
|
||||
manager = new ZoomManager(10, 10);
|
||||
w = 200;
|
||||
h = 200;
|
||||
manager = new ZoomManager(w, h);
|
||||
});
|
||||
|
||||
it('should offer a function to get the current font-size', function() {
|
||||
expect(manager.getFontSize).toBeDefined();
|
||||
expect(manager.getFontSize).toEqual(Jasmine.any(Function));
|
||||
describe('the interface', function() {
|
||||
it('should offer a function to get the current font-size', function() {
|
||||
expect(manager.getFontSize).toBeDefined();
|
||||
expect(manager.getFontSize).toEqual(Jasmine.any(Function));
|
||||
});
|
||||
|
||||
it('should offer a function to get the current node-radius', function() {
|
||||
expect(manager.getRadius).toBeDefined();
|
||||
expect(manager.getRadius).toEqual(Jasmine.any(Function));
|
||||
});
|
||||
|
||||
it('should offer a function to get the node limit', function() {
|
||||
expect(manager.getNodeLimit).toBeDefined();
|
||||
expect(manager.getNodeLimit).toEqual(Jasmine.any(Function));
|
||||
});
|
||||
|
||||
it('should offer a function to get the distortion', function() {
|
||||
expect(manager.getDistortion).toBeDefined();
|
||||
expect(manager.getDistortion).toEqual(Jasmine.any(Function));
|
||||
});
|
||||
|
||||
it('should offer a function for zoom-in', function() {
|
||||
expect(manager.zoomIn).toBeDefined();
|
||||
expect(manager.zoomIn).toEqual(Jasmine.any(Function));
|
||||
});
|
||||
|
||||
it('should offer a function for zoom-out', function() {
|
||||
expect(manager.zoomOut).toBeDefined();
|
||||
expect(manager.zoomOut).toEqual(Jasmine.any(Function));
|
||||
});
|
||||
});
|
||||
|
||||
it('should offer a function to get the current node-radius', function() {
|
||||
expect(manager.getRadius).toBeDefined();
|
||||
expect(manager.getRadius).toEqual(Jasmine.any(Function));
|
||||
describe('default values', function() {
|
||||
|
||||
var fontMax,
|
||||
fontMin,
|
||||
radMax,
|
||||
radMin,
|
||||
nodeMax,
|
||||
nodeMaxNoLabel,
|
||||
nodeMinLabel,
|
||||
nodeMin;
|
||||
|
||||
|
||||
beforeEach(function() {
|
||||
var labelSize = function (font) {
|
||||
return 60 * font * font;
|
||||
},
|
||||
circleSize = function (radius) {
|
||||
return 4 * radius * radius * Math.PI;
|
||||
};
|
||||
fontMax = 16;
|
||||
fontMin = 6;
|
||||
radMax = 25;
|
||||
radMin = 1;
|
||||
nodeMax = Math.floor(w * h / labelSize(fontMax));
|
||||
nodeMinLabel = Math.floor(w * h / labelSize(fontMin));
|
||||
nodeMaxNoLabel = Math.floor(w * h / circleSize((radMax - radMin) / 2 + radMin));
|
||||
nodeMin = Math.floor(w * h / circleSize(radMin));
|
||||
});
|
||||
|
||||
it('should offer maximized values if no zoom happens', function() {
|
||||
expect(manager.getFontSize()).toEqual(fontMax);
|
||||
expect(manager.getRadius()).toEqual(radMax);
|
||||
expect(manager.getNodeLimit()).toEqual(nodeMax);
|
||||
expect(manager.getDistortion()).toBeCloseTo(0, 6);
|
||||
});
|
||||
|
||||
it('should not be possible to zoom in if max-zoom is reached', function() {
|
||||
var oldFS = manager.getFontSize(),
|
||||
oldR = manager.getRadius(),
|
||||
oldNL = manager.getNodeLimit(),
|
||||
oldD = manager.getDistortion();
|
||||
manager.zoomIn();
|
||||
expect(manager.getFontSize()).toEqual(oldFS);
|
||||
expect(manager.getRadius()).toEqual(oldR);
|
||||
expect(manager.getNodeLimit()).toEqual(oldNL);
|
||||
expect(manager.getDistortion()).toEqual(oldD);
|
||||
});
|
||||
|
||||
it('should be possible to zoom-out until minimal font-size is reached', function() {
|
||||
var oldFS,
|
||||
oldR,
|
||||
oldNL,
|
||||
oldD,
|
||||
loopCounter = 0;
|
||||
while (manager.getFontSize() > fontMin && manager.getFontSize() !== null) {
|
||||
oldFS = manager.getFontSize();
|
||||
oldR = manager.getRadius();
|
||||
oldNL = manager.getNodeLimit();
|
||||
oldD = manager.getDistortion();
|
||||
manager.zoomOut();
|
||||
expect(manager.getFontSize()).toBeLessThan(oldFS);
|
||||
expect(manager.getRadius()).toBeLessThan(oldR);
|
||||
expect(manager.getNodeLimit()).toBeGreaterThan(oldNL);
|
||||
expect(manager.getDistortion()).toBeGreaterThan(oldD);
|
||||
loopCounter++;
|
||||
if (loopCounter === 1000) {
|
||||
this.fail(new Error('The minimal font-size should have been reached'));
|
||||
}
|
||||
}
|
||||
if (manager.getFontSize() === null) {
|
||||
manager.zoomIn();
|
||||
}
|
||||
expect(manager.getFontSize()).toBeCloseTo(fontMin, 6);
|
||||
expect(manager.getRadius()).toBeCloseTo((radMax-radMin) / 2, 6);
|
||||
expect(manager.getNodeLimit()).toBeCloseTo(nodeMinLabel, 6);
|
||||
//expect(manager.getDistortion()).toBeCloseTo(0, 6);
|
||||
});
|
||||
|
||||
describe('with zoomlevel adjusted to minimal font-size', function() {
|
||||
|
||||
beforeEach(function() {
|
||||
var loopCounter = 0;
|
||||
while (manager.getFontSize() > fontMin && manager.getFontSize() !== null) {
|
||||
manager.zoomOut();
|
||||
loopCounter++;
|
||||
if (loopCounter === 1000) {
|
||||
this.fail(new Error('The minimal font-size should have been reached'));
|
||||
}
|
||||
}
|
||||
if (manager.getFontSize() === null) {
|
||||
manager.zoomIn();
|
||||
}
|
||||
});
|
||||
|
||||
it('should be able to zoom-in again', function() {
|
||||
var oldFS,
|
||||
oldR,
|
||||
oldNL,
|
||||
oldD,
|
||||
loopCounter = 0;
|
||||
while (manager.getFontSize() < fontMax) {
|
||||
oldFS = manager.getFontSize();
|
||||
oldR = manager.getRadius();
|
||||
oldNL = manager.getNodeLimit();
|
||||
oldD = manager.getDistortion();
|
||||
manager.zoomIn();
|
||||
expect(manager.getFontSize()).toBeGreaterThan(oldFS);
|
||||
expect(manager.getRadius()).toBeGreaterThan(oldR);
|
||||
expect(manager.getNodeLimit()).toBeLessThan(oldNL);
|
||||
expect(manager.getDistortion()).toBeLessThan(oldD);
|
||||
loopCounter++;
|
||||
if (loopCounter === 1000) {
|
||||
this.fail(new Error('The maximal font-size should have been reached'));
|
||||
}
|
||||
}
|
||||
expect(manager.getFontSize()).toEqual(fontMax);
|
||||
expect(manager.getRadius()).toEqual(radMax);
|
||||
expect(manager.getNodeLimit()).toEqual(nodeMax);
|
||||
expect(manager.getDistortion()).toBeCloseTo(0, 6);
|
||||
});
|
||||
|
||||
it('should return null for font-size if further zoomed out', function() {
|
||||
manager.zoomOut();
|
||||
expect(manager.getFontSize()).toEqual(null);
|
||||
});
|
||||
|
||||
it('should significantly increase the node limit if further zoomed out', function() {
|
||||
manager.zoomOut();
|
||||
expect(manager.getNodeLimit()).toEqual(nodeMaxNoLabel);
|
||||
});
|
||||
|
||||
it('should be able to zoom-out until minimal node radius is reached', function() {
|
||||
var oldR,
|
||||
oldNL,
|
||||
oldD,
|
||||
loopCounter = 0;
|
||||
while (manager.getRadius > radMin) {
|
||||
oldR = manager.getRadius();
|
||||
oldNL = manager.getNodeLimit();
|
||||
oldD = manager.getDistortion();
|
||||
manager.zoomOut();
|
||||
expect(manager.getFontSize()).toEqual(null);
|
||||
expect(manager.getRadius()).toBeLessThan(oldR);
|
||||
expect(manager.getNodeLimit()).toBeGreaterThan(oldNL);
|
||||
expect(manager.getDistortion()).toBeGreaterThan(oldD);
|
||||
loopCounter++;
|
||||
if (loopCounter === 1000) {
|
||||
this.fail(new Error('The minimal font-size should have been reached'));
|
||||
}
|
||||
}
|
||||
if (manager.getFontSize() === null) {
|
||||
manager.zoomIn();
|
||||
}
|
||||
expect(manager.getFontSize()).toBeCloseTo(fontMin, 6);
|
||||
expect(manager.getRadius()).toBeCloseTo((radMax-radMin) / 2, 6);
|
||||
expect(manager.getNodeLimit()).toBeCloseTo(nodeMinLabel, 6);
|
||||
//expect(manager.getDistortion()).toBeCloseTo(0, 6);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('with zoomlevel adjusted to maximal zoom out', function() {
|
||||
|
||||
beforeEach(function() {
|
||||
var loopCounter = 0;
|
||||
while (manager.getRadius > radMin) {
|
||||
manager.zoomOut();
|
||||
loopCounter++;
|
||||
if (loopCounter === 2000) {
|
||||
this.fail(new Error('The minimal zoom level should have been reached'));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it('should offer a function for zoom-in', function() {
|
||||
expect(manager.zoomIn).toBeDefined();
|
||||
expect(manager.zoomIn).toEqual(Jasmine.any(Function));
|
||||
});
|
||||
|
||||
it('should offer a function for zoom-out', function() {
|
||||
expect(manager.zoomOut).toBeDefined();
|
||||
expect(manager.zoomOut).toEqual(Jasmine.any(Function));
|
||||
});
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
describe('testing user-defined values', function() {
|
||||
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue