Search in sources :

Example 6 with IntervalSet

use of org.gephi.graph.api.types.IntervalSet in project gephi by gephi.

the class ExporterGEXF method writeTimeSet.

private void writeTimeSet(XMLStreamWriter xmlWriter, Graph graph, Element element) throws Exception {
    Interval visibleInterval = graph.getView().getTimeInterval();
    TimeRepresentation timeRepresentation = graph.getModel().getConfiguration().getTimeRepresentation();
    TimeSet timeSet = (TimeSet) element.getAttribute("timeset");
    TimeFormat timeFormat = graph.getModel().getTimeFormat();
    DateTimeZone timeZone = graph.getModel().getTimeZone();
    if (timeSet != null && !timeSet.isEmpty()) {
        if (timeSet.size() > 1) {
            xmlWriter.writeStartElement(SPELLS);
            if (timeRepresentation.equals(TimeRepresentation.INTERVAL)) {
                for (Interval interval : ((IntervalSet) timeSet).toArray()) {
                    if (!exportVisible || interval.compareTo(visibleInterval) == 0) {
                        xmlWriter.writeStartElement(SPELL);
                        if (!Double.isInfinite(interval.getLow())) {
                            String intervalLow = AttributeUtils.printTimestampInFormat(interval.getLow(), timeFormat, timeZone);
                            xmlWriter.writeAttribute(START, intervalLow);
                        }
                        if (!Double.isInfinite(interval.getHigh())) {
                            String intervalHigh = AttributeUtils.printTimestampInFormat(interval.getHigh(), timeFormat, timeZone);
                            xmlWriter.writeAttribute(END, intervalHigh);
                        }
                        xmlWriter.writeEndElement();
                    }
                }
            } else if (timeRepresentation.equals(TimeRepresentation.TIMESTAMP)) {
                for (Double timestamp : ((TimestampSet) timeSet).toArray()) {
                    if (!exportVisible || visibleInterval.compareTo(timestamp) == 0) {
                        xmlWriter.writeStartElement(SPELL);
                        xmlWriter.writeAttribute(TIMESTAMP, AttributeUtils.printTimestampInFormat(timestamp, timeFormat, timeZone));
                        xmlWriter.writeEndElement();
                    }
                }
            }
            xmlWriter.writeEndElement();
        } else if (timeRepresentation.equals(TimeRepresentation.INTERVAL)) {
            Interval interval = ((IntervalSet) timeSet).toArray()[0];
            if (!Double.isInfinite(interval.getLow())) {
                String intervalLow = AttributeUtils.printTimestampInFormat(interval.getLow(), timeFormat, timeZone);
                xmlWriter.writeAttribute(START, intervalLow);
            }
            if (!Double.isInfinite(interval.getHigh())) {
                String intervalHigh = AttributeUtils.printTimestampInFormat(interval.getHigh(), timeFormat, timeZone);
                xmlWriter.writeAttribute(END, intervalHigh);
            }
        } else if (timeRepresentation.equals(TimeRepresentation.TIMESTAMP)) {
            Double timestamp = ((TimestampSet) timeSet).toArray()[0];
            xmlWriter.writeAttribute(TIMESTAMP, AttributeUtils.printTimestampInFormat(timestamp, timeFormat, timeZone));
        }
    }
}
Also used : TimeSet(org.gephi.graph.api.types.TimeSet) IntervalSet(org.gephi.graph.api.types.IntervalSet) DateTimeZone(org.joda.time.DateTimeZone)

Example 7 with IntervalSet

use of org.gephi.graph.api.types.IntervalSet in project gephi by gephi.

the class IntervalSetGraphicsComponentProvider method getTimeIntervalGraphicsParameters.

@Override
public TimeIntervalGraphicsParameters getTimeIntervalGraphicsParameters(TimeSet value) {
    IntervalSet intervalSet = (IntervalSet) value;
    double[] intervals = intervalSet.getIntervals();
    double[] starts = new double[intervals.length / 2];
    double[] ends = new double[intervals.length / 2];
    for (int i = 0, startIndex = 0; startIndex < intervals.length; i++, startIndex += 2) {
        starts[i] = intervals[startIndex];
        ends[i] = intervals[startIndex + 1];
    }
    return new TimeIntervalGraphicsParameters(starts, ends);
}
Also used : IntervalSet(org.gephi.graph.api.types.IntervalSet)

Aggregations

IntervalSet (org.gephi.graph.api.types.IntervalSet)7 AttributeColumnsController (org.gephi.datalab.api.AttributeColumnsController)2 Column (org.gephi.graph.api.Column)2 Element (org.gephi.graph.api.Element)2 Interval (org.gephi.graph.api.Interval)2 Issue (org.gephi.io.importer.api.Issue)2 DateTimeZone (org.joda.time.DateTimeZone)2 TimeFormat (org.gephi.graph.api.TimeFormat)1 TimeSet (org.gephi.graph.api.types.TimeSet)1 TimestampSet (org.gephi.graph.api.types.TimestampSet)1