Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
update color pt3
Browse files
utils.py
CHANGED
|
@@ -68,7 +68,7 @@ def _build_palette():
|
|
| 68 |
palette.append('#' + b + g + r)
|
| 69 |
return palette # 24 colors
|
| 70 |
|
| 71 |
-
_PALETTE = _build_palette()
|
| 72 |
|
| 73 |
|
| 74 |
def colorsCSS(n, startingHue=None, pool=None):
|
|
@@ -331,21 +331,39 @@ def build_fig_pie2(df4, speakerNames, speakerColors, catColors, get_display_name
|
|
| 331 |
return fig
|
| 332 |
|
| 333 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 334 |
def build_fig_sunburst(df5, catTypeColors, speakerColors, get_display_name_fn, currFile):
|
| 335 |
"""Sunburst voice-category chart."""
|
| 336 |
df5 = df5.copy()
|
| 337 |
df5["labels"] = df5["labels"].apply(lambda s: get_display_name_fn(s, currFile))
|
| 338 |
df5["parentNames"] = df5["parentNames"].apply(lambda s: get_display_name_fn(s, currFile))
|
| 339 |
|
| 340 |
-
|
| 341 |
-
# regardless of encounter order. color_discrete_sequence is position-based
|
| 342 |
-
# and can silently drop nodes when label count exceeds sequence length.
|
| 343 |
-
top_labels = ["No Voice", "Single Voice", "Multi Voice"]
|
| 344 |
-
speaker_labels = [l for l in df5["labels"] if l not in top_labels]
|
| 345 |
-
color_map = {lbl: catTypeColors[i % len(catTypeColors)]
|
| 346 |
-
for i, lbl in enumerate(top_labels)}
|
| 347 |
-
for i, lbl in enumerate(speaker_labels):
|
| 348 |
-
color_map[lbl] = speakerColors[i % len(speakerColors)]
|
| 349 |
|
| 350 |
fig = px.sunburst(
|
| 351 |
df5,
|
|
@@ -374,14 +392,7 @@ def build_fig_treemap(df5, catTypeColors, speakerColors, get_display_name_fn, cu
|
|
| 374 |
df5["labels"] = df5["labels"].apply(lambda s: get_display_name_fn(s, currFile))
|
| 375 |
df5["parentNames"] = df5["parentNames"].apply(lambda s: get_display_name_fn(s, currFile))
|
| 376 |
|
| 377 |
-
|
| 378 |
-
# position-based color_discrete_sequence running out of colors.
|
| 379 |
-
top_labels = ["No Voice", "Single Voice", "Multi Voice"]
|
| 380 |
-
speaker_labels = [l for l in df5["labels"] if l not in top_labels]
|
| 381 |
-
color_map = {lbl: catTypeColors[i % len(catTypeColors)]
|
| 382 |
-
for i, lbl in enumerate(top_labels)}
|
| 383 |
-
for i, lbl in enumerate(speaker_labels):
|
| 384 |
-
color_map[lbl] = speakerColors[i % len(speakerColors)]
|
| 385 |
|
| 386 |
fig = px.treemap(
|
| 387 |
df5,
|
|
|
|
| 68 |
palette.append('#' + b + g + r)
|
| 69 |
return palette # 24 colors
|
| 70 |
|
| 71 |
+
_PALETTE = _build_palette() + ["#999DA0"] # index 24: grey for No Voice
|
| 72 |
|
| 73 |
|
| 74 |
def colorsCSS(n, startingHue=None, pool=None):
|
|
|
|
| 331 |
return fig
|
| 332 |
|
| 333 |
|
| 334 |
+
def _voice_color_map(df5_labels, speakerColors):
|
| 335 |
+
"""Build the label->color map for sunburst/treemap charts.
|
| 336 |
+
|
| 337 |
+
Single Voice → palette index 0 (always)
|
| 338 |
+
Multi Voice → palette index 4 (always)
|
| 339 |
+
No Voice → palette index 8 (neutral, always)
|
| 340 |
+
Speakers → cycle through every index EXCEPT 0 and 4 so they never
|
| 341 |
+
blend into their parent category layer.
|
| 342 |
+
"""
|
| 343 |
+
reserved = {0, 4}
|
| 344 |
+
speaker_indices = [i for i in range(24) if i not in reserved] # exclude grey index
|
| 345 |
+
|
| 346 |
+
top_labels = ["No Voice", "Single Voice", "Multi Voice"]
|
| 347 |
+
color_map = {
|
| 348 |
+
"Single Voice": _PALETTE[0],
|
| 349 |
+
"Multi Voice": _PALETTE[4],
|
| 350 |
+
"No Voice": _PALETTE[24], # grey
|
| 351 |
+
}
|
| 352 |
+
speaker_labels = [l for l in df5_labels if l not in top_labels]
|
| 353 |
+
for i, lbl in enumerate(speaker_labels):
|
| 354 |
+
color_map[lbl] = speaker_indices[i % len(speaker_indices)]
|
| 355 |
+
# speaker_indices contains palette indices; convert to hex
|
| 356 |
+
color_map[lbl] = _PALETTE[speaker_indices[i % len(speaker_indices)]]
|
| 357 |
+
return color_map
|
| 358 |
+
|
| 359 |
+
|
| 360 |
def build_fig_sunburst(df5, catTypeColors, speakerColors, get_display_name_fn, currFile):
|
| 361 |
"""Sunburst voice-category chart."""
|
| 362 |
df5 = df5.copy()
|
| 363 |
df5["labels"] = df5["labels"].apply(lambda s: get_display_name_fn(s, currFile))
|
| 364 |
df5["parentNames"] = df5["parentNames"].apply(lambda s: get_display_name_fn(s, currFile))
|
| 365 |
|
| 366 |
+
color_map = _voice_color_map(df5["labels"], speakerColors)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 367 |
|
| 368 |
fig = px.sunburst(
|
| 369 |
df5,
|
|
|
|
| 392 |
df5["labels"] = df5["labels"].apply(lambda s: get_display_name_fn(s, currFile))
|
| 393 |
df5["parentNames"] = df5["parentNames"].apply(lambda s: get_display_name_fn(s, currFile))
|
| 394 |
|
| 395 |
+
color_map = _voice_color_map(df5["labels"], speakerColors)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 396 |
|
| 397 |
fig = px.treemap(
|
| 398 |
df5,
|