Skip to content

Commit

Permalink
Merge pull request #1080 from girder/speed-up-color-validation
Browse files Browse the repository at this point in the history
Speed up validating color values
  • Loading branch information
manthey authored Mar 10, 2023
2 parents 0016e08 + 409bdd8 commit c8f1332
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
9 changes: 4 additions & 5 deletions girder_annotation/docs/annotations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -387,11 +387,10 @@ Component Values
Colors
~~~~~~

Colors are specified using a css-like string. Specifically, values of
the form ``#RRGGBB`` and ``#RGB`` are allowed where ``R``, ``G``, and
``B`` are case-insensitive hexadecimal digits. Additionally, values of
the form ``rgb(123, 123, 123)`` and ``rgba(123, 123, 123, 0.123)`` are
allowed, where the colors are specified on a [0-255] integer scale, and
Colors are specified using a css-like string. Specifically, values of the form ``#RRGGBB``, ``#RGB``, ``#RRGGBBAA``, and ``#RGBA`` are allowed where ``R``,
``G``, ``B``, and ``A`` are case-insensitive hexadecimal digits. Additionally,
values of the form ``rgb(123, 123, 123)`` and ``rgba(123, 123, 123, 0.123)``
are allowed, where the colors are specified on a [0-255] integer scale, and
the opacity is specified as a [0-1] floating-point number.

Coordinates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,17 @@ class AnnotationSchema:
colorSchema = {
'type': 'string',
# We accept colors of the form
# #aabbcc six digit RRGGBB hex
# #abc three digit RGB hex
# #rrggbb six digit RRGGBB hex
# #rgb three digit RGB hex
# #rrggbbaa eight digit RRGGBBAA hex
# #rgba four digit RGBA hex
# rgb(255, 255, 255) rgb decimal triplet
# rgba(255, 255, 255, 1) rgba quad with RGB in the range [0-255] and
# alpha [0-1]
# TODO: make rgb and rgba spec validate that rgb is [0-255] and a is
# [0-1], rather than just checking if they are digits and such.
'pattern': r'^(#[0-9a-fA-F]{3,6}|rgb\(\d+,\s*\d+,\s*\d+\)|'
'pattern': r'^(#([0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})|'
r'rgb\(\d+,\s*\d+,\s*\d+\)|'
r'rgba\(\d+,\s*\d+,\s*\d+,\s*(\d?\.|)\d+\))$',
}

Expand Down Expand Up @@ -1009,7 +1012,7 @@ def _similarElementStructure(self, a, b, parentKey=None): # noqa
if k == 'id':
if not isinstance(b[k], str) or not self.idRegex.match(b[k]):
return False
elif parentKey == 'user':
elif parentKey in {'user'} or k in {'fillColor', 'lineColor'}:
continue
elif parentKey != 'label' or k != 'value':
if not self._similarElementStructure(a[k], b[k], k):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ var GeojsImageViewerWidgetExtension = function (viewer) {
_addPixelmapLayerParams(layerParams, pixelmapElement, levelDifference) {
// For pixelmap overlays, there are additional parameters to set
layerParams.keepLower = false;
if (typeof layerParams.url === 'function' || levelDifference) {
if (_.isFunction(layerParams.url) || levelDifference) {
layerParams.url = (x, y, z) => 'api/v1/item/' + pixelmapElement.girderId + `/tiles/zxy/${z - levelDifference}/${x}/${y}?encoding=PNG`;
} else {
layerParams.url = layerParams.url + '?encoding=PNG';
Expand Down

0 comments on commit c8f1332

Please sign in to comment.