malepati/custom_template_working
0
1# Fix Missing Charts - Implementation Plan (Correction)2 3## Problem4The previous fix injected `__chart_data__`, but the frontend component (`ChartLeftTextRightLayout.tsx`) expects data in a `chart` property with a specific structure (`[{label, value}]`). The `ChartData` from the outline usually has `[{category, value}]`.5 6## Proposed Changes7 8### **servers/fastapi/api/v1/ppt/endpoints/presentation.py**9 10**Function**: `stream_presentation`11 12**Logic to Update**:131. Remove the previous `__chart_data__` injection.142. Implement a transformation logic:15 * Take `outline.slides[i].chart_data`.16 * Map its `data` list: Rename `category` (or other keys) to `label`.17 * Construct a `chart` dictionary matching the layout's schema: `{ "type": ..., "data": [...], "showLabels": True }`.183. Inject this dictionary into `slide_content["chart"]`.19 20**Code Snippet**:21```python22 # ... inside the loop ...23 if outline.slides[i].chart_data:24 chart_model = outline.slides[i].chart_data25 26 # Transform data points: key mapping to 'label' and 'value'27 transformed_data = []28 for item in chart_model.data:29 # Attempt to find the label key (usually 'category' or the first string key)30 label = item.get("category") or item.get("label") or list(item.keys())[0]31 value = item.get("value")32 if value is not None:33 transformed_data.append({"label": str(label), "value": value})34 35 if transformed_data:36 # Inject into the 'chart' field expected by the React component37 slide_content["chart"] = {38 "type": chart_model.type if chart_model.type in ['bar', 'horizontalBar', 'line', 'pie'] else 'bar',39 "data": transformed_data,40 "primaryColor": "#1B8C2D", # Default41 "gridColor": "#E5E7EB",42 "showLabels": True43 }44 print(f"DEBUG: Injected chart data into slide {i}: {len(transformed_data)} points")45 46 # Keep the image prompt removal logic47 remove_image_prompts(slide_content)48```49 50## Verification511. Restart Backend.522. Generate a presentation with a chart request (e.g., "Pie chart of user types").533. Verify in the UI that the chart renders.54 