Example usage for org.jfree.chart.axis ValueAxis isInverted

List of usage examples for org.jfree.chart.axis ValueAxis isInverted

Introduction

In this page you can find the example usage for org.jfree.chart.axis ValueAxis isInverted.

Prototype

public boolean isInverted() 

Source Link

Document

Returns a flag that controls the direction of values on the axis.

Usage

From source file:org.gumtree.vis.hist2d.Hist2DChartEditor.java

private void initialise(JFreeChart chart) {
    showColorScale.setSelected(chart.isShowSubtitle());
    XYItemRenderer renderer = chart.getXYPlot().getRenderer();
    if (renderer instanceof XYBlockRenderer) {
        PaintScale scale = ((XYBlockRenderer) renderer).getPaintScale();
        if (scale instanceof ColorPaintScale) {
            colourScaleCombo.setSelectedItem(((ColorPaintScale) scale).getColorScale());
            logarithmScale.setSelected(((ColorPaintScale) scale).isLogScale());
        }// w  ww  .j  a  va2s  .  co  m
    }
    ValueAxis axis = chart.getXYPlot().getDomainAxis();
    initialFlipX = axis.isInverted();
    flipX.setSelected(initialFlipX);

    axis = chart.getXYPlot().getRangeAxis();
    initialFlipY = axis.isInverted();
    flipY.setSelected(initialFlipY);

}

From source file:org.gumtree.vis.plot1d.Plot1DChartEditor.java

private void initialise(int seriesIndex) {
    if (seriesIndex >= 0) {
        XYItemRenderer renderer = chart.getXYPlot().getRenderer();
        if (renderer instanceof XYErrorRenderer) {
            //Update show marker field
            showMarker.setSelected(((XYLineAndShapeRenderer) renderer).getBaseShapesVisible());

            //Update show error field
            showError.setSelected(((XYErrorRenderer) renderer).getDrawYError());

            //Update logarithm X filed
            ValueAxis axis = chart.getXYPlot().getDomainAxis();
            if (axis instanceof LogarithmizableAxis) {
                initialLogarithmX = ((LogarithmizableAxis) axis).isLogarithmic();
                logarithmX.setSelected(initialLogarithmX);
            } else {
                logarithmX.setEnabled(false);
            }/*from   ww w  . j ava2s  .  c om*/
            initialFlipX = axis.isInverted();
            flipX.setSelected(initialFlipX);

            initialMargin = (float) axis.getLowerMargin();
            horizontalMargin.setText(String.valueOf(initialMargin));
            //Update logarithm Y filed
            axis = chart.getXYPlot().getRangeAxis();
            if (axis instanceof LogarithmizableAxis) {
                initialLogarithmY = ((LogarithmizableAxis) axis).isLogarithmic();
                logarithmY.setSelected(initialLogarithmY);
            } else {
                logarithmY.setEnabled(false);
            }
            initialFlipY = axis.isInverted();
            flipY.setSelected(initialFlipY);

            //Update series selection combo field
            seriesCombo.setSelectedIndex(seriesIndex);

            //Update curve stroke fields
            Boolean isLineVisible = ((XYLineAndShapeRenderer) renderer).getSeriesLinesVisible(seriesIndex);
            if (isLineVisible == null) {
                isLineVisible = ((XYLineAndShapeRenderer) renderer).getBaseLinesVisible();
            }
            if (isLineVisible) {
                Stroke stroke = renderer.getSeriesStroke(seriesIndex);
                curveStrokeSample.setStroke(stroke);
                if (stroke instanceof BasicStroke) {
                    strokeCombo.setSelectedItem(new Float(((BasicStroke) stroke).getLineWidth()));
                }
            } else {
                curveStrokeSample.setStroke(null);
                strokeCombo.setSelectedIndex(0);
            }

            //Update curve colour fields
            Paint paint = renderer.getSeriesPaint(seriesIndex);
            curveColorPaint.setPaint(paint);

            //Update marker fill field
            Boolean seriesShapeFilled = ((XYLineAndShapeRenderer) renderer).getSeriesShapesFilled(seriesIndex);
            if (seriesShapeFilled == null) {
                seriesShapeFilled = ((XYLineAndShapeRenderer) renderer).getBaseShapesFilled();
            }
            if (seriesShapeFilled != null) {
                markerFilled.setSelected(seriesShapeFilled);
            }

            //Update marker shape fields
            Boolean isShapeVisible = ((XYLineAndShapeRenderer) renderer)
                    .getSeriesShapesVisible(currentSeriesIndex);
            if (isShapeVisible == null) {
                isShapeVisible = true;
            }
            if (isShapeVisible) {
                Shape serieseShape = renderer.getSeriesShape(seriesIndex);
                currentShape = MarkerShape.findMarkerShape(serieseShape);
                shapeLabel.setIcon(MarkerShape.createIcon(serieseShape, paint, markerFilled.isSelected()));
                shapeLabel.setText(null);
            } else {
                currentShape = MarkerShape.NONE;
                shapeLabel.setIcon(null);
                shapeLabel.setText("None");
            }
            updateComborender(paint, markerFilled.isSelected());

            //Update curve visibility field
            Boolean isCurveVisible = ((XYLineAndShapeRenderer) renderer).isSeriesVisible(seriesIndex);
            if (isCurveVisible == null) {
                isCurveVisible = ((XYLineAndShapeRenderer) renderer).getBaseSeriesVisible();
            }
            curveVisable.setSelected(isCurveVisible);
        }
    }
}

From source file:org.gumtree.vis.plot1d.Plot1DPanel.java

private double getBinWidth() {
    double binWidth = 0;
    try {/*  w  ww  .  jav a  2s . c o m*/
        ValueAxis axis = getChart().getXYPlot().getDomainAxis();
        double max = axis.getUpperBound();
        double min = axis.getLowerBound();
        binWidth = (max - min) / StaticValues.DOMAIN_MASK_SHIFT_RESOLUTION;
        if (axis.isInverted()) {
            binWidth = -binWidth;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return binWidth;
}

From source file:edu.dlnu.liuwenpeng.render.BarRenderer.java

/**    
* Draws the bar for a single (series, category) data item.    
*    /*  w w  w .j  a  v a2 s. c  om*/
* @param g2  the graphics device.    
* @param state  the renderer state.    
* @param dataArea  the data area.    
* @param plot  the plot.    
* @param domainAxis  the domain axis.    
* @param rangeAxis  the range axis.    
* @param dataset  the dataset.    
* @param row  the row index (zero-based).    
* @param column  the column index (zero-based).    
* @param pass  the pass index.    
*/
public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot,
        CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) {

    // nothing is drawn for null values...   

    Number dataValue = dataset.getValue(row, column);
    if (dataValue == null) {
        return;
    }

    double value = dataValue.doubleValue();
    PlotOrientation orientation = plot.getOrientation();
    double barW0 = calculateBarW0(plot, orientation, dataArea, domainAxis, state, row, column);
    double[] barL0L1 = calculateBarL0L1(value);
    if (barL0L1 == null) {
        return; // the bar is not visible    
    }

    RectangleEdge edge = plot.getRangeAxisEdge();
    double transL0 = rangeAxis.valueToJava2D(barL0L1[0], dataArea, edge);
    double transL1 = rangeAxis.valueToJava2D(barL0L1[1], dataArea, edge);

    // in the following code, barL0 is (in Java2D coordinates) the LEFT    
    // end of the bar for a horizontal bar chart, and the TOP end of the    
    // bar for a vertical bar chart.  Whether this is the BASE of the bar    
    // or not depends also on (a) whether the data value is 'negative'    
    // relative to the base value and (b) whether or not the range axis is    
    // inverted.  This only matters if/when we apply the minimumBarLength    
    // attribute, because we should extend the non-base end of the bar    
    boolean positive = (value >= this.base);
    boolean inverted = rangeAxis.isInverted();
    double barL0 = Math.min(transL0, transL1);
    double barLength = Math.abs(transL1 - transL0);
    double barLengthAdj = 0.0;
    if (barLength > 0.0 && barLength < getMinimumBarLength()) {
        barLengthAdj = getMinimumBarLength() - barLength;
    }
    double barL0Adj = 0.0;
    if (orientation == PlotOrientation.HORIZONTAL) {
        if (positive && inverted || !positive && !inverted) {
            barL0Adj = barLengthAdj;
        }
    } else {
        if (positive && !inverted || !positive && inverted) {
            barL0Adj = barLengthAdj;
        }
    }

    // draw the bar...    
    Rectangle2D bar = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
        bar = new Rectangle2D.Double(barL0 - barL0Adj, barW0, barLength + barLengthAdj, state.getBarWidth());
    } else {

        bar = new Rectangle2D.Double(barW0, barL0 - barL0Adj, state.getBarWidth(), barLength + barLengthAdj);
    }
    Paint itemPaint = getItemPaint(row, column);
    if (dataset.getValue(row, column).doubleValue() >= 0) {
        itemPaint = Color.red;

    } else {
        itemPaint = Color.GREEN;
    }
    GradientPaintTransformer t = getGradientPaintTransformer();
    if (t != null && itemPaint instanceof GradientPaint) {
        itemPaint = t.transform((GradientPaint) itemPaint, bar);
    }
    g2.setPaint(itemPaint);
    g2.fill(bar);

    // draw the outline...    
    if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) {
        Stroke stroke = getItemOutlineStroke(row, column);
        Paint paint = getItemOutlinePaint(row, column);

        if (dataset.getValue(row, column).doubleValue() >= 0) {
            paint = Color.red;

        } else {
            paint = Color.green;
        }
        if (stroke != null && paint != null) {
            g2.setStroke(stroke);

            g2.setPaint(paint);
            g2.draw(bar);
        }
    }

    CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column);
    if (generator != null && isItemLabelVisible(row, column)) {
        drawItemLabel(g2, dataset, row, column, plot, generator, bar, (value < 0.0));
    }

    // add an item entity, if this information is being collected    
    EntityCollection entities = state.getEntityCollection();
    if (entities != null) {
        addItemEntity(entities, dataset, row, column, bar);
    }

}

From source file:KIDLYRenderer.java

/**
 * Draws the bar for a single (series, category) data item.
 *
 * @param g2  the graphics device.//from   w w  w .  j av a  2  s  .co  m
 * @param state  the renderer state.
 * @param dataArea  the data area.
 * @param plot  the plot.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param dataset  the dataset.
 * @param row  the row index (zero-based).
 * @param column  the column index (zero-based).
 * @param pass  the pass index.
 */
public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot,
        CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) {

    // nothing is drawn if the row index is not included in the list with
    // the indices of the visible rows...
    int visibleRow = state.getVisibleSeriesIndex(row);
    if (visibleRow < 0) {
        return;
    }
    // nothing is drawn for null values...
    Number dataValue = dataset.getValue(row, column);
    if (dataValue == null) {
        return;
    }

    final double value = dataValue.doubleValue();
    PlotOrientation orientation = plot.getOrientation();
    double barW0 = calculateBarW0(plot, orientation, dataArea, domainAxis, state, visibleRow, column);
    double[] barL0L1 = calculateBarL0L1(value);
    if (barL0L1 == null) {
        return; // the bar is not visible
    }

    RectangleEdge edge = plot.getRangeAxisEdge();
    double transL0 = rangeAxis.valueToJava2D(barL0L1[0], dataArea, edge);
    double transL1 = rangeAxis.valueToJava2D(barL0L1[1], dataArea, edge);

    // in the following code, barL0 is (in Java2D coordinates) the LEFT
    // end of the bar for a horizontal bar chart, and the TOP end of the
    // bar for a vertical bar chart.  Whether this is the BASE of the bar
    // or not depends also on (a) whether the data value is 'negative'
    // relative to the base value and (b) whether or not the range axis is
    // inverted.  This only matters if/when we apply the minimumBarLength
    // attribute, because we should extend the non-base end of the bar
    boolean positive = (value >= this.base);
    boolean inverted = rangeAxis.isInverted();
    double barL0 = Math.min(transL0, transL1);
    double barLength = Math.abs(transL1 - transL0);
    double barLengthAdj = 0.0;
    if (barLength > 0.0 && barLength < getMinimumBarLength()) {
        barLengthAdj = getMinimumBarLength() - barLength;
    }
    double barL0Adj = 0.0;
    RectangleEdge barBase;
    if (orientation == PlotOrientation.HORIZONTAL) {
        if (positive && inverted || !positive && !inverted) {
            barL0Adj = barLengthAdj;
            barBase = RectangleEdge.RIGHT;
        } else {
            barBase = RectangleEdge.LEFT;
        }
    } else {
        if (positive && !inverted || !positive && inverted) {
            barL0Adj = barLengthAdj;
            barBase = RectangleEdge.BOTTOM;
        } else {
            barBase = RectangleEdge.TOP;
        }
    }

    // draw the bar...
    Rectangle2D bar = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
        bar = new Rectangle2D.Double(barL0 - barL0Adj, barW0, barLength + barLengthAdj, state.getBarWidth());
    } else {
        bar = new Rectangle2D.Double(barW0, barL0 - barL0Adj, state.getBarWidth(), barLength + barLengthAdj);
    }
    /* if (getShadowsVisible()) {
    this.barPainter.paintBarShadow(g2, this, row, column, bar, barBase,
        true);
     }
     this.barPainter.paintBar(g2, this, row, column, bar, barBase);*/

    CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column);
    if (generator != null && isItemLabelVisible(row, column)) {
        drawItemLabel(g2, dataset, row, column, plot, generator, bar, (value < 0.0));
    }

    // submit the current data point as a crosshair candidate
    int datasetIndex = plot.indexOf(dataset);
    updateCrosshairValues(state.getCrosshairState(), dataset.getRowKey(row), dataset.getColumnKey(column),
            value, datasetIndex, barW0, barL0, orientation);

    // add an item entity, if this information is being collected
    EntityCollection entities = state.getEntityCollection();
    if (entities != null) {
        addItemEntity(entities, dataset, row, column, bar);
    }

}

From source file:org.trade.ui.chart.renderer.VolumeBarRenderer.java

/**
 * Draws the visual representation of a single data item.
 * //from   www.  ja v  a  2 s  .c  o  m
 * @param g2
 *            the graphics device.
 * @param state
 *            the renderer state.
 * @param dataArea
 *            the area within which the plot is being drawn.
 * @param info
 *            collects information about the drawing.
 * @param plot
 *            the plot (can be used to obtain standard color information
 *            etc).
 * @param domainAxis
 *            the domain axis.
 * @param rangeAxis
 *            the range axis.
 * @param dataset
 *            the dataset.
 * @param series
 *            the series index (zero-based).
 * @param item
 *            the item index (zero-based).
 * @param crosshairState
 *            crosshair information for the plot (<code>null</code>
 *            permitted).
 * @param pass
 *            the pass index.
 * @see org.jfree.chart.renderer.xy.XYItemRenderer#drawItem(Graphics2D,
 *      XYItemRendererState, Rectangle2D, PlotRenderingInfo, XYPlot,
 *      ValueAxis, ValueAxis, XYDataset, int, int, CrosshairState, int)
 */
public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info,
        XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item,
        CrosshairState crosshairState, int pass) {

    if (!getItemVisible(series, item)) {
        return;
    }

    VolumeDataset volumeDataset = (VolumeDataset) dataset;
    VolumeItem volumeItem = (VolumeItem) volumeDataset.getSeries(series).getDataItem(item);

    if (volumeItem.isSide()) {
        this.color = Color.GREEN;
    } else {
        this.color = Color.RED;
    }

    double value0;
    double value1;
    if (this.getUseYInterval()) {
        value0 = volumeDataset.getStartYValue(series, item);
        value1 = volumeDataset.getEndYValue(series, item);
    } else {
        value0 = this.getBase();
        value1 = volumeDataset.getYValue(series, item);
    }
    if (Double.isNaN(value0) || Double.isNaN(value1)) {
        return;
    }
    if (value0 <= value1) {
        if (!rangeAxis.getRange().intersects(value0, value1)) {
            return;
        }
    } else {
        if (!rangeAxis.getRange().intersects(value1, value0)) {
            return;
        }
    }

    double translatedValue0 = rangeAxis.valueToJava2D(value0, dataArea, plot.getRangeAxisEdge());
    double translatedValue1 = rangeAxis.valueToJava2D(value1, dataArea, plot.getRangeAxisEdge());
    double bottom = Math.min(translatedValue0, translatedValue1);
    double top = Math.max(translatedValue0, translatedValue1);

    double startX = volumeItem.getPeriod().getFirstMillisecond();
    if (Double.isNaN(startX)) {
        return;
    }
    double endX = volumeItem.getPeriod().getLastMillisecond();
    if (Double.isNaN(endX)) {
        return;
    }

    if (startX <= endX) {
        if (!domainAxis.getRange().intersects(startX, endX)) {
            return;
        }
    } else {
        if (!domainAxis.getRange().intersects(endX, startX)) {
            return;
        }
    }

    // is there an alignment adjustment to be made?
    if (this.getBarAlignmentFactor() >= 0.0 && this.getBarAlignmentFactor() <= 1.0) {
        double x = volumeDataset.getXValue(series, item);
        double interval = endX - startX;
        startX = x - interval * this.getBarAlignmentFactor();
        endX = startX + interval;
    }

    RectangleEdge location = plot.getDomainAxisEdge();
    double translatedStartX = domainAxis.valueToJava2D(startX, dataArea, location);
    double translatedEndX = domainAxis.valueToJava2D(endX, dataArea, location);

    double translatedWidth = Math.max(1, Math.abs(translatedEndX - translatedStartX));

    RectangleEdge domainEdge = plot.getDomainAxisEdge();
    double xx = domainAxis.valueToJava2D(startX, dataArea, domainEdge);

    if (getMargin() > 0.0) {
        double cut = translatedWidth * getMargin();
        translatedWidth = translatedWidth - cut;
    }

    Rectangle2D bar = null;
    PlotOrientation orientation = plot.getOrientation();
    if (orientation == PlotOrientation.HORIZONTAL) {
        // clip left and right bounds to data area
        bottom = Math.max(bottom, dataArea.getMinX());
        top = Math.min(top, dataArea.getMaxX());
        bar = new Rectangle2D.Double(bottom, xx, top - bottom, translatedWidth);
    } else if (orientation == PlotOrientation.VERTICAL) {
        // clip top and bottom bounds to data area
        bottom = Math.max(bottom, dataArea.getMinY());
        top = Math.min(top, dataArea.getMaxY());
        bar = new Rectangle2D.Double(xx - (translatedWidth / 2), bottom, translatedWidth, top - bottom);
    }

    boolean positive = (value1 > 0.0);
    boolean inverted = rangeAxis.isInverted();
    RectangleEdge barBase;
    if (orientation == PlotOrientation.HORIZONTAL) {
        if (positive && inverted || !positive && !inverted) {
            barBase = RectangleEdge.RIGHT;
        } else {
            barBase = RectangleEdge.LEFT;
        }
    } else {
        if (positive && !inverted || !positive && inverted) {
            barBase = RectangleEdge.BOTTOM;
        } else {
            barBase = RectangleEdge.TOP;
        }
    }
    if (getShadowsVisible()) {
        this.getBarPainter().paintBarShadow(g2, this, series, item, bar, barBase, !this.getUseYInterval());
    }
    this.getBarPainter().paintBar(g2, this, series, item, bar, barBase);

    if (isItemLabelVisible(series, item)) {
        XYItemLabelGenerator generator = getItemLabelGenerator(series, item);
        drawItemLabel(g2, dataset, series, item, plot, generator, bar, value1 < 0.0);
    }

    // update the cross hair point
    double x1 = dataset.getXValue(series, item);
    double y1 = dataset.getYValue(series, item);
    double transX1 = domainAxis.valueToJava2D(x1, dataArea, location);
    double transY1 = rangeAxis.valueToJava2D(y1, dataArea, plot.getRangeAxisEdge());
    int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
    int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
    updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex, rangeAxisIndex, transX1, transY1,
            plot.getOrientation());

    EntityCollection entities = state.getEntityCollection();
    // add an entity for the item...
    if (entities != null) {
        String tip = null;
        XYToolTipGenerator generator = getToolTipGenerator(series, item);
        if (generator != null) {
            tip = generator.generateToolTip(dataset, series, item);
        }
        XYItemEntity entity = new XYItemEntity(bar, dataset, series, item, tip, null);

        entities.add(entity);
    }
}