forked from bokeh/bokeh
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for click-style pan tools (bokeh#14033)
- Loading branch information
Showing
19 changed files
with
305 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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.
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 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 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 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,108 @@ | ||
import {PlotActionTool, PlotActionToolView} from "./plot_action_tool" | ||
import {Float} from "core/kinds" | ||
import {PanDirection} from "core/enums" | ||
import type * as p from "core/properties" | ||
import * as icons from "styles/icons.css" | ||
import {update_ranges} from "../gestures/pan_tool" | ||
|
||
export class ClickPanToolView extends PlotActionToolView { | ||
declare model: ClickPanTool | ||
|
||
doit(): void { | ||
const direction = (() => { | ||
switch (this.model.direction) { | ||
case "left": | ||
case "west": | ||
return {x: -1, y: 0} | ||
case "right": | ||
case "east": | ||
return {x: +1, y: 0} | ||
case "up": | ||
case "north": | ||
return {x: 0, y: -1} | ||
case "down": | ||
case "south": | ||
return {x: 0, y: +1} | ||
} | ||
})() | ||
|
||
const {frame} = this.plot_view | ||
const {factor} = this.model | ||
|
||
const x_offset = direction.x*factor*frame.bbox.width | ||
const y_offset = direction.y*factor*frame.bbox.height | ||
|
||
const bbox = frame.bbox.translate(x_offset, y_offset) | ||
|
||
const xrs = update_ranges(frame.x_scales, bbox.x0, bbox.x1) | ||
const yrs = update_ranges(frame.y_scales, bbox.y0, bbox.y1) | ||
this.plot_view.update_range({xrs, yrs}, {panning: true}) | ||
} | ||
} | ||
|
||
export namespace ClickPanTool { | ||
export type Attrs = p.AttrsOf<Props> | ||
|
||
export type Props = PlotActionTool.Props & { | ||
direction: p.Property<PanDirection> | ||
factor: p.Property<number> | ||
} | ||
} | ||
|
||
export interface ClickPanTool extends ClickPanTool.Attrs {} | ||
|
||
export class ClickPanTool extends PlotActionTool { | ||
declare properties: ClickPanTool.Props | ||
declare __view_type__: ClickPanToolView | ||
|
||
constructor(attrs?: Partial<ClickPanTool.Attrs>) { | ||
super(attrs) | ||
} | ||
|
||
static { | ||
this.prototype.default_view = ClickPanToolView | ||
|
||
this.define<ClickPanTool.Props>(() => ({ | ||
direction: [ PanDirection ], | ||
factor: [ Float, 0.1 ], | ||
})) | ||
|
||
this.register_alias("pan_left", () => new ClickPanTool({direction: "left"})) | ||
this.register_alias("pan_right", () => new ClickPanTool({direction: "right"})) | ||
this.register_alias("pan_up", () => new ClickPanTool({direction: "up"})) | ||
this.register_alias("pan_down", () => new ClickPanTool({direction: "down"})) | ||
|
||
this.register_alias("pan_west", () => new ClickPanTool({direction: "west"})) | ||
this.register_alias("pan_east", () => new ClickPanTool({direction: "east"})) | ||
this.register_alias("pan_north", () => new ClickPanTool({direction: "north"})) | ||
this.register_alias("pan_south", () => new ClickPanTool({direction: "south"})) | ||
} | ||
|
||
override tool_name = "Click Pan" | ||
|
||
override get tooltip(): string { | ||
return `Pan ${this.direction}` | ||
} | ||
|
||
override get computed_icon(): string { | ||
const icon = super.computed_icon | ||
if (icon != null) { | ||
return icon | ||
} else { | ||
switch (this.direction) { | ||
case "left": | ||
case "west": | ||
return `.${icons.tool_icon_pan_left}` | ||
case "right": | ||
case "east": | ||
return `.${icons.tool_icon_pan_right}` | ||
case "up": | ||
case "north": | ||
return `.${icons.tool_icon_pan_up}` | ||
case "down": | ||
case "south": | ||
return `.${icons.tool_icon_pan_down}` | ||
} | ||
} | ||
} | ||
} |
This file contains 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
2 changes: 1 addition & 1 deletion
2
bokehjs/test/baselines/linux/Icons__should_support_all_icons_defined_in_less_icons.less.blf
This file contains 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 |
---|---|---|
@@ -1 +1 @@ | ||
FlexDiv bbox=[0, 0, 300, 262] | ||
FlexDiv bbox=[0, 0, 300, 296] |
Binary file modified
BIN
+1.34 KB
(110%)
.../baselines/linux/Icons__should_support_all_icons_defined_in_less_icons.less.png
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 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 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 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,90 @@ | ||
import {expect} from "assertions" | ||
import {display} from "../../../_util" | ||
|
||
import {ClickPanTool} from "@bokehjs/models/tools/actions/click_pan_tool" | ||
import {Range1d} from "@bokehjs/models/ranges/range1d" | ||
import {Plot} from "@bokehjs/models/plots/plot" | ||
import type {PanDirection} from "@bokehjs/core/enums" | ||
|
||
describe("ClickPanTool", () => { | ||
|
||
async function mkplot(direction: PanDirection) { | ||
const plot = new Plot({ | ||
x_range: new Range1d({start: 0, end: 1}), | ||
y_range: new Range1d({start: 0, end: 1}), | ||
}) | ||
const tool = new ClickPanTool({direction, factor: 0.2}) | ||
plot.add_tools(tool) | ||
const {view: plot_view} = await display(plot) | ||
const tool_view = plot_view.owner.get_one(tool) | ||
return {plot_view, tool_view} | ||
} | ||
|
||
it("should translate x-range left", async () => { | ||
const {plot_view, tool_view} = await mkplot("left") | ||
const {x_range, y_range} = plot_view.frame | ||
|
||
tool_view.doit() | ||
expect(x_range.interval).to.be.similar([-0.2, 0.8]) | ||
expect(y_range.interval).to.be.similar([ 0.0, 1.0]) | ||
|
||
tool_view.doit() | ||
expect(x_range.interval).to.be.similar([-0.4, 0.6]) | ||
expect(y_range.interval).to.be.similar([ 0.0, 1.0]) | ||
|
||
tool_view.doit() | ||
expect(x_range.interval).to.be.similar([-0.6, 0.4]) | ||
expect(y_range.interval).to.be.similar([ 0.0, 1.0]) | ||
}) | ||
|
||
it("should translate x-range right", async () => { | ||
const {plot_view, tool_view} = await mkplot("right") | ||
const {x_range, y_range} = plot_view.frame | ||
|
||
tool_view.doit() | ||
expect(x_range.interval).to.be.similar([0.2, 1.2]) | ||
expect(y_range.interval).to.be.similar([0.0, 1.0]) | ||
|
||
tool_view.doit() | ||
expect(x_range.interval).to.be.similar([0.4, 1.4]) | ||
expect(y_range.interval).to.be.similar([0.0, 1.0]) | ||
|
||
tool_view.doit() | ||
expect(x_range.interval).to.be.similar([0.6, 1.6]) | ||
expect(y_range.interval).to.be.similar([0.0, 1.0]) | ||
}) | ||
|
||
it("should translate y-range up", async () => { | ||
const {plot_view, tool_view} = await mkplot("up") | ||
const {x_range, y_range} = plot_view.frame | ||
|
||
tool_view.doit() | ||
expect(x_range.interval).to.be.similar([0.0, 1.0]) | ||
expect(y_range.interval).to.be.similar([0.2, 1.2]) | ||
|
||
tool_view.doit() | ||
expect(x_range.interval).to.be.similar([0.0, 1.0]) | ||
expect(y_range.interval).to.be.similar([0.4, 1.4]) | ||
|
||
tool_view.doit() | ||
expect(x_range.interval).to.be.similar([0.0, 1.0]) | ||
expect(y_range.interval).to.be.similar([0.6, 1.6]) | ||
}) | ||
|
||
it("should translate y-range down", async () => { | ||
const {plot_view, tool_view} = await mkplot("down") | ||
const {x_range, y_range} = plot_view.frame | ||
|
||
tool_view.doit() | ||
expect(x_range.interval).to.be.similar([ 0.0, 1.0]) | ||
expect(y_range.interval).to.be.similar([-0.2, 0.8]) | ||
|
||
tool_view.doit() | ||
expect(x_range.interval).to.be.similar([ 0.0, 1.0]) | ||
expect(y_range.interval).to.be.similar([-0.4, 0.6]) | ||
|
||
tool_view.doit() | ||
expect(x_range.interval).to.be.similar([ 0.0, 1.0]) | ||
expect(y_range.interval).to.be.similar([-0.6, 0.4]) | ||
}) | ||
}) |
This file contains 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 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
Oops, something went wrong.