From b3b750462ae414d10fff957d3c3500b98889af11 Mon Sep 17 00:00:00 2001
From: David Manthey <david.manthey@kitware.com>
Date: Fri, 19 Nov 2021 10:58:22 -0500
Subject: [PATCH] Have appropriate default properties when emitting centroids.

This fixes a bug when emitting annotations where centroids are used for
rendering and the annotation element doesn't specify color.
---
 CHANGELOG.md                                           |  3 +++
 .../girder_large_image_annotation/models/annotation.py |  2 +-
 .../models/annotationelement.py                        | 10 +++++++++-
 3 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 95ff3e43c..3315251a2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,9 @@
 - On Girder with read-only assetstores, return results even if caching fails ([#684](../../pull/684))
 - Handle geospatial files with no explicit projection ([#686](../../pull/686))
 
+### Bug Fixes
+- Fix default properties on annotations when emitted as centroids ([#687](../../pull/687))
+
 ## Version 1.8.6
 
 ### Bug Fixes
diff --git a/girder_annotation/girder_large_image_annotation/models/annotation.py b/girder_annotation/girder_large_image_annotation/models/annotation.py
index 4e0640f2d..8534a7b30 100644
--- a/girder_annotation/girder_large_image_annotation/models/annotation.py
+++ b/girder_annotation/girder_large_image_annotation/models/annotation.py
@@ -919,7 +919,7 @@ def _similarElementStructure(self, a, b, parentKey=None):  # noqa
                         return False
         elif isinstance(a, list):
             if len(a) != len(b):
-                if parentKey not in {'points', 'values'} or len(a) < 3 or len(b) < 3:
+                if parentKey not in {'points', 'values'} or len(a) < 2 or len(b) < 2:
                     return False
                 # If this is an array of points, let it pass
                 for idx in range(len(b)):
diff --git a/girder_annotation/girder_large_image_annotation/models/annotationelement.py b/girder_annotation/girder_large_image_annotation/models/annotationelement.py
index 6a7d65041..bc73c3dee 100644
--- a/girder_annotation/girder_large_image_annotation/models/annotationelement.py
+++ b/girder_annotation/girder_large_image_annotation/models/annotationelement.py
@@ -221,6 +221,12 @@ def yieldElements(self, annotation, region=None, info=None):  # noqa
                 'bbox': True}
             proplist = []
             propskeys = ['type', 'fillColor', 'lineColor', 'lineWidth', 'closed']
+            # This should match the javascript
+            defaultProps = {
+                'fillColor': 'rgba(0,0,0,0)',
+                'lineColor': 'rgb(0,0,0)',
+                'lineWidth': 2,
+            }
             for key in propskeys:
                 fields['element.%s' % key] = True
             props = {}
@@ -249,7 +255,9 @@ def yieldElements(self, annotation, region=None, info=None):  # noqa
                 bbox = entry.get('bbox')
                 if not bbox or 'lowx' not in bbox or 'size' not in bbox:
                     continue
-                prop = tuple(element.get(key) for key in propskeys)
+                prop = tuple(
+                    element.get(key, defaultProps.get(key)) for key in propskeys
+                    if element.get(key, defaultProps.get(key)) is not None)
                 if prop not in props:
                     props[prop] = len(props)
                     proplist.append(list(prop))