-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into peak-cleanup
- Loading branch information
Showing
24 changed files
with
458 additions
and
232 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 141 additions & 0 deletions
141
TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/MultiLineLinePlot.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.