File tree Expand file tree Collapse file tree 3 files changed +35
-1
lines changed
Expand file tree Collapse file tree 3 files changed +35
-1
lines changed Original file line number Diff line number Diff line change 1+ const MAX_AXIS_LABEL_WIDTH = 20
2+
13@recipe function f (mach:: MLJBase.Machine{<:EitherTunedModel} )
24 rep = report (mach)
35 measurement = repr (rep. best_history_entry. measure[1 ])
46 r = rep. plotting
57 z = r. measurements
68 X = r. parameter_values
7- guides = r. parameter_names
9+ guides = map (r. parameter_names) do name
10+ trim (name, MAX_AXIS_LABEL_WIDTH)
11+ end
812 scales = r. parameter_scales
913 n = size (X, 2 )
1014 indices = LinearIndices ((n, n))'
Original file line number Diff line number Diff line change @@ -39,3 +39,22 @@ signature(measure) =
3939 else
4040 0
4141 end
42+
43+ # function to trim a string like "transformed_target_model_deterministic.model.K" to `N`
44+ # characters. For example, if `N=20`, return `…model.K`. Used in plotrecipes.jl.
45+ function trim (str, N)
46+ n = length (str)
47+ n <= N && return str
48+ fits = false
49+ parts = split (str, " ." ) |> reverse
50+ # removes parts until what remains fits, with room for ellipsis (1 character), or if
51+ # there is only one part left:
52+ while ! fits && length (parts) > 1
53+ removed = pop! (parts)
54+ n -= length (removed) + 1 # the `1` is for the dot, `.`
55+ if n < N
56+ fits = true
57+ end
58+ end
59+ " …" * join (reverse (parts), " ." )
60+ end
Original file line number Diff line number Diff line change 2222 @test MLJTuning. signature .(measures) == [- 1 , 0 , 1 ]
2323end
2424
25+ @testset " trim" begin
26+ str = " some.long.name" # 14 characters
27+ @test MLJTuning. trim (str, 14 ) == str
28+ @test MLJTuning. trim (str, 13 ) == " …long.name" # 10 characters
29+ @test MLJTuning. trim (str, 12 ) == " …long.name"
30+ @test MLJTuning. trim (str, 11 ) == " …long.name"
31+ @test MLJTuning. trim (str, 10 ) == " …long.name"
32+ @test MLJTuning. trim (str, 9 ) == " …name"
33+ @test MLJTuning. trim (str, 1 ) == " …name" # cannot go any smaller
34+ end
35+
2536true
2637
You can’t perform that action at this time.
0 commit comments