|
56 | 56 | "# it would require to execute the notebook twice: Once including interactivity and once for static Markdown and PDF.\n", |
57 | 57 | "# Therefore, command line executed notebooks (nbconvert) will contain static graphics (here using svg).\n", |
58 | 58 | "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", |
60 | 65 | "\n", |
61 | 66 | "default_renderer = None\n", |
62 | 67 | "\n", |
|
177 | 182 | "metadata": {}, |
178 | 183 | "outputs": [], |
179 | 184 | "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 | + "# --------------------------------------------------------------------------------" |
189 | 188 | ] |
190 | 189 | }, |
191 | 190 | { |
|
208 | 207 | ")\n", |
209 | 208 | "plotly_treemap_figure_show_settings = dict(\n", |
210 | 209 | " 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", |
213 | 213 | ")\n", |
214 | 214 | "\n", |
215 | 215 | "plotly_treemap_marker_base_style = dict(\n", |
|
222 | 222 | ")" |
223 | 223 | ] |
224 | 224 | }, |
| 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 | + }, |
225 | 246 | { |
226 | 247 | "cell_type": "code", |
227 | 248 | "execution_count": null, |
|
280 | 301 | ] |
281 | 302 | }, |
282 | 303 | { |
283 | | - "cell_type": "markdown", |
284 | | - "id": "acacc415", |
| 304 | + "cell_type": "code", |
| 305 | + "execution_count": null, |
| 306 | + "id": "c37c64a4", |
285 | 307 | "metadata": {}, |
| 308 | + "outputs": [], |
286 | 309 | "source": [ |
287 | | - "### Visualization Data Preparation Functions" |
| 310 | + "# --------------------------------------------------------------------------------\n", |
| 311 | + "# Shared Visualization Data Preparation Functions\n", |
| 312 | + "# --------------------------------------------------------------------------------" |
288 | 313 | ] |
289 | 314 | }, |
290 | 315 | { |
|
330 | 355 | ] |
331 | 356 | }, |
332 | 357 | { |
333 | | - "cell_type": "markdown", |
334 | | - "id": "da109679", |
| 358 | + "cell_type": "code", |
| 359 | + "execution_count": null, |
| 360 | + "id": "fb368425", |
335 | 361 | "metadata": {}, |
| 362 | + "outputs": [], |
336 | 363 | "source": [ |
337 | | - "### File Data Preparation Functions" |
| 364 | + "# --------------------------------------------------------------------------------\n", |
| 365 | + "# Shared File Data Preparation Functions\n", |
| 366 | + "# --------------------------------------------------------------------------------" |
338 | 367 | ] |
339 | 368 | }, |
340 | 369 | { |
|
490 | 519 | ] |
491 | 520 | }, |
492 | 521 | { |
493 | | - "cell_type": "markdown", |
494 | | - "id": "09aeae9b", |
| 522 | + "cell_type": "code", |
| 523 | + "execution_count": null, |
| 524 | + "id": "69fc63ff", |
495 | 525 | "metadata": {}, |
| 526 | + "outputs": [], |
496 | 527 | "source": [ |
497 | | - "### File Data Preparation " |
| 528 | + "# --------------------------------------------------------------------------------\n", |
| 529 | + "# Main File Data Preparation\n", |
| 530 | + "# --------------------------------------------------------------------------------" |
498 | 531 | ] |
499 | 532 | }, |
500 | 533 | { |
|
659 | 692 | " **plotly_treemap_layout_base_settings,\n", |
660 | 693 | " title='Directories and their file count'\n", |
661 | 694 | ")\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\"))" |
663 | 698 | ] |
664 | 699 | }, |
665 | 700 | { |
|
695 | 730 | " **plotly_treemap_layout_base_settings,\n", |
696 | 731 | " title='Most frequent file extension per directory'\n", |
697 | 732 | ")\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\"))" |
699 | 736 | ] |
700 | 737 | }, |
701 | 738 | { |
|
729 | 766 | " **plotly_treemap_layout_base_settings,\n", |
730 | 767 | " title='Number of git commits',\n", |
731 | 768 | ")\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\"))" |
733 | 772 | ] |
734 | 773 | }, |
735 | 774 | { |
|
763 | 802 | " **plotly_treemap_layout_base_settings,\n", |
764 | 803 | " title='Number of distinct commit authors',\n", |
765 | 804 | ")\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\"))" |
767 | 808 | ] |
768 | 809 | }, |
769 | 810 | { |
|
805 | 846 | " title='Number of distinct commit authors (red/black = only one or very few authors)',\n", |
806 | 847 | ")\n", |
807 | 848 | "\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\"))" |
850 | 852 | ] |
851 | 853 | }, |
852 | 854 | { |
|
882 | 884 | " **plotly_treemap_layout_base_settings,\n", |
883 | 885 | " title='Main authors with highest number of commits'\n", |
884 | 886 | ")\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\"))" |
886 | 890 | ] |
887 | 891 | }, |
888 | 892 | { |
|
919 | 923 | " **plotly_treemap_layout_base_settings,\n", |
920 | 924 | " title='Second author with the second highest number of commits'\n", |
921 | 925 | ")\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\"))" |
923 | 929 | ] |
924 | 930 | }, |
925 | 931 | { |
|
954 | 960 | " **plotly_treemap_layout_base_settings,\n", |
955 | 961 | " title='Days since last commit',\n", |
956 | 962 | ")\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\"))" |
958 | 966 | ] |
959 | 967 | }, |
960 | 968 | { |
|
989 | 997 | " **plotly_treemap_layout_base_settings,\n", |
990 | 998 | " title='Rank of days since last commit',\n", |
991 | 999 | ")\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\"))" |
993 | 1003 | ] |
994 | 1004 | }, |
995 | 1005 | { |
|
1023 | 1033 | " **plotly_treemap_layout_base_settings,\n", |
1024 | 1034 | " title='Days since last file creation',\n", |
1025 | 1035 | ")\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\"))" |
1027 | 1039 | ] |
1028 | 1040 | }, |
1029 | 1041 | { |
|
1057 | 1069 | " **plotly_treemap_layout_base_settings,\n", |
1058 | 1070 | " title='Rank of days since last file creation',\n", |
1059 | 1071 | ")\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\"))" |
1061 | 1075 | ] |
1062 | 1076 | }, |
1063 | 1077 | { |
|
1091 | 1105 | " **plotly_treemap_layout_base_settings,\n", |
1092 | 1106 | " title='Days since last file modification',\n", |
1093 | 1107 | ")\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\"))" |
1095 | 1111 | ] |
1096 | 1112 | }, |
1097 | 1113 | { |
|
1125 | 1141 | " **plotly_treemap_layout_base_settings,\n", |
1126 | 1142 | " title='Rank of days since last file modification',\n", |
1127 | 1143 | ")\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\"))" |
1129 | 1147 | ] |
1130 | 1148 | }, |
1131 | 1149 | { |
|
1212 | 1230 | " **plotly_treemap_layout_base_settings,\n", |
1213 | 1231 | " title='Pairwise file changes',\n", |
1214 | 1232 | ")\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\"))" |
1216 | 1236 | ] |
1217 | 1237 | }, |
1218 | 1238 | { |
|
1278 | 1298 | " xaxis_title='file count',\n", |
1279 | 1299 | " yaxis_title='commit count'\n", |
1280 | 1300 | " )\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\"))" |
1282 | 1304 | ] |
1283 | 1305 | }, |
1284 | 1306 | { |
|
1384 | 1406 | " xaxis_title='commit count',\n", |
1385 | 1407 | " yaxis_title='dependency weight',\n", |
1386 | 1408 | " )\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\"))" |
1388 | 1412 | ] |
1389 | 1413 | }, |
1390 | 1414 | { |
|
0 commit comments