Search in sources :

Example 1 with TimelineChart

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;
}
Also used : Graphics(java.awt.Graphics) SparklineParameters(org.gephi.utils.sparklines.SparklineParameters) TimelineChart(org.gephi.timeline.api.TimelineChart) BufferedImage(java.awt.image.BufferedImage)

Example 2 with TimelineChart

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;
    }
}
Also used : DecimalFormat(java.text.DecimalFormat) TimelineChart(org.gephi.timeline.api.TimelineChart) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) Point(java.awt.Point) DateTime(org.joda.time.DateTime)

Aggregations

TimelineChart (org.gephi.timeline.api.TimelineChart)2 Graphics (java.awt.Graphics)1 Point (java.awt.Point)1 BufferedImage (java.awt.image.BufferedImage)1 DecimalFormat (java.text.DecimalFormat)1 SparklineParameters (org.gephi.utils.sparklines.SparklineParameters)1 DateTime (org.joda.time.DateTime)1 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)1