Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up validating color values #1080

Merged
merged 1 commit into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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