Skip to content

Commit

Permalink
ScalarBars.add_scalar_bar: correct annotation text scaling setting, w…
Browse files Browse the repository at this point in the history
…hen fixed font size is given (#1750)

* ScalarBars.add_scalar_bar: correct annotation text scaling setting, when fixed font size is given

Even if a label font size was given, size of `below_label` and `above_label` was scaled with the view port.
Line 423 must be `SetAnnotationTextScalingOff` (value 0) for no scaling,
see <https://vtk.org/doc/nightly/html/classvtkScalarBarActor.html#acfe97b358b89cd544df5e7826d59e4f7>

* Annotation text scaling on, when none font size is given

(addition to last commit)

When you give none label or title font size, you want a scaling annotation text, at it was already true for the labels and the title texts.

Comment for Image Regression Testing: This will slightly change the images of the tests:
- test_above_below_scalar_range_annotations
- test_user_annotations_scalar_bar_mesh

* add test for fix/add_scalar_bar-AnnotationTextScaling

I union the both upper tests and add fixed settings for title and label font sizes.

* Add image for new test

image_cache/fixed_font_size_annotation_text_scaling_off.png

Co-authored-by: Alex Kaszynski <akascap@gmail.com>
  • Loading branch information
beppo-dd and akaszynski committed Dec 23, 2021
1 parent dc60a8d commit 0bf59f6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pyvista/plotting/scalar_bars.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,8 @@ def add_scalar_bar(self, title='', mapper=None, n_labels=5, italic=False,

if label_font_size is not None or title_font_size is not None:
scalar_bar.UnconstrainedFontSizeOn()
scalar_bar.AnnotationTextScalingOff()
else:
scalar_bar.AnnotationTextScalingOn()

label_text = scalar_bar.GetLabelTextProperty()
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions tests/plotting/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -1595,6 +1595,18 @@ def test_user_annotations_scalar_bar_mesh(uniform):
p.show(before_close_callback=verify_cache_image)


def test_fixed_font_size_annotation_text_scaling_off():
p = pyvista.Plotter()
sargs = {
'title_font_size': 12,
'label_font_size': 10}
p.add_mesh(examples.load_uniform(), clim=[100, 500], cmap='viridis',
below_color='blue', above_color='red',
annotations={300.: 'yum'},
scalar_bar_args=sargs)
p.show(before_close_callback=verify_cache_image)


def test_user_annotations_scalar_bar_volume(uniform):
p = pyvista.Plotter()
p.add_volume(uniform, scalars='Spatial Point Data', annotations={100.: 'yum'})
Expand Down

0 comments on commit 0bf59f6

Please sign in to comment.