Add seaborn colour palletes for tab10, paired, rocket, mako, spectral, and coolwarm

This covers three usecases: qualitative, quantitative min->max, and quantitative middle with low/high
This commit is contained in:
Dion Moult
2024-08-21 15:27:21 +10:00
parent e4a4a33920
commit e83eb68fe1
4 changed files with 150 additions and 50 deletions
@@ -255,10 +255,11 @@ class ColourByProperty(Operator):
self.report({"ERROR"}, "No Query Provided")
return {"CANCELLED"}
is_qualitative = props.pallette in ("tab10", "paired")
palette = props.palette
is_qualitative = palette in ("tab10", "paired")
if is_qualitative:
colours = tool.Search.get_qualitative_pallette(props.pallette)
colours = tool.Search.get_qualitative_palette(palette)
colourscheme = {}
@@ -307,7 +308,7 @@ class ColourByProperty(Operator):
step_value = min_value + i * step_size
values.append(step_value)
colourscheme[str(step_value)] = {
"colour": tool.Search.get_quantitative_pallette("foo", step_value, min_value, max_value),
"colour": tool.Search.get_quantitative_palette(palette, step_value, min_value, max_value),
"total": 0,
}
@@ -316,7 +317,7 @@ class ColourByProperty(Operator):
if index >= len(values):
index = -1
colourscheme[str(values[index])]["total"] += 1
obj.color = (*tool.Search.get_quantitative_pallette("foo", value, min_value, max_value), 1)
obj.color = (*tool.Search.get_quantitative_palette(palette, value, min_value, max_value), 1)
if areas := [a for a in context.screen.areas if a.type == "VIEW_3D"]:
areas[0].spaces[0].shading.color_type = "OBJECT"
@@ -362,8 +363,9 @@ class SelectByProperty(Operator):
return {"CANCELLED"}
active_value = props.colourscheme[props.active_colourscheme_index].name
palette = props.palette
is_qualitative = props.pallette in ("tab10", "paired")
is_qualitative = palette in ("tab10", "paired")
if not is_qualitative:
values = []
+16 -6
View File
@@ -123,14 +123,24 @@ class BIMSearchProperties(PropertyGroup):
saved_searches: EnumProperty(items=get_saved_searches, name="Saved Searches")
saved_colourschemes: EnumProperty(items=get_saved_colourschemes, name="Saved Colourschemes")
colourscheme_query: StringProperty(name="Colourscheme Query", default="class")
pallette: EnumProperty(
palette: EnumProperty(
items=[
("tab10", "Default", "Contrasting colours to distinguish categories"),
("paired", "Paired", "Pairs of colours to distinguish categories"),
("coolwarm", "CoolWarm", "A diverging linear range from blue to red with white in the middle"),
("spectral", "Spectral", "A diverging spectral range from red to blue with white in the middle"),
("tab10", "Default (Qualitative)", "10 Contrasting colours to distinguish categories"),
("paired", "Paired (Qualitative)", "12 Contrasting colour pairs to distinguish categories"),
("rocket", "Rocket (Quantitative - Sequential)", "A sequential range from black to red to white"),
("mako", "Mako (Quantitative - Sequential)", "A sequential range from black to blue to white"),
(
"coolwarm",
"CoolWarm (Quantitative - Diverging)",
"A diverging linear range from blue to red with white in the middle",
),
(
"spectral",
"Spectral (Quantitative - Diverging)",
"A diverging spectral range from red to blue with white in the middle",
),
],
name="Pallette",
name="Palette",
)
colourscheme: CollectionProperty(type=BIMColour)
active_colourscheme_index: IntProperty(name="Active Colourscheme Index")
+1 -1
View File
@@ -86,7 +86,7 @@ class BIM_PT_colour_by_property(Panel):
row.prop(props, "colourscheme_query", text="Query")
row = self.layout.row()
row.prop(props, "pallette")
row.prop(props, "palette")
row = self.layout.row(align=True)
row.operator("bim.colour_by_property", icon="BRUSH_DATA")
+126 -38
View File
@@ -115,23 +115,37 @@ class Search(bonsai.core.tool.Search):
return '"' + value.replace('"', '\\"') + '"'
@classmethod
def get_qualitative_pallette(cls, theme: str = "tab10") -> cycle:
def get_qualitative_palette(cls, theme: str = "tab10") -> cycle:
if theme == "paired":
pass
return cycle(
[
(0.651, 0.81, 0.892, 1),
(0.121, 0.471, 0.706, 1),
(0.699, 0.876, 0.54, 1),
(0.199, 0.629, 0.174, 1),
(0.983, 0.605, 0.602, 1),
(0.89, 0.101, 0.112, 1),
(0.989, 0.751, 0.427, 1),
(0.986, 0.497, 0.1, 1),
(0.792, 0.699, 0.839, 1),
(0.414, 0.239, 0.603, 1),
(0.993, 0.999, 0.6, 1),
(0.693, 0.349, 0.157, 1),
]
)
# tab10
return cycle(
[
(0.651, 0.81, 0.892, 1),
(0.121, 0.471, 0.706, 1),
(0.699, 0.876, 0.54, 1),
(0.199, 0.629, 0.174, 1),
(0.983, 0.605, 0.602, 1),
(0.89, 0.101, 0.112, 1),
(0.989, 0.751, 0.427, 1),
(0.986, 0.497, 0.1, 1),
(0.792, 0.699, 0.839, 1),
(0.414, 0.239, 0.603, 1),
(0.993, 0.999, 0.6, 1),
(0.693, 0.349, 0.157, 1),
(0.122, 0.467, 0.706, 1),
(1.00, 0.498, 0.055, 1),
(0.173, 0.627, 0.173, 1),
(0.839, 0.153, 0.157, 1),
(0.580, 0.404, 0.741, 1),
(0.549, 0.337, 0.294, 1),
(0.890, 0.467, 0.761, 1),
(0.498, 0.498, 0.498, 1),
(0.737, 0.741, 0.133, 1),
(0.090, 0.745, 0.812, 1),
]
)
@@ -140,30 +154,104 @@ class Search(bonsai.core.tool.Search):
return tuple((1 - factor) * x + factor * y for x, y in zip(c1, c2))
@classmethod
def get_quantitative_pallette(cls, theme: str, value, min_val, max_val):
palette = [
(0.227, 0.298, 0.753),
(0.282, 0.376, 0.820),
(0.345, 0.463, 0.886),
(0.412, 0.545, 0.937),
(0.482, 0.620, 0.973),
(0.553, 0.686, 0.992),
(0.616, 0.741, 0.996),
(0.686, 0.792, 0.984),
(0.753, 0.827, 0.961),
(0.812, 0.851, 0.918),
(0.865, 0.863, 0.863),
(0.910, 0.835, 0.792),
(0.945, 0.792, 0.714),
(0.965, 0.737, 0.635),
(0.965, 0.671, 0.553),
(0.957, 0.604, 0.482),
(0.929, 0.518, 0.404),
(0.890, 0.424, 0.329),
(0.839, 0.322, 0.263),
(0.773, 0.196, 0.200),
(0.702, 0.012, 0.149),
]
def get_quantitative_palette(cls, theme: str, value, min_val, max_val):
if theme == "coolwarm":
palette = [
(0.227, 0.298, 0.753),
(0.282, 0.376, 0.820),
(0.345, 0.463, 0.886),
(0.412, 0.545, 0.937),
(0.482, 0.620, 0.973),
(0.553, 0.686, 0.992),
(0.616, 0.741, 0.996),
(0.686, 0.792, 0.984),
(0.753, 0.827, 0.961),
(0.812, 0.851, 0.918),
(0.865, 0.863, 0.863),
(0.910, 0.835, 0.792),
(0.945, 0.792, 0.714),
(0.965, 0.737, 0.635),
(0.965, 0.671, 0.553),
(0.957, 0.604, 0.482),
(0.929, 0.518, 0.404),
(0.890, 0.424, 0.329),
(0.839, 0.322, 0.263),
(0.773, 0.196, 0.200),
(0.702, 0.012, 0.149),
]
elif theme == "spectral":
palette = [
(0.620, 0.004, 0.259),
(0.718, 0.114, 0.282),
(0.827, 0.235, 0.306),
(0.894, 0.333, 0.286),
(0.957, 0.427, 0.263),
(0.973, 0.557, 0.322),
(0.988, 0.675, 0.376),
(0.992, 0.776, 0.459),
(0.996, 0.878, 0.545),
(0.996, 0.937, 0.647),
(0.996, 0.996, 0.743),
(0.949, 0.980, 0.671),
(0.902, 0.961, 0.596),
(0.780, 0.910, 0.620),
(0.663, 0.863, 0.643),
(0.537, 0.812, 0.643),
(0.400, 0.761, 0.647),
(0.294, 0.643, 0.694),
(0.196, 0.525, 0.737),
(0.286, 0.412, 0.682),
(0.369, 0.310, 0.635),
]
elif theme == "rocket":
palette = [
(0.008, 0.016, 0.098),
(0.071, 0.047, 0.145),
(0.145, 0.078, 0.196),
(0.220, 0.098, 0.247),
(0.298, 0.110, 0.290),
(0.380, 0.118, 0.322),
(0.455, 0.118, 0.345),
(0.541, 0.114, 0.357),
(0.631, 0.098, 0.353),
(0.714, 0.086, 0.341),
(0.792, 0.100, 0.310),
(0.855, 0.161, 0.275),
(0.906, 0.243, 0.243),
(0.937, 0.341, 0.251),
(0.949, 0.439, 0.302),
(0.957, 0.525, 0.369),
(0.961, 0.612, 0.451),
(0.965, 0.694, 0.545),
(0.965, 0.773, 0.647),
(0.973, 0.847, 0.761),
(0.980, 0.918, 0.863),
]
elif theme == "mako":
palette = [
(0.043, 0.012, 0.020),
(0.090, 0.047, 0.086),
(0.141, 0.086, 0.161),
(0.184, 0.122, 0.243),
(0.220, 0.165, 0.329),
(0.243, 0.204, 0.420),
(0.251, 0.247, 0.502),
(0.243, 0.302, 0.573),
(0.224, 0.365, 0.608),
(0.208, 0.424, 0.624),
(0.204, 0.476, 0.635),
(0.204, 0.533, 0.647),
(0.204, 0.588, 0.663),
(0.212, 0.647, 0.671),
(0.239, 0.702, 0.675),
(0.286, 0.757, 0.678),
(0.373, 0.808, 0.675),
(0.522, 0.847, 0.690),
(0.659, 0.882, 0.741),
(0.773, 0.922, 0.816),
(0.871, 0.957, 0.894),
]
if value < min_val:
value = min_val