Skip to content

Commit ef2d0d8

Browse files
committed
enforce SymbolicDimensions for DQConversion
1 parent 2d09a66 commit ef2d0d8

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

docs/src/examples.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -543,8 +543,8 @@ lines(x_si, y_si;
543543
)
544544
```
545545

546-
!!! warning
547-
Make sure to use [Symbolic Dimensions](@ref) for this conversion to work properly.
546+
!!! note
547+
A [Symbolic Dimensions](@ref) object is passed to `DQConversion` for this conversion to work properly. Passing a regular `Quantity`, e.g., (u"km") will throw an error.
548548

549549
Finally, the desired units for a figure can also be set ahead of time. All plot objects within it will automatically convert to the given units:
550550

ext/DynamicQuantitiesMakieExt.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module DynamicQuantitiesMakieExt
22

3-
using DynamicQuantities: UnionAbstractQuantity, ustrip, dimension
3+
using DynamicQuantities: UnionAbstractQuantity, SymbolicDimensions, ustrip, dimension
44
using TestItems: @testitem
55

66
import Makie as M
@@ -25,7 +25,6 @@ function unit_convert(quantity::UnionAbstractQuantity, value)
2525
return Float64(conv)
2626
end
2727

28-
# TODO: Maybe only allow symbolic units to avoid bugs?
2928
"""
3029
DQConversion(unit=automatic; units_in_label=false)
3130
@@ -40,7 +39,7 @@ Allows to plot arrays of DynamicQuantity objects into an axis.
4039
```julia
4140
using DynamicQuantities, CairoMakie
4241
43-
# DQConversion will get chosen automatically:
42+
# DQConversion will get chosen automatically,
4443
scatter(1:4, [1u"ns", 2u"ns", 3u"ns", 4u"ns"])
4544
```
4645
@@ -56,7 +55,7 @@ scatter(1:4, [0.01u"km", 0.02u"km", 0.03u"km", 0.04u"km"]; axis=(dim2_conversion
5655
```
5756
"""
5857
struct DQConversion <: M.AbstractDimConversion
59-
quantity::M.Observable{Any}
58+
quantity::M.Observable{UnionAbstractQuantity{T1, SymbolicDimensions{T2}} where {T1 <: Real, T2 <: Real}}
6059
automatic_units::Bool
6160
units_in_label::M.Observable{Bool}
6261
end

0 commit comments

Comments
 (0)