use of org.cytoscape.view.vizmap.mappings.ContinuousMappingPoint in project EnrichmentMapApp by BaderLab.
the class EMStyleBuilder method setNodeSize.
@SuppressWarnings("rawtypes")
private void setNodeSize(VisualStyle vs, EMStyleOptions options, ChartType chartType) {
if (chartType == null || chartType == ChartType.RADIAL_HEAT_MAP) {
String prefix = options.getAttributePrefix();
String columnName = Columns.NODE_GS_SIZE.with(prefix, null);
int val0 = 10;
int val1 = 474;
VisualMappingFunction<?, Double> oldMapping = vs.getVisualMappingFunction(NODE_SIZE);
// This is done for performance optimization only!
boolean update = oldMapping instanceof ContinuousMapping == false;
if (!update) {
try {
// Also test the mapped column name and number of points
update = !columnName.equals(oldMapping.getMappingColumnName()) || ((ContinuousMapping) oldMapping).getPointCount() != 2;
if (!update) {
// And the mapping values
ContinuousMappingPoint pt0 = ((ContinuousMapping) oldMapping).getPoint(0);
ContinuousMappingPoint pt1 = ((ContinuousMapping) oldMapping).getPoint(1);
update = val0 != (Integer) pt0.getValue();
update = update || val1 != (Integer) pt1.getValue();
if (// Finally test the boundary ranges
!update)
update = MIN_NODE_SIZE != (Double) pt0.getRange().equalValue || MAX_NODE_SIZE != (Double) pt1.getRange().equalValue;
}
} catch (NullPointerException | ClassCastException e) {
update = true;
}
}
if (update) {
ContinuousMapping<Integer, Double> cm = (ContinuousMapping<Integer, Double>) cmFactory.createVisualMappingFunction(columnName, Integer.class, NODE_SIZE);
BoundaryRangeValues<Double> bv0 = new BoundaryRangeValues<>(MIN_NODE_SIZE, MIN_NODE_SIZE, MIN_NODE_SIZE);
BoundaryRangeValues<Double> bv1 = new BoundaryRangeValues<>(MAX_NODE_SIZE, MAX_NODE_SIZE, MAX_NODE_SIZE);
// Silence events fired by this mapping to prevent unnecessary style and view updates
eventHelper.silenceEventSource(cm);
try {
cm.addPoint(val0, bv0);
cm.addPoint(val1, bv1);
} finally {
eventHelper.unsilenceEventSource(cm);
}
vs.addVisualMappingFunction(cm);
}
} else {
vs.removeVisualMappingFunction(NODE_SIZE);
}
}
Aggregations