Skip to content

Commit

Permalink
Simple spatial index for wedge-like glyphs (bokeh#14212)
Browse files Browse the repository at this point in the history
  • Loading branch information
bryevdv authored Jan 3, 2025
1 parent 1c9a054 commit f95be9e
Show file tree
Hide file tree
Showing 22 changed files with 423 additions and 255 deletions.
11 changes: 11 additions & 0 deletions bokehjs/src/lib/models/glyphs/annular_wedge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type * as visuals from "core/visuals"
import {Direction} from "core/enums"
import * as p from "core/properties"
import {angle_between} from "core/util/math"
import type {SpatialIndex} from "core/util/spatial"
import type {Context2d} from "core/util/canvas"
import {Selection} from "../selections/selection"
import {max} from "../../core/util/arrayable"
Expand All @@ -28,6 +29,16 @@ export class AnnularWedgeView extends XYGlyphView {
return AnnularWedgeGL
}

protected override _index_data(index: SpatialIndex): void {
const {x, y, outer_radius, data_size} = this
for (let i = 0; i < data_size; i++) {
const x_i = x[i]
const y_i = y[i]
const r_i = outer_radius.get(i)
index.add_rect(x_i - r_i, y_i - r_i, x_i + r_i, y_i + r_i)
}
}

protected override _map_data(): void {
this._define_or_inherit_attr<AnnularWedge.Data>("sinner_radius", () => {
if (this.model.properties.inner_radius.units == "data") {
Expand Down
11 changes: 11 additions & 0 deletions bokehjs/src/lib/models/glyphs/annulus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {PointGeometry} from "core/geometry"
import {LineVector, FillVector, HatchVector} from "core/property_mixins"
import type * as visuals from "core/visuals"
import * as p from "core/properties"
import type {SpatialIndex} from "core/util/spatial"
import type {Context2d} from "core/util/canvas"
import {Selection} from "../selections/selection"
import type {AnnulusGL} from "./webgl/annulus"
Expand All @@ -24,6 +25,16 @@ export class AnnulusView extends XYGlyphView {
return AnnulusGL
}

protected override _index_data(index: SpatialIndex): void {
const {x, y, outer_radius, data_size} = this
for (let i = 0; i < data_size; i++) {
const x_i = x[i]
const y_i = y[i]
const r_i = outer_radius.get(i)
index.add_rect(x_i - r_i, y_i - r_i, x_i + r_i, y_i + r_i)
}
}

protected override _map_data(): void {
this._define_or_inherit_attr<Annulus.Data>("sinner_radius", () => {
if (this.model.properties.inner_radius.units == "data") {
Expand Down
11 changes: 11 additions & 0 deletions bokehjs/src/lib/models/glyphs/wedge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {to_screen} from "core/types"
import {Direction} from "core/enums"
import * as p from "core/properties"
import {angle_between} from "core/util/math"
import type {SpatialIndex} from "core/util/spatial"
import type {Context2d} from "core/util/canvas"
import {Selection} from "../selections/selection"
import {max} from "../../core/util/arrayable"
Expand All @@ -28,6 +29,16 @@ export class WedgeView extends XYGlyphView {
return WedgeGL
}

protected override _index_data(index: SpatialIndex): void {
const {x, y, radius, data_size} = this
for (let i = 0; i < data_size; i++) {
const x_i = x[i]
const y_i = y[i]
const r_i = radius.get(i)
index.add_rect(x_i - r_i, y_i - r_i, x_i + r_i, y_i + r_i)
}
}

protected override _map_data(): void {
this._define_or_inherit_attr<Wedge.Data>("sradius", () => {
if (this.model.properties.radius.units == "data") {
Expand Down
4 changes: 1 addition & 3 deletions bokehjs/src/lib/models/glyphs/xy_glyph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ export abstract class XYGlyphView extends GlyphView {
const {x, y, data_size} = this

for (let i = 0; i < data_size; i++) {
const x_i = x[i]
const y_i = y[i]
index.add_point(x_i, y_i)
index.add_point(x[i], y[i])
}
}

Expand Down
20 changes: 10 additions & 10 deletions bokehjs/test/baselines/linux/Examples__should_support_Burtin.blf
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
Figure bbox=[0, 0, 800, 800]
Canvas bbox=[0, 0, 800, 800]
CartesianFrame bbox=[0, 0, 770, 800]
GlyphRenderer bbox=[385, 400, 0, 0]
AnnularWedge bbox=[385, 400, 0, 0]
GlyphRenderer bbox=[385, 400, 0, 0]
AnnularWedge bbox=[385, 400, 0, 0]
GlyphRenderer bbox=[385, 400, 0, 0]
AnnularWedge bbox=[385, 400, 0, 0]
GlyphRenderer bbox=[385, 400, 0, 0]
AnnularWedge bbox=[385, 400, 0, 0]
GlyphRenderer bbox=[119, 124, 532, 552]
AnnularWedge bbox=[119, 124, 532, 552]
GlyphRenderer bbox=[119, 124, 532, 552]
AnnularWedge bbox=[119, 124, 532, 552]
GlyphRenderer bbox=[165, 172, 440, 456]
AnnularWedge bbox=[165, 172, 440, 456]
GlyphRenderer bbox=[119, 124, 532, 552]
AnnularWedge bbox=[119, 124, 532, 552]
GlyphRenderer bbox=[119, 124, 532, 552]
Circle bbox=[119, 124, 532, 552]
GlyphRenderer bbox=[385, 124, 0, 168]
Text bbox=[385, 124, 0, 168]
GlyphRenderer bbox=[385, 400, 0, 0]
AnnularWedge bbox=[385, 400, 0, 0]
GlyphRenderer bbox=[110, 114, 550, 572]
AnnularWedge bbox=[110, 114, 550, 572]
GlyphRenderer bbox=[120, 142, 530, 529]
Text bbox=[120, 142, 530, 529]
GlyphRenderer bbox=[344, 748, 9, 28]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Figure bbox=[0, 0, 510, 541]
Canvas bbox=[0, 0, 510, 541]
CartesianFrame bbox=[5, 36, 500, 500]
GlyphRenderer bbox=[255, 286, 0, 0]
AnnularWedge bbox=[255, 286, 0, 0]
GlyphRenderer bbox=[47, 78, 416, 416]
AnnularWedge bbox=[47, 78, 416, 416]
GlyphRenderer bbox=[213, 244, 84, 84]
Circle bbox=[213, 244, 84, 84]
GlyphRenderer bbox=[255, 286, 0, 0]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@ Row bbox=[0, 0, 900, 300]
Figure bbox=[0, 0, 300, 300]
Canvas bbox=[0, 0, 300, 300]
CartesianFrame bbox=[29, 27, 266, 251]
GlyphRenderer bbox=[73, 90, 89, 125]
AnnularWedge bbox=[73, 90, 89, 125]
GlyphRenderer bbox=[162, 90, 89, 125]
AnnularWedge bbox=[162, 90, 89, 125]
GlyphRenderer bbox=[29, 27, 177, 251]
AnnularWedge bbox=[29, 27, 177, 251]
GlyphRenderer bbox=[118, 27, 177, 251]
AnnularWedge bbox=[118, 27, 177, 251]
LinearAxis bbox=[29, 278, 266, 22]
LinearAxis bbox=[0, 27, 29, 251]
Title bbox=[29, 0, 266, 27]
Figure bbox=[300, 0, 300, 300]
Canvas bbox=[0, 0, 300, 300]
CartesianFrame bbox=[29, 27, 266, 251]
GlyphRenderer bbox=[73, 90, 89, 125]
AnnularWedge bbox=[73, 90, 89, 125]
GlyphRenderer bbox=[162, 90, 89, 125]
AnnularWedge bbox=[162, 90, 89, 125]
GlyphRenderer bbox=[29, 27, 177, 251]
AnnularWedge bbox=[29, 27, 177, 251]
GlyphRenderer bbox=[118, 27, 177, 251]
AnnularWedge bbox=[118, 27, 177, 251]
LinearAxis bbox=[29, 278, 266, 22]
LinearAxis bbox=[0, 27, 29, 251]
Title bbox=[29, 0, 266, 27]
Figure bbox=[600, 0, 300, 300]
Canvas bbox=[0, 0, 300, 300]
CartesianFrame bbox=[29, 27, 266, 251]
GlyphRenderer bbox=[73, 90, 89, 125]
AnnularWedge bbox=[73, 90, 89, 125]
GlyphRenderer bbox=[162, 90, 89, 125]
AnnularWedge bbox=[162, 90, 89, 125]
GlyphRenderer bbox=[29, 27, 177, 251]
AnnularWedge bbox=[29, 27, 177, 251]
GlyphRenderer bbox=[118, 27, 177, 251]
AnnularWedge bbox=[118, 27, 177, 251]
LinearAxis bbox=[29, 278, 266, 22]
LinearAxis bbox=[0, 27, 29, 251]
Title bbox=[29, 0, 266, 27]
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@ Row bbox=[0, 0, 900, 300]
Figure bbox=[0, 0, 300, 300]
Canvas bbox=[0, 0, 300, 300]
CartesianFrame bbox=[29, 27, 266, 251]
GlyphRenderer bbox=[73, 90, 89, 125]
AnnularWedge bbox=[73, 90, 89, 125]
GlyphRenderer bbox=[162, 90, 89, 125]
AnnularWedge bbox=[162, 90, 89, 125]
GlyphRenderer bbox=[29, 27, 177, 251]
AnnularWedge bbox=[29, 27, 177, 251]
GlyphRenderer bbox=[118, 27, 177, 251]
AnnularWedge bbox=[118, 27, 177, 251]
LinearAxis bbox=[29, 278, 266, 22]
LinearAxis bbox=[0, 27, 29, 251]
Title bbox=[29, 0, 266, 27]
Figure bbox=[300, 0, 300, 300]
Canvas bbox=[0, 0, 300, 300]
CartesianFrame bbox=[29, 27, 266, 251]
GlyphRenderer bbox=[73, 90, 89, 125]
AnnularWedge bbox=[73, 90, 89, 125]
GlyphRenderer bbox=[162, 90, 89, 125]
AnnularWedge bbox=[162, 90, 89, 125]
GlyphRenderer bbox=[29, 27, 177, 251]
AnnularWedge bbox=[29, 27, 177, 251]
GlyphRenderer bbox=[118, 27, 177, 251]
AnnularWedge bbox=[118, 27, 177, 251]
LinearAxis bbox=[29, 278, 266, 22]
LinearAxis bbox=[0, 27, 29, 251]
Title bbox=[29, 0, 266, 27]
Figure bbox=[600, 0, 300, 300]
Canvas bbox=[0, 0, 300, 300]
CartesianFrame bbox=[29, 27, 266, 251]
GlyphRenderer bbox=[73, 90, 89, 125]
AnnularWedge bbox=[73, 90, 89, 125]
GlyphRenderer bbox=[162, 90, 89, 125]
AnnularWedge bbox=[162, 90, 89, 125]
GlyphRenderer bbox=[29, 27, 177, 251]
AnnularWedge bbox=[29, 27, 177, 251]
GlyphRenderer bbox=[118, 27, 177, 251]
AnnularWedge bbox=[118, 27, 177, 251]
LinearAxis bbox=[29, 278, 266, 22]
LinearAxis bbox=[0, 27, 29, 251]
Title bbox=[29, 0, 266, 27]
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@ Row bbox=[0, 0, 900, 300]
Figure bbox=[0, 0, 300, 300]
Canvas bbox=[0, 0, 300, 300]
CartesianFrame bbox=[29, 27, 266, 251]
GlyphRenderer bbox=[73, 90, 89, 125]
AnnularWedge bbox=[73, 90, 89, 125]
GlyphRenderer bbox=[162, 90, 89, 125]
AnnularWedge bbox=[162, 90, 89, 125]
GlyphRenderer bbox=[29, 27, 177, 251]
AnnularWedge bbox=[29, 27, 177, 251]
GlyphRenderer bbox=[118, 27, 177, 251]
AnnularWedge bbox=[118, 27, 177, 251]
LinearAxis bbox=[29, 278, 266, 22]
LinearAxis bbox=[0, 27, 29, 251]
Title bbox=[29, 0, 266, 27]
Figure bbox=[300, 0, 300, 300]
Canvas bbox=[0, 0, 300, 300]
CartesianFrame bbox=[29, 27, 266, 251]
GlyphRenderer bbox=[73, 90, 89, 125]
AnnularWedge bbox=[73, 90, 89, 125]
GlyphRenderer bbox=[162, 90, 89, 125]
AnnularWedge bbox=[162, 90, 89, 125]
GlyphRenderer bbox=[29, 27, 177, 251]
AnnularWedge bbox=[29, 27, 177, 251]
GlyphRenderer bbox=[118, 27, 177, 251]
AnnularWedge bbox=[118, 27, 177, 251]
LinearAxis bbox=[29, 278, 266, 22]
LinearAxis bbox=[0, 27, 29, 251]
Title bbox=[29, 0, 266, 27]
Figure bbox=[600, 0, 300, 300]
Canvas bbox=[0, 0, 300, 300]
CartesianFrame bbox=[29, 27, 266, 251]
GlyphRenderer bbox=[73, 90, 89, 125]
AnnularWedge bbox=[73, 90, 89, 125]
GlyphRenderer bbox=[162, 90, 89, 125]
AnnularWedge bbox=[162, 90, 89, 125]
GlyphRenderer bbox=[29, 27, 177, 251]
AnnularWedge bbox=[29, 27, 177, 251]
GlyphRenderer bbox=[118, 27, 177, 251]
AnnularWedge bbox=[118, 27, 177, 251]
LinearAxis bbox=[29, 278, 266, 22]
LinearAxis bbox=[0, 27, 29, 251]
Title bbox=[29, 0, 266, 27]
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@ Row bbox=[0, 0, 900, 300]
Figure bbox=[0, 0, 300, 300]
Canvas bbox=[0, 0, 300, 300]
CartesianFrame bbox=[29, 27, 266, 251]
GlyphRenderer bbox=[73, 90, 89, 125]
AnnularWedge bbox=[73, 90, 89, 125]
GlyphRenderer bbox=[162, 90, 89, 125]
AnnularWedge bbox=[162, 90, 89, 125]
GlyphRenderer bbox=[29, 27, 177, 251]
AnnularWedge bbox=[29, 27, 177, 251]
GlyphRenderer bbox=[118, 27, 177, 251]
AnnularWedge bbox=[118, 27, 177, 251]
LinearAxis bbox=[29, 278, 266, 22]
LinearAxis bbox=[0, 27, 29, 251]
Title bbox=[29, 0, 266, 27]
Figure bbox=[300, 0, 300, 300]
Canvas bbox=[0, 0, 300, 300]
CartesianFrame bbox=[29, 27, 266, 251]
GlyphRenderer bbox=[73, 90, 89, 125]
AnnularWedge bbox=[73, 90, 89, 125]
GlyphRenderer bbox=[162, 90, 89, 125]
AnnularWedge bbox=[162, 90, 89, 125]
GlyphRenderer bbox=[29, 27, 177, 251]
AnnularWedge bbox=[29, 27, 177, 251]
GlyphRenderer bbox=[118, 27, 177, 251]
AnnularWedge bbox=[118, 27, 177, 251]
LinearAxis bbox=[29, 278, 266, 22]
LinearAxis bbox=[0, 27, 29, 251]
Title bbox=[29, 0, 266, 27]
Figure bbox=[600, 0, 300, 300]
Canvas bbox=[0, 0, 300, 300]
CartesianFrame bbox=[29, 27, 266, 251]
GlyphRenderer bbox=[73, 90, 89, 125]
AnnularWedge bbox=[73, 90, 89, 125]
GlyphRenderer bbox=[162, 90, 89, 125]
AnnularWedge bbox=[162, 90, 89, 125]
GlyphRenderer bbox=[29, 27, 177, 251]
AnnularWedge bbox=[29, 27, 177, 251]
GlyphRenderer bbox=[118, 27, 177, 251]
AnnularWedge bbox=[118, 27, 177, 251]
LinearAxis bbox=[29, 278, 266, 22]
LinearAxis bbox=[0, 27, 29, 251]
Title bbox=[29, 0, 266, 27]
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@ Row bbox=[0, 0, 900, 300]
Figure bbox=[0, 0, 300, 300]
Canvas bbox=[0, 0, 300, 300]
CartesianFrame bbox=[29, 27, 266, 251]
GlyphRenderer bbox=[73, 90, 89, 125]
AnnularWedge bbox=[73, 90, 89, 125]
GlyphRenderer bbox=[162, 90, 89, 125]
AnnularWedge bbox=[162, 90, 89, 125]
GlyphRenderer bbox=[29, 27, 177, 251]
AnnularWedge bbox=[29, 27, 177, 251]
GlyphRenderer bbox=[118, 27, 177, 251]
AnnularWedge bbox=[118, 27, 177, 251]
LinearAxis bbox=[29, 278, 266, 22]
LinearAxis bbox=[0, 27, 29, 251]
Title bbox=[29, 0, 266, 27]
Figure bbox=[300, 0, 300, 300]
Canvas bbox=[0, 0, 300, 300]
CartesianFrame bbox=[29, 27, 266, 251]
GlyphRenderer bbox=[73, 90, 89, 125]
AnnularWedge bbox=[73, 90, 89, 125]
GlyphRenderer bbox=[162, 90, 89, 125]
AnnularWedge bbox=[162, 90, 89, 125]
GlyphRenderer bbox=[29, 27, 177, 251]
AnnularWedge bbox=[29, 27, 177, 251]
GlyphRenderer bbox=[118, 27, 177, 251]
AnnularWedge bbox=[118, 27, 177, 251]
LinearAxis bbox=[29, 278, 266, 22]
LinearAxis bbox=[0, 27, 29, 251]
Title bbox=[29, 0, 266, 27]
Figure bbox=[600, 0, 300, 300]
Canvas bbox=[0, 0, 300, 300]
CartesianFrame bbox=[29, 27, 266, 251]
GlyphRenderer bbox=[73, 90, 89, 125]
AnnularWedge bbox=[73, 90, 89, 125]
GlyphRenderer bbox=[162, 90, 89, 125]
AnnularWedge bbox=[162, 90, 89, 125]
GlyphRenderer bbox=[29, 27, 177, 251]
AnnularWedge bbox=[29, 27, 177, 251]
GlyphRenderer bbox=[118, 27, 177, 251]
AnnularWedge bbox=[118, 27, 177, 251]
LinearAxis bbox=[29, 278, 266, 22]
LinearAxis bbox=[0, 27, 29, 251]
Title bbox=[29, 0, 266, 27]
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@ Row bbox=[0, 0, 900, 300]
Figure bbox=[0, 0, 300, 300]
Canvas bbox=[0, 0, 300, 300]
CartesianFrame bbox=[29, 27, 266, 251]
GlyphRenderer bbox=[73, 90, 89, 125]
AnnularWedge bbox=[73, 90, 89, 125]
GlyphRenderer bbox=[162, 90, 89, 125]
AnnularWedge bbox=[162, 90, 89, 125]
GlyphRenderer bbox=[29, 27, 177, 251]
AnnularWedge bbox=[29, 27, 177, 251]
GlyphRenderer bbox=[118, 27, 177, 251]
AnnularWedge bbox=[118, 27, 177, 251]
LinearAxis bbox=[29, 278, 266, 22]
LinearAxis bbox=[0, 27, 29, 251]
Title bbox=[29, 0, 266, 27]
Figure bbox=[300, 0, 300, 300]
Canvas bbox=[0, 0, 300, 300]
CartesianFrame bbox=[29, 27, 266, 251]
GlyphRenderer bbox=[73, 90, 89, 125]
AnnularWedge bbox=[73, 90, 89, 125]
GlyphRenderer bbox=[162, 90, 89, 125]
AnnularWedge bbox=[162, 90, 89, 125]
GlyphRenderer bbox=[29, 27, 177, 251]
AnnularWedge bbox=[29, 27, 177, 251]
GlyphRenderer bbox=[118, 27, 177, 251]
AnnularWedge bbox=[118, 27, 177, 251]
LinearAxis bbox=[29, 278, 266, 22]
LinearAxis bbox=[0, 27, 29, 251]
Title bbox=[29, 0, 266, 27]
Figure bbox=[600, 0, 300, 300]
Canvas bbox=[0, 0, 300, 300]
CartesianFrame bbox=[29, 27, 266, 251]
GlyphRenderer bbox=[73, 90, 89, 125]
AnnularWedge bbox=[73, 90, 89, 125]
GlyphRenderer bbox=[162, 90, 89, 125]
AnnularWedge bbox=[162, 90, 89, 125]
GlyphRenderer bbox=[29, 27, 177, 251]
AnnularWedge bbox=[29, 27, 177, 251]
GlyphRenderer bbox=[118, 27, 177, 251]
AnnularWedge bbox=[118, 27, 177, 251]
LinearAxis bbox=[29, 278, 266, 22]
LinearAxis bbox=[0, 27, 29, 251]
Title bbox=[29, 0, 266, 27]
Loading

0 comments on commit f95be9e

Please sign in to comment.