Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional plots and conversion to ojAlgo matrix library #60

Merged
merged 2 commits into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void paint(GraphicsContext g2d) {
g2d.fillText(intensityLinePlotBuilder.getTitle(), leftMargin + 25, 15);

g2d.setLineWidth(2.0);
// new line graph
// new line plot
g2d.setStroke(Paint.valueOf("Black"));
g2d.beginPath();
g2d.moveTo(mapX(xAxisData[0]), mapY(yAxisData[0]));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
package org.cirdles.tripoli.gui.dataViews.plots;

import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Paint;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import org.cirdles.tripoli.visualizationUtilities.linePlots.ComboPlotBuilder;


public class BasicScatterAndLinePlot extends AbstractDataView {

private final ComboPlotBuilder comboPlotBuilder;
private double[] yAxisData2;
/**
* @param bounds
* @param comboPlotBuilder
*/
public BasicScatterAndLinePlot(Rectangle bounds, ComboPlotBuilder comboPlotBuilder) {
super(bounds, 50, 5);
this.comboPlotBuilder = comboPlotBuilder;
}

@Override
public void preparePanel() {
xAxisData = comboPlotBuilder.getxData();
yAxisData = comboPlotBuilder.getyData();
yAxisData2 = comboPlotBuilder.getyData2();

minX = xAxisData[0];
maxX = xAxisData[xAxisData.length - 1];

ticsX = TicGeneratorForAxes.generateTics(minX, maxX, (int) (graphWidth / 40.0));
double xMarginStretch = TicGeneratorForAxes.generateMarginAdjustment(minX, maxX, 0.01);
minX -= xMarginStretch;
maxX += xMarginStretch;

minY = Double.MAX_VALUE;
maxY = -Double.MAX_VALUE;

for (int i = 0; i < yAxisData.length; i++) {
minY = StrictMath.min(minY, yAxisData[i]);
maxY = StrictMath.max(maxY, yAxisData[i]);
minY = StrictMath.min(minY, yAxisData2[i]);
maxY = StrictMath.max(maxY, yAxisData2[i]);
if (comboPlotBuilder.isyData2OneSigma()){
minY = StrictMath.min(minY, -yAxisData2[i]);
}
}
ticsY = TicGeneratorForAxes.generateTics(minY, maxY, (int) (graphHeight / 15.0));
if ((ticsY != null) && (ticsY.length > 1)) {
// force y to tics
minY = ticsY[0].doubleValue();
maxY = ticsY[ticsY.length - 1].doubleValue();
// adjust margins
double yMarginStretch = TicGeneratorForAxes.generateMarginAdjustment(minY, maxY, 0.1);
minY -= yMarginStretch * 2.0;
maxY += yMarginStretch;
}

setDisplayOffsetY(0.0);
setDisplayOffsetX(0.0);

this.repaint();
}

@Override
public void paint(GraphicsContext g2d) {
super.paint(g2d);

Text text = new Text();
text.setFont(Font.font("SansSerif", 12));
int textWidth = 0;

g2d.setFont(Font.font("SansSerif", FontWeight.SEMI_BOLD, 12));
g2d.setFill(Paint.valueOf("BLUE"));
g2d.fillText(comboPlotBuilder.getTitle(), leftMargin + 25, 15);

// scatter plot
g2d.setLineWidth(0.75);
g2d.setStroke(Paint.valueOf("Black"));
for (int i = 0; i < xAxisData.length; i++) {
g2d.strokeOval(mapX(xAxisData[i]) - 2f, mapY(yAxisData[i]) -2f, 4f, 4f);
}

// new line plot from yAxisData2
g2d.setStroke(Paint.valueOf("red"));
g2d.beginPath();
g2d.moveTo(mapX(xAxisData[0]), mapY(yAxisData2[0]));
for (int i = 0; i < xAxisData.length; i++) {
// line tracing through points
g2d.lineTo(mapX(xAxisData[i]), mapY(yAxisData2[i]));
}
g2d.stroke();

if (comboPlotBuilder.isyData2OneSigma()){
g2d.beginPath();
g2d.moveTo(mapX(xAxisData[0]), mapY(-yAxisData2[0]));
for (int i = 0; i < xAxisData.length; i++) {
// line tracing through points
g2d.lineTo(mapX(xAxisData[i]), mapY(-yAxisData2[i]));
}
g2d.stroke();
}


if (ticsY.length > 1) {
// border and fill
g2d.setLineWidth(0.5);
g2d.setStroke(Paint.valueOf("BLACK"));
g2d.strokeRect(
mapX(minX),
mapY(ticsY[ticsY.length - 1].doubleValue()),
graphWidth,
StrictMath.abs(mapY(ticsY[ticsY.length - 1].doubleValue()) - mapY(ticsY[0].doubleValue())));

g2d.setFill(Paint.valueOf("BLACK"));

// ticsY
float verticalTextShift = 3.2f;
g2d.setFont(Font.font("SansSerif", 10));
if (ticsY != null) {
for (int i = 0; i < ticsY.length; i++) {
g2d.strokeLine(
mapX(minX), mapY(ticsY[i].doubleValue()), mapX(maxX), mapY(ticsY[i].doubleValue()));

// left side
text.setText(ticsY[i].toString());
textWidth = (int) text.getLayoutBounds().getWidth();
g2d.fillText(text.getText(),//
(float) mapX(minX) - textWidth + 5f,
(float) mapY(ticsY[i].doubleValue()) + verticalTextShift);

}
// ticsX
if (ticsX != null) {
for (int i = 0; i < ticsX.length - 1; i++) {
try {
g2d.strokeLine(
mapX(ticsX[i].doubleValue()),
mapY(ticsY[0].doubleValue()),
mapX(ticsX[i].doubleValue()),
mapY(ticsY[0].doubleValue()) + 5);

// bottom
String xText = ticsX[i].toPlainString();
g2d.fillText(xText,
(float) mapX(ticsX[i].doubleValue()) - 5f,
(float) mapY(ticsY[0].doubleValue()) + 15);

} catch (Exception e) {
}
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void paint(GraphicsContext g2d) {
g2d.fillText(intensityLinePlotBuilder.getTitle(), leftMargin + 25, 15);

g2d.setLineWidth(0.5);
// new line graph
// scatter plot
g2d.setStroke(Paint.valueOf("Black"));
for (int i = 0; i < xAxisData.length; i++) {
g2d.strokeOval(mapX(xAxisData[i]) - 2f, mapY(yAxisData[i]) -2f, 4f, 4f);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public class RJMCMCPlotBuildersTask extends Task<String> implements LoggingCallb

private AbstractPlotBuilder convergeRatioLineBuilder;

private AbstractPlotBuilder ObserveDataLineBuilder;
private AbstractPlotBuilder observedDataLineBuilder;
private AbstractPlotBuilder residualDataLineBuilder;

public RJMCMCPlotBuildersTask(Path dataFile) {
this.dataFile = dataFile;
Expand Down Expand Up @@ -67,8 +68,12 @@ public AbstractPlotBuilder getConvergeRatioLineBuilder() {
return convergeRatioLineBuilder;
}

public AbstractPlotBuilder getObserveDataLineBuilder() {
return ObserveDataLineBuilder;
public AbstractPlotBuilder getObservedDataLineBuilder() {
return observedDataLineBuilder;
}

public AbstractPlotBuilder getResidualDataLineBuilder() {
return residualDataLineBuilder;
}

@Override
Expand All @@ -82,7 +87,8 @@ protected String call() throws Exception {

convergeRatioLineBuilder = plots[5];

ObserveDataLineBuilder = plots[6];
observedDataLineBuilder = plots[6];
residualDataLineBuilder = plots[7];
return "DONE";
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.cirdles.tripoli.gui.dataViews.plots.plotsControllers.RJMCMCPlots;

import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.*;
Expand All @@ -11,12 +9,10 @@
import javafx.scene.shape.Rectangle;
import org.cirdles.commons.util.ResourceExtractor;
import org.cirdles.tripoli.Tripoli;
import org.cirdles.tripoli.gui.dataViews.plots.AbstractDataView;
import org.cirdles.tripoli.gui.dataViews.plots.BasicScatterPlot;
import org.cirdles.tripoli.gui.dataViews.plots.HistogramPlot;
import org.cirdles.tripoli.gui.dataViews.plots.BasicLinePlot;
import org.cirdles.tripoli.gui.dataViews.plots.*;
import org.cirdles.tripoli.visualizationUtilities.AbstractPlotBuilder;
import org.cirdles.tripoli.visualizationUtilities.histograms.HistogramBuilder;
import org.cirdles.tripoli.visualizationUtilities.linePlots.ComboPlotBuilder;
import org.cirdles.tripoli.visualizationUtilities.linePlots.LinePlotBuilder;

import java.io.IOException;
Expand Down Expand Up @@ -112,7 +108,8 @@ public void processDataFileAndShowPlotsOfRJMCMC() throws IOException {

AbstractPlotBuilder convergeRatioPlotBuilder = ((RJMCMCPlotBuildersTask) service.getPlotBuildersTask()).getConvergeRatioLineBuilder();

AbstractPlotBuilder observedDataPlotBuilder = ((RJMCMCPlotBuildersTask) service.getPlotBuildersTask()).getObserveDataLineBuilder();
AbstractPlotBuilder observedDataPlotBuilder = ((RJMCMCPlotBuildersTask) service.getPlotBuildersTask()).getObservedDataLineBuilder();
AbstractPlotBuilder residualDataPlotBuilder = ((RJMCMCPlotBuildersTask) service.getPlotBuildersTask()).getResidualDataLineBuilder();

AbstractDataView ratiosHistogramPlot = new HistogramPlot(
new Rectangle(ensembleGridPane.getWidth(),
Expand Down Expand Up @@ -145,58 +142,61 @@ public void processDataFileAndShowPlotsOfRJMCMC() throws IOException {
convergeRatioScrollPane.getHeight()),
(LinePlotBuilder) convergeRatioPlotBuilder);

AbstractDataView observedDataLinePlot = new BasicScatterPlot(
AbstractDataView observedDataLinePlot = new BasicScatterAndLinePlot(
new Rectangle(dataFitGridPane.getWidth(),
dataFitGridPane.getHeight() / dataFitGridPane.getRowCount()),
(LinePlotBuilder) observedDataPlotBuilder);


plotTabPane.widthProperty().addListener(new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
if (newValue.intValue() > 100) {
double newWidth = newValue.intValue() - ensembleLegendTextBox.getWidth();
ratiosHistogramPlot.setMyWidth(newWidth);
ratiosHistogramPlot.repaint();
baselineHistogramPlot.setMyWidth(newWidth / ensembleGridPane.getColumnCount());
baselineHistogramPlot.repaint();
dalyFaradayHistogramPlot.setMyWidth(newWidth / ensembleGridPane.getColumnCount());
dalyFaradayHistogramPlot.repaint();
intensityLinePlot.setMyWidth(newWidth);
intensityLinePlot.repaint();
signalNoiseHistogramPlot.setMyWidth(newWidth);
signalNoiseHistogramPlot.repaint();

convergeRatioLinePlot.setMyWidth(newValue.intValue());
convergeRatioLinePlot.repaint();

observedDataLinePlot.setMyWidth(newWidth);
observedDataLinePlot.repaint();
}
(ComboPlotBuilder) observedDataPlotBuilder);

AbstractDataView residualDataLinePlot = new BasicScatterAndLinePlot(
new Rectangle(dataFitGridPane.getWidth(),
dataFitGridPane.getHeight() / dataFitGridPane.getRowCount()),
(ComboPlotBuilder) residualDataPlotBuilder);


plotTabPane.widthProperty().addListener((observable, oldValue, newValue) -> {
if (newValue.intValue() > 100) {
double newWidth = newValue.intValue() - ensembleLegendTextBox.getWidth();
ratiosHistogramPlot.setMyWidth(newWidth);
ratiosHistogramPlot.repaint();
baselineHistogramPlot.setMyWidth(newWidth / ensembleGridPane.getColumnCount());
baselineHistogramPlot.repaint();
dalyFaradayHistogramPlot.setMyWidth(newWidth / ensembleGridPane.getColumnCount());
dalyFaradayHistogramPlot.repaint();
intensityLinePlot.setMyWidth(newWidth);
intensityLinePlot.repaint();
signalNoiseHistogramPlot.setMyWidth(newWidth);
signalNoiseHistogramPlot.repaint();

convergeRatioLinePlot.setMyWidth(newValue.intValue());
convergeRatioLinePlot.repaint();

observedDataLinePlot.setMyWidth(newWidth);
observedDataLinePlot.repaint();
residualDataLinePlot.setMyWidth(newWidth);
residualDataLinePlot.repaint();
}
});

plotTabPane.heightProperty().addListener(new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
if (newValue.intValue() > 100) {
ratiosHistogramPlot.setMyHeight(newValue.intValue() / ensembleGridPane.getRowCount() - 5);
ratiosHistogramPlot.repaint();
baselineHistogramPlot.setMyHeight(newValue.intValue() / ensembleGridPane.getRowCount() - 5);
baselineHistogramPlot.repaint();
dalyFaradayHistogramPlot.setMyHeight(newValue.intValue() / ensembleGridPane.getRowCount() - 5);
dalyFaradayHistogramPlot.repaint();
intensityLinePlot.setMyHeight(newValue.intValue() / ensembleGridPane.getRowCount() - 5);
intensityLinePlot.repaint();
signalNoiseHistogramPlot.setMyHeight(newValue.intValue() / ensembleGridPane.getRowCount() - 5);
signalNoiseHistogramPlot.repaint();

convergeRatioLinePlot.setMyHeight(newValue.intValue());
convergeRatioLinePlot.repaint();

observedDataLinePlot.setMyHeight(newValue.intValue());
observedDataLinePlot.repaint();
}
plotTabPane.heightProperty().addListener((observable, oldValue, newValue) -> {
if (newValue.intValue() > 100) {
ratiosHistogramPlot.setMyHeight(newValue.intValue() / ensembleGridPane.getRowCount() - 5);
ratiosHistogramPlot.repaint();
baselineHistogramPlot.setMyHeight(newValue.intValue() / ensembleGridPane.getRowCount() - 5);
baselineHistogramPlot.repaint();
dalyFaradayHistogramPlot.setMyHeight(newValue.intValue() / ensembleGridPane.getRowCount() - 5);
dalyFaradayHistogramPlot.repaint();
intensityLinePlot.setMyHeight(newValue.intValue() / ensembleGridPane.getRowCount() - 5);
intensityLinePlot.repaint();
signalNoiseHistogramPlot.setMyHeight(newValue.intValue() / ensembleGridPane.getRowCount() - 5);
signalNoiseHistogramPlot.repaint();

convergeRatioLinePlot.setMyHeight(newValue.intValue());
convergeRatioLinePlot.repaint();

observedDataLinePlot.setMyHeight(newValue.intValue() / dataFitGridPane.getRowCount() - 5);
observedDataLinePlot.repaint();
residualDataLinePlot.setMyHeight(newValue.intValue() / dataFitGridPane.getRowCount() - 5);
residualDataLinePlot.repaint();
}
});

Expand All @@ -216,6 +216,8 @@ public void changed(ObservableValue<? extends Number> observable, Number oldValu

observedDataLinePlot.preparePanel();
dataFitGridPane.add(observedDataLinePlot, 0,0);
residualDataLinePlot.preparePanel();
dataFitGridPane.add(residualDataLinePlot, 0,1);


});
Expand Down
Loading