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

Plotting progress for 5-isotopes #71

Merged
merged 3 commits into from
Sep 6, 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 @@ -49,8 +49,9 @@ public abstract class AbstractDataView extends Canvas {
protected BigDecimal[] ticsX;
protected BigDecimal[] ticsY;
// protected BigDecimal[] ticsYII;
private double displayOffsetY = 0;
private double displayOffsetX = 0;
protected double displayOffsetY = 0;
protected double displayOffsetX = 0;
protected String xAxisLabel;

private AbstractDataView() {
super();
Expand Down Expand Up @@ -108,9 +109,9 @@ public void labelXAxis(String label) {

public void showTitle(String title) {
Paint savedPaint = getGraphicsContext2D().getFill();
getGraphicsContext2D().setFont(Font.font("SansSerif", 14));
getGraphicsContext2D().setFont(Font.font("SansSerif", 10));
getGraphicsContext2D().setFill(Paint.valueOf("RED"));
getGraphicsContext2D().fillText(title, leftMargin + 25, topMargin + 12);
getGraphicsContext2D().fillText(title, leftMargin + 25, topMargin + 7);
getGraphicsContext2D().setFill(savedPaint);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void paint(GraphicsContext g2d) {
g2d.beginPath();
g2d.setStroke(Paint.valueOf("Blue"));
g2d.setLineDashes(0);
// x = magnetMass y = intensity
// x = magnetMass y = blockIntensities

for (int i = 0; i < xMass.length; i++) {
g2d.lineTo(mapX(xMass[i]), mapY(yIntensity[i]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@ public void preparePanel() {
minX = xAxisData[0];
maxX = xAxisData[xAxisData.length - 1];
if (histogramBuilder.getHistograms().length > 1) {
// assume only 2 for now
minX = Math.min(minX, histogramBuilder.getHistograms()[1].binCenters()[0]);
maxX = Math.max(maxX, histogramBuilder.getHistograms()[1].binCenters()[histogramBuilder.getHistograms()[1].binCount() - 1]);
for (int histogramIndex = 0; histogramIndex < histogramBuilder.getHistograms().length; histogramIndex++) {
minX = Math.min(minX, histogramBuilder.getHistograms()[histogramIndex].binCenters()[0]);
maxX = Math.max(maxX, histogramBuilder.getHistograms()[histogramIndex].binCenters()[histogramBuilder.getHistograms()[histogramIndex].binCount() - 1]);
}
}

double xMarginStretch = TicGeneratorForAxes.generateMarginAdjustment(minX, maxX, 0.05);
double xMarginStretch = TicGeneratorForAxes.generateMarginAdjustment(minX, maxX, 0.25);
minX -= xMarginStretch;
maxX += xMarginStretch;
ticsX = TicGeneratorForAxes.generateTics(minX, maxX, (int) (graphWidth / 40.0));
Expand All @@ -64,16 +65,17 @@ public void preparePanel() {
maxY = StrictMath.max(maxY, yAxisDatum);
}
if (histogramBuilder.getHistograms().length > 1) {
// assume only 2 for now
for (double yAxisDatum : histogramBuilder.getHistograms()[1].binCounts()) {
minY = StrictMath.min(minY, yAxisDatum);
maxY = StrictMath.max(maxY, yAxisDatum);
for (int histogramIndex = 0; histogramIndex < histogramBuilder.getHistograms().length; histogramIndex++) {
for (double yAxisDatum : histogramBuilder.getHistograms()[histogramIndex].binCounts()) {
minY = StrictMath.min(minY, yAxisDatum);
maxY = StrictMath.max(maxY, yAxisDatum);
}
}
}

// customized for histogram
minY = 0;
ticsY = TicGeneratorForAxes.generateTics(minY, maxY, (int) (graphHeight / 10.0));
ticsY = TicGeneratorForAxes.generateTics(minY, maxY, (int) (graphHeight / 20.0));

// check for no data
if ((ticsY != null) && (ticsY.length > 1)) {
Expand Down Expand Up @@ -111,11 +113,15 @@ public void paint(GraphicsContext g2d) {

if (histogramBuilder.getHistograms().length > 1) {
g2d.setFill(Paint.valueOf("GREEN"));
xAxisData = histogramBuilder.getHistograms()[1].binCenters();
yAxisData = histogramBuilder.getHistograms()[1].binCounts();
binWidth = histogramBuilder.getHistograms()[1].binWidth();
doFrameBins = (mapX(xAxisData[1]) - mapX(xAxisData[0])) > 1.0;
plotData(g2d, binWidth, doFrameBins);

for (int histogramIndex = 0; histogramIndex < histogramBuilder.getHistograms().length; histogramIndex++) {
xAxisData = histogramBuilder.getHistograms()[histogramIndex].binCenters();
yAxisData = histogramBuilder.getHistograms()[histogramIndex].binCounts();
binWidth = histogramBuilder.getHistograms()[histogramIndex].binWidth();
doFrameBins = (mapX(xAxisData[1]) - mapX(xAxisData[0])) > 1.0;
plotData(g2d, binWidth, doFrameBins);
}

xAxisData = histogramBuilder.getHistograms()[0].binCenters();
yAxisData = histogramBuilder.getHistograms()[0].binCounts();
}
Expand Down Expand Up @@ -143,7 +149,7 @@ public void paint(GraphicsContext g2d) {
text.setText(bigDecimal.toString());
textWidth = (int) text.getLayoutBounds().getWidth();
g2d.fillText(text.getText(),//
(float) mapX(minX) - textWidth - 5f,
(float) mapX(minX) - textWidth - 2.5f,
(float) mapY(bigDecimal.doubleValue()) + verticalTextShift);

// right side
Expand Down Expand Up @@ -181,7 +187,7 @@ private void plotData(GraphicsContext g2d, double binWidth, boolean doFrameBins)
g2d.fillRect(
mapX(xAxisData[i] - binWidth / 2.0) + (doFrameBins ? 1.0 : 0.0),
mapY(yAxisData[i]),
mapX(xAxisData[1]) - mapX(xAxisData[0]) - (doFrameBins ? 1.0 : 0.0),
mapX(xAxisData[1]) - mapX(xAxisData[0]) - (doFrameBins ? 1.0 : -0.5),
mapY(0.0) - mapY(yAxisData[i]));
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
package org.cirdles.tripoli.gui.dataViews.plots;

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


public class MultiLineLinePlot extends AbstractDataView {

private final MultiLinePlotBuilder multiLinePlotBuilder;
private double[][] yData;

/**
* @param bounds
* @param linePlotBuilder
*/
public MultiLineLinePlot(Rectangle bounds, MultiLinePlotBuilder multiLinePlotBuilder) {
super(bounds, 50, 5);
this.multiLinePlotBuilder = multiLinePlotBuilder;
}

@Override
public void preparePanel() {
xAxisData = multiLinePlotBuilder.getxData();
yData = multiLinePlotBuilder.getyData();

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 < yData.length; i++) {
for (int j = 0; j < yData[i].length; j++) {
minY = StrictMath.min(minY, yData[i][j]);
maxY = StrictMath.max(maxY, yData[i][j]);
}
}
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;

showTitle(multiLinePlotBuilder.getTitle());

// new line plots
g2d.setLineWidth(1.0);
g2d.setStroke(Paint.valueOf("Black"));
for (int lineIndex = 0; lineIndex < yData.length; lineIndex++) {
g2d.setLineDashes(8);
g2d.beginPath();
g2d.moveTo(mapX(xAxisData[0]), mapY(yData[lineIndex][0]));
for (int i = 0; i < xAxisData.length; i++) {
// line tracing through points
g2d.lineTo(mapX(xAxisData[i]), mapY(yData[lineIndex][i]));
}
g2d.stroke();
}
g2d.setLineDashes(0);

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 @@ -86,7 +86,7 @@ public void paint(GraphicsContext g2d) {
g2d.beginPath();
g2d.setStroke(Paint.valueOf("Black"));
g2d.setLineDashes(0);
// x = magnetMass y = intensity
// x = magnetMass y = blockIntensities

for (int i = 0; i < xAxisData.length; i++) {
g2d.lineTo(mapX(xAxisData[i]), mapY(yAxisData[i]));
Expand Down Expand Up @@ -216,4 +216,4 @@ public void handle(MouseEvent mouseEvent) {
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import javafx.scene.layout.GridPane;
import javafx.scene.layout.VBox;
import javafx.scene.shape.Rectangle;
import org.cirdles.commons.util.ResourceExtractor;
import org.cirdles.tripoli.Tripoli;
import org.cirdles.tripoli.gui.dataViews.plots.*;
import org.cirdles.tripoli.sessions.analysis.methods.AnalysisMethod;
import org.cirdles.tripoli.sessions.analysis.methods.AnalysisMethodBuiltinFactory;
Expand Down Expand Up @@ -99,28 +101,35 @@ public class RJMCMCPlotsController {
@FXML
private Button processFileButton;

@FXML
private Button processFileButton2;

@FXML
private ToolBar toolbar;

private ListView<File> listViewOfSyntheticFiles = new ListView<>();


@FXML
void demo1ButtonAction(ActionEvent event) throws IOException {
void demo1_2IsotopeButtonAction(ActionEvent event) throws IOException {
processDataFileAndShowPlotsOfRJMCMC(
listViewOfSyntheticFiles.getSelectionModel().selectedItemProperty().getValue().toPath(),
AnalysisMethodBuiltinFactory.analysisMethodsBuiltinMap.get("BurdickBlSyntheticData"));

((Button) event.getSource()).setDisable(true);
processFileButton2.setDisable(true);
}
@FXML
void demo1_5IsotopeButtonAction(ActionEvent event) throws IOException {
// Jim's playground for 5 isotopes
// ResourceExtractor RESOURCE_EXTRACTOR= new ResourceExtractor(Tripoli.class);
// Path dataFile = RESOURCE_EXTRACTOR
// .extractResourceAsFile("/org/cirdles/tripoli/dataProcessors/dataSources/synthetic/fiveIsotopeSyntheticData/SyntheticDataset_01R.txt").toPath();
// processDataFileAndShowPlotsOfRJMCMC(
// dataFile,
// AnalysisMethodBuiltinFactory.analysisMethodsBuiltinMap.get("KU_204_5_6_7_8_Daly_AllFaradayPb"));

ResourceExtractor RESOURCE_EXTRACTOR = new ResourceExtractor(Tripoli.class);
Path dataFile = RESOURCE_EXTRACTOR
.extractResourceAsFile("/org/cirdles/tripoli/dataProcessors/dataSources/synthetic/fiveIsotopeSyntheticData/SyntheticDataset_01R.txt").toPath();
processDataFileAndShowPlotsOfRJMCMC(
dataFile,
AnalysisMethodBuiltinFactory.analysisMethodsBuiltinMap.get("KU_204_5_6_7_8_Daly_AllFaradayPb"));

((Button) event.getSource()).setDisable(true);
processFileButton.setDisable(true);
}

@FXML
Expand Down Expand Up @@ -159,6 +168,7 @@ void initialize() {
populateListOfSyntheticData2IsotopesFiles();

processFileButton.setDisable(listViewOfSyntheticFiles.getItems().isEmpty());
processFileButton2.setDisable(listViewOfSyntheticFiles.getItems().isEmpty());
}

private void populateListOfSyntheticData2IsotopesFiles() {
Expand Down Expand Up @@ -242,10 +252,10 @@ public void processDataFileAndShowPlotsOfRJMCMC(Path dataFile, AnalysisMethod an
(plotTabPane.getHeight() - TAB_HEIGHT) / ensembleGridPane.getRowCount()),
(HistogramBuilder) dalyFaradayHistogramBuilder);

AbstractDataView intensityLinePlot = new BasicLinePlot(
AbstractDataView intensityLinePlot = new MultiLineLinePlot(
new Rectangle(ensembleGridPane.getWidth(),
(plotTabPane.getHeight() - TAB_HEIGHT) / ensembleGridPane.getRowCount()),
(LinePlotBuilder) intensityLinePlotBuilder
(MultiLinePlotBuilder) intensityLinePlotBuilder
);

AbstractDataView signalNoiseHistogramPlot = new HistogramPlot(
Expand Down Expand Up @@ -400,7 +410,7 @@ public void processDataFileAndShowPlotsOfRJMCMC(Path dataFile, AnalysisMethod an
intensityLinePlot.preparePanel();
ensembleGridPane.add(intensityLinePlot, 0, 2, 2, 1);
signalNoiseHistogramPlot.preparePanel();
ensembleGridPane.add(signalNoiseHistogramPlot, 0, 4, 2, 1);
ensembleGridPane.add(signalNoiseHistogramPlot, 0, 3, 2, 1);

convergeRatioLinePlot.preparePanel();
convergeRatioAnchorPane.getChildren().add(convergeRatioLinePlot);
Expand Down
Loading