Example usage for org.jfree.data DefaultContourDataset DefaultContourDataset

List of usage examples for org.jfree.data DefaultContourDataset DefaultContourDataset

Introduction

In this page you can find the example usage for org.jfree.data DefaultContourDataset DefaultContourDataset.

Prototype

public DefaultContourDataset(final String seriesName, final Object[] xData, final Object[] yData,
        final Object[] zData) 

Source Link

Document

Constructs a new dataset with the given data.

Usage

From source file:net.sf.statcvs.output.xml.chart.ModuleActivityChart.java

private ContourDataset createDataset() {
    List dirs = content.getDirectories();
    List dateList = new ArrayList();

    Date firstDate = content.getFirstDate();
    Date lastDate = content.getLastDate();
    Calendar cal = new GregorianCalendar();
    cal.setTime(firstDate);/*  w  w  w .ja  va  2  s .c o m*/
    while (cal.getTime().before(lastDate)) {
        dateList.add(cal.getTime());
        cal.add(Calendar.DATE, 1);
    }
    dateList.add(lastDate);

    Double[][] values = new Double[dateList.size()][dirs.size()];
    for (int i = 0; i < dateList.size(); i++) {
        Iterator dirsIt = dirs.iterator();
        IntegerMap changesMap = new IntegerMap();
        while (dirsIt.hasNext()) {
            Directory dir = (Directory) dirsIt.next();
            RevisionIterator revIt = new RevisionSortIterator(dir.getRevisionIterator());
            while (revIt.hasNext()) {
                CvsRevision rev = revIt.next();
                Date revDate = rev.getDate();
                Date currDate = (Date) dateList.get(i);
                Date nextDate = null;
                if (i < dateList.size() - 1) {
                    nextDate = (Date) dateList.get(i + 1);
                }

                if (revDate.equals(currDate) || (revDate.after(currDate) && revDate.before(nextDate))) {
                    changesMap.inc(dir);
                }
            }
        }
        Iterator cIt = changesMap.iteratorSortedByKey();
        while (cIt.hasNext()) {
            Directory dir = (Directory) cIt.next();
            int dirIndex = dirs.indexOf(dir);
            //values[i][dirIndex] = new Double(changesMap.getPercent(dir));
            values[i][dirIndex] = new Double(changesMap.getPercentOfMaximum(dir));
        }
    }

    int numValues = dateList.size() * dirs.size();
    Date[] oDateX = new Date[numValues];
    Double[] oDoubleY = new Double[numValues];
    Double[] oDoubleZ = new Double[numValues];

    for (int x = 0; x < dateList.size(); x++) {
        for (int y = 0; y < dirs.size(); y++) {
            int index = (x * dirs.size()) + y;
            oDateX[index] = (Date) dateList.get(x);
            oDoubleY[index] = new Double(y);
            if ((values[x][y] != null) && ((values[x][y].isNaN()) || (values[x][y].equals(new Double(0))))) {
                values[x][y] = null;
            }
            oDoubleZ[index] = values[x][y];
        }
    }
    oDoubleZ[0] = new Double(0.0);
    return new DefaultContourDataset(getTitle(), oDateX, oDoubleY, oDoubleZ);
}

From source file:de.berlios.statcvs.xml.report.ActivityProgressionChart.java

private ContourDataset createDataset(Grouper grouper) {
    Map mapByDate = new LinkedHashMap();
    // define 100% to correlate at least to 1
    int max = 0;//from w  w w  .j ava2 s .c om
    long diff = content.getLastDate().getTime() - content.getFirstDate().getTime();
    long day = 24 * 60 * 60 * 1000; // 86400
    //      long windowSize 
    //         = (diff > 10 * 30 * day) 
    //         ? 30 * day
    //         : (diff > 10 * 7 * day)
    //         ? 7 * day
    //         : day;
    long windowSize = Math.max(diff / 60, 1);

    IntegerMap commitsPerGroup = new IntegerMap();
    Iterator it = settings.getRevisionIterator(content);
    long currentDate = -1;
    while (it.hasNext()) {
        CvsRevision rev = (CvsRevision) it.next();
        Date date = rev.getDate();
        if (currentDate == -1) {
            currentDate = date.getTime();
        } else if (date.getTime() > currentDate + windowSize) {
            // save old map
            max = Math.max(commitsPerGroup.max(), max);
            mapByDate.put(new Date(currentDate), commitsPerGroup);

            // create new map
            commitsPerGroup = new IntegerMap();

            // hack: fill in intermediate values
            int fill = (int) ((date.getTime() - currentDate) / windowSize);
            //            for (int i = 0; i < fill; i++) {
            //               currentDate += windowSize;
            //               mapByDate.put(new Date(currentDate), null);
            //               
            //            }
            if (fill > 1) {
                mapByDate.put(new Date(currentDate + windowSize), null);
            }
            currentDate += fill * windowSize;
        }
        commitsPerGroup.inc(grouper.getGroup(rev));
    }

    if (currentDate != -1) {
        mapByDate.put(new Date(currentDate), commitsPerGroup);
        max = Math.max(commitsPerGroup.max(), max);
    }

    Iterator it3 = grouper.getGroups(content, settings);
    while (it3.hasNext()) {
        this.groupNames.add(grouper.getName(it3.next()));
    }
    this.groupCount = groupNames.size();

    int dateCount = mapByDate.size();
    int numValues = dateCount * groupCount;
    if (numValues == 0 || max == 0 || dateCount == 1) {
        return null;
    }

    Date[] oDateX = new Date[numValues];
    Double[] oDoubleY = new Double[numValues];
    Double[] oDoubleZ = new Double[numValues];

    it = mapByDate.keySet().iterator();
    for (int x = 0; x < dateCount; x++) {
        if (!it.hasNext()) {
            throw new RuntimeException("Invalid date count");
        }
        Date date = (Date) it.next();

        IntegerMap map = (IntegerMap) mapByDate.get(date);
        if (map != null) {
            Iterator it2 = grouper.getGroups(content, settings);
            for (int y = 0; y < groupCount; y++) {
                if (!it2.hasNext()) {
                    throw new RuntimeException("Invalid group count");
                }
                Object group = it2.next();

                int index = (x * groupCount) + y;
                oDateX[index] = date;
                oDoubleY[index] = new Double(y);
                double value = (double) map.get(group) * 100.0 / max;
                oDoubleZ[index] = (value != 0) ? new Double(value) : null;
            }
        } else {
            for (int y = 0; y < groupCount; y++) {
                int index = (x * groupCount) + y;
                oDateX[index] = date;
                oDoubleY[index] = new Double(y);
                //oDoubleZ[index] = null;
            }
        }
    }
    //      if (oDoubleZ[0] == null) {
    //         oDoubleZ[0] = new Double(0.0);
    //      }
    return new DefaultContourDataset(null, oDateX, oDoubleY, oDoubleZ);
}