use of org.gephi.timeline.api.TimelineChart in project gephi by gephi.
the class Sparkline method getImage.
public BufferedImage getImage(TimelineModel model, int width, int height) {
double newMin = model.getCustomMin();
double newMax = model.getCustomMax();
TimelineChart newChart = model.getChart();
if (chart == null || newMax != max || newMin != min || image.getWidth() != width || image.getHeight() != height || newChart != chart) {
min = newMin;
max = newMax;
chart = newChart;
if (chart != null) {
double minX = chart.getMinX().doubleValue();
double maxX = chart.getMaxX().doubleValue();
int sparklineWidth = (int) (((maxX - minX) / (max - min)) * width);
parameters = new SparklineParameters(sparklineWidth, height);
parameters.setTransparentBackground(true);
parameters.setDrawArea(true);
image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
int sparklineX = (int) ((minX - min) / (max - min) * width);
BufferedImage sparklineImage = draw();
Graphics g = image.getGraphics();
g.drawImage(sparklineImage, sparklineX, 0, null);
g.dispose();
} else {
return null;
}
}
return image;
}
use of org.gephi.timeline.api.TimelineChart in project gephi by gephi.
the class TimelineTooltip method buildData.
private void buildData(double currentPosition) {
switch(model.getTimeFormat()) {
case DOUBLE:
int exponentMin = (int) Math.round(Math.log10(model.getCustomMin()));
DecimalFormat decimalFormat = new DecimalFormat();
decimalFormat.setRoundingMode(RoundingMode.HALF_EVEN);
if (exponentMin > 0) {
min = String.valueOf(model.getCustomMin());
max = String.valueOf(model.getCustomMax());
position = String.valueOf(currentPosition);
} else {
decimalFormat.setMaximumFractionDigits(Math.abs(exponentMin) + 2);
min = decimalFormat.format(model.getCustomMin());
max = decimalFormat.format(model.getCustomMax());
position = decimalFormat.format(currentPosition);
}
break;
case DATE:
{
DateTime minDate = new DateTime((long) model.getCustomMin());
DateTime maxDate = new DateTime((long) model.getCustomMax());
DateTime posDate = new DateTime((long) currentPosition);
DateTimeFormatter formatter = ISODateTimeFormat.date();
min = formatter.print(minDate);
max = formatter.print(maxDate);
position = formatter.print(posDate);
break;
}
default:
{
DateTime minDate = new DateTime((long) model.getCustomMin());
DateTime maxDate = new DateTime((long) model.getCustomMax());
DateTime posDate = new DateTime((long) currentPosition);
DateTimeFormatter formatter = ISODateTimeFormat.dateTime();
min = formatter.print(minDate);
max = formatter.print(maxDate);
position = formatter.print(posDate);
break;
}
}
if (model.getChart() != null) {
TimelineChart chart = model.getChart();
Number yNumber = chart.getY(currentPosition);
y = yNumber != null ? yNumber.toString() : null;
} else {
y = null;
}
}
Aggregations