@@ -6,36 +6,40 @@ using Observables
66using Dates
77
88struct UnixTimeConversion <: Makie.AbstractDimConversion
9- custom_epoch:: Observable{Union{Nothing, UnixTime} }
10- function UnixTimeConversion (custom_epoch = nothing )
11- new (Observable {Union{Nothing, UnixTime} } (custom_epoch; ignore_equal_values= true ))
9+ custom_epoch:: Observable{UnixTime}
10+ function UnixTimeConversion (custom_epoch = UNIX_EPOCH )
11+ new (Observable {UnixTime} (custom_epoch; ignore_equal_values= true ))
1212 end
1313end
1414
1515function number_to_unixtime (conversion:: UnixTimeConversion , i)
16- Nanosecond (round (Int64, Float64 (i))) + something ( conversion. custom_epoch[], UNIX_EPOCH)
16+ Nanosecond (round (Int64, Float64 (i))) + conversion. custom_epoch[]
1717end
18+ function unixtime_to_number (conversion:: UnixTimeConversion , value:: UnixTime )
19+ Dates. value (value - conversion. custom_epoch[])
20+ end
21+
22+ Makie. expand_dimensions (:: PointBased , y:: AbstractVector{<:UnixTime} ) = (keys (y), y)
1823
19- Makie. needs_tick_update_observable (conversion:: UnixTimeConversion ) = nothing
24+ Makie. needs_tick_update_observable (conversion:: UnixTimeConversion ) = conversion . custom_epoch
2025
2126Makie. should_dim_convert (:: Type{UnixTime} ) = true
2227
2328Makie. create_dim_conversion (:: Type{UnixTime} ) = UnixTimeConversion ()
2429
2530function Makie. convert_dim_value (conversion:: UnixTimeConversion , value:: UnixTime )
26- Dates . value (value - something ( conversion. custom_epoch[], UNIX_EPOCH) )
31+ unixtime_to_number ( conversion, value )
2732end
2833function Makie. convert_dim_value (conversion:: UnixTimeConversion , values:: AbstractArray{UnixTime} )
29- Dates. value .(values .- something (conversion. custom_epoch[], UNIX_EPOCH))
34+ unixtime_to_number .(tuple (conversion), values)
35+ end
36+ function Makie. convert_dim_value (conversion:: UnixTimeConversion , attr, values, prev_values)
37+ unixtime_to_number .(tuple (conversion), values)
3038end
3139
3240function Makie. convert_dim_observable (conversion:: UnixTimeConversion , values:: Observable , deregister)
33- if conversion. custom_epoch[] === nothing
34- conversion. custom_epoch[] = last (values[])
35- end
36-
3741 result = map (values, conversion. custom_epoch) do vs, ep
38- Dates. value .(vs .- something (ep, UNIX_EPOCH) )
42+ Dates. value .(vs .- ep )
3943 end
4044 append! (deregister, result. inputs)
4145 result
0 commit comments