Skip to content

Commit 80ca64b

Browse files
committed
Ignore empty data sets when creating plots
1 parent 8688b62 commit 80ca64b

File tree

1 file changed

+15
-6
lines changed
  • stars-core/src/main/kotlin/tools/aqua/stars/core/metric/utils

1 file changed

+15
-6
lines changed

stars-core/src/main/kotlin/tools/aqua/stars/core/metric/utils/DataPlotter.kt

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,16 @@ val currentTimeAndDate: String =
5050
* accordingly.
5151
*/
5252
fun plotDataAsLineChart(
53-
plot: Plot,
53+
plot: Plot?,
5454
fileName: String,
5555
folder: String,
5656
subFolder: String = "",
5757
yAxisScaleMaxValue: Number? = null,
5858
) {
59+
if(plot == null){
60+
println("Skip plotting, as there was no data provided.")
61+
return
62+
}
5963
var innerPlot = plot
6064
val plotFolder = getAndCreatePlotFolder(folder, subFolder)
6165

@@ -76,11 +80,15 @@ fun plotDataAsLineChart(
7680
* resulting path
7781
*/
7882
fun plotDataAsBarChart(
79-
plot: Plot,
83+
plot: Plot?,
8084
fileName: String,
8185
folder: String,
8286
subFolder: String = "",
8387
) {
88+
if(plot == null){
89+
println("Skip plotting, as there was no data provided.")
90+
return
91+
}
8492
var innerPlot = plot
8593
val plotFolder = getAndCreatePlotFolder(folder, subFolder)
8694

@@ -107,7 +115,7 @@ fun <T : Number> getPlot(
107115
xAxisName: String,
108116
yAxisName: String,
109117
legendHeader: String
110-
): Plot {
118+
): Plot? {
111119
return getPlot(mapOf(legendEntry to yValues), xAxisName, yAxisName, legendHeader)
112120
}
113121

@@ -126,9 +134,10 @@ fun <T : Number> getPlot(
126134
xAxisName: String,
127135
yAxisName: String,
128136
legendHeader: String
129-
): Plot {
130-
// Check that every value list is filled
131-
check(!nameToValuesMap.values.any { it.isEmpty() })
137+
): Plot? {
138+
if (nameToValuesMap.values.any { it.isEmpty() }) {
139+
return null
140+
}
132141
// Check that every value list has the exact same amount of elements
133142
check(nameToValuesMap.values.map { it.size }.distinct().count() == 1)
134143

0 commit comments

Comments
 (0)