@@ -50,6 +50,7 @@ function fixaxis!(attr, x, axisletter)
5050 ustripattribute! (attr, :ribbon , u)
5151 ustripattribute! (attr, :fillrange , u)
5252 end
53+ fixaspectratio! (attr, u, axisletter)
5354 fixmarkercolor! (attr)
5455 fixmarkersize! (attr)
5556 fixlinecolor! (attr)
124125#= ==============
125126Attribute fixing
126127===============#
128+ # Aspect ratio
129+ function fixaspectratio! (attr, u, axisletter)
130+ aspect_ratio = get! (attr, :aspect_ratio , :auto )
131+ if aspect_ratio in (:auto , :none )
132+ # Keep the default behavior (let Plots figure it out)
133+ return
134+ end
135+ if aspect_ratio === :equal
136+ aspect_ratio = 1
137+ end
138+ #= ======================================================================================
139+ Implementation example:
140+
141+ Consider an x axis in `u"m"` and a y axis in `u"s"`, and an `aspect_ratio` in `u"m/s"`.
142+ On the first pass, `axisletter` is `:x`, so `aspect_ratio` is converted to `u"m/s"/u"m"
143+ = u"s^-1"`. On the second pass, `axisletter` is `:y`, so `aspect_ratio` becomes
144+ `u"s^-1"*u"s" = 1`. If at this point `aspect_ratio` is *not* unitless, an error has been
145+ made, and the default aspect ratio fixing of Plots throws a `DimensionError` as it tries
146+ to compare `0 < 1u"m"`.
147+ =======================================================================================#
148+ if axisletter === :y
149+ attr[:aspect_ratio ] = aspect_ratio* u
150+ return
151+ end
152+ if axisletter === :x
153+ attr[:aspect_ratio ] = aspect_ratio/ u
154+ return
155+ end
156+ return
157+ end
127158
128159# Markers / lines
129160function fixmarkercolor! (attr)
0 commit comments