Skip to content

Commit

Permalink
Update GraphsGUI
Browse files Browse the repository at this point in the history
  • Loading branch information
johnprif committed Jan 13, 2023
1 parent 5d0df96 commit 306e289
Showing 1 changed file with 49 additions and 33 deletions.
82 changes: 49 additions & 33 deletions src/View/GraphGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;

import Control.CustomChangeListener;
import Control.CustomMouseListener;

import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
Expand Down Expand Up @@ -73,10 +70,14 @@

public class GraphGUI
{
private Stage graphStage;
private ArrayList<Point2D> allPoints;
private Stage circleStage;
private Stage voronoiStage;
private DataBase dataBase;
private String path;

private XYSeriesCollection dataset;

private XYPlot plot;

public GraphGUI(String path)
{
Expand All @@ -85,52 +86,77 @@ public GraphGUI(String path)
System.out.println("The size of all points are = "+dataBase.getAllPointsSize());
createStage();
displaySmallestEnclosingCircle();
graphStage.show();
circleStage.show();
}


private void createStage()
{
graphStage = new Stage();
graphStage.setTitle("SmallestEnclosingCircle -> "+path+" -> "+(dataBase.getAllPointsSize()-1)+" points");
graphStage.setHeight(700);
graphStage.setWidth(700);
graphStage.setResizable(true);
circleStage = new Stage();
circleStage.setTitle("SmallestEnclosingCircle -> "+path+" -> "+(dataBase.getAllPointsSize()-1)+" points");
circleStage.setHeight(700);
circleStage.setWidth(700);
circleStage.setResizable(true);
}

private void displaySmallestEnclosingCircle()
{
makeSeries();

makePlots();

JFreeChart chart = new JFreeChart(plot);
chart.setTitle("Current Point: None");
ChartViewer viewer = new ChartViewer(chart);
//---------------------------------------------------------------------------
viewer.addChartMouseListener(new CustomMouseListener(chart));

//--------------------------------------------------
circleStage.setScene(new Scene(viewer));
}

private void makeSeries()
{
XYSeries series = new XYSeries("circlePoints -> "+(dataBase.getCirclePointsSize()-1));
XYSeries series1 = new XYSeries("allPoints -> "+(dataBase.getAllPointsSize()-1));
XYSeries series2 = new XYSeries("convexPoints -> "+(dataBase.getConvexPointsSize()-1));
XYSeries series3 = new XYSeries("circlePoints -> "+(dataBase.getCirclePointsSize()-1));


for(int i=0; i<dataBase.getAllPointsSize(); i++)
{
series1.add(dataBase.getAllPoints().get(i).getX(), dataBase.getAllPoints().get(i).getY());
}

for(int i=0; i<dataBase.getConvexPointsSize(); i++)
{
series.add(dataBase.getConvexPoints().get(i).getX(), dataBase.getConvexPoints().get(i).getY());
series2.add(dataBase.getConvexPoints().get(i).getX(), dataBase.getConvexPoints().get(i).getY());
}

for(int i=0; i<dataBase.getCirclePointsSize(); i++)
{
series2.add(dataBase.getCirclePoints().get(i).getX(), dataBase.getCirclePoints().get(i).getY());
series3.add(dataBase.getCirclePoints().get(i).getX(), dataBase.getCirclePoints().get(i).getY());
}


XYSeriesCollection dataset = new XYSeriesCollection();
dataset = new XYSeriesCollection();
dataset.addSeries(series3);
dataset.addSeries(series2);
dataset.addSeries(series);
dataset.addSeries(series1);
dataset.setAutoWidth(true);
}

private void makePlots()
{
JFreeChart scatterPlot = ChartFactory.createScatterPlot(
"JFreeChart Scatter Plot", // Chart title
"Current Point: None", // Chart title
"X", // X-Axis Label
"Y", // Y-Axis Label
dataset // Dataset for the Chart
);
);
scatterPlot.setElementHinting(true);
scatterPlot.setTextAntiAlias(true);
scatterPlot.setNotify(true);
scatterPlot.setAntiAlias(true);
// XYPlot plot = new XYPlot(dataset, new NumberAxis("X"), new NumberAxis("Y"), null);
XYPlot plot = (XYPlot)scatterPlot.getPlot();
// Ellipse2D circle = new Ellipse2D.Double(myDoublyLinkedList2.getPoints().get(0).getX(), myDoublyLinkedList2.getPoints().get(0).getY(), myDoublyLinkedList2.getRadius(myDoublyLinkedList2.getPoints().get(0), myDoublyLinkedList2.getPoints().get(1), myDoublyLinkedList2.getPoints().get(2)), myDoublyLinkedList2.getRadius(myDoublyLinkedList2.getPoints().get(0), myDoublyLinkedList2.getPoints().get(1), myDoublyLinkedList2.getPoints().get(2)));
plot = (XYPlot)scatterPlot.getPlot();
Ellipse2D circle = dataBase.findCircle(dataBase.getCirclePoints().get(0), dataBase.getCirclePoints().get(1), dataBase.getCirclePoints().get(2));
XYShapeAnnotation annotation = new XYShapeAnnotation(circle, new BasicStroke(1.0f), Color.BLACK, null);
plot.addAnnotation(annotation);
Expand All @@ -141,16 +167,6 @@ private void displaySmallestEnclosingCircle()
plot.setDomainCrosshairVisible(true);
plot.setDomainZeroBaselineVisible(true);
plot.setOutlineVisible(true);
JFreeChart chart = new JFreeChart(plot);
chart.setTitle("Current Point:");
ChartViewer viewer = new ChartViewer(chart);
//---------------------------------------------------------------------------
viewer.addChartMouseListener(new CustomMouseListener(chart));

//--------------------------------------------------
graphStage.setScene(new Scene(viewer));
}



}

0 comments on commit 306e289

Please sign in to comment.