Skip to content

Commit

Permalink
Use pseudo type members to avoid casting (bokeh#14051)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattpap authored Sep 5, 2024
1 parent 78dcbf3 commit 5036057
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 3 additions & 1 deletion bokehjs/src/lib/models/axes/axis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ export abstract class AxisView extends GuideRendererView {
declare model: Axis
declare visuals: Axis.Visuals

declare readonly RangeType: Range

layout?: Layoutable

private _panel: SidePanel
Expand Down Expand Up @@ -555,7 +557,7 @@ export abstract class AxisView extends GuideRendererView {
}
}

get ranges(): [Range, Range] {
get ranges(): [typeof this["RangeType"], typeof this["RangeType"]] {
const i = this.dimension
const j = 1 - i
const {ranges} = this.coordinates
Expand Down
8 changes: 5 additions & 3 deletions bokehjs/src/lib/models/axes/categorical_axis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export class CategoricalAxisView extends AxisView {
declare model: CategoricalAxis
declare visuals: CategoricalAxis.Visuals

declare readonly RangeType: FactorRange

protected override _paint(): void {
const {tick_coords, extents} = this
const ctx = this.layer.ctx
Expand All @@ -33,7 +35,7 @@ export class CategoricalAxisView extends AxisView {
}

protected _draw_group_separators(ctx: Context2d, _extents: Extents, _tick_coords: TickCoords): void {
const [range] = this.ranges as [FactorRange, FactorRange]
const [range] = this.ranges
const [start, end] = this.computed_bounds

const {factors} = range
Expand Down Expand Up @@ -94,7 +96,7 @@ export class CategoricalAxisView extends AxisView {
}

protected _get_factor_info(): [GraphicsBoxes, Coords, Orient | number, visuals.Text][] {
const [range] = this.ranges as [FactorRange, FactorRange]
const [range] = this.ranges
const [start, end] = this.computed_bounds
const loc = this.loc

Expand Down Expand Up @@ -142,7 +144,7 @@ export class CategoricalAxisView extends AxisView {
override get tick_coords(): CategoricalTickCoords {
const i = this.dimension
const j = 1 - i
const [range] = this.ranges as [FactorRange, FactorRange]
const [range] = this.ranges
const [start, end] = this.computed_bounds

const ticks = this.model.ticker.get_ticks(start, end, range, this.loc)
Expand Down

0 comments on commit 5036057

Please sign in to comment.