/** * Method to plot the data points as a curve chart * * @param g (Graphics) */ private void drawCurveGraphics(Graphics g) { for (ScatterPlotData currentScatterPlot : data) { g.setColor(currentScatterPlot.getColor()); for (int j = 0; j < (currentScatterPlot.getData().length - 1); j++) { Point current = new Point( getTranslatedPoint( currentScatterPlot.getData()[j][0], currentScatterPlot.getData()[j][1])); Point nexttonext = new Point( getTranslatedPoint( currentScatterPlot.getData()[j + 1][0], currentScatterPlot.getData()[j + 1][1])); g.drawLine(current.x, current.y, nexttonext.x, nexttonext.y); if ((currentScatterPlot.getData()[j][0] < xAxis.getMin()) || (currentScatterPlot.getData()[j][0] > xAxis.getMax()) || (currentScatterPlot.getData()[j + 1][1] <= yAxis.getMax())) { // we erase the part of the line that is not in the chart area // this means that the curve needs to be drawn before the axis and ticks and legend g.setColor(getBackground()); g.fillRect(0, 0, getWidth(), PAD); g.fillRect(0, getHeight() - PAD, getWidth(), PAD); g.setColor(currentScatterPlot.getColor()); } } } }
/** * @param screenPoint {@link Point} of a screen position * @return original data Point corresponding to the specified screen position */ private Point2D getDataPoint(Point screenPoint) { Point2D.Double retPoint = new Point2D.Double(); retPoint.x = (((screenPoint.x - PAD) * (xAxis.getMax() - xAxis.getMin())) / (getWidth() - (2 * PAD))) + xAxis.getMin(); retPoint.y = (-1 * ((((screenPoint.y - getHeight()) + PAD) * (yAxis.getMax() - yAxis.getMin())) / (getHeight() - (2 * PAD)))) + yAxis.getMin(); return retPoint; }
/** * Method to plot the data points as a point chart * * @param g (Graphics) */ private void drawPointGraphics(Graphics g) { for (ScatterPlotData currentScatterPlot : data) { g.setColor(currentScatterPlot.getColor()); for (int j = 0; j < (currentScatterPlot.getData().length - 1); j++) { Point current = new Point( getTranslatedPoint( currentScatterPlot.getData()[j][0], currentScatterPlot.getData()[j][1])); Point next = new Point( getTranslatedPoint( currentScatterPlot.getData()[j + 1][0], currentScatterPlot.getData()[j][1])); if ((currentScatterPlot.getData()[j][0] >= xAxis.getMin()) && (currentScatterPlot.getData()[j][0] <= xAxis.getMax()) && (currentScatterPlot.getData()[j][1] >= yAxis.getMin()) && (currentScatterPlot.getData()[j][1] <= yAxis.getMax())) { g.drawLine(current.x, current.y, next.x, next.y); } } } }