示例#1
0
    def __init__(self, parent, **params):
        #super(TachogramPlotCanvas, self).__init__(parent,
        #                                not_add_widget_to_parent_layout=True)
        self.params = Params(**params)
        self.title_manager = __TitleManager__(
                                    NormalTachogramPlotEngine.DEFAULT_TITLE)
        self.data_accessor = self.params.data_accessor  # alias
        self.data_accessor.addListener(self, __CanvasDataVectorListener__(self)) # @IgnorePep8
        self.fig = Figure()
        self.axes = self.fig.add_subplot(111)

        self.__current_plot_engine__ = None

        FigureCanvas.__init__(self, self.fig)
        self.title_text = self.fig.suptitle(self.title_manager.title,
                                            fontsize=12)

        self.plot(NormalTachogramPlotEngine)

        # automatic layout adjustment to use available space more efficiently
        self.fig.tight_layout()
        self.setParent(parent)

        FigureCanvas.setSizePolicy(self, QSizePolicy.Expanding,
                                    QSizePolicy.Expanding)
        FigureCanvas.updateGeometry(self)
        self.__dropper__ = CopyDropper(self, STATISTIC_MIME_ID)
示例#2
0
class TachogramPlotCanvas(FigureCanvas):
    """
    this class represents core of the tachogram plot that is a plot itself
    """
    def __init__(self, parent, **params):
        #super(TachogramPlotCanvas, self).__init__(parent,
        #                                not_add_widget_to_parent_layout=True)
        self.params = Params(**params)
        self.title_manager = __TitleManager__(
                                    NormalTachogramPlotEngine.DEFAULT_TITLE)
        self.data_accessor = self.params.data_accessor  # alias
        self.data_accessor.addListener(self, __CanvasDataVectorListener__(self)) # @IgnorePep8
        self.fig = Figure()
        self.axes = self.fig.add_subplot(111)

        self.__current_plot_engine__ = None

        FigureCanvas.__init__(self, self.fig)
        self.title_text = self.fig.suptitle(self.title_manager.title,
                                            fontsize=12)

        self.plot(NormalTachogramPlotEngine)

        # automatic layout adjustment to use available space more efficiently
        self.fig.tight_layout()
        self.setParent(parent)

        FigureCanvas.setSizePolicy(self, QSizePolicy.Expanding,
                                    QSizePolicy.Expanding)
        FigureCanvas.updateGeometry(self)
        self.__dropper__ = CopyDropper(self, STATISTIC_MIME_ID)

    def plot(self, _plot_engine_class=None, force_plot=False):

        if self.__current_plot_engine__ == None:
            self.__current_plot_engine__ = NormalTachogramPlotEngine()
        #plot engine not specified and doesn't have to plot
        elif force_plot == False and (_plot_engine_class == None or \
            _plot_engine_class.__name__ == \
                self.__current_plot_engine__.__class__.__name__):
                return

        #plot engine class changed
        if not _plot_engine_class == None and not _plot_engine_class.__name__ \
            == self.__current_plot_engine__.__class__.__name__:
            self.__current_plot_engine__ = _plot_engine_class()
        self.axes.cla()
        self.__calculate__()
        self.__current_plot_engine__.plot(self)
        print('PLOTTING')

        self.axes.set_xlabel(self.__current_plot_engine__.x_label)
        self.axes.set_ylabel(self.__current_plot_engine__.y_label)

        self.title_text.set_text(self.title_manager.title)
        self.draw()

    def dropEvent(self, event):
        if self.__dropper__.dropEvent(event):
            statistic = self.__dropper__.dropObject(STATISTIC_CLASS_NAME_ID)
            print('STATISTIC: ' + str(statistic))

    def dragEnterEvent(self, event):
        self.__dropper__.dragEnterEvent(event)

    def __calculate__(self):
        self.y = self.data_accessor.signal

        if self.data_accessor.signal_x_unit == OrderUnit:
            self.x = np.arange(0, len(self.y), 1)
        # x axis unit is the same as signal unit
        elif self.data_accessor.signal_x_unit == \
                                    self.data_accessor.signal_unit:
            self.x = np.cumsum(self.y)
        else:
            #express signal unit in terms of x axis unit
            multiplier = self.data_accessor.signal_unit.expressInUnit(
                                        self.data_accessor.signal_x_unit)
            self.x = np.cumsum(self.y) * multiplier

    @property
    def title_manager(self):
        return self.__title_manager__

    @title_manager.setter
    def title_manager(self, _title_manager):
        self.__title_manager__ = _title_manager