Search in sources :

Example 16 with View

use of org.cytoscape.view.model.View in project EnrichmentMapApp by BaderLab.

the class EMStyleBuilder method setNodeColors.

private void setNodeColors(VisualStyle vs, EMStyleOptions options) {
    String prefix = options.getAttributePrefix();
    List<AbstractDataSet> dataSets = options.getDataSets().stream().filter(// Ignore Signature Data Sets in charts
    ds -> ds instanceof EMDataSet).collect(Collectors.toList());
    if (dataSets.size() == 1) {
        // Only 1 Data Set? Use node colour instead of charts...
        EMDataSet ds = (EMDataSet) dataSets.iterator().next();
        // Create boundary conditions
        BoundaryRangeValues<Paint> bv3a = new BoundaryRangeValues<>(Colors.MAX_PHENOTYPE_2, Colors.MAX_PHENOTYPE_2, Colors.MAX_PHENOTYPE_2);
        BoundaryRangeValues<Paint> bv3b = new BoundaryRangeValues<>(Colors.LIGHTER_PHENOTYPE_2, Colors.LIGHTER_PHENOTYPE_2, Colors.MAX_PHENOTYPE_2);
        BoundaryRangeValues<Paint> bv3c = new BoundaryRangeValues<>(Colors.LIGHTEST_PHENOTYPE_2, Colors.LIGHTEST_PHENOTYPE_2, Colors.LIGHTER_PHENOTYPE_2);
        BoundaryRangeValues<Paint> bv3d = new BoundaryRangeValues<>(Colors.LIGHTEST_PHENOTYPE_2, Colors.OVER_COLOR, Colors.OVER_COLOR);
        BoundaryRangeValues<Paint> bv3e = new BoundaryRangeValues<>(Colors.OVER_COLOR, Colors.OVER_COLOR, Colors.OVER_COLOR);
        BoundaryRangeValues<Paint> bv3f = new BoundaryRangeValues<>(Colors.OVER_COLOR, Colors.OVER_COLOR, Colors.LIGHTEST_PHENOTYPE_1);
        BoundaryRangeValues<Paint> bv3g = new BoundaryRangeValues<>(Colors.LIGHTEST_PHENOTYPE_1, Colors.LIGHTEST_PHENOTYPE_1, Colors.LIGHTER_PHENOTYPE_1);
        BoundaryRangeValues<Paint> bv3h = new BoundaryRangeValues<>(Colors.LIGHTER_PHENOTYPE_1, Colors.LIGHTER_PHENOTYPE_1, Colors.MAX_PHENOTYPE_1);
        BoundaryRangeValues<Paint> bv3i = new BoundaryRangeValues<>(Colors.MAX_PHENOTYPE_1, Colors.MAX_PHENOTYPE_1, Colors.MAX_PHENOTYPE_1);
        // Continuous Mapping - set node colour based on the sign of the ES score of the dataset
        ContinuousMapping<Double, Paint> cm = (ContinuousMapping<Double, Paint>) cmFactory.createVisualMappingFunction(Columns.NODE_COLOURING.with(prefix, ds.getName()), Double.class, BasicVisualLexicon.NODE_FILL_COLOR);
        // Silence events fired by this mapping to prevent unnecessary style and view updates
        eventHelper.silenceEventSource(cm);
        try {
            // Set the attribute point values associated with the boundary values
            cm.addPoint(-1.0, bv3a);
            cm.addPoint(-0.995, bv3b);
            cm.addPoint(-0.95, bv3c);
            cm.addPoint(-0.9, bv3d);
            cm.addPoint(0.0, bv3e);
            cm.addPoint(0.9, bv3f);
            cm.addPoint(0.95, bv3g);
            cm.addPoint(0.995, bv3h);
            cm.addPoint(1.0, bv3i);
        } finally {
            eventHelper.unsilenceEventSource(cm);
        }
        vs.addVisualMappingFunction(cm);
        // Then we need to use bypass to colour the hub nodes (signature genesets)
        List<EMSignatureDataSet> signatureDataSets = options.getEnrichmentMap().getSignatureSetList();
        CyNetworkView netView = options.getNetworkView();
        CyNetwork net = netView.getModel();
        for (EMSignatureDataSet sds : signatureDataSets) {
            for (Long suid : sds.getNodeSuids()) {
                CyNode node = net.getNode(suid);
                if (node != null) {
                    View<CyNode> nv = netView.getNodeView(node);
                    if (nv != null)
                        nv.setLockedValue(NODE_FILL_COLOR, Colors.SIG_NODE_COLOR);
                }
            }
        }
    } else {
        // 2 or more Data Sets? Use simple node colours and charts...
        // Add mapping function for node fill color
        DiscreteMapping<String, Paint> dm = (DiscreteMapping<String, Paint>) dmFactory.createVisualMappingFunction(Columns.NODE_GS_TYPE.with(prefix, null), String.class, NODE_FILL_COLOR);
        // Silence events fired by this mapping to prevent unnecessary style and view updates
        eventHelper.silenceEventSource(dm);
        try {
            dm.putMapValue(Columns.NODE_GS_TYPE_ENRICHMENT, Colors.DEF_NODE_COLOR);
            dm.putMapValue(Columns.NODE_GS_TYPE_SIGNATURE, Colors.SIG_NODE_COLOR);
        } finally {
            eventHelper.unsilenceEventSource(dm);
        }
        vs.addVisualMappingFunction(dm);
    }
}
Also used : Color(java.awt.Color) NODE_SHAPE(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_SHAPE) RECTANGLE(org.cytoscape.view.presentation.property.NodeShapeVisualProperty.RECTANGLE) NODE_BORDER_TRANSPARENCY(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_BORDER_TRANSPARENCY) NodeShape(org.cytoscape.view.presentation.property.values.NodeShape) Inject(com.google.inject.Inject) EDGE_UNSELECTED_PAINT(org.cytoscape.view.presentation.property.BasicVisualLexicon.EDGE_UNSELECTED_PAINT) LineType(org.cytoscape.view.presentation.property.values.LineType) ColorBrewer(org.jcolorbrewer.ColorBrewer) View(org.cytoscape.view.model.View) CyCustomGraphics2(org.cytoscape.view.presentation.customgraphics.CyCustomGraphics2) NODE_TOOLTIP(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_TOOLTIP) Discrete(org.baderlab.csplugins.enrichmentmap.CytoscapeServiceModule.Discrete) CyNetwork(org.cytoscape.model.CyNetwork) NODE_SIZE(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_SIZE) NODE_FILL_COLOR(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_FILL_COLOR) VisualStyleChangedEvent(org.cytoscape.view.vizmap.events.VisualStyleChangedEvent) BasicVisualLexicon(org.cytoscape.view.presentation.property.BasicVisualLexicon) RenderingEngineManager(org.cytoscape.view.presentation.RenderingEngineManager) VisualLexicon(org.cytoscape.view.model.VisualLexicon) Collectors(java.util.stream.Collectors) AbstractDataSet(org.baderlab.csplugins.enrichmentmap.model.AbstractDataSet) List(java.util.List) NETWORK_BACKGROUND_PAINT(org.cytoscape.view.presentation.property.BasicVisualLexicon.NETWORK_BACKGROUND_PAINT) EMDataSet(org.baderlab.csplugins.enrichmentmap.model.EMDataSet) Paint(java.awt.Paint) DIAMOND(org.cytoscape.view.presentation.property.NodeShapeVisualProperty.DIAMOND) Optional(java.util.Optional) NODE_LABEL(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_LABEL) LineTypeVisualProperty(org.cytoscape.view.presentation.property.LineTypeVisualProperty) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) ContinuousMapping(org.cytoscape.view.vizmap.mappings.ContinuousMapping) Passthrough(org.baderlab.csplugins.enrichmentmap.CytoscapeServiceModule.Passthrough) EDGE_LINE_TYPE(org.cytoscape.view.presentation.property.BasicVisualLexicon.EDGE_LINE_TYPE) EDGE_STROKE_UNSELECTED_PAINT(org.cytoscape.view.presentation.property.BasicVisualLexicon.EDGE_STROKE_UNSELECTED_PAINT) CyNode(org.cytoscape.model.CyNode) PassthroughMapping(org.cytoscape.view.vizmap.mappings.PassthroughMapping) EnrichmentMap(org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap) EDGE_LABEL_TRANSPARENCY(org.cytoscape.view.presentation.property.BasicVisualLexicon.EDGE_LABEL_TRANSPARENCY) EDGE_WIDTH(org.cytoscape.view.presentation.property.BasicVisualLexicon.EDGE_WIDTH) ELLIPSE(org.cytoscape.view.presentation.property.NodeShapeVisualProperty.ELLIPSE) DiscreteMapping(org.cytoscape.view.vizmap.mappings.DiscreteMapping) NODE_BORDER_PAINT(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_BORDER_PAINT) NODE_BORDER_WIDTH(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_BORDER_WIDTH) Continuous(org.baderlab.csplugins.enrichmentmap.CytoscapeServiceModule.Continuous) NODE_TRANSPARENCY(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_TRANSPARENCY) VisualMappingFunctionFactory(org.cytoscape.view.vizmap.VisualMappingFunctionFactory) CyEventHelper(org.cytoscape.event.CyEventHelper) DiscreteRange(org.cytoscape.view.model.DiscreteRange) NODE_LABEL_TRANSPARENCY(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_LABEL_TRANSPARENCY) EDGE_TRANSPARENCY(org.cytoscape.view.presentation.property.BasicVisualLexicon.EDGE_TRANSPARENCY) VisualProperty(org.cytoscape.view.model.VisualProperty) ContinuousMappingPoint(org.cytoscape.view.vizmap.mappings.ContinuousMappingPoint) BoundaryRangeValues(org.cytoscape.view.vizmap.mappings.BoundaryRangeValues) CyNetworkView(org.cytoscape.view.model.CyNetworkView) VisualMappingFunction(org.cytoscape.view.vizmap.VisualMappingFunction) EMSignatureDataSet(org.baderlab.csplugins.enrichmentmap.model.EMSignatureDataSet) CyEdge(org.cytoscape.model.CyEdge) VisualStyleChangeRecord(org.cytoscape.view.vizmap.events.VisualStyleChangeRecord) ContinuousMapping(org.cytoscape.view.vizmap.mappings.ContinuousMapping) EMSignatureDataSet(org.baderlab.csplugins.enrichmentmap.model.EMSignatureDataSet) DiscreteMapping(org.cytoscape.view.vizmap.mappings.DiscreteMapping) CyNetwork(org.cytoscape.model.CyNetwork) Paint(java.awt.Paint) AbstractDataSet(org.baderlab.csplugins.enrichmentmap.model.AbstractDataSet) BoundaryRangeValues(org.cytoscape.view.vizmap.mappings.BoundaryRangeValues) EMDataSet(org.baderlab.csplugins.enrichmentmap.model.EMDataSet) CyNode(org.cytoscape.model.CyNode) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Example 17 with View

use of org.cytoscape.view.model.View in project cytoscape-impl by cytoscape.

the class LayerOrderNode method layout.

public void layout() {
    taskMonitor.setProgress(0.0);
    taskMonitor.setStatusMessage("Capturing snapshot of network and selected nodes");
    if (cancelled)
        return;
    /* construct node list with selected nodes first */
    int numLayoutNodes = nodesToLayOut.size();
    if (numLayoutNodes == 1) {
        // We were asked to do a hierchical layout of a single node -- done!
        return;
    }
    HashMap<Long, Integer> suid2Index = new HashMap<Long, Integer>(numLayoutNodes);
    List<View<CyNode>> nodeViews = new ArrayList<View<CyNode>>(nodesToLayOut);
    int index = 0;
    for (View<CyNode> view : nodeViews) {
        CyNode node = view.getModel();
        Long suid = node.getSUID();
        suid2Index.put(suid, index);
        index++;
    }
    if (cancelled)
        return;
    /* create edge list from edges between selected nodes */
    LinkedList<Edge> edges = new LinkedList();
    for (View<CyEdge> ev : networkView.getEdgeViews()) {
        // FIXME: much better would be to query adjacent edges of selected nodes...
        Integer edgeFrom = suid2Index.get(ev.getModel().getSource().getSUID());
        Integer edgeTo = suid2Index.get(ev.getModel().getTarget().getSUID());
        if ((edgeFrom == null) || (edgeTo == null)) {
            // Must be from an unselected node
            continue;
        }
        if (cancelled)
            return;
        if ((numLayoutNodes <= 1) || ((edgeFrom < numLayoutNodes) && (edgeTo < numLayoutNodes))) {
            /* add edge to graph */
            Edge theEdge = new Edge(edgeFrom, edgeTo);
            edges.add(theEdge);
        }
    }
    /* find horizontal and vertical coordinates of each node */
    Edge[] edge = new Edge[edges.size()];
    edges.toArray(edge);
    Graph graph = new Graph(numLayoutNodes, edge);
    /*
		int edgeIndex;
		for (edgeIndex = 0; edgeIndex<edge.length; edgeIndex++) {
		     System.out.println("Edge: " + edge[edgeIndex].getFrom() + " - " + edge[edgeIndex].getTo());
		}
		*/
    int[] cI = graph.componentIndex();
    int x;
    /*
		System.out.println("Node index:\n");
		for (x=0; x<graph.getNodecount(); x++) {
		    System.out.println(cI[x]);
		}
		System.out.println("Partitioning into components:\n");
		*/
    taskMonitor.setProgress(0.1);
    taskMonitor.setStatusMessage("Finding connected components");
    if (cancelled)
        return;
    int[] renumber = new int[cI.length];
    Graph[] component = graph.partition(cI, renumber);
    final int numComponents = component.length;
    int[][] layer = new int[numComponents][];
    int[][] horizontalPosition = new int[numComponents][];
    Graph[] reduced = new Graph[component.length];
    Graph[] reducedTmp = new Graph[component.length];
    HashMap<Integer, Edge>[] dummy2Edge = new HashMap[component.length];
    int[] dummyStartForComp = new int[component.length];
    HashMap<Edge, View<CyEdge>>[] myEdges2EdgeViews = new HashMap[component.length];
    for (x = 0; x < component.length; x++) {
        /*
			System.out.println("plain component:\n");
			System.out.println(component[x]);
			System.out.println("filtered component:\n");
			System.out.println(component[x].getGraphWithoutOneOrTwoCycles());
			System.out.println("nonmulti component:\n");
			System.out.println(component[x].getGraphWithoutMultipleEdges());
			int cycleEliminationPriority[] = component[x].getCycleEliminationVertexPriority();
			System.out.println("acyclic component:\n");
			System.out.println(component[x].getGraphWithoutCycles(cycleEliminationPriority));
			System.out.println("reduced component:\n");
			System.out.println(component[x].getReducedGraph());
			System.out.println("layer assignment:\n");
			*/
        taskMonitor.setProgress((20 + ((40 * (x * 3)) / numComponents / 3)) / 100.0);
        taskMonitor.setStatusMessage("making acyclic transitive reduction");
        Thread.yield();
        if (cancelled)
            return;
        reducedTmp[x] = component[x].getReducedGraph();
        taskMonitor.setProgress((20 + ((40 * ((x * 3) + 1)) / numComponents / 3)) / 100.0);
        taskMonitor.setStatusMessage("layering nodes vertically");
        Thread.yield();
        if (cancelled)
            return;
        layer[x] = reducedTmp[x].getVertexLayers();
        LinkedList<Integer> layerWithDummy = new LinkedList<Integer>();
        for (int i = 0; i < layer[x].length; i++) layerWithDummy.add(Integer.valueOf(layer[x][i]));
        /*
			int y;
			for (y=0;y<layer[x].length;y++) {
			    System.out.println("" + y + " : " + layer[x][y]);
			}
			System.out.println("horizontal position:\n");
			*/
        /* Insertion of the dummy nodes in the graph */
        Edge[] allEdges = component[x].GetEdges();
        LinkedList<Edge> edgesWithAdd = new LinkedList<Edge>();
        int dummyStart = component[x].getNodecount();
        dummyStartForComp[x] = dummyStart;
        dummy2Edge[x] = new HashMap<Integer, Edge>();
        for (int i = 0; i < allEdges.length; i++) {
            int from = allEdges[i].getFrom();
            int to = allEdges[i].getTo();
            if (layer[x][from] == (layer[x][to] + 1)) {
                edgesWithAdd.add(allEdges[i]);
            } else {
                if (layer[x][from] < layer[x][to]) {
                    int tmp = from;
                    from = to;
                    to = tmp;
                }
                layerWithDummy.add(Integer.valueOf(layer[x][to] + 1));
                dummy2Edge[x].put(Integer.valueOf(layerWithDummy.size() - 1), allEdges[i]);
                edgesWithAdd.add(new Edge(layerWithDummy.size() - 1, to));
                for (int j = layer[x][to] + 2; j < layer[x][from]; j++) {
                    layerWithDummy.add(Integer.valueOf(j));
                    dummy2Edge[x].put(Integer.valueOf(layerWithDummy.size() - 1), allEdges[i]);
                    edgesWithAdd.add(new Edge(layerWithDummy.size() - 1, layerWithDummy.size() - 2));
                }
                edgesWithAdd.add(new Edge(from, layerWithDummy.size() - 1));
            }
        }
        allEdges = new Edge[edgesWithAdd.size()];
        edgesWithAdd.toArray(allEdges);
        reduced[x] = new Graph(layerWithDummy.size(), allEdges);
        reduced[x].setDummyNodesStart(dummyStart);
        reduced[x].setReduced(true);
        int[] layerNew = new int[layerWithDummy.size()];
        Iterator<Integer> iter = layerWithDummy.iterator();
        for (int i = 0; i < layerNew.length; i++) layerNew[i] = iter.next();
        layer[x] = layerNew;
        taskMonitor.setProgress((20 + ((40 * ((x * 3) + 2)) / numComponents / 3)) / 100.0);
        taskMonitor.setStatusMessage("positioning nodes within layer");
        Thread.yield();
        if (cancelled)
            return;
        horizontalPosition[x] = reduced[x].getHorizontalPositionReverse(layer[x]);
    /*
			for (y=0;y<horizontalPosition[x].length;y++) {
			    System.out.println("" + y + " : " + horizontalPosition[x][y]);
			}
			*/
    }
    int resize = renumber.length;
    for (int i = 0; i < component.length; i++) resize += (layer[i].length - dummyStartForComp[i]);
    int[] newRenumber = new int[resize];
    int[] newcI = new int[resize];
    for (int i = 0; i < renumber.length; i++) {
        newRenumber[i] = renumber[i];
        newcI[i] = cI[i];
    }
    int t = renumber.length;
    for (int i = 0; i < reduced.length; i++) {
        for (int j = reduced[i].getDummyNodesStart(); j < reduced[i].getNodecount(); j++) {
            newRenumber[t] = j;
            newcI[t] = i;
            t++;
        }
    }
    renumber = newRenumber;
    cI = newcI;
    edges = new LinkedList<Edge>();
    for (int i = 0; i < reduced.length; i++) {
        edge = reduced[i].GetEdges();
        for (int j = 0; j < edge.length; j++) {
            // uzasna budzevina!!!!!! // FIXME: what does this mean?
            int from = -1;
            int to = -1;
            for (int k = 0; k < cI.length; k++) {
                if ((cI[k] == i) && (renumber[k] == edge[j].getFrom()))
                    from = k;
                if ((cI[k] == i) && (renumber[k] == edge[j].getTo()))
                    to = k;
                if ((from != -1) && (to != -1))
                    break;
            }
            // edges.add(new Edge(to, from));
            edges.add(new Edge(from, to));
        }
    }
    edge = new Edge[edges.size()];
    edges.toArray(edge);
    graph = new Graph(resize, edge);
    taskMonitor.setProgress(0.6);
    taskMonitor.setStatusMessage("Repositioning nodes in view");
    Thread.yield();
    if (cancelled)
        return;
    /* order nodeviews by layout order */
    HierarchyFlowLayoutOrderNode[] flowLayoutOrder = new HierarchyFlowLayoutOrderNode[resize];
    for (x = 0; x < resize; x++) {
        if (x < numLayoutNodes)
            flowLayoutOrder[x] = new HierarchyFlowLayoutOrderNode(nodeViews.get(x), cI[x], reduced[cI[x]].getNodecount(), layer[cI[x]][renumber[x]], horizontalPosition[cI[x]][renumber[x]], x);
        else
            flowLayoutOrder[x] = new HierarchyFlowLayoutOrderNode(null, cI[x], reduced[cI[x]].getNodecount(), layer[cI[x]][renumber[x]], horizontalPosition[cI[x]][renumber[x]], x);
        nodes2HFLON.put(x, flowLayoutOrder[x]);
    }
    Arrays.sort(flowLayoutOrder);
    int lastComponent = -1;
    int lastLayer = -1;
    int startBandY = context.topEdge;
    int cleanBandY = context.topEdge;
    int startComponentX = context.leftEdge;
    int cleanComponentX = context.leftEdge;
    int startLayerY = context.topEdge;
    int cleanLayerY = context.topEdge;
    int cleanLayerX = context.leftEdge;
    int[] layerStart = new int[numLayoutNodes + 1];
    /* layout nodes which are selected */
    int nodeIndex;
    /* layout nodes which are selected */
    int lastComponentEnd = -1;
    for (nodeIndex = 0; nodeIndex < resize; nodeIndex++) {
        HierarchyFlowLayoutOrderNode node = flowLayoutOrder[nodeIndex];
        int currentComponent = node.componentNumber;
        int currentLayer = node.layer;
        View<CyNode> currentView = node.nodeView;
        taskMonitor.setProgress((60 + ((40 * (nodeIndex + 1)) / resize)) / 100.0);
        taskMonitor.setStatusMessage("layering nodes vertically");
        Thread.yield();
        if (cancelled)
            return;
        if (lastComponent == -1) {
            /* this is the first component */
            lastComponent = currentComponent;
            lastLayer = currentLayer;
            layerStart[currentLayer] = -1;
        }
        if (lastComponent != currentComponent) {
            /* new component */
            // first call function for Horizontal Positioning of nodes in lastComponent
            int[] minXArray = new int[1];
            int maxX = HorizontalNodePositioning(nodeIndex - flowLayoutOrder[nodeIndex - 1].componentSize, nodeIndex - 1, flowLayoutOrder, graph, renumber, cI, dummyStartForComp, minXArray);
            int minX = minXArray[0];
            lastComponentEnd = nodeIndex - 1;
            for (int i = nodeIndex - flowLayoutOrder[nodeIndex - 1].componentSize; i <= (nodeIndex - 1); i++) flowLayoutOrder[i].xPos -= (minX - startComponentX);
            maxX -= (minX - startComponentX);
            layerStart[lastLayer] = startComponentX;
            /* initialize for new component */
            startComponentX = cleanComponentX + context.componentSpacing;
            if (maxX > startComponentX)
                startComponentX = maxX + context.componentSpacing;
            if (startComponentX > context.rightMargin) {
                /* new band */
                startBandY = cleanBandY + context.bandGap;
                cleanBandY = startBandY;
                startComponentX = context.leftEdge;
                cleanComponentX = context.leftEdge;
            }
            startLayerY = startBandY;
            cleanLayerY = startLayerY;
            cleanLayerX = startComponentX;
            layerStart[currentLayer] = -1;
        } else if (lastLayer != currentLayer) {
            /* new layer */
            layerStart[lastLayer] = startComponentX;
            startLayerY = cleanLayerY + context.nodeVerticalSpacing;
            cleanLayerY = startLayerY;
            cleanLayerX = startComponentX;
            layerStart[currentLayer] = -1;
        }
        node.setXPos(cleanLayerX);
        node.setYPos(startLayerY);
        cleanLayerX += context.nodeHorizontalSpacing;
        int currentBottom;
        int currentRight;
        if (currentView != null) {
            currentBottom = startLayerY + currentView.getVisualProperty(BasicVisualLexicon.NODE_HEIGHT).intValue();
            currentRight = cleanLayerX + currentView.getVisualProperty(BasicVisualLexicon.NODE_WIDTH).intValue();
        } else {
            currentBottom = startLayerY;
            currentRight = cleanLayerX;
        }
        if (currentBottom > cleanBandY)
            cleanBandY = currentBottom;
        if (currentRight > cleanComponentX)
            cleanComponentX = currentRight;
        if (currentBottom > cleanLayerY)
            cleanLayerY = currentBottom;
        if (currentRight > cleanLayerX)
            cleanLayerX = currentRight;
        lastComponent = currentComponent;
        lastLayer = currentLayer;
    }
    if (cancelled)
        return;
    /* Set horizontal positions of last component */
    int[] minXArray = new int[1];
    HorizontalNodePositioning(lastComponentEnd + 1, resize - 1, flowLayoutOrder, graph, renumber, cI, dummyStartForComp, minXArray);
    int minX = minXArray[0];
    for (int i = lastComponentEnd + 1; i < resize; i++) flowLayoutOrder[i].xPos -= (minX - startComponentX);
    /* Map edges to edge views in order to map dummy nodes to edge bends properly */
    for (View<CyEdge> ev : networkView.getEdgeViews()) {
        Integer edgeFrom = suid2Index.get(ev.getModel().getSource().getSUID());
        Integer edgeTo = suid2Index.get(ev.getModel().getTarget().getSUID());
        if ((edgeFrom == null) || (edgeTo == null)) {
            // Must be from an unselected node
            continue;
        }
        if ((numLayoutNodes <= 1) || ((edgeFrom < numLayoutNodes) && (edgeTo < numLayoutNodes))) {
            /* add edge to graph */
            Edge theEdge = component[cI[edgeFrom]].GetTheEdge(renumber[edgeFrom], renumber[edgeTo]);
            if (myEdges2EdgeViews[cI[edgeFrom]] == null)
                myEdges2EdgeViews[cI[edgeFrom]] = new HashMap<Edge, View<CyEdge>>();
            myEdges2EdgeViews[cI[edgeFrom]].put(theEdge, ev);
        }
    }
    for (nodeIndex = 0; nodeIndex < resize; nodeIndex++) {
        HierarchyFlowLayoutOrderNode node = flowLayoutOrder[nodeIndex];
        if (node.nodeView != null) {
            View<CyNode> currentView = node.nodeView;
            currentView.setVisualProperty(BasicVisualLexicon.NODE_X_LOCATION, Double.valueOf((double) node.getXPos()));
            currentView.setVisualProperty(BasicVisualLexicon.NODE_Y_LOCATION, Double.valueOf((double) node.getYPos()));
        }
    }
    final HandleFactory handleFactory = serviceRegistrar.getService(HandleFactory.class);
    final BendFactory bendFactory = serviceRegistrar.getService(BendFactory.class);
    for (nodeIndex = 0; nodeIndex < resize; nodeIndex++) {
        HierarchyFlowLayoutOrderNode node = flowLayoutOrder[nodeIndex];
        if (node.nodeView == null) {
            Edge theEdge = (Edge) dummy2Edge[cI[node.graphIndex]].get(Integer.valueOf(renumber[node.graphIndex]));
            View<CyEdge> ev = myEdges2EdgeViews[cI[node.graphIndex]].get(theEdge);
            if (ev != null) {
                View<CyNode> source = networkView.getNodeView(ev.getModel().getSource());
                View<CyNode> target = networkView.getNodeView(ev.getModel().getTarget());
                double k = (getYPositionOf(target) - getYPositionOf(source)) / (getXPositionOf(target) - getXPositionOf(source));
                double xPos = getXPositionOf(source);
                if (k != 0)
                    xPos += ((node.yPos - getYPositionOf(source)) / k);
                Bend b = bendFactory.createBend();
                Handle h = handleFactory.createHandle(networkView, ev, xPos, node.yPos);
                b.insertHandleAt(0, h);
                ev.setVisualProperty(BasicVisualLexicon.EDGE_BEND, b);
            }
        }
    }
    for (nodeIndex = 0; nodeIndex < resize; nodeIndex++) {
        HierarchyFlowLayoutOrderNode node = flowLayoutOrder[nodeIndex];
        if (node.nodeView == null) {
            Edge theEdge = dummy2Edge[cI[node.graphIndex]].get(Integer.valueOf(renumber[node.graphIndex]));
            View<CyEdge> ev = myEdges2EdgeViews[cI[node.graphIndex]].get(theEdge);
            if (ev != null) {
                List<Handle> handles = ev.getVisualProperty(BasicVisualLexicon.EDGE_BEND).getAllHandles();
                for (Handle h : handles) {
                    Point2D handelPt = h.calculateHandleLocation(networkView, ev);
                    if (handelPt.getY() == node.yPos) {
                        h.defineHandle(networkView, ev, (double) (node.xPos), (double) (node.yPos));
                        break;
                    }
                }
            }
        }
    }
    taskMonitor.setProgress(1.0);
    taskMonitor.setStatusMessage("hierarchical layout complete");
}
Also used : BendFactory(org.cytoscape.view.presentation.property.values.BendFactory) HashMap(java.util.HashMap) Bend(org.cytoscape.view.presentation.property.values.Bend) ArrayList(java.util.ArrayList) HandleFactory(org.cytoscape.view.presentation.property.values.HandleFactory) Point2D(java.awt.geom.Point2D) CyNode(org.cytoscape.model.CyNode) View(org.cytoscape.view.model.View) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CyEdge(org.cytoscape.model.CyEdge) LinkedList(java.util.LinkedList) Handle(org.cytoscape.view.presentation.property.values.Handle) CyEdge(org.cytoscape.model.CyEdge)

Example 18 with View

use of org.cytoscape.view.model.View in project cytoscape-impl by cytoscape.

the class LayoutSettingsDialog method getLayoutNodes.

private Set<View<CyNode>> getLayoutNodes(CyLayoutAlgorithm layout, CyNetworkView networkView) {
    if (layout.getSupportsSelectedOnly() && selectedTunable.selectedNodesOnly) {
        Set<View<CyNode>> nodeViews = new HashSet<View<CyNode>>();
        CyNetwork network = networkView.getModel();
        for (View<CyNode> view : networkView.getNodeViews()) {
            if (network.getRow(view.getModel()).get(CyNetwork.SELECTED, Boolean.class) && view.getVisualProperty(BasicVisualLexicon.NODE_VISIBLE)) {
                nodeViews.add(view);
            }
        }
        return nodeViews;
    }
    return CyLayoutAlgorithm.ALL_NODE_VIEWS;
}
Also used : CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode) View(org.cytoscape.view.model.View) CyNetworkView(org.cytoscape.view.model.CyNetworkView) HashSet(java.util.HashSet)

Example 19 with View

use of org.cytoscape.view.model.View in project cytoscape-impl by cytoscape.

the class VizMapperMediator method createVisualPropertySheetItems.

@SuppressWarnings("rawtypes")
private Set<VisualPropertySheetItem<?>> createVisualPropertySheetItems(final Class<? extends CyIdentifiable> type, final VisualLexicon lexicon, final VisualStyle style) {
    final Set<VisualPropertySheetItem<?>> items = new HashSet<>();
    if (lexicon == null || style == null)
        return items;
    final Collection<VisualProperty<?>> vpList = lexicon.getAllDescendants(BasicVisualLexicon.NETWORK);
    final CyNetworkView curNetView = vmProxy.getCurrentNetworkView();
    final Set<View<CyNode>> selectedNodeViews = vmProxy.getSelectedNodeViews(curNetView);
    final Set<View<CyEdge>> selectedEdgeViews = vmProxy.getSelectedEdgeViews(curNetView);
    final Set<View<CyNetwork>> selectedNetViews = curNetView != null ? Collections.singleton((View<CyNetwork>) curNetView) : Collections.EMPTY_SET;
    final RenderingEngine<CyNetwork> engine = vizMapperMainPanel.getRenderingEngine();
    for (final VisualProperty<?> vp : vpList) {
        if (vp.getTargetDataType() != type || vp instanceof DefaultVisualizableVisualProperty)
            continue;
        if (!vmProxy.isSupported(vp))
            continue;
        // Create model
        final VisualPropertySheetItemModel<?> model = new VisualPropertySheetItemModel(vp, style, engine, lexicon);
        final Set values;
        if (vp.getTargetDataType() == CyNode.class) {
            values = getDistinctLockedValues(vp, selectedNodeViews);
            updateVpInfoLockedState(model, values, selectedNodeViews);
        } else if (vp.getTargetDataType() == CyEdge.class) {
            values = getDistinctLockedValues(vp, selectedEdgeViews);
            updateVpInfoLockedState(model, values, selectedEdgeViews);
        } else {
            values = getDistinctLockedValues(vp, selectedNetViews);
            updateVpInfoLockedState(model, values, selectedNetViews);
        }
        // Create View
        final VisualPropertySheetItem<?> sheetItem = new VisualPropertySheetItem(model, vizMapPropertyBuilder, servicesUtil);
        items.add(sheetItem);
        // Add listeners to item and model:
        if (model.isVisualMappingAllowed()) {
            sheetItem.getPropSheetPnl().addPropertySheetChangeListener(evt -> {
                if (evt.getPropertyName().equals("value") && evt.getSource() instanceof VizMapperProperty)
                    updateMappingStatus(sheetItem);
            });
        }
        // Set the updated values to the visual style
        model.addPropertyChangeListener("defaultValue", evt -> {
            final VisualStyle vs = model.getVisualStyle();
            vs.setDefaultValue((VisualProperty) vp, evt.getNewValue());
        });
        model.addPropertyChangeListener("visualMappingFunction", evt -> {
            final VisualStyle vs = model.getVisualStyle();
            if (evt.getNewValue() == null && vs.getVisualMappingFunction(vp) != null)
                vs.removeVisualMappingFunction(vp);
            else if (evt.getNewValue() != null && !evt.getNewValue().equals(vs.getVisualMappingFunction(vp)))
                vs.addVisualMappingFunction((VisualMappingFunction<?, ?>) evt.getNewValue());
            updateMappingStatus(sheetItem);
        });
    }
    // Add dependencies
    final Set<VisualPropertyDependency<?>> dependencies = style.getAllVisualPropertyDependencies();
    for (final VisualPropertyDependency<?> dep : dependencies) {
        if (dep.getParentVisualProperty().getTargetDataType() != type)
            continue;
        if (!vmProxy.isSupported(dep))
            continue;
        final VisualPropertySheetItemModel<?> model = new VisualPropertySheetItemModel(dep, style, engine, lexicon);
        final VisualPropertySheetItem<?> sheetItem = new VisualPropertySheetItem(model, vizMapPropertyBuilder, servicesUtil);
        items.add(sheetItem);
    }
    return items;
}
Also used : Set(java.util.Set) SortedSet(java.util.SortedSet) HashSet(java.util.HashSet) CyNetwork(org.cytoscape.model.CyNetwork) CyNetworkView(org.cytoscape.view.model.CyNetworkView) View(org.cytoscape.view.model.View) CyEdge(org.cytoscape.model.CyEdge) VizMapperProperty(org.cytoscape.view.vizmap.gui.internal.VizMapperProperty) VisualPropertyDependency(org.cytoscape.view.vizmap.VisualPropertyDependency) DefaultVisualizableVisualProperty(org.cytoscape.view.presentation.property.DefaultVisualizableVisualProperty) VisualProperty(org.cytoscape.view.model.VisualProperty) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) CyNetworkView(org.cytoscape.view.model.CyNetworkView) HashSet(java.util.HashSet) DefaultVisualizableVisualProperty(org.cytoscape.view.presentation.property.DefaultVisualizableVisualProperty)

Example 20 with View

use of org.cytoscape.view.model.View in project cytoscape-impl by cytoscape.

the class CircularLayoutAlgorithmTask method layoutPartition.

@Override
public void layoutPartition(LayoutPartition partition) {
    if (cancelled)
        return;
    final int numNodes = partition.nodeCount();
    if (numNodes == 1) {
        // We were asked to do a circular layout of a single node -- done!
        return;
    }
    nodeViews = new HashMap<Integer, View<CyNode>>(numNodes);
    Map<CyNode, Integer> nodeIdexMap = new HashMap<CyNode, Integer>();
    int nodeIndex = 0;
    Iterator<LayoutNode> nodeIter = partition.getNodeList().iterator();
    while (nodeIter.hasNext() && !cancelled) {
        // final View<CyNode> nv = nodeIter.next().getNodeView();
        LayoutNode ln = nodeIter.next();
        if (ln.isLocked())
            continue;
        final View<CyNode> nv = ln.getNodeView();
        nodeViews.put(nodeIndex, nv);
        nodeIdexMap.put(nv.getModel(), nodeIndex);
        nodeIndex++;
    }
    if (cancelled)
        return;
    /* create edge list from edges between selected nodes */
    final List<Edge> edges = new LinkedList<Edge>();
    final Iterator<LayoutEdge> edgeIter = partition.edgeIterator();
    while (edgeIter.hasNext() && !cancelled) {
        final LayoutEdge ev = edgeIter.next();
        final Integer edgeFrom = nodeIdexMap.get(ev.getEdge().getSource());
        final Integer edgeTo = nodeIdexMap.get(ev.getEdge().getTarget());
        if ((edgeFrom == null) || (edgeTo == null))
            continue;
        edges.add(new Edge(edgeFrom, edgeTo));
        edges.add(new Edge(edgeTo, edgeFrom));
    }
    nodeIdexMap.clear();
    nodeIdexMap = null;
    if (cancelled)
        return;
    /* find horizontal and vertical coordinates of each node */
    final Edge[] edge = new Edge[edges.size()];
    edges.toArray(edge);
    final Graph graph = new Graph(numNodes, edge);
    if (cancelled)
        return;
    // all false
    posSet = new boolean[nodeViews.size()];
    // all false
    depthPosSet = new boolean[nodeViews.size()];
    bc = graph.biconnectedComponents();
    int maxSize = -1;
    int maxIndex = -1;
    for (int i = 0; i < bc.length; i++) if (bc[i].length > maxSize) {
        maxSize = bc[i].length;
        maxIndex = i;
    }
    if (maxIndex == -1)
        return;
    if (cancelled)
        return;
    drawnBiComps = new boolean[bc.length];
    node2BiComp = new HashMap<Integer, Integer>();
    for (int i = 0; i < bc.length; i++) if (bc[i].length > 3) {
        for (int j = 0; j < bc[i].length; j++) {
            node2BiComp.put(bc[i][j], i);
        }
    }
    final double radius = (48 * maxSize) / (2 * Math.PI);
    final double deltaAngle = (2 * Math.PI) / maxSize;
    double angle = 0;
    int startX = (int) radius;
    int startY = (int) radius;
    edgesFrom = graph.GetEdgesFrom();
    // sorting nodes on inner circle
    bc[maxIndex] = SortInnerCircle(bc[maxIndex]);
    // setting nodes on inner circle
    for (int i = 0; i < bc[maxIndex].length; i++) {
        setOffset(nodeViews.get(bc[maxIndex][i]), startX + (Math.cos(angle) * radius), startY - (Math.sin(angle) * radius));
        posSet[bc[maxIndex][i]] = true;
        angle += deltaAngle;
    }
    drawnBiComps[maxIndex] = true;
    nodeHeights = new HashMap<Integer, Integer>();
    SetOuterCircle(maxIndex, radius, startX, startY, -1);
    if (cancelled)
        return;
    nodeIter = partition.nodeIterator();
    while (nodeIter.hasNext() && !cancelled) {
        final LayoutNode ln = nodeIter.next();
        final View<CyNode> nv = ln.getNodeView();
        ln.setX(nv.getVisualProperty(BasicVisualLexicon.NODE_X_LOCATION));
        ln.setY(nv.getVisualProperty(BasicVisualLexicon.NODE_Y_LOCATION));
        partition.moveNodeToLocation(ln);
    }
}
Also used : LayoutNode(org.cytoscape.view.layout.LayoutNode) HashMap(java.util.HashMap) View(org.cytoscape.view.model.View) CyNetworkView(org.cytoscape.view.model.CyNetworkView) LinkedList(java.util.LinkedList) LayoutEdge(org.cytoscape.view.layout.LayoutEdge) Graph(csapps.layout.algorithms.hierarchicalLayout.Graph) CyNode(org.cytoscape.model.CyNode) LayoutEdge(org.cytoscape.view.layout.LayoutEdge) Edge(csapps.layout.algorithms.hierarchicalLayout.Edge)

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