List of usage examples for org.jfree.data Range getLowerBound
public double getLowerBound()
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);/*from w ww . j a v a2 s . c o m*/ 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 .ja v a 2 s . c o m 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.maltcms.chromaui.chromatogram1Dviewer.ui.panel.Chromatogram1DHeatmapViewerPanel.java
private void setViewPortAround(final double value) { Runnable r = new Runnable() { @Override/*from w w w . j a v a 2 s .c o 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:net.sf.fspdfs.chartthemes.spring.AegeanChartTheme.java
/** * *//*from ww w.j a v a 2 s . com*/ protected JFreeChart createDialChart() throws JRException { JRMeterPlot jrPlot = (JRMeterPlot) getPlot(); // get data for diagrams DialPlot dialPlot = new DialPlot(); if (getDataset() != null) { dialPlot.setDataset((ValueDataset) getDataset()); } StandardDialFrame dialFrame = new StandardDialFrame(); dialFrame.setForegroundPaint(Color.BLACK); dialFrame.setBackgroundPaint(Color.BLACK); dialFrame.setStroke(new BasicStroke(1f)); dialPlot.setDialFrame(dialFrame); DialBackground db = new DialBackground(ChartThemesConstants.TRANSPARENT_PAINT); dialPlot.setBackground(db); ScaledDialScale scale = null; int dialUnitScale = 1; Range range = convertRange(jrPlot.getDataRange()); if (range != null) { double bound = Math.max(Math.abs(range.getUpperBound()), Math.abs(range.getLowerBound())); dialUnitScale = ChartThemesUtilities.getScale(bound); double lowerBound = ChartThemesUtilities.getTruncatedValue(range.getLowerBound(), dialUnitScale); double upperBound = ChartThemesUtilities.getTruncatedValue(range.getUpperBound(), dialUnitScale); scale = new ScaledDialScale(lowerBound, upperBound, 210, -240, (upperBound - lowerBound) / 6, 1); if ((lowerBound == (int) lowerBound && upperBound == (int) upperBound && scale.getMajorTickIncrement() == (int) scale.getMajorTickIncrement()) || dialUnitScale > 1) { scale.setTickLabelFormatter(new DecimalFormat("#,##0")); } else if (dialUnitScale == 1) { scale.setTickLabelFormatter(new DecimalFormat("#,##0.0")); } else if (dialUnitScale <= 0) { scale.setTickLabelFormatter(new DecimalFormat("#,##0.00")); } } else { scale = new ScaledDialScale(); } scale.setTickRadius(0.9); scale.setTickLabelOffset(0.16); 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); scale.setTickLabelFont(themeTickLabelFont); scale.setMajorTickStroke(new BasicStroke(1f)); scale.setMinorTickStroke(new BasicStroke(0.7f)); scale.setMajorTickPaint(Color.BLACK); scale.setMinorTickPaint(Color.BLACK); scale.setTickLabelsVisible(true); scale.setFirstTickLabelVisible(true); dialPlot.addScale(0, scale); List 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 = (JRMeterInterval) intervals.get(i); Range intervalRange = convertRange(interval.getDataRange()); double intervalLowerBound = ChartThemesUtilities.getTruncatedValue(intervalRange.getLowerBound(), dialUnitScale); double intervalUpperBound = ChartThemesUtilities.getTruncatedValue(intervalRange.getUpperBound(), dialUnitScale); Color color = i < 3 ? (Color) ChartThemesConstants.AEGEAN_INTERVAL_COLORS.get(i) : new Color(255 - colorStep * (i - 3), 0 + colorStep * (i - 3), 0); ScaledDialRange dialRange = new ScaledDialRange(intervalLowerBound, intervalUpperBound, interval.getBackgroundColor() == null ? color : interval.getBackgroundColor(), 15f); dialRange.setInnerRadius(0.5); dialRange.setOuterRadius(0.5); dialPlot.addLayer(dialRange); } } JRValueDisplay display = jrPlot.getValueDisplay(); String displayVisibility = display != null && getChart().hasProperties() ? getChart().getPropertiesMap().getProperty(DefaultChartTheme.PROPERTY_DIAL_VALUE_DISPLAY_VISIBLE) : "false"; if (Boolean.valueOf(displayVisibility).booleanValue()) { ScaledDialValueIndicator dvi = new ScaledDialValueIndicator(0, dialUnitScale); dvi.setBackgroundPaint(ChartThemesConstants.TRANSPARENT_PAINT); // dvi.setFont(JRFontUtil.getAwtFont(jrFont).deriveFont(10f).deriveFont(Font.BOLD)); dvi.setOutlinePaint(ChartThemesConstants.TRANSPARENT_PAINT); dvi.setPaint(Color.WHITE); String pattern = display.getMask() != null ? display.getMask() : "#,##0.####"; if (pattern != null) dvi.setNumberFormat(new DecimalFormat(pattern)); dvi.setRadius(0.15); dvi.setValueAnchor(RectangleAnchor.CENTER); dvi.setTextAnchor(TextAnchor.CENTER); //dvi.setTemplateValue(Double.valueOf(getDialTickValue(dialPlot.getValue(0),dialUnitScale))); dialPlot.addLayer(dvi); } 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)) }); JRFont displayFont = jrPlot.getValueDisplay().getFont(); Font themeDisplayFont = getFont( (JRFont) getDefaultValue(defaultPlotPropertiesMap, ChartThemesConstants.PLOT_DISPLAY_FONT), displayFont, defaultBaseFontSize); String[] textLines = label.split("\\n"); for (int i = 0; i < textLines.length; i++) { DialTextAnnotation dialAnnotation = new DialTextAnnotation(textLines[i]); dialAnnotation.setFont(themeDisplayFont); dialAnnotation.setPaint(Color.BLACK); dialAnnotation.setRadius(Math.sin(Math.PI / 6.0) + i / 10.0); dialAnnotation.setAnchor(TextAnchor.CENTER); dialPlot.addLayer(dialAnnotation); } } DialPointer needle = new ScaledDialPointer(dialUnitScale, 0.047); needle.setVisible(true); needle.setRadius(0.7); dialPlot.addLayer(needle); DialCap cap = new DialCap(); cap.setRadius(0.05); cap.setFillPaint(Color.BLACK); cap.setOutlinePaint(ChartThemesConstants.TRANSPARENT_PAINT); dialPlot.setCap(cap); JFreeChart jfreeChart = new JFreeChart((String) evaluateExpression(getChart().getTitleExpression()), null, dialPlot, getChart().getShowLegend() == null ? false : getChart().getShowLegend().booleanValue()); // Set all the generic options configureChart(jfreeChart, getPlot()); jfreeChart.setBackgroundPaint(ChartThemesConstants.TRANSPARENT_PAINT); jfreeChart.setBorderVisible(false); return jfreeChart; }
From source file:gov.llnl.lc.infiniband.opensm.plugin.gui.chart.PortHeatMapWorker.java
protected Void doInBackground() throws Exception { // this is a SwingWorker thread from its pool, give it a recognizable name Thread.currentThread().setName("PortHeatMapWorker"); JFreeChart Chart = PlotPanel.getHeatChart(); logger.info("Worker Building HeatMapPlot"); MessageManager.getInstance()// www .jav a 2s . c o m .postMessage(new SmtMessage(SmtMessageType.SMT_MSG_INFO, "Worker Building HeatMapPlot")); PortHeatMapDataSet pHeatMap = null; if (UseService) { SMT_UpdateService updateService = SMT_UpdateService.getInstance(); History = updateService.getCollection(); if (IncludedNodes != null) pHeatMap = new PortHeatMapDataSet(History, IncludedNodes); else pHeatMap = new PortHeatMapDataSet(History, IncludedDepths); } else if (History != null) { if (IncludedNodes != null) pHeatMap = new PortHeatMapDataSet(History, IncludedNodes); else pHeatMap = new PortHeatMapDataSet(History, IncludedDepths); } else { // FIXME - eliminate this, for test purposes only if (IncludedNodes != null) pHeatMap = new PortHeatMapDataSet("%h/scripts/OsmScripts/SmtScripts/sierra3H.his", IncludedNodes); else pHeatMap = new PortHeatMapDataSet("%h/scripts/OsmScripts/SmtScripts/sierra3H.his", IncludedDepths); } // logger.fine("Finished creating dataset"); // logger.fine("Max X: " + pHeatMap.getMaximumXValue()); // logger.fine("Max Y: " + pHeatMap.getMaximumYValue()); // logger.fine("Max Z: " + pHeatMap.getMaximumZValue()); // // if any of these "maximum" values are illegal, stop here and return null if (!pHeatMap.isValid()) { logger.severe("Invalid HeatMap, check OMS Collection or Depth filter (empty or null)"); MessageManager.getInstance().postMessage(new SmtMessage(SmtMessageType.SMT_MSG_SEVERE, "Invalid HeatMap, check OMS Collection or Depth filter (empty or null)")); PlotPanel.setHeatMapDataSet(null); return null; } PlotPanel.setHeatMapDataSet(pHeatMap); Range fixedXRange = new Range(0, pHeatMap.getMaximumXValue()); // time # Range fixedYRange = new Range(0, pHeatMap.getMaximumYValue()); // port # Range fixedZRange = new Range(0, pHeatMap.getMaximumZValue()); // % Util // there are 3 valid paint scales, 0, 1, & 2 LookupPaintScale paintScale = PaintScaleFactory.getLookupPaintScale(1, 0, fixedZRange.getUpperBound(), fixedZRange.getUpperBound()); ValueAxis paintAxis = PaintScaleFactory.getPaintScaleAxis(0, fixedZRange.getUpperBound(), PortHeatMapPlotPanel.UtilizationAxisLabel); BufferedImage image = HeatMapUtilities.createHeatMapImage(pHeatMap, paintScale); XYDataImageAnnotation ann = new XYDataImageAnnotation(image, fixedXRange.getLowerBound(), fixedYRange.getLowerBound(), fixedXRange.getUpperBound(), fixedYRange.getUpperBound(), true); XYPlot plot = (XYPlot) Chart.getPlot(); plot.getRenderer().addAnnotation(ann, Layer.BACKGROUND); // finally, show the heatmap PaintScaleLegend psLegend = new PaintScaleLegend(paintScale, paintAxis); psLegend.setMargin(new RectangleInsets(3, 40, 3, 10)); psLegend.setPosition(RectangleEdge.TOP); // location (within NORTH) of // heatmap legend psLegend.setAxisOffset(4.0); psLegend.setFrame(new BlockBorder(Color.GRAY)); Chart.addSubtitle(psLegend); // fix the sliders ranges, and set them for the middle if ((pHeatMap != null) && (PlotPanel != null)) { PlotPanel.getTimeSlider().setMinimum((int) fixedXRange.getLowerBound()); PlotPanel.getTimeSlider().setMaximum((int) fixedXRange.getUpperBound()); PlotPanel.getTimeSlider().setValue((int) fixedXRange.getCentralValue()); PlotPanel.getPortSlider().setMinimum((int) fixedYRange.getLowerBound()); PlotPanel.getPortSlider().setMaximum((int) fixedYRange.getUpperBound()); PlotPanel.getPortSlider().setValue((int) fixedYRange.getCentralValue()); HeatMapDepthPanel hmdp = new HeatMapDepthPanel(pHeatMap); PlotPanel.replaceDepthPanel(hmdp); } return null; }
From source file:apidemo.PanScrollZoomDemo.java
/** * used for zooming/*w w w .j av a2s . c om*/ * * @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:net.sf.jasperreports.chartthemes.spring.AegeanChartTheme.java
@Override protected JFreeChart createDialChart() throws JRException { JRMeterPlot jrPlot = (JRMeterPlot) getPlot(); // get data for diagrams DialPlot dialPlot = new DialPlot(); if (getDataset() != null) { dialPlot.setDataset((ValueDataset) getDataset()); }/*from w w w .ja v a2 s .c o m*/ StandardDialFrame dialFrame = new StandardDialFrame(); dialFrame.setForegroundPaint(Color.BLACK); dialFrame.setBackgroundPaint(Color.BLACK); dialFrame.setStroke(new BasicStroke(1f)); dialPlot.setDialFrame(dialFrame); DialBackground db = new DialBackground(ChartThemesConstants.TRANSPARENT_PAINT); dialPlot.setBackground(db); ScaledDialScale scale = null; int dialUnitScale = 1; Range range = convertRange(jrPlot.getDataRange()); if (range != null) { double bound = Math.max(Math.abs(range.getUpperBound()), Math.abs(range.getLowerBound())); dialUnitScale = ChartThemesUtilities.getScale(bound); double lowerBound = ChartThemesUtilities.getTruncatedValue(range.getLowerBound(), dialUnitScale); double upperBound = ChartThemesUtilities.getTruncatedValue(range.getUpperBound(), dialUnitScale); int tickCount = jrPlot.getTickCount() != null && jrPlot.getTickCount() > 1 ? jrPlot.getTickCount() : 7; scale = new ScaledDialScale(lowerBound, upperBound, 210, -240, (upperBound - lowerBound) / (tickCount - 1), 1); if ((lowerBound == (int) lowerBound && upperBound == (int) upperBound && scale.getMajorTickIncrement() == (int) scale.getMajorTickIncrement()) || dialUnitScale > 1) { scale.setTickLabelFormatter( new DecimalFormat("#,##0", DecimalFormatSymbols.getInstance(getLocale()))); } else if (dialUnitScale == 1) { scale.setTickLabelFormatter( new DecimalFormat("#,##0.0", DecimalFormatSymbols.getInstance(getLocale()))); } else if (dialUnitScale <= 0) { scale.setTickLabelFormatter( new DecimalFormat("#,##0.00", DecimalFormatSymbols.getInstance(getLocale()))); } else { // localizing the default tick label formatter scale.setTickLabelFormatter( new DecimalFormat("0.0", DecimalFormatSymbols.getInstance(getLocale()))); } } else { scale = new ScaledDialScale(); // localizing the default tick label formatter scale.setTickLabelFormatter(new DecimalFormat("0.0", DecimalFormatSymbols.getInstance(getLocale()))); } scale.setTickRadius(0.9); scale.setTickLabelOffset(0.16); 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); scale.setTickLabelFont(themeTickLabelFont); scale.setMajorTickStroke(new BasicStroke(1f)); scale.setMinorTickStroke(new BasicStroke(0.7f)); scale.setMajorTickPaint(Color.BLACK); scale.setMinorTickPaint(Color.BLACK); scale.setTickLabelsVisible(true); scale.setFirstTickLabelVisible(true); dialPlot.addScale(0, scale); 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); Range intervalRange = convertRange(interval.getDataRange()); double intervalLowerBound = ChartThemesUtilities.getTruncatedValue(intervalRange.getLowerBound(), dialUnitScale); double intervalUpperBound = ChartThemesUtilities.getTruncatedValue(intervalRange.getUpperBound(), dialUnitScale); Color color = i < 3 ? (Color) ChartThemesConstants.AEGEAN_INTERVAL_COLORS.get(i) : new Color(255 - colorStep * (i - 3), 0 + colorStep * (i - 3), 0); ScaledDialRange dialRange = new ScaledDialRange(intervalLowerBound, intervalUpperBound, interval.getBackgroundColor() == null ? color : interval.getBackgroundColor(), 15f); dialRange.setInnerRadius(0.5); dialRange.setOuterRadius(0.5); dialPlot.addLayer(dialRange); } } JRValueDisplay display = jrPlot.getValueDisplay(); String displayVisibility = display != null && getChart().hasProperties() ? getChart().getPropertiesMap().getProperty(DefaultChartTheme.PROPERTY_DIAL_VALUE_DISPLAY_VISIBLE) : "false"; if (Boolean.valueOf(displayVisibility)) { ScaledDialValueIndicator dvi = new ScaledDialValueIndicator(0, dialUnitScale); dvi.setBackgroundPaint(ChartThemesConstants.TRANSPARENT_PAINT); // dvi.setFont(JRFontUtil.getAwtFont(jrFont).deriveFont(10f).deriveFont(Font.BOLD)); dvi.setOutlinePaint(ChartThemesConstants.TRANSPARENT_PAINT); dvi.setPaint(Color.WHITE); String pattern = display.getMask() != null ? display.getMask() : "#,##0.####"; if (pattern != null) dvi.setNumberFormat(new DecimalFormat(pattern, DecimalFormatSymbols.getInstance(getLocale()))); dvi.setRadius(0.15); dvi.setValueAnchor(RectangleAnchor.CENTER); dvi.setTextAnchor(TextAnchor.CENTER); //dvi.setTemplateValue(Double.valueOf(getDialTickValue(dialPlot.getValue(0),dialUnitScale))); dialPlot.addLayer(dvi); } 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)) }); JRFont displayFont = jrPlot.getValueDisplay().getFont(); Font themeDisplayFont = getFont( (JRFont) getDefaultValue(defaultPlotPropertiesMap, ChartThemesConstants.PLOT_DISPLAY_FONT), displayFont, defaultBaseFontSize); String[] textLines = label.split("\\n"); for (int i = 0; i < textLines.length; i++) { DialTextAnnotation dialAnnotation = new DialTextAnnotation(textLines[i]); dialAnnotation.setFont(themeDisplayFont); dialAnnotation.setPaint(Color.BLACK); dialAnnotation.setRadius(Math.sin(Math.PI / 6.0) + i / 10.0); dialAnnotation.setAnchor(TextAnchor.CENTER); dialPlot.addLayer(dialAnnotation); } } DialPointer needle = new ScaledDialPointer(dialUnitScale, 0.047); needle.setVisible(true); needle.setRadius(0.7); dialPlot.addLayer(needle); DialCap cap = new DialCap(); cap.setRadius(0.05); cap.setFillPaint(Color.BLACK); cap.setOutlinePaint(ChartThemesConstants.TRANSPARENT_PAINT); dialPlot.setCap(cap); JFreeChart jfreeChart = new JFreeChart(evaluateTextExpression(getChart().getTitleExpression()), null, dialPlot, getChart().getShowLegend() == null ? false : getChart().getShowLegend()); // Set all the generic options configureChart(jfreeChart, getPlot()); jfreeChart.setBackgroundPaint(ChartThemesConstants.TRANSPARENT_PAINT); jfreeChart.setBorderVisible(false); return jfreeChart; }
From source file:net.sf.fspdfs.chartthemes.spring.AegeanChartTheme.java
/** * *///from ww w.j a v a 2s .c om 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: 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().intValue(); // 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().doubleValue(); 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); 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")); } else if (dialUnitScale == 1) { chartPlot.setTickLabelFormat(new DecimalFormat("#,##0.0")); } else if (dialUnitScale <= 0) { chartPlot.setTickLabelFormat(new DecimalFormat("#,##0.00")); } } 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)); 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 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 = (JRMeterInterval) 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(new Double(1.0)); chartPlot.addInterval(convertInterval(interval)); } } // Actually create the chart around the plot JFreeChart jfreeChart = new JFreeChart((String) evaluateExpression(getChart().getTitleExpression()), null, chartPlot, getChart().getShowLegend() == null ? false : getChart().getShowLegend().booleanValue()); // Set all the generic options configureChart(jfreeChart, getPlot()); return jfreeChart; }
From source file:apidemo.PanScrollZoomDemo.java
/** * Handles a {@link ChartChangeEvent}./*from w w w .ja va 2 s .c om*/ * * @param event the event. */ public void chartChanged(final ChartChangeEvent event) { try { if (event.getChart() == null) { return; } final BoundedRangeModel scrollBarModel = this.scrollBar.getModel(); if (scrollBarModel == null) { return; } boolean chartIsZoomed = false; final Plot plot = event.getChart().getPlot(); if (plot instanceof XYPlot) { final XYPlot hvp = (XYPlot) plot; final ValueAxis xAxis = hvp.getDomainAxis(); final Range xAxisRange = xAxis.getRange(); // avoid recursion scrollBarModel.removeChangeListener(this); final int low = (int) (xAxisRange.getLowerBound() * this.scrollFactor); scrollBarModel.setValue(low); final int ext = (int) (xAxisRange.getUpperBound() * this.scrollFactor - low); scrollBarModel.setExtent(ext); // restore scrollBarModel.addChangeListener(this); // check if zoomed horizontally //Range hdr = hvp.getHorizontalDataRange(xAxis); final Range hdr = hvp.getDataRange(xAxis); final double len = hdr == null ? 0 : hdr.getLength(); chartIsZoomed |= xAxisRange.getLength() < len; } if (!chartIsZoomed && plot instanceof XYPlot) { // check if zoomed vertically final XYPlot vvp = (XYPlot) plot; ValueAxis yAxis = vvp.getRangeAxis(); if (yAxis != null) { chartIsZoomed = yAxis.getLowerBound() > this.primYMinMax[0] || yAxis.getUpperBound() < this.primYMinMax[1]; // right y-axis if (!chartIsZoomed && plot instanceof XYPlot) { final XYPlot xyPlot = (XYPlot) plot; yAxis = xyPlot.getRangeAxis(1); if (yAxis != null) { chartIsZoomed = yAxis.getLowerBound() > this.secondYMinMax[0] || yAxis.getUpperBound() < this.secondYMinMax[1]; } } } } // enable "zoom-out-buttons" if chart is zoomed // otherwise disable them this.panButton.setEnabled(chartIsZoomed); this.zoomOutButton.setEnabled(chartIsZoomed); this.fitButton.setEnabled(chartIsZoomed); this.scrollBar.setEnabled(chartIsZoomed); if (!chartIsZoomed) { setPanMode(false); this.zoomButton.setSelected(true); } } catch (Exception e) { e.printStackTrace(); } }
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 v a2 s .c o m*/ } } } } if (range != null) { axis.setRange(range); } else { axis.setAutoRange(true); axis.setAutoRangeStickyZero(false); axis.setAutoRangeIncludesZero(false); } }