Skip to content

Commit dd2617d

Browse files
committed
Allow some color control too
1 parent f10f12a commit dd2617d

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

scripts/tools/file_size_from_nm.py

+25-1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,15 @@
7070
}
7171

7272

73+
# Scales from https://plotly.com/python/builtin-colorscales/
74+
__COLOR_SCALES__ = {
75+
"none": None,
76+
"tempo": px.colors.sequential.tempo,
77+
"blues": px.colors.sequential.Blues,
78+
"plasma": px.colors.sequential.Plasma_r,
79+
}
80+
81+
7382
class FetchStyle(Enum):
7483
NM = auto()
7584
OBJDUMP = auto()
@@ -358,6 +367,7 @@ def build_treemap(
358367
symbols: list[Symbol],
359368
separator: str,
360369
figure_generator: Callable,
370+
color: Optional[list[str]],
361371
max_depth: int,
362372
zoom: Optional[str],
363373
strip: Optional[str],
@@ -459,13 +469,19 @@ def build_treemap(
459469

460470
data["name_with_size"][idx] = f"{short_name}: {data["size"][idx]}"
461471

472+
extra_args = {}
473+
if color is not None:
474+
extra_args['color_continuous_scale'] = color
475+
extra_args['color'] = "size"
476+
462477
fig = figure_generator(
463478
data,
464479
names="name_with_size",
465480
ids="name",
466481
parents="parent",
467482
values="size",
468483
maxdepth=max_depth,
484+
**extra_args,
469485
)
470486

471487
fig.update_traces(
@@ -771,6 +787,13 @@ def compute_symbol_diff(orig: list[Symbol], base: list[Symbol]) -> list[Symbol]:
771787
type=click.Choice(list(__CHART_STYLES__.keys()), case_sensitive=False),
772788
help="Style of the chart",
773789
)
790+
@click.option(
791+
"--color",
792+
default="None",
793+
show_default=True,
794+
type=click.Choice(list(__COLOR_SCALES__.keys()), case_sensitive=False),
795+
help="Color display (if any)",
796+
)
774797
@click.option(
775798
"--fetch-via",
776799
default="nm",
@@ -806,6 +829,7 @@ def main(
806829
log_level,
807830
elf_file: str,
808831
display_type: str,
832+
color: str,
809833
fetch_via: str,
810834
max_depth: int,
811835
zoom: Optional[str],
@@ -824,7 +848,7 @@ def main(
824848
title = f"{elf_file} COMPARED TO {diff}"
825849

826850
build_treemap(
827-
title, symbols, separator, __CHART_STYLES__[display_type], max_depth, zoom, strip
851+
title, symbols, separator, __CHART_STYLES__[display_type], __COLOR_SCALES__[color], max_depth, zoom, strip
828852
)
829853

830854

0 commit comments

Comments
 (0)