Skip to content

Add AxisClick event#14050

Merged
bryevdv merged 8 commits intobranch-3.6from
bv/601-axis-events
Sep 17, 2024
Merged

Add AxisClick event#14050
bryevdv merged 8 commits intobranch-3.6from
bv/601-axis-events

Conversation

@bryevdv
Copy link
Member

@bryevdv bryevdv commented Sep 4, 2024

This PR adds support for an AxisClick / "axis_click" event that reports the location that an axis was clicked.

This can be tested by adding code like the following to nearly any example":

from bokeh.models import CustomJS
p.xaxis[0].js_on_event("axis_click", CustomJS(code="""
    alert('It works! ' + cb_obj.value)
"""))

p.yaxis[0].js_on_event("axis_click", CustomJS(code="""
    alert('It works! ' + cb_obj.value)
"""))

This needs some polish:

  • @mattpap as usual any suggestions for BokehJS tests welcome. I did not see much existing tests for these sorts of events that I might look to emulate
  • @bokeh/dev thoughts on interesting examples? This has been long-requested but there were never concrete use-cases described that I recall.
  • @tcmetzger any thoughts on where / how much narrative docs to add are welcome

@bryevdv bryevdv added this to the 3.6 milestone Sep 4, 2024
@mattpap
Copy link
Contributor

mattpap commented Sep 4, 2024

as usual any suggestions for BokehJS tests welcome. I did not see much existing tests for these sorts of events that I might look to emulate

There aren't many tests for this, but there is one recently added that should be quite useful as a basis:

describe("in issue #12778", () => {
it("doesn't allow emitting RangesUpdate event for linked plots", async () => {
const p0 = fig([200, 200], {tools: "pan"})
const p1 = fig([200, 200], {tools: "pan", x_range: p0.x_range, y_range: p0.y_range})
const p2 = fig([200, 200], {tools: "pan", x_range: p0.x_range})
p0.scatter([1, 2, 3], [0, 1, 2])
p1.scatter([1, 2, 3], [2, 3, 4])
p2.scatter([1, 2, 3], [5, 6, 7])
const events: RangesUpdate[] = []
p0.on_event(RangesUpdate, (event) => events.push(event))
p1.on_event(RangesUpdate, (event) => events.push(event))
p2.on_event(RangesUpdate, (event) => events.push(event))
const row = new Row({children: [p0, p1, p2]})
const {view} = await display(row)
const pv0 = view.owner.get_one(p0)
const actions = new PlotActions(pv0)
await actions.pan(xy(2, 1), xy(2, 3))
await paint()
expect(events.length).to.be.equal(3)
expect(events[0].origin).to.be.equal(p0)
expect(events[1].origin).to.be.equal(p1)
expect(events[2].origin).to.be.equal(p2)
})
})

@bryevdv
Copy link
Member Author

bryevdv commented Sep 16, 2024

@mattpap it looks like you've addressed all your own comments?

@bryevdv bryevdv requested a review from mattpap September 16, 2024 19:35
@mattpap
Copy link
Contributor

mattpap commented Sep 17, 2024

it looks like you've addressed all your own comments?

Yes, given that they were all related to the same code block.

@bryevdv bryevdv merged commit e721634 into branch-3.6 Sep 17, 2024
@bryevdv bryevdv deleted the bv/601-axis-events branch September 17, 2024 16:01
@github-actions
Copy link

github-actions bot commented Jan 1, 2025

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 Jan 1, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for click events on categorical axes

2 participants