List of usage examples for java.awt.geom Point2D getX
public abstract double getX();
From source file:org.gwaspi.gui.reports.ManhattanPlotZoom.java
public void initChart(boolean usePhysicalPosition) { //<editor-fold defaultstate="expanded" desc="PLOT DEFAULTS"> this.threshold = Config.getSingleton().getDouble(GenericReportGenerator.PLOT_MANHATTAN_THRESHOLD_CONFIG, GenericReportGenerator.PLOT_MANHATTAN_THRESHOLD_DEFAULT); this.manhattan_back = Config.getSingleton().getColor( GenericReportGenerator.PLOT_MANHATTAN_BACKGROUND_CONFIG, GenericReportGenerator.PLOT_MANHATTAN_BACKGROUND_DEFAULT); this.manhattan_dot = Config.getSingleton().getColor(GenericReportGenerator.PLOT_MANHATTAN_MAIN_CONFIG, GenericReportGenerator.PLOT_MANHATTAN_MAIN_DEFAULT); //</editor-fold> final MarkerKey toUseMarkerKey; final long toUseRequestedPosWindow; if (usePhysicalPosition) { toUseMarkerKey = null;//from w ww .j av a 2s. com toUseRequestedPosWindow = requestedPosWindow; } else { toUseMarkerKey = origMarkerKey; toUseRequestedPosWindow = requestedSetSize; // XXX should this be requestedPosWindow instead? } initXYDataset = GenericReportGenerator.getManhattanZoomByChrAndPos(this, testOpKey, origChr, toUseMarkerKey, startPhysPos, toUseRequestedPosWindow); zoomChart = createChart(initXYDataset, currentChr); zoomPanel = new ChartPanel(zoomChart); zoomPanel.setInitialDelay(10); zoomPanel.setDismissDelay(5000); zoomPanel.addChartMouseListener(new ChartMouseListener() { @Override public void chartMouseClicked(ChartMouseEvent event) { int mouseX = event.getTrigger().getX(); int mouseY = event.getTrigger().getY(); final Point2D point = zoomPanel.translateScreenToJava2D(new Point(mouseX, mouseY)); XYPlot plot = (XYPlot) zoomChart.getPlot(); ChartRenderingInfo info = zoomPanel.getChartRenderingInfo(); Rectangle2D dataArea = info.getPlotInfo().getDataArea(); ValueAxis domainAxis = plot.getDomainAxis(); RectangleEdge domainAxisEdge = plot.getDomainAxisEdge(); long chartX = (long) domainAxis.java2DToValue(point.getX(), dataArea, domainAxisEdge); // ValueAxis rangeAxis = plot.getRangeAxis(); // RectangleEdge rangeAxisEdge = plot.getRangeAxisEdge(); // double chartY = rangeAxis.java2DToValue(p.getY(), dataArea, // rangeAxisEdge); try { if (LinksExternalResouces.checkIfRsNecessary(cmb_SearchDB.getSelectedIndex())) { // THE SELECTED EXTERNAL RESOURCE NEEDS RSID INFO String tooltip = zoomPanel.getToolTipText(event.getTrigger()); if (tooltip == null || tooltip.isEmpty()) { // CHECK IF THERE IS AN RSID Dialogs.showWarningDialogue(Text.Reports.warnExternalResource); } else { String rsId = tooltip.substring(6, tooltip.indexOf('<', 6)); URLInDefaultBrowser.browseGenericURL(LinksExternalResouces.getResourceLink( cmb_SearchDB.getSelectedIndex(), currentChr, // chr rsId, // rsId chartX) // pos ); } } else { // THE SELECTED EXTERNAL RESOURCE ONLY NEEDS CHR+POS INFO URLInDefaultBrowser.browseGenericURL( LinksExternalResouces.getResourceLink(cmb_SearchDB.getSelectedIndex(), currentChr, // chr "", // rsId chartX) // pos ); } // URLInDefaultBrowser.browseGenericURL(LinkEnsemblUrl.getHomoSapiensLink(currentChr, (int) chartX)); } catch (IOException ex) { log.error(Text.Reports.cannotOpenEnsembl, ex); } } /** * Receives chart mouse moved events. * * @param event the event. */ @Override public void chartMouseMoved(ChartMouseEvent event) { // ignore } }); initGUI(); }
From source file:org.eurocarbdb.application.glycoworkbench.plugin.reporting.AnnotationReportCanvas.java
public void moveControlPointTo(AnnotationObject selection, Point2D p) { Point2D dp = screenToDataCoords(p); theDocument.moveControlPointTo(selection, dp.getX(), dp.getY()); }
From source file:edu.dlnu.liuwenpeng.render.BarRenderer.java
/** * Draws an item label. This method is overridden so that the bar can be * used to calculate the label anchor point. * /*from ww w . j a v a2 s .c o m*/ * @param g2 the graphics device. * @param data the dataset. * @param row the row. * @param column the column. * @param plot the plot. * @param generator the label generator. * @param bar the bar. * @param negative a flag indicating a negative value. */ protected void drawItemLabel(Graphics2D g2, CategoryDataset data, int row, int column, CategoryPlot plot, CategoryItemLabelGenerator generator, Rectangle2D bar, boolean negative) { String label = generator.generateLabel(data, row, column); if (label == null) { return; // nothing to do } Font labelFont = getItemLabelFont(row, column); g2.setFont(labelFont); Paint paint = getItemLabelPaint(row, column); g2.setPaint(paint); // find out where to place the label... ItemLabelPosition position = null; if (!negative) { position = getPositiveItemLabelPosition(row, column); } else { position = getNegativeItemLabelPosition(row, column); } // work out the label anchor point... Point2D anchorPoint = calculateLabelAnchorPoint(position.getItemLabelAnchor(), bar, plot.getOrientation()); if (isInternalAnchor(position.getItemLabelAnchor())) { Shape bounds = TextUtilities.calculateRotatedStringBounds(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(), position.getRotationAnchor()); if (bounds != null) { if (!bar.contains(bounds.getBounds2D())) { if (!negative) { position = getPositiveItemLabelPositionFallback(); } else { position = getNegativeItemLabelPositionFallback(); } if (position != null) { anchorPoint = calculateLabelAnchorPoint(position.getItemLabelAnchor(), bar, plot.getOrientation()); } } } } if (position != null) { TextUtilities.drawRotatedString(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(), position.getRotationAnchor()); } }
From source file:org.jcurl.core.base.CurveTransformedTest.java
/** * Test the transformation from a Rock Coordinates (rc) System at wc(3,3.5) * with positive y axis along wc(2,4.2) into World Coordinates (wc). Uses a * Point rc(5,1.3) = wc(8,2.5).//w w w. jav a 2 s. co m */ public void testAffineTransformRotateShift() { final Point2D p0_wc = new Point2D.Double(3, 3.5); final Rock v0_wc = new RockDouble(2, 4.2, 0.3); final double v = v0_wc.distance(0, 0); final double[] d = { v0_wc.getY(), -v0_wc.getX(), v0_wc.getX(), v0_wc.getY(), 0, 0 }; final AffineTransform at = new AffineTransform(d); at.scale(1 / v, 1 / v); assertEquals(AffineTransform.TYPE_GENERAL_ROTATION + AffineTransform.TYPE_UNIFORM_SCALE, at.getType()); assertEquals(1.0, at.getDeterminant()); assertEquals(0.9028605188239303, at.getScaleX()); assertEquals(at.getScaleX(), at.getScaleY()); assertEquals(0.42993358039234775, at.getShearX()); assertEquals(-at.getShearX(), at.getShearY()); assertEquals(0, at.getTranslateX()); assertEquals(0, at.getTranslateY()); Point2D p = null; p = at.transform(new Point2D.Double(5, 1.3), null); assertEquals("Point2D.Double[5.073216248629703, -0.9759492274906292]", p.toString()); at.preConcatenate(AffineTransform.getTranslateInstance(p0_wc.getX(), p0_wc.getY())); assertEquals(AffineTransform.TYPE_GENERAL_ROTATION + AffineTransform.TYPE_TRANSLATION + AffineTransform.TYPE_UNIFORM_SCALE, at.getType()); assertEquals(1.0, at.getDeterminant()); assertEquals(0.9028605188239303, at.getScaleX()); assertEquals(at.getScaleX(), at.getScaleY()); assertEquals(0.42993358039234775, at.getShearX()); assertEquals(-at.getShearX(), at.getShearY()); assertEquals(p0_wc.getX(), at.getTranslateX()); assertEquals(p0_wc.getY(), at.getTranslateY()); p = at.transform(new Point2D.Double(5, 1.3), null); assertEquals("Point2D.Double[8.073216248629702, 2.524050772509371]", p.toString()); }
From source file:org.eurocarbdb.application.glycoworkbench.plugin.reporting.AnnotationReportCanvas.java
private void xorConnection(AnnotationObject selection, Point start_point, Point end_point) { Graphics g = getGraphics();//from ww w. j a v a 2 s .com g.setXORMode(Color.white); g.setColor(Color.gray); Rectangle rect = rectangles_complete.get(selection); Point2D peak = dataToScreenCoords(selection.getPeakPoint()); // select anchor Point2D anchor = computeAnchor(rect, end_point, peak); // draw connection g.drawLine((int) anchor.getX(), (int) anchor.getY(), (int) end_point.getX(), (int) end_point.getY()); g.drawLine((int) end_point.getX(), (int) end_point.getY(), (int) peak.getX(), (int) peak.getY()); }
From source file:org.eurocarbdb.application.glycoworkbench.plugin.SpectraPanel.java
public Peak findPeakAt(Point2D p) { if (theDocument.getNoScans() > 0) { Point2D dp = screenToDataCoords(p); double mz_toll = screenToDataX(3.); double int_toll = screenToDataY(3.); return findNearestPeak(dp.getX(), dp.getY(), mz_toll, int_toll); }//from www. j a v a2 s . c om return null; }
From source file:org.eurocarbdb.application.glycoworkbench.plugin.reporting.AnnotationReportCanvas.java
public AnnotationObject getConnectionAtPoint(Point2D p) { for (Map.Entry<AnnotationObject, Polygon> e : connections.entrySet()) { if (e.getValue().intersects(p.getX() - 3, p.getY() - 3, 6., 6.)) return e.getKey(); }/* w ww .j ava 2 s . c o m*/ return null; }
From source file:projects.wdlf47tuc.ProcessAllSwathcal.java
/** * Main entry point./* ww w . j av a 2 s . c om*/ * * @param args * * @throws IOException * */ public ProcessAllSwathcal() { // Path to AllSwathcal.dat file File allSwathcal = new File( "/home/nrowell/Astronomy/Data/47_Tuc/Kalirai_2012/UVIS/www.stsci.edu/~jkalirai/47Tuc/AllSwathcal.dat"); // Read file contents into the List try (BufferedReader in = new BufferedReader(new FileReader(allSwathcal))) { String sourceStr; while ((sourceStr = in.readLine()) != null) { Source source = Source.parseSource(sourceStr); if (source != null) { allSources.add(source); } } } catch (IOException e) { } logger.info("Parsed " + allSources.size() + " Sources from AllSwathcal.dat"); // Initialise chart cmdPanel = new ChartPanel(updateDataAndPlotCmd(allSources)); cmdPanel.addChartMouseListener(new ChartMouseListener() { @Override public void chartMouseClicked(ChartMouseEvent e) { // Capture mouse click location, transform to graph coordinates and add // a point to the polygonal selection box. Point2D p = cmdPanel.translateScreenToJava2D(e.getTrigger().getPoint()); Rectangle2D plotArea = cmdPanel.getScreenDataArea(); XYPlot plot = (XYPlot) cmdPanel.getChart().getPlot(); double chartX = plot.getDomainAxis().java2DToValue(p.getX(), plotArea, plot.getDomainAxisEdge()); double chartY = plot.getRangeAxis().java2DToValue(p.getY(), plotArea, plot.getRangeAxisEdge()); points.add(new double[] { chartX, chartY }); cmdPanel.setChart(plotCmd()); } @Override public void chartMouseMoved(ChartMouseEvent arg0) { } }); // Create colour combo boxes final JComboBox<Filter> magComboBox = new JComboBox<Filter>(filters); final JComboBox<Filter> col1ComboBox = new JComboBox<Filter>(filters); final JComboBox<Filter> col2ComboBox = new JComboBox<Filter>(filters); // Set initial values magComboBox.setSelectedItem(magFilter); col1ComboBox.setSelectedItem(col1Filter); col2ComboBox.setSelectedItem(col2Filter); // Create an action listener for these ActionListener al = new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { if (evt.getSource() == magComboBox) { magFilter = (Filter) magComboBox.getSelectedItem(); } if (evt.getSource() == col1ComboBox) { col1Filter = (Filter) col1ComboBox.getSelectedItem(); } if (evt.getSource() == col2ComboBox) { col2Filter = (Filter) col2ComboBox.getSelectedItem(); } // Changed colour(s), so reset selection box coordinates points.clear(); cmdPanel.setChart(updateDataAndPlotCmd(allSources)); } }; magComboBox.addActionListener(al); col1ComboBox.addActionListener(al); col2ComboBox.addActionListener(al); // Add a bit of padding to space things out magComboBox.setBorder(new EmptyBorder(5, 5, 5, 5)); col1ComboBox.setBorder(new EmptyBorder(5, 5, 5, 5)); col2ComboBox.setBorder(new EmptyBorder(5, 5, 5, 5)); // Set up statistic sliders final JSlider magErrMaxSlider = GuiUtil.buildSlider(magErrorRangeMin, magErrorRangeMax, 3, "%3.3f"); final JSlider chi2MaxSlider = GuiUtil.buildSlider(chi2RangeMin, chi2RangeMax, 3, "%3.3f"); final JSlider sharpMinSlider = GuiUtil.buildSlider(sharpRangeMin, sharpRangeMax, 3, "%3.3f"); final JSlider sharpMaxSlider = GuiUtil.buildSlider(sharpRangeMin, sharpRangeMax, 3, "%3.3f"); // Set intial values magErrMaxSlider.setValue( (int) Math.rint(100.0 * (magErrMax - magErrorRangeMin) / (magErrorRangeMax - magErrorRangeMin))); chi2MaxSlider.setValue((int) Math.rint(100.0 * (chi2Max - chi2RangeMin) / (chi2RangeMax - chi2RangeMin))); sharpMinSlider .setValue((int) Math.rint(100.0 * (sharpMin - sharpRangeMin) / (sharpRangeMax - sharpRangeMin))); sharpMaxSlider .setValue((int) Math.rint(100.0 * (sharpMax - sharpRangeMin) / (sharpRangeMax - sharpRangeMin))); // Set labels & initial values final JLabel magErrMaxLabel = new JLabel(getMagErrMaxLabel()); final JLabel chi2MaxLabel = new JLabel(getChi2MaxLabel()); final JLabel sharpMinLabel = new JLabel(getSharpMinLabel()); final JLabel sharpMaxLabel = new JLabel(getSharpMaxLabel()); // Create a change listener fot these ChangeListener cl = new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { JSlider source = (JSlider) e.getSource(); if (source == magErrMaxSlider) { // Compute max mag error from slider position double newMagErrMax = magErrorRangeMin + (magErrorRangeMax - magErrorRangeMin) * (source.getValue() / 100.0); magErrMax = newMagErrMax; magErrMaxLabel.setText(getMagErrMaxLabel()); } if (source == chi2MaxSlider) { // Compute Chi2 max from slider position double newChi2Max = chi2RangeMin + (chi2RangeMax - chi2RangeMin) * (source.getValue() / 100.0); chi2Max = newChi2Max; chi2MaxLabel.setText(getChi2MaxLabel()); } if (source == sharpMinSlider) { // Compute sharp min from slider position double newSharpMin = sharpRangeMin + (sharpRangeMax - sharpRangeMin) * (source.getValue() / 100.0); sharpMin = newSharpMin; sharpMinLabel.setText(getSharpMinLabel()); } if (source == sharpMaxSlider) { // Compute sharp max from slider position double newSharpMax = sharpRangeMin + (sharpRangeMax - sharpRangeMin) * (source.getValue() / 100.0); sharpMax = newSharpMax; sharpMaxLabel.setText(getSharpMaxLabel()); } cmdPanel.setChart(updateDataAndPlotCmd(allSources)); } }; magErrMaxSlider.addChangeListener(cl); chi2MaxSlider.addChangeListener(cl); sharpMinSlider.addChangeListener(cl); sharpMaxSlider.addChangeListener(cl); // Add a bit of padding to space things out magErrMaxSlider.setBorder(new EmptyBorder(5, 5, 5, 5)); chi2MaxSlider.setBorder(new EmptyBorder(5, 5, 5, 5)); sharpMinSlider.setBorder(new EmptyBorder(5, 5, 5, 5)); sharpMaxSlider.setBorder(new EmptyBorder(5, 5, 5, 5)); // Text field to store distance modulus final JTextField distanceModulusField = new JTextField(Double.toString(mu)); distanceModulusField.setBorder(new EmptyBorder(5, 5, 5, 5)); Border compound = BorderFactory.createCompoundBorder(new LineBorder(this.getBackground(), 5), BorderFactory.createEtchedBorder(EtchedBorder.LOWERED)); final JButton lfButton = new JButton("Luminosity function for selection"); lfButton.setBorder(compound); lfButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // Read distance modulus field try { double mu_new = Double.parseDouble(distanceModulusField.getText()); mu = mu_new; } catch (NullPointerException | NumberFormatException ex) { JOptionPane.showMessageDialog(lfButton, "Error parsing the distance modulus: " + ex.getMessage(), "Distance Modulus Error", JOptionPane.ERROR_MESSAGE); return; } if (boxedSources.isEmpty()) { JOptionPane.showMessageDialog(lfButton, "No sources are currently selected!", "Selection Error", JOptionPane.ERROR_MESSAGE); } else { computeAndPlotLuminosityFunction(boxedSources); } } }); final JButton clearSelectionButton = new JButton("Clear selection"); clearSelectionButton.setBorder(compound); clearSelectionButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { points.clear(); cmdPanel.setChart(plotCmd()); } }); JPanel controls = new JPanel(new GridLayout(9, 2)); controls.setBorder(new EmptyBorder(10, 10, 10, 10)); controls.add(new JLabel("Magnitude = ")); controls.add(magComboBox); controls.add(new JLabel("Colour 1 = ")); controls.add(col1ComboBox); controls.add(new JLabel("Colour 2 = ")); controls.add(col2ComboBox); controls.add(magErrMaxLabel); controls.add(magErrMaxSlider); controls.add(chi2MaxLabel); controls.add(chi2MaxSlider); controls.add(sharpMinLabel); controls.add(sharpMinSlider); controls.add(sharpMaxLabel); controls.add(sharpMaxSlider); controls.add(new JLabel("Adopted distance modulus = ")); controls.add(distanceModulusField); controls.add(lfButton); controls.add(clearSelectionButton); this.setLayout(new BorderLayout()); this.add(cmdPanel, BorderLayout.CENTER); this.add(controls, BorderLayout.SOUTH); this.validate(); }
From source file:org.esa.snap.rcp.statistics.ScatterPlotPanel.java
private void compute(final Mask selectedMask) { final RasterDataNode raster = getRaster(); final AttributeDescriptor dataField = scatterPlotModel.dataField; if (raster == null || dataField == null) { return;/* w ww .jav a 2s.c om*/ } SwingWorker<ComputedData[], Object> swingWorker = new SwingWorker<ComputedData[], Object>() { @Override protected ComputedData[] doInBackground() throws Exception { SystemUtils.LOG.finest("start computing scatter plot data"); final List<ComputedData> computedDataList = new ArrayList<>(); final FeatureCollection<SimpleFeatureType, SimpleFeature> collection = scatterPlotModel.pointDataSource .getFeatureCollection(); final SimpleFeature[] features = collection.toArray(new SimpleFeature[collection.size()]); final int boxSize = scatterPlotModel.boxSize; final Rectangle sceneRect = new Rectangle(raster.getRasterWidth(), raster.getRasterHeight()); final GeoCoding geoCoding = raster.getGeoCoding(); final AffineTransform imageToModelTransform; imageToModelTransform = Product.findImageToModelTransform(geoCoding); for (SimpleFeature feature : features) { final Point point = (Point) feature.getDefaultGeometryProperty().getValue(); Point2D modelPos = new Point2D.Float((float) point.getX(), (float) point.getY()); final Point2D imagePos = imageToModelTransform.inverseTransform(modelPos, null); if (!sceneRect.contains(imagePos)) { continue; } final float imagePosX = (float) imagePos.getX(); final float imagePosY = (float) imagePos.getY(); final Rectangle imageRect = sceneRect.intersection(new Rectangle( ((int) imagePosX) - boxSize / 2, ((int) imagePosY) - boxSize / 2, boxSize, boxSize)); if (imageRect.isEmpty()) { continue; } final double[] rasterValues = new double[imageRect.width * imageRect.height]; raster.readPixels(imageRect.x, imageRect.y, imageRect.width, imageRect.height, rasterValues); final int[] maskBuffer = new int[imageRect.width * imageRect.height]; Arrays.fill(maskBuffer, 1); if (selectedMask != null) { selectedMask.readPixels(imageRect.x, imageRect.y, imageRect.width, imageRect.height, maskBuffer); } final int centerIndex = imageRect.width * (imageRect.height / 2) + (imageRect.width / 2); if (maskBuffer[centerIndex] == 0) { continue; } double sum = 0; double sumSqr = 0; int n = 0; boolean valid = false; for (int y = 0; y < imageRect.height; y++) { for (int x = 0; x < imageRect.width; x++) { final int index = y * imageRect.height + x; if (raster.isPixelValid(x + imageRect.x, y + imageRect.y) && maskBuffer[index] != 0) { final double rasterValue = rasterValues[index]; sum += rasterValue; sumSqr += rasterValue * rasterValue; n++; valid = true; } } } if (!valid) { continue; } double rasterMean = sum / n; double rasterSigma = n > 1 ? Math.sqrt((sumSqr - (sum * sum) / n) / (n - 1)) : 0.0; String localName = dataField.getLocalName(); Number attribute = (Number) feature.getAttribute(localName); final Collection<org.opengis.feature.Property> featureProperties = feature.getProperties(); final float correlativeData = attribute.floatValue(); final GeoPos geoPos = new GeoPos(); if (geoCoding.canGetGeoPos()) { final PixelPos pixelPos = new PixelPos(imagePosX, imagePosY); geoCoding.getGeoPos(pixelPos, geoPos); } else { geoPos.setInvalid(); } computedDataList.add( new ComputedData(imagePosX, imagePosY, (float) geoPos.getLat(), (float) geoPos.getLon(), (float) rasterMean, (float) rasterSigma, correlativeData, featureProperties)); } return computedDataList.toArray(new ComputedData[computedDataList.size()]); } @Override public void done() { try { final ValueAxis xAxis = getPlot().getDomainAxis(); final ValueAxis yAxis = getPlot().getRangeAxis(); xAxis.setAutoRange(false); yAxis.setAutoRange(false); scatterpointsDataset.removeAllSeries(); acceptableDeviationDataset.removeAllSeries(); regressionDataset.removeAllSeries(); getPlot().removeAnnotation(r2Annotation); computedDatas = null; final ComputedData[] data = get(); if (data.length == 0) { return; } computedDatas = data; final XYIntervalSeries scatterValues = new XYIntervalSeries(getCorrelativeDataName()); for (ComputedData computedData : computedDatas) { final float rasterMean = computedData.rasterMean; final float rasterSigma = computedData.rasterSigma; final float correlativeData = computedData.correlativeData; scatterValues.add(correlativeData, correlativeData, correlativeData, rasterMean, rasterMean - rasterSigma, rasterMean + rasterSigma); } computingData = true; scatterpointsDataset.addSeries(scatterValues); xAxis.setAutoRange(true); yAxis.setAutoRange(true); xAxis.setAutoRange(false); yAxis.setAutoRange(false); xAutoRangeAxisRange = new Range(xAxis.getLowerBound(), xAxis.getUpperBound()); yAutoRangeAxisRange = new Range(yAxis.getLowerBound(), yAxis.getUpperBound()); if (xAxisRangeControl.isAutoMinMax()) { xAxisRangeControl.adjustComponents(xAxis, 3); } else { xAxisRangeControl.adjustAxis(xAxis, 3); } if (yAxisRangeControl.isAutoMinMax()) { yAxisRangeControl.adjustComponents(yAxis, 3); } else { yAxisRangeControl.adjustAxis(yAxis, 3); } computeRegressionAndAcceptableDeviationData(); computingData = false; } catch (InterruptedException | CancellationException e) { SystemUtils.LOG.log(Level.WARNING, "Failed to compute correlative plot.", e); Dialogs.showMessage(CHART_TITLE, "Failed to compute correlative plot.\n" + "Calculation canceled.", JOptionPane.ERROR_MESSAGE, null); } catch (ExecutionException e) { SystemUtils.LOG.log(Level.WARNING, "Failed to compute correlative plot.", e); Dialogs.showMessage(CHART_TITLE, "Failed to compute correlative plot.\n" + "An error occurred:\n" + e.getCause().getMessage(), JOptionPane.ERROR_MESSAGE, null); } } }; swingWorker.execute(); }
From source file:cellularAutomata.analysis.PricingDistributionAnalysis.java
/** * Plots the pricing data as a time series. *///w ww . j a v a2 s. co m private void plotTimeSeriesData() { for (int i = 0; i < numberOfStates; i++) { // create a list of all data points (exclude 0 if necessary) LinkedList<Point2D.Double> allPoints = new LinkedList<Point2D.Double>(); int startPosition = 0; if (!plotZeroState) { startPosition = 1; } allPoints.addAll(timeSeriesOfDistributionList[i]); // set the min and max values on the plot Point2D firstPoint = (Point2D) timeSeriesOfDistributionList[i].getFirst(); timeSeriesPlot[i].setMaximumXValue(firstPoint.getX() + MAX_NUMBER_TO_PLOT - 1); timeSeriesPlot[i].setMinimumXValue(0); timeSeriesPlot[i].setMinimumYValue(0.0); timeSeriesPlot[i].setXAxisLabel("Histogram"); timeSeriesPlot[i].setYAxisLabel("% bin"); timeSeriesPlot[i].showPlotLines(false); // set the max y-value double maxYValue = 0.0; Iterator<Point2D.Double> iterator = allPoints.iterator(); while (iterator.hasNext()) { Point2D.Double point = iterator.next(); if (point.y > maxYValue) { maxYValue = point.y; } } // now round up to the nearest tenth and add 0.1. This gives some // wiggle room before the plot will have to redraw the y-axis. If // redraw the y-axis too often, it will look bad. This crazy case // statement ensures that we don't get something like 0.7999999 // instead // of 0.8 (which is what was happening when I would divide by 10.0 // using // a formula to calculate the maxYValue). switch ((int) Math.ceil(maxYValue * 10.0)) { case 0: maxYValue = 0.1; break; case 1: maxYValue = 0.2; break; case 2: maxYValue = 0.3; break; case 3: maxYValue = 0.4; break; case 4: maxYValue = 0.5; break; case 5: maxYValue = 0.6; break; case 6: maxYValue = 0.7; break; case 7: maxYValue = 0.8; break; case 8: maxYValue = 0.9; break; case 9: maxYValue = 1.0; break; case 10: maxYValue = 1.0; break; case 11: maxYValue = 1.0; break; case 12: maxYValue = 1.0; break; } if (maxYValue > 1.0) { maxYValue = 1.0; } maxYValue = maxYValue * 1; timeSeriesPlot[i].setMaximumYValue(maxYValue); // draw some extra points on the y axes (looks good) int numberOfInteriorYValueLabels = (int) ((maxYValue / 20)); double[] yValues = new double[numberOfInteriorYValueLabels]; for (int j = 0; j < yValues.length; j++) { double answer = (j * 20); yValues[j] = answer; } timeSeriesPlot[i].setExtraYAxisValues(yValues); // specify colors for the points Color[] colorArray = new Color[allPoints.size()]; CellStateView view = Cell.getView(); Color stateColor = view.getDisplayColor(new IntegerCellState(i), null, new Coordinate(0, 0)); for (int j = 0; j < timeSeriesOfDistributionList[i].size(); j++) { colorArray[j] = stateColor; } timeSeriesPlot[i].setPointDisplayColors(colorArray); // draw the points! timeSeriesPlot[i].drawPoints(allPoints); } }