-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
106 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import {display} from "../_util" | ||
|
||
import {ScaleBar, Plot, Range1d} from "@bokehjs/models" | ||
import type {Location} from "@bokehjs/core/enums" | ||
|
||
describe("ScaleBar annotation", () => { | ||
describe("should support horizontal orientation", () => { | ||
function plot(scale_bar: ScaleBar) { | ||
return new Plot({ | ||
width: 300, | ||
height: 100, | ||
x_range: new Range1d({start: 0, end: 1}), | ||
y_range: new Range1d({start: 0, end: 1}), | ||
center: [scale_bar], | ||
}) | ||
} | ||
|
||
async function scale_bar_with_label_location(label_location: Location, label_standoff?: number) { | ||
const scale_bar = new ScaleBar({ | ||
range: new Range1d({start: 0, end: 1}), | ||
bar_length: 0.2, | ||
orientation: "horizontal", | ||
location: "top_right", | ||
label_location, | ||
label_standoff, | ||
}) | ||
await display(plot(scale_bar)) | ||
} | ||
|
||
it("with label above", async () => await scale_bar_with_label_location("above")) | ||
it("with label below", async () => await scale_bar_with_label_location("below")) | ||
it("with label left", async () => await scale_bar_with_label_location("left")) | ||
it("with label right", async () => await scale_bar_with_label_location("right")) | ||
|
||
const standoff = 20 | ||
it(`with label above and ${standoff}px standoff`, async () => await scale_bar_with_label_location("above", standoff)) | ||
it(`with label below and ${standoff}px standoff`, async () => await scale_bar_with_label_location("below", standoff)) | ||
it(`with label left and ${standoff}px standoff`, async () => await scale_bar_with_label_location("left", standoff)) | ||
it(`with label right and ${standoff}px standoff`, async () => await scale_bar_with_label_location("right", standoff)) | ||
|
||
it("with 0px padding", async () => { | ||
const scale_bar = new ScaleBar({ | ||
range: new Range1d({start: 0, end: 1}), | ||
bar_length: 0.2, | ||
orientation: "horizontal", | ||
location: "top_right", | ||
label_location: "above", | ||
padding: 0, | ||
}) | ||
await display(plot(scale_bar)) | ||
}) | ||
|
||
it("with 20px padding", async () => { | ||
const scale_bar = new ScaleBar({ | ||
range: new Range1d({start: 0, end: 1}), | ||
bar_length: 0.2, | ||
orientation: "horizontal", | ||
location: "top_right", | ||
label_location: "above", | ||
padding: 20, | ||
}) | ||
await display(plot(scale_bar)) | ||
}) | ||
|
||
it("with 0px padding and no border", async () => { | ||
const scale_bar = new ScaleBar({ | ||
range: new Range1d({start: 0, end: 1}), | ||
bar_length: 0.2, | ||
orientation: "horizontal", | ||
location: "top_right", | ||
label_location: "above", | ||
padding: 0, | ||
border_line_color: null, | ||
}) | ||
await display(plot(scale_bar)) | ||
}) | ||
}) | ||
|
||
describe("should support vertical orientation", () => { | ||
function plot(scale_bar: ScaleBar) { | ||
return new Plot({ | ||
width: 100, | ||
height: 300, | ||
x_range: new Range1d({start: 0, end: 1}), | ||
y_range: new Range1d({start: 0, end: 1}), | ||
center: [scale_bar], | ||
}) | ||
} | ||
|
||
async function scale_bar_with_label_location(label_location: Location) { | ||
const scale_bar = new ScaleBar({ | ||
range: new Range1d({start: 0, end: 1}), | ||
bar_length: 0.2, | ||
orientation: "vertical", | ||
location: "top_right", | ||
label_location, | ||
}) | ||
await display(plot(scale_bar)) | ||
} | ||
|
||
it("with label above", async () => await scale_bar_with_label_location("above")) | ||
it("with label below", async () => await scale_bar_with_label_location("below")) | ||
it("with label left", async () => await scale_bar_with_label_location("left")) | ||
it("with label right", async () => await scale_bar_with_label_location("right")) | ||
}) | ||
}) |