Skip to content

Commit

Permalink
Minor GUI adjustments
Browse files Browse the repository at this point in the history
- fix XZ/ZY plane angles reporting values > 0
- simplify Path Analyzer command
- sort columns before sorting
- polar plot options
- misc
  • Loading branch information
tferr committed Aug 19, 2024
1 parent 85a8500 commit 0282b36
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 74 deletions.
12 changes: 10 additions & 2 deletions src/main/java/sc/fiji/snt/Path.java
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ public double getExtensionAngleXY() {
* @return the overall 'extension' angle in degrees [0-360[ in the XZ plane or zero if path is 2D.
*/
public double getExtensionAngleXZ() {
return getExtensionAngle(MultiDThreePanes.XZ_PLANE);
return (is3D()) ? getExtensionAngle(MultiDThreePanes.XZ_PLANE) : 0;
}

/**
Expand All @@ -500,7 +500,15 @@ public double getExtensionAngleXZ() {
* @return the overall 'extension' angle in degrees [0-360[ in the ZY plane or zero if path is 2D.
*/
public double getExtensionAngleZY() {
return getExtensionAngle(MultiDThreePanes.ZY_PLANE);
return (is3D()) ? getExtensionAngle(MultiDThreePanes.ZY_PLANE) : 0;
}

private boolean is3D() throws IllegalArgumentException {
final double zRef = getNodeWithoutChecks(0).getZ();
for (int i=0; i< size(); i++) {
if (getNodeWithoutChecks(i).getZ() != zRef) return true;
}
return false;
}

private double getExtensionAngle(final int view) {
Expand Down
67 changes: 22 additions & 45 deletions src/main/java/sc/fiji/snt/analysis/SNTChart.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,47 +45,19 @@

import net.imglib2.roi.geom.real.Polygon2D;
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
import org.jfree.chart.ChartMouseEvent;
import org.jfree.chart.ChartMouseListener;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.ChartUtils;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.LegendItem;
import org.jfree.chart.LegendItemSource;
import org.jfree.chart.*;
import org.jfree.chart.annotations.*;
import org.jfree.chart.axis.Axis;
import org.jfree.chart.axis.CategoryAnchor;
import org.jfree.chart.entity.AxisEntity;
import org.jfree.chart.entity.ChartEntity;
import org.jfree.chart.entity.JFreeChartEntity;
import org.jfree.chart.entity.PlotEntity;
import org.jfree.chart.entity.TitleEntity;
import org.jfree.chart.entity.XYAnnotationEntity;
import org.jfree.chart.entity.XYItemEntity;
import org.jfree.chart.plot.CategoryMarker;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.CombinedRangeXYPlot;
import org.jfree.chart.plot.Marker;
import org.jfree.chart.plot.Plot;
import org.jfree.chart.plot.PolarPlot;
import org.jfree.chart.plot.ValueMarker;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.entity.*;
import org.jfree.chart.plot.*;
import org.jfree.chart.plot.flow.FlowPlot;
import org.jfree.chart.renderer.AbstractRenderer;
import org.jfree.chart.renderer.DefaultPolarItemRenderer;
import org.jfree.chart.renderer.category.AbstractCategoryItemRenderer;
import org.jfree.chart.renderer.category.BoxAndWhiskerRenderer;
import org.jfree.chart.renderer.category.CategoryItemRenderer;
import org.jfree.chart.renderer.category.*;
import org.jfree.chart.renderer.xy.XYItemRenderer;
import org.jfree.chart.title.LegendTitle;
import org.jfree.chart.title.PaintScaleLegend;
import org.jfree.chart.title.TextTitle;
import org.jfree.chart.title.Title;
import org.jfree.chart.ui.HorizontalAlignment;
import org.jfree.chart.ui.Layer;
import org.jfree.chart.ui.RectangleAnchor;
import org.jfree.chart.ui.RectangleEdge;
import org.jfree.chart.ui.TextAnchor;
import org.jfree.chart.title.*;
import org.jfree.chart.ui.*;
import org.jfree.data.Range;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.statistics.HistogramDataset;
Expand All @@ -94,8 +66,7 @@
import org.scijava.plot.CategoryChart;
import org.scijava.table.Column;
import org.scijava.ui.awt.AWTWindows;
import org.scijava.ui.swing.viewer.plot.jfreechart.CategoryChartConverter;
import org.scijava.ui.swing.viewer.plot.jfreechart.XYPlotConverter;
import org.scijava.ui.swing.viewer.plot.jfreechart.*;
import org.scijava.util.ColorRGB;
import org.scijava.util.Colors;

Expand Down Expand Up @@ -123,7 +94,6 @@ public class SNTChart extends ChartPanel {
private static final Color BACKGROUND_COLOR = Color.WHITE;
private static final List<SNTChart> openInstances = new ArrayList<>();
private List<SNTChart> otherCombinedCharts;
private LegendTitle stashedLegend;
private JFrame frame;
private String title;

Expand Down Expand Up @@ -153,8 +123,7 @@ protected SNTChart(final String title, final JFreeChart chart, final Dimension p
}
setFontSize(GuiUtils.uiFontSize());
}
// Tweak: Ensure chart is always drawn and not scaled to avoid rendering
// artifacts
// Tweak: Ensure chart is always drawn and not scaled to avoid rendering artifacts
setMinimumDrawWidth(0);
setMaximumDrawWidth(Integer.MAX_VALUE);
setMinimumDrawHeight(0);
Expand Down Expand Up @@ -350,12 +319,8 @@ public void setOutlineVisible(final boolean visible) {
}

public void setLegendVisible(final boolean visible) {
if (visible && stashedLegend != null) {
getChart().addLegend(stashedLegend);
} else if (!visible) {
stashedLegend = getChart().getLegend();
getChart().removeLegend();
}
if (getChart().getLegend() != null)
getChart().getLegend().setVisible(!getChart().getLegend().isVisible());
}

/**
Expand Down Expand Up @@ -1246,6 +1211,7 @@ private void addCustomizationPanel(final JPopupMenu popup) {
grids.add(jmi);
jmi = new JMenuItem("Legend");
jmi.addActionListener( e -> setLegendVisible(!isLegendVisible()));
jmi.setEnabled(getChart().getLegend() != null);
grids.add(jmi);
jmi = new JMenuItem("Outline");
jmi.addActionListener( e -> setOutlineVisible(!isOutlineVisible()));
Expand All @@ -1271,6 +1237,17 @@ private void addCustomizationPanel(final JPopupMenu popup) {
}
});
grids.add(jmi);
GuiUtils.addSeparator(grids, "Polar Plots:");
jmi = new JMenuItem("Clockwise/Counterclockwise");
jmi.addActionListener( e -> {
if (getChart().getPlot() instanceof PolarPlot) {
((PolarPlot) getChart().getPlot()).setCounterClockwise(!((PolarPlot) getChart().getPlot()).isCounterClockwise());
getChart().fireChartChanged();
} else {
new GuiUtils(frame).error("This option requires a polar plot.", "Option Not Available");
}
});
grids.add(jmi);
popup.add(grids);

final JMenu utils = new JMenu("Utilities");
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/sc/fiji/snt/gui/GuiUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -1678,8 +1678,8 @@ public static JMenu helpMenu() {
helpMenu.add(MenuItems.devResourceAPI());
helpMenu.addSeparator();

mi = menuItemTriggeringURL("SNT's Algorithms", "https://github.com/morphonets/SNT/blob/master/NOTES.md#algorithms");
mi.setIcon(IconFactory.getMenuIcon(GLYPH.COGS));
mi = menuItemTriggeringURL("Implemented Algorithms", "https://github.com/morphonets/SNT/blob/master/NOTES.md#algorithms");
mi.setIcon(IconFactory.getMenuIcon(GLYPH.MATH));
helpMenu.add(mi);
mi = menuItemTriggeringURL("SNT Manuscript", "http://dx.doi.org/10.1038/s41592-021-01105-7");
mi.setIcon(IconFactory.getMenuIcon(GLYPH.FILE));
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/sc/fiji/snt/gui/cmds/SNTLoaderCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public class SNTLoaderCmd extends DynamicCommand {
private String SPACER1;

@Parameter(required = false, label = "Reconstruction file", //
description="The reconstruction file to be loaded (.traces, .(e)swc or .json) (optional)",
description="The reconstruction file to be loaded: JSON, NDF, SWC, or TRACES (optional)",
style = FileWidget.OPEN_STYLE, callback = "tracesFileChanged")
private File tracesFile;

Expand All @@ -115,7 +115,7 @@ public class SNTLoaderCmd extends DynamicCommand {

@Parameter(required = false, label = "Tracing channel",
description = DEF_DESCRIPTION, min = "1", //
max = ""+ ij.CompositeImage.MAX_CHANNELS +"", callback = "channelChanged")
max = ""+ ij.CompositeImage.MAX_CHANNELS, callback = "channelChanged")
private int channel;

private Collection<ImagePlus> openImps;
Expand Down
39 changes: 17 additions & 22 deletions src/main/java/sc/fiji/snt/plugin/PathAnalyzerCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@

package sc.fiji.snt.plugin;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;

import org.scijava.ItemVisibility;
import org.scijava.command.Command;
Expand Down Expand Up @@ -65,14 +61,8 @@ public class PathAnalyzerCmd extends CommonDynamicCmd {
@Parameter(label = "Fractal dimension")
private boolean fractalDimension;

@Parameter(label = "Extension angle (XY plane)")
private boolean extensionAngleXY;

@Parameter(label = "Extension angle (XZ plane)")
private boolean extensionAngleXZ;

@Parameter(label = "Extension angle (ZY plane)")
private boolean extensionAngleZY;
@Parameter(label = "Extension angles")
private boolean extensionAngles;

@Parameter(label = "Length")
private boolean pathLength;
Expand All @@ -83,6 +73,9 @@ public class PathAnalyzerCmd extends CommonDynamicCmd {
@Parameter(label = "No. of branch points")
private boolean nBranchPoints;

@Parameter(label = "No. of children")
private boolean nChildren;

@Parameter(label = "No. of nodes (fragmentation)")
private boolean pathFragmentation;

Expand Down Expand Up @@ -146,11 +139,10 @@ private void setAllCheckboxesEnabled(final boolean enable) {
convexHull = enable;
fractalDimension = enable;
nBranchPoints = enable;
nChildren = enable;
pathContraction = enable;
pathFragmentation = enable;
extensionAngleXY = enable;
extensionAngleXZ = enable;
extensionAngleZY = enable;
extensionAngles = enable;
pathLength = enable;
pathMeanRadius = enable;
pathNSpines = enable;
Expand All @@ -167,11 +159,10 @@ private void toggleCheckboxes() {
convexHull = !convexHull;
fractalDimension = !fractalDimension;
nBranchPoints = !nBranchPoints;
nChildren = !nChildren;
pathContraction = !pathContraction;
pathFragmentation = !pathFragmentation;
extensionAngleXY = !extensionAngleXY;
extensionAngleXZ = !extensionAngleXZ;
extensionAngleZY = !extensionAngleZY;
extensionAngles= !extensionAngles;
pathLength = !pathLength;
pathMeanRadius = !pathMeanRadius;
pathNSpines = !pathNSpines;
Expand All @@ -198,11 +189,14 @@ public void run() {
}
if (fractalDimension) metrics.add(PathAnalyzer.PATH_FRACTAL_DIMENSION);
if (nBranchPoints) metrics.add(PathAnalyzer.N_BRANCH_POINTS);
if (nChildren) metrics.add(PathAnalyzer.N_CHILDREN);
if (pathContraction) metrics.add(PathAnalyzer.PATH_CONTRACTION);
if (pathFragmentation) metrics.add(PathAnalyzer.N_PATH_NODES);
if (extensionAngleXY) metrics.add(PathAnalyzer.PATH_EXT_ANGLE_XY);
if (extensionAngleXZ) metrics.add(PathAnalyzer.PATH_EXT_ANGLE_XZ);
if (extensionAngleZY) metrics.add(PathAnalyzer.PATH_EXT_ANGLE_ZY);
if (extensionAngles) {
metrics.add(PathAnalyzer.PATH_EXT_ANGLE_XY);
metrics.add(PathAnalyzer.PATH_EXT_ANGLE_XZ);
metrics.add(PathAnalyzer.PATH_EXT_ANGLE_ZY);
}
if (pathLength) metrics.add(PathAnalyzer.PATH_LENGTH);
if (pathMeanRadius) metrics.add(PathAnalyzer.PATH_MEAN_RADIUS);
if (pathOrder) metrics.add(PathAnalyzer.PATH_ORDER);
Expand All @@ -222,6 +216,7 @@ public void run() {
final PathAnalyzer analyzer = new PathAnalyzer(paths, "");
analyzer.setContext(getContext());
analyzer.setTable(table, TABLE_TITLE);
Collections.sort(metrics);
analyzer.measureIndividualPaths(metrics, summarize); // will display table
resetUI();
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/sc/fiji/snt/plugin/PathSpineAnalysisCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ private void addSeries(final XYPlot plot, final String label, final List<Double>
final ColorRGB color) {
if (y != null) {
final XYSeries series = plot.addXYSeries();
series.setStyle(plotService.newSeriesStyle(color, LineStyle.SOLID, MarkerStyle.FILLEDCIRCLE));
series.setStyle(plotService.newSeriesStyle(color, (anyMetric) ? LineStyle.NONE : LineStyle.SOLID,
MarkerStyle.FILLEDCIRCLE));
series.setValues(x, y);
series.setLabel(label);
}
Expand Down

0 comments on commit 0282b36

Please sign in to comment.