Generate an HTML representation of the Colormap.
(self)
| 1036 | return png_bytes.getvalue() |
| 1037 | |
| 1038 | def _repr_html_(self): |
| 1039 | """Generate an HTML representation of the Colormap.""" |
| 1040 | png_bytes = self._repr_png_() |
| 1041 | png_base64 = base64.b64encode(png_bytes).decode('ascii') |
| 1042 | def color_block(color): |
| 1043 | hex_color = to_hex(color, keep_alpha=True) |
| 1044 | return (f'<div title="{hex_color}" ' |
| 1045 | 'style="display: inline-block; ' |
| 1046 | 'width: 1em; height: 1em; ' |
| 1047 | 'margin: 0; ' |
| 1048 | 'vertical-align: middle; ' |
| 1049 | 'border: 1px solid #555; ' |
| 1050 | f'background-color: {hex_color};"></div>') |
| 1051 | |
| 1052 | return ('<div style="vertical-align: middle;">' |
| 1053 | f'<strong>{self.name}</strong> ' |
| 1054 | '</div>' |
| 1055 | '<div class="cmap"><img ' |
| 1056 | f'alt="{self.name} colormap" ' |
| 1057 | f'title="{self.name}" ' |
| 1058 | 'style="border: 1px solid #555;" ' |
| 1059 | f'src="data:image/png;base64,{png_base64}"></div>' |
| 1060 | '<div style="vertical-align: middle; ' |
| 1061 | f'max-width: {_REPR_PNG_SIZE[0]+2}px; ' |
| 1062 | 'display: flex; justify-content: space-between;">' |
| 1063 | '<div style="float: left;">' |
| 1064 | f'{color_block(self.get_under())} under' |
| 1065 | '</div>' |
| 1066 | '<div style="margin: 0 auto; display: inline-block;">' |
| 1067 | f'bad {color_block(self.get_bad())}' |
| 1068 | '</div>' |
| 1069 | '<div style="float: right;">' |
| 1070 | f'over {color_block(self.get_over())}' |
| 1071 | '</div>' |
| 1072 | '</div>') |
| 1073 | |
| 1074 | def copy(self): |
| 1075 | """Return a copy of the colormap.""" |
no test coverage detected