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

Replace data annotations with glyphs #13344

Open
wants to merge 23 commits into
base: branch-3.5
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c0005da
Add support for Whisker glyph
mattpap Aug 21, 2023
cea8efd
Add support for Band glyph
mattpap Sep 18, 2023
8ab1dd1
Add a backwards compatibility layer
mattpap Sep 20, 2023
00bb1a2
Make auto-ranging configurable in data renderers
mattpap Sep 20, 2023
a2c89d1
Replace LabelSet with Text glyph
mattpap Oct 11, 2023
8cc51c5
Update visual baselines
mattpap Nov 7, 2023
1e3df99
Rename GlyphView.{base->base_glyph}
mattpap Dec 6, 2023
4c4022d
Update cross integration tests' baselines
mattpap Feb 17, 2024
3daf988
Rename {Band,Whisker} glyphs to {Band,Whisker}Glyph
mattpap Mar 30, 2024
5afa7b1
Remove models/annotations/upper_lower.ts
mattpap Mar 30, 2024
72b95e3
Update deprecation notices
mattpap Mar 30, 2024
92a3d0c
Replace Arrow annotation with ArrowGlyph
mattpap Apr 3, 2024
550efad
Fix order of glyph decoration painting
mattpap Apr 3, 2024
fd1b307
Improve typing in plotting._renderer
mattpap Apr 3, 2024
914c9da
Replace HTMLLabelSet annotation with HTMLText glyph
mattpap Apr 4, 2024
c7fe1da
Remove DataAnnotation base class
mattpap Apr 4, 2024
e00e15d
Update baseline images
mattpap Apr 4, 2024
2fef394
Update *.blf files after a rebase
mattpap May 8, 2024
581ced1
Rename html/{->html}{label,title}.ts
mattpap May 9, 2024
f507a45
Add support for screen coordinates to renderers
mattpap May 9, 2024
7b8ca2c
Attempt to finalize implementation of HTMLText
mattpap May 15, 2024
c284974
Allow Range-like objects in Figure.subplot()
mattpap May 17, 2024
a892d6e
Finalize screen coordinates for legacy annotations
mattpap May 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
55 changes: 55 additions & 0 deletions bokehjs/src/lib/api/glyph_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
AnnularWedge,
Annulus,
Arc,
ArrowGlyph as Arrow,
BandGlyph as Band,
Bezier,
Block,
Circle,
Expand All @@ -21,6 +23,7 @@ import {
HBar,
HSpan,
HStrip,
HTMLText,
HexTile,
Image,
ImageRGBA,
Expand Down Expand Up @@ -48,6 +51,7 @@ import {
VSpan,
VStrip,
Wedge,
WhiskerGlyph as Whisker,
} from "../models/glyphs"

import type {Marker} from "../models/glyphs/marker"
Expand Down Expand Up @@ -157,6 +161,8 @@ export type GlyphArgs<P> = ArgsOf<P> & UnitsOf<P> & AuxGlyph & ColorAlpha
export type AnnularWedgeArgs = GlyphArgs<AnnularWedge.Props> & AuxLine & AuxFill & AuxHatch
export type AnnulusArgs = GlyphArgs<Annulus.Props> & AuxLine & AuxFill & AuxHatch
export type ArcArgs = GlyphArgs<Arc.Props> & AuxLine
export type ArrowArgs = GlyphArgs<Arrow.Props> & AuxLine
export type BandArgs = GlyphArgs<Band.Props> & AuxLine & AuxFill & AuxHatch
export type BezierArgs = GlyphArgs<Bezier.Props> & AuxLine
export type BlockArgs = GlyphArgs<Block.Props> & AuxLine & AuxFill & AuxHatch
export type CircleArgs = GlyphArgs<Circle.Props> & AuxLine & AuxFill & AuxHatch
Expand All @@ -166,6 +172,7 @@ export type HAreaStepArgs = GlyphArgs<HAreaStep.Props> & AuxFi
export type HBarArgs = GlyphArgs<HBar.Props> & AuxLine & AuxFill & AuxHatch
export type HSpanArgs = GlyphArgs<HSpan.Props> & AuxLine
export type HStripArgs = GlyphArgs<HStrip.Props> & AuxLine & AuxFill & AuxHatch
export type HTMLTextArgs = GlyphArgs<HTMLText.Props> & AuxText
export type HexTileArgs = GlyphArgs<HexTile.Props> & AuxLine & AuxFill & AuxHatch
export type ImageArgs = GlyphArgs<Image.Props>
export type ImageRGBAArgs = GlyphArgs<ImageRGBA.Props>
Expand Down Expand Up @@ -194,6 +201,7 @@ export type VBarArgs = GlyphArgs<VBar.Props> & AuxLine & AuxFi
export type VSpanArgs = GlyphArgs<VSpan.Props> & AuxLine
export type VStripArgs = GlyphArgs<VStrip.Props> & AuxLine & AuxFill & AuxHatch
export type WedgeArgs = GlyphArgs<Wedge.Props> & AuxLine & AuxFill & AuxHatch
export type WhiskerArgs = GlyphArgs<Whisker.Props> & AuxLine

export abstract class GlyphAPI {
abstract _glyph<G extends Glyph>(cls: Class<G>, method: string, positional: NamesOf<G>, args: unknown[], overrides?: object): TypedGlyphRenderer<G>
Expand Down Expand Up @@ -237,6 +245,30 @@ export abstract class GlyphAPI {
return this._glyph(Arc, "arc", ["x", "y", "radius", "start_angle", "end_angle"], args)
}

arrow(): TypedGlyphRenderer<Arrow>
arrow(args: Partial<ArrowArgs>): TypedGlyphRenderer<Arrow>
arrow(
x0: ArrowArgs["x0"],
y0: ArrowArgs["y0"],
x1: ArrowArgs["x1"],
y1: ArrowArgs["y1"],
args?: Partial<ArrowArgs>): TypedGlyphRenderer<Arrow>
arrow(...args: unknown[]): TypedGlyphRenderer<Arrow> {
return this._glyph(Arrow, "arrow", ["x0", "y0", "x1", "y1"], args)
}

band(): TypedGlyphRenderer<Band>
band(args: Partial<BandArgs>): TypedGlyphRenderer<Band>
band(
dimension: BandArgs["dimension"],
base: BandArgs["base"],
lower: BandArgs["lower"],
upper: BandArgs["upper"],
args?: Partial<BandArgs>): TypedGlyphRenderer<Band>
band(...args: unknown[]): TypedGlyphRenderer<Band> {
return this._glyph(Band, "band", ["dimension", "base", "lower", "upper"], args)
}

bezier(): TypedGlyphRenderer<Bezier>
bezier(args: Partial<BezierArgs>): TypedGlyphRenderer<Bezier>
bezier(
Expand Down Expand Up @@ -342,6 +374,17 @@ export abstract class GlyphAPI {
return this._glyph(HStrip, "hstrip", ["y0", "y1"], args)
}

html_text(): TypedGlyphRenderer<HTMLText>
html_text(args: Partial<HTMLTextArgs>): TypedGlyphRenderer<HTMLText>
html_text(
x: HTMLTextArgs["x"],
y: HTMLTextArgs["y"],
text: HTMLTextArgs["text"],
args?: Partial<HTMLTextArgs>): TypedGlyphRenderer<HTMLText>
html_text(...args: unknown[]): TypedGlyphRenderer<HTMLText> {
return this._glyph(HTMLText, "html_text", ["x", "y", "text"], args)
}

hex_tile(): TypedGlyphRenderer<HexTile>
hex_tile(args: Partial<HexTileArgs>): TypedGlyphRenderer<HexTile>
hex_tile(
Expand Down Expand Up @@ -636,6 +679,18 @@ export abstract class GlyphAPI {
return this._glyph(Wedge, "wedge", ["x", "y", "radius", "start_angle", "end_angle"], args)
}

whisker(): TypedGlyphRenderer<Whisker>
whisker(args: Partial<WhiskerArgs>): TypedGlyphRenderer<Whisker>
whisker(
dimension: WhiskerArgs["dimension"],
base: WhiskerArgs["base"],
lower: WhiskerArgs["lower"],
upper: WhiskerArgs["upper"],
args?: Partial<WhiskerArgs>): TypedGlyphRenderer<Whisker>
whisker(...args: unknown[]): TypedGlyphRenderer<Whisker> {
return this._glyph(Whisker, "whisker", ["dimension", "base", "lower", "upper"], args)
}

private _scatter(args: unknown[], marker?: MarkerType): TypedGlyphRenderer<Scatter> {
return this._glyph(Scatter, marker ?? "scatter", ["x", "y"], args, marker != null ? {marker} : undefined)
}
Expand Down
1 change: 1 addition & 0 deletions bokehjs/src/lib/core/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type ElementOurAttrs = {
}

type ElementCommonAttrs = {
id: Element["id"]
title: HTMLElement["title"]
tabIndex: HTMLOrSVGElement["tabIndex"]
}
Expand Down
2 changes: 2 additions & 0 deletions bokehjs/src/lib/core/enums.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import {Enum} from "./kinds"

export {Auto} from "./kinds"

export const Align = Enum("start", "center", "end")
export type Align = typeof Align["__type__"]

Expand Down
4 changes: 3 additions & 1 deletion bokehjs/src/lib/core/kinds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -654,9 +654,11 @@ export const Positive = <BaseType extends number>(base_type: Kind<BaseType>) =>
export const Percent = new Kinds.Percent()
export const Alpha = Percent
export const Color = new Kinds.Color()
export const Auto = Enum("auto")
export const CSSLength = new Kinds.CSSLength()

export const Auto = Enum("auto")
export type Auto = typeof Auto["__type__"]

export const FontSize = Str
export const Font = Str
export const Angle = Float
Expand Down
17 changes: 17 additions & 0 deletions bokehjs/src/lib/core/properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {Signal0} from "./signaling"
import {logger} from "./logging"
import type {HasProps} from "./has_props"
import * as enums from "./enums"
import type {Dimension} from "./enums"
import type {Arrayable, IntArray, FloatArray, TypedArray, uint32, Dict} from "./types"
import {RGBAArray, ColorArray} from "./types"
import type * as types from "./types"
Expand Down Expand Up @@ -609,6 +610,22 @@ export class YCoordinateSeqSeqSeqSpec extends CoordinateSeqSeqSeqSpec {
readonly dimension = "y"
}

export class XOrYCoordinateSpec extends CoordinateSpec {
declare readonly obj: HasProps & {dimension: Dimension}

get dimension(): "x" | "y" {
return this.obj.dimension == "width" ? "x" : "y"
}
}

export class XOrYCrossCoordinateSpec extends XOrYCoordinateSpec {
declare readonly obj: HasProps & {dimension: Dimension}

override get dimension(): "x" | "y" {
return super.dimension == "x" ? "y" : "x"
}
}

export class AngleSpec extends NumberUnitsSpec<enums.AngleUnits> {
get default_units(): enums.AngleUnits {
return "rad"
Expand Down
18 changes: 18 additions & 0 deletions bokehjs/src/lib/core/util/bbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,24 @@ export function empty(): Rect {
}
}

export function x_only(x0: number, x1: number): Rect {
return {
x0,
x1,
y0: Infinity,
y1: -Infinity,
}
}

export function y_only(y0: number, y1: number): Rect {
return {
x0: Infinity,
x1: -Infinity,
y0,
y1,
}
}

export function positive_x(): Rect {
return {
x0: Number.MIN_VALUE,
Expand Down
4 changes: 4 additions & 0 deletions bokehjs/src/lib/core/view_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ abstract class AbstractViewQuery {
find_all_by_id(id: string): View[] {
return [...this.find_by_id(id)]
}

collect<T extends HasProps>(models: T[]): ViewOf<T>[] {
return models.map((model) => this.get_one(model))
}
}

export class ViewQuery extends AbstractViewQuery {
Expand Down