List of usage examples for org.jfree.data Range getUpperBound
public double getUpperBound()
From source file:net.sf.jasperreports.chartthemes.spring.AegeanChartTheme.java
@Override protected JFreeChart createThermometerChart() throws JRException { JRThermometerPlot jrPlot = (JRThermometerPlot) getPlot(); // Create the plot that will hold the thermometer. ThermometerPlot chartPlot = new ThermometerPlot((ValueDataset) getDataset()); ChartUtil chartUtil = ChartUtil.getInstance(getChartContext().getJasperReportsContext()); // setting localized range axis formatters chartPlot.getRangeAxis().setStandardTickUnits(chartUtil.createIntegerTickUnits(getLocale())); // Build a chart around this plot JFreeChart jfreeChart = new JFreeChart(evaluateTextExpression(getChart().getTitleExpression()), null, chartPlot, getChart().getShowLegend() == null ? false : getChart().getShowLegend()); // Set the generic options configureChart(jfreeChart, getPlot()); jfreeChart.setBackgroundPaint(ChartThemesConstants.TRANSPARENT_PAINT); jfreeChart.setBorderVisible(false);/* w ww. j a v a2 s .com*/ Range range = convertRange(jrPlot.getDataRange()); if (range != null) { // Set the boundary of the thermomoter chartPlot.setLowerBound(range.getLowerBound()); chartPlot.setUpperBound(range.getUpperBound()); } chartPlot.setGap(0); // Units can only be Fahrenheit, Celsius or none, so turn off for now. chartPlot.setUnits(ThermometerPlot.UNITS_NONE); // Set the color of the mercury. Only used when the value is outside of // any defined ranges. @SuppressWarnings("unchecked") List<Paint> seriesPaints = (List<Paint>) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.SERIES_COLORS); Paint paint = jrPlot.getMercuryColor(); if (paint != null) { chartPlot.setUseSubrangePaint(false); } else { //it has no effect, but is kept for backward compatibility reasons paint = seriesPaints.get(0); } chartPlot.setMercuryPaint(paint); chartPlot.setThermometerPaint(THERMOMETER_COLOR); chartPlot.setThermometerStroke(new BasicStroke(2f)); chartPlot.setOutlineVisible(false); chartPlot.setValueFont(chartPlot.getValueFont().deriveFont(Font.BOLD)); // localizing the default format, can be overridden by display.getMask() chartPlot.setValueFormat(NumberFormat.getNumberInstance(getLocale())); // Set the formatting of the value display JRValueDisplay display = jrPlot.getValueDisplay(); if (display != null) { if (display.getColor() != null) { chartPlot.setValuePaint(display.getColor()); } if (display.getMask() != null) { chartPlot.setValueFormat( new DecimalFormat(display.getMask(), DecimalFormatSymbols.getInstance(getLocale()))); } if (display.getFont() != null) { // chartPlot.setValueFont(JRFontUtil.getAwtFont(display.getFont()).deriveFont(Font.BOLD)); } } // Set the location of where the value is displayed // Set the location of where the value is displayed ValueLocationEnum valueLocation = jrPlot.getValueLocationValue(); switch (valueLocation) { case NONE: chartPlot.setValueLocation(ThermometerPlot.NONE); break; case LEFT: chartPlot.setValueLocation(ThermometerPlot.LEFT); break; case RIGHT: chartPlot.setValueLocation(ThermometerPlot.RIGHT); break; case BULB: default: chartPlot.setValueLocation(ThermometerPlot.BULB); break; } // Define the three ranges range = convertRange(jrPlot.getLowRange()); if (range != null) { chartPlot.setSubrangeInfo(2, range.getLowerBound(), range.getUpperBound()); } range = convertRange(jrPlot.getMediumRange()); if (range != null) { chartPlot.setSubrangeInfo(1, range.getLowerBound(), range.getUpperBound()); } range = convertRange(jrPlot.getHighRange()); if (range != null) { chartPlot.setSubrangeInfo(0, range.getLowerBound(), range.getUpperBound()); } return jfreeChart; }
From source file:org.gumtree.vis.plot1d.Plot1DChartEditor.java
private void chooseROI(RangeMask mask) { if (mask != null) { roiName.setText(mask.getName()); if (mask.isInclusive()) { inclusiveRadio.setSelected(true); } else {/*from ww w. j a v a 2 s . com*/ exclusiveRadio.setSelected(true); } Range bounds = mask.getRange(); xMin.setText(String.valueOf(bounds.getLowerBound())); xMax.setText(String.valueOf(bounds.getUpperBound())); deleteButton.setEnabled(true); } else { roiName.setText(null); inclusiveRadio.setSelected(false); exclusiveRadio.setSelected(false); xMin.setText(null); xMax.setText(null); } applyButton.setEnabled(false); }
From source file:net.sf.jasperreports.chartthemes.spring.AegeanChartTheme.java
@Override protected JFreeChart createMeterChart() throws JRException { // Start by creating the plot that will hold the meter MeterPlot chartPlot = new MeterPlot((ValueDataset) getDataset()); JRMeterPlot jrPlot = (JRMeterPlot) getPlot(); // Set the shape MeterShapeEnum shape = jrPlot.getShapeValue() == null ? MeterShapeEnum.DIAL : jrPlot.getShapeValue(); switch (shape) { case CHORD:/*from w ww . j a v a2 s .c o m*/ chartPlot.setDialShape(DialShape.CHORD); break; case PIE: chartPlot.setDialShape(DialShape.PIE); break; case CIRCLE: chartPlot.setDialShape(DialShape.CIRCLE); break; case DIAL: default: return createDialChart(); } chartPlot.setDialOutlinePaint(Color.BLACK); int meterAngle = jrPlot.getMeterAngleInteger() == null ? 180 : jrPlot.getMeterAngleInteger(); // Set the size of the meter chartPlot.setMeterAngle(meterAngle); // Set the spacing between ticks. I hate the name "tickSize" since to me it // implies I am changing the size of the tick, not the spacing between them. double tickInterval = jrPlot.getTickIntervalDouble() == null ? 10.0 : jrPlot.getTickIntervalDouble(); chartPlot.setTickSize(tickInterval); JRFont tickLabelFont = jrPlot.getTickLabelFont(); Integer defaultBaseFontSize = (Integer) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.BASEFONT_SIZE); Font themeTickLabelFont = getFont( (JRFont) getDefaultValue(defaultPlotPropertiesMap, ChartThemesConstants.PLOT_TICK_LABEL_FONT), tickLabelFont, defaultBaseFontSize); chartPlot.setTickLabelFont(themeTickLabelFont); // localizing the default format, can be overridden by display.getMask() chartPlot.setTickLabelFormat(NumberFormat.getInstance(getLocale())); Color tickColor = jrPlot.getTickColor() == null ? Color.BLACK : jrPlot.getTickColor(); chartPlot.setTickPaint(tickColor); int dialUnitScale = 1; Range range = convertRange(jrPlot.getDataRange()); if (range != null) { // Set the meter's range chartPlot.setRange(range); double bound = Math.max(Math.abs(range.getUpperBound()), Math.abs(range.getLowerBound())); dialUnitScale = ChartThemesUtilities.getScale(bound); if ((range.getLowerBound() == (int) range.getLowerBound() && range.getUpperBound() == (int) range.getUpperBound() && tickInterval == (int) tickInterval) || dialUnitScale > 1) { chartPlot.setTickLabelFormat( new DecimalFormat("#,##0", DecimalFormatSymbols.getInstance(getLocale()))); } else if (dialUnitScale == 1) { chartPlot.setTickLabelFormat( new DecimalFormat("#,##0.0", DecimalFormatSymbols.getInstance(getLocale()))); } else if (dialUnitScale <= 0) { chartPlot.setTickLabelFormat( new DecimalFormat("#,##0.00", DecimalFormatSymbols.getInstance(getLocale()))); } } chartPlot.setTickLabelsVisible(true); // Set all the colors we support Paint backgroundPaint = jrPlot.getOwnBackcolor() == null ? ChartThemesConstants.TRANSPARENT_PAINT : jrPlot.getOwnBackcolor(); chartPlot.setBackgroundPaint(backgroundPaint); GradientPaint gp = new GradientPaint(new Point(), Color.LIGHT_GRAY, new Point(), Color.BLACK, false); if (jrPlot.getMeterBackgroundColor() != null) { chartPlot.setDialBackgroundPaint(jrPlot.getMeterBackgroundColor()); } else { chartPlot.setDialBackgroundPaint(gp); } //chartPlot.setForegroundAlpha(1f); Paint needlePaint = jrPlot.getNeedleColor() == null ? new Color(191, 48, 0) : jrPlot.getNeedleColor(); chartPlot.setNeedlePaint(needlePaint); JRValueDisplay display = jrPlot.getValueDisplay(); if (display != null) { Color valueColor = display.getColor() == null ? Color.BLACK : display.getColor(); chartPlot.setValuePaint(valueColor); String pattern = display.getMask() != null ? display.getMask() : "#,##0.####"; if (pattern != null) chartPlot.setTickLabelFormat( new DecimalFormat(pattern, DecimalFormatSymbols.getInstance(getLocale()))); JRFont displayFont = display.getFont(); Font themeDisplayFont = getFont( (JRFont) getDefaultValue(defaultPlotPropertiesMap, ChartThemesConstants.PLOT_DISPLAY_FONT), displayFont, defaultBaseFontSize); if (themeDisplayFont != null) { chartPlot.setValueFont(themeDisplayFont); } } String label = getChart().hasProperties() ? getChart().getPropertiesMap().getProperty(DefaultChartTheme.PROPERTY_DIAL_LABEL) : null; if (label != null) { if (dialUnitScale < 0) label = new MessageFormat(label) .format(new Object[] { String.valueOf(Math.pow(10, dialUnitScale)) }); else if (dialUnitScale < 3) label = new MessageFormat(label).format(new Object[] { "1" }); else label = new MessageFormat(label) .format(new Object[] { String.valueOf((int) Math.pow(10, dialUnitScale - 2)) }); } // Set the units - this is just a string that will be shown next to the // value String units = jrPlot.getUnits() == null ? label : jrPlot.getUnits(); if (units != null && units.length() > 0) chartPlot.setUnits(units); chartPlot.setTickPaint(Color.BLACK); // Now define all of the intervals, setting their range and color List<JRMeterInterval> intervals = jrPlot.getIntervals(); if (intervals != null && intervals.size() > 0) { int size = Math.min(3, intervals.size()); int colorStep = 0; if (size > 3) colorStep = 255 / (size - 3); for (int i = 0; i < size; i++) { JRMeterInterval interval = intervals.get(i); Color color = i < 3 ? (Color) ChartThemesConstants.AEGEAN_INTERVAL_COLORS.get(i) : new Color(255 - colorStep * (i - 3), 0 + colorStep * (i - 3), 0); interval.setBackgroundColor(color); interval.setAlpha(1.0d); chartPlot.addInterval(convertInterval(interval)); } } // Actually create the chart around the plot JFreeChart jfreeChart = new JFreeChart(evaluateTextExpression(getChart().getTitleExpression()), null, chartPlot, getChart().getShowLegend() == null ? false : getChart().getShowLegend()); // Set all the generic options configureChart(jfreeChart, getPlot()); return jfreeChart; }
From source file:ec.util.chart.swing.JTimeSeriesChart.java
@Nonnull public double[] getZoom() { Range domainRange = roSubPlots.get(0).getDomainAxis().getRange(); Range rangeRange = roSubPlots.get(0).getRangeAxis().getRange(); return new double[] { domainRange.getLowerBound(), domainRange.getUpperBound(), rangeRange.getLowerBound(), rangeRange.getUpperBound() }; }
From source file:apidemo.PanScrollZoomDemo.java
/** * used for zooming/* www. jav a2s . c o m*/ * * @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:com.epiq.bitshark.ui.IVQPanel.java
public IVQPanel() { initComponents();/* w ww.j a va2 s . co m*/ initGraph(); JPanel holderPanel = new JPanel() { @Override public void paint(Graphics g) { Range newDomain = null; // x Range newRange = null; // y Range currentDomainRange = plot.getDomainAxis().getRange(); Range currentRangeRange = plot.getRangeAxis().getRange(); if (plot.getDomainAxis().isAutoRange()) { plot.getDomainAxis().setAutoRange(false); } if (plot.getRangeAxis().isAutoRange()) { plot.getRangeAxis().setAutoRange(false); } Rectangle2D dataArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea(); double width = dataArea.getWidth(); double height = dataArea.getHeight(); double domainScale = 1; double rangeScale = 1; // scale the domain values up to match the pixels if (width > height) { domainScale = width / height; double extent = currentRangeRange.getUpperBound() - currentRangeRange.getLowerBound(); newDomain = new Range(-(extent * domainScale) / 2, (extent * domainScale) / 2); } else if (height > width) { rangeScale = height / width; double extent = currentDomainRange.getUpperBound() - currentDomainRange.getLowerBound(); newRange = new Range(-(extent * rangeScale) / 2, (extent * rangeScale) / 2); } if (newDomain == null) { double extent = currentDomainRange.getUpperBound() - currentDomainRange.getLowerBound(); newDomain = new Range(-(extent) / 2, (extent) / 2); } if (newRange == null) { double extent = currentRangeRange.getUpperBound() - currentRangeRange.getLowerBound(); newRange = new Range(-(extent) / 2, (extent) / 2); } if (newDomain != null) { plot.getDomainAxis().setRange(newDomain, true, false); } if (newRange != null) { plot.getRangeAxis().setRange(newRange, true, false); } Graphics2D g2 = (Graphics2D) g.create(); super.paint(g2); g2.dispose(); } }; holderPanel.setLayout(new BorderLayout()); holderPanel.add(chartPanel, BorderLayout.CENTER); mainPanel.add(holderPanel, BorderLayout.CENTER); headerPanel.setBackgroundPainter(Common.getHeaderPainter()); chartLabel.setUI(new BasicLabelUI()); }
From source file:org.jfree.data.time.TimeSeriesCollectionTest.java
/** * This method provides a check for the bounds calculated using the * {@link DatasetUtilities#findDomainBounds(org.jfree.data.xy.XYDataset, * java.util.List, boolean)} method.//from www . ja v a2 s . co m */ @Test public void testFindDomainBounds() { TimeSeriesCollection dataset = new TimeSeriesCollection(); List visibleSeriesKeys = new java.util.ArrayList(); Range r = DatasetUtilities.findDomainBounds(dataset, visibleSeriesKeys, true); assertNull(r); TimeSeries s1 = new TimeSeries("S1"); dataset.addSeries(s1); visibleSeriesKeys.add("S1"); r = DatasetUtilities.findDomainBounds(dataset, visibleSeriesKeys, true); assertNull(r); // store the current time zone TimeZone saved = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/Paris")); s1.add(new Year(2008), 8.0); r = DatasetUtilities.findDomainBounds(dataset, visibleSeriesKeys, true); assertEquals(1199142000000.0, r.getLowerBound(), EPSILON); assertEquals(1230764399999.0, r.getUpperBound(), EPSILON); TimeSeries s2 = new TimeSeries("S2"); dataset.addSeries(s2); s2.add(new Year(2009), 9.0); s2.add(new Year(2010), 10.0); r = DatasetUtilities.findDomainBounds(dataset, visibleSeriesKeys, true); assertEquals(1199142000000.0, r.getLowerBound(), EPSILON); assertEquals(1230764399999.0, r.getUpperBound(), EPSILON); visibleSeriesKeys.add("S2"); r = DatasetUtilities.findDomainBounds(dataset, visibleSeriesKeys, true); assertEquals(1199142000000.0, r.getLowerBound(), EPSILON); assertEquals(1293836399999.0, r.getUpperBound(), EPSILON); // restore the default time zone TimeZone.setDefault(saved); }
From source file:net.sf.maltcms.chromaui.chromatogram1Dviewer.ui.panel.Chromatogram1DHeatmapViewerPanel.java
private void setViewPortAround(final double value) { Runnable r = new Runnable() { @Override/*from ww w. j a v a2 s . co m*/ public void run() { double value2 = value / 100.0d; System.out.println("ViewPort around " + value2); Range dataDomainBounds = DatasetUtilities .findDomainBounds(chartPanel.getChart().getXYPlot().getDataset()); ValueAxis domainAxis = chartPanel.getChart().getXYPlot().getDomainAxis(); double lowerBound = Math.max(dataDomainBounds.getLowerBound(), dataDomainBounds.getLowerBound() + (value / 99.0d * dataDomainBounds.getLength())); double upperBound = Math.min(dataDomainBounds.getUpperBound(), dataDomainBounds.getLowerBound() + ((value + 10.0d) / 99.0d * dataDomainBounds.getLength())); domainAxis.setRange(lowerBound, upperBound); } }; SwingUtilities.invokeLater(r); }
From source file:com.rapidminer.gui.plotter.charts.SeriesChartPlotter.java
private void setYAxisRange(NumberAxis axis) { Range range = getRangeForName(VALUEAXIS_LABEL); if (range == null) { for (int c = 0; c < this.dataTable.getNumberOfColumns(); c++) { if (this.columns[c] || c == getAxis(0) || c == getAxis(1)) { if (range == null) { range = getRangeForDimension(c); } else { Range newRange = getRangeForDimension(c); if (newRange != null) { range = new Range( MathFunctions.robustMin(range.getLowerBound(), newRange.getLowerBound()), MathFunctions.robustMax(range.getUpperBound(), newRange.getUpperBound())); }//w w w .j a va 2s. c om } } } } if (range != null) { axis.setRange(range); } else { axis.setAutoRange(true); axis.setAutoRangeStickyZero(false); axis.setAutoRangeIncludesZero(false); } }
From source file:org.eurocarbdb.application.glycoworkbench.plugin.PeakListChartPanel.java
public void updateChart() { // auto zoom//from w w w . j av a2s . c o m if (theDocument.size() > 0) { Range mz_range = thePlot.getDomainAxis().getRange(); // update data double mz_toll = screenToDataX(1.); double[][] data = theDocument.getData(mz_range.getLowerBound(), mz_range.getUpperBound()); // update visible data and compute intensity range visibleData.clear(); double min_int = (data[0].length > 0) ? data[1][0] : 0.; double max_int = (data[0].length > 0) ? data[1][0] : 0.; for (int i = 0; i < data[0].length; i++) { min_int = Math.min(min_int, data[1][i]); max_int = Math.max(max_int, data[1][i]); visibleData.put(data[0][i], data[1][i]); } //Range new_int_range = new Range(min_int,max_int); Range new_int_range = new Range(0., max_int); // make space for annotations Rectangle2D data_area = theChartPanel.getScreenDataArea(); if (data_area.getHeight() > 0) new_int_range = Range.expand(new_int_range, 0., 12. / data_area.getHeight()); // resize y axis thePlot.getRangeAxis().setRange(new_int_range); // reload dataset theDataset.removeSeries("intensities"); theDataset.addSeries("intensities", data); } else { thePlot.getRangeAxis().setRange(new Range(0., 1.)); theDataset.removeSeries("intensities"); } // restore annotation shapes showSelection(); }