|
|
@@ -12,6 +12,7 @@ from dataclasses import dataclass
|
|
|
from enum import Enum
|
|
|
|
|
|
from PyQt6.QtWidgets import (
|
|
|
+ QDialog,
|
|
|
QWidget,
|
|
|
QVBoxLayout,
|
|
|
QHBoxLayout,
|
|
|
@@ -110,42 +111,43 @@ class StatisticsData:
|
|
|
average_wpm: float
|
|
|
|
|
|
|
|
|
-class StatisticsFigureCanvas(FigureCanvas):
|
|
|
- """
|
|
|
- Matplotlib canvas for embedding charts in PyQt.
|
|
|
-
|
|
|
- Provides a clean interface for rendering various chart types.
|
|
|
- """
|
|
|
-
|
|
|
- def __init__(self, parent: Optional[QWidget] = None, width: int = 5, height: int = 4, dpi: int = 100) -> None:
|
|
|
- """Initialize the figure canvas."""
|
|
|
- if Figure is None:
|
|
|
- raise RuntimeError("Matplotlib is not installed")
|
|
|
-
|
|
|
- self.fig = Figure(figsize=(width, height), dpi=dpi)
|
|
|
- self.axes = self.fig.add_subplot(111)
|
|
|
- super().__init__(self.fig)
|
|
|
- self.setParent(parent)
|
|
|
-
|
|
|
- # Styling
|
|
|
- self.fig.patch.set_facecolor("#ffffff")
|
|
|
- self.fig.subplots_adjust(left=0.1, right=0.95, top=0.95, bottom=0.1)
|
|
|
-
|
|
|
- def clear(self) -> None:
|
|
|
- """Clear the current chart."""
|
|
|
- self.axes.clear()
|
|
|
- self.draw()
|
|
|
-
|
|
|
- def set_chinese_font(self) -> None:
|
|
|
- """Configure matplotlib to use Chinese-compatible fonts."""
|
|
|
- try:
|
|
|
- import matplotlib as mpl
|
|
|
- mpl.rcParams["font.sans-serif"] = ["SimHei", "Microsoft YaHei", "Arial Unicode MS"]
|
|
|
- mpl.rcParams["axes.unicode_minus"] = False
|
|
|
- except Exception:
|
|
|
- pass
|
|
|
-
|
|
|
-
|
|
|
+if MATPLOTLIB_AVAILABLE:
|
|
|
+ class StatisticsFigureCanvas(FigureCanvas):
|
|
|
+ """
|
|
|
+ Matplotlib canvas for embedding charts in PyQt.
|
|
|
+
|
|
|
+ Provides a clean interface for rendering various chart types.
|
|
|
+ """
|
|
|
+
|
|
|
+ def __init__(self, parent: Optional[QWidget] = None, width: int = 5, height: int = 4, dpi: int = 100) -> None:
|
|
|
+ """Initialize the figure canvas."""
|
|
|
+ if Figure is None:
|
|
|
+ raise RuntimeError("Matplotlib is not installed")
|
|
|
+
|
|
|
+ self.fig = Figure(figsize=(width, height), dpi=dpi)
|
|
|
+ self.axes = self.fig.add_subplot(111)
|
|
|
+ super().__init__(self.fig)
|
|
|
+ self.setParent(parent)
|
|
|
+
|
|
|
+ # Styling
|
|
|
+ self.fig.patch.set_facecolor("#ffffff")
|
|
|
+ self.fig.subplots_adjust(left=0.1, right=0.95, top=0.95, bottom=0.1)
|
|
|
+
|
|
|
+ def clear(self) -> None:
|
|
|
+ """Clear the current chart."""
|
|
|
+ self.axes.clear()
|
|
|
+ self.draw()
|
|
|
+
|
|
|
+ def set_chinese_font(self) -> None:
|
|
|
+ """Configure matplotlib to use Chinese-compatible fonts."""
|
|
|
+ try:
|
|
|
+ import matplotlib as mpl
|
|
|
+ mpl.rcParams["font.sans-serif"] = ["SimHei", "Microsoft YaHei", "Arial Unicode MS"]
|
|
|
+ mpl.rcParams["axes.unicode_minus"] = False
|
|
|
+ except Exception:
|
|
|
+ pass
|
|
|
+
|
|
|
+
|
|
|
class StatisticsPanel(QWidget):
|
|
|
"""
|
|
|
Statistics panel widget (Story 7.23).
|