Package org.gephi.graph.api

Examples of org.gephi.graph.api.Graph


    //Settings
    private boolean useOnlyConnections = false;

    @Override
    public void execute(GraphModel graphModel, AttributeModel attributeModel) {
        Graph graph = graphModel.getGraphVisible();
        execute(graph, attributeModel);
    }
View Full Code Here


        double lat = 0;
        float nodeX = 0;
        float nodeY = 0;
        float averageX = 0;
        float averageY = 0;
        Graph gr = graphModel.getGraph();
       
        // try to handle dynamics
        DynamicController dc = Lookup.getDefault().lookup(DynamicController.class);
        DynamicModel dm = dc.getModel();
        boolean isDynamic = dm.isDynamicGraph();
        Graph graph = null;
        Estimator estimator = null;
        TimeInterval timeInt = null;
        Interval currentInt = null;
        if ( isDynamic ) {
            DynamicGraph dg = dm.createDynamicGraph(gr);
            timeInt = dm.getVisibleInterval();
            dg.setInterval(timeInt);
            // Presumably the graph at the given time interval
            graph = dg.getSnapshotGraph(timeInt.getLow(), timeInt.getHigh());
            estimator = dm.getEstimator();
            // Handy for converting DynamicDouble to appropriate primitive
            currentInt = new Interval(timeInt.getLow(), timeInt.getHigh());
        } else {
            graph = gr;
        }
           
        Node[] nodes = graph.getNodes().toArray();
        Vector<Node> validNodes = new Vector<Node>();
        Vector<Node> unvalidNodes = new Vector<Node>();

        // Set valid and non valid nodes:
        for(Node n: nodes){
View Full Code Here

                Thread thread = new Thread(new Runnable() {

                    @Override
                    public void run() {
                        TimelineChart chart = null;
                        Graph graph = Lookup.getDefault().lookup(GraphController.class).getModel().getGraphVisible();
                        if (column != null) {
                            DynamicType type = (DynamicType) graph.getAttributes().getValue(column.getIndex());
                            if (type != null) {
                                List<Interval> intervals = type.getIntervals(model.getCustomMin(), model.getCustomMax());
                                Number[] xs = new Number[intervals.size() * 2];
                                Number[] ys = new Number[intervals.size() * 2];
                                int i = 0;
View Full Code Here

                }
            }

            //Create nodes:
            GraphElementsController gec = Lookup.getDefault().lookup(GraphElementsController.class);
            Graph graph = Lookup.getDefault().lookup(GraphController.class).getModel().getGraph();
            String id = null;
            Node node;
            Attributes nodeAttributes;
            reader = new CsvReader(new FileInputStream(file), separator, charset);
            reader.setTrimWhitespace(false);
            reader.readHeaders();
            while (reader.readRecord()) {
                //Prepare the correct node to assign the attributes:
                if (idColumn != null) {
                    id = reader.get(idColumn);
                    if (id == null || id.isEmpty()) {
                        node = gec.createNode(null);//id null or empty, assign one
                    } else {
                        graph.readLock();
                        node = graph.getNode(id);
                        graph.readUnlock();
                        if (node != null) {//Node with that id already in graph
                            if (assignNewNodeIds) {
                                node = gec.createNode(null);
                            }
                        } else {
View Full Code Here

                }
            }

            //Create edges:
            GraphElementsController gec = Lookup.getDefault().lookup(GraphElementsController.class);
            Graph graph = Lookup.getDefault().lookup(GraphController.class).getModel().getGraph();
            String id = null;
            Edge edge;
            String sourceId, targetId;
            Node source, target;
            String type;
            boolean directed;
            Attributes edgeAttributes;
            reader = new CsvReader(new FileInputStream(file), separator, charset);
            reader.setTrimWhitespace(false);
            reader.readHeaders();
            while (reader.readRecord()) {
                sourceId = reader.get(sourceColumn);
                targetId = reader.get(targetColumn);

                if (sourceId == null || sourceId.isEmpty() || targetId == null || targetId.isEmpty()) {
                    continue;//No correct source and target ids were provided, ignore row
                }

                graph.readLock();
                source = graph.getNode(sourceId);
                graph.readUnlock();

                if (source == null) {
                    if (createNewNodes) {//Create new nodes when they don't exist already and option is enabled
                        if (source == null) {
                            source = gec.createNode(null, sourceId);
                        }
                    } else {
                        continue;//Ignore this edge row, since no new nodes should be created.
                    }
                }

                graph.readLock();
                target = graph.getNode(targetId);
                graph.readUnlock();

                if (target == null) {
                    if (createNewNodes) {//Create new nodes when they don't exist already and option is enabled
                        if (target == null) {
                            target = gec.createNode(null, targetId);
                        }
                    } else {
                        continue;//Ignore this edge row, since no new nodes should be created.
                    }
                }

                if (typeColumn != null) {
                    type = reader.get(typeColumn);
                    //Undirected if indicated correctly, otherwise always directed:
                    if (type != null) {
                        directed = !type.equalsIgnoreCase("undirected");
                    } else {
                        directed = true;
                    }
                } else {
                    directed = true;//Directed by default when not indicated
                }

                //Prepare the correct edge to assign the attributes:
                if (idColumn != null) {
                    id = reader.get(idColumn);
                    if (id == null || id.isEmpty()) {
                        edge = gec.createEdge(source, target, directed);//id null or empty, assign one
                    } else {
                        edge = gec.createEdge(id, source, target, directed);
                        if (edge == null) {//Edge with that id already in graph
                            edge = gec.createEdge(source, target, directed);
                        }
                    }
                } else {
                    edge = gec.createEdge(source, target, directed);
                }

                if (edge != null) {//Edge could be created because it does not already exist:
                    //Assign attributes to the current edge:
                    edgeAttributes = edge.getEdgeData().getAttributes();
                    for (AttributeColumn column : columnsList) {
                        setAttributeValue(reader.get(columnHeaders.get(column)), edgeAttributes, column);
                    }
                } else {
                    //Do not ignore repeated edge, instead increase edge weight
                    edge = graph.getEdge(source, target);
                    if (edge == null) {
                        //Not from source to target but undirected and reverse?
                        edge = graph.getEdge(target, source);
                        if (edge != null && edge.isDirected()) {
                            edge = null;
                        }
                    }
                    if (edge != null) {
View Full Code Here

    public List<List<Node>> detectNodeDuplicatesByColumn(AttributeColumn column, boolean caseSensitive) {
        final HashMap<String, List<Node>> valuesMap = new HashMap<String, List<Node>>();
        final int columnIndex = column.getIndex();

        Graph graph = Lookup.getDefault().lookup(GraphController.class).getModel().getGraph();
        Object value;
        String strValue;
        for (Node node : graph.getNodes().toArray()) {
            value = node.getNodeData().getAttributes().getValue(columnIndex);
            if (value != null) {
                strValue = value.toString();
                if (!caseSensitive) {
                    strValue = strValue.toLowerCase();
View Full Code Here

            @Override
            public void actionPerformed(ActionEvent evt) {
                color = resetColorButton.getColor();
                GraphController gc = Lookup.getDefault().lookup(GraphController.class);
                GraphModel gm = gc.getGraphModel();
                Graph graph = gm.getGraphVisible();
                for (Node n : graph.getNodes()) {
                    n.setR(color.getRed() / 255f);
                    n.setG(color.getGreen() / 255f);
                    n.setB(color.getBlue() / 255f);
                    n.setAlpha(1f);
                }
                for (Edge e : graph.getEdges()) {
                    e.setR(color.getRed() / 255f);
                    e.setG(color.getGreen() / 255f);
                    e.setB(color.getBlue() / 255f);
                    e.setAlpha(0f);
                }
            }
        });
        add(resetColorButton);

        //Reset sizes
        final JButton resetSizeButton = new JButton();
        resetSizeButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/gephi/visualization/component/resetSize.png")));
        resetSizeButton.setToolTipText(NbBundle.getMessage(ActionsToolbar.class, "ActionsToolbar.resetSizes"));
        resetSizeButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                GraphController gc = Lookup.getDefault().lookup(GraphController.class);
                GraphModel gm = gc.getGraphModel();
                Graph graph = gm.getGraphVisible();
                for (Node n : graph.getNodes()) {
                    n.setSize(size);
                }
            }
        });
        resetSizeButton.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {

                if (SwingUtilities.isRightMouseButton(e)) {
                    Object res = JOptionPane.showInputDialog(resetSizeButton, NbBundle.getMessage(ActionsToolbar.class, "ActionsToolbar.resetSizes.dialog"), "" + size);
                    if (res != null) {
                        try {
                            size = Float.parseFloat((String) res);
                        } catch (Exception ex) {
                        }
                    }
                }
            }
        });
        add(resetSizeButton);

        //Reset label colors
        final JButton resetLabelColorButton = new JButton();
        resetLabelColorButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/gephi/visualization/component/resetLabelColor.png")));
        resetLabelColorButton.setToolTipText(NbBundle.getMessage(ActionsToolbar.class, "ActionsToolbar.resetLabelColors"));
        resetLabelColorButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent evt) {
                GraphController gc = Lookup.getDefault().lookup(GraphController.class);
                GraphModel gm = gc.getGraphModel();
                Graph graph = gm.getGraphVisible();
                for (Node n : graph.getNodes().toArray()) {
                    n.getTextProperties().setColor(null);
                }
                for (Edge e : graph.getEdges().toArray()) {
                    e.getTextProperties().setColor(null);
                }
            }
        });
        add(resetLabelColorButton);

        //Reset label colors
        final JButton resetLabelVisibleButton = new JButton();
        resetLabelVisibleButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/gephi/visualization/component/resetLabelVisible.png")));
        resetLabelVisibleButton.setToolTipText(NbBundle.getMessage(ActionsToolbar.class, "ActionsToolbar.resetLabelVisible"));
        resetLabelVisibleButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent evt) {
                GraphController gc = Lookup.getDefault().lookup(GraphController.class);
                GraphModel gm = gc.getGraphModel();
                Graph graph = gm.getGraphVisible();
                for (Node n : graph.getNodes()) {
                    n.getTextProperties().setVisible(true);
                }
                for (Edge e : graph.getEdges()) {
                    e.getTextProperties().setVisible(true);
                }
            }
        });
        add(resetLabelVisibleButton);

        //Reset label size
        JButton resetLabelSizeButton = new JButton();
        resetLabelSizeButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/gephi/visualization/component/resetLabelSize.png")));
        resetLabelSizeButton.setToolTipText(NbBundle.getMessage(ActionsToolbar.class, "ActionsToolbar.resetLabelSizes"));
        resetLabelSizeButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                GraphController gc = Lookup.getDefault().lookup(GraphController.class);
                GraphModel gm = gc.getGraphModel();
                Graph graph = gm.getGraphVisible();
                for (Node n : graph.getNodes()) {
                    n.getTextProperties().setSize(1f);
                }
            }
        });
        add(resetLabelSizeButton);
View Full Code Here

        };
        graphModel.addGraphListener(graphListener);
    }

    private void indexNodeColumnsValues(AttributeColumn[] dynamicCols) {
        Graph graph = graphModel.getGraph();
        for (Node n : graph.getNodes()) {
            Attributes attributeRow = n.getNodeData().getAttributes();
            for (int i = 0; i < dynamicCols.length; i++) {
                DynamicType<?> ti = (DynamicType) attributeRow.getValue(dynamicCols[i].getIndex());
                if (ti != null) {
                    for (Interval interval : ti.getIntervals(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY)) {
View Full Code Here

            }
        }
    }

    private void indexEdgeColumnsValues(AttributeColumn[] dynamicCols) {
        Graph graph = graphModel.getGraph();
        for (Edge e : graph.getEdges()) {
            Attributes attributeRow = e.getEdgeData().getAttributes();
            for (int i = 0; i < dynamicCols.length; i++) {
                DynamicType<?> ti = (DynamicType) attributeRow.getValue(dynamicCols[i].getIndex());
                if (ti != null) {
                    for (Interval interval : ti.getIntervals(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY)) {
View Full Code Here

        this.low = low;
        this.high = high;

        if (low != Double.NEGATIVE_INFINITY || high != Double.POSITIVE_INFINITY) {
            Graph vgraph = model.getGraph(currentView);
            for (Node n : vgraph.getNodes().toArray()) {
                TimeInterval ti = (TimeInterval) n.getNodeData().getAttributes().getValue(
                        DynamicModel.TIMEINTERVAL_COLUMN);
                if (ti != null && !ti.isInRange(low, high)) {
                    vgraph.removeNode(n);
                }
            }
            for (Edge e : vgraph.getEdges().toArray()) {
                TimeInterval ti = (TimeInterval) e.getEdgeData().getAttributes().getValue(
                        DynamicModel.TIMEINTERVAL_COLUMN);
                if (ti != null && !ti.isInRange(low, high)) {
                    vgraph.removeEdge(e);
                }
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.gephi.graph.api.Graph

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.