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 Legend item fill policies #12701

Merged
merged 6 commits into from Jan 27, 2023

Conversation

mattpap
Copy link
Contributor

@mattpap mattpap commented Dec 28, 2022

This adds rudimentary support for item fill policies:

import numpy as np

from bokeh.plotting import figure, show

x = np.linspace(0, 4*np.pi, 50)
y = np.sin(x)

TOOLS = "pan,wheel_zoom,box_zoom,reset,save,box_select"

p1 = figure(title="Legend Example", tools=TOOLS, width=300, height=300)

p1.circle(x, 1*y, legend_label="1*sin(x)", fill_color=None, line_color="green")

p1.square(x, 2*y, legend_label="2*sin(x)", fill_color=None, line_color="orange")
p1.line(x, 2*y, legend_label="2*sin(x)", line_color="orange")

p1.circle(x, 3*y, legend_label="3*sin(x)", fill_color=None, line_color="blue")

p1.square(x, 4*y, legend_label="4*sin(x)", fill_color=None, line_color="tomato")
p1.line(x, 4*y, legend_label="4*sin(x)", line_color="tomato")

p1.circle(x, 5*y, legend_label="5*sin(x)", fill_color=None, line_color="purple")

p1.square(x, 6*y, legend_label="6*sin(x)", fill_color=None, line_color="pink")
p1.line(x, 6*y, legend_label="6*sin(x)", line_color="pink")

p1.legend.title = 'Markers'
p1.legend.ncols = 2
p1.legend.orientation = "vertical"
p1.legend.click_policy = "mute"
p1.legend.title_location = "above"
p1.legend.item_background_policy = "even"
show(p1)

image

fixes #12692

/cc @mosc9575

@mattpap mattpap added this to the 3.1 milestone Dec 28, 2022
@codecov
Copy link

codecov bot commented Dec 28, 2022

Codecov Report

Merging #12701 (481787d) into branch-3.1 (f63969a) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@             Coverage Diff             @@
##           branch-3.1   #12701   +/-   ##
===========================================
  Coverage       92.23%   92.23%           
===========================================
  Files             314      314           
  Lines           19682    19687    +5     
===========================================
+ Hits            18154    18159    +5     
  Misses           1528     1528           

@mosc9575
Copy link
Contributor

mosc9575 commented Jan 2, 2023

This looks great. Thank you @mattpap.

@mattpap mattpap force-pushed the mattpap/12692_legend_item_background branch from ca0c1c1 to 9ddbd19 Compare January 5, 2023 15:41
@mattpap mattpap force-pushed the mattpap/12692_legend_item_background branch from 9ddbd19 to b872bbc Compare January 5, 2023 21:43
Copy link
Member

@bryevdv bryevdv left a comment

Choose a reason for hiding this comment

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

The first two comments are suggestions/advisory but I do want to get discussion and agreement regarding any changes to defaults.

bokehjs/src/lib/core/enums.ts Outdated Show resolved Hide resolved
bokehjs/src/lib/models/annotations/legend.ts Show resolved Hide resolved
bokehjs/src/lib/models/annotations/legend.ts Outdated Show resolved Hide resolved
@bryevdv
Copy link
Member

bryevdv commented Jan 25, 2023

@mattpap I think this PR is very close, would you like me to finish off the three suggestions above so that it can be merged while you focus on other PRs?

@mattpap mattpap force-pushed the mattpap/12692_legend_item_background branch from 43f46dd to 659343f Compare January 26, 2023 15:19
@mattpap mattpap requested a review from bryevdv January 26, 2023 15:19
@mattpap
Copy link
Contributor Author

mattpap commented Jan 27, 2023

Examples' test failure is unrelated and fixed in PR #12754.

@mattpap mattpap merged commit 749cdb3 into branch-3.1 Jan 27, 2023
@mattpap mattpap deleted the mattpap/12692_legend_item_background branch January 27, 2023 00:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] Add visual separation for legend items with multiline text
3 participants