Skip to content

Commit

Permalink
Fix gephi#1771 Fix timeline graphics
Browse files Browse the repository at this point in the history
  • Loading branch information
eduramiba committed Aug 15, 2017
1 parent 7abb96d commit d00d686
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ Development and Distribution License("CDDL") (collectively, the

import java.math.BigDecimal;
import java.math.BigInteger;
import org.gephi.graph.api.Graph;
import org.gephi.graph.api.types.IntervalMap;
import org.gephi.graph.api.types.TimestampMap;
import org.gephi.timeline.api.TimelineChart;

/**
Expand Down Expand Up @@ -159,4 +162,68 @@ private Number calculateMax(Number[] yValues) {
}
return max;
}

public static TimelineChartImpl of(Graph graph, String column) {
if (graph != null && column != null) {
Object dynamicValue = graph.getAttribute(column);
if (dynamicValue instanceof IntervalMap) {
return TimelineChartImpl.of(column, (IntervalMap) dynamicValue);
} else if (dynamicValue instanceof TimestampMap) {
return TimelineChartImpl.of(column, (TimestampMap) dynamicValue);
}
}

return null;
}

public static TimelineChartImpl of(String column, IntervalMap dynamicValue) {
double[] lowsAndHighs = dynamicValue.getIntervals();
Object[] values = dynamicValue.toValuesArray();

final Number[] xs = new Number[lowsAndHighs.length];
final Number[] ys = new Number[lowsAndHighs.length];

for (int i = 0; i < lowsAndHighs.length; i += 2) {
xs[i] = lowsAndHighs[i];
xs[i + 1] = lowsAndHighs[i + 1];

Number numValue = (Number) values[i];
if (numValue == null) {
numValue = 0.0;
}

ys[i] = numValue;
ys[i + 1] = numValue;
}

if (xs.length > 0) {
return new TimelineChartImpl(column, xs, ys);
} else {
return null;
}
}

public static TimelineChartImpl of(String column, TimestampMap dynamicValue) {
double[] timestamps = dynamicValue.getTimestamps();
Object[] values = dynamicValue.toValuesArray();

final Number[] xs = new Number[timestamps.length];
final Number[] ys = new Number[timestamps.length];

for (int i = 0; i < timestamps.length; i++) {
xs[i] = timestamps[i];
Number numValue = (Number) values[i];
if (numValue == null) {
numValue = 0.0;
}

ys[i] = numValue;
}

if (xs.length > 0) {
return new TimelineChartImpl(column, xs, ys);
} else {
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -354,43 +354,15 @@ public void selectColumn(final String column) {
if (model != null) {
if (!(model.getChart() == null && column == null)
|| (model.getChart() != null && !model.getChart().getColumn().equals(column))) {
if (column != null && graphModel.getGraph().getAttribute(column) != null) {
if (column != null && graphModel.getGraph().getAttribute(column) == null) {
throw new IllegalArgumentException("Not a graph column");
}
Thread thread = new Thread(new Runnable() {

@Override
public void run() {
TimelineChart chart = null;
Graph graph = Lookup.getDefault().lookup(GraphController.class).getGraphModel().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;
// Interval interval;
// for (int j = 0; j < intervals.size(); j++) {
// interval = intervals.get(j);
// Number x = (Double) interval.getLow();
// Number y = (Number) interval.getValue();
// xs[i] = x;
// ys[i] = y;
// i++;
// if (j != intervals.size() - 1 && intervals.get(j + 1).getLow() < interval.getHigh()) {
// xs[i] = (Double) intervals.get(j + 1).getLow();
// } else {
// xs[i] = (Double) interval.getHigh();
// }
// ys[i] = y;
// i++;
// }
// if (xs.length > 0) {
// chart = new TimelineChartImpl(column, xs, ys);
// }
// }
}
TimelineChart chart = TimelineChartImpl.of(graph, column);
model.setChart(chart);

fireTimelineModelEvent(new TimelineModelEvent(TimelineModelEvent.EventType.CHART, model, chart));
Expand Down

0 comments on commit d00d686

Please sign in to comment.