|
[HepData-svn] r1305 - in trunk: hepdata-model/src/main/java/cedar/hepdata/model hepdata-webapp/src/main/java/cedar/hepdata/webapp/plotblackhole at projects.hepforge.org blackhole at projects.hepforge.orgFri Nov 6 12:09:24 GMT 2009
Author: whalley Date: Fri Nov 6 12:09:24 2009 New Revision: 1305 Log: fixes for negative log pplotting Modified: trunk/hepdata-model/src/main/java/cedar/hepdata/model/XAxis.java trunk/hepdata-model/src/main/java/cedar/hepdata/model/YAxis.java trunk/hepdata-webapp/src/main/java/cedar/hepdata/webapp/plot/Plotter.java Modified: trunk/hepdata-model/src/main/java/cedar/hepdata/model/XAxis.java ============================================================================== --- trunk/hepdata-model/src/main/java/cedar/hepdata/model/XAxis.java Thu Nov 5 15:53:13 2009 (r1304) +++ trunk/hepdata-model/src/main/java/cedar/hepdata/model/XAxis.java Fri Nov 6 12:09:24 2009 (r1305) @@ -223,6 +223,14 @@ return rtn; } + public Double getMinPositiveValue() { + Double rtn = Double.MAX_VALUE; + for (Bin b : getBins()) { + if(b.getLowValue() > 0.0) rtn = Math.min(rtn, b.getLowValue()); + } + return rtn; + } + public Double getMaxValue() { Double rtn = -Double.MAX_VALUE; Modified: trunk/hepdata-model/src/main/java/cedar/hepdata/model/YAxis.java ============================================================================== --- trunk/hepdata-model/src/main/java/cedar/hepdata/model/YAxis.java Thu Nov 5 15:53:13 2009 (r1304) +++ trunk/hepdata-model/src/main/java/cedar/hepdata/model/YAxis.java Fri Nov 6 12:09:24 2009 (r1305) @@ -400,7 +400,16 @@ } - public Double getMaxValue() { + public Double getMinPositiveValue() { + Double rtn = Double.MAX_VALUE; + for (Point p : getPoints()) { + if(p.getValue()-p.getQuadCombinedMinusError() > 0.0) rtn = Math.min(rtn, p.getValue()-p.getQuadCombinedMinusError()); + } + return rtn; + } + + + public Double getMaxValue() { Double rtn = -Double.MAX_VALUE; for (Point p : getPoints()) { rtn = Math.max(rtn, p.getValue()+p.getQuadCombinedPlusError()); Modified: trunk/hepdata-webapp/src/main/java/cedar/hepdata/webapp/plot/Plotter.java ============================================================================== --- trunk/hepdata-webapp/src/main/java/cedar/hepdata/webapp/plot/Plotter.java Thu Nov 5 15:53:13 2009 (r1304) +++ trunk/hepdata-webapp/src/main/java/cedar/hepdata/webapp/plot/Plotter.java Fri Nov 6 12:09:24 2009 (r1305) @@ -48,6 +48,7 @@ // Work out display x range String xlabel = x.getHeader(); Double xlow = x.getMinValue(); + Double xlowpos = x.getMinPositiveValue(); Double xhigh = x.getMaxValue(); Double xrange = xhigh - xlow; if (xrange > 0) { @@ -57,20 +58,23 @@ xlow *= 0.9; xhigh *= 1.1; } +// Double xrangepos = xhigh - xlow; +// if (xrangepos > 0) { +// xlowpos -= 0.05 * xrangepos; +// } else { +// xlowpos *= 0.9; +// } - // Work out y range and add series + // Work out y range String ylabel = null; Double ylow = Double.MAX_VALUE; + Double ylowpos = Double.MAX_VALUE; Double yhigh = -Double.MAX_VALUE; for (YAxis y : ys) { ylow = Math.min(ylow, y.getMinValue()); - yhigh = Math.max(ylow, y.getMaxValue()); + ylowpos = Math.min(ylowpos,y.getMinPositiveValue()); + yhigh = Math.max(yhigh, y.getMaxValue()); ylabel = y.getHeader(); - XYIntervalSeries series = getDataSeries(x, y, xscale, yscale); - series.setKey("Dataset " + x.getDataset().getId().toString() + - ", x-axis " + x.getId().toString() + - ", y-axis " + y.getId().toString()); - allseries.addSeries(series); } // Expand y range for viewing pleasure ;) @@ -82,30 +86,54 @@ ylow *= 0.9; yhigh *= 1.1; } + Double yrangepos = yhigh - ylowpos; + if (yrangepos > 0) { + ylowpos -= 0.05 * yrangepos; + } else { + ylowpos *= 0.9; + } // Configure x axis - Range rangeX = new Range(xlow, xhigh); + Range rangeX = null; + if(xscale == AxisType.LIN) { rangeX = new Range(xlow, xhigh); } + else { rangeX = new Range(xlowpos, xhigh); } + NumberAxis axisX = null; if (xscale == AxisType.LIN) { axisX = new NumberAxis(xlabel); axisX.setRange(rangeX); } else { axisX = new LogarithmicAxis(xlabel); + axisX.setRange(rangeX); } // Configure y axis - Range rangeY = new Range(ylow, yhigh); + + Range rangeY = null; + if(yscale == AxisType.LIN) { rangeY = new Range(ylow, yhigh); } + else { rangeY = new Range(ylowpos, yhigh); } + NumberAxis axisY = null; if (yscale == AxisType.LIN) { axisY = new NumberAxis(ylabel); axisY.setRange(rangeY); } else { axisY = new LogarithmicAxis(ylabel); + axisY.setRange(rangeY); + } + + // add series + for (YAxis y : ys) { + XYIntervalSeries series = getDataSeries(x, y, xscale, yscale, axisX, axisY); + series.setKey("Dataset " + x.getDataset().getId().toString() + + ", x-axis " + x.getId().toString() + + ", y-axis " + y.getId().toString()); + allseries.addSeries(series); } final XYErrorRenderer renderer = new XYErrorRenderer(); renderer.setCapLength(3); - final XYPlot plot = new XYPlot(allseries, axisX, axisY, renderer); + XYPlot plot = new XYPlot(allseries, axisX, axisY, renderer); Boolean showLegend = (ys.size() > 1); final JFreeChart chart = new JFreeChart("", new Font("Serif", Font.PLAIN, 12), plot, showLegend); //chart.setBackgroundPaint(Color.WHITE); @@ -119,7 +147,7 @@ - protected static XYIntervalSeries getDataSeries(XAxis xa, YAxis ya, AxisType xscale, AxisType yscale) { + protected static XYIntervalSeries getDataSeries(XAxis xa, YAxis ya, AxisType xscale, AxisType yscale, NumberAxis axisX, NumberAxis axisY) { XYIntervalSeries series = new XYIntervalSeries(" "); for (int ip = 1; ip <= xa.getDataset().getMaxPointId(); ++ip) { try { @@ -129,6 +157,8 @@ Double dyplus = pt.getQuadCombinedPlusError(); double ylow = y - dyminus; double yhigh = y + dyplus; + if ( ylow < axisY.getRange().getLowerBound() ) ylow = axisY.getRange().getLowerBound(); + Bin b = xa.getBin(ip); Double x = b.getFocus(); @@ -141,13 +171,13 @@ } Double xlow = x - dxminus; Double xhigh = x + dxplus; + if ( xlow < axisX.getRange().getLowerBound() ) xlow = axisX.getRange().getLowerBound(); // Check log ranges before adding to the data series - System.out.println("xscale is " + xscale + " xlow is " + xlow + " yscale is " + yscale + "ylow is " + ylow); -// boolean rangeok = !((xscale.equals("LOG") && xlow <= 0.0) || (yscale.equals("LOG") && ylow <= 0.0)); - boolean rangeok = !((xscale == AxisType.LOG && xlow <= 0.0) || (yscale == AxisType.LOG && ylow <= 0.0)); - System.out.println("rangeok is " + rangeok); - if (rangeok) series.add(x, xlow, xhigh, y, ylow, yhigh); +// boolean rangeok = !((xscale == AxisType.LOG && xlow <= 0.0) || (yscale == AxisType.LOG && ylow <= 0.0)); +// if (rangeok) { + series.add(x, xlow, xhigh, y, ylow, yhigh); +// } } catch(Exception e) { // }
More information about the HepData-svn mailing list |