List of usage examples for org.jfree.data Range getLength
public double getLength()
From source file:net.sf.mzmine.chartbasics.ChartLogics.java
/** * Calculates the size of a chart for a given fixed plot width Domain and Range axes need to share * the same unit (e.g. mm)//from w w w . j av a 2 s .c o m * * @param chart * @param plotWidth * @return */ public static Dimension calcSizeForPlotWidth(ChartPanel myChart, double plotWidth, int iterations) { // ranges XYPlot plot = (XYPlot) myChart.getChart().getPlot(); ValueAxis domainAxis = plot.getDomainAxis(); Range x = domainAxis.getRange(); ValueAxis rangeAxis = plot.getRangeAxis(); Range y = rangeAxis.getRange(); // plot height is fixed double plotHeight = plotWidth / x.getLength() * y.getLength(); return calcSizeForPlotSize(myChart, plotWidth, plotHeight, iterations); }
From source file:net.sf.mzmine.chartbasics.ChartLogicsFX.java
/** * calculates the correct height with multiple iterations Domain and Range axes need to share the * same unit (e.g. mm)/* w w w .j av a 2 s .c o m*/ * * @param myChart * @param dataWidth width of data * @param axis for width calculation * @return */ public static double calcHeightToWidth(ChartViewer myChart, double chartWidth, double estimatedHeight, int iterations) { // if(myChart.getChartRenderingInfo()==null || // myChart.getChartRenderingInfo().getChartArea()==null || // myChart.getChartRenderingInfo().getChartArea().getWidth()==0) // result double height = estimatedHeight; double lastH = height; makeChartResizable(myChart); try { for (int i = 0; i < iterations; i++) { // paint on ghost panel with estimated height (if copy panel==true) myChart.getCanvas().setWidth((int) chartWidth); myChart.getCanvas().setHeight((int) estimatedHeight); myChart.getCanvas().draw(); XYPlot plot = (XYPlot) myChart.getChart().getPlot(); ChartRenderingInfo info = myChart.getRenderingInfo(); Rectangle2D dataArea = info.getPlotInfo().getDataArea(); Rectangle2D chartArea = info.getChartArea(); // calc title space: will be added later to the right plot size double titleWidth = chartArea.getWidth() - dataArea.getWidth(); double titleHeight = chartArea.getHeight() - dataArea.getHeight(); // calc right plot size with axis dim. // real plot width is given by factor; double realPW = chartWidth - titleWidth; // ranges ValueAxis domainAxis = plot.getDomainAxis(); org.jfree.data.Range x = domainAxis.getRange(); ValueAxis rangeAxis = plot.getRangeAxis(); org.jfree.data.Range y = rangeAxis.getRange(); // real plot height can be calculated by double realPH = realPW / x.getLength() * y.getLength(); // the real height height = realPH + titleHeight; // for next iteration estimatedHeight = height; if ((int) lastH == (int) height) break; else lastH = height; } } catch (Exception ex) { ex.printStackTrace(); } return height; }
From source file:net.sf.mzmine.chartbasics.ChartLogics.java
/** * calculates the correct height with multiple iterations Domain and Range axes need to share the * same unit (e.g. mm)/* w w w .j a v a2 s . c om*/ * * @param myChart * @param copyToNewPanel * @param dataWidth width of data * @param axis for width calculation * @return */ public static double calcHeightToWidth(ChartPanel myChart, double chartWidth, double estimatedHeight, int iterations, boolean copyToNewPanel) { // if(myChart.getChartRenderingInfo()==null || // myChart.getChartRenderingInfo().getChartArea()==null || // myChart.getChartRenderingInfo().getChartArea().getWidth()==0) // result double height = estimatedHeight; double lastH = height; makeChartResizable(myChart); // paint on a ghost panel JPanel parent = (JPanel) myChart.getParent(); JPanel p = copyToNewPanel ? new JPanel() : parent; if (copyToNewPanel) p.add(myChart, BorderLayout.CENTER); try { for (int i = 0; i < iterations; i++) { // paint on ghost panel with estimated height (if copy panel==true) myChart.setSize((int) chartWidth, (int) estimatedHeight); myChart.paintImmediately(myChart.getBounds()); XYPlot plot = (XYPlot) myChart.getChart().getPlot(); ChartRenderingInfo info = myChart.getChartRenderingInfo(); Rectangle2D dataArea = info.getPlotInfo().getDataArea(); Rectangle2D chartArea = info.getChartArea(); // calc title space: will be added later to the right plot size double titleWidth = chartArea.getWidth() - dataArea.getWidth(); double titleHeight = chartArea.getHeight() - dataArea.getHeight(); // calc right plot size with axis dim. // real plot width is given by factor; double realPW = chartWidth - titleWidth; // ranges ValueAxis domainAxis = plot.getDomainAxis(); org.jfree.data.Range x = domainAxis.getRange(); ValueAxis rangeAxis = plot.getRangeAxis(); org.jfree.data.Range y = rangeAxis.getRange(); // real plot height can be calculated by double realPH = realPW / x.getLength() * y.getLength(); // the real height height = realPH + titleHeight; // for next iteration estimatedHeight = height; if ((int) lastH == (int) height) break; else lastH = height; } } catch (Exception ex) { ex.printStackTrace(); } if (copyToNewPanel) { // reset to frame p.removeAll(); parent.add(myChart); } return height; }
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 w w w .ja va2 s . 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:gda.plots.DataMagnifierWindow.java
/** * The SimplePlot will call this method when the Rectangle to be magnified has changed. * //from w w w . j a va2 s . c o m * @param magnifyRectangle * the Rectangle to be magnified */ @Override public void update(Rectangle2D magnifyRectangle) { // The magnifyRectangle will be in Java coordinates, need to calculate // the axis limits required. This mechanism was copied from the zooming // methods within JFreeChart. double hLower = 0.0; double hUpper = 0.0; double vLower = 0.0; double vUpper = 0.0; double a; double b; Rectangle2D scaledDataArea; if (magnifyRectangle != null) { scaledDataArea = simplePlot.getScreenDataArea(); hLower = (magnifyRectangle.getMinX() - scaledDataArea.getMinX()) / scaledDataArea.getWidth(); hUpper = (magnifyRectangle.getMaxX() - scaledDataArea.getMinX()) / scaledDataArea.getWidth(); vLower = (scaledDataArea.getMaxY() - magnifyRectangle.getMaxY()) / scaledDataArea.getHeight(); vUpper = (scaledDataArea.getMaxY() - magnifyRectangle.getMinY()) / scaledDataArea.getHeight(); Range r = simplePlot.getChart().getXYPlot().getDomainAxis().getRange(); a = r.getLowerBound() + hLower * r.getLength(); b = r.getLowerBound() + hUpper * r.getLength(); Range newR = new Range(Math.min(a, b), Math.max(a, b)); magnifiedPlot.getDomainAxis().setRange(newR); r = simplePlot.getChart().getXYPlot().getRangeAxis().getRange(); a = r.getLowerBound() + vLower * r.getLength(); b = r.getLowerBound() + vUpper * r.getLength(); newR = new Range(Math.min(a, b), Math.max(a, b)); magnifiedPlot.getRangeAxis().setRange(newR); repaint(); } }
From source file:org.lmn.fc.frameworks.starbase.plugins.observatory.ui.tabs.charts.ChartUIHelper.java
/*********************************************************************************************** * Calculate and update the Domain Offset Crosshair and draw the crosshair on the XYPlot. * Return the value set on the XYPlot, or Double.MIN_VALUE on failure. * * @param chartui/*from ww w.j a v a 2 s.c o m*/ * @param valueminimum * @param valuemaximum * @param offset * @param debug * * @return double */ public static double updateDomainCrosshairForOffsetControl(final ChartUIComponentPlugin chartui, final int valueminimum, final int valuemaximum, final double offset, final boolean debug) { final String SOURCE = "ChartHelper.updateDomainCrosshairForOffsetControl() "; double dblDomainCrosshairXYPlot; dblDomainCrosshairXYPlot = Double.MIN_VALUE; if (chartui != null) { if ((chartui.getChartPanel() != null) && (chartui.getChartPanel().getChart() != null) && (chartui.getChartPanel().getChart().getPlot() != null)) { final XYPlot plot; final ValueAxis domainAxis; final Range range; final double dblPositionFraction; // Save the supplied new value chartui.setDomainCrosshair(offset); plot = (XYPlot) chartui.getChartPanel().getChart().getPlot(); domainAxis = plot.getDomainAxis(); range = domainAxis.getRange(); if (offset >= 0) { //dblPositionFraction = (offset - (double)valueminimum) / (double)(valuemaximum - valueminimum); dblPositionFraction = (offset * 2.0) / (double) (valuemaximum - valueminimum); } else { dblPositionFraction = 0.0; } dblDomainCrosshairXYPlot = domainAxis.getLowerBound() + (dblPositionFraction * range.getLength()); // Update the XYPlot plot.setDomainCrosshairValue(dblDomainCrosshairXYPlot); FrameworkSingletons.LOGGER.debug(debug, SOURCE + "Domain Crosshair updated [value.knob=" + offset + "] [value.xyplot=" + dblDomainCrosshairXYPlot + "] [domain.lowerbound=" + domainAxis.getLowerBound() + "] [domain.upperbound=" + domainAxis.getUpperBound() + "] [value.fraction=" + dblPositionFraction + "] [value.minimum=" + valueminimum + "] [value.maximum=" + valuemaximum + "]"); } else { FrameworkSingletons.LOGGER.debug(debug, SOURCE + "There is no Chart, so cannot update Domain Crosshair on XYPlot"); // Save a default value chartui.setDomainCrosshair(valueminimum); dblDomainCrosshairXYPlot = Double.MIN_VALUE; } } return (dblDomainCrosshairXYPlot); }
From source file:org.jfree.chart.demo.bottom_slider.java
/** * Create the panel.//from ww w . ja va 2s. c o m */ public bottom_slider(Color color, ArrayList<JFreeChart> chart, final Graphic graph, int num) { setBounds(5, 380, 740, 100); setLayout(null); charts = chart; plot = charts.get(num).getXYPlot(); table = new JTable( new Object[][] { { "Slider", "X", "Y", "X1-X2", "Y1-Y2" }, { "Slider1", null, null, null, null }, { "Slider2", null, null, null, null } }, new String[] { "Slider", "X", "Y", "X1-X2", "Y1-Y2" }); setBackground(color); table.setBounds(255, 22, 485, 48); add(table); slider_2 = new JSlider(); slider_2.setBounds(5, 22, 250, 20); slider_2.setBackground(color); slider_2.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { try { int value = slider_2.getValue(); ValueAxis domainAxis = plot.getDomainAxis(); Range range = domainAxis.getRange(); X1 = domainAxis.getLowerBound() + (value / 100.0) * range.getLength(); int i = 0; for (; i < graph.mas_x.size(); i++) { // System.out.println("X"+ Arrays.toString(graph.mas_x.toArray())); if (graph.mas_x.get(i).doubleValue() <= X1) { } else { break; } } Y1 = graph.mas_y.get(i).doubleValue(); } catch (Exception e1) { if (e.toString() == "java.lang.IndexOutOfBoundsException") Y1 = graph.mas_y.get(graph.mas_y.size() - 1).doubleValue(); } plot.removeDomainMarker(distanceTiers2); distanceTiers2 = new ValueMarker(X1); distanceTiers2.setPaint(Color.BLACK); plot.addDomainMarker(distanceTiers2); table.setValueAt("" + new BigDecimal(X1).setScale(3, RoundingMode.UP).doubleValue(), 1, 1); table.setValueAt("" + new BigDecimal(Y1).setScale(3, RoundingMode.UP).doubleValue(), 1, 2); table.setValueAt("" + new BigDecimal(X2).setScale(3, RoundingMode.UP).doubleValue(), 2, 1); table.setValueAt("" + new BigDecimal(Y2).setScale(3, RoundingMode.UP).doubleValue(), 2, 2); table.setValueAt("" + new BigDecimal(Math.abs(X2 - X1)).setScale(3, RoundingMode.UP).doubleValue(), 2, 3); table.setValueAt("" + new BigDecimal(Math.abs(X2 - X1)).setScale(3, RoundingMode.UP).doubleValue(), 1, 3); table.setValueAt("" + new BigDecimal(Math.abs(Y2 - Y1)).setScale(3, RoundingMode.UP).doubleValue(), 2, 4); table.setValueAt("" + new BigDecimal(Math.abs(Y2 - Y1)).setScale(3, RoundingMode.UP).doubleValue(), 1, 4); } }); add(slider_2); slider_3 = new JSlider(); slider_3.setBounds(5, 55, 250, 20); slider_3.setBackground(color); slider_3.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { try { int value = slider_3.getValue(); ValueAxis domainAxis = plot.getDomainAxis(); Range range = domainAxis.getRange(); X2 = domainAxis.getLowerBound() + (value / 100.0) * range.getLength(); plot.removeDomainMarker(distanceTiers1); distanceTiers1 = new ValueMarker(X2); distanceTiers1.setPaint(Color.BLACK); plot.addDomainMarker(distanceTiers1); int i = 0; for (; i < graph.mas_x.size(); i++) { if (graph.mas_x.get(i).doubleValue() <= X2) { } else { break; } } Y2 = graph.mas_y.get(i).doubleValue(); } catch (Exception e1) { if (e.toString() == "java.lang.IndexOutOfBoundsException") Y1 = graph.mas_y.get(graph.mas_y.size() - 1).doubleValue(); } table.setValueAt("" + new BigDecimal(X1).setScale(3, RoundingMode.UP).doubleValue(), 1, 1); table.setValueAt("" + new BigDecimal(Y1).setScale(3, RoundingMode.UP).doubleValue(), 1, 2); table.setValueAt("" + new BigDecimal(X2).setScale(3, RoundingMode.UP).doubleValue(), 2, 1); table.setValueAt("" + new BigDecimal(Y2).setScale(3, RoundingMode.UP).doubleValue(), 2, 2); table.setValueAt("" + new BigDecimal(Math.abs(X2 - X1)).setScale(3, RoundingMode.UP).doubleValue(), 2, 3); table.setValueAt("" + new BigDecimal(Math.abs(X2 - X1)).setScale(3, RoundingMode.UP).doubleValue(), 1, 3); table.setValueAt("" + new BigDecimal(Math.abs(Y2 - Y1)).setScale(3, RoundingMode.UP).doubleValue(), 2, 4); table.setValueAt("" + new BigDecimal(Math.abs(Y2 - Y1)).setScale(3, RoundingMode.UP).doubleValue(), 1, 4); } }); add(slider_3); }
From source file:org.jfree.data.contour.NonGridContourDataset.java
/** * Builds a regular grid. Maps the non-grid data into the regular grid * using an inverse distance between grid and non-grid points. Weighting * of distance can be controlled by setting through the power parameter * that controls the exponent used on the distance weighting * (e.g., distance^power)./*from ww w .ja v a2 s .c o m*/ * * @param numX number grid points in along the x-axis * @param numY number grid points in along the y-axis * @param power exponent for inverse distance weighting */ protected void buildGrid(int numX, int numY, int power) { int numValues = numX * numY; double[] xGrid = new double[numValues]; double[] yGrid = new double[numValues]; double[] zGrid = new double[numValues]; // Find min, max for the x and y axes double xMin = 1.e20; for (int k = 0; k < this.xValues.length; k++) { xMin = Math.min(xMin, this.xValues[k].doubleValue()); } double xMax = -1.e20; for (int k = 0; k < this.xValues.length; k++) { xMax = Math.max(xMax, this.xValues[k].doubleValue()); } double yMin = 1.e20; for (int k = 0; k < this.yValues.length; k++) { yMin = Math.min(yMin, this.yValues[k].doubleValue()); } double yMax = -1.e20; for (int k = 0; k < this.yValues.length; k++) { yMax = Math.max(yMax, this.yValues[k].doubleValue()); } Range xRange = new Range(xMin, xMax); Range yRange = new Range(yMin, yMax); xRange.getLength(); yRange.getLength(); // Determine the cell size double dxGrid = xRange.getLength() / (numX - 1); double dyGrid = yRange.getLength() / (numY - 1); // Generate the grid double x = 0.0; for (int i = 0; i < numX; i++) { if (i == 0) { x = xMin; } else { x += dxGrid; } double y = 0.0; for (int j = 0; j < numY; j++) { int k = numY * i + j; xGrid[k] = x; if (j == 0) { y = yMin; } else { y += dyGrid; } yGrid[k] = y; } } // Map the nongrid data into the new regular grid for (int kGrid = 0; kGrid < xGrid.length; kGrid++) { double dTotal = 0.0; zGrid[kGrid] = 0.0; for (int k = 0; k < this.xValues.length; k++) { double xPt = this.xValues[k].doubleValue(); double yPt = this.yValues[k].doubleValue(); double d = distance(xPt, yPt, xGrid[kGrid], yGrid[kGrid]); if (power != 1) { d = Math.pow(d, power); } d = Math.sqrt(d); if (d > 0.0) { d = 1.0 / d; } else { // if d is real small set the inverse to a large number // to avoid INF d = 1.e20; } if (this.zValues[k] != null) { // scale by the inverse of distance^power zGrid[kGrid] += this.zValues[k].doubleValue() * d; } dTotal += d; } zGrid[kGrid] = zGrid[kGrid] / dTotal; //remove distance of the sum } //initalize xValues, yValues, and zValues arrays. initialize(formObjectArray(xGrid), formObjectArray(yGrid), formObjectArray(zGrid)); }
From source file:gov.llnl.lc.infiniband.opensm.plugin.gui.chart.AdvancedXY_PlotPanel.java
@Override public void stateChanged(ChangeEvent e) { int value = this.slider.getValue(); XYPlot plot = (XYPlot) this.getChart().getPlot(); ValueAxis domainAxis = plot.getDomainAxis(); Range range = domainAxis.getRange(); double c = domainAxis.getLowerBound() + (value / 100.0) * range.getLength(); // displays the vertical crosshair in the desired position plot.setDomainCrosshairValue(c);/*from ww w.j a v a2 s . c o m*/ // the cross hair is keyed to the horizontal slider - for the time domain axis setCrossHairDomainIndex(); }
From source file:net.sf.jasperreports.charts.util.ChartUtil.java
public void setAutoTickUnit(NumberAxis numberAxis) { if (numberAxis.isAutoTickUnitSelection()) { Range range = numberAxis.getRange(); if (range.getLength() >= AUTO_TICK_UNIT_THRESHOLD) { // this is a workaround for a floating point error makes JFreeChart // select tick units that are too small when the values are very large double autoSize = range.getLength() / AUTO_TICK_UNIT_THRESHOLD; TickUnit unit = numberAxis.getStandardTickUnits().getCeilingTickUnit(autoSize); numberAxis.setTickUnit((NumberTickUnit) unit, false, false); }/*from w ww. j a va2 s . c o m*/ } }