Skip to content

Commit ab80da4

Browse files
committed
DataArrayModel : create a new LinearGradient object only when max and min values are changed (i.e. in reset_minmax() method)
1 parent fe6635d commit ab80da4

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

larray_editor/arraymodel.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,11 +284,14 @@ def reset_minmax(self):
284284
if self.vmax == self.vmin:
285285
self.vmin -= 1
286286
self.bgcolor_enabled = True
287+
self.bg_gradient = LinearGradient([(self.vmin, self.hsv_min), (self.vmax, self.hsv_max)])
288+
287289
# ValueError for empty arrays
288290
except (TypeError, ValueError):
289291
self.vmin = None
290292
self.vmax = None
291293
self.bgcolor_enabled = False
294+
self.bg_gradient = None
292295

293296
def set_format(self, format):
294297
"""Change display format"""
@@ -343,10 +346,8 @@ def data(self, index, role=Qt.DisplayRole):
343346
return to_qvariant(self._format % value)
344347
elif role == Qt.BackgroundColorRole:
345348
if self.bgcolor_enabled and value is not np.ma.masked:
346-
if self.bg_gradient is None:
347-
color_val = float(self.color_func(value))
348-
bg_gradient = LinearGradient([(self.vmin, self.hsv_min), (self.vmax, self.hsv_max)])
349-
return bg_gradient[color_val]
349+
if self.bg_value is None:
350+
return self.bg_gradient[float(self.color_func(value))]
350351
else:
351352
bg_value = self.bg_value
352353
x, y = index.row(), index.column()

0 commit comments

Comments
 (0)