List of usage examples for org.jfree.chart ChartRenderingInfo getChartArea
public Rectangle2D getChartArea()
From source file:net.sf.mzmine.chartbasics.ChartLogicsFX.java
/** * /*w ww. j a va2s . c om*/ * Domain and Range axes need to share the same unit (e.g. mm) * * @param myChart * @return */ public static double calcWidthToHeight(ChartViewer myChart, double chartHeight) { makeChartResizable(myChart); 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 realPH = chartHeight - titleHeight; // 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 realPW = realPH / y.getLength() * x.getLength(); double width = realPW + titleWidth; return width; }
From source file:net.sf.mzmine.chartbasics.ChartLogicsFX.java
/** * Returns dimensions for limiting factor width or height * /* w ww . j a v a 2s. c o m*/ * @param myChart * @return */ public static Dimension calcMaxSize(ChartViewer myChart, double chartWidth, double chartHeight) { makeChartResizable(myChart); // paint on a ghost panel 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(); // calculatig width for max height // calc right plot size with axis dim. // real plot width is given by factor; double realPH = chartHeight - titleHeight; // 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 realPW = realPH / y.getLength() * x.getLength(); double width = realPW + titleWidth; // if width is higher than given chartWidth then calc height for chartWidth if (width > chartWidth) { // calc right plot size with axis dim. // real plot width is given by factor; realPW = chartWidth - titleWidth; // real plot height can be calculated by realPH = realPW / x.getLength() * y.getLength(); double height = realPH + titleHeight; // Return size return new Dimension((int) chartWidth, (int) height); } else { // Return size return new Dimension((int) width, (int) chartHeight); } }
From source file:net.sf.mzmine.chartbasics.ChartLogics.java
/** * /* w ww . ja v a 2 s . com*/ * Domain and Range axes need to share the same unit (e.g. mm) * * @param myChart * @return */ public static double calcWidthToHeight(ChartPanel myChart, double chartHeight) { makeChartResizable(myChart); // paint on a ghost panel JPanel parent = (JPanel) myChart.getParent(); JPanel p = new JPanel(); p.removeAll(); p.add(myChart, BorderLayout.CENTER); p.setBounds(myChart.getBounds()); myChart.paintImmediately(myChart.getBounds()); p.removeAll(); parent.add(myChart); 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 realPH = chartHeight - titleHeight; // 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 realPW = realPH / y.getLength() * x.getLength(); double width = realPW + titleWidth; return width; }
From source file:net.sf.mzmine.chartbasics.ChartLogicsFX.java
/** * Calculates the size of a chart for a given fixed plot width and height * /*from w w w. j a v a 2 s .c o m*/ * @param chart * @param plotWidth * @return */ public static Dimension calcSizeForPlotSize(ChartViewer myChart, double plotWidth, double plotHeight, int iterations) { makeChartResizable(myChart); // estimate plotwidth / height double estimatedChartWidth = plotWidth + 200; double estimatedChartHeight = plotHeight + 200; double lastW = estimatedChartWidth; double lastH = estimatedChartHeight; // paint and get closer try { for (int i = 0; i < iterations; i++) { // paint on ghost panel with estimated height (if copy panel==true) myChart.getCanvas().setWidth((int) estimatedChartWidth); myChart.getCanvas().setHeight((int) estimatedChartHeight); myChart.getCanvas().draw(); // rendering info 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 width and height estimatedChartWidth = estimatedChartWidth - dataArea.getWidth() + plotWidth; estimatedChartHeight = estimatedChartHeight - dataArea.getHeight() + plotHeight; if ((int) lastW == (int) estimatedChartWidth && (int) lastH == (int) estimatedChartHeight) break; else { lastW = estimatedChartWidth; lastH = estimatedChartHeight; } } } catch (Exception ex) { ex.printStackTrace(); } return new Dimension((int) estimatedChartWidth, (int) estimatedChartHeight); }
From source file:net.sf.mzmine.chartbasics.ChartLogics.java
/** * Returns dimensions for limiting factor width or height * //from w w w .ja v a2 s . c om * @param myChart * @return */ public static Dimension calcMaxSize(ChartPanel myChart, double chartWidth, double chartHeight) { makeChartResizable(myChart); // paint on a ghost panel JPanel parent = (JPanel) myChart.getParent(); JPanel p = new JPanel(); p.removeAll(); p.add(myChart, BorderLayout.CENTER); p.setBounds(myChart.getBounds()); myChart.paintImmediately(myChart.getBounds()); p.removeAll(); parent.add(myChart); 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(); // calculatig width for max height // calc right plot size with axis dim. // real plot width is given by factor; double realPH = chartHeight - titleHeight; // 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 realPW = realPH / y.getLength() * x.getLength(); double width = realPW + titleWidth; // if width is higher than given chartWidth then calc height for chartWidth if (width > chartWidth) { // calc right plot size with axis dim. // real plot width is given by factor; realPW = chartWidth - titleWidth; // real plot height can be calculated by realPH = realPW / x.getLength() * y.getLength(); double height = realPH + titleHeight; // Return size return new Dimension((int) chartWidth, (int) height); } else { // Return size return new Dimension((int) width, (int) chartHeight); } }
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 a va 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 size of a chart for a given fixed plot width and height * //from ww w . j a va 2 s . c om * @param chart * @param plotWidth * @return */ public static Dimension calcSizeForPlotSize(ChartPanel myChart, double plotWidth, double plotHeight, int iterations) { makeChartResizable(myChart); // estimate plotwidth / height double estimatedChartWidth = plotWidth + 200; double estimatedChartHeight = plotHeight + 200; double lastW = estimatedChartWidth; double lastH = estimatedChartHeight; // paint and get closer try { for (int i = 0; i < iterations; i++) { // paint on ghost panel with estimated height (if copy panel==true) myChart.setSize((int) estimatedChartWidth, (int) estimatedChartHeight); myChart.paintImmediately(myChart.getBounds()); // rendering info 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 width and height estimatedChartWidth = estimatedChartWidth - dataArea.getWidth() + plotWidth; estimatedChartHeight = estimatedChartHeight - dataArea.getHeight() + plotHeight; if ((int) lastW == (int) estimatedChartWidth && (int) lastH == (int) estimatedChartHeight) break; else { lastW = estimatedChartWidth; lastH = estimatedChartHeight; } } } catch (Exception ex) { ex.printStackTrace(); } return new Dimension((int) estimatedChartWidth, (int) estimatedChartHeight); }
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)/*from w w w.ja v a 2s .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:com.projity.pm.graphic.chart.TimeChartPanel.java
/** * Gets space used by legend and headers if any * /* w w w.j av a2 s . c o m*/ * @return */ public double getNonPlotHeight() { ChartRenderingInfo info = getChartRenderingInfo(); return info.getChartArea().getHeight() - info.getPlotInfo().getDataArea().getHeight(); }
From source file:net.sourceforge.processdash.ui.web.CGIChartBase.java
private void writeImageHtml(int width, int height, int imgID, ChartRenderingInfo info) throws IOException { String tooltip = getParameter("tooltip"); if (!StringUtils.hasValue(tooltip)) tooltip = resources.getHTML("More_Detail_Here_Instruction"); String href = getParameter("href"); if (StringUtils.hasValue(href)) { // create a copy of the entity collection, and place an entity for // the entire chart at the beginning of the list. This will // make it appear last in the image map (which is important, // because browsers process the image map areas in the order that // they appear; having the entire chart area listed first would // obscure all of the other image map areas). EntityCollection entities = new StandardEntityCollection(); entities.add(new ChartEntity(info.getChartArea(), tooltip, href)); if (info.getEntityCollection() != null) entities.addAll(info.getEntityCollection()); // Next: most of our chart entities will not have URLs. URL values // don't inherit in the imagemap, so if we want the entire image // to have a single URL, we need to assign that URL to every // area in the chart. for (Iterator i = entities.iterator(); i.hasNext();) { ChartEntity ce = (ChartEntity) i.next(); // check for no-op chart entity - these won't appear in the // image map anyway, so they don't need to be adjusted if (ce.getToolTipText() == null && ce.getURLText() == null) continue; // for other entities, add a tooltip and a URL as needed. if (!StringUtils.hasValue(ce.getToolTipText())) ce.setToolTipText(tooltip); if (!StringUtils.hasValue(ce.getURLText())) ce.setURLText(href);/*w w w.j a v a2s . c o m*/ } // install our modified version of the entity collection into // the chart info object, so it will be used when generating // the image map later. info.setEntityCollection(entities); } // write the image tag out.write("<img width=\"" + width + "\" height=\"" + height + "\" src=\"/reports/pngCache?id=" + imgID + "\" usemap=\"#IMG" + imgID + '"'); // imagemaps have hyperlink borders by default, even if we don't // have a URL we're pointing to. Turn that border off. if (!StringUtils.hasValue(href) || parameters.containsKey("noBorder")) out.write(" border=\"0\""); // Our client might want to add attributes to the image tag. Look // through the query parameters we received for arbitrary attributes // starting with the prefix "img", and copy them into the tag. for (Iterator i = parameters.entrySet().iterator(); i.hasNext();) { Map.Entry e = (Map.Entry) i.next(); String attrName = (String) e.getKey(); if (attrName.startsWith("img") && !attrName.endsWith("_ALL")) { out.write(" " + attrName.substring(3) + "=\""); out.write(HTMLUtils.escapeEntities(e.getValue().toString())); out.write('"'); } } out.write(">"); // finally, write the image map. Note that we have to strip line // break characters from the resulting HTML, otherwise firefox seems // to decide that the <map> tag actually takes up space on the page String imageMapHtml = ImageMapUtilities.getImageMap("IMG" + imgID, info, getToolTipGenerator(tooltip), new StandardURLTagFragmentGenerator()); for (int i = 0; i < imageMapHtml.length(); i++) { char c = imageMapHtml.charAt(i); if (c != '\r' && c != '\n') out.write(c); } out.flush(); }