feat([2fd88f42]): implement tooltip column manager
This commit is contained in:
@@ -42,14 +42,20 @@ def load_plz_data():
|
||||
plz_geocoord_df = pd.DataFrame()
|
||||
|
||||
# --- Pydantic Models ---
|
||||
class TooltipColumnConfig(BaseModel):
|
||||
id: str
|
||||
name: str
|
||||
visible: bool
|
||||
|
||||
class FilterRequest(BaseModel):
|
||||
filters: Dict[str, List[str]]
|
||||
tooltip_config: List[TooltipColumnConfig] = []
|
||||
|
||||
class PlzColumnRequest(BaseModel):
|
||||
plz_column: str
|
||||
|
||||
# --- API Endpoints ---
|
||||
@app.get("/")
|
||||
@app.get("/ ")
|
||||
def read_root():
|
||||
return {"message": "Heatmap Tool Backend"}
|
||||
|
||||
@@ -146,15 +152,22 @@ async def get_heatmap_data(request: FilterRequest):
|
||||
plz_grouped = filtered_df.groupby(plz_column_name)
|
||||
plz_counts = plz_grouped.size().reset_index(name='count')
|
||||
|
||||
# Collect unique attributes for each PLZ
|
||||
# Collect unique attributes for each PLZ based on tooltip_config
|
||||
attribute_summaries = {}
|
||||
if request.tooltip_config:
|
||||
visible_columns = [col.name for col in request.tooltip_config if col.visible]
|
||||
ordered_columns = [col.name for col in request.tooltip_config]
|
||||
else:
|
||||
# Fallback if no config is provided
|
||||
visible_columns = [col for col in filtered_df.columns if col != plz_column_name]
|
||||
ordered_columns = visible_columns
|
||||
|
||||
for plz_val, group in plz_grouped:
|
||||
summary = {}
|
||||
for col in filtered_df.columns:
|
||||
if col != plz_column_name and col != 'lat' and col != 'lon': # Exclude lat/lon if they somehow exist
|
||||
unique_attrs = group[col].unique().tolist()
|
||||
# Limit to top 3 unique values for readability
|
||||
summary[col] = unique_attrs[:3]
|
||||
for col_name in visible_columns:
|
||||
if col_name in group:
|
||||
unique_attrs = group[col_name].unique().tolist()
|
||||
summary[col_name] = unique_attrs[:3]
|
||||
attribute_summaries[plz_val] = summary
|
||||
|
||||
# Convert summaries to a DataFrame for merging
|
||||
@@ -199,16 +212,21 @@ async def get_heatmap_data(request: FilterRequest):
|
||||
# For each record, pick out the attributes that are not 'plz', 'lat', 'lon', 'count'
|
||||
final_heatmap_data = []
|
||||
for record in heatmap_data:
|
||||
attrs = {k: v for k, v in record.items() if k not in ['plz', 'lat', 'lon', 'count']}
|
||||
# Order the attributes based on tooltip_config
|
||||
ordered_attrs = {
|
||||
col_name: record.get(col_name)
|
||||
for col_name in ordered_columns
|
||||
if col_name in record and record.get(col_name) is not None
|
||||
}
|
||||
final_heatmap_data.append({
|
||||
"plz": record['plz'],
|
||||
"lat": record['lat'],
|
||||
"lon": record['lon'],
|
||||
"count": record['count'],
|
||||
"attributes_summary": attrs
|
||||
"attributes_summary": ordered_attrs
|
||||
})
|
||||
|
||||
print(f"Generated heatmap data with {len(final_heatmap_data)} PLZ points.")
|
||||
print(f"Generated heatmap data with {len(final_heatmap_data)} PLZ points, respecting tooltip config.")
|
||||
return final_heatmap_data
|
||||
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user