moderne-visualizations-misc 0.72.0__py3-none-any.whl → 0.73.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -171,7 +171,7 @@
171
171
  ],
172
172
  "metadata": {
173
173
  "kernelspec": {
174
- "display_name": "moderne-visualizations-misc",
174
+ "display_name": ".python",
175
175
  "language": "python",
176
176
  "name": "python3"
177
177
  },
@@ -185,7 +185,7 @@
185
185
  "name": "python",
186
186
  "nbconvert_exporter": "python",
187
187
  "pygments_lexer": "ipython3",
188
- "version": "3.9.6"
188
+ "version": "3.12.8"
189
189
  }
190
190
  },
191
191
  "nbformat": 4,
@@ -0,0 +1,46 @@
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "metadata": {
7
+ "tags": [
8
+ "parameters"
9
+ ]
10
+ },
11
+ "outputs": [],
12
+ "source": [
13
+ "repository_filter: list[str] = []\n",
14
+ "top_n_classes: int = 50"
15
+ ]
16
+ },
17
+ {
18
+ "cell_type": "code",
19
+ "execution_count": null,
20
+ "metadata": {},
21
+ "outputs": [],
22
+ "source": "import pandas as pd\nimport warnings\nimport plotly.graph_objects as go\nimport plotly.express as px\nimport code_data_science.data_table as dt\nimport numpy as np\n\nwarnings.simplefilter(\"ignore\")\n\ndf = dt.read_csv(\"../samples/cyclomatic_complexity.csv\")\n\n# Filter the data frame to only include rows where repositoryPath contains\n# a term in the repository_filter (case insensitive)\nif len(repository_filter) > 0:\n df = df[\n df[\"repositoryPath\"].str.contains(\"|\".join(repository_filter), case=False)\n ]\n\n# Exit early if there are no records and render a plot with a message\nif len(df) == 0:\n fig = go.Figure()\n fig.add_annotation(\n text=\"No data available for the selected repositories\",\n xref=\"paper\",\n yref=\"paper\",\n x=0.5,\n y=0.5,\n showarrow=False,\n font=dict(size=14)\n )\n fig.update_layout(\n xaxis=dict(visible=False),\n yaxis=dict(visible=False),\n margin=dict(l=0, r=0, t=60, b=60),\n title=\"Cyclomatic Complexity Heatmap\"\n )\n fig.show(render=\"plotly_mimetype\")\nelse:\n # Aggregate complexity metrics by repository and class\n class_metrics = df.groupby(['repositoryPath', 'className']).agg({\n 'complexity': ['sum', 'mean', 'max', 'count']\n }).reset_index()\n \n # Flatten column names\n class_metrics.columns = ['repository', 'className', 'total_complexity', 'avg_complexity', 'max_complexity', 'method_count']\n \n # Get short class names for display\n class_metrics['classShortName'] = class_metrics['className'].str.split('.').str[-1]\n \n # Get top N classes by total complexity\n top_classes = class_metrics.nlargest(min(top_n_classes, len(class_metrics)), 'total_complexity')\n \n # Create pivot table for heatmap\n # We'll show different metrics as columns\n metrics_data = []\n for _, row in top_classes.iterrows():\n metrics_data.append({\n 'class': f\"{row['repository'].split('/')[-1]}::{row['classShortName']}\",\n 'metric': 'Total Complexity',\n 'value': row['total_complexity']\n })\n metrics_data.append({\n 'class': f\"{row['repository'].split('/')[-1]}::{row['classShortName']}\",\n 'metric': 'Avg Complexity',\n 'value': row['avg_complexity']\n })\n metrics_data.append({\n 'class': f\"{row['repository'].split('/')[-1]}::{row['classShortName']}\",\n 'metric': 'Max Complexity',\n 'value': row['max_complexity']\n })\n metrics_data.append({\n 'class': f\"{row['repository'].split('/')[-1]}::{row['classShortName']}\",\n 'metric': 'Method Count',\n 'value': row['method_count']\n })\n \n metrics_df = pd.DataFrame(metrics_data)\n pivot_table = metrics_df.pivot(index='class', columns='metric', values='value')\n \n # Reorder columns\n pivot_table = pivot_table[['Method Count', 'Avg Complexity', 'Max Complexity', 'Total Complexity']]\n \n # Sort by total complexity to maintain order\n pivot_table = pivot_table.sort_values('Total Complexity', ascending=False)\n \n # Normalize values for each metric (0-1 scale) for better color representation\n normalized_data = pivot_table.copy()\n for col in normalized_data.columns:\n col_min = normalized_data[col].min()\n col_max = normalized_data[col].max()\n if col_max > col_min:\n normalized_data[col] = (normalized_data[col] - col_min) / (col_max - col_min)\n \n # Create custom hover text\n hover_text = []\n for i in range(len(pivot_table)):\n hover_row = []\n for j, col in enumerate(pivot_table.columns):\n value = pivot_table.iloc[i, j]\n if col == 'Avg Complexity':\n hover_row.append(f\"{col}: {value:.1f}\")\n else:\n hover_row.append(f\"{col}: {int(value)}\")\n hover_text.append(hover_row)\n \n # Create the heatmap\n fig = go.Figure(data=go.Heatmap(\n z=normalized_data.values,\n x=normalized_data.columns,\n y=normalized_data.index,\n colorscale=[\n [0, '#E8F5E9'],\n [0.2, '#A5D6A7'],\n [0.4, '#FFE082'],\n [0.6, '#FFB74D'],\n [0.8, '#FF8A65'],\n [1, '#EF5350']\n ],\n colorbar=dict(\n title=\"Normalized<br>Complexity\",\n thickness=15,\n len=0.7\n ),\n text=hover_text,\n texttemplate=\"\",\n hovertemplate=(\n '<b>%{y}</b><br>' +\n '%{text}' +\n '<extra></extra>'\n )\n ))\n \n # Add text annotations for actual values\n annotations = []\n for i in range(len(pivot_table)):\n for j, col in enumerate(pivot_table.columns):\n value = pivot_table.iloc[i, j]\n if col == 'Avg Complexity':\n text = f\"{value:.1f}\"\n else:\n text = str(int(value))\n \n annotations.append(\n go.layout.Annotation(\n text=text,\n x=j,\n y=i,\n xref=\"x\",\n yref=\"y\",\n showarrow=False,\n font=dict(\n size=10,\n color=\"black\" if normalized_data.iloc[i, j] < 0.6 else \"white\"\n )\n )\n )\n \n # Update layout\n fig.update_layout(\n title=dict(\n text=f\"Cyclomatic Complexity Heatmap by Class<br><sub>Top {len(pivot_table)} classes by total complexity</sub>\",\n font=dict(size=16)\n ),\n xaxis=dict(\n title=\"Complexity Metrics\",\n tickfont=dict(size=12),\n showgrid=False,\n side=\"bottom\"\n ),\n yaxis=dict(\n title=\"Repository::Class\",\n tickfont=dict(size=10),\n showgrid=False,\n autorange=\"reversed\" # Put highest complexity at top\n ),\n annotations=annotations,\n margin=dict(l=250, r=50, t=100, b=80),\n height=max(600, len(pivot_table) * 25 + 200),\n plot_bgcolor='white'\n )\n \n # Show the figure\n fig.show(render=\"plotly_mimetype\")"
23
+ }
24
+ ],
25
+ "metadata": {
26
+ "kernelspec": {
27
+ "display_name": ".python",
28
+ "language": "python",
29
+ "name": "python3"
30
+ },
31
+ "language_info": {
32
+ "codemirror_mode": {
33
+ "name": "ipython",
34
+ "version": 3
35
+ },
36
+ "file_extension": ".py",
37
+ "mimetype": "text/x-python",
38
+ "name": "python",
39
+ "nbconvert_exporter": "python",
40
+ "pygments_lexer": "ipython3",
41
+ "version": "3.12.8"
42
+ }
43
+ },
44
+ "nbformat": 4,
45
+ "nbformat_minor": 4
46
+ }