List of usage examples for org.jfree.data Range Range
public Range(double lower, double upper)
From source file:org.jfree.chart.demo.SampleXYDataset2.java
/** * Creates a sample dataset.//from ww w .j av a 2 s. c o m * * @param seriesCount the number of series. * @param itemCount the number of items. */ public SampleXYDataset2(final int seriesCount, final int itemCount) { this.xValues = new Double[seriesCount][itemCount]; this.yValues = new Double[seriesCount][itemCount]; this.seriesCount = seriesCount; this.itemCount = itemCount; double minX = Double.POSITIVE_INFINITY; double maxX = Double.NEGATIVE_INFINITY; double minY = Double.POSITIVE_INFINITY; double maxY = Double.NEGATIVE_INFINITY; for (int series = 0; series < seriesCount; series++) { for (int item = 0; item < itemCount; item++) { final double x = (Math.random() - 0.5) * DEFAULT_RANGE; this.xValues[series][item] = new Double(x); if (x < minX) { minX = x; } if (x > maxX) { maxX = x; } final double y = (Math.random() + 0.5) * 6 * x + x; this.yValues[series][item] = new Double(y); if (y < minY) { minY = y; } if (y > maxY) { maxY = y; } } } this.domainMin = new Double(minX); this.domainMax = new Double(maxX); this.domainRange = new Range(minX, maxX); this.rangeMin = new Double(minY); this.rangeMax = new Double(maxY); this.range = new Range(minY, maxY); }
From source file:edu.cuny.cat.ui.ClockPanel.java
@Override public void setup(final ParameterDatabase parameters, final Parameter base) { clock = GameController.getInstance().getClock(); dataset = new DefaultValueDataset(); meterplot = new MyMeterPlot(dataset) { /**//from w w w . ja va 2 s . c om * */ private static final long serialVersionUID = 1L; @Override protected void drawValueLabel(final Graphics2D g2, final Rectangle2D area) { g2.setFont(getValueFont()); g2.setPaint(getValuePaint()); String valueStr = "No value"; if (dataset != null) { final Number n = dataset.getValue(); if (n != null) { if (n.intValue() == 0) { valueStr = "to start"; } else if (n.intValue() == clock.getGameLen() * clock.getDayLen()) { valueStr = "done"; } else { valueStr = "day " + (n.intValue() / clock.getDayLen()) + ", round " + (n.intValue() % clock.getDayLen()); } } } final float x = (float) area.getCenterX(); final float y = (float) area.getCenterY() + MeterPlot.DEFAULT_CIRCLE_SIZE; TextUtilities.drawAlignedString(valueStr, g2, x, y, TextAnchor.TOP_CENTER); } }; meterplot.setRange(new Range(0, clock.getDayLen() * clock.getGameLen())); meterplot.setNeedlePaint( parameters.getColorWithDefault(base.push(ClockPanel.P_NEEDLE), null, Color.darkGray)); meterplot.setDialBackgroundPaint(new Color(0, 255, 0, 64)); meterplot.setDialOutlinePaint(Color.gray); meterplot.setDialShape(DialShape.CHORD); meterplot.setMeterAngle(parameters.getIntWithDefault(base.push(ClockPanel.P_ANGLE), null, 260)); meterplot.setTickLabelsVisible(true); meterplot.setTickLabelFont(new Font("Dialog", 1, 10)); meterplot.setTickLabelPaint(Color.darkGray); meterplot.setTickSize(clock.getDayLen()); meterplot.setTickPaint(Color.lightGray); meterplot.setValuePaint(Color.black); meterplot.setValueFont(new Font("Dialog", 1, 14)); meterplot.setUnits(""); meterplot.setTickLabelFormat(new NumberFormat() { /** * */ private static final long serialVersionUID = 1L; @Override public StringBuffer format(final double number, final StringBuffer toAppendTo, final FieldPosition pos) { return format((long) number, toAppendTo, pos); } @Override public StringBuffer format(final long number, final StringBuffer toAppendTo, final FieldPosition pos) { if (number % clock.getDayLen() == 0) { toAppendTo.append(String.valueOf(number / clock.getDayLen())); } return toAppendTo; } @Override public Number parse(final String source, final ParsePosition parsePosition) { return null; } }); final JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, meterplot, false); final ChartPanel panel = new ChartPanel(chart); panel.setPreferredSize(new Dimension(parameters.getIntWithDefault(base.push(ClockPanel.P_WIDTH), null, 200), parameters.getIntWithDefault(base.push(ClockPanel.P_HEIGHT), null, 200))); add(panel, BorderLayout.CENTER); initIterationLabel(); initScoreReport(); }
From source file:org.jfree.experimental.chart.renderer.xy.VectorRenderer.java
/** * Returns the lower and upper bounds (range) of the x-values in the * specified dataset.//from ww w.jav a 2s . c o m * * @param dataset the dataset (<code>null</code> permitted). * * @return The range (<code>null</code> if the dataset is <code>null</code> * or empty). */ public Range findDomainBounds(XYDataset dataset) { if (dataset == null) { throw new IllegalArgumentException("Null 'dataset' argument."); } double minimum = Double.POSITIVE_INFINITY; double maximum = Double.NEGATIVE_INFINITY; int seriesCount = dataset.getSeriesCount(); double lvalue; double uvalue; if (dataset instanceof VectorXYDataset) { VectorXYDataset vdataset = (VectorXYDataset) dataset; for (int series = 0; series < seriesCount; series++) { int itemCount = dataset.getItemCount(series); for (int item = 0; item < itemCount; item++) { double delta = vdataset.getDeltaXValue(series, item); if (delta < 0.0) { uvalue = vdataset.getXValue(series, item); lvalue = uvalue + delta; } else { lvalue = vdataset.getXValue(series, item); uvalue = lvalue + delta; } minimum = Math.min(minimum, lvalue); maximum = Math.max(maximum, uvalue); } } } else { for (int series = 0; series < seriesCount; series++) { int itemCount = dataset.getItemCount(series); for (int item = 0; item < itemCount; item++) { lvalue = dataset.getXValue(series, item); uvalue = lvalue; minimum = Math.min(minimum, lvalue); maximum = Math.max(maximum, uvalue); } } } if (minimum > maximum) { return null; } else { return new Range(minimum, maximum); } }
From source file:inflor.core.gates.ui.RectangleGateAnnotation.java
@Override public Range getXRange() { return new Range(Math.min(x0, x1), Math.max(x0, x1)); }
From source file:org.metacsp.utility.UI.PlotBoxTLSmall.java
public PlotBoxTLSmall(Timeline simpletimeline, String n, boolean f, boolean l, long min, long max) { //super(title); if (min != -1 && max != -1) { this.range = new Range(min, max); }//w w w . ja v a 2s . c o m first = f; last = l; this.title = "Simple Timeline"; this.name = n; this.stl = simpletimeline; //estProfile = (SimpleTimeline) stateVariable.extractTimeline(0); JFreeChart chart = createChart(createDataset()); ChartPanel chartPanel = new ChartPanel(chart); this.add(chartPanel); chartPanel.setPreferredSize(new java.awt.Dimension(xsize, 200)); //this.setPreferredSize(new Dimension(500, 400)); }
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 w w w .j a v a 2 s . co 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:inflor.core.gates.ui.RectangleGateAnnotation.java
@Override public Range getYRange() { return new Range(Math.min(y0, y1), Math.max(y0, y1)); }
From source file:biz.ixnay.pivot.charts.skin.jfree.LineChartViewSkin.java
public void setRangeAxisLowerBound(double lower) { this.rangeAxisRange = new Range(lower, getRangeAxisUpperBound()); repaintComponent();/*from w ww.ja va 2s. c o m*/ }
From source file:org.jfree.data.statistics.DefaultMultiValueCategoryDataset.java
/** * Adds a list of values to the dataset (<code>null</code> and Double.NaN * items are automatically removed) and sends a {@link DatasetChangeEvent} * to all registered listeners.//w w w .j ava2 s. co m * * @param values a list of values (<code>null</code> not permitted). * @param rowKey the row key (<code>null</code> not permitted). * @param columnKey the column key (<code>null</code> not permitted). */ public void add(List values, Comparable rowKey, Comparable columnKey) { ParamChecks.nullNotPermitted(values, "values"); ParamChecks.nullNotPermitted(rowKey, "rowKey"); ParamChecks.nullNotPermitted(columnKey, "columnKey"); List vlist = new ArrayList(values.size()); Iterator iterator = values.listIterator(); while (iterator.hasNext()) { Object obj = iterator.next(); if (obj instanceof Number) { Number n = (Number) obj; double v = n.doubleValue(); if (!Double.isNaN(v)) { vlist.add(n); } } } Collections.sort(vlist); this.data.addObject(vlist, rowKey, columnKey); if (vlist.size() > 0) { double maxval = Double.NEGATIVE_INFINITY; double minval = Double.POSITIVE_INFINITY; for (int i = 0; i < vlist.size(); i++) { Number n = (Number) vlist.get(i); double v = n.doubleValue(); minval = Math.min(minval, v); maxval = Math.max(maxval, v); } // update the cached range values... if (this.maximumRangeValue == null) { this.maximumRangeValue = new Double(maxval); } else if (maxval > this.maximumRangeValue.doubleValue()) { this.maximumRangeValue = new Double(maxval); } if (this.minimumRangeValue == null) { this.minimumRangeValue = new Double(minval); } else if (minval < this.minimumRangeValue.doubleValue()) { this.minimumRangeValue = new Double(minval); } this.rangeBounds = new Range(this.minimumRangeValue.doubleValue(), this.maximumRangeValue.doubleValue()); } fireDatasetChanged(); }
From source file:org.jax.haplotype.analysis.visualization.GenomicGraphFactory.java
/** * Create a snp interval histogram without any axes * @param intervals/*from www . j a va 2 s .c o m*/ * the intervals to use * @param startInBasePairs * where should we start the graph? * @param extentInBasePairs * how far should the graph extend * @param visualInterval * the visual interval to use * @param xAxisLabel * the x axis title to use * @param yAxisLabel * the y axis title to use * @return * the histogram */ public JFreeChart createSnpIntervalHistogram(final List<? extends RealValuedBasePairInterval> intervals, final long startInBasePairs, final long extentInBasePairs, final HighlightedSnpInterval visualInterval, final String xAxisLabel, final String yAxisLabel) { // create the axes NumberAxis xAxis = new NumberAxis(); xAxis.setAutoRangeIncludesZero(false); xAxis.setRange(new Range(startInBasePairs, startInBasePairs + extentInBasePairs)); if (xAxisLabel != null) { xAxis.setLabel(xAxisLabel); } NumberAxis yAxis = new NumberAxis(); if (yAxisLabel != null) { yAxis.setLabel(yAxisLabel); } // create the plot XYPlot plot = this.createSnpIntervalHistogramPlot(intervals, visualInterval, xAxis, yAxis); // create the final chart JFreeChart histogram = new JFreeChart(plot); histogram.removeLegend(); return histogram; }