def _dataframe_changed(self, old, new): ''' Handles how updates occur when dataframe changes. Evaluates if columns or columnlabels have been changed. Provides entry condition as well. Note: New automatically sets self.dataframe, so when I refer to new, I am actually referring to self.dataframe. Using "new" instead of self.dataframe is just for readability''' ### Initialize plot first time dataframe is passed into the class. Boolean listeners ### for dataframe behave oddly, so uses self.plotdata for entry condition. if not self.plotdata: self.plotdata = PandasPlotData(df=new) self.originaldata = new ### Try to infer plot title from dataframe name ### try: self.plot_title = new.name except AttributeError: pass ### Draw barebones of plot self.draw_plot() ### Draw lines self._draw_lines() return ### Decide to update columns or completely redraw dataframe. else: labelold = self._getlabelarray(old) labelnew = self._getlabelarray(new) ### Have columns been added or removed? if len(labelold) != len(labelnew): self._overwrite_plotdata ### Has index along primaryaxis changed any? ### Pandas index comparison is a bit tricky so just list conver elif list(labelold) != list(labelnew): self._overwrite_plotdata else: print 'updating frame' self.plotdata.set_df(new)
def _overwrite_plotdata(self): '''When a new instance of PandasPlotData is created, this overwrites the data source and updates the axis values.''' self.plotdata = PandasPlotData(dataframe=self.dataframe)