# Path: pytripgui/view/chart_widget.py
# class ChartWidget:
#     def __init__(self):
#         self.model = QChart()
#         self.view = QChartView()
# 
#         self.view.setChart(self.model)
# 
#         self.model.legend().setAlignment(Qt.AlignBottom)
#         self.view.setRenderHint(QPainter.Antialiasing)
# 
#     def show(self):
#         self.view.show()
# 
#     def exit(self):
#         self.view.close()
# 
#     @property
#     def title(self):
#         return self.model.title()
# 
#     @title.setter
#     def title(self, title):
#         self.model.setTitle(title)
# 
#     def add_series(self, x_list, y_list, name):
#         series = QLineSeries()
#         series.setName(name)
# 
#         for x, y in zip(x_list, y_list):
#             series.append(x, y)
# 
#         self.model.addSeries(series)
#         self.model.createDefaultAxes()
# 
#         # axis = QValueAxis()
#         # axis.setTitleText("Dose")
#         #
#         # self.model.setAxisX(axis, series)
#         # self.model.axisY(series).setTitleText("Dose")


from pytripgui.view.chart_widget import ChartWidget
from PyQt5.QtWidgets import QDockWidget
from PyQt5.QtCore import Qt
class Charts:
    def __init__(self, parent_gui):
        self._parent_gui = parent_gui

        self._charts = []
        self._dock_widgets = []

    def set_simulation_result(self, simulation_result):
        self._charts = []

        for histogram_name in simulation_result.volume_histograms:
            widget = ChartWidget()
            widget.title = histogram_name

            histogram = simulation_result.volume_histograms[histogram_name]
            for name, value in histogram.items():
                widget.add_series(value.x, value.y, name)

            self._charts.append(widget)

        self._show()

    def _show(self):
        self._close_all()
        self._dock_widgets = []

        for chart in self._charts:
            widget = QDockWidget()
            widget.setWidget(chart.view)
            self._parent_gui.ui.addDockWidget(Qt.RightDockWidgetArea, widget)

# Path: pytripgui/view/chart_widget.py
# class ChartWidget:
#     def __init__(self):
#         self.model = QChart()
#         self.view = QChartView()
# 
#         self.view.setChart(self.model)
# 
#         self.model.legend().setAlignment(Qt.AlignBottom)
#         self.view.setRenderHint(QPainter.Antialiasing)
# 
#     def show(self):
#         self.view.show()
# 
#     def exit(self):
#         self.view.close()
# 
#     @property
#     def title(self):
#         return self.model.title()
# 
#     @title.setter
#     def title(self, title):
#         self.model.setTitle(title)
# 
#     def add_series(self, x_list, y_list, name):
#         series = QLineSeries()
#         series.setName(name)
# 
#         for x, y in zip(x_list, y_list):
#             series.append(x, y)
# 
#         self.model.addSeries(series)
#         self.model.createDefaultAxes()
# 
#         # axis = QValueAxis()
#         # axis.setTitleText("Dose")
#         #
#         # self.model.setAxisX(axis, series)
#         # self.model.axisY(series).setTitleText("Dose")


# Path: pytripgui/app_logic/charts.py
from pytripgui.view.chart_widget import ChartWidget
from PyQt5.QtWidgets import QDockWidget
from PyQt5.QtCore import Qt

class Charts:
    def __init__(self, parent_gui):
        self._parent_gui = parent_gui

        self._charts = []
        self._dock_widgets = []

    def set_simulation_result(self, simulation_result):
        self._charts = []

        for histogram_name in simulation_result.volume_histograms:
            widget = ChartWidget()
            widget.title = histogram_name

            histogram = simulation_result.volume_histograms[histogram_name]
            for name, value in histogram.items():
                widget.add_series(value.x, value.y, name)

            self._charts.append(widget)

        self._show()

    def _show(self):
        self._close_all()
        self._dock_widgets = []

        for chart in self._charts:
            widget = QDockWidget()
            widget.setWidget(chart.view)
            self._parent_gui.ui.addDockWidget(Qt.RightDockWidgetArea, widget)

            self._dock_widgets.append(widget)