Skip to content

Commit

Permalink
Ranges.RangeData: add constructors, fix parser
Browse files Browse the repository at this point in the history
  • Loading branch information
hhaensel committed Jan 14, 2025
1 parent 72b0afb commit 8520762
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/Ranges.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ Base.@kwdef mutable struct RangeData{T}
range::UnitRange{T}
end

RangeData(min::Number, max::Number) = RangeData(UnitRange(min, max))
RangeData(ar::AbstractRange) = RangeData(UnitRange(minimum(ar), maximum(ar)))

const QRangeType = Union{Symbol, String, Real}
struct QRange <: AbstractRange{QRangeType}
min::QRangeType
Expand Down Expand Up @@ -209,8 +212,12 @@ function Stipple.render(rd::RangeData{T}) where {T}
Dict(:min => rd.range.start, :max => rd.range.stop)
end

function Base.parse(::Type{RangeData{T}}, d::Dict{X,Y}) where {T,X,Y}
RangeData(d["min"]:d["max"])
function Stipple.stipple_parse(::Type{RangeData{T}}, d::Dict) where T
RangeData(T(d["min"]), T(d["max"]))
end

function Stipple.stipple_parse(::Type{RangeData}, d::Dict)
RangeData(d["min"], d["max"])
end

end

0 comments on commit 8520762

Please sign in to comment.