Skip to content

Commit 5016679

Browse files
committed
Add StyleUpdateScope enum. Add JUnits for applying style.
Refs #451
1 parent 9a5c2c2 commit 5016679

File tree

8 files changed

+479
-176
lines changed

8 files changed

+479
-176
lines changed

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/style/EMStyleBuilder.java

Lines changed: 66 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package org.baderlab.csplugins.enrichmentmap.style;
22

3+
import static org.baderlab.csplugins.enrichmentmap.style.EMStyleBuilder.StyleUpdateScope.*;
34
import static org.cytoscape.view.presentation.property.BasicVisualLexicon.*;
4-
import static org.cytoscape.view.presentation.property.NodeShapeVisualProperty.DIAMOND;
5-
import static org.cytoscape.view.presentation.property.NodeShapeVisualProperty.ELLIPSE;
6-
import static org.cytoscape.view.presentation.property.NodeShapeVisualProperty.RECTANGLE;
5+
import static org.cytoscape.view.presentation.property.NodeShapeVisualProperty.*;
76

87
import java.awt.Color;
98
import java.awt.Paint;
@@ -44,10 +43,12 @@
4443
import org.jcolorbrewer.ColorBrewer;
4544

4645
import com.google.inject.Inject;
46+
import com.google.inject.Singleton;
4747

4848
/**
4949
* Responsible for updating the EnrichmentMap styles.
5050
*/
51+
@Singleton
5152
public class EMStyleBuilder {
5253

5354
public final static String DEFAULT_NAME_SUFFIX = "Visual_Style"; // TEMPORARY probably won't be called 'MasterMap' in the final version
@@ -158,13 +159,26 @@ public static class Colors {
158159
private static final Color BG_COLOR = Color.WHITE;
159160
}
160161

162+
163+
public static enum StyleUpdateScope {
164+
ALL,
165+
ONLY_CHARTS,
166+
ONLY_DATASETS,
167+
ONLY_EDGE_WIDTH, // Need to update edge width when Post Analysis is run.
168+
PUBLICATION_READY
169+
}
170+
171+
161172
@Inject private @Continuous VisualMappingFunctionFactory cmFactory;
162173
@Inject private @Discrete VisualMappingFunctionFactory dmFactory;
163174
@Inject private @Passthrough VisualMappingFunctionFactory pmFactory;
164175

165176
@Inject private RenderingEngineManager renderingEngineManager;
166177
@Inject private CyEventHelper eventHelper;
167178

179+
private VisualMappingFunction<?, ?> nonPublicationReadyLabelMapping;
180+
181+
168182
public static String getStyleName(EnrichmentMap map) {
169183
String prefix = map.getParams().getStylePrefix();
170184
return prefix + DEFAULT_NAME_SUFFIX;
@@ -182,66 +196,69 @@ public static NodeShape getDefaultNodeShape(ChartType chartType) {
182196
return chartType == null || chartType == ChartType.RADIAL_HEAT_MAP ? ELLIPSE : RECTANGLE;
183197
}
184198

185-
/**
186-
* Updates the whole EM style.
187-
*/
188-
public void updateProperties(VisualStyle vs, EMStyleOptions options, CyCustomGraphics2<?> chart) {
199+
200+
public void updateStyle(VisualStyle vs, EMStyleOptions options, CyCustomGraphics2<?> chart, StyleUpdateScope scope) {
201+
System.out.println("EMStyleBuilder.updateStyle(): " + scope);
202+
String chartName = chart != null ? chart.getDisplayName() : null;
203+
ChartType chartType = ChartType.toChartType(chartName);
204+
189205
eventHelper.silenceEventSource(vs);
190206

191207
try {
192-
// Network Properties
193-
vs.setDefaultValue(NETWORK_BACKGROUND_PAINT, Colors.BG_COLOR);
194-
195-
setEdgeDefaults(vs, options);
196-
setEdgePaint(vs, options);
197-
setEdgeWidth(vs, options);
198-
setEdgeLineType(vs, options);
199-
200-
String chartName = chart != null ? chart.getDisplayName() : null;
201-
ChartType chartType = ChartType.toChartType(chartName);
202-
203-
setNodeDefaults(vs, options, chartType);
204-
setNodeShapes(vs, options, chartType);
205-
setNodeSize(vs, options, chartType);
206-
setNodeBorderColors(vs, options);
207-
setNodeColors(vs, options);
208-
setNodeLabels(vs, options);
209-
setNodeTooltip(vs, options);
210-
setNodeChart(vs, chart);
211-
212-
if (options.isPublicationReady()) {
213-
vs.removeVisualMappingFunction(BasicVisualLexicon.NODE_LABEL);
214-
vs.setDefaultValue(BasicVisualLexicon.NODE_LABEL, "");
215-
vs.setDefaultValue(BasicVisualLexicon.NETWORK_BACKGROUND_PAINT, Color.WHITE);
208+
if(scope == ALL) {
209+
vs.setDefaultValue(NETWORK_BACKGROUND_PAINT, Colors.BG_COLOR);
210+
setEdgeDefaults(vs, options);
211+
setEdgePaint(vs, options);
212+
setEdgeLineType(vs, options);
213+
setEdgeWidth(vs, options);
214+
setNodeShapes(vs, options, chartType);
215+
setNodeSize(vs, options, chartType);
216+
setNodeChart(vs, chart);
217+
setNodeColors(vs, options);
218+
setNodeDefaults(vs, options, chartType);
219+
setNodeBorderColors(vs, options);
220+
setNodeLabels(vs, options);
221+
setNodeTooltip(vs, options);
222+
}
223+
else if(scope == ONLY_EDGE_WIDTH) {
224+
setEdgeWidth(vs, options);
225+
}
226+
else if(scope == ONLY_CHARTS) {
227+
setNodeChartDefaults(vs, chartType);
228+
setNodeShapes(vs, options, chartType);
229+
setNodeSize(vs, options, chartType);
230+
setNodeChart(vs, chart);
231+
}
232+
else if(scope == ONLY_DATASETS) {
233+
setEdgePaint(vs, options);
234+
setNodeColors(vs, options);
235+
}
236+
else if(scope == PUBLICATION_READY) {
237+
if (options.isPublicationReady()) {
238+
nonPublicationReadyLabelMapping = vs.getVisualMappingFunction(NODE_LABEL);
239+
vs.removeVisualMappingFunction(NODE_LABEL);
240+
vs.setDefaultValue(NODE_LABEL, "");
241+
vs.setDefaultValue(NETWORK_BACKGROUND_PAINT, Color.WHITE);
242+
} else {
243+
if(nonPublicationReadyLabelMapping != null) {
244+
vs.addVisualMappingFunction(nonPublicationReadyLabelMapping);
245+
} else {
246+
setNodeLabels(vs, options);
247+
}
248+
vs.setDefaultValue(NETWORK_BACKGROUND_PAINT, Colors.BG_COLOR);
249+
}
216250
}
217251
} finally {
218252
eventHelper.unsilenceEventSource(vs);
219253
eventHelper.addEventPayload(vs, new VisualStyleChangeRecord(), VisualStyleChangedEvent.class);
220254
}
221255
}
222256

223-
public void updateNodeChart(VisualStyle vs, EMStyleOptions options, CyCustomGraphics2<?> chart) {
224-
eventHelper.silenceEventSource(vs);
225-
226-
try {
227-
String chartName = chart != null ? chart.getDisplayName() : null;
228-
ChartType chartType = ChartType.toChartType(chartName);
229-
230-
setNodeChartDefaults(vs, chartType);
231-
setNodeShapes(vs, options, chartType);
232-
setNodeSize(vs, options, chartType);
233-
setNodeChart(vs, chart);
234-
} finally {
235-
eventHelper.unsilenceEventSource(vs);
236-
eventHelper.addEventPayload(vs, new VisualStyleChangeRecord(), VisualStyleChangedEvent.class);
237-
}
238-
}
239257

240258
@SuppressWarnings({ "rawtypes", "unchecked" })
241259
private void setNodeChart(VisualStyle vs, CyCustomGraphics2<?> chart) {
242260
VisualLexicon lexicon = renderingEngineManager.getDefaultVisualLexicon();
243261
VisualProperty customPaint1 = lexicon.lookup(CyNode.class, "NODE_CUSTOMGRAPHICS_1");
244-
245262
if (customPaint1 != null)
246263
vs.setDefaultValue(customPaint1, chart);
247264
}
@@ -452,7 +469,7 @@ private void setNodeBorderColors(VisualStyle vs, EMStyleOptions options) {
452469

453470
try {
454471
dm.putMapValue(Columns.NODE_GS_TYPE_ENRICHMENT, Colors.DEF_NODE_BORDER_COLOR);
455-
dm.putMapValue(Columns.NODE_GS_TYPE_SIGNATURE, Colors.SIG_NODE_BORDER_COLOR);
472+
dm.putMapValue(Columns.NODE_GS_TYPE_SIGNATURE, Colors.SIG_NODE_BORDER_COLOR);
456473
} finally {
457474
eventHelper.unsilenceEventSource(dm);
458475
}

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/task/ApplyEMStyleTask.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.baderlab.csplugins.enrichmentmap.style.ColorScheme;
2222
import org.baderlab.csplugins.enrichmentmap.style.EMStyleBuilder;
2323
import org.baderlab.csplugins.enrichmentmap.style.EMStyleBuilder.Columns;
24+
import org.baderlab.csplugins.enrichmentmap.style.EMStyleBuilder.StyleUpdateScope;
2425
import org.baderlab.csplugins.enrichmentmap.style.EMStyleOptions;
2526
import org.baderlab.csplugins.enrichmentmap.style.charts.AbstractChart;
2627
import org.baderlab.csplugins.enrichmentmap.style.charts.radialheatmap.RadialHeatMapChart;
@@ -59,16 +60,16 @@ public class ApplyEMStyleTask extends AbstractTask {
5960
@Inject private Provider<ControlPanelMediator> controlPanelMediatorProvider;
6061

6162
private final EMStyleOptions options;
62-
private final boolean updateChartOnly;
63+
private final StyleUpdateScope scope;
6364

6465
public interface Factory {
65-
ApplyEMStyleTask create(EMStyleOptions options, boolean updateChartOnly);
66+
ApplyEMStyleTask create(EMStyleOptions options, StyleUpdateScope scope);
6667
}
6768

6869
@Inject
69-
public ApplyEMStyleTask(@Assisted EMStyleOptions options, @Assisted boolean updateChartOnly) {
70+
public ApplyEMStyleTask(@Assisted EMStyleOptions options, @Assisted StyleUpdateScope scope) {
7071
this.options = options;
71-
this.updateChartOnly = updateChartOnly;
72+
this.scope = scope;
7273
}
7374

7475
@Override
@@ -177,12 +178,7 @@ private void applyVisualStyle() {
177178

178179
CyCustomGraphics2<?> chart = createChart();
179180

180-
if (updateChartOnly)
181-
styleBuilderProvider.get().updateNodeChart(vs, options, chart);
182-
else
183-
styleBuilderProvider.get().updateProperties(vs, options, chart);
184-
185-
181+
styleBuilderProvider.get().updateStyle(vs, options, chart, scope);
186182
}
187183

188184
private VisualStyle getVisualStyle(EnrichmentMap map) {

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/task/CreateEMViewTask.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.baderlab.csplugins.enrichmentmap.task;
22

33
import org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap;
4+
import org.baderlab.csplugins.enrichmentmap.style.EMStyleBuilder.StyleUpdateScope;
45
import org.baderlab.csplugins.enrichmentmap.style.EMStyleOptions;
56
import org.cytoscape.model.CyNetwork;
67
import org.cytoscape.model.CyNetworkManager;
@@ -53,7 +54,7 @@ private void visualizeMap() {
5354
// This should probably get fixed so that the task only runs once...
5455

5556
EMStyleOptions options = new EMStyleOptions(view, map);
56-
ApplyEMStyleTask styleTask = applyStyleTaskFactory.create(options, false);
57+
ApplyEMStyleTask styleTask = applyStyleTaskFactory.create(options, StyleUpdateScope.ALL);
5758

5859
//apply force directed layout
5960
CyLayoutAlgorithm layout = layoutManager.getLayout("force-directed");

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/task/postanalysis/PATaskFactory.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap;
88
import org.baderlab.csplugins.enrichmentmap.model.EnrichmentMapManager;
99
import org.baderlab.csplugins.enrichmentmap.model.PostAnalysisParameters;
10+
import org.baderlab.csplugins.enrichmentmap.style.EMStyleBuilder.StyleUpdateScope;
1011
import org.baderlab.csplugins.enrichmentmap.style.EMStyleOptions;
1112
import org.baderlab.csplugins.enrichmentmap.task.ApplyEMStyleTask;
1213
import org.baderlab.csplugins.enrichmentmap.view.control.ControlPanelMediator;
@@ -68,7 +69,7 @@ public TaskIterator createTaskIterator() {
6869

6970
TaskIterator tasks = new TaskIterator();
7071
tasks.append(signatureTaskFactory.create(params, map, dataSetList));
71-
tasks.append(applyStyleTaskFactory.create(options, false));
72+
tasks.append(applyStyleTaskFactory.create(options, StyleUpdateScope.ONLY_EDGE_WIDTH));
7273

7374
return tasks;
7475
} else {

0 commit comments

Comments
 (0)