Search in sources :

Example 1 with CombinedDomainXYPlot

use of org.jfree.chart.plot.CombinedDomainXYPlot in project j6dof-flight-sim by chris-ali.

the class SimulationPlot method createPlots.

/**
 * Populates the {@link plotLists} List with {@link XYPlot} objects created from the logsOut ArrayList
 * argument. It first creates {@link XYSeries} objects with data from logsOut, adds those to
 * {@link XYSeriesCollection}, adds those series collections to {@link XYPlot} objects, and finally
 * puts the XYPlot objects into {@link plotList}. The types of {@link XYPlot} objects generated
 * comes from settings in {@link SubPlotBundle}
 *
 * @param logsOut
 * @param bundle
 */
private void createPlots(List<Map<SimOuts, Double>> logsOut, SubPlotBundle bundle) {
    for (SubPlotOptions option : bundle.getSubPlots()) {
        XYSeriesCollection collection = new XYSeriesCollection();
        for (SimOuts simout : option.getyData()) {
            XYSeries series = new XYSeries(simout.toString());
            xySeriesData.put(simout, series);
            collection.addSeries(series);
        }
        domainAxis = new NumberAxis(option.getxAxisName());
        rangeAxes.put(option.getTitle(), new NumberAxis(option.getyAxisName()));
        xyCollections.put(option.getTitle(), collection);
    }
    combinedDomPlot = new CombinedDomainXYPlot(domainAxis);
    updateXYSeriesData(logsOut, bundle);
    for (Map.Entry<String, XYSeriesCollection> entry : xyCollections.entrySet()) {
        logger.debug("Creating a subplot called: " + entry.getKey() + "...");
        XYPlot subPlot = new XYPlot(entry.getValue(), domainAxis, rangeAxes.get(entry.getKey()), new StandardXYItemRenderer());
        plotList.add(subPlot);
    }
}
Also used : XYSeries(org.jfree.data.xy.XYSeries) NumberAxis(org.jfree.chart.axis.NumberAxis) XYPlot(org.jfree.chart.plot.XYPlot) CombinedDomainXYPlot(org.jfree.chart.plot.CombinedDomainXYPlot) StandardXYItemRenderer(org.jfree.chart.renderer.xy.StandardXYItemRenderer) SimOuts(com.chrisali.javaflightsim.simulation.integration.SimOuts) XYSeriesCollection(org.jfree.data.xy.XYSeriesCollection) CombinedDomainXYPlot(org.jfree.chart.plot.CombinedDomainXYPlot) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) SubPlotOptions(com.chrisali.javaflightsim.swing.plotting.PlotConfiguration.SubPlotOptions)

Example 2 with CombinedDomainXYPlot

use of org.jfree.chart.plot.CombinedDomainXYPlot in project tdq-studio-se by Talend.

the class ToolTipChartComposite method getTooltipAtPoint.

/**
 * This method attempts to get a tooltip by converting the screen X,Y into Chart Area X,Y and then looking for a
 * data point in a data set that lies inside a hotspot around that value.
 *
 * @param point The Java 2D point
 * @return A string for the data at the point or null if no data is found.
 */
protected String getTooltipAtPoint(Point point) {
    String result = null;
    Point2D translatedPoint = this.translateScreenToJava2D(point);
    Plot plot = this.getChart().getPlot();
    PlotRenderingInfo info = this.getChartRenderingInfo().getPlotInfo();
    if (plot instanceof CombinedDomainXYPlot) {
        int index = info.getSubplotIndex(translatedPoint);
        if (index < 0) {
            index = 0;
        }
        plot = (Plot) ((CombinedDomainXYPlot) plot).getSubplots().get(index);
        info = this.getChartRenderingInfo().getPlotInfo().getSubplotInfo(index);
    }
    if (plot != null && plot instanceof XYPlot) {
        XYPlot xyPlot = (XYPlot) plot;
        ValueAxis domainAxis = xyPlot.getDomainAxis();
        ValueAxis rangeAxis = xyPlot.getRangeAxis();
        // had to switch to SWT's rectangle here.
        Rectangle screenArea = this.scale(info.getDataArea());
        double hotspotSizeX = hotspontsize * this.getScaleX();
        double hotspotSizeY = hotspontsize * this.getScaleY();
        double x0 = point.getX();
        double y0 = point.getY();
        double x1 = x0 - hotspotSizeX;
        double y1 = y0 + hotspotSizeY;
        double x2 = x0 + hotspotSizeX;
        double y2 = y0 - hotspotSizeY;
        RectangleEdge xEdge = RectangleEdge.BOTTOM;
        RectangleEdge yEdge = RectangleEdge.LEFT;
        // Switch everything for horizontal charts
        if (xyPlot.getOrientation() == PlotOrientation.HORIZONTAL) {
            hotspotSizeX = hotspontsize * this.getScaleY();
            hotspotSizeY = hotspontsize * this.getScaleX();
            x0 = point.getY();
            y0 = point.getX();
            x1 = x0 + hotspotSizeX;
            y1 = y0 - hotspotSizeY;
            x2 = x0 - hotspotSizeX;
            y2 = y0 + hotspotSizeY;
            xEdge = RectangleEdge.LEFT;
            yEdge = RectangleEdge.BOTTOM;
        }
        // OK, here we have to get ourselves back into AWT land...
        Rectangle2D r2d = new Rectangle2D.Double();
        r2d.setRect(screenArea.x, screenArea.y, screenArea.width, screenArea.height);
        double ty0 = rangeAxis.java2DToValue(y0, r2d, yEdge);
        double tx1 = domainAxis.java2DToValue(x1, r2d, xEdge);
        double ty1 = rangeAxis.java2DToValue(y1, r2d, yEdge);
        double tx2 = domainAxis.java2DToValue(x2, r2d, xEdge);
        double ty2 = rangeAxis.java2DToValue(y2, r2d, yEdge);
        int datasetCount = xyPlot.getDatasetCount();
        for (int datasetIndex = 0; datasetIndex < datasetCount; datasetIndex++) {
            XYDataset dataset = xyPlot.getDataset(datasetIndex);
            int seriesCount = dataset.getSeriesCount();
            for (int series = 0; series < seriesCount; series++) {
                int itemCount = dataset.getItemCount(series);
                if (dataset instanceof OHLCDataset) {
                    // This could be optimized to use a binary search for x first
                    for (int item = 0; item < itemCount; item++) {
                        double xValue = dataset.getXValue(series, item);
                        double yValueHi = ((OHLCDataset) dataset).getHighValue(series, item);
                        double yValueLo = ((OHLCDataset) dataset).getLowValue(series, item);
                        // Check hi lo and swap if needed
                        if (yValueHi < yValueLo) {
                            double temp = yValueHi;
                            yValueHi = yValueLo;
                            yValueLo = temp;
                        }
                        // Check if the dataset 'X' value lies between the hotspot (tx1 < xValue < tx2)
                        if (tx1 < xValue && xValue < tx2) {
                            // Check if the cursor 'y' value lies between the high and low (low < ty0 < high)
                            if (yValueLo < ty0 && ty0 < yValueHi) {
                                return hiLoTips.generateToolTip(dataset, series, item);
                            }
                        }
                    }
                } else {
                    // This could be optimized to use a binary search for x first
                    for (int item = 0; item < itemCount; item++) {
                        double xValue = dataset.getXValue(series, item);
                        double yValue = dataset.getYValue(series, item);
                        // Check if the dataset 'X' value lies between the hotspot (tx1< xValue < tx2)
                        if (tx1 < xValue && xValue < tx2) {
                            // Check if the dataset 'Y' value lies between the hotspot (ty1 < yValue < ty2)
                            if (ty1 < yValue && yValue < ty2) {
                                return xyTips.generateToolTip(dataset, series, item);
                            }
                        }
                    }
                }
            }
        }
    }
    return result;
}
Also used : PlotRenderingInfo(org.jfree.chart.plot.PlotRenderingInfo) XYPlot(org.jfree.chart.plot.XYPlot) CombinedDomainXYPlot(org.jfree.chart.plot.CombinedDomainXYPlot) Plot(org.jfree.chart.plot.Plot) Rectangle(org.eclipse.swt.graphics.Rectangle) Rectangle2D(java.awt.geom.Rectangle2D) Point(java.awt.Point) OHLCDataset(org.jfree.data.xy.OHLCDataset) XYPlot(org.jfree.chart.plot.XYPlot) CombinedDomainXYPlot(org.jfree.chart.plot.CombinedDomainXYPlot) Point2D(java.awt.geom.Point2D) ValueAxis(org.jfree.chart.axis.ValueAxis) XYDataset(org.jfree.data.xy.XYDataset) CombinedDomainXYPlot(org.jfree.chart.plot.CombinedDomainXYPlot) RectangleEdge(org.jfree.ui.RectangleEdge)

Example 3 with CombinedDomainXYPlot

use of org.jfree.chart.plot.CombinedDomainXYPlot in project nimbus by nimbus-org.

the class CombinedDomainXYPlotFactoryService method createService.

public void createService() throws Exception {
    tmpPlot = new CombinedDomainXYPlot(null);
    subPlotFactoryServices = new ArrayList();
}
Also used : ArrayList(java.util.ArrayList) CombinedDomainXYPlot(org.jfree.chart.plot.CombinedDomainXYPlot)

Example 4 with CombinedDomainXYPlot

use of org.jfree.chart.plot.CombinedDomainXYPlot in project nimbus by nimbus-org.

the class CombinedDomainXYPlotFactoryService method createPlot.

// PlotFactoryのJavaDoc
public Plot createPlot(PlotCondition[] plotConditions) throws PlotCreateException {
    CombinedDomainXYPlot combinedPlot = (CombinedDomainXYPlot) copyXYPlot();
    if (plotConditions == null || plotConditions.length == 0) {
        return combinedPlot;
    }
    for (int i = 0; i < subPlotFactoryServices.size(); i++) {
        PlotFactory plotFactory = (PlotFactory) subPlotFactoryServices.get(i);
        Plot plot = plotFactory.createPlot(plotConditions);
        if (plot != null && plot instanceof XYPlot) {
            XYPlot xyPlot = (XYPlot) plot;
            combinedPlot.add(xyPlot, xyPlot.getWeight());
        }
    }
    XYPlotConditionImpl xyPlotCondition = mergeXYPlotCondition(plotConditions);
    if (domainAxisServiceNames != null && domainAxisServiceNames.length > 0) {
        for (int i = 0; i < domainAxisServiceNames.length; i++) {
            ValueAxis domainAxis = (ValueAxis) ServiceManagerFactory.getServiceObject(domainAxisServiceNames[i]);
            if (xyPlotCondition != null) {
                // 横軸ラベルフォント
                if (xyPlotCondition.getDefaultDomainAxisLabelFontName() != null || xyPlotCondition.getDefaultDomainAxisLabelFontStyle() != Integer.MIN_VALUE || xyPlotCondition.getDefaultDomainAxisLabelFontSize() != Integer.MIN_VALUE) {
                    domainAxis.setLabelFont(mergeFont(domainAxis.getLabelFont(), xyPlotCondition.getDefaultDomainAxisLabelFontName(), xyPlotCondition.getDefaultDomainAxisLabelFontStyle(), xyPlotCondition.getDefaultDomainAxisLabelFontSize()));
                } else if (xyPlotCondition.getDomainAxisLabelFontName(i) != null || xyPlotCondition.getDomainAxisLabelFontStyle(i) != Integer.MIN_VALUE || xyPlotCondition.getDomainAxisLabelFontSize(i) != Integer.MIN_VALUE) {
                    domainAxis.setLabelFont(mergeFont(domainAxis.getLabelFont(), xyPlotCondition.getDomainAxisLabelFontName(i), xyPlotCondition.getDomainAxisLabelFontStyle(i), xyPlotCondition.getDomainAxisLabelFontSize(i)));
                }
                // 横軸Tickラベルフォント
                if (xyPlotCondition.getDefaultDomainAxisTickLabelFontName() != null || xyPlotCondition.getDefaultDomainAxisTickLabelFontStyle() != Integer.MIN_VALUE || xyPlotCondition.getDefaultDomainAxisTickLabelFontSize() != Integer.MIN_VALUE) {
                    domainAxis.setTickLabelFont(mergeFont(domainAxis.getTickLabelFont(), xyPlotCondition.getDefaultDomainAxisTickLabelFontName(), xyPlotCondition.getDefaultDomainAxisTickLabelFontStyle(), xyPlotCondition.getDefaultDomainAxisTickLabelFontSize()));
                } else if (xyPlotCondition.getDomainAxisTickLabelFontName(i) != null || xyPlotCondition.getDomainAxisTickLabelFontStyle(i) != Integer.MIN_VALUE || xyPlotCondition.getDomainAxisTickLabelFontSize(i) != Integer.MIN_VALUE) {
                    domainAxis.setTickLabelFont(mergeFont(domainAxis.getTickLabelFont(), xyPlotCondition.getDomainAxisTickLabelFontName(i), xyPlotCondition.getDomainAxisTickLabelFontStyle(i), xyPlotCondition.getDomainAxisTickLabelFontSize(i)));
                }
            }
            combinedPlot.setDomainAxis(i, domainAxis);
        }
    }
    if (getTickUnitAdjusters() != null) {
        // 目盛り調節
        TickUnitAdjuster[] adjusters = getTickUnitAdjusters();
        for (int i = 0; i < adjusters.length; i++) {
            adjusters[i].adjust(combinedPlot);
        }
    }
    return combinedPlot;
}
Also used : XYPlot(org.jfree.chart.plot.XYPlot) CombinedDomainXYPlot(org.jfree.chart.plot.CombinedDomainXYPlot) Plot(org.jfree.chart.plot.Plot) XYPlot(org.jfree.chart.plot.XYPlot) CombinedDomainXYPlot(org.jfree.chart.plot.CombinedDomainXYPlot) ValueAxis(org.jfree.chart.axis.ValueAxis) CombinedDomainXYPlot(org.jfree.chart.plot.CombinedDomainXYPlot)

Example 5 with CombinedDomainXYPlot

use of org.jfree.chart.plot.CombinedDomainXYPlot in project nimbus by nimbus-org.

the class CombinedDomainXYPlotFactoryService method copyXYPlot.

protected XYPlot copyXYPlot() {
    CombinedDomainXYPlot combinedPlot = (CombinedDomainXYPlot) super.copyXYPlot();
    // サブプロットの間隔
    combinedPlot.setGap(((CombinedDomainXYPlot) tmpPlot).getGap());
    return combinedPlot;
}
Also used : CombinedDomainXYPlot(org.jfree.chart.plot.CombinedDomainXYPlot)

Aggregations

CombinedDomainXYPlot (org.jfree.chart.plot.CombinedDomainXYPlot)5 XYPlot (org.jfree.chart.plot.XYPlot)3 ValueAxis (org.jfree.chart.axis.ValueAxis)2 Plot (org.jfree.chart.plot.Plot)2 SimOuts (com.chrisali.javaflightsim.simulation.integration.SimOuts)1 SubPlotOptions (com.chrisali.javaflightsim.swing.plotting.PlotConfiguration.SubPlotOptions)1 Point (java.awt.Point)1 Point2D (java.awt.geom.Point2D)1 Rectangle2D (java.awt.geom.Rectangle2D)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Rectangle (org.eclipse.swt.graphics.Rectangle)1 NumberAxis (org.jfree.chart.axis.NumberAxis)1 PlotRenderingInfo (org.jfree.chart.plot.PlotRenderingInfo)1 StandardXYItemRenderer (org.jfree.chart.renderer.xy.StandardXYItemRenderer)1 OHLCDataset (org.jfree.data.xy.OHLCDataset)1 XYDataset (org.jfree.data.xy.XYDataset)1 XYSeries (org.jfree.data.xy.XYSeries)1 XYSeriesCollection (org.jfree.data.xy.XYSeriesCollection)1