Skip to content

Commit 73e8869

Browse files
authored
Merge pull request #371 from JohT/feature/improve-git-history-rendering
Improve git history rendering
2 parents 438991b + 97a2602 commit 73e8869

File tree

2 files changed

+107
-80
lines changed

2 files changed

+107
-80
lines changed

jupyter/GitHistoryGeneral.ipynb

+102-78
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,12 @@
5656
"# it would require to execute the notebook twice: Once including interactivity and once for static Markdown and PDF.\n",
5757
"# Therefore, command line executed notebooks (nbconvert) will contain static graphics (here using svg).\n",
5858
"def is_command_line_execution():\n",
59-
" return 'NBCONVERT' in os.environ\n",
59+
" return 'NBCONVERT_PATH' in os.environ\n",
60+
"\n",
61+
"def get_offline_path():\n",
62+
" print(\"os.path.abspath=\" + os.path.abspath(''))\n",
63+
" print(\"os.path.curdir=\" + os.path.curdir)\n",
64+
" return os.environ.get('NBCONVERT_PATH', '')\n",
6065
"\n",
6166
"default_renderer = None\n",
6267
"\n",
@@ -177,15 +182,9 @@
177182
"metadata": {},
178183
"outputs": [],
179184
"source": [
180-
"# The first part provides functions that provide basic functionality for the following parts."
181-
]
182-
},
183-
{
184-
"cell_type": "markdown",
185-
"id": "01da524e",
186-
"metadata": {},
187-
"source": [
188-
"### Treemap Layout Functions and Constants"
185+
"# --------------------------------------------------------------------------------\n",
186+
"# Shared Treemap Layout Functions and Constants\n",
187+
"# --------------------------------------------------------------------------------"
189188
]
190189
},
191190
{
@@ -208,8 +207,9 @@
208207
")\n",
209208
"plotly_treemap_figure_show_settings = dict(\n",
210209
" renderer=\"svg\" if is_command_line_execution() else None,\n",
211-
" width=1080,\n",
212-
" height=1080\n",
210+
" width=680 if is_command_line_execution() else 1080,\n",
211+
" height=680 if is_command_line_execution() else 1080,\n",
212+
" config={'scrollZoom': False, 'displaylogo': False, 'displayModeBar': False} if is_command_line_execution() else {}\n",
213213
")\n",
214214
"\n",
215215
"plotly_treemap_marker_base_style = dict(\n",
@@ -222,6 +222,27 @@
222222
")"
223223
]
224224
},
225+
{
226+
"cell_type": "code",
227+
"execution_count": null,
228+
"id": "03ee42af",
229+
"metadata": {},
230+
"outputs": [],
231+
"source": [
232+
"def get_plotly_figure_write_image_settings(name: str):\n",
233+
" \"\"\"\n",
234+
" Returns the settings for the plotly figure write_image method\n",
235+
" :param name: Name of the figure\n",
236+
" :return: Dictionary with settings for the write_image method\n",
237+
" \"\"\"\n",
238+
" return dict(\n",
239+
" file=get_offline_path() + \"/\" + name + \".svg\", \n",
240+
" format=\"svg\", \n",
241+
" width=1080, \n",
242+
" height=1080\n",
243+
" )"
244+
]
245+
},
225246
{
226247
"cell_type": "code",
227248
"execution_count": null,
@@ -280,11 +301,15 @@
280301
]
281302
},
282303
{
283-
"cell_type": "markdown",
284-
"id": "acacc415",
304+
"cell_type": "code",
305+
"execution_count": null,
306+
"id": "c37c64a4",
285307
"metadata": {},
308+
"outputs": [],
286309
"source": [
287-
"### Visualization Data Preparation Functions"
310+
"# --------------------------------------------------------------------------------\n",
311+
"# Shared Visualization Data Preparation Functions\n",
312+
"# --------------------------------------------------------------------------------"
288313
]
289314
},
290315
{
@@ -330,11 +355,15 @@
330355
]
331356
},
332357
{
333-
"cell_type": "markdown",
334-
"id": "da109679",
358+
"cell_type": "code",
359+
"execution_count": null,
360+
"id": "fb368425",
335361
"metadata": {},
362+
"outputs": [],
336363
"source": [
337-
"### File Data Preparation Functions"
364+
"# --------------------------------------------------------------------------------\n",
365+
"# Shared File Data Preparation Functions\n",
366+
"# --------------------------------------------------------------------------------"
338367
]
339368
},
340369
{
@@ -490,11 +519,15 @@
490519
]
491520
},
492521
{
493-
"cell_type": "markdown",
494-
"id": "09aeae9b",
522+
"cell_type": "code",
523+
"execution_count": null,
524+
"id": "69fc63ff",
495525
"metadata": {},
526+
"outputs": [],
496527
"source": [
497-
"### File Data Preparation "
528+
"# --------------------------------------------------------------------------------\n",
529+
"# Main File Data Preparation\n",
530+
"# --------------------------------------------------------------------------------"
498531
]
499532
},
500533
{
@@ -659,7 +692,9 @@
659692
" **plotly_treemap_layout_base_settings,\n",
660693
" title='Directories and their file count'\n",
661694
")\n",
662-
"figure.show(**plotly_treemap_figure_show_settings)"
695+
"figure.show(**plotly_treemap_figure_show_settings)\n",
696+
"if is_command_line_execution():\n",
697+
" figure.write_image(**get_plotly_figure_write_image_settings(\"NumberOfFilesPerDirectory\"))"
663698
]
664699
},
665700
{
@@ -695,7 +730,9 @@
695730
" **plotly_treemap_layout_base_settings,\n",
696731
" title='Most frequent file extension per directory'\n",
697732
")\n",
698-
"figure.show(**plotly_treemap_figure_show_settings)"
733+
"figure.show(**plotly_treemap_figure_show_settings)\n",
734+
"if is_command_line_execution():\n",
735+
" figure.write_image(**get_plotly_figure_write_image_settings(\"MostFrequentFileExtensionPerDirectory\"))"
699736
]
700737
},
701738
{
@@ -729,7 +766,9 @@
729766
" **plotly_treemap_layout_base_settings,\n",
730767
" title='Number of git commits',\n",
731768
")\n",
732-
"figure.show(**plotly_treemap_figure_show_settings)"
769+
"figure.show(**plotly_treemap_figure_show_settings)\n",
770+
"if is_command_line_execution():\n",
771+
" figure.write_image(**get_plotly_figure_write_image_settings(\"NumberOfGitCommits\"))"
733772
]
734773
},
735774
{
@@ -763,7 +802,9 @@
763802
" **plotly_treemap_layout_base_settings,\n",
764803
" title='Number of distinct commit authors',\n",
765804
")\n",
766-
"figure.show(**plotly_treemap_figure_show_settings)"
805+
"figure.show(**plotly_treemap_figure_show_settings)\n",
806+
"if is_command_line_execution():\n",
807+
" figure.write_image(**get_plotly_figure_write_image_settings(\"NumberOfDistinctCommitAuthors\"))"
767808
]
768809
},
769810
{
@@ -805,48 +846,9 @@
805846
" title='Number of distinct commit authors (red/black = only one or very few authors)',\n",
806847
")\n",
807848
"\n",
808-
"figure.show(**plotly_treemap_figure_show_settings)"
809-
]
810-
},
811-
{
812-
"cell_type": "code",
813-
"execution_count": null,
814-
"id": "e11947c5",
815-
"metadata": {},
816-
"outputs": [],
817-
"source": [
818-
"import plotly.graph_objects as go\n",
819-
"\n",
820-
"# Example data\n",
821-
"labels = [\"A\", \"B\", \"C\", \"D\", \"E\"]\n",
822-
"parents = [\"\", \"A\", \"A\", \"B\", \"B\"]\n",
823-
"values = [10, 20, 30, 40, 50] # Color scale values\n",
824-
"max_value = max(values)\n",
825-
"\n",
826-
"# Create treemap\n",
827-
"fig = go.Figure(go.Treemap(\n",
828-
" labels=labels,\n",
829-
" parents=parents,\n",
830-
" values=values,\n",
831-
" marker=dict(\n",
832-
" colors=values,\n",
833-
" colorscale=\"Blues\",\n",
834-
" colorbar=dict(\n",
835-
" title=\"Value\",\n",
836-
" tickmode=\"auto\", # Let Plotly auto-select ticks\n",
837-
" ticklabelposition=\"outside top\",\n",
838-
" tickformat=\",\", # Use default formatting\n",
839-
" ticklabeloverflow=\"allow\", # Ensure long labels are displayed\n",
840-
" ticklabelstep=1 # Show all labels\n",
841-
" )\n",
842-
" )\n",
843-
"))\n",
844-
"\n",
845-
"# Add an alias for the highest tick value dynamically\n",
846-
"fig.update_layout(coloraxis_colorbar_tickvals=[max_value])\n",
847-
"fig.update_layout(coloraxis_colorbar_ticktext=[f\"{max_value} or more\"])\n",
848-
"\n",
849-
"fig.show()\n"
849+
"figure.show(**plotly_treemap_figure_show_settings)\n",
850+
"if is_command_line_execution():\n",
851+
" figure.write_image(**get_plotly_figure_write_image_settings(\"NumberOfDistinctCommitAuthorsLowFocus\"))"
850852
]
851853
},
852854
{
@@ -882,7 +884,9 @@
882884
" **plotly_treemap_layout_base_settings,\n",
883885
" title='Main authors with highest number of commits'\n",
884886
")\n",
885-
"figure.show(**plotly_treemap_figure_show_settings)"
887+
"figure.show(**plotly_treemap_figure_show_settings)\n",
888+
"if is_command_line_execution():\n",
889+
" figure.write_image(**get_plotly_figure_write_image_settings(\"MainAuthorsWithHighestNumberOfCommits\"))"
886890
]
887891
},
888892
{
@@ -919,7 +923,9 @@
919923
" **plotly_treemap_layout_base_settings,\n",
920924
" title='Second author with the second highest number of commits'\n",
921925
")\n",
922-
"figure.show(**plotly_treemap_figure_show_settings)"
926+
"figure.show(**plotly_treemap_figure_show_settings)\n",
927+
"if is_command_line_execution():\n",
928+
" figure.write_image(**get_plotly_figure_write_image_settings(\"SecondAuthorWithTheSecondHighestNumberOfCommits\"))"
923929
]
924930
},
925931
{
@@ -954,7 +960,9 @@
954960
" **plotly_treemap_layout_base_settings,\n",
955961
" title='Days since last commit',\n",
956962
")\n",
957-
"figure.show(**plotly_treemap_figure_show_settings)"
963+
"figure.show(**plotly_treemap_figure_show_settings)\n",
964+
"if is_command_line_execution():\n",
965+
" figure.write_image(**get_plotly_figure_write_image_settings(\"DaysSinceLastCommit\"))"
958966
]
959967
},
960968
{
@@ -989,7 +997,9 @@
989997
" **plotly_treemap_layout_base_settings,\n",
990998
" title='Rank of days since last commit',\n",
991999
")\n",
992-
"figure.show(**plotly_treemap_figure_show_settings)"
1000+
"figure.show(**plotly_treemap_figure_show_settings)\n",
1001+
"if is_command_line_execution():\n",
1002+
" figure.write_image(**get_plotly_figure_write_image_settings(\"DaysSinceLastCommitRanked\"))"
9931003
]
9941004
},
9951005
{
@@ -1023,7 +1033,9 @@
10231033
" **plotly_treemap_layout_base_settings,\n",
10241034
" title='Days since last file creation',\n",
10251035
")\n",
1026-
"figure.show(**plotly_treemap_figure_show_settings)"
1036+
"figure.show(**plotly_treemap_figure_show_settings)\n",
1037+
"if is_command_line_execution():\n",
1038+
" figure.write_image(**get_plotly_figure_write_image_settings(\"DaysSinceLastFileCreation\"))"
10271039
]
10281040
},
10291041
{
@@ -1057,7 +1069,9 @@
10571069
" **plotly_treemap_layout_base_settings,\n",
10581070
" title='Rank of days since last file creation',\n",
10591071
")\n",
1060-
"figure.show(**plotly_treemap_figure_show_settings)"
1072+
"figure.show(**plotly_treemap_figure_show_settings)\n",
1073+
"if is_command_line_execution():\n",
1074+
" figure.write_image(**get_plotly_figure_write_image_settings(\"DaysSinceLastFileCreationRanked\"))"
10611075
]
10621076
},
10631077
{
@@ -1091,7 +1105,9 @@
10911105
" **plotly_treemap_layout_base_settings,\n",
10921106
" title='Days since last file modification',\n",
10931107
")\n",
1094-
"figure.show(**plotly_treemap_figure_show_settings)"
1108+
"figure.show(**plotly_treemap_figure_show_settings)\n",
1109+
"if is_command_line_execution():\n",
1110+
" figure.write_image(**get_plotly_figure_write_image_settings(\"DaysSinceLastFileModification\"))"
10951111
]
10961112
},
10971113
{
@@ -1125,7 +1141,9 @@
11251141
" **plotly_treemap_layout_base_settings,\n",
11261142
" title='Rank of days since last file modification',\n",
11271143
")\n",
1128-
"figure.show(**plotly_treemap_figure_show_settings)"
1144+
"figure.show(**plotly_treemap_figure_show_settings)\n",
1145+
"if is_command_line_execution():\n",
1146+
" figure.write_image(**get_plotly_figure_write_image_settings(\"DaysSinceLastFileModificationRanked\"))"
11291147
]
11301148
},
11311149
{
@@ -1212,7 +1230,9 @@
12121230
" **plotly_treemap_layout_base_settings,\n",
12131231
" title='Pairwise file changes',\n",
12141232
")\n",
1215-
"figure.show(**plotly_treemap_figure_show_settings)"
1233+
"figure.show(**plotly_treemap_figure_show_settings)\n",
1234+
"if is_command_line_execution():\n",
1235+
" figure.write_image(**get_plotly_figure_write_image_settings(\"PairwiseFileChanges\"))"
12161236
]
12171237
},
12181238
{
@@ -1278,7 +1298,9 @@
12781298
" xaxis_title='file count',\n",
12791299
" yaxis_title='commit count'\n",
12801300
" )\n",
1281-
" figure.show(**plotly_treemap_figure_show_settings)"
1301+
" figure.show(**plotly_treemap_figure_show_settings)\n",
1302+
" if is_command_line_execution():\n",
1303+
" figure.write_image(**get_plotly_figure_write_image_settings(\"ChangedFilesPerCommit\"))"
12821304
]
12831305
},
12841306
{
@@ -1384,7 +1406,9 @@
13841406
" xaxis_title='commit count',\n",
13851407
" yaxis_title='dependency weight',\n",
13861408
" )\n",
1387-
" figure.show(**plotly_treemap_figure_show_settings)"
1409+
" figure.show(**plotly_treemap_figure_show_settings)\n",
1410+
" if is_command_line_execution():\n",
1411+
" figure.write_image(**get_plotly_figure_write_image_settings(\"PairwiseChangedFilesVsDependencyWeight\"))"
13881412
]
13891413
},
13901414
{

scripts/executeJupyterNotebook.sh

+5-2
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,12 @@ source "${SCRIPTS_DIR}/activateCondaEnvironment.sh"
8888
jupyter --version || exit 1
8989

9090
# Execute the Jupyter Notebook and write it to the output file name
91-
# The environment variable NBCONVERT is needed to be able to detect a command line execution in the Jupyter Notebook.
91+
# The environment variable NBCONVERT_PATH is needed to be able to detect a command line execution in the Jupyter Notebook.
92+
# Additionally, it is used to store the offline rendered images in the directory "${jupyter_notebook_file_name}_files".
9293
echo "executeJupyterNotebook: Executing Jupyter Notebook ${jupyter_notebook_output_file_name}..."
93-
NBCONVERT=true jupyter nbconvert --to notebook \
94+
95+
mkdir -p "${jupyter_notebook_file_name}_files"
96+
NBCONVERT_PATH="$(pwd)/${jupyter_notebook_file_name}_files" jupyter nbconvert --to notebook \
9497
--execute "${jupyter_notebook_file}" \
9598
--output "$jupyter_notebook_output_file_name" \
9699
--output-dir="./" \

0 commit comments

Comments
 (0)