From 110d90842e8d2cb9ae0ec8afa10e1a7cdfad06c2 Mon Sep 17 00:00:00 2001 From: smo Date: Thu, 30 Jan 2025 14:24:03 +0100 Subject: [PATCH 1/3] add error for df = nothing --- src/ParallelPlots.jl | 7 +++---- test/test_argument_errors.jl | 3 +++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/ParallelPlots.jl b/src/ParallelPlots.jl index 454ecf6..e7468ca 100644 --- a/src/ParallelPlots.jl +++ b/src/ParallelPlots.jl @@ -18,9 +18,6 @@ checks the Input Data if the size is correct and no missing values are available Throws error on wrong DF """ function input_data_check(data::DataFrame) - if isnothing(data) - throw(ArgumentError("Data cannot be nothing")) - end if size(data, 2) < 2 # otherwise there will be a nullpointer exception later throw(ArgumentError("Data must have at least two columns, currently ("*string(size(data, 2))*")")) end @@ -119,7 +116,9 @@ function Makie.plot!(pp::ParallelPlot) # this helper function will update our observables # whenever df_observable change function update_plot(data) - + if isnothing(data) + throw(ArgumentError("Data cannot be nothing")) + end # check the given DataFrame input_data_check(data) diff --git a/test/test_argument_errors.jl b/test/test_argument_errors.jl index cd7151e..0cd27f8 100644 --- a/test/test_argument_errors.jl +++ b/test/test_argument_errors.jl @@ -25,4 +25,7 @@ using CairoMakie: save @test_throws ArgumentError begin parallelplot(df_one_line) end + @test_throws ArgumentError begin + parallelplot(nothing) + end end \ No newline at end of file From fd26093fefe6a5840ab0fe7f385b4c988338ffc9 Mon Sep 17 00:00:00 2001 From: Leon Haufe Date: Thu, 30 Jan 2025 20:04:34 +0100 Subject: [PATCH 2/3] rollback the type annotation --- src/ParallelPlots.jl | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/ParallelPlots.jl b/src/ParallelPlots.jl index f6dbfa5..e98ecf4 100644 --- a/src/ParallelPlots.jl +++ b/src/ParallelPlots.jl @@ -303,10 +303,10 @@ Calculates the Color values for the Lines - color_max The max value of `color_values`. To Calculate the ColorRange """ function calculate_color(pp::ParallelPlot, data::DataFrame) :: Tuple{AbstractString, Vector{Real}, Real, Real} - color_col = get_color_col(pp, data) - color_values = data[:,color_col] # Get all values for selected feature - color_min = minimum(color_values) - color_max = maximum(color_values) + color_col:: AbstractString = get_color_col(pp, data) + color_values::Vector{Real} = data[:,color_col] # Get all values for selected feature + color_min::Real = minimum(color_values) + color_max::Real = maximum(color_values) return color_col, color_values, color_min, color_max @@ -374,6 +374,7 @@ function draw_lines( color_max ) for i in 1:sampleSize + dataPoints = Vector{Point2f}(undef, numberFeatures) # If Curved, Interpolate if(pp.curve[] == false) # calcuating the point respectivly of the width and height in the Screen @@ -515,7 +516,7 @@ end """ - interpolate(last_x::Float64, current_x::Float64, last_y::Float64, current_y::Float64, x::Float64) + interpolate(last_x::Float64, current_x::Float64, last_y::Float64, current_y::Float64, x::Float64)::Float64 Interpolates the Y Value between the given current/last(x/y) point with the given x value. @@ -525,7 +526,7 @@ Interpolates the Y Value between the given current/last(x/y) point with the give ### Output: - current, interpolated y Value """ -function interpolate(last_x::Float64, current_x::Float64, last_y::Float64, current_y::Float64, x::Float64) +function interpolate(last_x::Float64, current_x::Float64, last_y::Float64, current_y::Float64, x::Float64)::Float64 # calculate the % of Pi related to x between two x points x_pi = (x - last_x)/(current_x - last_x) * π From cd35bdf7334b834b77d374d2e2fde5afc73dc710 Mon Sep 17 00:00:00 2001 From: Leon Haufe Date: Thu, 30 Jan 2025 20:14:03 +0100 Subject: [PATCH 3/3] rollback the type annotation --- src/ParallelPlots.jl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/ParallelPlots.jl b/src/ParallelPlots.jl index e98ecf4..d4927dd 100644 --- a/src/ParallelPlots.jl +++ b/src/ParallelPlots.jl @@ -117,6 +117,10 @@ function Makie.plot!(pp::ParallelPlot) # whenever df_observable change function update_plot(data) + if isnothing(data) + throw(ArgumentError("Data cannot be nothing")) + end + # check the given DataFrame input_data_check(data)