3636
3737SCRIPT_NAME = "gitHistoryCharts"
3838
39+
40+ # ── Plotly serialization ──────────────────────────────────────────────────────
41+
42+ def plotly_values (data : pd .Series | pd .DataFrame ) -> list :
43+ """Returns pandas column(s) as a plain Python list for Plotly/orjson serialization."""
44+ return data .to_numpy ().tolist ()
45+
3946# ── Plotly layout constants ───────────────────────────────────────────────────
4047
4148PLOTLY_MAIN_LAYOUT_BASE_SETTINGS : dict [str , Any ] = dict (
@@ -337,11 +344,11 @@ def prepare_directory_commit_statistics(commit_statistics_data: pd.DataFrame) ->
337344
338345def create_treemap_commit_statistics_settings (data_frame : pd .DataFrame ) -> plotly_graph_objects .Treemap :
339346 """Creates a Plotly Treemap with the given settings and data frame."""
340- return plotly_graph_objects . Treemap (
341- labels = data_frame ["directoryName" ],
342- parents = data_frame ["directoryParentPath" ],
343- ids = data_frame ["directoryPath" ],
344- customdata = data_frame [
347+ params = dict (
348+ labels = plotly_values ( data_frame ["directoryName" ]) ,
349+ parents = plotly_values ( data_frame ["directoryParentPath" ]) ,
350+ ids = plotly_values ( data_frame ["directoryPath" ]) ,
351+ customdata = plotly_values ( data_frame [
345352 [
346353 "fileCount" ,
347354 "mostFrequentFileExtension" ,
@@ -357,7 +364,7 @@ def create_treemap_commit_statistics_settings(data_frame: pd.DataFrame) -> plotl
357364 "daysSinceLastModification" ,
358365 "directoryPath" ,
359366 ]
360- ],
367+ ]) ,
361368 hovertemplate = (
362369 "<b>%{label}</b><br>"
363370 "Files: %{customdata[0]} (%{customdata[1]})<br>"
@@ -372,20 +379,21 @@ def create_treemap_commit_statistics_settings(data_frame: pd.DataFrame) -> plotl
372379 root_color = "lightgrey" ,
373380 marker = dict (** PLOTLY_TREEMAP_MARKER_BASE_STYLE ),
374381 )
382+ return plotly_graph_objects .Treemap (** params )
375383
376384
377385def create_rank_colorbar_for_graph_objects_treemap_marker (data_frame : pd .DataFrame , name_column : str , rank_column : str ) -> dict :
378386 """Creates a plotly graph_objects.Treemap marker object for a colorbar representing ranked names."""
379387 inverse_ranked = data_frame [rank_column ].max () + 1 - data_frame [rank_column ]
380388 return dict (
381389 cornerradius = 5 ,
382- colors = inverse_ranked ,
390+ colors = plotly_values ( inverse_ranked ) ,
383391 colorscale = plotly_colors .qualitative .G10 ,
384392 colorbar = dict (
385393 title = "Rank" ,
386394 tickmode = "array" ,
387- ticktext = data_frame [name_column ],
388- tickvals = inverse_ranked ,
395+ ticktext = plotly_values ( data_frame [name_column ]) ,
396+ tickvals = plotly_values ( inverse_ranked ) ,
389397 tickfont_size = 10 ,
390398 ),
391399 )
@@ -410,7 +418,7 @@ def generate_directory_commit_statistic_treemaps(
410418 # 1. Number of files per directory
411419 figure = plotly_graph_objects .Figure (plotly_graph_objects .Treemap (
412420 create_treemap_commit_statistics_settings (git_files_with_commit_statistics ),
413- values = git_files_with_commit_statistics ["fileCount" ],
421+ values = plotly_values ( git_files_with_commit_statistics ["fileCount" ]) ,
414422 ))
415423 figure .update_layout (** PLOTLY_MAIN_LAYOUT_BASE_SETTINGS , title = "Directories and their file count" )
416424 write_image_and_log (figure , report_directory , "NumberOfFilesPerDirectory" , verbose )
@@ -437,7 +445,7 @@ def generate_directory_commit_statistic_treemaps(
437445 create_treemap_commit_statistics_settings (git_commit_count_per_directory ),
438446 marker = dict (
439447 ** PLOTLY_TREEMAP_MARKER_BASE_COLORSCALE ,
440- colors = git_commit_count_per_directory ["commitCount_limited" ],
448+ colors = plotly_values ( git_commit_count_per_directory ["commitCount_limited" ]) ,
441449 colorbar = dict (title = "Commits" ),
442450 ),
443451 ))
@@ -450,7 +458,7 @@ def generate_directory_commit_statistic_treemaps(
450458 create_treemap_commit_statistics_settings (git_commit_authors_per_directory ),
451459 marker = dict (
452460 ** PLOTLY_TREEMAP_MARKER_BASE_COLORSCALE ,
453- colors = git_commit_authors_per_directory ["authorCount_limited" ],
461+ colors = plotly_values ( git_commit_authors_per_directory ["authorCount_limited" ]) ,
454462 colorbar = dict (title = "Authors" ),
455463 ),
456464 ))
@@ -459,13 +467,13 @@ def generate_directory_commit_statistic_treemaps(
459467
460468 # 5. Directories with very few different authors (low bus-factor, focus = few authors)
461469 git_commit_authors_per_directory_low_focus = add_quantile_limited_column (git_files_with_commit_statistics , "authorCount" , 0.33 )
462- author_count_top_limit = git_commit_authors_per_directory_low_focus ["authorCount_limited" ].max (). astype ( int ). astype ( str )
470+ author_count_top_limit = str ( int ( git_commit_authors_per_directory_low_focus ["authorCount_limited" ].max ()) )
463471 author_count_top_limit_label_alias = {author_count_top_limit : author_count_top_limit + " or more" }
464472 figure = plotly_graph_objects .Figure (plotly_graph_objects .Treemap (
465473 create_treemap_commit_statistics_settings (git_commit_authors_per_directory_low_focus ),
466474 marker = dict (
467475 ** PLOTLY_TREEMAP_MARKER_BASE_COLORSCALE ,
468- colors = git_commit_authors_per_directory_low_focus ["authorCount_limited" ],
476+ colors = plotly_values ( git_commit_authors_per_directory_low_focus ["authorCount_limited" ]) ,
469477 colorbar = dict (
470478 title = "Authors" ,
471479 tickmode = "auto" ,
@@ -518,7 +526,7 @@ def generate_directory_commit_statistic_treemaps(
518526 create_treemap_commit_statistics_settings (git_commit_days_since_last_commit_per_directory ),
519527 marker = dict (
520528 ** PLOTLY_TREEMAP_MARKER_BASE_COLORSCALE ,
521- colors = git_commit_days_since_last_commit_per_directory ["daysSinceLastCommit_limited" ],
529+ colors = plotly_values ( git_commit_days_since_last_commit_per_directory ["daysSinceLastCommit_limited" ]) ,
522530 colorbar = dict (title = "Days" ),
523531 ),
524532 ))
@@ -531,7 +539,7 @@ def generate_directory_commit_statistic_treemaps(
531539 create_treemap_commit_statistics_settings (git_commit_days_since_last_commit_per_directory ),
532540 marker = dict (
533541 ** PLOTLY_TREEMAP_MARKER_BASE_COLORSCALE ,
534- colors = git_commit_days_since_last_commit_per_directory ["daysSinceLastCommit_rank" ],
542+ colors = plotly_values ( git_commit_days_since_last_commit_per_directory ["daysSinceLastCommit_rank" ]) ,
535543 colorbar = dict (title = "Rank" ),
536544 ),
537545 ))
@@ -544,7 +552,7 @@ def generate_directory_commit_statistic_treemaps(
544552 create_treemap_commit_statistics_settings (git_commit_days_since_last_file_creation_per_directory ),
545553 marker = dict (
546554 ** PLOTLY_TREEMAP_MARKER_BASE_COLORSCALE ,
547- colors = git_commit_days_since_last_file_creation_per_directory ["daysSinceLastCreation_limited" ],
555+ colors = plotly_values ( git_commit_days_since_last_file_creation_per_directory ["daysSinceLastCreation_limited" ]) ,
548556 colorbar = dict (title = "Days" ),
549557 ),
550558 ))
@@ -557,7 +565,7 @@ def generate_directory_commit_statistic_treemaps(
557565 create_treemap_commit_statistics_settings (git_commit_days_since_last_file_creation_per_directory ),
558566 marker = dict (
559567 ** PLOTLY_TREEMAP_MARKER_BASE_COLORSCALE ,
560- colors = git_commit_days_since_last_file_creation_per_directory ["daysSinceLastCreation_rank" ],
568+ colors = plotly_values ( git_commit_days_since_last_file_creation_per_directory ["daysSinceLastCreation_rank" ]) ,
561569 colorbar = dict (title = "Rank" ),
562570 ),
563571 ))
@@ -570,7 +578,7 @@ def generate_directory_commit_statistic_treemaps(
570578 create_treemap_commit_statistics_settings (git_commit_days_since_last_file_modification_per_directory ),
571579 marker = dict (
572580 ** PLOTLY_TREEMAP_MARKER_BASE_COLORSCALE ,
573- colors = git_commit_days_since_last_file_modification_per_directory ["daysSinceLastModification_limited" ],
581+ colors = plotly_values ( git_commit_days_since_last_file_modification_per_directory ["daysSinceLastModification_limited" ]) ,
574582 colorbar = dict (title = "Days" ),
575583 ),
576584 ))
@@ -583,7 +591,7 @@ def generate_directory_commit_statistic_treemaps(
583591 create_treemap_commit_statistics_settings (git_commit_days_since_last_file_modification_per_directory ),
584592 marker = dict (
585593 ** PLOTLY_TREEMAP_MARKER_BASE_COLORSCALE ,
586- colors = git_commit_days_since_last_file_modification_per_directory ["daysSinceLastModification_rank" ],
594+ colors = plotly_values ( git_commit_days_since_last_file_modification_per_directory ["daysSinceLastModification_rank" ]) ,
587595 colorbar = dict (title = "Rank" ),
588596 ),
589597 ))
@@ -633,7 +641,7 @@ def generate_cochange_treemaps(
633641 create_treemap_commit_statistics_settings (data_to_display ),
634642 marker = dict (
635643 ** PLOTLY_TREEMAP_MARKER_BASE_COLORSCALE ,
636- colors = data_to_display ["pairwiseChangeCommitCount_limited" ],
644+ colors = plotly_values ( data_to_display ["pairwiseChangeCommitCount_limited" ]) ,
637645 colorbar = dict (title = "Co-Changes" ),
638646 ),
639647 ))
@@ -646,7 +654,7 @@ def generate_cochange_treemaps(
646654 create_treemap_commit_statistics_settings (data_to_display ),
647655 marker = dict (
648656 ** PLOTLY_TREEMAP_MARKER_BASE_COLORSCALE ,
649- colors = data_to_display ["pairwiseChangeMaxLift_limited" ],
657+ colors = plotly_values ( data_to_display ["pairwiseChangeMaxLift_limited" ]) ,
650658 colorbar = dict (title = "Co-Change Lift" ),
651659 ),
652660 ))
@@ -662,7 +670,7 @@ def generate_cochange_treemaps(
662670 create_treemap_commit_statistics_settings (data_to_display ),
663671 marker = dict (
664672 ** PLOTLY_TREEMAP_MARKER_BASE_COLORSCALE ,
665- colors = data_to_display ["pairwiseChangeAverageLift_limited" ],
673+ colors = plotly_values ( data_to_display ["pairwiseChangeAverageLift_limited" ]) ,
666674 colorbar = dict (title = "Co-Change Lift" ),
667675 ),
668676 ))
@@ -685,8 +693,8 @@ def generate_files_per_commit_bar_chart(
685693 print (f"{ SCRIPT_NAME } : Skipping files-per-commit bar chart — no data" )
686694 return
687695 figure = plotly_graph_objects .Figure (plotly_graph_objects .Bar (
688- x = git_file_count_per_commit ["filesPerCommit" ].head (30 ),
689- y = git_file_count_per_commit ["commitCount" ].head (30 ),
696+ x = plotly_values ( git_file_count_per_commit ["filesPerCommit" ].head (30 ) ),
697+ y = plotly_values ( git_file_count_per_commit ["commitCount" ].head (30 ) ),
690698 ))
691699 figure .update_layout (
692700 ** PLOTLY_MAIN_LAYOUT_BASE_SETTINGS ,
0 commit comments