Example usage for org.jfree.data Range Range

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

Introduction

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

Prototype

public Range(double lower, double upper) 

Source Link

Document

Creates a new range.

Usage

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

/**
 * Zooms in on the current range./*from w w w . jav  a2  s .c o  m*/
 *
 * @param lowerPercent  the new lower bound.
 * @param upperPercent  the new upper bound.
 */
public void logZoomRange(double lowerPercent, double upperPercent) {
    double startLog = switchedLog10(getRange().getLowerBound());
    double lengthLog = switchedLog10(getRange().getUpperBound()) - startLog;
    Range adjusted;

    if (isInverted()) {
        adjusted = new Range(switchedPow10(startLog + (lengthLog * (1 - upperPercent))),
                switchedPow10(startLog + (lengthLog * (1 - lowerPercent))));
    } else {
        adjusted = new Range(switchedPow10(startLog + (lengthLog * lowerPercent)),
                switchedPow10(startLog + (lengthLog * upperPercent)));
    }

    setRange(adjusted);
}

From source file:org.pentaho.platform.uifoundation.chart.JFreeChartEngine.java

private static void updatePlot(final Plot plot, final ChartDefinition chartDefinition) {
    plot.setBackgroundPaint(chartDefinition.getPlotBackgroundPaint());
    plot.setBackgroundImage(chartDefinition.getPlotBackgroundImage());

    plot.setNoDataMessage(chartDefinition.getNoDataMessage());

    // create a custom palette if it was defined
    if (chartDefinition.getPaintSequence() != null) {
        DefaultDrawingSupplier drawingSupplier = new DefaultDrawingSupplier(chartDefinition.getPaintSequence(),
                DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE,
                DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE,
                DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE,
                DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE);
        plot.setDrawingSupplier(drawingSupplier);
    }/*from w w  w. ja v  a  2  s .  co  m*/
    plot.setOutlineStroke(null); // TODO define outline stroke

    if (plot instanceof CategoryPlot) {
        CategoryPlot categoryPlot = (CategoryPlot) plot;
        CategoryDatasetChartDefinition categoryDatasetChartDefintion = (CategoryDatasetChartDefinition) chartDefinition;
        categoryPlot.setOrientation(categoryDatasetChartDefintion.getOrientation());
        CategoryAxis domainAxis = categoryPlot.getDomainAxis();
        if (domainAxis != null) {
            domainAxis.setLabel(categoryDatasetChartDefintion.getDomainTitle());
            domainAxis.setLabelFont(categoryDatasetChartDefintion.getDomainTitleFont());
            if (categoryDatasetChartDefintion.getDomainTickFont() != null) {
                domainAxis.setTickLabelFont(categoryDatasetChartDefintion.getDomainTickFont());
            }
            domainAxis.setCategoryLabelPositions(categoryDatasetChartDefintion.getCategoryLabelPositions());
        }
        NumberAxis numberAxis = (NumberAxis) categoryPlot.getRangeAxis();
        if (numberAxis != null) {
            numberAxis.setLabel(categoryDatasetChartDefintion.getRangeTitle());
            numberAxis.setLabelFont(categoryDatasetChartDefintion.getRangeTitleFont());
            if (categoryDatasetChartDefintion.getRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
                numberAxis.setLowerBound(categoryDatasetChartDefintion.getRangeMinimum());
            }
            if (categoryDatasetChartDefintion.getRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
                numberAxis.setUpperBound(categoryDatasetChartDefintion.getRangeMaximum());
            }

            if (categoryDatasetChartDefintion.getRangeTickFormat() != null) {
                numberAxis.setNumberFormatOverride(categoryDatasetChartDefintion.getRangeTickFormat());
            }
            if (categoryDatasetChartDefintion.getRangeTickFont() != null) {
                numberAxis.setTickLabelFont(categoryDatasetChartDefintion.getRangeTickFont());
            }
            if (categoryDatasetChartDefintion.getRangeTickUnits() != null) {
                numberAxis.setTickUnit(new NumberTickUnit(categoryDatasetChartDefintion.getRangeTickUnits()));
            }
        }

    }
    if (plot instanceof PiePlot) {
        PiePlot pie = (PiePlot) plot;
        PieDatasetChartDefinition pieDefinition = (PieDatasetChartDefinition) chartDefinition;
        pie.setInteriorGap(pieDefinition.getInteriorGap());
        pie.setStartAngle(pieDefinition.getStartAngle());
        pie.setLabelFont(pieDefinition.getLabelFont());
        if (pieDefinition.getLabelPaint() != null) {
            pie.setLabelPaint(pieDefinition.getLabelPaint());
        }
        pie.setLabelBackgroundPaint(pieDefinition.getLabelBackgroundPaint());
        if (pieDefinition.isLegendIncluded()) {
            StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator("{0}"); //$NON-NLS-1$
            pie.setLegendLabelGenerator(labelGen);
        }
        if (pieDefinition.getExplodedSlices() != null) {
            for (Iterator iter = pieDefinition.getExplodedSlices().iterator(); iter.hasNext();) {
                pie.setExplodePercent((Comparable) iter.next(), .30);
            }
        }
        pie.setLabelGap(pieDefinition.getLabelGap());
        if (!pieDefinition.isDisplayLabels()) {
            pie.setLabelGenerator(null);
        } else {
            if (pieDefinition.isLegendIncluded()) {
                StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator("{1} ({2})"); //$NON-NLS-1$
                pie.setLabelGenerator(labelGen);
            } else {
                StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator(
                        "{0} = {1} ({2})"); //$NON-NLS-1$
                pie.setLabelGenerator(labelGen);
            }
        }
    }
    if (plot instanceof MultiplePiePlot) {
        MultiplePiePlot pies = (MultiplePiePlot) plot;
        CategoryDatasetChartDefinition categoryDatasetChartDefintion = (CategoryDatasetChartDefinition) chartDefinition;
        pies.setDataset(categoryDatasetChartDefintion);
    }
    if (plot instanceof MeterPlot) {
        MeterPlot meter = (MeterPlot) plot;
        DialWidgetDefinition widget = (DialWidgetDefinition) chartDefinition;
        List intervals = widget.getIntervals();
        Iterator intervalIterator = intervals.iterator();
        while (intervalIterator.hasNext()) {
            MeterInterval interval = (MeterInterval) intervalIterator.next();
            meter.addInterval(interval);
        }

        meter.setNeedlePaint(widget.getNeedlePaint());
        meter.setDialShape(widget.getDialShape());
        meter.setDialBackgroundPaint(widget.getPlotBackgroundPaint());
        meter.setRange(new Range(widget.getMinimum(), widget.getMaximum()));

    }
    if (plot instanceof XYPlot) {
        XYPlot xyPlot = (XYPlot) plot;
        if (chartDefinition instanceof XYSeriesCollectionChartDefinition) {
            XYSeriesCollectionChartDefinition xySeriesCollectionChartDefintion = (XYSeriesCollectionChartDefinition) chartDefinition;
            xyPlot.setOrientation(xySeriesCollectionChartDefintion.getOrientation());
            ValueAxis domainAxis = xyPlot.getDomainAxis();
            if (domainAxis != null) {
                domainAxis.setLabel(xySeriesCollectionChartDefintion.getDomainTitle());
                domainAxis.setLabelFont(xySeriesCollectionChartDefintion.getDomainTitleFont());
                domainAxis.setVerticalTickLabels(xySeriesCollectionChartDefintion.isDomainVerticalTickLabels());
                if (xySeriesCollectionChartDefintion.getDomainTickFormat() != null) {
                    ((NumberAxis) domainAxis)
                            .setNumberFormatOverride(xySeriesCollectionChartDefintion.getDomainTickFormat());
                }
                if (xySeriesCollectionChartDefintion.getDomainTickFont() != null) {
                    domainAxis.setTickLabelFont(xySeriesCollectionChartDefintion.getDomainTickFont());
                }
                if (xySeriesCollectionChartDefintion.getDomainMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
                    domainAxis.setLowerBound(xySeriesCollectionChartDefintion.getDomainMinimum());
                }
                if (xySeriesCollectionChartDefintion.getDomainMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
                    domainAxis.setUpperBound(xySeriesCollectionChartDefintion.getDomainMaximum());
                }
            }

            ValueAxis rangeAxis = xyPlot.getRangeAxis();
            if (rangeAxis != null) {
                rangeAxis.setLabel(xySeriesCollectionChartDefintion.getRangeTitle());
                rangeAxis.setLabelFont(xySeriesCollectionChartDefintion.getRangeTitleFont());
                if (xySeriesCollectionChartDefintion.getRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
                    rangeAxis.setLowerBound(xySeriesCollectionChartDefintion.getRangeMinimum());
                }
                if (xySeriesCollectionChartDefintion.getRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
                    rangeAxis.setUpperBound(xySeriesCollectionChartDefintion.getRangeMaximum());
                }
                if (xySeriesCollectionChartDefintion.getRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
                    rangeAxis.setLowerBound(xySeriesCollectionChartDefintion.getRangeMinimum());
                }
                if (xySeriesCollectionChartDefintion.getRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
                    rangeAxis.setUpperBound(xySeriesCollectionChartDefintion.getRangeMaximum());
                }
                if (xySeriesCollectionChartDefintion.getRangeTickFormat() != null) {
                    ((NumberAxis) rangeAxis)
                            .setNumberFormatOverride(xySeriesCollectionChartDefintion.getRangeTickFormat());
                }
                if (xySeriesCollectionChartDefintion.getRangeTickFont() != null) {
                    rangeAxis.setTickLabelFont(xySeriesCollectionChartDefintion.getRangeTickFont());
                }
            }

        } else if (chartDefinition instanceof TimeSeriesCollectionChartDefinition) {
            TimeSeriesCollectionChartDefinition timeSeriesCollectionChartDefintion = (TimeSeriesCollectionChartDefinition) chartDefinition;
            xyPlot.setOrientation(timeSeriesCollectionChartDefintion.getOrientation());
            ValueAxis domainAxis = xyPlot.getDomainAxis();
            if (domainAxis != null) {
                domainAxis.setLabel(timeSeriesCollectionChartDefintion.getDomainTitle());
                domainAxis.setLabelFont(timeSeriesCollectionChartDefintion.getDomainTitleFont());
                domainAxis
                        .setVerticalTickLabels(timeSeriesCollectionChartDefintion.isDomainVerticalTickLabels());
                if (domainAxis instanceof DateAxis) {
                    DateAxis da = (DateAxis) domainAxis;
                    if (timeSeriesCollectionChartDefintion.getDateMinimum() != null) {
                        da.setMinimumDate(timeSeriesCollectionChartDefintion.getDateMinimum());
                    }
                    if (timeSeriesCollectionChartDefintion.getDateMaximum() != null) {
                        da.setMaximumDate(timeSeriesCollectionChartDefintion.getDateMaximum());
                    }
                }
            }

            ValueAxis rangeAxis = xyPlot.getRangeAxis();
            if (rangeAxis != null) {
                rangeAxis.setLabel(timeSeriesCollectionChartDefintion.getRangeTitle());
                rangeAxis.setLabelFont(timeSeriesCollectionChartDefintion.getRangeTitleFont());
                if (timeSeriesCollectionChartDefintion.getRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
                    rangeAxis.setLowerBound(timeSeriesCollectionChartDefintion.getRangeMinimum());
                }
                if (timeSeriesCollectionChartDefintion.getRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
                    rangeAxis.setUpperBound(timeSeriesCollectionChartDefintion.getRangeMaximum());
                }
            }
        } else if (chartDefinition instanceof XYZSeriesCollectionChartDefinition) {
            XYZSeriesCollectionChartDefinition xyzSeriesCollectionChartDefintion = (XYZSeriesCollectionChartDefinition) chartDefinition;
            xyPlot.setOrientation(xyzSeriesCollectionChartDefintion.getOrientation());
            ValueAxis domainAxis = xyPlot.getDomainAxis();
            if (domainAxis != null) {
                domainAxis.setLabel(xyzSeriesCollectionChartDefintion.getDomainTitle());
                domainAxis.setLabelFont(xyzSeriesCollectionChartDefintion.getDomainTitleFont());
                domainAxis
                        .setVerticalTickLabels(xyzSeriesCollectionChartDefintion.isDomainVerticalTickLabels());
                if (xyzSeriesCollectionChartDefintion.getDomainMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
                    domainAxis.setLowerBound(xyzSeriesCollectionChartDefintion.getDomainMinimum());
                }
                if (xyzSeriesCollectionChartDefintion.getDomainMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
                    domainAxis.setUpperBound(xyzSeriesCollectionChartDefintion.getDomainMaximum());
                }
                if (xyzSeriesCollectionChartDefintion.getDomainTickFormat() != null) {
                    ((NumberAxis) domainAxis)
                            .setNumberFormatOverride(xyzSeriesCollectionChartDefintion.getDomainTickFormat());
                }
                if (xyzSeriesCollectionChartDefintion.getDomainTickFont() != null) {
                    domainAxis.setTickLabelFont(xyzSeriesCollectionChartDefintion.getDomainTickFont());
                }
            }

            ValueAxis rangeAxis = xyPlot.getRangeAxis();
            if (rangeAxis != null) {
                rangeAxis.setLabel(xyzSeriesCollectionChartDefintion.getRangeTitle());
                rangeAxis.setLabelFont(xyzSeriesCollectionChartDefintion.getRangeTitleFont());
                rangeAxis.setLowerBound(xyzSeriesCollectionChartDefintion.getRangeMinimum());
                if (xyzSeriesCollectionChartDefintion.getRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
                    rangeAxis.setLowerBound(xyzSeriesCollectionChartDefintion.getRangeMinimum());
                }
                if (xyzSeriesCollectionChartDefintion.getRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
                    rangeAxis.setUpperBound(xyzSeriesCollectionChartDefintion.getRangeMaximum());
                }
                if (xyzSeriesCollectionChartDefintion.getRangeTickFormat() != null) {
                    ((NumberAxis) rangeAxis)
                            .setNumberFormatOverride(xyzSeriesCollectionChartDefintion.getRangeTickFormat());
                }
                if (xyzSeriesCollectionChartDefintion.getRangeTickFont() != null) {
                    rangeAxis.setTickLabelFont(xyzSeriesCollectionChartDefintion.getRangeTickFont());
                }
            }

        }
    }
}

From source file:com.att.aro.diagnostics.GraphPanel.java

/**
 * Resets the chart labels, and the chart and axis information of the
 * GraphPanel when the specified trace data is loaded. The current instance
 * of the GraphPanel is preserved, along with the current zoom state. The
 * scroll bar is moved to position 0.// w w  w.  jav a2 s . c om
 * 
 * @param analysis
 *            - An Analysis object containing the new trace analysis data.
 */
public synchronized void resetChart(TraceData.Analysis analysis) {

    this.traceData = analysis != null ? analysis.getTraceData() : null;
    getSaveGraphButton().setEnabled(analysis != null);
    // Setting the initial value on the time axis to -0.01 as the first
    // packet time stamp in pcap analysis is always zero and hence the tool
    // tip does not get displayed.
    if (analysis != null && analysis.getFilter().getTimeRange() != null) {
        this.axis.setRange(new Range(-0.01,
                analysis != null ? analysis.getFilter().getTimeRange().getEndTime() : DEFAULT_TIMELINE));
    } else {
        if (this.endTime > 0) { //greg story selected rows from UI
            if (analysis != null) {
                this.axis.setRange(new Range(this.startTime, this.endTime));
            } else {
                this.axis.setRange(new Range(-0.01, DEFAULT_TIMELINE));
            }
            this.startTime = 0.0; //Reset times
            this.endTime = 0.0;
        } else {
            this.axis.setRange(new Range(-0.01,
                    analysis != null ? analysis.getTraceData().getTraceDuration() : DEFAULT_TIMELINE));
        }
    }
    setGraphView(0);
    for (Map.Entry<ChartPlotOptions, GraphPanelPlotLabels> entry : subplotMap.entrySet()) {
        switch (entry.getKey()) {
        case ALARM:
            populateAlarmPlot(entry.getValue().getPlot(), analysis);
            break;
        case BATTERY:
            populateBatteryPlot(entry.getValue().getPlot(), analysis);
            break;
        case WAKELOCK:
            populateWakelockStatePlot(entry.getValue().getPlot(), analysis);
            break;
        case BLUETOOTH:
            populateBluetoothPlot(entry.getValue().getPlot(), analysis);
            break;
        case BURSTS:
            populateBurstPlot(entry.getValue().getPlot(), analysis);
            break;
        case CAMERA:
            populateCameraPlot(entry.getValue().getPlot(), analysis);
            break;
        case GPS:
            populateGpsPlot(entry.getValue().getPlot(), analysis);
            break;
        case NETWORK_TYPE:
            populateNetworkTyesPlot(entry.getValue().getPlot(), analysis);
            break;
        case RADIO:
            populateRadioPlot(entry.getValue().getPlot(), analysis);
            break;
        case RRC:
            populateRrcPlot(entry.getValue().getPlot(), analysis);
            break;
        case SCREEN:
            populateScreenStatePlot(entry.getValue().getPlot(), analysis);
            break;
        case THROUGHPUT:
            populateThroughputPlot(entry.getValue().getPlot(), analysis);
            break;
        case USER_INPUT:
            populateUserEventPlot(entry.getValue().getPlot(), analysis);
            break;
        case WIFI:
            populateWifiPlot(entry.getValue().getPlot(), analysis);
            break;
        case CPU:
            populateCpuPlot(entry.getValue().getPlot(), analysis);
            break;
        default:
            break;
        }
    }
    this.pp.populatePacketPlots(analysis);
    this.getZoomInButton().setEnabled(analysis != null);
    this.getZoomOutButton().setEnabled(analysis != null);
    this.getSaveGraphButton().setEnabled(analysis != null);
    this.getRefreshButton().setEnabled(false); //Greg Story
}

From source file:org.jfree.data.general.DatasetUtils.java

/**
 * Iterates over the items in an {@link XYDataset} to find
 * the range of x-values./*from   w w w  .ja va2 s .  c om*/
 *
 * @param dataset  the dataset ({@code null} not permitted).
 * @param includeInterval  a flag that determines, for an
 *          {@link IntervalXYDataset}, whether the x-interval or just the
 *          x-value is used to determine the overall range.
 *
 * @return The range (possibly {@code null}).
 */
public static Range iterateDomainBounds(XYDataset dataset, boolean includeInterval) {
    Args.nullNotPermitted(dataset, "dataset");
    double minimum = Double.POSITIVE_INFINITY;
    double maximum = Double.NEGATIVE_INFINITY;
    int seriesCount = dataset.getSeriesCount();
    double lvalue, uvalue;
    if (includeInterval && dataset instanceof IntervalXYDataset) {
        IntervalXYDataset intervalXYData = (IntervalXYDataset) dataset;
        for (int series = 0; series < seriesCount; series++) {
            int itemCount = dataset.getItemCount(series);
            for (int item = 0; item < itemCount; item++) {
                double value = intervalXYData.getXValue(series, item);
                lvalue = intervalXYData.getStartXValue(series, item);
                uvalue = intervalXYData.getEndXValue(series, item);
                if (!Double.isNaN(value)) {
                    minimum = Math.min(minimum, value);
                    maximum = Math.max(maximum, value);
                }
                if (!Double.isNaN(lvalue)) {
                    minimum = Math.min(minimum, lvalue);
                    maximum = Math.max(maximum, lvalue);
                }
                if (!Double.isNaN(uvalue)) {
                    minimum = Math.min(minimum, uvalue);
                    maximum = Math.max(maximum, uvalue);
                }
            }
        }
    } else {
        for (int series = 0; series < seriesCount; series++) {
            int itemCount = dataset.getItemCount(series);
            for (int item = 0; item < itemCount; item++) {
                lvalue = dataset.getXValue(series, item);
                uvalue = lvalue;
                if (!Double.isNaN(lvalue)) {
                    minimum = Math.min(minimum, lvalue);
                    maximum = Math.max(maximum, uvalue);
                }
            }
        }
    }
    if (minimum > maximum) {
        return null;
    } else {
        return new Range(minimum, maximum);
    }
}

From source file:org.jfree.data.general.DatasetUtilities.java

/**
 * Iterates over the items in an {@link XYDataset} to find
 * the range of x-values.//  w w  w  .  j  a  v  a2  s .c  o  m
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param includeInterval  a flag that determines, for an
 *          {@link IntervalXYDataset}, whether the x-interval or just the
 *          x-value is used to determine the overall range.
 *
 * @return The range (possibly <code>null</code>).
 */
public static Range iterateDomainBounds(XYDataset dataset, boolean includeInterval) {
    ParamChecks.nullNotPermitted(dataset, "dataset");
    double minimum = Double.POSITIVE_INFINITY;
    double maximum = Double.NEGATIVE_INFINITY;
    int seriesCount = dataset.getSeriesCount();
    double lvalue, uvalue;
    if (includeInterval && dataset instanceof IntervalXYDataset) {
        IntervalXYDataset intervalXYData = (IntervalXYDataset) dataset;
        for (int series = 0; series < seriesCount; series++) {
            int itemCount = dataset.getItemCount(series);
            for (int item = 0; item < itemCount; item++) {
                double value = intervalXYData.getXValue(series, item);
                lvalue = intervalXYData.getStartXValue(series, item);
                uvalue = intervalXYData.getEndXValue(series, item);
                if (!Double.isNaN(value)) {
                    minimum = Math.min(minimum, value);
                    maximum = Math.max(maximum, value);
                }
                if (!Double.isNaN(lvalue)) {
                    minimum = Math.min(minimum, lvalue);
                    maximum = Math.max(maximum, lvalue);
                }
                if (!Double.isNaN(uvalue)) {
                    minimum = Math.min(minimum, uvalue);
                    maximum = Math.max(maximum, uvalue);
                }
            }
        }
    } else {
        for (int series = 0; series < seriesCount; series++) {
            int itemCount = dataset.getItemCount(series);
            for (int item = 0; item < itemCount; item++) {
                lvalue = dataset.getXValue(series, item);
                uvalue = lvalue;
                if (!Double.isNaN(lvalue)) {
                    minimum = Math.min(minimum, lvalue);
                    maximum = Math.max(maximum, uvalue);
                }
            }
        }
    }
    if (minimum > maximum) {
        return null;
    } else {
        return new Range(minimum, maximum);
    }
}

From source file:apidemo.PanScrollZoomDemo.java

/**
 * Decreases the range on the vertical axis, centered about a Java2D y coordinate.
 * <P>/*from  ww  w . j  a v  a  2 s.  c  om*/
 * The range on the y axis is multiplied by zoomFactor
 * 
 * @param y  the y coordinate in Java2D space.
 * @param zoomFactor  the zoomFactor < 1 == zoom in; else out.
 */
private void zoomVertical(final double y, final double zoomFactor) {

    final JFreeChart chart = this.chartPanel.getChart();
    final ChartRenderingInfo info = this.chartPanel.getChartRenderingInfo();

    // 1. (left) Y-Axis

    if (chart.getPlot() instanceof XYPlot) {
        final XYPlot vvp = (XYPlot) chart.getPlot();
        final ValueAxis primYAxis = vvp.getRangeAxis();
        if (primYAxis != null) {
            final double anchorValue = primYAxis.java2DToValue((float) y, info.getPlotInfo().getDataArea(),
                    vvp.getRangeAxisEdge());
            if (zoomFactor < 1.0) {
                // zoom in
                primYAxis.resizeRange(zoomFactor, anchorValue);

            } else if (zoomFactor > 1.0) {
                // zoom out
                final Range range = new Range(this.primYMinMax[0], this.primYMinMax[1]);
                adjustRange(primYAxis, range, zoomFactor, anchorValue);
            }
        }

        // 2. (right) Y-Axis

        if (chart.getPlot() instanceof XYPlot) {
            final XYPlot xyp = (XYPlot) chart.getPlot();
            final ValueAxis secYAxis = xyp.getRangeAxis(1);
            if (secYAxis != null) {
                final double anchorValue = secYAxis.java2DToValue((float) y, info.getPlotInfo().getDataArea(),
                        xyp.getRangeAxisEdge(1));
                if (zoomFactor < 1.0) {
                    // zoom in
                    secYAxis.resizeRange(zoomFactor, anchorValue);

                } else if (zoomFactor > 1.0) {
                    // zoom out
                    final Range range = new Range(this.secondYMinMax[0], this.secondYMinMax[1]);
                    adjustRange(secYAxis, range, zoomFactor, anchorValue);
                }
            }
        }
    }
}

From source file:org.eurocarbdb.application.glycoworkbench.plugin.PeakListChartPanel.java

public void mouseDragged(MouseEvent e) {
    if (mouse_start_point != null && theDocument.size() > 0) {
        if (is_moving) {
            // moving
            double mz_delta = screenToDataX(mouse_start_point.getX() - e.getPoint().getX());
            if (mz_delta > 0.) {
                double old_upper_bound = thePlot.getDomainAxis().getUpperBound();
                double old_lower_bound = thePlot.getDomainAxis().getLowerBound();
                double new_upper_bound = Math.min(old_upper_bound + mz_delta, theDocument.getMaxMZ());
                double new_lower_bound = old_lower_bound + new_upper_bound - old_upper_bound;

                thePlot.getDomainAxis().setRange(new Range(new_lower_bound, new_upper_bound));
            } else {
                double old_upper_bound = thePlot.getDomainAxis().getUpperBound();
                double old_lower_bound = thePlot.getDomainAxis().getLowerBound();
                double new_lower_bound = Math.max(old_lower_bound + mz_delta, theDocument.getMinMZ());
                double new_upper_bound = old_upper_bound + new_lower_bound - old_lower_bound;

                thePlot.getDomainAxis().setRange(new Range(new_lower_bound, new_upper_bound));
            }//from   w  w w. ja v  a  2 s . c  om

            mouse_start_point = e.getPoint();
        } else {
            // zooming                
            Graphics2D g2 = (Graphics2D) theChartPanel.getGraphics();
            g2.setXORMode(java.awt.Color.gray);

            // delete old rectangle
            if (zoom_rectangle != null)
                g2.draw(zoom_rectangle);

            // create new rectangle
            double start_x = Math.min(e.getX(), mouse_start_point.getX());
            double end_x = Math.max(e.getX(), mouse_start_point.getX());

            Rectangle2D data_area = theChartPanel.getScreenDataArea((int) start_x,
                    (int) mouse_start_point.getY());
            double xmax = Math.min(end_x, data_area.getMaxX());
            zoom_rectangle = new Rectangle2D.Double(start_x, data_area.getMinY(), xmax - start_x,
                    data_area.getHeight());

            // draw new rectangle
            g2.draw(zoom_rectangle);
            g2.dispose();
        }
    }
}

From source file:apidemo.PanScrollZoomDemo.java

/**
 * used for zooming//from w ww .  j  a  v  a 2 s.  com
 * 
 * @param axis  the axis.
 * @param range  the range.
 * @param zoomFactor  the zoom factor.
 * @param anchorValue  the anchor value.
 */
private void adjustRange(final ValueAxis axis, final Range range, final double zoomFactor,
        final double anchorValue) {

    if (axis == null || range == null) {
        return;
    }

    final double rangeMinVal = range.getLowerBound() - range.getLength() * axis.getLowerMargin();
    final double rangeMaxVal = range.getUpperBound() + range.getLength() * axis.getUpperMargin();
    final double halfLength = axis.getRange().getLength() * zoomFactor / 2;
    double zoomedMinVal = anchorValue - halfLength;
    double zoomedMaxVal = anchorValue + halfLength;
    double adjMinVal = zoomedMinVal;
    if (zoomedMinVal < rangeMinVal) {
        adjMinVal = rangeMinVal;
        zoomedMaxVal += rangeMinVal - zoomedMinVal;
    }
    double adjMaxVal = zoomedMaxVal;
    if (zoomedMaxVal > rangeMaxVal) {
        adjMaxVal = rangeMaxVal;
        zoomedMinVal -= zoomedMaxVal - rangeMaxVal;
        adjMinVal = Math.max(zoomedMinVal, rangeMinVal);
    }

    final Range adjusted = new Range(adjMinVal, adjMaxVal);
    axis.setRange(adjusted);
}

From source file:org.oscarehr.web.reports.ocan.NeedRatingOverTimeReportGenerator.java

private JFreeChart generateNeedsOverTimeChart() {

    CategoryDataset dataset = this.createDataset();

    JFreeChart chart = ChartFactory.createStackedBarChart("Needs over Time (Consumer and Staff)", // chart title
            "Assessments", // x axis label
            "# of Domain", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );// www .j  a v a 2 s .  co  m

    chart.setBackgroundPaint(Color.LIGHT_GRAY);

    GroupedStackedBarRenderer renderer = new GroupedStackedBarRenderer();
    KeyToGroupMap map = new KeyToGroupMap("G1");
    map.mapKeyToGroup("Consumer (Unknown)", "G1");
    map.mapKeyToGroup("Consumer (No Needs)", "G1");
    map.mapKeyToGroup("Consumer (Met Needs)", "G1");
    map.mapKeyToGroup("Consumer (Unmet Needs)", "G1");

    map.mapKeyToGroup("Staff (Unknown)", "G2");
    map.mapKeyToGroup("Staff (No Needs)", "G2");
    map.mapKeyToGroup("Staff (Met Needs)", "G2");
    map.mapKeyToGroup("Staff (Unmet Needs)", "G2");

    renderer.setSeriesToGroupMap(map);
    renderer.setItemMargin(0.1);
    //renderer.setItemLabelsVisible(true);
    renderer.setMaximumBarWidth(15);

    Paint p1 = Color.GREEN;
    renderer.setSeriesPaint(0, p1);
    renderer.setSeriesPaint(4, p1);
    renderer.setSeriesPaint(7, p1);

    Paint p2 = Color.BLUE;
    renderer.setSeriesPaint(1, p2);
    renderer.setSeriesPaint(5, p2);
    renderer.setSeriesPaint(8, p2);

    Paint p3 = new Color(255, 255, 153);
    renderer.setSeriesPaint(2, p3);
    renderer.setSeriesPaint(6, p3);
    renderer.setSeriesPaint(9, p3);

    Paint p4 = Color.ORANGE;
    renderer.setSeriesPaint(3, p4);
    renderer.setSeriesPaint(7, p4);
    renderer.setSeriesPaint(10, p4);

    SubCategoryAxis domainAxis = new SubCategoryAxis("Assessments");
    domainAxis.setCategoryMargin(0.05);
    domainAxis.addSubCategory("Consumer");
    domainAxis.addSubCategory("Staff");
    domainAxis.setMinorTickMarkInsideLength(10);
    domainAxis.setMinorTickMarkInsideLength(10);
    domainAxis.setMinorTickMarksVisible(true);

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setDomainAxis(domainAxis);
    plot.setRenderer(renderer);

    LegendItemCollection result = new LegendItemCollection();
    LegendItem item1 = new LegendItem("Unknown", Color.GREEN);
    LegendItem item2 = new LegendItem("No Needs", Color.BLUE);
    LegendItem item3 = new LegendItem("Met Needs", new Color(255, 255, 153));
    LegendItem item4 = new LegendItem("Unmet Needs", Color.ORANGE);

    result.add(item1);
    result.add(item2);
    result.add(item3);
    result.add(item4);

    plot.setFixedLegendItems(result);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.black);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setRange(new Range(0, 24), true, false);
    rangeAxis.setTickUnit(new NumberTickUnit(4));

    plot.getDomainAxis().setCategoryMargin(0.35);

    renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    renderer.setBaseItemLabelsVisible(true);
    renderer.setBasePositiveItemLabelPosition(
            new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.BASELINE_LEFT));

    return chart;
}

From source file:org.eurocarbdb.application.glycoworkbench.plugin.PeakListChartPanel.java

public void mouseReleased(MouseEvent e) {
    if (MouseUtils.isPopupTrigger(e)) {
        // clear all
        if (zoom_rectangle != null) {
            Graphics2D g2 = (Graphics2D) getGraphics();
            g2.setXORMode(java.awt.Color.gray);
            g2.draw(zoom_rectangle);//  w w w .jav a  2 s.  c  om
            g2.dispose();
        }
        mouse_start_point = null;
        zoom_rectangle = null;

        // open popup
        current_peak = findPeakAt(e.getPoint());
        enforceSelection(current_peak);
        createPopupMenu(current_peak != null).show(theChartPanel, e.getX(), e.getY());
    } else {
        if (zoom_rectangle != null && mouse_start_point != null) {
            if (Math.abs(e.getX() - mouse_start_point.getX()) > 10) {
                //if( e.getX() < mouse_start_point.getX() ) {
                // unzoom all
                //    onZoomNone();
                //}
                //else {        

                // zoom area           
                double start_x = Math.min(e.getX(), mouse_start_point.getX());
                double end_x = Math.max(e.getX(), mouse_start_point.getX());

                Rectangle2D data_area = theChartPanel.getScreenDataArea((int) start_x,
                        (int) mouse_start_point.getY());
                double new_lower_bound = screenToDataCoordX(start_x);
                double new_upper_bound = screenToDataCoordX(Math.min(end_x, data_area.getMaxX()));
                thePlot.getDomainAxis().setRange(new Range(new_lower_bound, new_upper_bound));
            } else {
                // clear rectangle
                Graphics2D g2 = (Graphics2D) getGraphics();
                g2.setXORMode(java.awt.Color.gray);
                g2.draw(zoom_rectangle);
                g2.dispose();
            }
        }

        // restore zooming
        if (!was_moving && is_moving)
            onActivateZooming();

        zoom_rectangle = null;
        mouse_start_point = null;
    }
}