Skip to content

Commit 6bdd7e5

Browse files
authored
Merge pull request #1 from leonhaufe/log-scale
Log scale
2 parents ab763be + 75800d0 commit 6bdd7e5

File tree

7 files changed

+238
-33
lines changed

7 files changed

+238
-33
lines changed

.github/workflows/documentation.yml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Documentation
2+
3+
on:
4+
push:
5+
branches:
6+
- main # update to match your development branch (master, main, dev, trunk, ...)
7+
tags: '*'
8+
pull_request:
9+
10+
jobs:
11+
build:
12+
permissions:
13+
actions: write
14+
contents: write
15+
pull-requests: read
16+
statuses: write
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v4
20+
- uses: julia-actions/setup-julia@v2
21+
with:
22+
version: '1'
23+
- uses: julia-actions/cache@v2
24+
- name: Install dependencies
25+
run: julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
26+
- name: Build and deploy
27+
env:
28+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # If authenticating with GitHub Actions token
29+
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }} # If authenticating with SSH deploy key
30+
run: julia --project=docs/ docs/make.jl

README.md

+17-9
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,16 @@ using ParallelPlots
2626
### Usage
2727
#### Available Parameter
2828

29-
| Parameter | Default | Example | Description |
30-
|-------------------|----------|------------------------------------|------------------------------------------------------------------------------------------------------------------------|
31-
| title::String | "" | title="My Title" | The Title of The Figure, |
32-
| colormap | :viridis | colormap=:thermal | The Colors of the [Lines](https://docs.makie.org/dev/explanations/colors) |
33-
| 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 |
34-
| feature_labels | nothing | feature_labels=["Weight","Age"] | Add your own Axis labels, just use the exact amount of labes as you have axis |
35-
| 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 |
36-
| curve | false | curve=true | Show the Lines Curved |
37-
| 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 |
29+
| Parameter | Default | Example | Description |
30+
|-------------------|----------|------------------------------------|----------------------------------------------------------------------------------------------------------------------------|
31+
| title::String | "" | title="My Title" | The Title of The Figure, |
32+
| colormap | :viridis | colormap=:thermal | The Colors of the [Lines](https://docs.makie.org/dev/explanations/colors) |
33+
| 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 |
34+
| feature_labels | nothing | feature_labels=["Weight","Age"] | Add your own Axis labels, just use the exact amount of labes as you have axis |
35+
| 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 |
36+
| curve | false | curve=true | Show the Lines Curved |
37+
| 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 |
38+
| 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 |
3839

3940

4041
#### Examples
@@ -76,6 +77,13 @@ parallelplot(df,
7677
show_color_legend = true
7778
)
7879
```
80+
```
81+
# Adjust the Axis scale
82+
parallelplot(df,
83+
feature_selection=["height","age","income"],
84+
scale=[log2, identity, log10]
85+
)
86+
```
7987

8088
### Working on ParallelPlots / Cheatsheet
8189
1. Using ParallelPlots

docs/src/getting_started.md

+17-9
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,16 @@ using ParallelPlots
1313
## Usage
1414
### Available Parameter
1515

16-
| Parameter | Default | Example | Description |
17-
|-------------------|----------|------------------------------------|------------------------------------------------------------------------------------------------------------------------|
18-
| title::String | "" | title="My Title" | The Title of The Figure, |
19-
| colormap | :viridis | colormap=:thermal | The Colors of the [Lines](https://docs.makie.org/dev/explanations/colors) |
20-
| 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 |
21-
| feature_labels | nothing | feature_labels=["Weight","Age"] | Add your own Axis labels, just use the exact amount of labes as you have axis |
22-
| 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 |
23-
| curve | false | curve=true | Show the Lines Curved |
24-
| 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 |
16+
| Parameter | Default | Example | Description |
17+
|-------------------|----------|------------------------------------|----------------------------------------------------------------------------------------------------------------------------|
18+
| title::String | "" | title="My Title" | The Title of The Figure, |
19+
| colormap | :viridis | colormap=:thermal | The Colors of the [Lines](https://docs.makie.org/dev/explanations/colors) |
20+
| 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 |
21+
| feature_labels | nothing | feature_labels=["Weight","Age"] | Add your own Axis labels, just use the exact amount of labes as you have axis |
22+
| 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 |
23+
| curve | false | curve=true | Show the Lines Curved |
24+
| 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 |
25+
| 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 |
2526

2627

2728
### Examples
@@ -63,6 +64,13 @@ parallelplot(df,
6364
show_color_legend = true
6465
)
6566
```
67+
```
68+
# Adjust the Axis scale
69+
parallelplot(df,
70+
feature_selection=["height","age","income"],
71+
scale=[log2, identity, log10]
72+
)
73+
```
6674

6775
## Working on ParallelPlots / Cheatsheet
6876
1. Using ParallelPlots

src/ParallelPlots.jl

+125-15
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,16 @@ end
3838
3939
# Arguments
4040
41-
| Parameter | Default | Example | Description |
42-
|-------------------|----------|------------------------------------|------------------------------------------------------------------------------------------------------------------------|
43-
| title | "" | title="My Title" | The Title of The Figure, |
44-
| colormap | :viridis | colormap=:thermal | The Colors of the [Lines](https://docs.makie.org/dev/explanations/colors) |
45-
| 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 |
46-
| feature_labels | nothing | feature_labels=["Weight","Age"] | Add your own Axis labels, just use the exact amount of labes as you have axis |
47-
| 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 |
48-
| curve | false | curve=true | Show the Lines Curved |
49-
| 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 |
41+
| Parameter | Default | Example | Description |
42+
|-------------------|----------|------------------------------------|----------------------------------------------------------------------------------------------------------------------------|
43+
| title::String | "" | title="My Title" | The Title of The Figure, |
44+
| colormap | :viridis | colormap=:thermal | The Colors of the [Lines](https://docs.makie.org/dev/explanations/colors) |
45+
| 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 |
46+
| feature_labels | nothing | feature_labels=["Weight","Age"] | Add your own Axis labels, just use the exact amount of labes as you have axis |
47+
| 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 |
48+
| curve | false | curve=true | Show the Lines Curved |
49+
| 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 |
50+
| 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 |
5051
5152
5253
# Examples
@@ -133,6 +134,13 @@ parallelplot(df,
133134
show_color_legend = true
134135
)
135136
```
137+
```
138+
# Adjust the Axis scale
139+
parallelplot(df,
140+
feature_selection=["height","age","income"],
141+
scale=[log2, identity, log10]
142+
)
143+
```
136144
137145
"""
138146
@recipe(ParallelPlot, df) do scene
@@ -145,7 +153,8 @@ parallelplot(df,
145153
feature_selection = nothing, # which features should be shown, default: nothing --> show all features
146154
curve = false, # If Lines should be curved between the axis. Default false
147155
# if colorlegend/ ColorBar should be shown. Default: when color_feature is not visible, true, else false
148-
show_color_legend = nothing
156+
show_color_legend = nothing,
157+
scale = nothing
149158
)
150159
end
151160

@@ -232,6 +241,9 @@ function Makie.plot!(pp::ParallelPlot)
232241
numberFeatures = length(parsed_data) # Number of features, equivalent to the X Axis
233242
sampleSize = size(data, 1) # Number of samples, equivalent to the Y Axis
234243

244+
#create the list of scales for each Axis/feature
245+
scale_list = create_scale_list(numberFeatures, pp.scale[])
246+
235247
# # # # # # # # # #
236248
# # # L I N E # # #
237249
# # # # # # # # # #
@@ -246,6 +258,7 @@ function Makie.plot!(pp::ParallelPlot)
246258
offset,
247259
limits,
248260
numberFeatures,
261+
scale_list,
249262
sampleSize,
250263
parsed_data,
251264
color_values,
@@ -266,7 +279,8 @@ function Makie.plot!(pp::ParallelPlot)
266279
offset,
267280
limits,
268281
labels,
269-
numberFeatures
282+
numberFeatures,
283+
scale_list
270284
)
271285

272286

@@ -297,6 +311,30 @@ function Makie.plot!(pp::ParallelPlot)
297311
pp
298312
end
299313

314+
"""
315+
316+
create_scale_list(numberFeatures :: Number, scale_list)
317+
318+
check the length of the given scale Attribute. Throws an Error if the Length does not match the amount of axis/features
319+
If scale is not set, identity, so linear will be used for all axis.
320+
if the length of the scale attribute does not fit, an assert error will be thrown
321+
322+
### Input:
323+
- numberFeatures::Number
324+
- scale_list nothing or Vector e.g. [log2, log10, identity]
325+
### Output:
326+
- given scale_list or vector of [identity, identity, ...] with the length of axis/features
327+
### Throws
328+
Assertion, if amount of scales in the scale list does not match the amount of axis/features
329+
"""
330+
function create_scale_list(numberFeatures :: Number, scale_list)
331+
if isnothing(scale_list)
332+
[identity for i = 1:numberFeatures]
333+
else
334+
@assert length(scale_list) === numberFeatures "The Number of given scales ("*string(length(scale_list))*") does not match the amount of axis/features ("*string(numberFeatures)*")"
335+
return scale_list
336+
end
337+
end
300338

301339
"""
302340
@@ -371,6 +409,8 @@ function show_color_legend!(pp) :: Bool
371409
return true
372410
elseif pp.show_color_legend[] == false
373411
return false
412+
elseif isnothing(pp.color_feature[])
413+
return false
374414
elseif !isnothing(pp.feature_selection[]) && !(pp.color_feature[] in pp.feature_selection[])
375415
return true
376416
else
@@ -390,6 +430,7 @@ end
390430
offset::Number,
391431
limits,
392432
numberFeatures::Number,
433+
scale_list,
393434
sampleSize::Number,
394435
parsed_data,
395436
color_values,
@@ -410,6 +451,7 @@ function draw_lines(
410451
offset::Number,
411452
limits,
412453
numberFeatures::Number,
454+
scale_list,
413455
sampleSize::Number,
414456
parsed_data,
415457
color_values,
@@ -426,7 +468,7 @@ function draw_lines(
426468
# calculates which feature the Point should be on
427469
offset + (j - 1) / (numberFeatures - 1) * width,
428470
# calculates the Y axis value
429-
(parsed_data[j][i] - limits[j][1]) / (limits[j][2] - limits[j][1]) * height + offset,
471+
calc_y_coordinate(parsed_data, limits, height,offset, j, i, scale_list),
430472
)
431473
# iterates through the Features/Axis and creates for each feature the samplePoint (above)
432474
for j in 1:numberFeatures
@@ -440,9 +482,9 @@ function draw_lines(
440482
for j in 2:numberFeatures
441483
last_x = offset + ((j-1) - 1) / (numberFeatures - 1) * width
442484
current_x = offset + ((j) - 1) / (numberFeatures - 1) * width
443-
last_y = (parsed_data[j-1][i] - limits[j-1][1]) / (limits[j-1][2] - limits[j-1][1]) * height + offset
444-
current_y = (parsed_data[j][i] - limits[j][1]) / (limits[j][2] - limits[j][1]) * height + offset
445-
# interpolate points between the current and the last point
485+
last_y = calc_y_coordinate(parsed_data, limits, height, offset, j-1, i, scale_list)
486+
current_y = calc_y_coordinate(parsed_data, limits, height,offset, j, i, scale_list)
487+
# interpolate points between the current and the last point
446488
for x in range(last_x, current_x, step = ( (current_x-last_x) / 30 ) )
447489
# calculate the interpolated Y Value
448490
y = interpolate(last_x, current_x, last_y, current_y, x)
@@ -462,6 +504,71 @@ function draw_lines(
462504
end
463505
end
464506

507+
"""
508+
calc_y_coordinate(parsed_data, limits, height, offset, feature_index :: Number, sample_index :: Number, scale_list) :: Number
509+
510+
This function will return the y position in the scene, depending of the scale if set
511+
512+
### Output:
513+
- the y position of the datapoint in the scene
514+
"""
515+
function calc_y_coordinate(parsed_data, limits, height, offset, feature_index :: Number, sample_index :: Number, scale_list) :: Number
516+
517+
# linear factor between 0 and 1, depending on the value inside the feature
518+
factor = (
519+
(parsed_data[feature_index][sample_index] - limits[feature_index][1])
520+
/
521+
(limits[feature_index][2] - limits[feature_index][1])
522+
)
523+
524+
# get the scale of the current feature
525+
scale = scale_list[feature_index]
526+
527+
# change the linear factor - when needed - with the equivalent function for a log distribution
528+
# throws error when cscalijg parameter is not one of [identity, log2, log10]
529+
if scale === identity
530+
elseif scale === log2
531+
factor = log_scale2(factor)
532+
elseif scale === log10
533+
factor = log_scale10(factor)
534+
else
535+
throw(ArgumentError("The scaling parameter '"*string(scale)*"' is currently not supported. Supported: [identity, log2, log10]"))
536+
end
537+
538+
# return the y position. use the height depending on the factor (full/no height)
539+
return factor * height + offset
540+
end
541+
542+
"""
543+
log_scale10(x::Float64)
544+
545+
In Linear Axis represenatation, values between 0-1 are linear distributed.
546+
Due to the Logarithmfunction, we need to distribute the values with the given log values to match the axis
547+
548+
### Input:
549+
- value x, distributed between 0 and 1
550+
### Output:
551+
- the log10 distribution, beween 0 and 1
552+
"""
553+
function log_scale10(x::Float64)
554+
return log10(1+99*x)/2
555+
end
556+
557+
"""
558+
log_scale2(x::Float64)
559+
560+
In Linear Axis represenatation, values between 0-1 are linear distributed.
561+
Due to the Logarithmfunction, we need to distribute the values with the given log values to match the axis
562+
563+
### Input:
564+
- value x, distributed between 0 and 1
565+
### Output:
566+
- the log2 distribution, beween 0 and 1
567+
"""
568+
function log_scale2(x::Float64)
569+
return log2(1 + 3 * x) / 2
570+
end
571+
465572
"""
466573
draw_axis(
467574
scene,
@@ -471,6 +578,7 @@ end
471578
limits,
472579
labels,
473580
numberFeatures::Number,
581+
scale_list
474582
)
475583
476584
Draws the Axis/Feature vertical Axis Lines on the given Scene
@@ -484,6 +592,7 @@ function draw_axis(
484592
limits,
485593
labels,
486594
numberFeatures::Number,
595+
scale_list
487596
)
488597
for i in 1:numberFeatures
489598
# x will be used to split the Scene for each feature
@@ -508,6 +617,7 @@ function draw_axis(
508617
ticklabelfont = def[:yticklabelfont],
509618
ticklabelsize = def[:yticklabelsize],
510619
minorticks = def[:yminorticks],
620+
scale = scale_list[i]
511621
)
512622

513623
# Create Lable for the Axis

test/runtests.jl

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
include("test_utils.jl")
22

33
include("test_argument_errors.jl")
4+
include("test_log_scale.jl")
45
include("test_curved.jl")
56
include("test_call_with_color_feature.jl")
67
include("test_call_with_feature_labels.jl")

0 commit comments

Comments
 (0)