Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/plotrecipes.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
const MAX_AXIS_LABEL_WIDTH = 20

@recipe function f(mach::MLJBase.Machine{<:EitherTunedModel})
rep = report(mach)
measurement = repr(rep.best_history_entry.measure[1])
r = rep.plotting
z = r.measurements
X = r.parameter_values
guides = r.parameter_names
guides = map(r.parameter_names) do name
trim(name, MAX_AXIS_LABEL_WIDTH)
end
scales = r.parameter_scales
n = size(X, 2)
indices = LinearIndices((n, n))'
Expand Down
19 changes: 19 additions & 0 deletions src/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,22 @@ signature(measure) =
else
0
end

# function to trim a string like "transformed_target_model_deterministic.model.K" to `N`
# characters. For example, if `N=20`, return `…model.K`. Used in plotrecipes.jl.
function trim(str, N)
n = length(str)
n <= N && return str
fits = false
parts = split(str, ".") |> reverse
# removes parts until what remains fits, with room for ellipsis (1 character), or if
# there is only one part left:
while !fits && length(parts) > 1
removed = pop!(parts)
n -= length(removed) + 1 # the `1` is for the dot, `.`
if n < N
fits = true
end
end
"…"*join(reverse(parts), ".")
Copy link
Member

@OkonSamuel OkonSamuel Dec 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the ellipsis unicode (i.e "\u2026" ) or just 3 dots?. If this isn't unicode ellipsis, we can get more space by using unicode ellipsis.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It the single character unicode character.

end
11 changes: 11 additions & 0 deletions test/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,16 @@ end
@test MLJTuning.signature.(measures) == [-1, 0, 1]
end

@testset "trim" begin
str = "some.long.name" # 14 characters
@test MLJTuning.trim(str, 14) == str
@test MLJTuning.trim(str, 13) == "…long.name" # 10 characters
@test MLJTuning.trim(str, 12) == "…long.name"
@test MLJTuning.trim(str, 11) == "…long.name"
@test MLJTuning.trim(str, 10) == "…long.name"
@test MLJTuning.trim(str, 9) == "…name"
@test MLJTuning.trim(str, 1) == "…name" # cannot go any smaller
end

true

Loading