Adapt heatmap layer to be used with a colormap control#1036
Adapt heatmap layer to be used with a colormap control#1036HaudinFlorence wants to merge 13 commits intojupyter-widgets:masterfrom
Conversation
97a77e7 to
0a396c7
Compare
davidbrochart
left a comment
There was a problem hiding this comment.
Looks like you should rebase (79e7d94 is already in master).
ipyleaflet/leaflet.py
Outdated
| colors = ['blue', 'cyan', 'lime', 'yellow', 'red'] | ||
| values = [0.4, 0.6, 0.7, 0.8, 1.0] |
There was a problem hiding this comment.
You might want to use traits for these, otherwise they are not configurable.
There was a problem hiding this comment.
Thanks a lot for the review @davidbrochart. Logics of the attributes has been changed a little bit in 93fa3c4, but the choice of the values and colors are configurable using gradient, as shown in the the example notebook Heatmap_with_colormap.
ipyleaflet/leaflet.py
Outdated
| dict = {} | ||
| for i in range(len(values)): | ||
| dict[values[i]] = colors[i] | ||
| vmin = values[0] | ||
| vmax = values[len(values) - 1] | ||
| gradient = Dict(dict).tag(sync=True, o=True) | ||
| colormap = LinearColormap(colors, vmin=vmin, vmax=vmax) |
There was a problem hiding this comment.
vmin, vmax, gradient and colormap should be computed when values or colors change.
…vmax and colormap from gradient data (values and colors).
0a396c7 to
93fa3c4
Compare
This has been fixed. |
ipyleaflet/leaflet.py
Outdated
| colors = list(self.gradient.values()) | ||
| self.vmin = values[0] | ||
| self.vmax = values[len(values) - 1] | ||
| self.colormap = LinearColormap(colors, vmin=self.vmin, vmax=self.vmax) |
There was a problem hiding this comment.
With the way gradient is defined, is it really a linear color map?
Update docstrings Co-authored-by: David Brochart <david.brochart@gmail.com>
Co-authored-by: David Brochart <david.brochart@gmail.com>
…ar colormap with custom boundary colors and values.
ipyleaflet/leaflet.py
Outdated
| self.vmin = values[0] | ||
| self.vmax = values[-1] |
There was a problem hiding this comment.
I think we need to sort the gradient by value first.
There was a problem hiding this comment.
Sorry. I am not sure to understand.
There was a problem hiding this comment.
gradient is a dict of "value:color" entries. I don't think we can expect the first entry to have the minimum value and the last entry to have the maximum value.
There was a problem hiding this comment.
Thanks for pointing this out. The name values was indeed not a good choice, since it actually refers to the key of the gradient dict. New naming colormap_labels is proposed in 27acdac
There was a problem hiding this comment.
I meant that we need to sort the colormap_labels. What happens to vmin and vmax if gradient = {1.0: 'red', 0.6: 'cyan', 0.7: 'lime', 0.8: 'yellow', 0.4: 'blue'}?
There was a problem hiding this comment.
I meant that we need to sort the
colormap_labels. What happens tovminandvmaxifgradient = {1.0: 'red', 0.6: 'cyan', 0.7: 'lime', 0.8: 'yellow', 0.4: 'blue'}?
You're right. Branca colormap requires that the colormaps_labels are sorted. This point has been solved in commit 373f5d9
The example notebook has also been modified for a case where the gradient is initially not sorted.
Co-authored-by: David Brochart <david.brochart@gmail.com>

Adapt heatmap layer for an easier use with a colormap control. The colormap is defined from the color gradient defined in Heatmap class

.