Class Charts.ScatterChartBuilder

java.lang.Object
qupath.lib.gui.charts.Charts.ScatterChartBuilder
Enclosing class:
Charts

public static class Charts.ScatterChartBuilder extends Object
Builder for creating scatter charts.
  • Field Details

    • xLabel

      protected String xLabel
    • yLabel

      protected String yLabel
    • viewer

      protected QuPathViewer viewer
    • imageData

      protected ImageData<?> imageData
    • title

      protected String title
    • legendVisible

      protected boolean legendVisible
    • legendSide

      protected Side legendSide
    • markerOpacity

      protected double markerOpacity
    • width

      protected double width
    • height

      protected double height
  • Method Details

    • limitDatapoints

      public Charts.ScatterChartBuilder limitDatapoints(int max)
      Choose the maximum number of supported datapoints per series. Scattercharts are rather 'heavyweight', and including many thousands of datapoints can cause severe performance issues due to high processing and memory requirements.

      By default, datapoints will be randomly subsampled to a 'manageable number' where necessary, which can be customized with this setting.

      Parameters:
      max - the maximum number of data points to show per series
      Returns:
      this builder
      See Also:
    • unlimitedDatapoints

      public Charts.ScatterChartBuilder unlimitedDatapoints()
      Show all datapoints, without subsampling, even when this may cause performance issues. Use with caution.
      Returns:
      this builder
      See Also:
    • getDefaultWindowTitle

      protected String getDefaultWindowTitle()
      Get a window title to use for charts of this kind, assuming the user has not specified one.
      Returns:
      a suitable title to use
    • random

      public Charts.ScatterChartBuilder random(Random rnd)
      Set the random number generator.
      Parameters:
      rnd - A random number generator
      Returns:
      A modified builder.
    • centroids

      public <T> Charts.ScatterChartBuilder centroids(Collection<? extends PathObject> pathObjects, PixelCalibration cal)
      Plot centroids for the specified objects using a fixed pixel calibration.
      Parameters:
      pathObjects - the objects to plot
      cal - the pixel calibration used to convert the centroids into other units
      Returns:
      this builder
    • centroids

      public Charts.ScatterChartBuilder centroids(Collection<? extends PathObject> pathObjects)
      Plot centroids for the specified objects in pixel units.
      Parameters:
      pathObjects - the objects to plot.
      Returns:
      this builder
    • measurements

      public Charts.ScatterChartBuilder measurements(Collection<? extends PathObject> pathObjects, String xMeasurement, String yMeasurement)
      Plot two measurements against one another for the specified objects.
      Parameters:
      pathObjects - the objects to plot
      xMeasurement - the measurement to extract from each object's measurement list for the x location
      yMeasurement - the measurement to extract from each object's measurement list for the y location
      Returns:
      this builder
    • addSeries

      public <T> Charts.ScatterChartBuilder addSeries(String name, Collection<? extends T> collection, Function<T,Number> xFun, Function<T,Number> yFun)
      Add values extracted from objects within a specified collection.
      Type Parameters:
      T - The type of input for X and Y.
      Parameters:
      name - the name of the data series (useful if multiple series will be plotted, otherwise may be null)
      collection - the objects to plot
      xFun - function capable of extracting a numeric value for the x location from each object in the collection
      yFun - function capable of extracting a numeric value for the y location from each object in the collection
      Returns:
      this builder
    • addSeries

      public Charts.ScatterChartBuilder addSeries(String name, Collection<? extends Number> x, Collection<? extends Number> y)
      Create and add a scatterplot using collections of numeric values.
      Parameters:
      name - the name of the data series (useful if multiple series will be plot, otherwise may be null)
      x - The x variable
      y - The y variable
      Returns:
      this builder
    • addSeries

      public Charts.ScatterChartBuilder addSeries(String name, double[] x, double[] y)
      Create and add a scatterplot using arrays of numeric values.
      Parameters:
      name - the name of the data series (useful if multiple series will be plot, otherwise may be null)
      x - x-values
      y - y-values
      Returns:
      this builder
    • addSeries

      public <T> Charts.ScatterChartBuilder addSeries(String name, double[] x, double[] y, T[] extra)
      Create and add a scatterplot using collections of numeric values, with an associated custom object.
      Type Parameters:
      T - The type of custom object.
      Parameters:
      name - the name of the data series (useful if multiple series will be plot, otherwise may be null)
      x - x-values
      y - y-values
      extra - array of values to associate with each data point; should be the same length as x and y
      Returns:
      this builder
    • addSeries

      public <T> Charts.ScatterChartBuilder addSeries(String name, double[] x, double[] y, List<T> extra)
      Create and add a scatterplot series using collections of numeric values, with an associated custom object.
      Type Parameters:
      T - The type of custom object.
      Parameters:
      name - the name of the data series (useful if multiple series will be plot, otherwise may be null)
      x - x-values
      y - y-values
      extra - list of values to associate with each data point; should be the same length as x and y
      Returns:
      this builder
    • addSeries

      Create and add a scatterplot series from existing data.
      Parameters:
      name - the name of the data series (useful if multiple series will be plot, otherwise may be null)
      data - the data points to plot
      Returns:
      this builder
    • addSeries

      Create a scatterplot series from existing data.
      Parameters:
      series - the data points to plot
      Returns:
      this builder
    • createSeriesFromMeasurements

      public static XYChart.Series<Number,Number> createSeriesFromMeasurements(Collection<? extends PathObject> pathObjects, String xMeasurement, String yMeasurement)
      Create a data series from two measurements for the specified objects.
      Parameters:
      pathObjects - the objects to plot
      xMeasurement - the measurement to extract from each object's measurement list for the x location
      yMeasurement - the measurement to extract from each object's measurement list for the y location
      Returns:
      a series of data
    • createSeries

      public static <T> XYChart.Series<Number,Number> createSeries(String name, Collection<? extends T> collection, Function<T,Number> xFun, Function<T,Number> yFun)
      Create a data series extracted from objects within a specified collection.
      Type Parameters:
      T - The type of input for X and Y.
      Parameters:
      name - the name of the data series (useful if multiple series will be plotted, otherwise may be null)
      collection - the objects to plot
      xFun - function capable of extracting a numeric value for the x location from each object in the collection
      yFun - function capable of extracting a numeric value for the y location from each object in the collection
      Returns:
      a series of data
    • createSeries

      public static XYChart.Series<Number,Number> createSeries(String name, Collection<? extends Number> x, Collection<? extends Number> y)
      Create a series using collections of numeric values.
      Parameters:
      name - the name of the data series (useful if multiple series will be plot, otherwise may be null)
      x - The x variable
      y - The y variable
      Returns:
      a series of data
    • createSeries

      public static XYChart.Series<Number,Number> createSeries(String name, double[] x, double[] y)
      Create a scatterplot using arrays of numeric values.
      Parameters:
      name - the name of the data series (useful if multiple series will be plotted, otherwise may be null)
      x - x-values
      y - y-values
      Returns:
      a series of data
    • createSeries

      public static <T> XYChart.Series<Number,Number> createSeries(String name, double[] x, double[] y, T[] extra)
      Create a series of data using collections of numeric values, with an associated custom object.
      Type Parameters:
      T - The type of custom object.
      Parameters:
      name - the name of the data series (useful if multiple series will be plotted, otherwise may be null)
      x - x-values
      y - y-values
      extra - array of values to associate with each data point; should be the same length as x and y
      Returns:
      a series of data
    • createSeries

      public static <T> XYChart.Series<Number,Number> createSeries(String name, double[] x, double[] y, List<T> extra)
      Create a scatterplot using collections of numeric values, with an associated custom object.
      Type Parameters:
      T - The type of custom object.
      Parameters:
      name - the name of the data series (useful if multiple series will be plotted, otherwise may be null)
      x - x-values
      y - y-values
      extra - list of values to associate with each data point; should be the same length as x and y
      Returns:
      a series of data
    • updateChart

      protected void updateChart(ScatterChart<Number,Number> chart)
      Method that applies properties of this builder to the chart. Each subclass should call the method in the parent class to ensure its properties have been applied.
      Parameters:
      chart -
    • createNewChart

      protected ScatterChart<Number,Number> createNewChart(Axis<Number> xAxis, Axis<Number> yAxis)
    • tryToSelect

      public static void tryToSelect(PathObject pathObject, QuPathViewer viewer, ImageData<?> imageData, boolean addToSelection, boolean centerObject)
      Try to select an object if possible (e.g. because a user clicked on it).
      Parameters:
      pathObject - the object to select
      addToSelection - if true, add to an existing selection; if false, reset any current selection
      centerObject - if true, try to center it in a viewer (if possible)
    • getThis

      protected Charts.ScatterChartBuilder getThis()
    • build

      public ScatterChart<Number,Number> build()
      Build a chart according to the specified parameters.
      Returns:
      the chart
    • xAxisMin

      public Charts.ScatterChartBuilder xAxisMin(double lowerBound)
      Set the lower bound for the x-axis.
      Parameters:
      lowerBound -
      Returns:
      this builder
    • yAxisMin

      public Charts.ScatterChartBuilder yAxisMin(double lowerBound)
      Set the lower bound for the y-axis.
      Parameters:
      lowerBound -
      Returns:
      this builder
    • xAxisMax

      public Charts.ScatterChartBuilder xAxisMax(double upperBound)
      Set the upper bound for the x-axis.
      Parameters:
      upperBound -
      Returns:
      this builder
    • yAxisMax

      public Charts.ScatterChartBuilder yAxisMax(double upperBound)
      Set the upper bound for the y-axis.
      Parameters:
      upperBound -
      Returns:
      this builder
    • xAxisRange

      public Charts.ScatterChartBuilder xAxisRange(double lowerBound, double upperBound)
      Set the lower and upper bounds for the x-axis.
      Parameters:
      lowerBound -
      upperBound -
      Returns:
      this builder
    • yAxisRange

      public Charts.ScatterChartBuilder yAxisRange(double lowerBound, double upperBound)
      Set the lower and upper bounds for the y-axis.
      Parameters:
      lowerBound -
      upperBound -
      Returns:
      this builder
    • createNewChart

      protected ScatterChart<Number,Number> createNewChart()
    • xLabel

      public Charts.ScatterChartBuilder xLabel(String label)
      Specify the x-axis label.
      Parameters:
      label - the label to display
      Returns:
      this builder
    • yLabel

      public Charts.ScatterChartBuilder yLabel(String label)
      Specify the y-axis label.
      Parameters:
      label - the label to display
      Returns:
      this builder
    • title

      public Charts.ScatterChartBuilder title(String title)
      Specify the chart title.
      Parameters:
      title - the title to display
      Returns:
      this builder
    • legend

      public Charts.ScatterChartBuilder legend(boolean show)
      Specify whether the legend should be shown or not.
      Parameters:
      show - if true, show the legend; otherwise hide the legend
      Returns:
      this builder
    • legend

      public Charts.ScatterChartBuilder legend(String side)
      Specify the side of the chart where the legend should be shown. Valid values are "top", "bottom", "left", "right".

      Any other value (including null) will result in the legend being hidden.

      Parameters:
      side - the side where the legend should be shown
      Returns:
      this builder
    • legend

      public Charts.ScatterChartBuilder legend(Side side)
      Specify the side of the chart where the legend should be shown. If null, the legend will be hidden.
      Parameters:
      side - the side where the legend should be shown
      Returns:
      this builder
    • markerOpacity

      public Charts.ScatterChartBuilder markerOpacity(double opacity)
      Specify the marker opacity.
      Parameters:
      opacity - value between 0 (transparent) and 1 (opaque).
      Returns:
      this builder
    • imageData

      public Charts.ScatterChartBuilder imageData(ImageData<?> imageData)
      Specify an ImageData object. This can be used to make some charts 'live', e.g. if they relate to objects within the hierarchy of this data.
      Parameters:
      imageData - the imageData to associated with this chart
      Returns:
      this builder
    • viewer

      public Charts.ScatterChartBuilder viewer(QuPathViewer viewer)
      Specify a viewer. This can be used to make some charts 'live', e.g. if they relate to objects within the viewer.
      Parameters:
      viewer - the viewer to associated with this chart
      Returns:
      this builder
    • width

      public Charts.ScatterChartBuilder width(double width)
      Set the preferred width of the chart.
      Parameters:
      width - preferred width
      Returns:
      this builder
    • height

      public Charts.ScatterChartBuilder height(double height)
      Set the preferred height of the chart.
      Parameters:
      height - preferred height
      Returns:
      this builder
    • size

      public Charts.ScatterChartBuilder size(double width, double height)
      Set the preferred size of the chart.
      Parameters:
      width - preferred width
      height - preferred height
      Returns:
      this builder
    • parent

      public Charts.ScatterChartBuilder parent(Window parent)
      Set the parent window. If not set, QuPath will try to choose a sensible default. This is useful to avoid the chart falling 'behind' other windows when not in focus.

      This is relevant only if show() or toStage() will be called.

      Parameters:
      parent - the requested parent window
      Returns:
      this builder
    • windowTitle

      public Charts.ScatterChartBuilder windowTitle(String title)
      Title to use for the window, if the chart is shown.

      This is relevant only if show() or toStage() will be called.

      Parameters:
      title - window title
      Returns:
      this builder
    • toStage

      public Stage toStage()
      Add the chart to a stage, but do not show it.
      Returns:
      the stage containing this Chart.
      See Also:
    • show

      public Stage show()
      Add the chart to a stage, and show it in the Application thread.
      Returns:
      the stage containing this Chart.
      See Also: