-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add post: SVG viewPort, width and height
Fixes #141
- Loading branch information
Showing
5 changed files
with
94 additions
and
22 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
--- | ||
title: SVG viewPort, width and height | ||
author: thilo | ||
published: 2022-05-01 | ||
modified: 2022-05-01 | ||
description: TODO | ||
category: data-viz | ||
tags: | ||
- sveltekit | ||
--- | ||
|
||
# SVG test | ||
|
||
test | ||
|
||
## SVG with viewBox | ||
|
||
### Constrain parent | ||
|
||
- [Default width of SVG element is `auto` (treated as 100%).](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/width#svg) | ||
- [Default height of SVG element is `auto` (treated as 100%).](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/height#svg) | ||
|
||
#### Width and height of parent are not constrained | ||
|
||
SVG takes 100% of width and maintains aspect ratio defined in viewBox. | ||
|
||
#### Constrain width of parent | ||
|
||
SVG adapts to contrained width and maintains aspect ratio defined in viewBox. | ||
|
||
#### Constrain height of parent | ||
|
||
SVG still takes up availalbe width and maintains aspect ratio, but overflows | ||
height. Use `overflow` property to control overflow behavior. | ||
|
||
https://developer.mozilla.org/en-US/docs/Web/CSS/overflow | ||
|
||
#### Constrain width and height of parent | ||
|
||
Previous two cases combined. | ||
|
||
### Constrain SVG element (not parent) | ||
|
||
#### Constrain width | ||
|
||
Aspect ratio from viewBox is preserved. | ||
|
||
#### Constrain height | ||
|
||
Aspect ratio from viewBox is preserved. | ||
|
||
#### Constrain width and height different aspect ratio | ||
|
||
Build big nested SVG like on mozilla help page. | ||
|
||
## SVG without viewBox | ||
|
||
Pixel width and height become coordinate system. When you leave width or height | ||
away, defaults kick in. | ||
|
||
## Exaggerated viewBox | ||
|
||
viewbox with 9 logical pixels is still displayed smoothly, becaue it scales up | ||
to the availalbe pixels. You can think of viewBox like a retina display. |