Skip to content

Commit

Permalink
Merge pull request #1 from laurium-labs/115
Browse files Browse the repository at this point in the history
implements suggestions by Mark on pr #118
  • Loading branch information
markhalonen authored Feb 23, 2021
2 parents 2c1bc0e + ae40d34 commit 0285d64
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ public ArrayList<DataSubset> getDataSubsets(){
private void renderChartData() {
NumberAxis xAxis = new NumberAxis();
NumberAxis yAxis = new NumberAxis();
chart = new LineChartWithMarkers<>(xAxis, yAxis, LineChartWithMarkers.chartDataType.TIME, null, null);
chart = new LineChartWithMarkers<>(xAxis, yAxis, LineChartWithMarkers.chartDataType.TIME, null);

chartAnchorPane.getChildren().clear();
chartAnchorPane.getChildren().add(chart);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public class TrimDataController {

NumberAxis xAxis = new NumberAxis();
NumberAxis yAxis = new NumberAxis();
LineChartWithMarkers<Number, Number> chart = new LineChartWithMarkers<Number, Number>(xAxis, yAxis, null, null, null);
LineChartWithMarkers<Number, Number> chart = new LineChartWithMarkers<Number, Number>(xAxis, yAxis, null, null);
XYChart.Series<Number, Number> expectedPulseSeries;
final ToggleGroup group = new ToggleGroup();
Button getReflectedBeginFromIncidentButton = new Button("Set Begin From Incident and Bar Setup");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,13 @@
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
import net.relinc.viewer.GUI.ChartingPreferences;
import net.relinc.viewer.GUI.HomeController;

import javax.swing.*;

public class LineChartWithMarkers<X,Y> extends LineChart<X,Y> {

public chartDataType xDataType;
public chartDataType yDataType;
public chartType thisChartType;

public enum chartType {
STRESSSTRAIN, STRESSTIME, STRAINTIME, STRAINRATETIME, FACEFORCETIME, LOADDISPLACEMENT, LOADTIME, DISCPLACEMENTTIME, DISPLACEMENTRATETIME;
}

public enum chartDataType {
TIME, DISPLACEMENT, LOAD, STRAINRATE, STRAIN, STRESS, DISPLACEMENTRATE, FACEFORCE;
Expand All @@ -46,15 +40,12 @@ public enum chartDataType {
private ObservableList<Data<X, Y>> verticalMarkers;

private ObservableList<Data<X, X>> verticalRangeMarkers;

public LineChartWithMarkers(Axis<X> xAxis, Axis<Y> yAxis, chartDataType xData, chartDataType yData, chartType type) {
public LineChartWithMarkers(Axis<X> xAxis, Axis<Y> yAxis, chartDataType xData, chartDataType yData) {
super(xAxis, yAxis);

xDataType = xData;
yDataType = yData;

thisChartType = type;

horizontalMarkers = FXCollections.observableArrayList(data -> new Observable[]{data.YValueProperty()});
horizontalMarkers.addListener((InvalidationListener) observable -> layoutPlotChildren());
verticalMarkers = FXCollections.observableArrayList(data -> new Observable[]{data.XValueProperty()});
Expand All @@ -65,10 +56,6 @@ public LineChartWithMarkers(Axis<X> xAxis, Axis<Y> yAxis, chartDataType xData, c
verticalRangeMarkers.addListener((InvalidationListener) observable -> layoutPlotChildren());
}

public chartType getChartType(LineChartWithMarkers chart) {
return chart.thisChartType;
}

public void addHorizontalValueMarker(Data<X, Y> marker) {
Objects.requireNonNull(marker, "the marker must not be null");
if (horizontalMarkers.contains(marker)) return;
Expand Down Expand Up @@ -213,7 +200,8 @@ public void removeVerticalRangeMarker(Data<X, X> marker) {
verticalRangeMarkers.remove(marker);
}

public void chartWithPreferences(ChartingPreferences preference, String defaultTitle) {
public void applyPreferences(ChartingPreferences preference) {
String defaultTitle = this.getDefaultTitle();
if (preference.title == null) {
this.setTitle(defaultTitle);
} else {
Expand Down Expand Up @@ -243,33 +231,36 @@ public void chartWithPreferences(ChartingPreferences preference, String defaultT

private String getDefaultTitle() {
String title = "";
switch (this.thisChartType){
case STRESSSTRAIN:
switch (xDataType) {
case TIME:
switch (yDataType){
case STRESS:
title = "Stress Vs Time";
break;
case STRAIN:
title = "Strain Vs Time";
break;
case STRAINRATE:
title = "Strain Rate Vs Time";
break;
case FACEFORCE:
title = "Face Force Vs Time";
break;
case LOAD:
title = "Load Vs Time";
break;
case DISPLACEMENT:
title = "Displacement Vs Time";
break;
case DISPLACEMENTRATE:
title = "Displacement Rate Vs Time";
}
case STRAIN:
title = "Stress Vs Strain";
break;
case STRESSTIME:
title = "Stress Vs Time";
break;
case STRAINTIME:
title = "Strain Vs Time";
break;
case STRAINRATETIME:
title = "Strain Rate Vs Time";
break;
case FACEFORCETIME:
title = "Face Force Vs Time";
break;
case LOADDISPLACEMENT:
case DISPLACEMENT:
title = "Load Vs Displacement";
break;
case LOADTIME:
title = "Load Vs Time";
break;
case DISCPLACEMENTTIME:
title = "Displacement Vs Time";
break;
case DISPLACEMENTRATETIME:
title = "Displacement Rate Vs Time";
}
return title;
}
Expand Down Expand Up @@ -367,7 +358,7 @@ public void handle(ActionEvent event) {
}
if (changed) {
if (xMax>xMin & yMax>yMin) {
chartWithPreferences(preference, getDefaultTitle());
applyPreferences(preference);
stage.close();
} else {
JOptionPane.showMessageDialog(null,
Expand Down Expand Up @@ -395,7 +386,7 @@ public void handle(ActionEvent event) {
preference.xMax = null;
preference.yMin = null;
preference.yMax = null;
chartWithPreferences(preference, getDefaultTitle());
applyPreferences(preference);
}
});

Expand Down
51 changes: 23 additions & 28 deletions Viewer/src/net/relinc/viewer/GUI/ChartUserPreferences.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package net.relinc.viewer.GUI;

import net.relinc.libraries.application.LineChartWithMarkers.chartType;
import net.relinc.libraries.application.LineChartWithMarkers.chartDataType;

import java.util.Optional;

Expand All @@ -27,36 +27,31 @@ public ChartUserPreferences() {
displacementRateTimePreferences = new ChartingPreferences();
}

public void setPreferences(ChartingPreferences preference, chartType type) {
this.getChartingPreferenceType(type).title = preference.title;
this.getChartingPreferenceType(type).xMin = preference.xMin;
this.getChartingPreferenceType(type).xMax = preference.xMax;
this.getChartingPreferenceType(type).yMin = preference.yMin;
this.getChartingPreferenceType(type).yMax = preference.yMax;
}

public ChartingPreferences getChartingPreferenceType(chartType type) {
switch (type) {
case STRESSSTRAIN:
public ChartingPreferences getChartingPreferenceType(chartDataType xType, chartDataType yType) {
switch (xType) {
case TIME:
switch (yType) {
case STRESS:
return stressTimePreferences;
case STRAIN:
return strainTimePrefrences;
case STRAINRATE:
return strainRateTimePrefrences;
case FACEFORCE:
return faceForceTimePreferences;
case LOAD:
return loadTimePreferences;
case DISPLACEMENT:
return displacementTimePreferences;
case DISPLACEMENTRATE:
return displacementRateTimePreferences;
}
case STRAIN:
return stressStrainPreferences;
case STRESSTIME:
return stressTimePreferences;
case STRAINTIME:
return strainTimePrefrences;
case STRAINRATETIME:
return strainRateTimePrefrences;
case FACEFORCETIME:
return faceForceTimePreferences;
case LOADDISPLACEMENT:
case DISPLACEMENT:
return loadDisplacementPreferences;
case LOADTIME:
return loadTimePreferences;
case DISCPLACEMENTTIME:
return displacementTimePreferences;
case DISPLACEMENTRATETIME:
return displacementRateTimePreferences;
default:
throw new IllegalStateException("Unexpected value: " + type);
throw new IllegalStateException("Unexpected value:" + xType + yType);
}
}
}
Expand Down
53 changes: 26 additions & 27 deletions Viewer/src/net/relinc/viewer/GUI/ChartsGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import javafx.scene.paint.Color;
import net.relinc.libraries.application.LineChartWithMarkers;
import net.relinc.libraries.application.LineChartWithMarkers.chartDataType;
import net.relinc.libraries.application.LineChartWithMarkers.chartType;
import net.relinc.libraries.referencesample.ReferenceSample;
import net.relinc.libraries.referencesample.StressStrainMode;
import net.relinc.libraries.referencesample.StressUnit;
Expand Down Expand Up @@ -117,9 +116,9 @@ public LineChartWithMarkers<Number, Number> getStressTimeChart() {

XAxis.setLabel(xlabel + " " + xUnits);
YAxis.setLabel(yLabel + " " + yUnits);

LineChartWithMarkers<Number, Number> chart = new LineChartWithMarkers<>(XAxis, YAxis, chartDataType.TIME, chartDataType.STRESS, chartType.STRESSTIME);
chart.chartWithPreferences(preference, "Stress Vs Time");
//
LineChartWithMarkers<Number, Number> chart = new LineChartWithMarkers<>(XAxis, YAxis, chartDataType.TIME, chartDataType.STRESS);
chart.applyPreferences(preference);
chart.setCreateSymbols(false);

if(homeController.zoomToROICB.isSelected()){
Expand Down Expand Up @@ -181,9 +180,9 @@ public LineChartWithMarkers<Number, Number> getStrainTimeChart() {

XAxis.setLabel(xlabel + " " + xUnits);
YAxis.setLabel(yLabel + " " + yUnits);

LineChartWithMarkers<Number, Number> chart = new LineChartWithMarkers<>(XAxis, YAxis, chartDataType.TIME, chartDataType.STRAIN, chartType.STRAINTIME);
chart.chartWithPreferences(preference, "Strain Vs Time");
//
LineChartWithMarkers<Number, Number> chart = new LineChartWithMarkers<>(XAxis, YAxis, chartDataType.TIME, chartDataType.STRAIN);
chart.applyPreferences(preference);
chart.setCreateSymbols(false);

if(homeController.zoomToROICB.isSelected()){
Expand Down Expand Up @@ -244,9 +243,9 @@ public LineChartWithMarkers<Number, Number> getStrainRateTimeChart() {
XAxis.setLabel(xlabel + " " + xUnits);
YAxis.setLabel(yLabel + " " + yUnits);


LineChartWithMarkers<Number, Number> chart = new LineChartWithMarkers<>(XAxis, YAxis, chartDataType.TIME, chartDataType.STRAINRATE, chartType.STRAINRATETIME);
chart.chartWithPreferences(preference, "Strain Rate Vs Time");
//
LineChartWithMarkers<Number, Number> chart = new LineChartWithMarkers<>(XAxis, YAxis, chartDataType.TIME, chartDataType.STRAINRATE);
chart.applyPreferences(preference);
chart.setCreateSymbols(false);

if(homeController.zoomToROICB.isSelected()){
Expand Down Expand Up @@ -325,9 +324,9 @@ public LineChartWithMarkers<Number, Number> getStressStrainChart() {

XAxis.setLabel(xlabel + " " + xUnits);
YAxis.setLabel(yLabel + " " + yUnits);

LineChartWithMarkers<Number, Number> chart = new LineChartWithMarkers<>(XAxis, YAxis, chartDataType.STRAIN, chartDataType.STRESS, chartType.STRESSSTRAIN);
chart.chartWithPreferences(preference, "Stress Vs Strain");
//
LineChartWithMarkers<Number, Number> chart = new LineChartWithMarkers<>(XAxis, YAxis, chartDataType.STRAIN, chartDataType.STRESS);
chart.applyPreferences(preference);
chart.setCreateSymbols(false);

getStressStrainSerie(Optional.of(chart));
Expand Down Expand Up @@ -355,9 +354,9 @@ public LineChartWithMarkers<Number, Number> getLoadTimeChart() {

XAxis.setLabel(xlabel + " " + xUnits);
YAxis.setLabel(yLabel + " " + yUnits);

LineChartWithMarkers<Number, Number> chart = new LineChartWithMarkers<>(XAxis, YAxis, chartDataType.TIME, chartDataType.LOAD, chartType.LOADTIME);
chart.chartWithPreferences(preference, "Load Vs Time");
//
LineChartWithMarkers<Number, Number> chart = new LineChartWithMarkers<>(XAxis, YAxis, chartDataType.TIME, chartDataType.LOAD);
chart.applyPreferences(preference);
chart.setCreateSymbols(false);

for(Sample s : getCheckedSamples()){
Expand Down Expand Up @@ -405,9 +404,9 @@ public LineChartWithMarkers<Number, Number> getDisplacementTimeChart() {

XAxis.setLabel(xlabel + " " + xUnits);
YAxis.setLabel(yLabel + " " + yUnits);

LineChartWithMarkers<Number, Number> chart = new LineChartWithMarkers<>(XAxis, YAxis, chartDataType.TIME, chartDataType.DISPLACEMENT, chartType.DISCPLACEMENTTIME);
chart.chartWithPreferences(preference, "Displacement Vs Time");
//
LineChartWithMarkers<Number, Number> chart = new LineChartWithMarkers<>(XAxis, YAxis, chartDataType.TIME, chartDataType.DISPLACEMENT);
chart.applyPreferences(preference);
chart.setCreateSymbols(false);

for(Sample s : getCheckedSamples()){
Expand Down Expand Up @@ -458,9 +457,9 @@ public LineChartWithMarkers<Number, Number> getDisplacementRateTimeChart() {
XAxis.setLabel(xlabel + " " + xUnits);
YAxis.setLabel(yLabel + " " + yUnits);


LineChartWithMarkers<Number, Number> chart = new LineChartWithMarkers<Number, Number>(XAxis, YAxis, chartDataType.TIME, chartDataType.DISPLACEMENTRATE, chartType.DISPLACEMENTRATETIME);
chart.chartWithPreferences(preference, "Displacement Rate Vs Time");
//
LineChartWithMarkers<Number, Number> chart = new LineChartWithMarkers<Number, Number>(XAxis, YAxis, chartDataType.TIME, chartDataType.DISPLACEMENTRATE);
chart.applyPreferences(preference);
chart.setCreateSymbols(false);

double maxPlottedVal = Double.MIN_VALUE;
Expand Down Expand Up @@ -524,8 +523,8 @@ public LineChartWithMarkers<Number, Number> getLoadDisplacementChart() {

XAxis.setLabel(xlabel + " " + xUnits);
YAxis.setLabel(yLabel + " " + yUnits);

LineChartWithMarkers<Number, Number> chart = new LineChartWithMarkers<>(XAxis, YAxis, chartDataType.DISPLACEMENT, chartDataType.LOAD, chartType.LOADDISPLACEMENT);
//
LineChartWithMarkers<Number, Number> chart = new LineChartWithMarkers<>(XAxis, YAxis, chartDataType.DISPLACEMENT, chartDataType.LOAD);
chart.setCreateSymbols(false);

for(Sample s : getCheckedSamples()){
Expand Down Expand Up @@ -579,9 +578,9 @@ public LineChartWithMarkers<Number, Number> getFaceForceTimeChart() {

XAxis.setLabel(xlabel + " " + xUnits);
YAxis.setLabel(yLabel + " " + yUnits);

LineChartWithMarkers<Number, Number> chart = new LineChartWithMarkers<>(XAxis, YAxis, chartDataType.TIME, chartDataType.LOAD, chartType.FACEFORCETIME);
chart.chartWithPreferences(preference, "Face Force Vs Time");
//
LineChartWithMarkers<Number, Number> chart = new LineChartWithMarkers<>(XAxis, YAxis, chartDataType.TIME, chartDataType.LOAD);
chart.applyPreferences(preference);
chart.setCreateSymbols(false);

if(homeController.zoomToROICB.isSelected()){
Expand Down
2 changes: 1 addition & 1 deletion Viewer/src/net/relinc/viewer/GUI/HomeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2681,7 +2681,7 @@ public void handle(MouseEvent mouseEvent) {
return chart;
}
private void editLabels(LineChartWithMarkers<Number, Number> chart) {
ChartingPreferences preference = preferences.getChartingPreferenceType(chart.getChartType(chart));
ChartingPreferences preference = preferences.getChartingPreferenceType(chart.xDataType,chart.yDataType);
chart.showNewLabelsDialog(preference);
}
private void addChartEditingFeatures(LineChartWithMarkers<Number, Number> chart) {
Expand Down

0 comments on commit 0285d64

Please sign in to comment.