def getTable(): ''' Check if a table exists otherwise open a new one''' ## Check if we can get a table window if IJ.getFullVersion() >= "1.53g": # try to get any active table tableWindow = WindowManager.getActiveTable( ) # this function requires 1.53g (or at least not working with 1.53c), return None if no table else: # Fallback on fetching either a window called Annotations or Annotations.csv as in previous plugin version win = WindowManager.getWindow("Annotations") win2 = WindowManager.getWindow( "Annotations.csv") # upon saving it adds this extension if win: tableWindow = win elif win2: tableWindow = win2 else: tableWindow = None ## If a table window then get its table, otherwise new table. In this case, its name is set later return tableWindow.getResultsTable() if tableWindow else ResultsTable()
def actionPerformed(self, event): if IJ.getFullVersion() < "1.53g": IJ.error("This plugin requires ImageJ version 1.53g minimum.\n Update using Help > Update ImageJ...") return tableWindow = WindowManager.getActiveTable() # this function requires the 1.53g (or at least not working with 1.53c) if not tableWindow: return # Get column Category table = tableWindow.getResultsTable() column = table.getColumnAsVariables("Category") columnString = [str(item) for item in column] # Plot Pie Plot for this column pieChart = PieChart("Category", columnString) pieChart.showFrame("Data-distribution")
from QualiAnnotations.Charts import PieChart from ij.gui import GenericDialog from ij import IJ, WindowManager if IJ.getFullVersion() < "1.53g": IJ.error( "This plugin requires ImageJ version 1.53g minimum.\n Update using Help > Update ImageJ..." ) raise Exception("ImageJ version 1.53g minimum required") tableWindow = WindowManager.getActiveTable( ) # this function requires the 1.53g (or at least not working with 1.53c) #print tableWindow if not tableWindow: IJ.error("No open table") else: # List column headers table = tableWindow.getResultsTable() headers = table.getHeadings() # Generate dialog with dropdown for column selection dialog = GenericDialog("PieChart from table column") dialog.addChoice("Data column", headers, headers[0]) dialog.addMessage( """Hover the mouse over the plot to view absolute and relative (%) values\n Right-click to set colors, export to PNG...\n Note: BarCharts usually provide better distinction than PieCharts for sectors with similar sizes (see Help).""" )