Skip to content

Commit

Permalink
Add unit and integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mattpap committed Sep 19, 2023
1 parent bbb79cd commit a0e0ba9
Showing 1 changed file with 106 additions and 0 deletions.
106 changes: 106 additions & 0 deletions bokehjs/test/integration/annotations/scale_bar.ts
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"))
})
})

0 comments on commit a0e0ba9

Please sign in to comment.