Add missing wrapper functions for visualizations
Browse files- visualizations.py +36 -0
visualizations.py
CHANGED
|
@@ -170,3 +170,39 @@ def figure_to_png_bytes(fig: go.Figure) -> BytesIO:
|
|
| 170 |
except ValueError as exc: # pragma: no cover - fallback for environments without kaleido
|
| 171 |
raise ValueError("PNG export requires the 'kaleido' package. Please install it to enable downloads.") from exc
|
| 172 |
return BytesIO(image_bytes)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
except ValueError as exc: # pragma: no cover - fallback for environments without kaleido
|
| 171 |
raise ValueError("PNG export requires the 'kaleido' package. Please install it to enable downloads.") from exc
|
| 172 |
return BytesIO(image_bytes)
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
def create_time_series_plot(df: pd.DataFrame, date_column: str, value_column: str, aggregation: str = "sum") -> go.Figure:
|
| 176 |
+
"""Generate a time-series plot using the TimeSeriesStrategy."""
|
| 177 |
+
strategy = TimeSeriesStrategy()
|
| 178 |
+
return strategy.generate(df, date_column=date_column, value_column=value_column, aggregation=aggregation)
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
def create_distribution_plot(df: pd.DataFrame, column: str, plot_type: str = "histogram") -> go.Figure:
|
| 182 |
+
"""Generate a distribution plot using the DistributionStrategy."""
|
| 183 |
+
strategy = DistributionStrategy()
|
| 184 |
+
return strategy.generate(df, column=column, plot_type=plot_type)
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
def create_category_plot(
|
| 188 |
+
df: pd.DataFrame, category_column: str, value_column: str, aggregation: str = "sum", chart_type: str = "bar"
|
| 189 |
+
) -> go.Figure:
|
| 190 |
+
"""Generate a category plot using the CategoryStrategy."""
|
| 191 |
+
strategy = CategoryStrategy()
|
| 192 |
+
return strategy.generate(
|
| 193 |
+
df, category_column=category_column, value_column=value_column, aggregation=aggregation, chart_type=chart_type
|
| 194 |
+
)
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
def create_scatter_plot(
|
| 198 |
+
df: pd.DataFrame, x_column: str, y_column: str, color_column: Optional[str] = None
|
| 199 |
+
) -> go.Figure:
|
| 200 |
+
"""Generate a scatter plot using the ScatterStrategy."""
|
| 201 |
+
strategy = ScatterStrategy()
|
| 202 |
+
return strategy.generate(df, x_column=x_column, y_column=y_column, color_column=color_column)
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
def create_correlation_heatmap(df: pd.DataFrame) -> go.Figure:
|
| 206 |
+
"""Generate a correlation heatmap using the CorrelationHeatmapStrategy."""
|
| 207 |
+
strategy = CorrelationHeatmapStrategy()
|
| 208 |
+
return strategy.generate(df)
|