Haskell Diagrams, Normalized FontSize not working as expected

64 views Asked by At

I am new to Diagrams, so I've been reading the docs, and I came upon Normalized units. This is exactly what I think I want.

I am creating a Diagram, with a couple of bounding boxes around a lot of other diagrams. The diagram is quite big, and all these inner-diagrams aren't readable with the entire diagram in view. So I wanted to have a normalized FontSize text over these bounding boxes as a header, and I want these headers to be big enough to be read, while zoomed out. However, when you zoom into one of these bounding boxes, I want the header's pixel-width to stay the same, and not grow to an insane size.

This is my header:

header = frame 5 $ fontSize (normalized 0.05) $ p $ "Number of classes: " ++ (show $ length types)

I have tried 2 things to manipulate the scale of the svg with JS when rendered in Chrome.

function zoom(){
    [x, y, w, h] = svg.getAttribute("viewBox").split(' ').map(Number);
    let newViewBox = `${x} ${y} ${w * 0.9} ${h * 0.9}`
    svg.setAttribute("viewBox", newViewBox); // And also: setAttribute("transform", "scale(1.5)")
}

This zooms correctly, but to my surprise (and horror), the normalized text, zooms as well.

Now, I fear the normalized attribute, only works when rendered by the SVGBackend, and isn't actually something recognized by SVG as a whole.

Am I simply doing something wrong, or is there another way to achieve what I want?

1

There are 1 answers

0
Brent Yorgey On

Now, I fear the normalized attribute, only works when rendered by the SVGBackend, and isn't actually something recognized by SVG as a whole.

Yes, that's exactly the problem. I am not sure how/whether it is possible to make an SVG that behaves the way you want when zoomed.