Example usage for org.jfree.chart.plot XYPlot setRangeCrosshairValue

List of usage examples for org.jfree.chart.plot XYPlot setRangeCrosshairValue

Introduction

In this page you can find the example usage for org.jfree.chart.plot XYPlot setRangeCrosshairValue.

Prototype

public void setRangeCrosshairValue(double value) 

Source Link

Document

Sets the range crosshair value.

Usage

From source file:cgpanalyser.gui.chart.ChartCreator.java

/**
 * Sets value of crosshair to first item in chart.
 *
 * @param jfreechart/*  w ww  .j  ava 2s  .  c o  m*/
 */
private void setCrosshairDefaultValue(XYPlot plot, XYDataset dataset) {
    if (dataset.getItemCount(0) != 0) {
        plot.setDomainCrosshairValue(dataset.getXValue(0, 0));
        plot.setRangeCrosshairValue(dataset.getYValue(0, 0));
    }
}

From source file:cgpanalyser.gui.chart.XYChartPanel.java

public void setNextCrosshairValue(JFreeChart jfreechart) {
    XYPlot plot = (XYPlot) jfreechart.getPlot();
    XYDataset dataset = plot.getDataset();

    //set crosshair to next value if not on last already
    for (int i = 0; i < dataSampler.getLastToDisplay().size() - 1; i++) { //find generation in datasampler.todisplay
        if ((int) plot.getDomainCrosshairValue() == dataSampler.getLastToDisplay().get(i).getGenNumber()) {
            plot.setDomainCrosshairValue(dataset.getXValue(0, i + 1));
            plot.setRangeCrosshairValue(dataset.getYValue(0, i + 1));
            break;
        }//from  w  w w .  ja v  a  2s .  c om
    }

}

From source file:org.lmn.fc.frameworks.starbase.plugins.observatory.ui.tabs.charts.ChartUIHelper.java

/***********************************************************************************************
 * Draw the Chart Crosshair values on the XYPlot if possible.
 * Used by refreshChart()./*from  www .  j av  a  2s.c om*/
 * This should be followed by fireChartChanged() when all updates are complete.
 *
 * @param chartui
 * @param debug
 */

public static void drawChartCrosshairsOnXYPlot(final ChartUIComponentPlugin chartui, final boolean debug) {
    final String SOURCE = "ChartHelper.drawChartCrosshairsOnXYPlot() ";

    // RangeCrosshair
    if ((chartui != null) && (chartui.getRangeCrosshair() > ChartUIComponentPlugin.RANGE_MIN)
            && (chartui.getChartPanel() != null) && (chartui.getChartPanel().getChart() != null)
            && (chartui.getChartPanel().getChart().getXYPlot() != null)) {
        final XYPlot plot;
        final ValueAxis rangeAxis;
        final Range range;
        final double dblPositionFraction;
        final double dblRangeCrosshairXYPlot;

        plot = (XYPlot) chartui.getChartPanel().getChart().getPlot();
        rangeAxis = plot.getRangeAxis();
        range = rangeAxis.getRange();

        dblPositionFraction = (chartui.getRangeCrosshair() - ChartUIComponentPlugin.RANGE_MIN)
                / (double) (ChartUIComponentPlugin.RANGE_MAX - ChartUIComponentPlugin.RANGE_MIN);
        dblRangeCrosshairXYPlot = rangeAxis.getLowerBound() + (dblPositionFraction * range.getLength());

        FrameworkSingletons.LOGGER.debug(debug,
                SOURCE + "Draw Range Crosshair on XYPlot [crosshair.range=" + chartui.getRangeCrosshair()
                        + "] [crosshair.xyplot=" + dblRangeCrosshairXYPlot + "] [range.min="
                        + ChartUIComponentPlugin.RANGE_MIN + "] [range.max=" + ChartUIComponentPlugin.RANGE_MAX
                        + "]");

        plot.setRangeCrosshairValue(dblRangeCrosshairXYPlot);
    }

    // DomainCrosshair
    if ((chartui != null) && (chartui.getDomainCrosshair() > ChartUIComponentPlugin.DOMAIN_MIN)
            && (chartui.getChartPanel() != null) && (chartui.getChartPanel().getChart() != null)
            && (chartui.getChartPanel().getChart().getXYPlot() != null)) {
        final XYPlot plot;
        final ValueAxis domainAxis;
        final Range range;
        final double dblPositionFraction;
        final double dblDomainCrosshairXYPlot;

        plot = (XYPlot) chartui.getChartPanel().getChart().getPlot();
        domainAxis = plot.getDomainAxis();
        range = domainAxis.getRange();

        // ToDo WARNING! Needs to be the same as for the slider??
        dblPositionFraction = (chartui.getDomainCrosshair()
                - ChartUIComponentPlugin.OFFSET_CONTROL_COARSE_MINIMUM)
                / (double) (ChartUIComponentPlugin.OFFSET_CONTROL_COARSE_MAXIMUM
                        - ChartUIComponentPlugin.OFFSET_CONTROL_COARSE_MINIMUM);
        //            dblPositionFraction = (chartui.getDomainCrosshair() - ChartUIComponentPlugin.DOMAIN_MIN) / (double)(ChartUIComponentPlugin.DOMAIN_MAX - ChartUIComponentPlugin.DOMAIN_MIN);
        dblDomainCrosshairXYPlot = domainAxis.getLowerBound() + (dblPositionFraction * range.getLength());

        FrameworkSingletons.LOGGER.debug(debug,
                SOURCE + "Draw Domain Crosshair on XYPlot [crosshair.domain=" + chartui.getDomainCrosshair()
                        + "] [crosshair.xyplot=" + dblDomainCrosshairXYPlot + "] [domain.min="
                        + ChartUIComponentPlugin.OFFSET_CONTROL_COARSE_MINIMUM + "] [domain.max="
                        + ChartUIComponentPlugin.OFFSET_CONTROL_COARSE_MAXIMUM + "]");

        //            LOGGER.debug(debug,
        //                         SOURCE + "Draw Domain Crosshair on XYPlot [crosshair.domain=" + chartui.getDomainCrosshair()
        //                                + "] [crosshair.xyplot=" + dblDomainCrosshairXYPlot
        //                                + "] [domain.min=" + ChartUIComponentPlugin.DOMAIN_MIN
        //                                + "] [domain.max=" + ChartUIComponentPlugin.DOMAIN_MAX
        //                                + "]");
        //
        plot.setDomainCrosshairValue(dblDomainCrosshairXYPlot);
    }
}

From source file:cgpanalyser.gui.chart.XYChartPanel.java

public void setPrevCrosshairValue(JFreeChart jfreechart) {
    XYPlot plot = (XYPlot) jfreechart.getPlot();
    XYDataset dataset = plot.getDataset();

    //set crosshair to previous value if not on first already
    for (int i = 0; i < dataSampler.getLastToDisplay().size(); i++) { //find generation in datasampler.todisplay
        if ((int) plot.getDomainCrosshairValue() == dataSampler.getLastToDisplay().get(i).getGenNumber()) {
            if (i > 0) {
                plot.setDomainCrosshairValue(dataset.getXValue(0, i - 1));
                plot.setRangeCrosshairValue(dataset.getYValue(0, i - 1));
            }//w w  w  .  j  a  v  a2s  .c  o m
            break;
        }
    }

}

From source file:org.lmn.fc.frameworks.starbase.plugins.observatory.ui.tabs.charts.GpsScatterPlotUIComponent.java

/***********************************************************************************************
 * Update the Centroid Crosshairs, provided that ObservatoryMetadata contains valid
 * Observation.Centroid.Longitude and Observation.Centroid.Latitude.
 *//*from w  w w . jav  a 2 s  . c  om*/

private void updateCentroidCrosshairs() {
    final String SOURCE = "GpsScatterPlotUIComponent.updateCentroidCrosshairs() ";

    if ((getHostInstrument() != null) && (getHostInstrument().getDAO() != null)
            && (getHostInstrument().getDAO().getChartUI() != null)
            && (getHostInstrument().getDAO().getChartUI().getChartPanel() != null)
            && (getHostInstrument().getDAO().getChartUI().getChartPanel().getChart() != null)
            && (getHostInstrument().getDAO().getObservationMetadata() != null)) {
        final Metadata metadataLongitude;
        final Metadata metadataLatitude;
        DegMinSecInterface dmsCentroidLongitude;
        DegMinSecInterface dmsCentroidLatitude;
        final List<String> errors;

        dmsCentroidLongitude = null;
        dmsCentroidLatitude = null;
        errors = new ArrayList<String>(10);

        // Get the centroid of the fixes from the Observation Metadata
        metadataLongitude = MetadataHelper.getMetadataByKey(
                getHostInstrument().getDAO().getObservationMetadata(),
                MetadataDictionary.KEY_OBSERVATION_CENTROID_LONGITUDE.getKey());
        metadataLatitude = MetadataHelper.getMetadataByKey(
                getHostInstrument().getDAO().getObservationMetadata(),
                MetadataDictionary.KEY_OBSERVATION_CENTROID_LATITUDE.getKey());

        if (metadataLongitude != null) {
            dmsCentroidLongitude = (DegMinSecInterface) DataTypeHelper.parseDataTypeFromValueField(
                    metadataLongitude.getValue(), DataTypeDictionary.SIGNED_LONGITUDE, EMPTY_STRING,
                    EMPTY_STRING, errors);
        }

        if (metadataLatitude != null) {
            dmsCentroidLatitude = (DegMinSecInterface) DataTypeHelper.parseDataTypeFromValueField(
                    metadataLatitude.getValue(), DataTypeDictionary.LATITUDE, EMPTY_STRING, EMPTY_STRING,
                    errors);
        }

        if ((errors.isEmpty()) && (dmsCentroidLongitude != null) && (dmsCentroidLatitude != null)) {
            final XYPlot plot;

            plot = (XYPlot) getHostInstrument().getDAO().getChartUI().getChartPanel().getChart().getPlot();

            if (plot != null) {
                // Remember that the Domain is the X-axis, i.e. Longitude
                plot.setDomainCrosshairValue(dmsCentroidLongitude.toDouble());
                plot.setRangeCrosshairValue(dmsCentroidLatitude.toDouble());
            }
        }

        LOGGER.errors(SOURCE, errors);
    }
}

From source file:ec.util.chart.swing.JTimeSeriesChart.java

private void onCrosshairValueChange(ObsIndex value) {
    if (isElementVisible(Element.CROSSHAIR) && existPredicate.apply(value)) {
        double x = dataset.getXValue(value.getSeries(), value.getObs());
        double y = dataset.getYValue(value.getSeries(), value.getObs());
        int index = plotDispatcher.apply(value.getSeries());
        for (XYPlot subPlot : roSubPlots) {
            subPlot.setDomainCrosshairValue(x);
            subPlot.setDomainCrosshairVisible(crosshairOrientation != CrosshairOrientation.HORIZONTAL);
            if (roSubPlots.indexOf(subPlot) == index && crosshairOrientation != CrosshairOrientation.VERTICAL) {
                subPlot.setRangeCrosshairValue(y);
                subPlot.setRangeCrosshairVisible(true);
            } else {
                subPlot.setRangeCrosshairVisible(false);
            }/*from  ww  w .  java 2s.com*/
        }
    } else {
        for (XYPlot subPlot : roSubPlots) {
            subPlot.setRangeCrosshairVisible(false);
            subPlot.setDomainCrosshairVisible(false);
        }
    }
}