-
Notifications
You must be signed in to change notification settings - Fork 276
Add optional image to connectors and cables #153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 19 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
43ec3bf
Add an image attribute to both Connectors and Cables
kvid c8c4005
Add a caption attribute to both Connectors and Cables
kvid 0cb7118
Remove border between image and caption
kvid 06e6c49
Expand example 08 with images and captions
kvid 3dc2a55
Add an image_scale attribute to both Connectors and Cables
kvid 41b3f3a
Add an image_size attribute to both Connectors and Cables
kvid 3d7f027
Add fixedsize as third image_size value
kvid 204379a
Move image attributes into Image dataclass to fix change requests
kvid c23679d
Add info about Image dataclass
kvid d289f95
Add a minor image scaling to example 08
kvid 0c6b6f3
Compute sensible default values for unspecified image attributes
kvid c217079
Test image.width and image.height without using 'is not None'
kvid 285a28d
Avoid some bad combinations of default values
kvid 19c415c
Add aspect_ratio() function that reads image size from file
kvid 9950f7f
Improve the image.fixedsize default value computation
kvid c0a11d0
Simplify the image.fixedsize default value computation
kvid ede29cb
Make Image.gv_dir an InitVar
kvid 7c2fdd6
Improve error handling in aspect_ratio()
kvid dabd4ba
Add advanced image usage documentation
kvid a94ff3d
Add pillow (PIL) as dependecy
kvid 50d4dc7
Adjust image related attributes of ex08.yml
kvid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,61 @@ | ||
| # Advanced Image Usage | ||
|
|
||
| In rare cases when the [ordinary image scaling functionality](syntax.md#images) is insufficient, a couple of extra optional image attributes can be set to offer extra image cell space and scaling functionality when combined with the image dimension attributes `width` and `height`, but in most cases their default values below are sufficient: | ||
| - `scale: <str>` (how an image will use the available cell space) is default `false` if no dimension is set, or `true` if only one dimension is set, or `both` if both dimensions are set. | ||
| - `fixedsize: <bool>` (scale to fixed size or expand to minimum size) is default `false` when no dimension is set or if a `scale` value is set, and `true` otherwise. | ||
| - When `fixedsize` is true and only one dimension is set, then the other dimension is calculated using the image aspect ratio. If reading the aspect ratio fails, then 1:1 ratio is assumed. | ||
|
|
||
| See explanations of all supported values for these attributes in subsections below. | ||
|
|
||
| ## The effect of `fixedsize` boolean values | ||
|
|
||
| - When `false`, any `width` or `height` values are _minimum_ values used to expand the image cell size for more available space, but cell contents or other size demands in the table might expand this cell even more than specified by `width` or `height`. | ||
| - When `true`, both `width` and `height` values are required by Graphwiz and specify the fixed size of the image cell, distorting any image inside if it don't fit. Any borders are normally drawn around the fixed size, and therefore, WireViz enclose the image cell in an extra table without borders when `fixedsize` is true to keep the borders around the outer non-fixed cell. | ||
|
|
||
| ## The effect of `scale` string values: | ||
|
|
||
| - When `false`, the image is not scaled. | ||
| - When `true`, the image is scaled proportionally to fit within the available image cell space. | ||
| - When `width`, the image width is expanded (height is normally unchanged) to fill the available image cell space width. | ||
| - When `height`, the image height is expanded (width is normally unchanged) to fill the available image cell space height. | ||
| - When `both`, both image width and height are expanded independently to fill the available image cell space. | ||
|
|
||
| In all cases (except `true`) the image might get distorted when a specified fixed image cell size limits the available space to less than what an unscaled image needs. | ||
|
|
||
| In the WireViz diagrams there are no other space demanding cells in the same row, and hence, there are never extra available image cell space height unless a greater image cell `height` also is set. | ||
|
|
||
| ## Usage examples | ||
|
|
||
| All examples of `image` attribute combinations below also require the mandatory `src` attribute to be set. | ||
|
|
||
| - Expand the image proportionally to fit within a minimum height and the node width: | ||
| ```yaml | ||
| height: 100 # Expand image cell to this minimum height | ||
| fixedsize: false # Avoid scaling to a fixed size | ||
| # scale default value is true in this case | ||
| ``` | ||
|
|
||
| - Increase the space around the image by expanding the image cell space (width and/or height) to a larger value without scaling the image: | ||
| ```yaml | ||
| width: 200 # Expand image cell to this minimum width | ||
| height: 100 # Expand image cell to this minimum height | ||
| scale: false # Avoid scaling the image | ||
| # fixedsize default value is false in this case | ||
| ``` | ||
|
|
||
| - Stretch the image width to fill the available space in the node: | ||
| ```yaml | ||
| scale: width # Expand image width to fill the available image cell space | ||
| # fixedsize default value is false in this case | ||
| ``` | ||
|
|
||
| - Stretch the image height to a minimum value: | ||
| ```yaml | ||
| height: 100 # Expand image cell to this minimum height | ||
| scale: height # Expand image height to fill the available image cell space | ||
| # fixedsize default value is false in this case | ||
| ``` | ||
|
|
||
| ## How Graphviz support this image scaling | ||
|
|
||
| The connector and cable nodes are rendered using a HTML `<table>` containing an image cell `<td>` with `width`, `height`, and `fixedsize` attributes containing an image `<img>` with `src` and `scale` attributes. See also the [Graphviz doc](https://graphviz.org/doc/info/shapes.html#html), but note that WireViz uses default values as described above. |
This file contains hidden or 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.