From 85207628e87e1acb31bfb51b930232a6efb054c1 Mon Sep 17 00:00:00 2001 From: hhaensel Date: Tue, 14 Jan 2025 14:13:16 +0100 Subject: [PATCH] Ranges.RangeData: add constructors, fix parser --- src/Ranges.jl | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Ranges.jl b/src/Ranges.jl index 6c205a7b..5acd3224 100644 --- a/src/Ranges.jl +++ b/src/Ranges.jl @@ -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 @@ -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