Skip to content

Commit a7b04be

Browse files
author
mpschr
committed
adapt colored label header for new annotation values
1 parent 8b9fd4b commit a7b04be

File tree

8 files changed

+72
-20
lines changed

8 files changed

+72
-20
lines changed

org.gitools.heatmap/src/main/java/org/gitools/heatmap/header/HeatmapColoredLabelsHeader.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@
4141

4242
@XmlAccessorType(XmlAccessType.NONE)
4343
@XmlRootElement
44-
public class
45-
HeatmapColoredLabelsHeader extends HeatmapHeader {
44+
public class HeatmapColoredLabelsHeader extends HeatmapHeader {
4645

4746
private static final String THICKNESS_CHANGED = "thickness";
4847
private static final String SEPARATION_GRID_CHANGED = "separationGrid";

org.gitools.ui.app/src/main/java/org/gitools/ui/app/actions/edit/EditAnnotationValueAction.java

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@
2121
*/
2222
package org.gitools.ui.app.actions.edit;
2323

24+
import org.gitools.api.analysis.Clusters;
2425
import org.gitools.api.matrix.MatrixDimensionKey;
2526
import org.gitools.heatmap.Heatmap;
27+
import org.gitools.heatmap.header.ColoredLabel;
28+
import org.gitools.heatmap.header.HeatmapColoredLabelsHeader;
2629
import org.gitools.heatmap.header.HeatmapHeader;
2730
import org.gitools.heatmap.header.HierarchicalClusterHeatmapHeader;
2831
import org.gitools.matrix.model.matrix.AnnotationMatrix;
@@ -37,12 +40,17 @@
3740
import org.gitools.ui.platform.settings.ISettingsSection;
3841
import org.gitools.ui.platform.settings.SettingsDialog;
3942
import org.gitools.ui.platform.settings.SettingsPanel;
43+
import org.gitools.utils.color.ColorGenerator;
4044
import org.gitools.utils.textpattern.TextPattern;
4145

4246
import javax.swing.*;
47+
import java.awt.*;
4348
import java.awt.event.ActionEvent;
4449
import java.awt.event.ActionListener;
4550
import java.util.*;
51+
import java.util.List;
52+
53+
import static org.gitools.ui.app.commands.AddHeaderColoredLabelsCommand.makeAnnotationClustering;
4654

4755
public class EditAnnotationValueAction extends HeatmapDimensionAction implements IHeatmapHeaderAction {
4856

@@ -169,14 +177,31 @@ private static boolean editable(HeatmapHeader header) {
169177
&& !(header instanceof HierarchicalClusterHeatmapHeader);
170178
}
171179

172-
private static void applyChanges(ChangeAnnotationValueSection annotationValueSection) {
173-
Map<String, String> inputs = annotationValueSection.getInputMap();
174-
List<TextPattern.VariableToken> annotationKeys = annotationValueSection.getAnnotationKeys();
175-
AnnotationMatrix annotations = annotationValueSection.getAnnotations();
176-
for (String s : annotationValueSection.getSelected()) {
180+
private static void applyChanges(ChangeAnnotationValueSection section) {
181+
Map<String, String> inputs = section.getInputMap();
182+
List<TextPattern.VariableToken> annotationKeys = section.getAnnotationKeys();
183+
AnnotationMatrix annotations = section.getAnnotations();
184+
for (String s : section.getSelected()) {
177185
for (TextPattern.VariableToken annotationKey : annotationKeys) {
178186
annotations.setAnnotation(s, annotationKey.toString(), inputs.get(annotationKey.getVariableName()));
187+
}
188+
}
179189

190+
if (section.getHeatmapHeader() instanceof HeatmapColoredLabelsHeader) {
191+
HeatmapColoredLabelsHeader h = (HeatmapColoredLabelsHeader) section.getHeatmapHeader();
192+
List<Color> usedColors = new ArrayList<>();
193+
for (ColoredLabel coloredLabel : h.getClusters()) {
194+
usedColors.add(coloredLabel.getColor());
195+
}
196+
ColorGenerator cg = new ColorGenerator();
197+
cg.initUsed(usedColors);
198+
199+
200+
Clusters results = makeAnnotationClustering(h);
201+
for (String s : results.getClusters()) {
202+
if (!h.getClusters().contains(s)) {
203+
h.getClusters().add(new ColoredLabel(s, cg.next(s)));
204+
}
180205
}
181206
}
182207
}

org.gitools.ui.app/src/main/java/org/gitools/ui/app/commands/AddHeaderColoredLabelsCommand.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
import org.gitools.analysis.clustering.ClusteringData;
2525
import org.gitools.analysis.clustering.ClusteringException;
26-
import org.gitools.analysis.clustering.ClusteringMethod;
2726
import org.gitools.analysis.clustering.annotations.AnnPatClusteringData;
2827
import org.gitools.analysis.clustering.annotations.AnnPatClusteringMethod;
2928
import org.gitools.api.analysis.Clusters;
@@ -80,7 +79,7 @@ public void execute(IProgressMonitor monitor) throws CommandException {
8079

8180
if (autoGenerateColors) {
8281
cls = header.getClusters();
83-
autoGenerateColoredLabels(header, new AnnPatClusteringMethod());
82+
autoGenerateColoredLabels(header);
8483
}
8584

8685

@@ -141,16 +140,21 @@ public static void updateFromClusterResults(HeatmapColoredLabelsHeader header, C
141140
}
142141

143142

144-
public static void autoGenerateColoredLabels(HeatmapColoredLabelsHeader header, ClusteringMethod clusteringMethod) {
143+
public static void autoGenerateColoredLabels(HeatmapColoredLabelsHeader header) {
145144

145+
Clusters results = makeAnnotationClustering(header);
146+
updateFromClusterResults(header, results.getClusters());
147+
148+
}
149+
150+
public static Clusters makeAnnotationClustering(HeatmapColoredLabelsHeader header) {
146151
ClusteringData data = new AnnPatClusteringData(header.getHeatmapDimension(), header.getAnnotationPattern());
147152
Clusters results = null;
148153
try {
149-
results = clusteringMethod.cluster(data, new DefaultProgressMonitor());
154+
results = new AnnPatClusteringMethod().cluster(data, new DefaultProgressMonitor());
150155
} catch (ClusteringException e) {
151156
e.printStackTrace();
152157
}
153-
updateFromClusterResults(header, results.getClusters());
154-
158+
return results;
155159
}
156160
}

org.gitools.ui.app/src/main/java/org/gitools/ui/app/heatmap/header/wizard/coloredlabels/ColoredLabelsHeaderWizard.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
*/
2222
package org.gitools.ui.app.heatmap.header.wizard.coloredlabels;
2323

24-
import org.gitools.analysis.clustering.annotations.AnnPatClusteringMethod;
2524
import org.gitools.heatmap.HeatmapDimension;
2625
import org.gitools.heatmap.header.ColoredLabel;
2726
import org.gitools.heatmap.header.HeatmapColoredLabelsHeader;
@@ -42,7 +41,6 @@ public class ColoredLabelsHeaderWizard extends AbstractWizard {
4241
private final String lastPattern;
4342
private final HeatmapColoredLabelsHeader header;
4443

45-
private final AnnPatClusteringMethod clusteringMethod;
4644

4745
private PatternSourcePage sourcePage;
4846
private ColoredLabelsConfigPage headerPage;
@@ -56,7 +54,6 @@ public ColoredLabelsHeaderWizard(HeatmapDimension hdim, HeatmapColoredLabelsHead
5654
this.lastPattern = "";
5755
this.header = header;
5856

59-
clusteringMethod = new AnnPatClusteringMethod();
6057
}
6158

6259
@Override
@@ -99,7 +96,7 @@ public void pageLeft(IWizardPage currentPage) {
9996
header.setAnnotationMetadata(sourcePage.getSelectedValues()[0]);
10097
}
10198

102-
AddHeaderColoredLabelsCommand.autoGenerateColoredLabels(header, clusteringMethod);
99+
AddHeaderColoredLabelsCommand.autoGenerateColoredLabels(header);
103100

104101
clustersPage.setColoredLabels(header.getClusters());
105102
}

org.gitools.ui.app/src/main/java/org/gitools/ui/app/heatmap/panel/settings/headers/AddNewManualAnnotationSection.form

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
<rowspec value="top:4dlu:noGrow"/>
1010
<rowspec value="center:max(d;4px):noGrow"/>
1111
<rowspec value="top:4dlu:noGrow"/>
12+
<rowspec value="center:max(d;4px):noGrow"/>
13+
<rowspec value="top:4dlu:noGrow"/>
1214
<rowspec value="center:d:noGrow"/>
1315
<rowspec value="top:4dlu:noGrow"/>
1416
<rowspec value="center:max(d;4px):noGrow"/>
@@ -20,14 +22,14 @@
2022
<colspec value="left:4dlu:noGrow"/>
2123
<colspec value="fill:max(d;4px):noGrow"/>
2224
<constraints>
23-
<xy x="20" y="20" width="500" height="400"/>
25+
<xy x="20" y="20" width="524" height="400"/>
2426
</constraints>
2527
<properties/>
2628
<border type="none"/>
2729
<children>
2830
<scrollpane id="f9935">
2931
<constraints>
30-
<grid row="8" column="2" row-span="1" col-span="3" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
32+
<grid row="10" column="2" row-span="1" col-span="3" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
3133
<forms defaultalign-horz="false" defaultalign-vert="false"/>
3234
</constraints>
3335
<properties/>
@@ -43,7 +45,7 @@
4345
</scrollpane>
4446
<component id="2ec6b" class="javax.swing.JLabel">
4547
<constraints>
46-
<grid row="6" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
48+
<grid row="8" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
4749
<forms/>
4850
</constraints>
4951
<properties>
@@ -86,6 +88,16 @@
8688
<text value="Value of new Annotation"/>
8789
</properties>
8890
</component>
91+
<component id="f3380" class="javax.swing.JLabel" binding="explanationLabel">
92+
<constraints>
93+
<grid row="6" column="2" row-span="1" col-span="3" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
94+
<forms/>
95+
</constraints>
96+
<properties>
97+
<font style="0"/>
98+
<text value="Explanation"/>
99+
</properties>
100+
</component>
89101
</children>
90102
</grid>
91103
</form>

org.gitools.ui.app/src/main/java/org/gitools/ui/app/heatmap/panel/settings/headers/AddNewManualAnnotationSection.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,12 @@ public class AddNewManualAnnotationSection extends AbstractSettingsSection {
4242
private JTable currentValuesTable;
4343
private JTextField annotationLabel;
4444
private JTextField annotationValue;
45+
private JLabel explanationLabel;
4546

4647
public AddNewManualAnnotationSection(final AnnotationMatrix annotations, final List<String> selected) {
4748
this.annotations = annotations;
4849
this.selected = selected;
50+
this.explanationLabel.setText("<html><body><i>The annotation is not automatically added as header</i></body></html>");
4951

5052

5153
DocumentChangeListener docListener = new DocumentChangeListener() {

org.gitools.ui.app/src/main/java/org/gitools/ui/app/heatmap/panel/settings/headers/ChangeAnnotationValueSection.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,10 @@ public AnnotationMatrix getAnnotations() {
201201
return annotations;
202202
}
203203

204+
public HeatmapHeader getHeatmapHeader() {
205+
return heatmapHeader;
206+
}
207+
204208
public Map<String, String> getInputMap() {
205209
Map<String, String> m = new HashMap<>();
206210
for (String key : inputMap.keySet()) {

org.gitools.utils/src/main/java/org/gitools/utils/color/ColorGenerator.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
import java.awt.*;
2525
import java.util.ArrayList;
26+
import java.util.List;
27+
import java.util.Random;
2628

2729
public class ColorGenerator {
2830

@@ -45,6 +47,9 @@ private ColorGenerator(int[] palette) {
4547
for (int i = 0; i < palette.length; i++)
4648
this.palette[i] = new Color(palette[i]);
4749
colorRegistry = ColorRegistry.get();
50+
int max = palette.length - 1;
51+
int min = 0;
52+
index = new Random().nextInt((max - min) + 1) + min;
4853
}
4954

5055
public void reset() {
@@ -90,6 +95,10 @@ private boolean isUsed(Color c) {
9095
return false;
9196
}
9297

98+
public void initUsed(List<Color> colors) {
99+
used.addAll(colors);
100+
}
101+
93102
public int getCount() {
94103
return index;
95104
}

0 commit comments

Comments
 (0)