List of usage examples for org.jfree.data.xy XYDataset getXValue
public double getXValue(int series, int item);
From source file:no.met.jtimeseries.chart.XYCardinalSplineRenderer.java
/** * Draws the item (first pass). This method draws the lines connecting the * items. Instead of drawing separate lines, a GeneralPath is constructed * and drawn at the end of the series painting. * * @param g2//w w w .j av a 2 s. co m * the graphics device. * @param state * the renderer state. * @param plot * the plot (can be used to obtain standard color information * etc). * @param dataset * the dataset. * @param pass * the pass. * @param series * the series index (zero-based). * @param item * the item index (zero-based). * @param domainAxis * the domain axis. * @param rangeAxis * the range axis. * @param dataArea * the area within which the data is being drawn. */ @Override protected void drawPrimaryLineAsPath(XYItemRendererState state, Graphics2D g2, XYPlot plot, XYDataset dataset, int pass, int series, int item, ValueAxis domainAxis, ValueAxis rangeAxis, Rectangle2D dataArea) { RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); // get the data points double x1 = dataset.getXValue(series, item); double y1 = dataset.getYValue(series, item); double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation); double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation); // collect points if (!Double.isNaN(transX1) && !Double.isNaN(transY1)) { ControlPoint p = new ControlPoint( plot.getOrientation() == PlotOrientation.HORIZONTAL ? (float) transY1 : (float) transX1, plot.getOrientation() == PlotOrientation.HORIZONTAL ? (float) transX1 : (float) transY1); if (!this.points.contains(p)) { this.points.add(p); } } if (item == dataset.getItemCount(series) - 1) { State s = (State) state; // construct path // we need at least two points to draw something if (this.points.size() > 1) { ControlPoint cp0 = this.points.get(0); s.seriesPath.moveTo(cp0.x, cp0.y); // we need at least 2 points to spline. Draw simple line // for less then 2 points if (this.points.size() == 2) { ControlPoint cp1 = this.points.get(1); s.seriesPath.lineTo(cp1.x, cp1.y); } else { // construct spline // number of intervals (i.e. parametric curve would be // evaluted n+1 times) // set the minimum resolution int minimumN = 1; int maximumN = 4; // add two more points at the top and the end for drawing the curve between the first two and last two points this.points.add(0, this.points.get(0)); this.points.add(this.points.get(this.points.size() - 1)); // set the minimum distance when using minimumN double smallDistance = Math.pow(Math.pow(points.get(3).x - points.get(0).x, 2) + Math.pow(points.get(3).y - points.get(0).y, 2), 0.5); double currentDistance; double currentN; List<ControlPoint> newPoints; for (int i = 0; i < this.points.size() - 3; i++) { currentDistance = Math.pow(Math.pow(points.get(i + 3).x - points.get(i).x, 2) + Math.pow(points.get(i + 3).y - points.get(i).y, 2), 0.5); currentN = minimumN * currentDistance / smallDistance; currentN = currentN > maximumN ? maximumN : currentN; newPoints = evaluateCardinal2DAtNplusOneValues(this.points.get(i), this.points.get(i + 1), this.points.get(i + 2), this.points.get(i + 3), tension, (int) currentN); for (int j = 0; j < newPoints.size(); j++) { s.seriesPath.lineTo(newPoints.get(j).x, newPoints.get(j).y); } } } s.seriesPath.lineTo(points.get(points.size() - 1).x, points.get(points.size() - 1).y); // draw path drawFirstPassShape(g2, pass, series, item, s.seriesPath); } // reset points vector this.points = new Vector<ControlPoint>(); } }
From source file:longMethod.jfreechart.drawItem.SamplingXYLineRenderer.java
/** * Draws the visual representation of a single data item. * * @param g2 the graphics device.// w ww . j a va 2 s . c o m * @param state the renderer state. * @param dataArea the area within which the data is being drawn. * @param info collects information about the drawing. * @param plot the plot (can be used to obtain standard color * information etc). * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param dataset the dataset. * @param series the series index (zero-based). * @param item the item index (zero-based). * @param crosshairState crosshair information for the plot * (<code>null</code> permitted). * @param pass the pass index. */ public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { // do nothing if item is not visible if (!getItemVisible(series, item)) { return; } RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); // get the data point... double x1 = dataset.getXValue(series, item); double y1 = dataset.getYValue(series, item); double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation); double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation); State s = (State) state; // update path to reflect latest point if (!Double.isNaN(transX1) && !Double.isNaN(transY1)) { float x = (float) transX1; float y = (float) transY1; PlotOrientation orientation = plot.getOrientation(); if (orientation == PlotOrientation.HORIZONTAL) { x = (float) transY1; y = (float) transX1; } if (s.lastPointGood) { if ((Math.abs(x - s.lastX) > s.dX)) { s.seriesPath.lineTo(x, y); if (s.lowY < s.highY) { s.intervalPath.moveTo((float) s.lastX, (float) s.lowY); s.intervalPath.lineTo((float) s.lastX, (float) s.highY); } s.lastX = x; s.openY = y; s.highY = y; s.lowY = y; s.closeY = y; } else { s.highY = Math.max(s.highY, y); s.lowY = Math.min(s.lowY, y); s.closeY = y; } } else { s.seriesPath.moveTo(x, y); s.lastX = x; s.openY = y; s.highY = y; s.lowY = y; s.closeY = y; } s.lastPointGood = true; } else { s.lastPointGood = false; } // if this is the last item, draw the path ... if (item == s.getLastItemIndex()) { // draw path PathIterator pi = s.seriesPath.getPathIterator(null); int count = 0; while (!pi.isDone()) { count++; pi.next(); } g2.setStroke(getItemStroke(series, item)); g2.setPaint(getItemPaint(series, item)); g2.draw(s.seriesPath); g2.draw(s.intervalPath); } }
From source file:org.griphyn.vdl.karajan.monitor.monitors.swing.GraphPanel.java
private double binSearch(XYDataset d, int si, double x, int begin, int end) { if (begin >= end) { return d.getYValue(si, end); }/*from ww w .j a v a2s .c om*/ int mid = (begin + end) / 2; double vmid = d.getXValue(si, mid); if (x == vmid) { return d.getYValue(si, mid); } else if (x < vmid) { return binSearch(d, si, x, begin, mid - 1); } else { return binSearch(d, si, x, mid + 1, end); } }
From source file:org.trade.ui.chart.renderer.MACDItemRenderer.java
/** * Draws the visual representation of a single data item. * /*w w w.j a v a 2s. c o m*/ * @param g2 * the graphics device. * @param state * the renderer state. * @param dataArea * the area within which the data is being drawn. * @param info * collects information about the drawing. * @param plot * the plot (can be used to obtain standard color information * etc). * @param domainAxis * the domain axis. * @param rangeAxis * the range axis. * @param dataset * the dataset. * @param series * the series index (zero-based). * @param item * the item index (zero-based). * @param crosshairState * crosshair information for the plot (<code>null</code> * permitted). * @param pass * the pass index. */ @Override public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { // get the data point... MACDDataset mACDDataset = (MACDDataset) dataset; MACDItem mACDItem = (MACDItem) mACDDataset.getSeries(series).getDataItem(item); double x1 = dataset.getXValue(series, item); double y1 = mACDItem.getMACD(); double x0 = 0; double y0 = 0; int lastItem = 0; MACDItem prevMACDItem = null; if (item != 0) { prevMACDItem = (MACDItem) mACDDataset.getSeries(series).getDataItem(item - 1); x0 = mACDDataset.getXValue(series, item - 1); y0 = prevMACDItem.getMACD(); lastItem = mACDDataset.getItemCount(series) - 1; } int numX = mACDDataset.getItemCount(series); double minX = mACDDataset.getXValue(series, 0); double maxX = mACDDataset.getXValue(series, numX - 1); /* * Draw MACD. */ drawItem(g2, state, dataArea, info, plot, domainAxis, rangeAxis, x0, y0, x1, y1, lastItem, series, item, crosshairState, pass, numX, minX, maxX, mACDDataset.getSeriesColor(0), dataset); y1 = mACDItem.getSignalLine(); if (item != 0) { y0 = prevMACDItem.getSignalLine(); } /* * Draw MACD smoothing. */ drawItem(g2, state, dataArea, info, plot, domainAxis, rangeAxis, x0, y0, x1, y1, lastItem, series, item, crosshairState, pass, numX, minX, maxX, Color.RED, dataset); y1 = mACDItem.getMACDHistogram(); if (item != 0) { y0 = prevMACDItem.getMACDHistogram(); } /* * Draw MACD histogram. */ y0 = 0; x0 = x1; drawItem(g2, state, dataArea, info, plot, domainAxis, rangeAxis, x0, y0, x1, y1, lastItem, series, item, crosshairState, pass, numX, minX, maxX, Color.BLACK, dataset); }
From source file:org.operamasks.faces.render.graph.XYCurveAndShapeRenderer.java
/** * Draws the item (first pass). This method draws the lines * connecting the items. Instead of drawing separate lines, * a GeneralPath is constructed and drawn at the end of * the series painting./*w ww . j a v a 2 s .c om*/ * * @param g2 the graphics device. * @param state the renderer state. * @param plot the plot (can be used to obtain standard color information * etc). * @param dataset the dataset. * @param pass the pass. * @param series the series index (zero-based). * @param item the item index (zero-based). * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param dataArea the area within which the data is being drawn. */ protected void drawPrimaryLineAsPath(XYItemRendererState state, Graphics2D g2, XYPlot plot, XYDataset dataset, int pass, int series, int item, ValueAxis domainAxis, ValueAxis rangeAxis, Rectangle2D dataArea) { if (item != 0) { return; } RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); PlotOrientation orientation = plot.getOrientation(); int itemCount = dataset.getItemCount(series); double[][] points = new double[itemCount][2]; int count = 0; for (int i = 0; i < itemCount; i++) { double x = dataset.getXValue(series, i); double y = dataset.getYValue(series, i); double transX = domainAxis.valueToJava2D(x, dataArea, xAxisLocation); double transY = rangeAxis.valueToJava2D(y, dataArea, yAxisLocation); if (!Double.isNaN(transX) && !Double.isNaN(transY)) { points[count][0] = transX; points[count][1] = transY; count++; } } if (count < 2) { return; } // sort points according to x axis Arrays.sort(points, new Comparator<double[]>() { public int compare(double[] a, double[] b) { return a[0] > b[0] ? 1 : a[0] < b[0] ? -1 : 0; } }); // draw curve CubicSplineFunction2D f = new CubicSplineFunction2D(points, count); GeneralPath path = new GeneralPath(); double startX = points[0][0]; double startY = points[0][1]; double endX = points[count - 1][0]; double endY = points[count - 1][1]; double yz = rangeAxis.valueToJava2D(0.0, dataArea, yAxisLocation); if (orientation == PlotOrientation.HORIZONTAL) { if (drawArea) { path.moveTo((float) yz, (float) startX); path.lineTo((float) startY, (float) startX); for (double x = Math.floor(startX) + 1.0; x < endX; x += 1.0) { path.lineTo((float) f.getValue(x), (float) x); } path.lineTo((float) endY, (float) endX); path.lineTo((float) yz, (float) endX); path.closePath(); } else { path.moveTo((float) startY, (float) startX); for (double x = Math.floor(startX) + 1.0; x < endX; x += 1.0) { path.lineTo((float) f.getValue(x), (float) x); } path.lineTo((float) endY, (float) endX); } } else { if (drawArea) { path.moveTo((float) startX, (float) yz); path.lineTo((float) startX, (float) startY); for (double x = Math.floor(startX) + 1.0; x < endX; x += 1.0) { path.lineTo((float) x, (float) f.getValue(x)); } path.lineTo((float) endX, (float) endY); path.lineTo((float) endX, (float) yz); path.closePath(); } else { path.moveTo((float) startX, (float) startY); for (double x = Math.floor(startX) + 1.0; x < endX; x += 1.0) { path.lineTo((float) x, (float) f.getValue(x)); } path.lineTo((float) endX, (float) endY); } } Paint paint = getItemPaint(series, item); Stroke stroke = getItemStroke(series, item); if (drawArea) { g2.setPaint(paint); g2.fill(path); // create paint for outline if (paint instanceof Color) { paint = ((Color) paint).darker(); } else if (paint instanceof GradientPaint) { paint = ((GradientPaint) paint).getColor1().darker(); } } g2.setPaint(paint); g2.setStroke(stroke); g2.draw(path); }
From source file:msi.gama.outputs.layers.charts.ChartJFreeChartOutputHeatmap.java
@Override public void getModelCoordinatesInfo(final int xOnScreen, final int yOnScreen, final IDisplaySurface g, final Point positionInPixels, final StringBuilder sb) { final int x = xOnScreen - positionInPixels.x; final int y = yOnScreen - positionInPixels.y; final ChartEntity entity = info.getEntityCollection().getEntity(x, y); // getChart().handleClick(x, y, info); if (entity instanceof XYItemEntity) { final XYDataset data = ((XYItemEntity) entity).getDataset(); final int index = ((XYItemEntity) entity).getItem(); final int series = ((XYItemEntity) entity).getSeriesIndex(); final double xx = data.getXValue(series, index); final double yy = data.getYValue(series, index); final XYPlot plot = (XYPlot) getJFChart().getPlot(); final ValueAxis xAxis = plot.getDomainAxis(series); final ValueAxis yAxis = plot.getRangeAxis(series); final boolean xInt = xx % 1 == 0; final boolean yInt = yy % 1 == 0; String xTitle = xAxis.getLabel(); if (StringUtils.isBlank(xTitle)) { xTitle = "X"; }/* w w w . java 2 s . co m*/ String yTitle = yAxis.getLabel(); if (StringUtils.isBlank(yTitle)) { yTitle = "Y"; } sb.append(xTitle).append(" ").append(xInt ? (int) xx : String.format("%.2f", xx)); sb.append(" | ").append(yTitle).append(" ").append(yInt ? (int) yy : String.format("%.2f", yy)); return; } else if (entity instanceof PieSectionEntity) { final String title = ((PieSectionEntity) entity).getSectionKey().toString(); final PieDataset data = ((PieSectionEntity) entity).getDataset(); final int index = ((PieSectionEntity) entity).getSectionIndex(); final double xx = data.getValue(index).doubleValue(); final boolean xInt = xx % 1 == 0; sb.append(title).append(" ").append(xInt ? (int) xx : String.format("%.2f", xx)); return; } else if (entity instanceof CategoryItemEntity) { final Comparable<?> columnKey = ((CategoryItemEntity) entity).getColumnKey(); final String title = columnKey.toString(); final CategoryDataset data = ((CategoryItemEntity) entity).getDataset(); final Comparable<?> rowKey = ((CategoryItemEntity) entity).getRowKey(); final double xx = data.getValue(rowKey, columnKey).doubleValue(); final boolean xInt = xx % 1 == 0; sb.append(title).append(" ").append(xInt ? (int) xx : String.format("%.2f", xx)); return; } }
From source file:org.trade.ui.chart.renderer.PivotRenderer.java
/** * Draws the visual representation of a single data item. * /*from w w w . j a v a 2 s . c o m*/ * @param g2 * the graphics device. * @param state * the renderer state. * @param dataArea * the area within which the data is being drawn. * @param info * collects information about the drawing. * @param plot * the plot (can be used to obtain standard color information * etc). * @param domainAxis * the domain (horizontal) axis. * @param rangeAxis * the range (vertical) axis. * @param dataset * the dataset. * @param series * the series index (zero-based). * @param item * the item index (zero-based). * @param crosshairState * crosshair information for the plot (<code>null</code> * permitted). * @param pass * the pass index. * @see org.jfree.chart.renderer.xy.XYItemRenderer#drawItem(Graphics2D, * XYItemRendererState, Rectangle2D, PlotRenderingInfo, XYPlot, * ValueAxis, ValueAxis, XYDataset, int, int, CrosshairState, int) */ public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { // do nothing if item is not visible if (!getItemVisible(series, item)) { return; } // get the data point... double x = dataset.getXValue(series, item); double y = dataset.getYValue(series, item); double adjx = (this.dotWidth - 1) / 2.0; double adjy = (this.dotHeight - 1) / 2.0; if (!Double.isNaN(y)) { RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); double transX = domainAxis.valueToJava2D(x, dataArea, xAxisLocation) - adjx; double transY = rangeAxis.valueToJava2D(y, dataArea, yAxisLocation) - adjy; g2.setPaint(getItemPaint(series, item)); PlotOrientation orientation = plot.getOrientation(); if (orientation == PlotOrientation.HORIZONTAL) { g2.fillRect((int) transY, (int) transX, this.dotHeight, this.dotWidth); } else if (orientation == PlotOrientation.VERTICAL) { g2.fillRect((int) transX, (int) transY, this.dotWidth, this.dotHeight); } int domainAxisIndex = plot.getDomainAxisIndex(domainAxis); int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis); updateCrosshairValues(crosshairState, x, y, domainAxisIndex, rangeAxisIndex, transX, transY, orientation); PivotDataset pivotDataset = (PivotDataset) dataset; if (null != pivotDataset.getPivotSide(series, item)) { String ledgend = "Pivot"; if (pivotDataset.getPivotSide(series, item).equals(Side.BOT)) { drawPivotArrow(g2, plot, dataArea, domainAxis, rangeAxis, item, info, 45d, x, pivotDataset.getPivotValue(series, item), ledgend); } else { drawPivotArrow(g2, plot, dataArea, domainAxis, rangeAxis, item, info, -45d, x, pivotDataset.getPivotValue(series, item), ledgend); } } } }
From source file:org.openfaces.component.chart.impl.renderers.XYLineFillRenderer.java
public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataSet, int series, int item, CrosshairState crosshairState, int pass) { if (!getItemVisible(series, item)) { return;// w w w .j a v a 2 s . c o m } double itemXValue = dataSet.getXValue(series, item); double itemYValue = dataSet.getYValue(series, item); if (Double.isNaN(itemYValue) || Double.isNaN(itemXValue)) { return; } double currentItemX = calculateItemXPoint(series, item, dataArea, domainAxis, dataSet, plot); double currentItemY = calculateItemYPoint(series, item, dataArea, rangeAxis, dataSet, plot); int previousItemIndex = item > 0 ? item - 1 : 0; double previousItemX = calculateItemXPoint(series, previousItemIndex, dataArea, domainAxis, dataSet, plot); double previousItemY = calculateItemYPoint(series, previousItemIndex, dataArea, rangeAxis, dataSet, plot); final int lastItemIndex = dataSet.getItemCount(series) - 1; int nextItemIndex = item < lastItemIndex ? item + 1 : lastItemIndex; double nextItemX = calculateItemXPoint(series, nextItemIndex, dataArea, domainAxis, dataSet, plot); double nextItemY = calculateItemYPoint(series, nextItemIndex, dataArea, rangeAxis, dataSet, plot); double zeroRangePoint = rangeAxis.valueToJava2D(0.0, dataArea, plot.getRangeAxisEdge()); if (isAreaAndLinePass(pass)) { XYLineFillItemRendererState rendererState = (XYLineFillItemRendererState) state; renderLineArea(g2, info, plot, series, item, rendererState, dataSet, currentItemX, currentItemY, previousItemX, previousItemY, zeroRangePoint); } else if (isShapesAndLabelsPass(pass)) { Shape entityArea = renderShapeAndLabel(g2, dataArea, plot, dataSet, series, item, itemYValue, currentItemX, currentItemY, previousItemX, previousItemY, nextItemX, nextItemY, zeroRangePoint); int domainAxisIndex = plot.getDomainAxisIndex(domainAxis); int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis); updateCrosshairValues(crosshairState, itemXValue, itemYValue, domainAxisIndex, rangeAxisIndex, currentItemX, currentItemY, plot.getOrientation()); EntityCollection entityCollection = state.getEntityCollection(); if (entityCollection != null) { addEntity(entityCollection, entityArea, dataSet, series, item, 0.0, 0.0); } } else { throw new IllegalStateException("Unknown pass: " + pass); } }
From source file:no.met.jtimeseries.chart.XYHybridSplineRenderer.java
/** * Draws the item (first pass). This method draws the lines connecting the * items. Instead of drawing separate lines, a GeneralPath is constructed * and drawn at the end of the series painting. * * @param g2/*from www.j av a2s .c om*/ * the graphics device. * @param state * the renderer state. * @param plot * the plot (can be used to obtain standard color information * etc). * @param dataset * the dataset. * @param pass * the pass. * @param series * the series index (zero-based). * @param item * the item index (zero-based). * @param domainAxis * the domain axis. * @param rangeAxis * the range axis. * @param dataArea * the area within which the data is being drawn. */ @Override protected void drawPrimaryLineAsPath(XYItemRendererState state, Graphics2D g2, XYPlot plot, XYDataset dataset, int pass, int series, int item, ValueAxis domainAxis, ValueAxis rangeAxis, Rectangle2D dataArea) { RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); // get the data points double x1 = dataset.getXValue(series, item); double y1 = dataset.getYValue(series, item); double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation); double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation); // collect points if (!Double.isNaN(transX1) && !Double.isNaN(transY1)) { ControlPoint p = new ControlPoint( plot.getOrientation() == PlotOrientation.HORIZONTAL ? (float) transY1 : (float) transX1, plot.getOrientation() == PlotOrientation.HORIZONTAL ? (float) transX1 : (float) transY1); if (!this.points.contains(p)) { this.points.add(p); } } if (item == dataset.getItemCount(series) - 1) { State s = (State) state; // construct path if (this.points.size() > 1) { // we need at least two points to draw something ControlPoint cp0 = this.points.get(0); s.seriesPath.moveTo(cp0.x, cp0.y); if (this.points.size() == 2) { // we need at least 3 points to spline. Draw simple line // for two points ControlPoint cp1 = this.points.get(1); s.seriesPath.lineTo(cp1.x, cp1.y); } else { // construct spline // add some cardinal spline control points this.points = addCardinalSplinePoints(this.points, tension); // applying standard spline int np = this.points.size(); // number of points float[] d = new float[np]; // Newton form coefficients float[] x = new float[np]; // x-coordinates of nodes float y; float t; float oldy = 0; float oldt = 0; float[] a = new float[np]; float t1; float t2; float[] h = new float[np]; for (int i = 0; i < np; i++) { ControlPoint cpi = this.points.get(i); x[i] = cpi.x; d[i] = cpi.y; } for (int i = 1; i <= np - 1; i++) { h[i] = x[i] - x[i - 1]; } float[] sub = new float[np - 1]; float[] diag = new float[np - 1]; float[] sup = new float[np - 1]; for (int i = 1; i <= np - 2; i++) { diag[i] = (h[i] + h[i + 1]) / 3; sup[i] = h[i + 1] / 6; sub[i] = h[i] / 6; a[i] = (d[i + 1] - d[i]) / h[i + 1] - (d[i] - d[i - 1]) / h[i]; } solveTridiag(sub, diag, sup, a, np - 2); // note that a[0]=a[np-1]=0 // draw oldt = x[0]; oldy = d[0]; s.seriesPath.moveTo(oldt, oldy); for (int i = 1; i <= np - 1; i++) { // loop over intervals between nodes for (int j = 1; j <= this.precision; j++) { t1 = (h[i] * j) / this.precision; t2 = h[i] - t1; y = ((-a[i - 1] / 6 * (t2 + h[i]) * t1 + d[i - 1]) * t2 + (-a[i] / 6 * (t1 + h[i]) * t2 + d[i]) * t1) / h[i]; t = x[i - 1] + t1; s.seriesPath.lineTo(t, y); oldt = t; oldy = y; } } } // draw path drawFirstPassShape(g2, pass, series, item, s.seriesPath); } // reset points vector this.points = new Vector<ControlPoint>(); } }
From source file:com.newatlanta.bluedragon.CustomXYAreaRenderer.java
public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { super.drawItem(g2, state, dataArea, info, plot, domainAxis, rangeAxis, dataset, series, item, crosshairState, pass);/*from w w w. ja va2 s.c om*/ // The complete area chart is drawn when drawItem() is called for the last // item // so we need to draw all of the item labels after the last item so they'll // be // visible if they overlap the area chart. int itemCount = dataset.getItemCount(series); if (getPlotArea() && item > 0 && item == (itemCount - 1)) { // this is the last item so draw the item labels PlotOrientation orientation = plot.getOrientation(); for (int i = 0; i < itemCount; i++) { if (isItemLabelVisible(series, i)) { double xValue = dataset.getXValue(series, i); double yValue = dataset.getYValue(series, i); if (Double.isNaN(yValue)) { yValue = 0.0; } double transXValue = domainAxis.valueToJava2D(xValue, dataArea, plot.getDomainAxisEdge()); double transYValue = rangeAxis.valueToJava2D(yValue, dataArea, plot.getRangeAxisEdge()); double xx = transXValue; double yy = transYValue; if (orientation == PlotOrientation.HORIZONTAL) { xx = transYValue; yy = transXValue; } drawItemLabel(g2, orientation, dataset, series, i, xx, yy, (yValue < 0.0)); } } } }