Search in sources :

Example 11 with View

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);
    }
}
Also used : BasicVisualLexicon(org.cytoscape.view.presentation.property.BasicVisualLexicon) VisualLexicon(org.cytoscape.view.model.VisualLexicon) CyNetwork(org.cytoscape.model.CyNetwork) View(org.cytoscape.view.model.View) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CyApplicationManager(org.cytoscape.application.CyApplicationManager) ExecutorService(java.util.concurrent.ExecutorService) CyNetworkView(org.cytoscape.view.model.CyNetworkView) HashSet(java.util.HashSet)

Example 12 with View

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);
}
Also used : VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CyNetworkView(org.cytoscape.view.model.CyNetworkView) View(org.cytoscape.view.model.View) CyEdge(org.cytoscape.model.CyEdge)

Example 13 with View

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);
}
Also used : PaintedShape(org.cytoscape.view.presentation.customgraphics.PaintedShape) DiamondNodeShape(org.cytoscape.graph.render.immed.nodeshape.DiamondNodeShape) RoundedRectangleNodeShape(org.cytoscape.graph.render.immed.nodeshape.RoundedRectangleNodeShape) Shape(java.awt.Shape) HexagonNodeShape(org.cytoscape.graph.render.immed.nodeshape.HexagonNodeShape) NodeShape(org.cytoscape.graph.render.immed.nodeshape.NodeShape) PaintedShape(org.cytoscape.view.presentation.customgraphics.PaintedShape) LegacyCustomNodeShape(org.cytoscape.graph.render.immed.nodeshape.LegacyCustomNodeShape) VeeNodeShape(org.cytoscape.graph.render.immed.nodeshape.VeeNodeShape) ParallelogramNodeShape(org.cytoscape.graph.render.immed.nodeshape.ParallelogramNodeShape) EllipseNodeShape(org.cytoscape.graph.render.immed.nodeshape.EllipseNodeShape) OctagonNodeShape(org.cytoscape.graph.render.immed.nodeshape.OctagonNodeShape) ArrowShape(org.cytoscape.view.presentation.property.values.ArrowShape) RectangleNodeShape(org.cytoscape.graph.render.immed.nodeshape.RectangleNodeShape) TriangleNodeShape(org.cytoscape.graph.render.immed.nodeshape.TriangleNodeShape) Cy2DGraphicLayer(org.cytoscape.view.presentation.customgraphics.Cy2DGraphicLayer) ImageCustomGraphicLayer(org.cytoscape.view.presentation.customgraphics.ImageCustomGraphicLayer) Rectangle(java.awt.Rectangle) Rectangle2D(java.awt.geom.Rectangle2D) Paint(java.awt.Paint) TexturePaint(java.awt.TexturePaint) View(org.cytoscape.view.model.View) CyNetworkView(org.cytoscape.view.model.CyNetworkView) BufferedImage(java.awt.image.BufferedImage)

Example 14 with View

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;
    }
}
Also used : BasicVisualLexicon(org.cytoscape.view.presentation.property.BasicVisualLexicon) Logger(org.slf4j.Logger) CyNode(org.cytoscape.model.CyNode) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) UndoSupport(org.cytoscape.work.undo.UndoSupport) Collectors(java.util.stream.Collectors) View(org.cytoscape.view.model.View) ArrayList(java.util.ArrayList) List(java.util.List) CyNetwork(org.cytoscape.model.CyNetwork) CyNetworkView(org.cytoscape.view.model.CyNetworkView) TaskMonitor(org.cytoscape.work.TaskMonitor) CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode)

Example 15 with View

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;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CyNetwork(org.cytoscape.model.CyNetwork) CyEdge(org.cytoscape.model.CyEdge) View(org.cytoscape.view.model.View) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CyNode(org.cytoscape.model.CyNode)

Aggregations

CyNetworkView (org.cytoscape.view.model.CyNetworkView)35 View (org.cytoscape.view.model.View)35 CyNode (org.cytoscape.model.CyNode)24 CyEdge (org.cytoscape.model.CyEdge)17 CyNetwork (org.cytoscape.model.CyNetwork)15 ArrayList (java.util.ArrayList)12 HashSet (java.util.HashSet)11 VisualProperty (org.cytoscape.view.model.VisualProperty)8 VisualStyle (org.cytoscape.view.vizmap.VisualStyle)8 List (java.util.List)7 VisualMappingManager (org.cytoscape.view.vizmap.VisualMappingManager)6 HashMap (java.util.HashMap)5 Set (java.util.Set)5 CyEventHelper (org.cytoscape.event.CyEventHelper)5 BasicVisualLexicon (org.cytoscape.view.presentation.property.BasicVisualLexicon)5 Paint (java.awt.Paint)4 CyApplicationManager (org.cytoscape.application.CyApplicationManager)4 CyIdentifiable (org.cytoscape.model.CyIdentifiable)4 VisualLexicon (org.cytoscape.view.model.VisualLexicon)4 Collectors (java.util.stream.Collectors)3