Default diagonal-length rather than height of diagrams.

This is better-behaved for diagrams with strong aspect ratio, in particular
it prevents diagrams with very low height from being stretched “infinitely
wide”.
This commit is contained in:
Justus Sagemüller 2018-03-06 13:53:23 +01:00
parent a200c07f6b
commit 7c54a101ca

View File

@ -62,8 +62,12 @@ withSizeSpec spec renderable = ManuallySized renderable imgWidth imgHeight
V2 (Just w) (Just h) -> (w, h)
V2 (Just w) Nothing -> (w, w/aspect)
V2 Nothing (Just h) -> (aspect*h, h)
V2 Nothing Nothing -> (aspect*defaultHeight, defaultHeight)
defaultHeight = 300
V2 Nothing Nothing -> (defaultDiagonal / sqrt (1 + aspect^2)) *^ (aspect, 1)
-- w^2 + h^2 = defaultDiagonal^2 / (1+aspect^2)
-- * (aspect^2 + 1)
-- = defaultDiagonal^2
-- w/h = aspect/1 = aspect
defaultDiagonal = 500
withImgWidth :: Int -> Diagram Cairo -> ManuallySized (Diagram Cairo)
withImgWidth imgWidth = withSizeSpec $ mkSizeSpec2D (Just $ fromIntegral imgWidth)