1
1
package org .baderlab .csplugins .enrichmentmap .style ;
2
2
3
+ import static org .baderlab .csplugins .enrichmentmap .style .EMStyleBuilder .StyleUpdateScope .*;
3
4
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 .*;
7
6
8
7
import java .awt .Color ;
9
8
import java .awt .Paint ;
44
43
import org .jcolorbrewer .ColorBrewer ;
45
44
46
45
import com .google .inject .Inject ;
46
+ import com .google .inject .Singleton ;
47
47
48
48
/**
49
49
* Responsible for updating the EnrichmentMap styles.
50
50
*/
51
+ @ Singleton
51
52
public class EMStyleBuilder {
52
53
53
54
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 {
158
159
private static final Color BG_COLOR = Color .WHITE ;
159
160
}
160
161
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
+
161
172
@ Inject private @ Continuous VisualMappingFunctionFactory cmFactory ;
162
173
@ Inject private @ Discrete VisualMappingFunctionFactory dmFactory ;
163
174
@ Inject private @ Passthrough VisualMappingFunctionFactory pmFactory ;
164
175
165
176
@ Inject private RenderingEngineManager renderingEngineManager ;
166
177
@ Inject private CyEventHelper eventHelper ;
167
178
179
+ private VisualMappingFunction <?, ?> nonPublicationReadyLabelMapping ;
180
+
181
+
168
182
public static String getStyleName (EnrichmentMap map ) {
169
183
String prefix = map .getParams ().getStylePrefix ();
170
184
return prefix + DEFAULT_NAME_SUFFIX ;
@@ -182,66 +196,69 @@ public static NodeShape getDefaultNodeShape(ChartType chartType) {
182
196
return chartType == null || chartType == ChartType .RADIAL_HEAT_MAP ? ELLIPSE : RECTANGLE ;
183
197
}
184
198
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
+
189
205
eventHelper .silenceEventSource (vs );
190
206
191
207
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
+ }
216
250
}
217
251
} finally {
218
252
eventHelper .unsilenceEventSource (vs );
219
253
eventHelper .addEventPayload (vs , new VisualStyleChangeRecord (), VisualStyleChangedEvent .class );
220
254
}
221
255
}
222
256
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
- }
239
257
240
258
@ SuppressWarnings ({ "rawtypes" , "unchecked" })
241
259
private void setNodeChart (VisualStyle vs , CyCustomGraphics2 <?> chart ) {
242
260
VisualLexicon lexicon = renderingEngineManager .getDefaultVisualLexicon ();
243
261
VisualProperty customPaint1 = lexicon .lookup (CyNode .class , "NODE_CUSTOMGRAPHICS_1" );
244
-
245
262
if (customPaint1 != null )
246
263
vs .setDefaultValue (customPaint1 , chart );
247
264
}
@@ -452,7 +469,7 @@ private void setNodeBorderColors(VisualStyle vs, EMStyleOptions options) {
452
469
453
470
try {
454
471
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 );
456
473
} finally {
457
474
eventHelper .unsilenceEventSource (dm );
458
475
}
0 commit comments