use of org.cytoscape.view.model.View in project cytoscape-impl by cytoscape.
the class ApplyToNetworkHandler method apply.
@Override
public void apply(final CyRow row, final View<CyNetwork> view) {
final CyNetworkView netView = (CyNetworkView) view;
final Collection<View<CyNode>> nodeViews = netView.getNodeViews();
final Collection<View<CyEdge>> edgeViews = netView.getEdgeViews();
final Collection<View<CyNetwork>> networkViewSet = new HashSet<View<CyNetwork>>();
networkViewSet.add(netView);
// Make sure the dependency maps are up to date
updateDependencyMaps();
// Clear visual properties from all views first
view.clearVisualProperties();
for (final View<?> v : nodeViews) v.clearVisualProperties();
for (final View<?> v : edgeViews) v.clearVisualProperties();
// Get current Visual Lexicon
final CyApplicationManager appMgr = serviceRegistrar.getService(CyApplicationManager.class);
final VisualLexicon lexicon = appMgr.getCurrentNetworkViewRenderer().getRenderingEngineFactory(NetworkViewRenderer.DEFAULT_CONTEXT).getVisualLexicon();
applyDefaultsInParallel(netView, lexicon.getVisualLexiconNode(BasicVisualLexicon.NODE));
applyDefaultsInParallel(netView, lexicon.getVisualLexiconNode(BasicVisualLexicon.EDGE));
applyDefaultsInParallel(netView, lexicon.getVisualLexiconNode(BasicVisualLexicon.NETWORK));
applyDependencies(netView);
final ExecutorService exe = Executors.newCachedThreadPool();
exe.submit(new ApplyMappingsTask(netView, nodeViews, BasicVisualLexicon.NODE, lexicon));
exe.submit(new ApplyMappingsTask(netView, edgeViews, BasicVisualLexicon.EDGE, lexicon));
exe.submit(new ApplyMappingsTask(netView, networkViewSet, BasicVisualLexicon.NETWORK, lexicon));
try {
exe.shutdown();
exe.awaitTermination(15, TimeUnit.MINUTES);
} catch (Exception ex) {
logger.warn("Create apply operation failed.", ex);
}
}
use of org.cytoscape.view.model.View in project cytoscape-impl by cytoscape.
the class ClearAllEdgeBendsTask method run.
@Override
public void run(TaskMonitor tm) throws Exception {
tm.setTitle("Clear All Edge Bends");
tm.setProgress(0.0);
final VisualMappingManager vmManager = serviceRegistrar.getService(VisualMappingManager.class);
int count = 1;
int total = networkViews.size();
for (CyNetworkView nv : networkViews) {
tm.setStatusMessage(count + " of " + total + ": " + DataUtils.getViewTitle(nv) + "...");
tm.setProgress((float) count / total);
nv.setViewDefault(BasicVisualLexicon.EDGE_BEND, null);
VisualStyle vs = vmManager.getVisualStyle(nv);
vs.setDefaultValue(BasicVisualLexicon.EDGE_BEND, null);
vs.removeVisualMappingFunction(BasicVisualLexicon.EDGE_BEND);
final Collection<View<CyEdge>> edgeViews = nv.getEdgeViews();
for (final View<CyEdge> ev : edgeViews) {
ev.setVisualProperty(BasicVisualLexicon.EDGE_BEND, null);
ev.clearValueLock(BasicVisualLexicon.EDGE_BEND);
}
nv.updateView();
count++;
}
tm.setProgress(1.0);
}
use of org.cytoscape.view.model.View in project cytoscape-impl by cytoscape.
the class GraphGraphics method drawCustomGraphicFull.
/**
* Fills an arbitrary graphical shape with high detail.
* <p>
* This method will not work unless clear() has been called at least once
* previously.
*
* @param nodeShape
* the node shape
* @param cg
* the CustomGraphicLayer
* @param xOffset
* in node coordinates, a value to add to the X coordinates of
* the shape's definition.
* @param yOffset
* in node coordinates, a value to add to the Y coordinates of
* the shape's definition.
*/
public final void drawCustomGraphicFull(final CyNetworkView netView, final CyNode node, final Shape nodeShape, final CustomGraphicLayer cg, final float xOffset, final float yOffset) {
if (m_debug) {
checkDispatchThread();
checkCleared();
}
m_g2d.translate(xOffset, yOffset);
if (cg instanceof PaintedShape) {
PaintedShape ps = (PaintedShape) cg;
Shape shape = ps.getShape();
if (ps.getStroke() != null) {
Paint strokePaint = ps.getStrokePaint();
if (strokePaint == null)
strokePaint = Color.BLACK;
m_g2d.setPaint(strokePaint);
m_g2d.setStroke(ps.getStroke());
m_g2d.draw(shape);
}
m_g2d.setPaint(ps.getPaint());
m_g2d.fill(shape);
} else if (cg instanceof Cy2DGraphicLayer) {
Cy2DGraphicLayer layer = (Cy2DGraphicLayer) cg;
final View<CyNode> view = (netView != null && node != null) ? netView.getNodeView(node) : null;
layer.draw(m_g2d, nodeShape, netView, view);
} else if (cg instanceof ImageCustomGraphicLayer) {
Rectangle bounds = cg.getBounds2D().getBounds();
final BufferedImage bImg = ((ImageCustomGraphicLayer) cg).getPaint(bounds).getImage();
m_g2d.drawImage(bImg, bounds.x, bounds.y, bounds.width, bounds.height, null);
} else {
Rectangle2D bounds = nodeShape.getBounds2D();
m_g2d.setPaint(cg.getPaint(bounds));
m_g2d.fill(nodeShape);
}
m_g2d.setTransform(m_currNativeXform);
}
use of org.cytoscape.view.model.View in project cytoscape-api by cytoscape.
the class AbstractPartitionLayoutTask method doLayout.
/**
* AbstractGraphPartitionLayout implements the doLayout method
* of AbstractBasicLayout in which it calls the layoutParition
* method on each LayoutPartition object created for the network.
* @param taskMonitor the TaskMonitor provided by the run() method
* of the Task.
*/
@Override
public void doLayout(final TaskMonitor taskMonitor) {
final CyNetwork network = networkView.getModel();
if (edgeWeighter != null)
edgeWeighter.reset();
this.taskMonitor = taskMonitor;
long visibleNodeCount = networkView.getNodeViews().stream().filter(view -> view.getVisualProperty(BasicVisualLexicon.NODE_VISIBLE)).count();
boolean useAllNodes = nodesToLayOut.size() == visibleNodeCount;
// to lay out selected nodes, partitioning becomes a very bad idea!
if (singlePartition || !useAllNodes) {
// We still use the partition abstraction, even if we're
// not partitioning. This makes the code further down
// much cleaner
LayoutPartition partition = new LayoutPartition(networkView, nodesToLayOut, edgeWeighter);
partitionList = new ArrayList<>(1);
partitionList.add(partition);
} else {
Set<CyNode> nodes = nodesToLayOut.stream().map(nv -> nv.getModel()).collect(Collectors.toSet());
partitionList = PartitionUtil.partition(networkView, nodes, edgeWeighter);
}
total_nodes = network.getNodeCount();
current_start = 0;
// Set up offsets -- we start with the overall min and max
double xStart = (partitionList.get(0)).getMinX();
double yStart = (partitionList.get(0)).getMinY();
for (LayoutPartition part : partitionList) {
xStart = Math.min(xStart, part.getMinX());
yStart = Math.min(yStart, part.getMinY());
}
double next_x_start = xStart;
double next_y_start = yStart;
double current_max_y = 0;
double max_dimensions = Math.sqrt((double) network.getNodeCount());
// give each node room
max_dimensions *= incr;
max_dimensions += xStart;
for (LayoutPartition partition : partitionList) {
if (cancelled)
break;
// get the partition
current_size = (double) partition.size();
// System.out.println("Partition #"+partition.getPartitionNumber()+" has "+current_size+" nodes");
setTaskStatus(1);
// Partitions Requiring Layout
if (partition.nodeCount() > 1) {
try {
layoutPartition(partition);
} catch (Throwable _e) {
_e.printStackTrace();
return;
}
if (useAllNodes && !singlePartition) {
// System.out.println("Offsetting partition #"+partition.getPartitionNumber()+" to "+next_x_start+", "+next_y_start);
// OFFSET
partition.offset(next_x_start, next_y_start);
}
// single nodes
} else if (partition.nodeCount() == 1) {
// Reset our bounds
partition.resetNodes();
// Single node -- get it
LayoutNode node = (LayoutNode) partition.getNodeList().get(0);
node.setLocation(next_x_start, next_y_start);
partition.moveNodeToLocation(node);
} else {
continue;
}
double last_max_x = partition.getMaxX();
double last_max_y = partition.getMaxY();
if (last_max_y > current_max_y) {
current_max_y = last_max_y;
}
if (last_max_x > max_dimensions) {
next_x_start = xStart;
next_y_start = current_max_y;
next_y_start += incr;
} else {
next_x_start = last_max_x;
next_x_start += incr;
}
setTaskStatus(100);
current_start += current_size;
}
}
use of org.cytoscape.view.model.View in project cytoscape-api by cytoscape.
the class PartitionUtil method partition.
/**
* Partition the graph -- this builds the LayoutEdge and LayoutNode
* arrays as a byproduct. The algorithm for this was taken from
* algorithms/graphPartition/SGraphPartition.java.
*
* @param networkView the CyNetworkView representing the graph
* @param nodeSet the set of nodes to consider
* @param edgeWeighter the weighter to use for edge weighting
* @return a List of LayoutPartitions
*/
public static List<LayoutPartition> partition(CyNetworkView networkView, Collection<CyNode> nodeSet, EdgeWeighter edgeWeighter) {
final List<LayoutPartition> partitions = new ArrayList<LayoutPartition>();
final CyNetwork network = networkView.getModel();
final Map<CyNode, Integer> nodesSeenMap = new HashMap<CyNode, Integer>();
final Map<CyEdge, Integer> edgesSeenMap = new HashMap<CyEdge, Integer>();
final Map<CyNode, View<CyNode>> nodesToViews = new HashMap<CyNode, View<CyNode>>();
int partitionNumber = 1;
// Initialize the maps
for (final View<CyNode> nv : networkView.getNodeViews()) {
nodesSeenMap.put(nv.getModel(), m_NODE_HAS_NOT_BEEN_SEEN);
nodesToViews.put(nv.getModel(), nv);
}
for (CyEdge edge : network.getEdgeList()) edgesSeenMap.put(edge, m_NODE_HAS_NOT_BEEN_SEEN);
// OK, now traverse the graph
for (final CyNode node : nodeSet) {
// Have we seen this already?
if (nodesSeenMap.get(node) == m_NODE_HAS_BEEN_SEEN)
continue;
// Nope, first time
final LayoutPartition part = new LayoutPartition(network.getNodeCount(), network.getEdgeCount());
part.setPartitionNumber(partitionNumber++);
// Set the edge weighter
part.setEdgeWeighter(edgeWeighter);
nodesSeenMap.put(node, m_NODE_HAS_BEEN_SEEN);
// Traverse through all connected nodes
traverse(network, networkView, nodesToViews, node, part, nodesSeenMap, edgesSeenMap);
// Done -- finalize the parition
part.trimToSize();
// Finally, now that we're sure we've touched all of our
// nodes. Fix up our edgeLayout list to have all of our
// layoutNodes
part.fixEdges();
partitions.add(part);
}
// Now sort the partitions based on the partition's node count
Collections.sort(partitions, new Comparator<LayoutPartition>() {
public int compare(LayoutPartition p1, LayoutPartition p2) {
return (p2.size() - p1.size());
}
public boolean equals(LayoutPartition obj) {
return false;
}
});
return partitions;
}
Aggregations