diff --git a/README.md b/README.md index cfedd2e..aab93b0 100644 --- a/README.md +++ b/README.md @@ -25,16 +25,16 @@ using ParallelPlots ### Usage #### Available Parameter -| Parameter | Default | Example | Description | -|-------------------|----------|------------------------------------|----------------------------------------------------------------------------------------------------------------------------| -| title::String | "" | title="My Title" | The Title of The Figure, | -| colormap | :viridis | colormap=:thermal | The Colors of the [Lines](https://docs.makie.org/dev/explanations/colors) | -| color_feature | nothing | color_feature="weight" | The Color of the Lines will be based on the values of this selected feature. If nothing, the last feature will be used | -| feature_labels | nothing | feature_labels=["Weight","Age"] | Add your own Axis labels, just use the exact amount of labes as you have axis | -| feature_selection | nothing | feature_selection=["weight","age"] | Select, which features should be Displayed. If color_feature is not in this List, use the last one | -| curve | false | curve=true | Show the Lines Curved | -| show_color_legend | nothing | show_color_legend=true | Show the Color Legend. If parameter not set & color_feature not shown, it will be displayed automaticly | -| scale | nothing | scale=[log2, identity, log10] | Choose, how each Axis should be scaled. In the Example. The first Axis will be log2, the second linear and the third log10 | +| Parameter | Default | Example | Description | +|-------------------|----------|------------------------------------------|------------------------------------------------------------------------------------------------------------------------| +| title::String | "" | title="My Title" | The Title of The Figure, | +| colormap | :viridis | colormap=:thermal | The Colors of the [Lines](https://docs.makie.org/dev/explanations/colors) | +| color_feature | nothing | color_feature="weight" | The Color of the Lines will be based on the values of this selected feature. If nothing, the last feature will be used | +| feature_labels | nothing | feature_labels=["Weight","Age"] | Add your own Axis labels, just use the exact amount of labes as you have axis | +| feature_selection | nothing | feature_selection=["weight","age"] | Select, which features should be Displayed. If color_feature is not in this List, use the last one | +| curve | false | curve=true | Show the Lines Curved | +| show_color_legend | nothing | show_color_legend=true | Show the Color Legend. If parameter not set & color_feature not shown, it will be displayed automaticly | +| scale | nothing | scale=[identity, log, log2, log10, sqrt] | Choose, how each Axis should be scaled. | #### Examples diff --git a/docs/src/getting_started.md b/docs/src/getting_started.md index 44886eb..be7d839 100644 --- a/docs/src/getting_started.md +++ b/docs/src/getting_started.md @@ -13,16 +13,16 @@ using ParallelPlots ## Usage ### Available Parameter -| Parameter | Default | Example | Description | -|-------------------|----------|------------------------------------|----------------------------------------------------------------------------------------------------------------------------| -| title::String | "" | title="My Title" | The Title of The Figure, | -| colormap | :viridis | colormap=:thermal | The Colors of the [Lines](https://docs.makie.org/dev/explanations/colors) | -| color_feature | nothing | color_feature="weight" | The Color of the Lines will be based on the values of this selected feature. If nothing, the last feature will be used | -| feature_labels | nothing | feature_labels=["Weight","Age"] | Add your own Axis labels, just use the exact amount of labes as you have axis | -| feature_selection | nothing | feature_selection=["weight","age"] | Select, which features should be Displayed. If color_feature is not in this List, use the last one | -| curve | false | curve=true | Show the Lines Curved | -| show_color_legend | nothing | show_color_legend=true | Show the Color Legend. If parameter not set & color_feature not shown, it will be displayed automaticly | -| scale | nothing | scale=[log2, identity, log10] | Choose, how each Axis should be scaled. In the Example. The first Axis will be log2, the second linear and the third log10 | +| Parameter | Default | Example | Description | +|-------------------|----------|------------------------------------------|------------------------------------------------------------------------------------------------------------------------| +| title::String | "" | title="My Title" | The Title of The Figure, | +| colormap | :viridis | colormap=:thermal | The Colors of the [Lines](https://docs.makie.org/dev/explanations/colors) | +| color_feature | nothing | color_feature="weight" | The Color of the Lines will be based on the values of this selected feature. If nothing, the last feature will be used | +| feature_labels | nothing | feature_labels=["Weight","Age"] | Add your own Axis labels, just use the exact amount of labes as you have axis | +| feature_selection | nothing | feature_selection=["weight","age"] | Select, which features should be Displayed. If color_feature is not in this List, use the last one | +| curve | false | curve=true | Show the Lines Curved | +| show_color_legend | nothing | show_color_legend=true | Show the Color Legend. If parameter not set & color_feature not shown, it will be displayed automaticly | +| scale | nothing | scale=[identity, log, log2, log10, sqrt] | Choose, how each Axis should be scaled. | ### Examples diff --git a/src/ParallelPlots.jl b/src/ParallelPlots.jl index e743896..ea500b1 100644 --- a/src/ParallelPlots.jl +++ b/src/ParallelPlots.jl @@ -38,16 +38,16 @@ end # Arguments -| Parameter | Default | Example | Description | -|-------------------|----------|------------------------------------|----------------------------------------------------------------------------------------------------------------------------| -| title::String | "" | title="My Title" | The Title of The Figure, | -| colormap | :viridis | colormap=:thermal | The Colors of the [Lines](https://docs.makie.org/dev/explanations/colors) | -| color_feature | nothing | color_feature="weight" | The Color of the Lines will be based on the values of this selected feature. If nothing, the last feature will be used | -| feature_labels | nothing | feature_labels=["Weight","Age"] | Add your own Axis labels, just use the exact amount of labes as you have axis | -| feature_selection | nothing | feature_selection=["weight","age"] | Select, which features should be Displayed. If color_feature is not in this List, use the last one | -| curve | false | curve=true | Show the Lines Curved | -| show_color_legend | nothing | show_color_legend=true | Show the Color Legend. If parameter not set & color_feature not shown, it will be displayed automaticly | -| scale | nothing | scale=[log2, identity, log10] | Choose, how each Axis should be scaled. In the Example. The first Axis will be log2, the second linear and the third log10 | +| Parameter | Default | Example | Description | +|-------------------|----------|------------------------------------------|------------------------------------------------------------------------------------------------------------------------| +| title::String | "" | title="My Title" | The Title of The Figure, | +| colormap | :viridis | colormap=:thermal | The Colors of the [Lines](https://docs.makie.org/dev/explanations/colors) | +| color_feature | nothing | color_feature="weight" | The Color of the Lines will be based on the values of this selected feature. If nothing, the last feature will be used | +| feature_labels | nothing | feature_labels=["Weight","Age"] | Add your own Axis labels, just use the exact amount of labes as you have axis | +| feature_selection | nothing | feature_selection=["weight","age"] | Select, which features should be Displayed. If color_feature is not in this List, use the last one | +| curve | false | curve=true | Show the Lines Curved | +| show_color_legend | nothing | show_color_legend=true | Show the Color Legend. If parameter not set & color_feature not shown, it will be displayed automaticly | +| scale | nothing | scale=[identity, log, log2, log10, sqrt] | Choose, how each Axis should be scaled. | # Examples @@ -515,58 +515,42 @@ This function will return the y position in the scene, depending of the scale if function calc_y_coordinate(parsed_data, limits, height, offset, feature_index :: Number, sample_index :: Number, scale_list) :: Number # linear factor between 0 and 1, depending on the value inside the feature - factor = ( - (parsed_data[feature_index][sample_index] - limits[feature_index][1]) - / - (limits[feature_index][2] - limits[feature_index][1]) - ) + factor = Float64 # get the scale of the current feature scale = scale_list[feature_index] - # change the linear factor - when needed - with the equivalent function for a log distribution - # throws error when cscalijg parameter is not one of [identity, log2, log10] - if scale === identity - elseif scale === log2 - factor = log_scale2(factor) - elseif scale === log10 - factor = log_scale10(factor) - else - throw(ArgumentError("The scaling parameter '"*string(scale)*"' is currently not supported. Supported: [identity, log2, log10]")) - end + # create a factor with the equivalent function for a log/identity distribution + factor = calc_factor( + limits[feature_index][1], + limits[feature_index][2], + parsed_data[feature_index][sample_index], + scale + ) # return the y position. use the height depending on the factor (full/no height) return factor * height + offset end """ - log_scale10(x::Float64) - -In Linear Axis represenatation, values between 0-1 are linear distributed. -Due to the Logarithmfunction, we need to distribute the values with the given log values to match the axis - -### Input: -- value x, distributed between 0 and 1 -### Output: -- the log10 distribution, beween 0 and 1 -""" -function log_scale10(x::Float64) - return log10(1+99*x)/2 -end - -""" - log_scale2(x::Float64) + calc_factor(min::T, max::T, x::T, fun::Function):: Float64 where {T<:Real} In Linear Axis represenatation, values between 0-1 are linear distributed. Due to the Logarithmfunction, we need to distribute the values with the given log values to match the axis ### Input: -- value x, distributed between 0 and 1 +- min::T, +- max::T, +- x::T, +- fun::Function --> [identity, log, log2, log10, sqrt] ### Output: -- the log2 distribution, beween 0 and 1 +- the distribution with the given function beween 0 and 1 """ -function log_scale2(x::Float64) - return log2(1 + 3 * x) / 2 +function calc_factor(min::T, max::T, x::T, fun::Function):: Float64 where {T<:Real} + max_log = fun(max) + min_log = fun(min) + x_log = fun(x) + return (x_log-min_log)/(max_log-min_log) end """ diff --git a/test/projectile_simulation.png b/test/projectile_simulation.png deleted file mode 100644 index 43f2212..0000000 Binary files a/test/projectile_simulation.png and /dev/null differ diff --git a/test/test_log_scale.jl b/test/test_log_scale.jl index d8646e1..577c487 100644 --- a/test/test_log_scale.jl +++ b/test/test_log_scale.jl @@ -17,7 +17,7 @@ using CairoMakie: save # create log10 data for easy visual check df = create_log_df(10) fig = parallelplot(df, - scale=[log10, identity, log10], + scale=[log10, sqrt, log10], feature_selection=["height","age","income"], ) @test fig !== nothing @@ -31,12 +31,4 @@ using CairoMakie: save ) end - # length of scale attributes does not fit the length of the axis/features - @test_throws ArgumentError begin - fig = parallelplot(df, - scale=[log10, identity, log10, sqrt], - feature_selection=["height","weight","age","income"], - ) - end - end diff --git a/test/test_utils.jl b/test/test_utils.jl index bb594d0..50a5954 100644 --- a/test/test_utils.jl +++ b/test/test_utils.jl @@ -20,7 +20,7 @@ function create_person_df(n_samples = 10) end function create_log_df(log = 10) - df = DataFrame(height=[log^1,log^2,log^3],weight=[log^3,log^2,log^1],age=[log^3,log^2,log^1],income=[log^1,log^2,log^3]) + df = DataFrame(height=[log^1,log^4,log^5],weight=[log^5,log^3,log^2],age=[log^4,log^3,log^1],income=[log^2,log^3,log^6]) return df end