Skip to content
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

Add support for ScaleBar annotation #13319

Merged
merged 24 commits into from
Sep 28, 2023
Merged

Conversation

mattpap
Copy link
Contributor

@mattpap mattpap commented Aug 9, 2023

TODO:

  • finish vertical orientation
  • two-dimensional scale bar
  • support geographical projections (maps)
  • finish the internal layout of the annotation
  • move computational logic to Dimensional models
  • make Dimensional models configurable
  • add more predefined units and bases
  • label/title alignment
  • allow bar length in pixels
  • allow bar decorations (e.g. tee head)
  • add support for an exact mode
  • add support math text (or at least unicode e.g. for um)
  • add more examples
  • add tests

Example:

scale_bar = ScaleBar(
    range=p.x_range,
    unit="mm",
    dimensional=MetricLength(), 
    orientation="horizontal",
    location="top_right",
    label_location="above",
    bar_length=0.2,
    bar_line_width=2,
    background_fill_alpha=0.8,
)

image

Note that displaying both a plain bar and an axis is just for the sake of the example and won't be the default.

This incorporates PR #13106.

fixes #11755

@mattpap mattpap added this to the 3.3 milestone Aug 9, 2023
@codecov
Copy link

codecov bot commented Aug 9, 2023

Codecov Report

Merging #13319 (831ae5a) into branch-3.3 (0bdaa42) will increase coverage by 0.02%.
Report is 5 commits behind head on branch-3.3.
The diff coverage is 100.00%.

@@              Coverage Diff               @@
##           branch-3.3   #13319      +/-   ##
==============================================
+ Coverage       92.44%   92.47%   +0.02%     
==============================================
  Files             317      318       +1     
  Lines           20264    20339      +75     
==============================================
+ Hits            18734    18809      +75     
  Misses           1530     1530              

@mattpap mattpap force-pushed the mattpap/11755_scale_bar branch from 7f728e2 to a2c9b2d Compare August 10, 2023 06:33
@droumis droumis mentioned this pull request Aug 11, 2023
16 tasks
@mattpap mattpap added the grant: CZI R5 Funded by CZI Round 5 grant label Aug 12, 2023
@mattpap mattpap force-pushed the mattpap/11755_scale_bar branch from a2c9b2d to e2e2b8f Compare August 29, 2023 14:37
@mattpap mattpap force-pushed the mattpap/11755_scale_bar branch 3 times, most recently from a0e0ba9 to 555284c Compare September 19, 2023 15:29
@droumis
Copy link
Member

droumis commented Sep 20, 2023

@mattpap is this ready for review, given that geo projections and 2D will be in a different PR?

@mattpap
Copy link
Contributor Author

mattpap commented Sep 21, 2023

is this ready for review, given that geo projections and 2D will be in a different PR?

Tentatively yes, but I'm still working on multiple issues.

@mattpap mattpap force-pushed the mattpap/11755_scale_bar branch 2 times, most recently from f9988ff to 34cab71 Compare September 24, 2023 12:37
@mattpap mattpap force-pushed the mattpap/11755_scale_bar branch from 34cab71 to b21884f Compare September 24, 2023 19:52
Copy link
Member

@ianthomas23 ianthomas23 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The appearance and zooming look really good.

There are rather a lot of properties of ScaleBar but I cannot see how to get rid of any of them, and I presume that default values will be fine for most use cases.

src/bokeh/models/annotations/legends.py Outdated Show resolved Hide resolved
src/bokeh/models/annotations/legends.py Outdated Show resolved Hide resolved
src/bokeh/models/annotations/legends.py Outdated Show resolved Hide resolved
src/bokeh/models/annotations/legends.py Show resolved Hide resolved
src/bokeh/models/annotations/legends.py Outdated Show resolved Hide resolved
bokehjs/src/lib/models/annotations/scale_bar.ts Outdated Show resolved Hide resolved
bokehjs/src/lib/models/annotations/scale_bar.ts Outdated Show resolved Hide resolved
bokehjs/src/lib/models/annotations/scale_bar.ts Outdated Show resolved Hide resolved
bokehjs/src/lib/models/annotations/scale_bar.ts Outdated Show resolved Hide resolved
src/bokeh/models/annotations/legends.py Outdated Show resolved Hide resolved
@mattpap
Copy link
Contributor Author

mattpap commented Sep 27, 2023

There are rather a lot of properties of ScaleBar but I cannot see how to get rid of any of them, and I presume that default values will be fine for most use cases.

Which ones specifically? Many of those properties were "inherited" from Legend and ColorBar, and use the same default values. I've been considering to have a "bare" scale bar configurable in some way, i.e. no border, padding and background color and minimal spacing between its individual components.

@mattpap mattpap force-pushed the mattpap/11755_scale_bar branch from 771c30a to 30bf020 Compare September 27, 2023 01:20
@ianthomas23
Copy link
Member

There are rather a lot of properties of ScaleBar ...

Which ones specifically? ...

None specifically, they all look useful and worth keeping. I was just commenting that there are lots of properties which might make use of ScaleBar intimidating to users. But no action is required on this.

@mattpap mattpap merged commit 96546ee into branch-3.3 Sep 28, 2023
27 checks passed
@mattpap mattpap deleted the mattpap/11755_scale_bar branch September 28, 2023 22:39
@gmerritt123
Copy link

Amazing thanks so much for implementing this feature!

Chiemezuo pushed a commit to Chiemezuo/bokeh that referenced this pull request Aug 27, 2024
* Add support for ScaleBar annotation

* Allow to configure axis face

* Add support for ArrayBuffer to ImageURL.url

* Allow to recompute base_factor and extended_mantissas

* Add basic/annotations/scale_bar_image example

* Search for officially supported chromium first

* Implement vertical orientation layout

* Complete implementation of Dimensional models

* Finalize bar layout

* Improve label/title layout construction

* Use min orthogonal sizing for bar/axis

* Improve computation of Axis._tick_extent()

* Redesign label/title positioning

* Add support for pixel bar_length

* Add support for exact bar sizing

* Add unit and integration tests

* Finalize alignment of labels/titles

* Add automatic range mode

* Move TextLayout under core/layout

* Settle on using an axis for bar layout

* Refactor construction of text layouts

* Fix/improve docstrings

* Work around Grid layout's limitations

* Improve handling of title in the layout
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
grant: CZI R5 Funded by CZI Round 5 grant status: accepted
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] Show scale in map
4 participants