Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance DataInspector with dim conversions #4453

Open
mathieu17g opened this issue Oct 7, 2024 · 0 comments
Open

Enhance DataInspector with dim conversions #4453

mathieu17g opened this issue Oct 7, 2024 · 0 comments
Labels
DataInspector enhancement Feature requests and enhancements units aka dim converts

Comments

@mathieu17g
Copy link

Feature description

Convert values shown in DataInspector with corresponding axis dimension conversions

Here is a light mockup of what it could be for DateConversion and for Line and LineSegment plots

Add a value to dimension conversion in dates-integrations.jl

# Conversions to DateTimeConversion.type
function convert_value_dim(conversion::DateTimeConversion, value)
    return number_to_date(conversion.type[], value)
end
convert_value_dim(::Union{Nothing, NoDimConversion}, value) = value

Replace position2string functions in inspector.jl with ones using dimension conversions

value2string(conversion::T, value) where {T<:Union{Nothing,<:AbstractDimConversion}} =
    (converted = convert_value_dim(conversion, value)) isa AbstractFloat ?
        @sprintf("%0.3f", converted) : string(converted)
dimspos2string(conversions, p::StaticVector{2}) = 
    @sprintf("x: %s\ny: %s", 
             (value2string(c, p) for (c, p) in zip(ntuple(i -> conversions[i], 2), p))...)
dimspos2string(conversions, p::StaticVector{3}) = 
    @sprintf("x: %s\ny: %s\nz: %s",
             (value2string(c, p) for (c, p) in zip(ntuple(i -> conversions[i], 3), p))...)

Use them in show_data functions

    if to_value(get(plot, :inspector_label, automatic)) == automatic
<<<     tt.text[] = position2string(eltype(plot[1][])(pos))
>>>     conversions = get_conversions(plot)
>>>     tt.text[] = dimspos2string(conversions, eltype(plot[1][])(pos))
    else
...

Output plot example

Examples code
using GLMakie
using Dates

# Sample data
dates = [Date(2022, 1, 1) + Dates.Day(i) for i = 0:10]
values = [1, 3, 2, 4, 5, 3, 6, 4, 7, 6, 8]

fig = Figure(size=(800, 600))
axis = Axis(fig[1, 1], xlabel = "Date", ylabel = "Value")
lines!(axis, dates, values)
DataInspector(fig)
display(fig)

Before

Image

After

Image

@mathieu17g mathieu17g added the enhancement Feature requests and enhancements label Oct 7, 2024
@ffreyer ffreyer added units aka dim converts DataInspector labels Oct 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DataInspector enhancement Feature requests and enhancements units aka dim converts
Projects
None yet
Development

No branches or pull requests

2 participants