Class SNTChart

java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
org.jfree.chart.ChartPanel
sc.fiji.snt.analysis.SNTChart
All Implemented Interfaces:
ActionListener, MouseListener, MouseMotionListener, ImageObserver, MenuContainer, Printable, Serializable, EventListener, Accessible, org.jfree.chart.event.ChartChangeListener, org.jfree.chart.event.ChartProgressListener, org.jfree.chart.event.OverlayChangeListener

public class SNTChart extends org.jfree.chart.ChartPanel
Extension of ChartPanel modified for scientific publications and convenience methods for plot annotations.
Author:
Tiago Ferreira
See Also:
  • Constructor Details

    • SNTChart

      public SNTChart(String title, org.jfree.chart.JFreeChart chart)
    • SNTChart

      public SNTChart(String title, org.scijava.plot.XYPlot xyplot)
    • SNTChart

      public SNTChart(String title, org.scijava.plot.CategoryChart categoryChart)
    • SNTChart

      protected SNTChart(String title, org.jfree.chart.JFreeChart chart, Dimension preferredSize)
  • Method Details

    • getFrame

      public JFrame getFrame()
    • annotateXline

      public void annotateXline(double xValue, String label)
      Annotates the specified X-value (XY plots and histograms).
      Parameters:
      xValue - the X value to be annotated.
      label - the annotation label
    • annotateXline

      public void annotateXline(double xValue, String label, String color)
      Annotates the specified X-value (XY plots and histograms).
      Parameters:
      xValue - the X value to be annotated.
      label - the annotation label
      color - the font color
    • annotateYline

      public void annotateYline(double yValue, String label)
      Annotates the specified Y-value (XY plots and histograms).
      Parameters:
      yValue - the Y value to be annotated.
      label - the annotation label
    • annotateYline

      public void annotateYline(double yValue, String label, String color)
      Annotates the specified Y-value (XY plots and histograms).
      Parameters:
      yValue - the Y value to be annotated.
      label - the annotation label
      color - the font color
    • setAxesVisible

      public void setAxesVisible(boolean visible)
      Sets the visibility of chart axes.

      Controls whether the domain (X) and range (Y) axes are visible in the chart. This affects both XY plots and category plots.

      Parameters:
      visible - true to show axes, false to hide them
    • isLegendVisible

      public boolean isLegendVisible()
    • isOutlineVisible

      public boolean isOutlineVisible()
      Checks if the plot outline is visible.

      Returns true if the plot's border outline is currently visible.

      Returns:
      true if outline is visible, false otherwise
    • isGridlinesVisible

      public boolean isGridlinesVisible()
    • setGridlinesVisible

      public void setGridlinesVisible(boolean visible)
    • setOutlineVisible

      public void setOutlineVisible(boolean visible)
      Sets the visibility of the plot outline.

      Controls whether the border outline around the plot area is visible.

      Parameters:
      visible - true to show outline, false to hide it
    • setEqualizeAxes

      public void setEqualizeAxes(boolean equalize)
      Sets whether the axes of the underlying XY plot should be equalized (same scale).

      When enabled, both X and Y axes will use the same scale to maintain equal aspect ratio. When disabled, each axis maximizes its range.

      Parameters:
      equalize - true to equalize axes, false otherwise
      Throws:
      IllegalArgumentException - if the underlying plot is not a XY plot
    • isEqualized

      public boolean isEqualized()
      Checks if the axes of the underlying XY plot are equalized.

      Returns true if both X and Y axes use the same scale.

      Returns:
      true if axes are equalized, false otherwise
    • setLegendVisible

      public void setLegendVisible(boolean visible)
    • annotateCategory

      public void annotateCategory(String category, String label)
      Annotates the specified category (Category plots only)
      Parameters:
      category - the category to be annotated. Ignored if it does not exist in category axis.
      label - the annotation label
    • annotateCategory

      public void annotateCategory(String category, String label, String color)
      Annotates the specified category (Category plots only).
      Parameters:
      category - the category to be annotated. Ignored if it does not exist in category axis.
      label - the annotation label
      color - the annotation color
    • setColors

      public void setColors(String... colors)
      (Re)colors existing dataset series
      Parameters:
      colors - The series colors
    • setColors

      public void setColors(net.imglib2.display.ColorTable colorTable)
      (Re)colors existing dataset series
      Parameters:
      colorTable - The colorTable used to recolor series
    • setLineWidth

      public void setLineWidth(int width)
      Changes the line width of all series in a XY plot
      Parameters:
      width - the stroke width
      Throws:
      IllegalArgumentException - if this SNChart is not an XYPlot
    • setChartTitle

      public void setChartTitle(String title)
    • replace

      public void replace(SNTChart other)
      Replaces the current chart with the specified instance
      Parameters:
      other - the instance replacing current contents
    • setFontSize

      public void setFontSize(float size)
      Sets the font size to all components of this chart.
      Parameters:
      size - the new font size
    • setFontSize

      public void setFontSize(float size, String scope)
      Sets the font size for this chart.
      Parameters:
      size - the new font size
      scope - which components should be modified. Either "axes", "legends", or "labels" (singular/plural allowed)
    • getImage

      public ij.ImagePlus getImage()
      Gets an ImagePlus representation of the chart.

      Creates an ImagePlus object containing a rasterized version of the chart at default scaling (1.0x).

      Returns:
      an ImagePlus containing the chart image
    • getImages

      public List<ij.ImagePlus> getImages(float scalingFactor)
    • setTitle

      public void setTitle(String title)
    • getTitle

      public String getTitle()
    • save

      public boolean save(File file)
      Saves this chart.
      Parameters:
      file - the output file (null not permitted). The extension of its filename (".svg", ".png", ".pdf"), determines the file format
      Returns:
      true if file was successfully saved, false otherwise
    • save

      public boolean save(String filePath, double scalingFactor)
      Saves this chart.
      Parameters:
      filePath - the path of the output file (null not permitted). Its filename extension (".svg", ".png", ".pdf"), determines the file format.
      Returns:
      true if file was successfully saved, false otherwise
    • saveAsPNG

      public void saveAsPNG(File file) throws IOException
      Throws:
      IOException
    • saveAsPNG

      public void saveAsPNG(File file, double scalingFactor) throws IOException
      Throws:
      IOException
    • saveAsPNG

      public void saveAsPNG(String filePath) throws IOException
      Throws:
      IOException
    • saveAsPNG

      public void saveAsPNG(String filePath, double scalingFactor) throws IOException
      Throws:
      IOException
    • saveAsPDF

      public void saveAsPDF(String filePath) throws IOException
      Throws:
      IOException
    • saveAsPDF

      public void saveAsPDF(String filePath, double scalingFactor) throws IOException
      Throws:
      IOException
    • saveAsPDF

      public void saveAsPDF(File file, double scalingFactor) throws IOException
      Throws:
      IOException
    • saveAsSVG

      public void saveAsSVG(String filePath) throws IOException
      Throws:
      IOException
    • saveAsSVG

      public void saveAsSVG(String filePath, double scalingFactor) throws IOException
      Throws:
      IOException
    • saveAsSVG

      public void saveAsSVG(File file, double scalingFactor) throws IOException
      Throws:
      IOException
    • applyStyle

      public void applyStyle(SNTChart template)
    • addPolygon

      public void addPolygon(net.imglib2.roi.geom.real.Polygon2D poly, String lineColor, String fillColor)
    • addPolygon

      public void addPolygon(net.imglib2.roi.geom.real.Polygon2D poly, org.scijava.util.ColorRGB lineColor, org.scijava.util.ColorRGB fillColor)
    • annotate

      public void annotate(String label)
      Adds a subtitle to the chart.
      Parameters:
      label - the subtitle text
    • annotate

      public void annotate(String label, String tooltip, String alignment)
      Adds a subtitle to the chart.
      Parameters:
      label - the subtitle text
      tooltip - the tooltip text. null permitted
      alignment - either 'left', 'center', or 'right'
    • annotatePoint

      public void annotatePoint(double x, double y, String label)
      Highlights a point in a histogram/XY plot by drawing a labeled arrow at the specified location.
      Parameters:
      x - the x-coordinate
      y - the y-coordinate
      label - the annotation label
    • annotatePoint

      public void annotatePoint(double x, double y, String label, String color)
      Highlights a point in a histogram/XY plot by drawing a labeled arrow at the specified location.
      Parameters:
      x - the x-coordinate
      y - the y-coordinate
      label - the annotation label
      color - the annotation color
    • annotatePoint

      public void annotatePoint(double[] coordinates, String label, String color)
      Highlights a point in a histogram/XY plot by drawing a labeled arrow at the specified location.
      Parameters:
      coordinates - the array holding the focal point coordinates of the profile
      label - the annotation label
      color - the annotation color
    • getDefaultDirectoryForSaveAs

      public File getDefaultDirectoryForSaveAs()
      Overrides:
      getDefaultDirectoryForSaveAs in class org.jfree.chart.ChartPanel
    • show

      public void show(int width, int height)
      Shows this chart on a dedicated frame
      Parameters:
      width - the preferred frame width
      height - the preferred frame height
    • dispose

      public void dispose()
      Disposes of this chart and releases its resources.

      Closes the chart window and removes it from the list of open instances. This method should be called when the chart is no longer needed to prevent memory leaks.

    • containsValidData

      public boolean containsValidData()
      Checks if the chart contains valid data.

      Returns true if the chart object exists and presumably contains data that can be displayed.

      Returns:
      whether chart contains valid Data
    • setGaussianFitVisible

      public void setGaussianFitVisible(boolean visible)
      Sets whether a normal distribution curve should be overlaid over histogram frequencies.
      Parameters:
      visible - whether curve should be displayed. Ignored if current chart is not a histogram
    • setGMMFitVisible

      public void setGMMFitVisible(boolean visible)
      Sets whether a GMM distribution curve should be overlaid over histogram frequencies.
      Parameters:
      visible - whether curve should be displayed. Ignored if current chart is not a histogram
    • isQuartilesVisible

      public boolean isQuartilesVisible()
      Gets whether quartile markers (Q1, Median, Q3) are being overlaid over histogram frequencies
      Returns:
      true if current chart is a histogram with overlaid quartile markers
    • setQuartilesVisible

      public void setQuartilesVisible(boolean visible)
      Sets whether quartile markers (Q1, Median, Q3) should be overlaid over histogram frequencies.
      Parameters:
      visible - whether markers should be displayed. Ignored if current chart is not a histogram
    • isNormDistributionVisible

      public boolean isNormDistributionVisible()
      Gets whether a normal distribution curve is being overlaid over histogram frequencies
      Returns:
      true if current chart is a histogram with overlaid normal curve
    • isGMMDistributionVisible

      public boolean isGMMDistributionVisible()
      Gets whether the GMM distribution curve is being overlaid over histogram frequencies
      Returns:
      true if current chart is a histogram with overlaid GMM curve
    • setVisible

      @Deprecated public void setVisible(boolean b)
      Deprecated.
      Overrides:
      setVisible in class JComponent
    • show

      public void show()
      Overrides:
      show in class Component
    • show

      public void show(String title)
    • exportAsCSV

      protected void exportAsCSV(File file) throws IllegalStateException
      Throws:
      IllegalStateException
    • isCombined

      public boolean isCombined()
      Checks if this chart is part of a multi-panel montage
      Returns:
      true, if is combined
    • addColorBarLegend

      public void addColorBarLegend(String title, net.imglib2.display.ColorTable colorTable, double min, double max, int nDecimalPlaces)
      Adds a color bar legend (LUT ramp).
      Parameters:
      title - the color bar label
      colorTable - the color table
      min - the minimum value in the color table
      max - the maximum value in the color table
      nDecimalPlaces - the number of decimal places in the legend labels
    • getPaintScaleLegend

      public static org.jfree.chart.title.PaintScaleLegend getPaintScaleLegend(String title, net.imglib2.display.ColorTable colorTable, double min, double max, int nDecimalPlaces)
    • openCharts

      public static List<SNTChart> openCharts()
      Returns:
      a list of all opened charts
    • closeAll

      public static void closeAll()
      Closes all open charts
    • tileAll

      public static void tileAll()
      Tiles all open charts displaying them on a grid. Charts's windows are made visible if not displayed.
    • tile

      public static void tile(Collection<SNTChart> charts)
      Tiles specified charts displaying them on a grid. Charts's windows are made visible if not displayed.
      Parameters:
      charts - the charts to be tiled
    • combineAsImagePlus

      public static ij.ImagePlus combineAsImagePlus(Collection<SNTChart> charts)
      Combines a collection of charts into a ImageJ1 stack.
      Parameters:
      charts - input charts
      Returns:
      the stack as an ImagePlus (RGB)
    • combine

      public static SNTChart combine(Collection<SNTChart> charts)
      Combines a collection of charts into a multipanel montage. Number of rows and columns is automatically determined.
      Parameters:
      charts - input charts
      Returns:
      the frame containing the montage.
    • combine

      public static SNTChart combine(Collection<SNTChart> charts, boolean labelPanels)
      Combines a collection of charts into a multipanel montage. Number of rows and columns is automatically determined.
      Parameters:
      charts - input charts
      labelPanels - whether each panel in the montage should be labeled
      Returns:
      the frame containing the montage.
    • combine

      public static SNTChart combine(Collection<SNTChart> charts, int rows, int cols, boolean labelPanels)
      Combines a collection of charts into a multipanel montage.
      Parameters:
      charts - input charts
      rows - the number of rows in the montage
      cols - the number of columns in the montage
      labelPanels - whether each panel in the montage should be labeled
      Returns:
      the frame containing the montage
    • combine

      public static SNTChart combine(Collection<SNTChart> charts, String commonTitle, int rows, int cols, boolean labelPanels)
      Combines a collection of charts into a multipanel montage.
      Parameters:
      charts - input charts
      commonTitle - Common title for the montage
      rows - the number of rows in the montage
      cols - the number of columns in the montage
      labelPanels - whether each panel in the montage should be labeled
      Returns:
      the frame containing the montage
    • showHistogram3D

      public static void showHistogram3D(double[][] data, net.imglib2.display.ColorTable colorTable, boolean prob, String... axisLabels) throws InterruptedException, InvocationTargetException
      Shows a bivariate histogram (two-dimensional histogram) from a matrix. The number of bins is automatically determined using the Freedman-Diaconis rule.
      Parameters:
      data - the matrix holding the two distributions to be plotted
      colorTable - the color table (LUT) used to color histogram bars (null allowed)
      prob - Whether frequencies should be normalized to probabilities
      axisLabels - Labels for the axes (optional)
      Throws:
      InterruptedException - if the histogram cannot be displayed
      InvocationTargetException - if the histogram cannot be displayed
    • showHeatmap

      public static void showHeatmap(double[][] data, net.imglib2.display.ColorTable colorTable, String... axisLabels) throws InterruptedException, InvocationTargetException
      Shows a two-dimensional heatmap from a two-dimensional data matrix.
      Parameters:
      data - the two-dimensional matrix holding the data to be plotted
      colorTable - the heatmap color table (LUT) (null not allowed)
      axisLabels - Labels for the axes (optional)
      Throws:
      InterruptedException - if the heatmap cannot be displayed
      InvocationTargetException - if the heatmap cannot be displayed
    • showHistogram3D

      public static void showHistogram3D(Collection<Double> values1, Collection<Double> values2, net.imglib2.display.ColorTable colorTable, String... axisLabels) throws InterruptedException, InvocationTargetException
      Shows a bivariate histogram (two-dimensional histogram) from two collections of values. The number of bins is automatically determined using the Freedman-Diaconis rule.
      Parameters:
      values1 - the values of the first distribution to be plotted
      values2 - the values of the second distribution to be plotted
      colorTable - the color table (LUT) used to color histogram bars (null allowed)
      axisLabels - Labels for the axes (optional)
      Throws:
      InterruptedException - if the histogram cannot be displayed
      InvocationTargetException - if the histogram cannot be displayed
    • showHeatmap

      public static void showHeatmap(Collection<Double> values1, Collection<Double> values2, net.imglib2.display.ColorTable colorTable, String... axisLabels) throws InterruptedException, InvocationTargetException
      Shows a two-dimensional heatmap for a two-dimensional data matrix assembled from two collections
      Parameters:
      values1 - the values of the first matrix column
      values2 - the values of the second matrix column
      colorTable - the heatmap color table (LUT) (null not allowed)
      axisLabels - Labels for the axes (optional)
      Throws:
      InterruptedException - if the heatmap cannot be displayed
      InvocationTargetException - if the heatmap cannot be displayed
    • showHistogram3D

      public static void showHistogram3D(org.apache.commons.math3.stat.descriptive.DescriptiveStatistics stats1, org.apache.commons.math3.stat.descriptive.DescriptiveStatistics stats2, net.imglib2.display.ColorTable colorTable, String... axisLabels) throws InterruptedException, InvocationTargetException
      Shows a bivariate histogram (two-dimensional histogram) from two DescriptiveStatistics objects. The number of bins is automatically determined using the Freedman-Diaconis rule.
      Parameters:
      stats1 - DescriptiveStatistics for the first distribution
      stats2 - DescriptiveStatistics for the second distribution
      colorTable - the color table (LUT) used to color histogram bars (Null allowed)
      axisLabels - Labels for the axes (optional)
      Throws:
      InterruptedException - if the histogram cannot be displayed
      InvocationTargetException - if the histogram cannot be displayed
    • setDefaultFontScale

      public static void setDefaultFontScale(double scalingFactor)
    • getHistogram

      public static SNTChart getHistogram(SNTTable table, Collection<String> columnHeaders, boolean polar)
      Creates a histogram from the given table. The number of bins is automatically determined using the Freedman-Diaconis rule.
      Parameters:
      table - the table holding the data to be plotted
      columnHeaders - the headers of the columns to be plotted (case-sensitive)
      polar - whether the histogram should be polar. Data expected in degrees ]0, 360]
      Returns:
      the histogram chart
    • getHistogram

      public static SNTChart getHistogram(SNTTable table, int[] columnIndices, boolean polar)
      Creates a histogram from the given table. The number of bins is automatically determined using the Freedman-Diaconis rule.
      Parameters:
      table - the table holding the data to be plotted
      columnIndices - the indices (0-based) of the columns to be plotted
      polar - whether the histogram should be polar. Data expected in degrees ]0, 360]
      Returns:
      the histogram chart
    • getHistogram

      public static SNTChart getHistogram(SNTTable table, boolean polar)
    • main

      public static void main(String[] args)