Skip to content

Commit

Permalink
Add tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
manthey committed Mar 31, 2022
1 parent 0b90836 commit 8843725
Show file tree
Hide file tree
Showing 5 changed files with 217 additions and 5 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
## Unreleased

### Features
- Add support for ellipse and circle annotations
- Add support for ellipse and circle annotations ([811](../../pull/811))

### Improvements
- Improve parsing OME TIFF channel names ([806](../../pull/806))
- Improve handling when a file vanishes ([807](../../pull/807))
- Add TileSourceXYZRangeError ([809](../../pull/809))

## Version 1.12.0

Expand Down
2 changes: 1 addition & 1 deletion girder/girder_large_image/web_client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"dependencies": {
"copy-webpack-plugin": "^4.5.2",
"d3": "^3.5.16",
"geojs": "^1.0.1",
"geojs": "^1.8.0",
"hammerjs": "^2.0.8",
"js-yaml": "^3.14.0",
"sinon": "^2.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,44 @@ describe('Annotations', function () {
expect(obj.coordinates).toEqual([1, 2]);
});

it('ellipse', function () {
var obj = largeImageAnnotation.annotations.geometry.ellipse({
type: 'ellipse',
id: 'a',
center: [10, 20, 0],
width: 5,
height: 10,
rotation: 0
});

expect(obj.type).toBe('Polygon');
expect(obj.coordinates.length).toBe(1);
expect(obj.annotationType).toBe('ellipse');
expectClose(
obj.coordinates[0], [
[7.5, 15], [12.5, 15], [12.5, 25], [7.5, 25], [7.5, 15]
]
);
});

it('circle', function () {
var obj = largeImageAnnotation.annotations.geometry.circle({
type: 'circle',
id: 'a',
center: [10, 20, 0],
radius: 5
});

expect(obj.type).toBe('Polygon');
expect(obj.coordinates.length).toBe(1);
expect(obj.annotationType).toBe('circle');
expectClose(
obj.coordinates[0], [
[5, 15], [15, 15], [15, 25], [5, 25], [5, 15]
]
);
});

describe('heatmapColorTable', function () {
var values = [0.508, 0.806, 0.311, 0.402, 0.535, 0.661, 0.866, 0.31, 0.241, 0.63, 0.555, 0.067, 0.668, 0.164, 0.512, 0.647, 0.501, 0.637, 0.498, 0.658, 0.332, 0.431, 0.053, 0.531];
var tests = [{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,5 +219,44 @@ describe('geojs-annotations', function () {
lineWidth: lineWidth
});
});

it('ellipse', function () {
type = 'ellipse';
coordinates = [
{x: 1, y: 2},
{x: 1, y: 4},
{x: 3, y: 4},
{x: 3, y: 2}
];
expect(geojs.types.ellipse(annotation)).toEqual({
type: 'ellipse',
center: [2, 3, 0],
width: 2,
height: 2,
rotation: 0,
fillColor: fillColor,
lineColor: lineColor,
lineWidth: lineWidth,
normal: [0, 0, 1]
});
});

it('circle', function () {
type = 'circle';
coordinates = [
{x: 1, y: 2},
{x: 1, y: 4},
{x: 3, y: 4},
{x: 3, y: 2}
];
expect(geojs.types.circle(annotation)).toEqual({
type: 'circle',
center: [2, 3, 0],
radius: 1,
fillColor: fillColor,
lineColor: lineColor,
lineWidth: lineWidth
});
});
});
});
140 changes: 137 additions & 3 deletions girder_annotation/test_annotation/web_client_specs/geojsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ $(function () {
expect(elements.length).toBe(1);
expect(elements[0].type).toBe('point');
closeTo(elements[0].center, [100, 200, 0]);
created = true;
created = true;;
return null;
});
var pt = viewer.viewer.gcsToDisplay({x: 100, y: 200});
Expand Down Expand Up @@ -483,7 +483,7 @@ $(function () {
closeTo(elements[0].points[0], [100, 200, 0]);
closeTo(elements[0].points[1], [200, 200, 0]);
closeTo(elements[0].points[2], [200, 300, 0]);
created = true;
created = true;;
return null;
});

Expand Down Expand Up @@ -550,6 +550,140 @@ $(function () {
});
});

it('draw rectangle', function () {
var created;

runs(function () {
viewer.startDrawMode('rectangle').then(function (elements) {
expect(elements.length).toBe(1);
closeTo(elements[0].center, [150, 300, 0]);
expect(elements[0].width).toBe(100);
expect(elements[0].height).toBe(200);
created = true;;
return null;
});

interactor.simulateEvent('mousemove', {
button: 'left',
map: viewer.viewer.gcsToDisplay({x: 100, y: 200})
});
interactor.simulateEvent('mousedown', {
button: 'left',
map: viewer.viewer.gcsToDisplay({x: 100, y: 200})
});
interactor.simulateEvent('mouseup', {
button: 'left',
map: viewer.viewer.gcsToDisplay({x: 100, y: 200})
});

interactor.simulateEvent('mousemove', {
button: 'left',
map: viewer.viewer.gcsToDisplay({x: 200, y: 400})
});
interactor.simulateEvent('mousedown', {
button: 'left',
map: viewer.viewer.gcsToDisplay({x: 200, y: 400})
});
interactor.simulateEvent('mouseup', {
button: 'left',
map: viewer.viewer.gcsToDisplay({x: 200, y: 400})
});
});

waitsFor(function () {
return created;
});
});

it('draw ellipse', function () {
var created;

runs(function () {
viewer.startDrawMode('ellipse').then(function (elements) {
expect(elements.length).toBe(1);
closeTo(elements[0].center, [150, 300, 0]);
expect(elements[0].width).toBe(100);
expect(elements[0].height).toBe(200);
created = true;;
return null;
});

interactor.simulateEvent('mousemove', {
button: 'left',
map: viewer.viewer.gcsToDisplay({x: 100, y: 200})
});
interactor.simulateEvent('mousedown', {
button: 'left',
map: viewer.viewer.gcsToDisplay({x: 100, y: 200})
});
interactor.simulateEvent('mouseup', {
button: 'left',
map: viewer.viewer.gcsToDisplay({x: 100, y: 200})
});

interactor.simulateEvent('mousemove', {
button: 'left',
map: viewer.viewer.gcsToDisplay({x: 200, y: 400})
});
interactor.simulateEvent('mousedown', {
button: 'left',
map: viewer.viewer.gcsToDisplay({x: 200, y: 400})
});
interactor.simulateEvent('mouseup', {
button: 'left',
map: viewer.viewer.gcsToDisplay({x: 200, y: 400})
});
});

waitsFor(function () {
return created;
});
});

it('draw circle', function () {
var created;

runs(function () {
viewer.startDrawMode('circle').then(function (elements) {
expect(elements.length).toBe(1);
closeTo(elements[0].center, [200, 200, 0]);
expect(elements[0].radius).toBe(100);
created = true;;
return null;
});

interactor.simulateEvent('mousemove', {
button: 'left',
map: viewer.viewer.gcsToDisplay({x: 100, y: 100})
});
interactor.simulateEvent('mousedown', {
button: 'left',
map: viewer.viewer.gcsToDisplay({x: 100, y: 100})
});
interactor.simulateEvent('mouseup', {
button: 'left',
map: viewer.viewer.gcsToDisplay({x: 100, y: 100})
});

interactor.simulateEvent('mousemove', {
button: 'left',
map: viewer.viewer.gcsToDisplay({x: 200, y: 500})
});
interactor.simulateEvent('mousedown', {
button: 'left',
map: viewer.viewer.gcsToDisplay({x: 200, y: 500})
});
interactor.simulateEvent('mouseup', {
button: 'left',
map: viewer.viewer.gcsToDisplay({x: 200, y: 500})
});
});

waitsFor(function () {
return created;
});
});

it('draw line', function () {
var created;

Expand All @@ -562,7 +696,7 @@ $(function () {
closeTo(elements[0].points[0], [100, 200, 0]);
closeTo(elements[0].points[1], [200, 200, 0]);
closeTo(elements[0].points[2], [200, 300, 0]);
created = true;
created = true;;
return null;
});

Expand Down

0 comments on commit 8843725

Please sign in to comment.