Skip to content

Commit

Permalink
Update and make the annotation schema more uniform.
Browse files Browse the repository at this point in the history
  • Loading branch information
manthey committed Jan 24, 2022
1 parent d71c256 commit dc6175c
Showing 1 changed file with 68 additions and 56 deletions.
124 changes: 68 additions & 56 deletions girder_annotation/girder_large_image_annotation/models/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ class AnnotationSchema:
},
'fontSize': {
'type': 'number',
'minimum': 0,
'exclusiveMinimum': True,
'exclusiveMinimum': 0,
},
'color': colorSchema,
},
Expand All @@ -121,9 +120,7 @@ class AnnotationSchema:

groupSchema = {'type': 'string'}

baseShapeSchema = {
'$schema': 'http://json-schema.org/schema#',
'id': '/girder/plugins/large_image/models/base_shape',
baseElementSchema = {
'type': 'object',
'properties': {
'id': {
Expand All @@ -134,19 +131,38 @@ class AnnotationSchema:
# schema free field for users to extend annotations
'user': userSchema,
'label': labelSchema,
'lineColor': colorSchema,
'lineWidth': {
'type': 'number',
'minimum': 0
},
'group': groupSchema
},
'required': ['type'],
'additionalProperties': True
}
baseElementPatternProperties = {
'^%s$' % propertyName: {}
for propertyName in baseElementSchema['properties']
if propertyName != 'type'
}
baseShapeSchema = {
'type': 'object',
'allOf': [
baseElementSchema,
{
'properties': {
'lineColor': colorSchema,
'lineWidth': {
'type': 'number',
'minimum': 0
},
},
},
],
'required': ['type'],
'additionalProperties': True
}
baseShapePatternProperties = {
'^%s$' % propertyName: {}
for propertyName in baseShapeSchema['properties']
for part in [
part['properties'] for part in baseShapeSchema['allOf']
] for propertyName in part
if propertyName != 'type'
}

Expand Down Expand Up @@ -348,7 +364,7 @@ class AnnotationSchema:

heatmapSchema = {
'allOf': [
baseShapeSchema,
baseElementSchema,
{
'type': 'object',
'properties': {
Expand All @@ -362,8 +378,7 @@ class AnnotationSchema:
},
'radius': {
'type': 'number',
'minimum': 0,
'exclusiveMinimum': True,
'exclusiveMinimum': 0,
},
'colorRange': colorRangeSchema,
'rangeValues': rangeValueSchema,
Expand All @@ -388,7 +403,7 @@ class AnnotationSchema:

griddataSchema = {
'allOf': [
baseShapeSchema,
baseElementSchema,
{
'type': 'object',
'properties': {
Expand Down Expand Up @@ -423,8 +438,7 @@ class AnnotationSchema:
},
'radius': {
'type': 'number',
'minimum': 0,
'exclusiveMinimum': True,
'exclusiveMinimum': 0,
'description': 'radius used for heatmap interpretation',
},
'colorRange': colorRangeSchema,
Expand Down Expand Up @@ -468,53 +482,52 @@ class AnnotationSchema:
}

overlaySchema = {
'$schema': 'http://json-schema.org/schema#',
'type': 'object',
'properties': {
'type': {
'type': 'string',
'enum': ['imageoverlay']
},
'girderId': {
'type': 'string',
'pattern': '^[0-9a-f]{24}$',
'description': 'Girder item ID containing the image to '
'overlay.'
},
'opacity': {
'type': 'number',
'minimum': 0,
'maximum': 1,
'description': 'Default opacity for this image overlay. Must '
'be between 0 and 1. Defaults to 1.'
},
'transform': {
'allOf': [
baseElementSchema,
{
'type': 'object',
'description': 'Specification for an affine transform of the '
'image overlay. Includes a 2D transform matrix, '
'an X offset and a Y offset.',
'properties': {
'xoffset': {
'type': 'number'
'type': {
'type': 'string',
'enum': ['imageoverlay']
},
'girderId': {
'type': 'string',
'pattern': '^[0-9a-f]{24}$',
'description': 'Girder item ID containing the image to '
'overlay.'
},
'yoffset': {
'type': 'number'
'opacity': {
'type': 'number',
'minimum': 0,
'maximum': 1,
'description': 'Default opacity for this image overlay. Must '
'be between 0 and 1. Defaults to 1.'
},
'matrix': transformArray
'transform': {
'type': 'object',
'description': 'Specification for an affine transform of the '
'image overlay. Includes a 2D transform matrix, '
'an X offset and a Y offset.',
'properties': {
'xoffset': {
'type': 'number'
},
'yoffset': {
'type': 'number'
},
'matrix': transformArray
},
}
},
'required': ['girderId', 'type'],
'additionalProperties': False,
'description': 'An image overlay on top of the base resource.',
},
'user': userSchema,
'label': labelSchema,
'group': groupSchema,
},
'required': ['girderId', 'type'],
'additionalProperties': True,
'description': 'An image to overlay onto another like an '
'annotation.'
],
}

annotationElementSchema = {
'$schema': 'http://json-schema.org/schema#',
# Shape subtypes are mutually exclusive, so for efficiency, don't use
# 'oneOf'
'anyOf': [
Expand All @@ -536,7 +549,6 @@ class AnnotationSchema:

annotationSchema = {
'$schema': 'http://json-schema.org/schema#',
'id': '/girder/plugins/large_image/models/annotation',
'type': 'object',
'properties': {
'name': {
Expand Down

0 comments on commit dc6175c

Please sign in to comment.