Skip to content

Refactor DataVisualization into classes (keeping static API) #45

@mathparracho

Description

@mathparracho

DataVisualizationcurrently exposes several plotting utilities only as @staticmethods (plot_series, plot_multiple_series, correlation_heatmap, plot_fft, etc.).

The idea is to refactor this so that each plot is implemented as its own class while keeping the current static API working.

This should allow both styles:

# New style (OO)
plot = PlotSeries(data, title="...")
fig, path = plot.plot()

# Old style (still supported)
fig, path = DataVisualization.plot_series(data, title="...")

Proposal

  1. Add a common base class:
from abc import ABC, abstractmethod
from matplotlib.figure import Figure

class BaseVisualizer(ABC):
    @abstractmethod
    def plot(self) -> tuple[Figure, str]:
        ...
  1. For each existing static method, create a visualizer class:
class PlotSeries(BaseVisualizer):
    def __init__(self, series, title: str = "", save_path: str | None = None):
        self.series = series
        self.title = title
        self.save_path = save_path

    def plot(self) -> tuple[Figure, str]:
        # plotting logic
        path = DataVisualization._save_plot(...)
        return fig, path
  1. Keep DataVisualization as a façade that delegates to the classes:
class DataVisualization(ABC):

    @staticmethod
    def plot_series(series, title: str = "", save_path: str | None = None):
        return PlotSeries(series, title=title, save_path=save_path).plot()

    # Other methods follow the same pattern

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions