Java Code Examples for org.jfree.util.TableOrder#BY_ROW

The following examples show how to use org.jfree.util.TableOrder#BY_ROW . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CategoryToPieDataset.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns a value from the dataset.
 *
 * @param item  the item index (zero-based).
 *
 * @return The value (possibly <code>null</code>).
 *
 * @throws IndexOutOfBoundsException if <code>item</code> is not in the
 *     range <code>0</code> to <code>getItemCount() - 1</code>.
 */
@Override
public Number getValue(int item) {
    Number result = null;
    if (item < 0 || item >= getItemCount()) {
        // this will include the case where the underlying dataset is null
        throw new IndexOutOfBoundsException(
                "The 'item' index is out of bounds.");
    }
    if (this.extract == TableOrder.BY_ROW) {
        result = this.source.getValue(this.index, item);
    }
    else if (this.extract == TableOrder.BY_COLUMN) {
        result = this.source.getValue(item, this.index);
    }
    return result;
}
 
Example 2
Source File: CategoryToPieDatasetTest.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Some checks for the getIndex() method.
 */
@Test
public void testGetIndex() {
    DefaultCategoryDataset underlying = new DefaultCategoryDataset();
    underlying.addValue(1.1, "R1", "C1");
    underlying.addValue(2.2, "R1", "C2");
    CategoryToPieDataset d1 = new CategoryToPieDataset(underlying,
            TableOrder.BY_ROW, 0);
    assertEquals(0, d1.getIndex("C1"));
    assertEquals(1, d1.getIndex("C2"));
    assertEquals(-1, d1.getIndex("XX"));

    // try null
    boolean pass = false;
    try {
        d1.getIndex(null);
    }
    catch (IllegalArgumentException e) {
        pass = true;
    }
    assertTrue(pass);
}
 
Example 3
Source File: CategoryToPieDataset.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the keys for the dataset.
 * <p>
 * If the underlying dataset is <code>null</code>, this method returns an
 * empty list.
 *
 * @return The keys.
 */
@Override
public List getKeys() {
    List result = Collections.EMPTY_LIST;
    if (this.source != null) {
        if (this.extract == TableOrder.BY_ROW) {
            result = this.source.getColumnKeys();
        }
        else if (this.extract == TableOrder.BY_COLUMN) {
            result = this.source.getRowKeys();
        }
    }
    return result;
}
 
Example 4
Source File: CategoryToPieDataset.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the keys for the dataset.
 * <p>
 * If the underlying dataset is <code>null</code>, this method returns an
 * empty list.
 *
 * @return The keys.
 */
@Override
public List getKeys() {
    List result = Collections.EMPTY_LIST;
    if (this.source != null) {
        if (this.extract == TableOrder.BY_ROW) {
            result = this.source.getColumnKeys();
        }
        else if (this.extract == TableOrder.BY_COLUMN) {
            result = this.source.getRowKeys();
        }
    }
    return result;
}
 
Example 5
Source File: CategoryToPieDataset.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the number of items (values) in the collection.  If the
 * underlying dataset is <code>null</code>, this method returns zero.
 *
 * @return The item count.
 */
@Override
public int getItemCount() {
    int result = 0;
    if (this.source != null) {
        if (this.extract == TableOrder.BY_ROW) {
            result = this.source.getColumnCount();
        }
        else if (this.extract == TableOrder.BY_COLUMN) {
            result = this.source.getRowCount();
        }
    }
    return result;
}
 
Example 6
Source File: SpiderWebPlot.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a collection of legend items for the spider web chart.
 *
 * @return The legend items (never <code>null</code>).
 */
@Override
public LegendItemCollection getLegendItems() {
    LegendItemCollection result = new LegendItemCollection();
    if (getDataset() == null) {
        return result;
    }
    List keys = null;
    if (this.dataExtractOrder == TableOrder.BY_ROW) {
        keys = this.dataset.getRowKeys();
    }
    else if (this.dataExtractOrder == TableOrder.BY_COLUMN) {
        keys = this.dataset.getColumnKeys();
    }
    if (keys == null) {
        return result;
    }

    int series = 0;
    Iterator iterator = keys.iterator();
    Shape shape = getLegendItemShape();
    while (iterator.hasNext()) {
        Comparable key = (Comparable) iterator.next();
        String label = key.toString();
        String description = label;
        Paint paint = getSeriesPaint(series);
        Paint outlinePaint = getSeriesOutlinePaint(series);
        Stroke stroke = getSeriesOutlineStroke(series);
        LegendItem item = new LegendItem(label, description,
                null, null, shape, paint, stroke, outlinePaint);
        item.setDataset(getDataset());
        item.setSeriesKey(key);
        item.setSeriesIndex(series);
        result.add(item);
        series++;
    }
    return result;
}
 
Example 7
Source File: CategoryToPieDataset.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the index for a given key, or <code>-1</code> if there is no
 * such key.
 *
 * @param key  the key.
 *
 * @return The index for the key, or <code>-1</code>.
 */
@Override
public int getIndex(Comparable key) {
    int result = -1;
    if (this.source != null) {
        if (this.extract == TableOrder.BY_ROW) {
            result = this.source.getColumnIndex(key);
        }
        else if (this.extract == TableOrder.BY_COLUMN) {
            result = this.source.getRowIndex(key);
        }
    }
    return result;
}
 
Example 8
Source File: CategoryToPieDataset.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the number of items (values) in the collection.  If the
 * underlying dataset is <code>null</code>, this method returns zero.
 *
 * @return The item count.
 */
@Override
public int getItemCount() {
    int result = 0;
    if (this.source != null) {
        if (this.extract == TableOrder.BY_ROW) {
            result = this.source.getColumnCount();
        }
        else if (this.extract == TableOrder.BY_COLUMN) {
            result = this.source.getRowCount();
        }
    }
    return result;
}
 
Example 9
Source File: CategoryToPieDataset.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the key at the specified index.
 *
 * @param index  the item index (in the range <code>0</code> to 
 *     <code>getItemCount() - 1</code>).
 *
 * @return The key.
 * 
 * @throws IndexOutOfBoundsException if <code>index</code> is not in the 
 *     specified range.
 */
public Comparable getKey(int index) {
    Comparable result = null;
    if (index < 0 || index >= getItemCount()) {
        // this includes the case where the underlying dataset is null
        throw new IndexOutOfBoundsException("Invalid 'index': " + index);
    }
    if (this.extract == TableOrder.BY_ROW) {
        result = this.source.getColumnKey(index);
    }
    else if (this.extract == TableOrder.BY_COLUMN) {
        result = this.source.getRowKey(index);
    }
    return result;
}
 
Example 10
Source File: CategoryToPieDataset.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the value for a given key.  If the key is not recognised, the
 * method should return <code>null</code> (but note that <code>null</code>
 * can be associated with a valid key also).
 *
 * @param key  the key.
 *
 * @return The value (possibly <code>null</code>).
 */
@Override
public Number getValue(Comparable key) {
    Number result = null;
    int keyIndex = getIndex(key);
    if (keyIndex != -1) {
        if (this.extract == TableOrder.BY_ROW) {
            result = this.source.getValue(this.index, keyIndex);
        }
        else if (this.extract == TableOrder.BY_COLUMN) {
            result = this.source.getValue(keyIndex, this.index);
        }
    }
    return result;
}
 
Example 11
Source File: SpiderWebPlot.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a collection of legend items for the radar chart.
 * 
 * @return The legend items.
 */
public LegendItemCollection getLegendItems() {
    LegendItemCollection result = new LegendItemCollection();

    List keys = null;

    if (this.dataExtractOrder == TableOrder.BY_ROW) {
        keys = this.dataset.getRowKeys();
    }
    else if (this.dataExtractOrder == TableOrder.BY_COLUMN) {
        keys = this.dataset.getColumnKeys();
    }

    if (keys != null) {
        int series = 0;
        Iterator iterator = keys.iterator();
        Shape shape = getLegendItemShape();

        while (iterator.hasNext()) {
            String label = iterator.next().toString();
            String description = label;

            Paint paint = getSeriesPaint(series);
            Paint outlinePaint = getSeriesOutlinePaint(series);
            Stroke stroke = getSeriesOutlineStroke(series);
            LegendItem item = new LegendItem(label, description, 
                    null, null, shape, paint, stroke, outlinePaint);
            result.add(item);
            series++;
        }
    }

    return result;
}
 
Example 12
Source File: CategoryToPieDataset.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the index for a given key, or <code>-1</code> if there is no
 * such key.
 *
 * @param key  the key.
 *
 * @return The index for the key, or <code>-1</code>.
 */
@Override
public int getIndex(Comparable key) {
    int result = -1;
    if (this.source != null) {
        if (this.extract == TableOrder.BY_ROW) {
            result = this.source.getColumnIndex(key);
        }
        else if (this.extract == TableOrder.BY_COLUMN) {
            result = this.source.getRowIndex(key);
        }
    }
    return result;
}
 
Example 13
Source File: MultiplePiePlot.java    From opensim-gui with Apache License 2.0 4 votes vote down vote up
/**
 * Returns a collection of legend items for the pie chart.
 *
 * @return The legend items.
 */
public LegendItemCollection getLegendItems() {

    LegendItemCollection result = new LegendItemCollection();
    
    if (this.dataset != null) {
        List keys = null;
  
        prefetchSectionPaints();
        if (this.dataExtractOrder == TableOrder.BY_ROW) {
            keys = this.dataset.getColumnKeys();
        }
        else if (this.dataExtractOrder == TableOrder.BY_COLUMN) {
            keys = this.dataset.getRowKeys();
        }

        if (keys != null) {
            int section = 0;
            Iterator iterator = keys.iterator();
            while (iterator.hasNext()) {
                Comparable key = (Comparable) iterator.next();
                String label = key.toString();
                String description = label;
                Paint paint = (Paint) this.sectionPaints.get(key);
                LegendItem item = new LegendItem(label, description, 
                        null, null, Plot.DEFAULT_LEGEND_ITEM_CIRCLE, 
                        paint, Plot.DEFAULT_OUTLINE_STROKE, paint);

                result.add(item);
                section++;
            }
        }
        if (this.limit > 0.0) {
            result.add(new LegendItem(this.aggregatedItemsKey.toString(), 
                    this.aggregatedItemsKey.toString(), null, null, 
                    Plot.DEFAULT_LEGEND_ITEM_CIRCLE, 
                    this.aggregatedItemsPaint,
                    Plot.DEFAULT_OUTLINE_STROKE, 
                    this.aggregatedItemsPaint));
        }
    }
    return result;
}
 
Example 14
Source File: MultiplePiePlot.java    From ECG-Viewer with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns a collection of legend items for the pie chart.
 *
 * @return The legend items.
 */
@Override
public LegendItemCollection getLegendItems() {

    LegendItemCollection result = new LegendItemCollection();
    if (this.dataset == null) {
        return result;
    }

    List keys = null;
    prefetchSectionPaints();
    if (this.dataExtractOrder == TableOrder.BY_ROW) {
        keys = this.dataset.getColumnKeys();
    }
    else if (this.dataExtractOrder == TableOrder.BY_COLUMN) {
        keys = this.dataset.getRowKeys();
    }
    if (keys == null) {
        return result;
    }
    int section = 0;
    Iterator iterator = keys.iterator();
    while (iterator.hasNext()) {
        Comparable key = (Comparable) iterator.next();
        String label = key.toString();  // TODO: use a generator here
        String description = label;
        Paint paint = (Paint) this.sectionPaints.get(key);
        LegendItem item = new LegendItem(label, description, null,
                null, getLegendItemShape(), paint,
                Plot.DEFAULT_OUTLINE_STROKE, paint);
        item.setSeriesKey(key);
        item.setSeriesIndex(section);
        item.setDataset(getDataset());
        result.add(item);
        section++;
    }
    if (this.limit > 0.0) {
        LegendItem a = new LegendItem(this.aggregatedItemsKey.toString(),
                this.aggregatedItemsKey.toString(), null, null,
                getLegendItemShape(), this.aggregatedItemsPaint,
                Plot.DEFAULT_OUTLINE_STROKE, this.aggregatedItemsPaint);
        result.add(a);
    }
    return result;
}
 
Example 15
Source File: SpiderWebPlot.java    From opensim-gui with Apache License 2.0 4 votes vote down vote up
/**
 * Draws the plot on a Java 2D graphics device (such as the screen or a
 * printer).
 * 
 * @param g2  the graphics device.
 * @param area  the area within which the plot should be drawn.
 * @param anchor  the anchor point (<code>null</code> permitted).
 * @param parentState  the state from the parent plot, if there is one.
 * @param info  collects info about the drawing.
 */
public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor,
                 PlotState parentState,
                 PlotRenderingInfo info)
{
    // adjust for insets...
    RectangleInsets insets = getInsets();
    insets.trim(area);

    if (info != null) {
        info.setPlotArea(area);
        info.setDataArea(area);
    }

    drawBackground(g2, area);
    drawOutline(g2, area);

    Shape savedClip = g2.getClip();

    g2.clip(area);
    Composite originalComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 
            getForegroundAlpha()));

    if (!DatasetUtilities.isEmptyOrNull(this.dataset)) {
        int seriesCount = 0, catCount = 0;

        if (this.dataExtractOrder == TableOrder.BY_ROW) {
            seriesCount = this.dataset.getRowCount();
            catCount = this.dataset.getColumnCount();
        }
        else {
            seriesCount = this.dataset.getColumnCount();
            catCount = this.dataset.getRowCount();
        }

        // ensure we have a maximum value to use on the axes
        if (this.maxValue == DEFAULT_MAX_VALUE)
            calculateMaxValue(seriesCount, catCount);

        // Next, setup the plot area 
  
        // adjust the plot area by the interior spacing value

        double gapHorizontal = area.getWidth() * getInteriorGap();
        double gapVertical = area.getHeight() * getInteriorGap();

        double X = area.getX() + gapHorizontal / 2;
        double Y = area.getY() + gapVertical / 2;
        double W = area.getWidth() - gapHorizontal;
        double H = area.getHeight() - gapVertical;

        double headW = area.getWidth() * this.headPercent;
        double headH = area.getHeight() * this.headPercent;

        // make the chart area a square
        double min = Math.min(W, H) / 2;
        X = (X + X + W) / 2 - min;
        Y = (Y + Y + H) / 2 - min;
        W = 2 * min;
        H = 2 * min;

        Point2D  centre = new Point2D.Double(X + W / 2, Y + H / 2);
        Rectangle2D radarArea = new Rectangle2D.Double(X, Y, W, H);

        // draw the axis and category label
        for (int cat = 0; cat < catCount; cat++) {
            double angle = getStartAngle()
                    + (getDirection().getFactor() * cat * 360 / catCount);
            
            Point2D endPoint = getWebPoint(radarArea, angle, 1); 
                                                 // 1 = end of axis
            Line2D  line = new Line2D.Double(centre, endPoint);
            g2.setPaint(this.axisLinePaint);
            g2.setStroke(this.axisLineStroke);
            g2.draw(line);
            drawLabel(g2, radarArea, 0.0, cat, angle, 360.0 / catCount);
        }
        
        // Now actually plot each of the series polygons..
        for (int series = 0; series < seriesCount; series++) {
            drawRadarPoly(g2, radarArea, centre, info, series, catCount, 
                    headH, headW);
        }
    }
    else { 
        drawNoDataMessage(g2, area);
    }
    g2.clip(savedClip);
    g2.setComposite(originalComposite);
    drawOutline(g2, area);
}
 
Example 16
Source File: MultiplePiePlot.java    From ccu-historian with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Returns a collection of legend items for the pie chart.
 *
 * @return The legend items.
 */
@Override
public LegendItemCollection getLegendItems() {

    LegendItemCollection result = new LegendItemCollection();
    if (this.dataset == null) {
        return result;
    }

    List keys = null;
    prefetchSectionPaints();
    if (this.dataExtractOrder == TableOrder.BY_ROW) {
        keys = this.dataset.getColumnKeys();
    }
    else if (this.dataExtractOrder == TableOrder.BY_COLUMN) {
        keys = this.dataset.getRowKeys();
    }
    if (keys == null) {
        return result;
    }
    int section = 0;
    Iterator iterator = keys.iterator();
    while (iterator.hasNext()) {
        Comparable key = (Comparable) iterator.next();
        String label = key.toString();  // TODO: use a generator here
        String description = label;
        Paint paint = (Paint) this.sectionPaints.get(key);
        LegendItem item = new LegendItem(label, description, null,
                null, getLegendItemShape(), paint,
                Plot.DEFAULT_OUTLINE_STROKE, paint);
        item.setSeriesKey(key);
        item.setSeriesIndex(section);
        item.setDataset(getDataset());
        result.add(item);
        section++;
    }
    if (this.limit > 0.0) {
        LegendItem a = new LegendItem(this.aggregatedItemsKey.toString(),
                this.aggregatedItemsKey.toString(), null, null,
                getLegendItemShape(), this.aggregatedItemsPaint,
                Plot.DEFAULT_OUTLINE_STROKE, this.aggregatedItemsPaint);
        result.add(a);
    }
    return result;
}
 
Example 17
Source File: SpiderWebPlot.java    From SIMVA-SoS with Apache License 2.0 3 votes vote down vote up
/**
 * Returns the value to be plotted at the interseries of the
 * series and the category.  This allows us to plot
 * <code>BY_ROW</code> or <code>BY_COLUMN</code> which basically is just
 * reversing the definition of the categories and data series being
 * plotted.
 *
 * @param series the series to be plotted.
 * @param cat the category within the series to be plotted.
 *
 * @return The value to be plotted (possibly <code>null</code>).
 *
 * @see #getDataExtractOrder()
 */
protected Number getPlotValue(int series, int cat) {
    Number value = null;
    if (this.dataExtractOrder == TableOrder.BY_ROW) {
        value = this.dataset.getValue(series, cat);
    }
    else if (this.dataExtractOrder == TableOrder.BY_COLUMN) {
        value = this.dataset.getValue(cat, series);
    }
    return value;
}
 
Example 18
Source File: SpiderWebPlot.java    From ECG-Viewer with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns the value to be plotted at the interseries of the
 * series and the category.  This allows us to plot
 * <code>BY_ROW</code> or <code>BY_COLUMN</code> which basically is just
 * reversing the definition of the categories and data series being
 * plotted.
 *
 * @param series the series to be plotted.
 * @param cat the category within the series to be plotted.
 *
 * @return The value to be plotted (possibly <code>null</code>).
 *
 * @see #getDataExtractOrder()
 */
protected Number getPlotValue(int series, int cat) {
    Number value = null;
    if (this.dataExtractOrder == TableOrder.BY_ROW) {
        value = this.dataset.getValue(series, cat);
    }
    else if (this.dataExtractOrder == TableOrder.BY_COLUMN) {
        value = this.dataset.getValue(cat, series);
    }
    return value;
}
 
Example 19
Source File: SpiderWebPlot.java    From opensim-gui with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new spider web plot with the given dataset, with each row
 * representing a series.  
 * 
 * @param dataset  the dataset (<code>null</code> permitted).
 */
public SpiderWebPlot(CategoryDataset dataset) {
    this(dataset, TableOrder.BY_ROW);
}
 
Example 20
Source File: SpiderWebPlot.java    From ccu-historian with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Creates a new spider web plot with the given dataset, with each row
 * representing a series.
 *
 * @param dataset  the dataset (<code>null</code> permitted).
 */
public SpiderWebPlot(CategoryDataset dataset) {
    this(dataset, TableOrder.BY_ROW);
}