Skip to content

Commit

Permalink
feat(annotation) Add default annontation properties
Browse files Browse the repository at this point in the history
add line length property
  • Loading branch information
chrisj committed Jan 11, 2025
1 parent 5898236 commit c826934
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 3 deletions.
41 changes: 41 additions & 0 deletions src/annotation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import { parseDataTypeValue } from "#src/util/lerp.js";
import { getRandomHexString } from "#src/util/random.js";
import { NullarySignal, Signal } from "#src/util/signal.js";
import { Uint64 } from "#src/util/uint64.js";
import { vec3 } from "gl-matrix";

Check failure on line 58 in src/annotation/index.ts

View workflow job for this annotation

GitHub Actions / client (ubuntu-latest)

`gl-matrix` import should occur before type import of `#src/coordinate_transform.js`

Check failure on line 58 in src/annotation/index.ts

View workflow job for this annotation

GitHub Actions / client (macos-latest)

`gl-matrix` import should occur before type import of `#src/coordinate_transform.js`

export type AnnotationId = string;

Expand Down Expand Up @@ -695,6 +696,13 @@ export interface AnnotationTypeHandler<T extends Annotation = Annotation> {
annotation: T,
callback: (vec: Float32Array, isVector: boolean) => void,
) => void;
defaultProperties: (
annotation: T,
scales: vec3,
) => {
properties: AnnotationNumericPropertySpec[];
values: number[];
};
}

function serializeFloatVector(
Expand Down Expand Up @@ -814,6 +822,24 @@ export const annotationTypeHandlers: Record<
callback(annotation.pointA, false);
callback(annotation.pointB, false);
},
defaultProperties(annotation: Line, scales: vec3) {
return {
properties: [
{
type: "float32",
identifier: "Length",
default: 0,
description: "Length of the line annotation in nanometers",
},
],
values: [
vec3.dist(
vec3.mul(vec3.create(), scales, annotation.pointA as vec3),
vec3.mul(vec3.create(), scales, annotation.pointB as vec3),
),
],
};
},
},
[AnnotationType.POINT]: {
icon: "⚬",
Expand Down Expand Up @@ -858,6 +884,11 @@ export const annotationTypeHandlers: Record<
visitGeometry(annotation: Point, callback) {
callback(annotation.point, false);
},
defaultProperties(annotation: Point, scales: vec3) {
annotation;
scales;
return { properties: [], values: [] };
},
},
[AnnotationType.AXIS_ALIGNED_BOUNDING_BOX]: {
icon: "❑",
Expand Down Expand Up @@ -926,6 +957,11 @@ export const annotationTypeHandlers: Record<
callback(annotation.pointA, false);
callback(annotation.pointB, false);
},
defaultProperties(annotation: AxisAlignedBoundingBox, scales: vec3) {
annotation;
scales;
return { properties: [], values: [] };
},
},
[AnnotationType.ELLIPSOID]: {
icon: "◎",
Expand Down Expand Up @@ -994,6 +1030,11 @@ export const annotationTypeHandlers: Record<
callback(annotation.center, false);
callback(annotation.radii, true);
},
defaultProperties(annotation: Ellipsoid, scales: vec3) {
annotation;
scales;
return { properties: [], values: [] };
},
},
};

Expand Down
23 changes: 20 additions & 3 deletions src/ui/annotations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1854,6 +1854,22 @@ export function UserLayerWithAnnotationsMixin<

const { relationships, properties } = annotationLayer.source;
const sourceReadonly = annotationLayer.source.readonly;
const globalCoordinateSpace =
this.manager.root.coordinateSpace.value;
const scales = new Float32Array(
globalCoordinateSpace.scales.map((x) => x / 1e-9),
) as vec3;
const defaultProperties = annotationTypeHandlers[
annotation.type
].defaultProperties(annotation, scales);
const allProperties = [
...defaultProperties.properties,
...properties,
];
const allValues = [
...defaultProperties.values,
...annotation.properties,
];

// Add the ID to the annotation details.
const label = document.createElement("label");
Expand All @@ -1872,8 +1888,10 @@ export function UserLayerWithAnnotationsMixin<
label.appendChild(valueElement);
parent.appendChild(label);

for (let i = 0, count = properties.length; i < count; ++i) {
const property = properties[i];
for (let i = 0, count = allProperties.length; i < count; ++i) {
const property = allProperties[i];
const value = allValues[i];

const label = document.createElement("label");
label.classList.add("neuroglancer-annotation-property");
const idElement = document.createElement("span");
Expand All @@ -1886,7 +1904,6 @@ export function UserLayerWithAnnotationsMixin<
if (description !== undefined) {
label.title = description;
}
const value = annotation.properties[i];
const valueElement = document.createElement("span");
valueElement.classList.add(
"neuroglancer-annotation-property-value",
Expand Down

0 comments on commit c826934

Please sign in to comment.