Skip to content

Commit

Permalink
Use Classification object in DendrogramPanel instead of individual ob…
Browse files Browse the repository at this point in the history
…jects cluster, mapping and colors
  • Loading branch information
stefanhahmann committed Nov 2, 2023
1 parent 95f1d77 commit 7c38107
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 25 deletions.
32 changes: 12 additions & 20 deletions src/main/java/org/mastodon/mamut/clustering/ui/DendrogramPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.apporiented.algorithm.clustering.Cluster;
import com.apporiented.algorithm.clustering.visualization.ClusterComponent;
import com.apporiented.algorithm.clustering.visualization.VCoord;
import org.mastodon.mamut.clustering.util.Classification;

import javax.annotation.Nullable;
import javax.swing.JPanel;
Expand All @@ -26,18 +27,12 @@ public class DendrogramPanel< T > extends JPanel

private static final long serialVersionUID = 1L;

private final Cluster cluster;
private final Classification< T > classification;

private final CustomizedClusterComponent component;

private final Map< Cluster, Integer > clusterColors;

private final Map< String, T > leafMapping;

private final ModelMetrics modelMetrics;

private final double cutoff;

private double scaleValueInterval = 0;

private int scaleValueDecimalDigits = 0;
Expand Down Expand Up @@ -67,30 +62,25 @@ public class DendrogramPanel< T > extends JPanel
public DendrogramPanel()
{
super();
this.cluster = null;
this.clusterColors = null;
this.cutoff = 0d;
this.leafMapping = null;
this.classification = null;
this.component = null;
this.modelMetrics = null;
}

public DendrogramPanel(
final Cluster cluster, final Map< Cluster, Integer > clusterColors, final double cutoff, final Map< String, T > leafMapping
)
public DendrogramPanel( final Classification< T > classification )
{
super();
this.cluster = cluster;
this.clusterColors = clusterColors;
this.cutoff = cutoff;
this.leafMapping = leafMapping;
this.component = createComponent( cluster );
this.classification = classification;
this.component = createComponent( classification.getAlgorithmResult() );
this.modelMetrics = createModelMetrics( this.component );
adaptScaleBar();
}

private void adaptScaleBar()
{
if ( classification == null )
return;
Cluster cluster = classification.getAlgorithmResult();
if ( cluster == null )
return;
if ( cluster.getDistanceValue() > 1d )
Expand Down Expand Up @@ -152,7 +142,7 @@ public void paint( Graphics g )
private void paintCutoffLine( final Graphics g, final DisplayMetrics displayMetrics )
{
Stroke stroke = new BasicStroke( 1.75f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 5, 5 }, 0 );
paintVerticalLine( g, stroke, cutoff, displayMetrics );
paintVerticalLine( g, stroke, classification.getCutoff(), displayMetrics );
}

private void paintVerticalLine( final Graphics g, final Stroke stroke, final double xValue, final DisplayMetrics displayMetrics )
Expand Down Expand Up @@ -234,8 +224,10 @@ private CustomizedClusterComponent createComponent(
if ( cluster == null )
return null;

Map< Cluster, Integer > clusterColors = classification.getClusterColors();
if ( clusterColors != null && ( clusterColors.containsKey( cluster ) ) )
color = new Color( clusterColors.get( cluster ) );
Map< String, T > leafMapping = classification.getLeafMapping();
if ( leafMapping != null && cluster.isLeaf() && leafMapping.containsKey( cluster.getName() ) )
cluster.setName( leafMapping.get( cluster.getName() ).toString() );
CustomizedClusterComponent clusterComponent = new CustomizedClusterComponent( cluster, cluster.isLeaf(), initialCoordinate, color );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ public JPanel getPanel()
dendrogramPanel = new DendrogramPanel<>(); // NB: empty dendrogram
else
{
dendrogramPanel = new DendrogramPanel<>( classification.getAlgorithmResult(), classification.getClusterColors(),
classification.getCutoff(), classification.getLeafMapping()
);
dendrogramPanel = new DendrogramPanel<>( classification );
dendrogramPanel.setBackground( Color.WHITE );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
import com.apporiented.algorithm.clustering.Cluster;
import com.apporiented.algorithm.clustering.ClusteringAlgorithm;
import com.apporiented.algorithm.clustering.DefaultClusteringAlgorithm;
import com.apporiented.algorithm.clustering.Distance;
import org.mastodon.mamut.clustering.util.Classification;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.WindowConstants;
import java.awt.BorderLayout;
import java.awt.Color;
import java.util.Collections;

public class DendrogramPanelDemo
{
Expand All @@ -23,7 +24,8 @@ public static void main( String[] args )

JPanel content = new JPanel();
Cluster cluster = createSampleCluster();
DendrogramPanel< String > dp = new DendrogramPanel<>( cluster, null, 6d, null );
Classification< String > classification = new Classification<>( Collections.emptyList(), cluster, null, 6d );
DendrogramPanel< String > dp = new DendrogramPanel<>( classification );

frame.setContentPane( content );
content.setBackground( Color.red );
Expand Down

0 comments on commit 7c38107

Please sign in to comment.