Search in sources :

Example 1 with Interval

use of org.gephi.graph.api.Interval in project gephi by gephi.

the class StatisticsControllerImpl method executeDynamic.

private void executeDynamic(DynamicStatistics statistics, DynamicLongTask dynamicLongTask) {
    GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
    GraphModel graphModel = graphController.getGraphModel();
    double window = statistics.getWindow();
    double tick = statistics.getTick();
    GraphView currentView = graphModel.getVisibleView();
    Interval bounds = statistics.getBounds();
    if (bounds == null) {
        if (currentView.isMainView()) {
            bounds = graphModel.getTimeBounds();
        } else {
            bounds = currentView.getTimeInterval();
        }
        statistics.setBounds(bounds);
    }
    if (dynamicLongTask != null) {
        //Count
        int c = (int) ((bounds.getHigh() - window - bounds.getLow()) / tick);
        dynamicLongTask.start(c);
    }
    //Init
    statistics.execute(graphModel);
    //Loop
    for (double low = bounds.getLow(); low <= bounds.getHigh() - window; low += tick) {
        double high = low + window;
        Graph graph = graphModel.getGraphVisible();
        graph.writeLock();
        try {
            GraphView view = graphModel.createView();
            Subgraph g = graphModel.getGraph(view);
            TimeIndex<Node> nodeIndex = graphModel.getNodeTimeIndex(currentView);
            if (Double.isInfinite(nodeIndex.getMinTimestamp()) && Double.isInfinite(nodeIndex.getMaxTimestamp())) {
                for (Node node : graph.getNodes()) {
                    g.addNode(node);
                }
            } else {
                for (Node node : nodeIndex.get(new Interval(low, high))) {
                    g.addNode(node);
                }
            }
            TimeIndex<Edge> edgeIndex = graphModel.getEdgeTimeIndex(currentView);
            if (Double.isInfinite(edgeIndex.getMinTimestamp()) && Double.isInfinite(edgeIndex.getMaxTimestamp())) {
                for (Edge edge : graph.getEdges()) {
                    if (g.contains(edge.getSource()) && g.contains(edge.getTarget())) {
                        g.addEdge(edge);
                    }
                }
            } else {
                for (Edge edge : edgeIndex.get(new Interval(low, high))) {
                    if (g.contains(edge.getSource()) && g.contains(edge.getTarget())) {
                        g.addEdge(edge);
                    }
                }
            }
            statistics.loop(g.getView(), new Interval(low, high));
        } finally {
            graph.writeUnlock();
        }
        //Cancelled?
        if (dynamicLongTask != null && dynamicLongTask.isCancelled()) {
            return;
        } else if (dynamicLongTask != null) {
            dynamicLongTask.progress();
        }
    }
    statistics.end();
    model.addReport(statistics);
}
Also used : Graph(org.gephi.graph.api.Graph) GraphModel(org.gephi.graph.api.GraphModel) Node(org.gephi.graph.api.Node) Subgraph(org.gephi.graph.api.Subgraph) GraphView(org.gephi.graph.api.GraphView) Edge(org.gephi.graph.api.Edge) GraphController(org.gephi.graph.api.GraphController) Interval(org.gephi.graph.api.Interval)

Example 2 with Interval

use of org.gephi.graph.api.Interval in project gephi by gephi.

the class IntervalMapSparklinesGraphicsComponentProvider method getSparklinesXAndYNumbers.

@Override
public Number[][] getSparklinesXAndYNumbers(Object value) {
    IntervalMap intervalMap = (IntervalMap) value;
    ArrayList<Number> xValues = new ArrayList<>();
    ArrayList<Number> yValues = new ArrayList<>();
    if (intervalMap == null) {
        return new Number[2][0];
    }
    Interval[] intervals = intervalMap.toKeysArray();
    Object[] values = intervalMap.toValuesArray();
    Number n;
    for (int i = 0; i < intervals.length; i++) {
        n = (Number) values[i];
        if (n != null) {
            xValues.add(intervals[i].getLow());
            yValues.add(n);
        }
    }
    return new Number[][] { xValues.toArray(new Number[0]), yValues.toArray(new Number[0]) };
}
Also used : ArrayList(java.util.ArrayList) IntervalMap(org.gephi.graph.api.types.IntervalMap) Interval(org.gephi.graph.api.Interval)

Example 3 with Interval

use of org.gephi.graph.api.Interval in project gephi by gephi.

the class ElementDraftImpl method addIntervals.

@Override
public void addIntervals(String intervals) {
    if (!container.getTimeRepresentation().equals(TimeRepresentation.INTERVAL)) {
        String message = NbBundle.getMessage(ElementDraftImpl.class, "ElementDraftException_NotIntervalRepresentation", id);
        container.getReport().logIssue(new Issue(message, Issue.Level.SEVERE));
        return;
    }
    IntervalSet s = (IntervalSet) AttributeUtils.parse(intervals, IntervalSet.class);
    if (timeSet == null) {
        timeSet = s;
    } else {
        for (Interval i : s.toArray()) {
            timeSet.add(i);
        }
    }
}
Also used : Issue(org.gephi.io.importer.api.Issue) IntervalSet(org.gephi.graph.api.types.IntervalSet) Interval(org.gephi.graph.api.Interval)

Example 4 with Interval

use of org.gephi.graph.api.Interval in project gephi by gephi.

the class ElementDraftImpl method addInterval.

@Override
public void addInterval(double intervalStart, double intervalEnd) {
    if (!container.getTimeRepresentation().equals(TimeRepresentation.INTERVAL)) {
        String message = NbBundle.getMessage(ElementDraftImpl.class, "ElementDraftException_NotIntervalRepresentation", id);
        container.getReport().logIssue(new Issue(message, Issue.Level.SEVERE));
        return;
    }
    try {
        Interval interval = new Interval(intervalStart, intervalEnd);
        if (timeSet == null) {
            timeSet = new IntervalSet();
        }
        timeSet.add(interval);
    } catch (Exception e) {
        String interval = "[" + intervalStart + "," + intervalEnd + "]";
        String message = NbBundle.getMessage(ElementDraftImpl.class, "ElementDraftException_IntervalSetError", interval, id, e.getMessage());
        container.getReport().logIssue(new Issue(message, Issue.Level.SEVERE));
    }
}
Also used : Issue(org.gephi.io.importer.api.Issue) IntervalSet(org.gephi.graph.api.types.IntervalSet) Interval(org.gephi.graph.api.Interval)

Example 5 with Interval

use of org.gephi.graph.api.Interval in project gephi-plugins-bootcamp by gephi.

the class ConvertColumnToDynamic method execute.

@Override
public void execute(Table table, Column column) {
    Class dynamicType = AttributeUtils.getIntervalMapType(column.getTypeClass());
    AttributeColumnsController ac = Lookup.getDefault().lookup(AttributeColumnsController.class);
    Element[] rows = ac.getTableAttributeRows(table);
    Object[] values = new Object[rows.length];
    Interval interval = new Interval(Double.parseDouble(start), Double.parseDouble(end));
    for (int i = 0; i < values.length; i++) {
        try {
            IntervalMap val = (IntervalMap) dynamicType.newInstance();
            val.put(interval, rows[i].getAttribute(column));
        } catch (Exception e) {
        }
    }
    table.removeColumn(column);
    Column dynamicColumn = table.addColumn(column.getId(), column.getTitle(), dynamicType, null);
    for (int i = 0; i < values.length; i++) {
        rows[i].setAttribute(dynamicColumn, values[i]);
    }
}
Also used : Column(org.gephi.graph.api.Column) AttributeColumnsController(org.gephi.datalab.api.AttributeColumnsController) Element(org.gephi.graph.api.Element) IntervalMap(org.gephi.graph.api.types.IntervalMap) Interval(org.gephi.graph.api.Interval)

Aggregations

Interval (org.gephi.graph.api.Interval)12 ArrayList (java.util.ArrayList)3 Column (org.gephi.graph.api.Column)3 Graph (org.gephi.graph.api.Graph)3 Node (org.gephi.graph.api.Node)3 TimeRepresentation (org.gephi.graph.api.TimeRepresentation)3 Issue (org.gephi.io.importer.api.Issue)3 Element (org.gephi.graph.api.Element)2 GraphController (org.gephi.graph.api.GraphController)2 GraphModel (org.gephi.graph.api.GraphModel)2 IntervalMap (org.gephi.graph.api.types.IntervalMap)2 IntervalSet (org.gephi.graph.api.types.IntervalSet)2 AttributeColumnsController (org.gephi.datalab.api.AttributeColumnsController)1 AttributeDataColumn (org.gephi.desktop.datalab.tables.columns.AttributeDataColumn)1 ElementDataColumn (org.gephi.desktop.datalab.tables.columns.ElementDataColumn)1 DirectedGraph (org.gephi.graph.api.DirectedGraph)1 Edge (org.gephi.graph.api.Edge)1 GraphView (org.gephi.graph.api.GraphView)1 Subgraph (org.gephi.graph.api.Subgraph)1 ClusteringCoefficient (org.gephi.statistics.plugin.ClusteringCoefficient)1