Commit 3725f2d2 authored by Aaron Bray's avatar Aaron Bray
Browse files

Update plotter for new hemorrhage plots and add legend font size control

parent 05f45199
......@@ -119,5 +119,9 @@ elseif(TYPE STREQUAL "FullReport")
elseif(TYPE STREQUAL "plotter")
execute_process(COMMAND "${Java_JAVA_EXECUTABLE}" -classpath "${JAVA_CLASSPATH}" pulse.utilities.csv.plots.CSVPlotTool ${ARG1})
else()
execute_process(COMMAND "${Java_JAVA_EXECUTABLE}" -classpath "${JAVA_CLASSPATH}" pulse.cdm.testing.SETestDriver ${TYPE}.config)
if(${TYPE} MATCHES "Plot")
execute_process(COMMAND "${Java_JAVA_EXECUTABLE}" -classpath "${JAVA_CLASSPATH}" pulse.utilities.csv.plots.PlotDriver ${TYPE}.config)
else()
execute_process(COMMAND "${Java_JAVA_EXECUTABLE}" -classpath "${JAVA_CLASSPATH}" pulse.cdm.testing.SETestDriver ${TYPE}.config)
endif()
endif()
......@@ -17,7 +17,9 @@
# ImageDimensions - Specify the image width and height in pixels (i.e. ImageDimesions=1600,800) Default is 1600x800, but ActionEventPlots can stretch automatically
# RemoveLegends - Removes all legends from the generated plot
# FontSize - Set the font size of axis labels and chart title (FontSize=22 by default)
# LegendFontSize - Set the font size of the legend (LegendFontSize=15 by default)
# OutputFilename - Set the desired filename for the generated plot (no spaces allowed; will default to the chart title if nothing is set for this)
# PercentOfBaseline - All values will be set to Value@TimeX / Values@Time0
#FLAGS FOR ACTIONEVENTPLOTTER ONLY
# Header - Specify the header(s) that you want to plot on the Y axis
......@@ -51,11 +53,13 @@ Plotter=pulse.utilities.csv.plots.ActionEventPlotter
Plotter=pulse.utilities.csv.plots.MultiPlotter
Plotter=pulse.utilities.csv.plots.ConvexHullPlotter
Plotter=pulse.utilities.csv.plots.RespiratoryPFTPlotter
Plotter=pulse.utilities.csv.plots.MultiSourcePlotter
#ScenarioName=PlotterType Flag1=Stuff Flag2=Stuff Flag3 FlagN
#PralidoximeValidation=ActionEventPlotter Title=Pralidoxime NoActions NoEvents LogAxis Header=Pralidoxime-PlasmaConcentration(ug/L) DataPathOverride=./Scenarios/Validation/ DataFileOverride=PralidoximeValidationResults.csv ExperimentalData=../docs/Validation/Pharmacokinetic/CSVs/Pralidoxime.csv OutputOverride=..\docs\Doxygen\html\plots\Drugs
#VentricularSystolicDysfunction=ActionEventPlotter NoGrid Title=None Header=BloodVolume(L) OutputOverride=./docs/html/plots/Cardiovascular OutputFilename=HeartFailure.jpg
#CardiacShock=MultiPlotter X1Label=Percent_Of_Blood_Loss X1=BloodVolume(L) Y1=CardiacOutput(L/min) Y1LowerBound=0 X2=BloodVolume(L) Y2=MeanArterialPressure(mmHg) Y2LowerBound=0 X1LowerBound=0 X1UpperBound=0.5 DataPathVerificationOverride=scenarios/patient/ Title=None DataFileOverride=HemorrhageClass4NoFluidResults.csv OutputOverride=./docs/html/plots/Cardiovascular OutputFilename=CardiacShock.jpg
RespiratoryValidation=RespiratoryPFTPlotter Header=TotalLungVolume(mL) VerificationDir=validation/systems/ PFTFile=RespiratoryValidationPFT@120.02s.json Title=Pulmonary_Function_Test_Results OutputOverride=./docs/html/plots/Respiratory/
#RespiratoryValidation=RespiratoryPFTPlotter Header=TotalLungVolume(mL) VerificationDir=validation/systems/ PFTFile=RespiratoryValidationPFT@120.02s.json Title=Pulmonary_Function_Test_Results OutputOverride=./docs/html/plots/Respiratory/
CardiacShock=MultiPlotter Title=Cardiovascular_Response_To_Hemorrhage PercentOfBaseline X1Label=Percent_Of_Blood_Loss X1=BloodVolume(L) Y1=CardiacOutput(L/min) Y1LowerBound=0 X2=BloodVolume(L) Y2=MeanArterialPressure(mmHg) Y2LowerBound=0 X1LowerBound=0 X1UpperBound=50 DataPathVerificationOverride=scenarios/patient/ Title=None DataFileOverride=HemorrhageClass4NoFluidResults.csv OutputOverride=./docs/html/plots/Cardiovascular OutputFilename=CardiacShock.jpg
HemorrhageGroups=MultiSourcePlotter Title=Cardiovascular_Hemorrhage_Groups PercentOfBaseline X1=Time(s) Y1=MeanArterialPressure(mmHg) Y1Label=Mean_Arterial_Pressure_Delta Y1LowerBound=0 Y1UpperBound=100 DataPathVerificationOverride=scenarios/patient/ Title=None DataFileOverride=HemorrhageGroup1Results.csv,HemorrhageGroup2Results.csv,HemorrhageGroup3Results.csv,HemorrhageGroup4Results.csv,HemorrhageGroup5Results.csv,HemorrhageGroup6Results.csv OutputOverride=./docs/html/plots/Cardiovascular OutputFilename=HemorrhageGroups.jpg
......@@ -18,7 +18,9 @@
# ImageDimensions - Specify the image width and height in pixels (i.e. ImageDimesions=1600,800) Default is 1600x800, but ActionEventPlots can stretch automatically
# RemoveLegends - Removes all legends from the generated plot
# FontSize - Set the font size of axis labels and chart title (FontSize=22 by default)
# LegendFontSize - Set the font size of the legend (LegendFontSize=15 by default)
# OutputFilename - Set the desired filename for the generated plot (no spaces allowed; will default to the chart title if nothing is set for this)
# PercentOfBaseline - All values will be set to Value@TimeX / Values@Time0
#FLAGS FOR ACTIONEVENTPLOTTER ONLY
# Header - Specify the header(s) that you want to plot on the Y axis
......@@ -52,6 +54,7 @@ Plotter=pulse.utilities.csv.plots.ActionEventPlotter
Plotter=pulse.utilities.csv.plots.MultiPlotter
Plotter=pulse.utilities.csv.plots.ConvexHullPlotter
Plotter=pulse.utilities.csv.plots.RespiratoryPFTPlotter
Plotter=pulse.utilities.csv.plots.MultiSourcePlotter
########## Physiologic Systems ##########
......@@ -82,6 +85,8 @@ HemorrhageClass4NoFluid=ActionEventPlotter Header=BloodVolume(L) OutputOverride=
HemorrhageClass2Saline=ActionEventPlotter NoGrid Title=None RemoveLegends Header=BloodVolume(L) OutputOverride=./docs/html/plots/Cardiovascular ImageDimensions=1100,700 OutputFilename=Class2Saline_BloodVolume.jpg
HemorrhageClass2Saline=ActionEventPlotter NoGrid Title=None RemoveLegends Header=HemoglobinContent(g) OutputOverride=./docs/html/plots/Cardiovascular ImageDimensions=1100,700 OutputFilename=Class2Saline_Hb.jpg
HemorrhageClass2Saline=ActionEventPlotter Header=BloodVolume(L) OutputOverride=./docs/html/plots/Cardiovascular LegendOnly NoEvents ImageDimensions=2000,150 OutputFilename=Class2Saline_Legend.jpg
CardiacShock=MultiPlotter Title=Cardiovascular_Response_To_Hemorrhage PercentOfBaseline X1Label=Percent_Of_Blood_Loss X1=BloodVolume(L) Y1=CardiacOutput(L/min) Y1LowerBound=0 X2=BloodVolume(L) Y2=MeanArterialPressure(mmHg) Y2LowerBound=0 X1LowerBound=0 X1UpperBound=50 DataPathVerificationOverride=scenarios/patient/ Title=None DataFileOverride=HemorrhageClass4NoFluidResults.csv OutputOverride=./docs/html/plots/Cardiovascular OutputFilename=CardiacShock.jpg
HemorrhageGroups=MultiSourcePlotter Title=Cardiovascular_Hemorrhage_Groups PercentOfBaseline X1=Time(s) Y1=MeanArterialPressure(mmHg) Y1Label=Mean_Arterial_Pressure_Delta Y1LowerBound=0 Y1UpperBound=100 DataPathVerificationOverride=scenarios/patient/ Title=None DataFileOverride=HemorrhageGroup1Results.csv,HemorrhageGroup2Results.csv,HemorrhageGroup3Results.csv,HemorrhageGroup4Results.csv,HemorrhageGroup5Results.csv,HemorrhageGroup6Results.csv OutputOverride=./docs/html/plots/Cardiovascular OutputFilename=HemorrhageGroups.jpg
#CardiovascularValidation=MultiPlotter Y1=RightHeart-Volume(mL),LeftHeart-Volume(mL),VenaCava-Volume(mL),PulmonaryArteries-Volume(mL),PulmonaryCapillaries-Volume(mL),PulmonaryVeins-Volume(mL),RightArmVasculature-Volume(mL),RightLegVasculature-Volume(mL),LeftArmVasculature-Volume(mL),LeftLegVasculature-Volume(mL),BrainVasculature-Volume(mL),LiverVasculature-Volume(mL),KidneyVasculature-Volume(mL),Aorta-Volume(mL),MyocardiumVasculature-Volume(mL),SplanchnicVasculature-Volume(mL),SkinVasculature-Volume(mL),FatVasculature-Volume(mL) X1=Time(s) VerificationDir=validation/systems/ Title=Blood_Compartment_Volumes Y1Label=BloodVolume(mL) OutputOverride=./docs/html/plots/Cardiovascular
#heart faliure
VentricularSystolicDysfunction=ActionEventPlotter NoGrid Title=None Header=BloodVolume(L) OutputOverride=./docs/html/plots/Cardiovascular OutputFilename=HeartFailure.jpg
......@@ -190,7 +195,7 @@ HighAltitudeEnvironmentChange=ActionEventPlotter NoGrid Title=None NoActions Hea
HighAltitudeEnvironmentChange=ActionEventPlotter NoGrid NoActions Title=None Header=GlomerularFiltrationRate(mL/min) VerificationDir=energyenvironment FontSize=17 RemoveLegends ImageDimensions=800,400 OutputOverride=./docs/html/plots/Renal/ OutputFilename=AltitudeGFR.jpg
HighAltitudeEnvironmentChange=ActionEventPlotter NoGrid NoActions Title=None Header=RenalBloodFlow(L/min) VerificationDir=energyenvironment RemoveLegends FontSize=17 OutputOverride=./docs/html/plots/Renal/ ImageDimensions=800,400 OutputFilename=AltitudeRBF.jpg
HighAltitudeEnvironmentChange=ActionEventPlotter NoGrid NoActions Title=None Header=RightAfferentArterioleResistance(mmHg_min/mL) VerificationDir=energyenvironment FontSize=17 RemoveLegends OutputOverride=./docs/html/plots/Renal/ ImageDimensions=800,400 OutputFilename=AltitudeArterioleResistance.jpg
HighAltitudeEnvironmentChange=ActionEventPlotter LegendOnly NoActions Header=RightAfferentArterioleResistance(mmHg_min/mL) Title=HighAltitudeEnvironmentChangeLegend VerificationDir=energyenvironment OutputOverride=./docs/html/plots/Renal/ NoEvents ImageDimensions=800,400
HighAltitudeEnvironmentChange=ActionEventPlotter LegendOnly ActionsOnly Header=RightAfferentArterioleResistance(mmHg_min/mL) Title=HighAltitudeEnvironmentChangeLegend VerificationDir=energyenvironment OutputOverride=./docs/html/plots/Renal/ NoEvents ImageDimensions=480,300
12hrFast=ActionEventPlotter Header=Bladder-Volume(mL) VerificationDir=miscellaneous RemoveLegends OutputOverride=./docs/html/plots/Renal OutputFilename=12hr_Urination.jpg
RenalTGFFeedbackOutput=MultiPlotter Y1=GlomerularFiltrationRate(L/min) FontSize=34 X1=MeanArterialPressure(mmHg) Title=None ValidationData=Renal/MAP_vs_GFR.csv DataPathVerificationOverride=unit_tests/pulse/ X2=MeanArterialPressure(mmHg) OutputOverride=./docs/html/plots/Renal/ Y2=GlomerularFiltrationRate(L/min) X1LowerBound=60 X1UpperBound=200 Y1LowerBound=.09 Y2LowerBound=.09 Y1UpperBound=.16 Y2UpperBound=.16 OutputOverride=./docs/html/plots/Renal/ NoGrid RemoveLegends DataFileOverride=RenalTGFFeedbackOutput.csv OutputFilename=MAP_vs_GFR.jpg
RenalTGFFeedbackOutput=MultiPlotter Y1=RenalBloodFlow(L/min) X1=MeanArterialPressure(mmHg) Title=None FontSize=34 ValidationData=Renal/MAP_vs_RBF.csv DataPathVerificationOverride=unit_tests/pulse/ X2=MeanArterialPressure(mmHg) Y2=RenalBloodFlow(L/min) X1LowerBound=60 X1UpperBound=200 Y1LowerBound=1 Y2LowerBound=1 Y1UpperBound=1.7 Y2UpperBound=1.7 OutputOverride=./docs/html/plots/Renal/ NoGrid RemoveLegends OutputOverride=./docs/html/plots/Renal/ DataFileOverride=RenalTGFFeedbackOutput.csv OutputFilename=MAP_vs_RBF.jpg
......
......@@ -4,6 +4,7 @@
"PatientConfiguration": { "PatientFile": "StandardMale.json" },
"DataRequestManager":
{
"SamplesPerSecond": 1.0,
"DataRequest":
[
{ "DecimalFormat": { "Precision": 1 }, "PropertyName": "Weight", "Unit": "kg" },
......@@ -75,7 +76,7 @@
"AdvanceTime": {
"Time": {
"ScalarTime": {
"Value": 14000.0,
"Value": 3000.0,
"Unit": "s"
}
}
......
......@@ -4,6 +4,7 @@
"PatientConfiguration": { "PatientFile": "StandardMale.json" },
"DataRequestManager":
{
"SamplesPerSecond": 1.0,
"DataRequest":
[
{ "DecimalFormat": { "Precision": 1 }, "PropertyName": "Weight", "Unit": "kg" },
......@@ -75,7 +76,7 @@
"AdvanceTime": {
"Time": {
"ScalarTime": {
"Value": 14000.0,
"Value": 3000.0,
"Unit": "s"
}
}
......
......@@ -4,6 +4,7 @@
"PatientConfiguration": { "PatientFile": "StandardMale.json" },
"DataRequestManager":
{
"SamplesPerSecond": 1.0,
"DataRequest":
[
{ "DecimalFormat": { "Precision": 1 }, "PropertyName": "Weight", "Unit": "kg" },
......@@ -75,7 +76,7 @@
"AdvanceTime": {
"Time": {
"ScalarTime": {
"Value": 14000.0,
"Value": 3000.0,
"Unit": "s"
}
}
......
......@@ -4,6 +4,7 @@
"PatientConfiguration": { "PatientFile": "StandardMale.json" },
"DataRequestManager":
{
"SamplesPerSecond": 1.0,
"DataRequest":
[
{ "DecimalFormat": { "Precision": 1 }, "PropertyName": "Weight", "Unit": "kg" },
......@@ -75,7 +76,7 @@
"AdvanceTime": {
"Time": {
"ScalarTime": {
"Value": 14000.0,
"Value": 3000.0,
"Unit": "s"
}
}
......
......@@ -4,6 +4,7 @@
"PatientConfiguration": { "PatientFile": "StandardMale.json" },
"DataRequestManager":
{
"SamplesPerSecond": 1.0,
"DataRequest":
[
{ "DecimalFormat": { "Precision": 1 }, "PropertyName": "Weight", "Unit": "kg" },
......@@ -75,7 +76,7 @@
"AdvanceTime": {
"Time": {
"ScalarTime": {
"Value": 14000.0,
"Value": 3000.0,
"Unit": "s"
}
}
......
......@@ -4,6 +4,7 @@
"PatientConfiguration": { "PatientFile": "StandardMale.json" },
"DataRequestManager":
{
"SamplesPerSecond": 1.0,
"DataRequest":
[
{ "DecimalFormat": { "Precision": 1 }, "PropertyName": "Weight", "Unit": "kg" },
......@@ -75,7 +76,7 @@
"AdvanceTime": {
"Time": {
"ScalarTime": {
"Value": 14000.0,
"Value": 3000.0,
"Unit": "s"
}
}
......
......@@ -43,6 +43,6 @@ public class ReduceCSV
}
}
bIn.close();
bOut.close();
bOut.close();
}
}
......@@ -50,7 +50,6 @@ import pulse.cdm.substance.SESubstanceManager;
import pulse.utilities.DoubleUtils;
import pulse.utilities.FileUtils;
import pulse.utilities.Log;
import pulse.utilities.LogListener;
import pulse.utilities.csv.CSVContents;
import pulse.utilities.csv.plots.PlotDriver.PlotJob;
......@@ -67,10 +66,9 @@ public class ActionEventPlotter implements Plotter
PlotDriver.main(args);
}
public void plot(LogListener listener, SESubstanceManager subMgr)
public void plot(PlotJob job, SESubstanceManager subMgr)
{
//fill PlotJob with needed data if it doesn't exist
PlotJob job = (PlotJob)listener;
if(job.dataPath == null || job.dataPath.isEmpty())
{job.dataPath = job.verificationDirectory+"/";}
if(job.logPath == null || job.logPath.isEmpty())
......@@ -704,8 +702,9 @@ public class ActionEventPlotter implements Plotter
plot.setDomainCrosshairVisible(true);
plot.setRangeCrosshairVisible(true);
chart.getLegend().setItemFont(new Font("SansSerif", Font.PLAIN, 15));
XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
renderer.setBaseLegendTextFont(new Font("SansSerif", Font.PLAIN, job.legendFontSize));
chart.getTitle().setFont(new Font("SansSerif", Font.PLAIN, job.fontSize));
chart.getTitle().setPaint(job.bgColor==Color.red?Color.white:Color.black);
}
......
......@@ -31,7 +31,6 @@ import pulse.cdm.substance.SESubstanceManager;
import pulse.utilities.DoubleUtils;
import pulse.utilities.FileUtils;
import pulse.utilities.Log;
import pulse.utilities.LogListener;
import pulse.utilities.csv.CSVContents;
import pulse.utilities.csv.ConvexHullMaker;
import pulse.utilities.csv.plots.PlotDriver.PlotJob;
......@@ -103,10 +102,9 @@ public class ConvexHullPlotter implements Plotter
return splitVals;
}
public void plot(LogListener listener, SESubstanceManager subMgr)
public void plot(PlotJob job, SESubstanceManager subMgr)
{
//fill PlotJob with needed data if it doesn't exist
PlotJob job = (PlotJob)listener;
if(job.dataPath == null || job.dataPath.isEmpty())
{job.dataPath = job.verificationDirectory+"/";}
if(job.dataFile == null || job.dataFile.isEmpty())
......@@ -439,7 +437,7 @@ public class ConvexHullPlotter implements Plotter
plot.setDomainCrosshairVisible(true);
plot.setRangeCrosshairVisible(true);
chart.getLegend().setItemFont(new Font("SansSerif", Font.PLAIN, 15));
renderer1.setBaseLegendTextFont(new Font("SansSerif", Font.PLAIN, job.legendFontSize));
chart.getTitle().setFont(new Font("SansSerif", Font.PLAIN, job.fontSize));
chart.getTitle().setPaint(job.bgColor==Color.red?Color.white:Color.black);
......@@ -460,6 +458,7 @@ public class ConvexHullPlotter implements Plotter
else
{
StandardXYItemRenderer renderer2 = new StandardXYItemRenderer();
renderer2.setBaseLegendTextFont(new Font("SansSerif", Font.PLAIN, job.legendFontSize));
plot.setRenderer(1, renderer2);
for(int i = 0; i < dataSet1.getSeriesCount(); i++)
......
......@@ -31,7 +31,6 @@ import pulse.cdm.substance.SESubstanceManager;
import pulse.utilities.DoubleUtils;
import pulse.utilities.FileUtils;
import pulse.utilities.Log;
import pulse.utilities.LogListener;
import pulse.utilities.csv.CSVContents;
import pulse.utilities.csv.plots.PlotDriver.PlotJob;
......@@ -46,10 +45,9 @@ public class MultiPlotter implements Plotter
}
@Override
public void plot(LogListener listener, SESubstanceManager subMgr)
public void plot(PlotJob job, SESubstanceManager subMgr)
{
//fill PlotJob with needed data if it doesn't exist
PlotJob job = (PlotJob)listener;
if(job.dataPath == null || job.dataPath.isEmpty())
{job.dataPath = job.verificationDirectory+"/";}
if(job.dataFile == null || job.dataFile.isEmpty())
......@@ -64,10 +62,25 @@ public class MultiPlotter implements Plotter
csv.abreviateContents = job.resultsSkipNum;
for (int i = 0; i < job.headers.size(); i++)
{
if(data.containsKey(job.headers.get(i)))
continue;
List<Double> headerData = new ArrayList<Double>();
csv.readHeader(csv.unitUnderscoreToSpace(job.headers.get(i)), headerData);
if(job.percentOfBaseline)
{
double baseline = headerData.get(0);
boolean invertX = job.headers.get(i).contentEquals(job.X1header);
for(int j=0; j < headerData.size(); j++)
{
if(invertX)// And convert to %
headerData.set(j, (1-(headerData.get(j)/baseline))*100);
else
headerData.set(j, headerData.get(j)/baseline);
}
}
data.put(job.headers.get(i), headerData);
}
}
} catch (IOException e)
{
Log.error("Could not analyze file " + job.dataPath + job.dataFile);
......@@ -174,7 +187,7 @@ public class MultiPlotter implements Plotter
//set labels
String XAxisLabel = job.X1header;
String YAxisLabel = job.Y1headers.get(0);
JFreeChart chart = ChartFactory.createXYLineChart(
job.titleOverride!=null&&job.titleOverride.equalsIgnoreCase("None")?"":title, // chart title
XAxisLabel, // x axis label
......@@ -186,7 +199,7 @@ public class MultiPlotter implements Plotter
false // urls
);
Log.info("Creating Graph "+title);
Log.info("Creating Graph "+title);
XYPlot plot = (XYPlot) chart.getPlot();
if (!job.logAxis)
......@@ -398,7 +411,7 @@ public class MultiPlotter implements Plotter
plot.setDomainCrosshairVisible(true);
plot.setRangeCrosshairVisible(true);
chart.getLegend().setItemFont(new Font("SansSerif", Font.PLAIN, 15));
renderer1.setBaseLegendTextFont(new Font("SansSerif", Font.PLAIN, job.legendFontSize));
chart.getTitle().setFont(new Font("SansSerif", Font.PLAIN, job.fontSize));
chart.getTitle().setPaint(job.bgColor==Color.red?Color.white:Color.black);
......@@ -418,6 +431,7 @@ public class MultiPlotter implements Plotter
else
{
StandardXYItemRenderer renderer2 = new StandardXYItemRenderer();
renderer2.setBaseLegendTextFont(new Font("SansSerif", Font.PLAIN, job.legendFontSize));
plot.setRenderer(1, renderer2);
for(int i = 0, cIndex = 0; i < dataSet1.getSeriesCount(); i++, cIndex++)
......
package pulse.utilities.csv.plots;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import pulse.cdm.substance.SESubstanceManager;
import pulse.utilities.FileUtils;
import pulse.utilities.Log;
import pulse.utilities.csv.CSVContents;
import pulse.utilities.csv.plots.PlotDriver.PlotJob;
// Plotting the same columns from multiple csv files onto one plot
public class MultiSourcePlotter implements Plotter
{
public static void main(String[] args)
{
PlotDriver.main(args);
}
@Override
public void plot(PlotJob job, SESubstanceManager subMgr)
{
CSVPlotTool plotTool = new CSVPlotTool(); //to leverage existing functions
XYSeriesCollection xySeries = new XYSeriesCollection();
if (job.experimentalData != null)
Log.error("MultiSourcePlotter does not support experimentalData");// Can add later if needed
if(job.Y1headers.size()>1)
Log.error("MultiSourcePlotter does not support multiple columns from a csv source");// Can add later if needed
if(!job.Y2headers.isEmpty())
Log.error("MultiSourcePlotter does not support X2/Y2 directives");// Can add later if needed
//fill PlotJob with needed data if it doesn't exist
if(job.dataPath == null || job.dataPath.isEmpty())
{job.dataPath = job.verificationDirectory+"/";}
if(job.dataFile == null || job.dataFile.isEmpty())
{job.dataFile = job.name + "Results.csv";}
int numSources=0;
try
{
String[] dataFiles = job.dataFile.split(",");
numSources=dataFiles.length;
for(int s=0; s<numSources; s++)
{
String dataFile = dataFiles[s];
CSVContents csv = new CSVContents(job.dataPath + dataFile);
csv.abreviateContents = job.resultsSkipNum;
// Get X Data
Log.info("Reading "+job.X1header+" from "+dataFiles[s]);
List<Double> xData = new ArrayList<Double>();
csv.readHeader(csv.unitUnderscoreToSpace(job.X1header), xData);
// Get Y Data
Log.info("Reading "+job.Y1headers.get(0)+" from "+dataFiles[s]);
List<Double> yData = new ArrayList<Double>();
csv.readHeader(csv.unitUnderscoreToSpace(job.Y1headers.get(0)), yData);
// Optionally, Scale the data
if(job.percentOfBaseline)
{
double xBaseline = xData.get(0);
double yBaseline = yData.get(0);
for(int i=0; i < xData.size(); i++)
{
//xData.set(i, (1-(xData.get(i)/xBaseline))*100); // If not time
yData.set(i, (yData.get(i)/yBaseline)*100);
}
}
// Create our plot series with the data
XYSeries dataSeries = plotTool.createXYSeries("Group "+(s+1),xData,yData);
xySeries.addSeries(dataSeries);
}
} catch (IOException e)
{
Log.error("Could not analyze file " + job.dataPath + job.dataFile);
}
String title = job.name;
if(job.titleOverride != null && !job.titleOverride.isEmpty() && !job.titleOverride.equalsIgnoreCase("None"))
title = job.titleOverride;
//Default labels
String XAxisLabel = job.X1header;
String YAxisLabel = job.Y1headers.get(0);
JFreeChart chart = ChartFactory.createXYLineChart(
job.titleOverride!=null&&job.titleOverride.equalsIgnoreCase("None")?"":title, // chart title
XAxisLabel, // x axis label
YAxisLabel, // y axis label
xySeries, // data
PlotOrientation.VERTICAL, // orientation
true, // include legend
true, // tooltips
false // urls
);
Log.info("Creating Graph "+title);
XYPlot plot = (XYPlot) chart.getPlot();
if (!job.logAxis)
{
}
else
{
Log.error("MultiSourcePlotter does not support log axis");// Can add later if needed
}
//Override X bounds if desired
try
{
if(job.X1LowerBound != null)
plot.getDomainAxis(0).setLowerBound(job.X1LowerBound);
if(job.X1UpperBound != null)
plot.getDomainAxis(0).setUpperBound(job.X1UpperBound);
}
catch(Exception e)
{
Log.error("Couldn't set X bounds. You probably tried to set a bound on an axis that doesn't exist.");
}
//Override labels if desired
if(job.X1Label != null && !plot.getDomainAxis(0).getLabel().contains("NaN"))
plot.getDomainAxis(0).setLabel(job.X1Label.equalsIgnoreCase("None")?"":job.X1Label);
if(job.Y1Label != null)
plot.getRangeAxis(0).setLabel(job.Y1Label.equalsIgnoreCase("None")?"":job.Y1Label);
//Format lines and colors
plot.setDomainGridlinesVisible(job.showGridLines);
plot.setRangeGridlinesVisible(job.showGridLines);
formatPlotCollections(job, chart);
//Handle legends
if(job.removeAllLegends)
chart.removeLegend();
//Make the file
try
{
FileUtils.createDirectory(job.outputDir);
String filename = job.outputFilename==null ? job.outputDir+"/"+plotTool.MakeFileName(title)+".jpg" : job.outputDir+"/"+job.outputFilename;
if(!filename.endsWith(".jpg"))
filename = filename + ".jpg";
File JPGFile = new File(filename);
if(job.imageHeight != null && job.imageWidth != null)
ChartUtilities.saveChartAsJPEG(JPGFile, chart, job.imageWidth, job.imageHeight);
else
ChartUtilities.saveChartAsJPEG(JPGFile, chart, 1600, 800);
}
catch (IOException e)
{
Log.error(e.getMessage());
}
}
protected void formatPlotCollections(PlotJob job, JFreeChart chart)
{
Float[] strokes = {2.f,2.f,3.f,4.f,5.f,8.f};
Color[] variedColors = {Color.red, Color.blue, Color.green, Color.orange, Color.magenta, Color.cyan, Color.gray, new Color(255,165,0), new Color(42,183,136), new Color(87,158,186)};
XYPlot plot = (XYPlot) chart.getPlot();
XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
//For Scientific notation
//NumberFormat formatter = new DecimalFormat("0.######E0");
for(int i = 0; i < plot.getDomainAxisCount(); i++)
{
plot.getDomainAxis(i).setLabelFont(new Font("SansSerif", Font.PLAIN, job.fontSize));
plot.getDomainAxis(i).setTickLabelFont(new Font("SansSerif", Font.PLAIN, 15));
plot.getDomainAxis(i).setLabelPaint(job.bgColor==Color.red?Color.white:Color.black);
plot.getDomainAxis(i).setTickLabelPaint(job.bgColor==Color.red?Color.white:Color.black);
}
for(int i = 0; i < plot.getRangeAxisCount(); i++)
{
plot.getRangeAxis(i).setLabelFont(new Font("SansSerif", Font.PLAIN, job.fontSize));
plot.getRangeAxis(i).setTickLabelFont(new Font("SansSerif", Font.PLAIN, 15));
plot.getRangeAxis(i).setLabelPaint(job.bgColor==Color.red?Color.white:Color.black);
plot.getRangeAxis(i).setTickLabelPaint(job.bgColor==Color.red?Color.white:Color.black);
NumberAxis rangeAxis = (NumberAxis)plot.getRangeAxis(i);
//rangeAxis.setNumberFormatOverride(formatter);
}
//White background outside of plottable area
chart.setBackgroundPaint(job.bgColor);
plot.setBackgroundPaint(Color.white);
plot.setDomainGridlinePaint(Color.black);
plot.setRangeGridlinePaint(Color.black);
plot.setDomainCrosshairVisible(true);
plot.setRangeCrosshairVisible(true);
renderer.setBaseLegendTextFont(new Font("SansSerif", Font.PLAIN, job.legendFontSize));
chart.getTitle().setFont(new Font("SansSerif", Font.PLAIN, job.fontSize));
chart.getTitle().setPaint(job.bgColor==Color.red?Color.white:Color.black);
for(int i = 0, cIndex = 0; i < plot.getSeriesCount(); i++, cIndex++)
{
BasicStroke wideLine = new BasicStroke( strokes[i] );
renderer.setSeriesStroke(i, wideLine);
renderer.setBaseShapesVisible(false);
if(cIndex > 9) cIndex = 0;
renderer.setSeriesFillPaint(i, variedColors[cIndex]);
renderer.setSeriesPaint(i, variedColors[cIndex]);
}
}
}
......@@ -123,9 +123,9 @@ public class PlotDriver
protected static SESubstanceManager subMgr=null;
public class PlotJob extends LogListener
public class PlotJob
{
public PlotJob(){ listen(false); }
public PlotJob(){ }
public String name;