8000 Add support for CSS-based theming on the canvas by mattpap · Pull Request #13828 · bokeh/bokeh · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
366d1c5
Separate rendering from painting
mattpap Mar 29, 2024
4b74d9a
Make RendererView inherit from DOMComponentView
mattpap Mar 29, 2024
717a6c3
Don't use append(), remove() and replaceWith()
mattpap Apr 11, 2024
18f3e08
Move RendererGroup to a separate module
mattpap Apr 13, 2024
8edd1a1
Introduce StyledElement base class
mattpap Apr 14, 2024
346ad21
Attach renderers' elements to the canvas
mattpap Apr 16, 2024
2783f4d
Use CSS variables in canvas visuals
mattpap Apr 16, 2024
ef6b1f0
Add styling/visuals/css_variables.py
mattpap Apr 16, 2024
ecb85a7
Restore functionality of HTML label annotation
mattpap Apr 17, 2024
084a5ec
Update bokehjs' unit tests
mattpap Apr 17, 2024
6f4193d
Use stylesheet based styling in HTML labels
mattpap Apr 18, 2024
0273ed1
Update cross tests baselines
mattpap Apr 18, 2024
85edc1b
Correctly render the Toolbar in ToolbarPanel
mattpap Apr 21, 2024
fc318fc
Add CSS support to Text and Hatch visuals
mattpap Apr 21, 2024
cad5ad0
Style text in css_variables example
mattpap Apr 21, 2024
9827484
Migrate styling/visuals/css_variables.py to bokehjs
mattpap Apr 21, 2024
75eee1b
Allow to specific rendering target for canvas renderers
mattpap Apr 22, 2024
80aac1f
Reposition menu after toolbar resize if open
mattpap Apr 22, 2024
3dabe74
Correctly update canvas renderers' elements
mattpap Apr 22, 2024
f2d9a79
Allow to recover from invalid gesture state
mattpap Apr 22, 2024
be4ad84
Safeguard against disconnected elements
mattpap Apr 22, 2024
67cba1f
Use render_to() to render toolbar's tool buttons
mattpap Apr 22, 2024
d4c9030
Add integration tests for HTMLLabel
mattpap Apr 22, 2024
431040a
Add docstrings to models/ui/ui_element.py
mattpap Apr 23, 2024
15d4f4a
Remove deprecated APIs from core/dom.ts
mattpap Apr 23, 2024
22bcd1d
Compute CSS prefix of visual properties once
mattpap Apr 23, 2024
0c4c892
Robustify render() and after_render() logic
mattpap Apr 26, 2024
8a28c2a
Call r_after_render() after updating children
mattpap May 1, 2024
980a149
Use computed_renderer_views to avoid race conditions
mattpap May 1, 2024
c9cd2dc
Display duration in devtools' progress bar
mattpap May 1, 2024
5b20522
Robustify is_paused and hold_render logic
mattpap May 1, 2024
2d8bfb0
Recompute toolbar buttons after layout
mattpap May 1, 2024
3bbb63e
Update integration baseline images
mattpap May 1, 2024
77a1459
Robustify ready state in TileRenderer
mattpap May 2, 2024
500f55f
Mark _was_build in after_render()
mattpap May 2, 2024
f22de60
Correctly render contents in Dialog
mattpap May 2, 2024
1e4544a
Add a regression test for issue #13787
mattpap May 2, 2024
11804cd
Update *.blf baseline files
mattpap May 2, 2024
cf8dc3e
Update bokeh's examples
mattpap May 2, 2024
55d9deb
Add release notes
mattpap May 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Separate rendering from painting
* rendering is for constructing DOM nodes
* painting is for drawing to the canvas
  • Loading branch information
mattpap committed May 1, 2024
commit 366d1c507bcd8715dc532d0596effa61669e9975
6 changes: 3 additions & 3 deletions bokehjs/src/lib/core/visuals/hatch.ts
6284
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class Hatch extends VisualProperties {
void image.then((image) => {
if (this._update_iteration == _update_iteration) {
finalize(image)
this.obj.request_render()
this.obj.request_paint()
}
})
} else {
Expand Down Expand Up @@ -156,7 +156,7 @@ export class HatchScalar extends VisualUniforms {
void image.then((image) => {
if (this._update_iteration == _update_iteration) {
finalize(image)
this.obj.request_render()
this.obj.request_paint()
}
})
} else {
Expand Down Expand Up @@ -269,7 +269,7 @@ export class HatchVector extends VisualUniforms {
void image.then((image) => {
if (this._update_iteration == _update_iteration) {
finalize(image)
this.obj.request_render()
this.obj.request_paint()
}
})
} else {
Expand Down
2 changes: 1 addition & 1 deletion bokehjs/src/lib/core/visuals/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function load_font(font: string, obj: Renderable): void {

const {fonts} = document
if (!fonts.check(font)) {
void fonts.load(font).then(() => obj.request_render())
void fonts.load(font).then(() => obj.request_paint())
}
}

Expand Down
2 changes: 1 addition & 1 deletion bokehjs/src/lib/core/visuals/visual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export type NameOf<Key extends string> = Key extends `text_${infer Name}` ? Name
export type ValuesOf<T> = {[Key in keyof T & string as NameOf<Key>]: T[Key] extends p.Property<infer V> ? V : never}

export interface Renderable {
request_render(): void
request_paint(): void
readonly canvas: {
create_layer(): CanvasLayer
}
Expand Down
6 changes: 3 additions & 3 deletions bokehjs/src/lib/models/annotations/arrow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export class ArrowView extends DataAnnotationView {
}
}

paint(ctx: Context2d): void {
_paint_data(ctx: Context2d): void {
const {start, end} = this

const {_sx_start, _sy_start, _sx_end, _sy_end, _angles} = this
Expand All @@ -144,15 +144,15 @@ export class ArrowView extends DataAnnotationView {
ctx.save()
ctx.translate(_sx_end[i], _sy_end[i])
ctx.rotate(_angles[i])
end.render(ctx, i)
end.paint(ctx, i)
ctx.restore()
}

if (start != null) {
ctx.save()
ctx.translate(_sx_start[i], _sy_start[i])
ctx.rotate(_angles[i] + Math.PI)
start.render(ctx, i)
start.paint(ctx, i)
ctx.restore()
}

Expand Down
8 changes: 4 additions & 4 deletions bokehjs/src/lib/models/annotations/arrow_head.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class OpenHeadView extends ArrowHeadView {
ctx.lineTo(0.5*size_i, size_i)
}

render(ctx: Context2d, i: number): void {
paint(ctx: Context2d, i: number): void {
const size_i = this.size.get(i)
ctx.beginPath()
ctx.moveTo(0.5*size_i, size_i)
Expand Down Expand Up @@ -102,7 +102,7 @@ export class NormalHeadView extends ArrowHeadView {
ctx.lineTo(0.5*size_i, size_i)
}

render(ctx: Context2d, i: number): void {
paint(ctx: Context2d, i: number): void {
const size_i = this.size.get(i)
ctx.beginPath()
ctx.moveTo(0.5*size_i, size_i)
Expand Down Expand Up @@ -161,7 +161,7 @@ export class VeeHeadView extends ArrowHeadView {
ctx.lineTo(0.5*size_i, size_i)
}

render(ctx: Context2d, i: number): void {
paint(ctx: Context2d, i: number): void {
const size_i = this.size.get(i)
ctx.beginPath()
ctx.moveTo(0.5*size_i, size_i)
Expand Down Expand Up @@ -210,7 +210,7 @@ export class TeeHeadView extends ArrowHeadView {
declare model: TeeHead
declare visuals: TeeHead.Visuals

render(ctx: Context2d, i: number): void {
paint(ctx: Context2d, i: number): void {
const size_i = this.size.get(i)
ctx.beginPath()
ctx.moveTo(0.5*size_i, 0)
Expand Down
2 changes: 1 addition & 1 deletion bokehjs/src/lib/models/annotations/band.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class BandView extends UpperLowerView {
declare model: Band
declare visuals: Band.Visuals

paint(ctx: Context2d): void {
_paint_data(ctx: Context2d): void {
// Draw the band body
ctx.beginPath()
ctx.moveTo(this._lower_sx[0], this._lower_sy[0])
Expand Down
13 changes: 5 additions & 8 deletions bokehjs/src/lib/models/annotations/base_color_bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,6 @@ export abstract class BaseColorBarView extends AnnotationView {
request_paint() {
self.parent.request_paint(self)
},
request_render() {
self.request_paint()
},
notify_finished_after_paint() {
self.parent.notify_finished_after_paint()
},
Expand Down Expand Up @@ -173,8 +170,8 @@ export abstract class BaseColorBarView extends AnnotationView {
this._apply_axis_properties()
// TODO?: this.plot_view.invalidate_layout()
})
this.connect(this._ticker.change, () => this.request_render())
this.connect(this._formatter.change, () => this.request_render())
this.connect(this._ticker.change, () => this.request_paint())
this.connect(this._formatter.change, () => this.request_paint())
}

protected _update_frame(): void {
Expand Down Expand Up @@ -483,13 +480,13 @@ export abstract class BaseColorBarView extends AnnotationView {

protected abstract _paint_colors(ctx: Context2d, bbox: BBox): void

protected _render(): void {
protected _paint(): void {
const {ctx} = this.layer
ctx.save()
this._paint_bbox(ctx, this._inner_layout.bbox)
this._paint_colors(ctx, this._inner_layout.center_panel.bbox)
this._title_view.render()
this._axis_view.render()
this._title_view.paint()
this._axis_view.paint()
ctx.restore()
}

Expand Down
4 changes: 2 additions & 2 deletions bokehjs/src/lib/models/annotations/box_annotation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class BoxAnnotationView extends AnnotationView implements Pannable, Pinch

override connect_signals(): void {
super.connect_signals()
this.connect(this.model.change, () => this.request_render())
this.connect(this.model.change, () => this.request_paint())
}

readonly [auto_ranged] = true
Expand Down Expand Up @@ -133,7 +133,7 @@ export class BoxAnnotationView extends AnnotationView implements Pannable, Pinch
})
}

protected _render(): void {
protected _paint(): void {
if (!this.bbox.is_valid) {
return
}
Expand Down
2 changes: 1 addition & 1 deletion bokehjs/src/lib/models/annotations/color_bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ export class ColorBarView extends BaseColorBarView {
}

this._set_canvas_image()
this.plot_view.request_layout() // this.request_render()
this.plot_view.request_layout() // this.request_paint()
}

override _paint_colors(ctx: Context2d, bbox: BBox): void {
Expand Down
8 changes: 4 additions & 4 deletions bokehjs/src/lib/models/annotations/data_annotation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export abstract class DataAnnotationView extends AnnotationView {
}

protected _rerender(): void {
this.request_render()
this.request_paint()
}

set_data(source: ColumnarDataSource): void {
Expand Down Expand Up @@ -57,17 +57,17 @@ export abstract class DataAnnotationView extends AnnotationView {

abstract map_data(): void

abstract paint(ctx: Context2d): void
abstract _paint_data(ctx: Context2d): void

private _initial_set_data = false

protected _render(): void {
protected _paint(): void {
if (!this._initial_set_data) {
this.set_data(this.model.source)
this._initial_set_data = true
}
this.map_data()
this.paint(this.layer.ctx)
this._paint_data(this.layer.ctx)
}
}

Expand Down
4 changes: 2 additions & 2 deletions bokehjs/src/lib/models/annotations/html/label.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class HTMLLabelView extends TextAnnotationView {
return {width, height}
}

protected _render(): void {
protected _paint(): void {
const {angle, angle_units} = this.model
const rotation = compute_angle(angle, angle_units)

Expand Down Expand Up @@ -71,7 +71,7 @@ export class HTMLLabelView extends TextAnnotationView {
sx += this.model.x_offset
sy -= this.model.y_offset

this._paint(this.layer.ctx, this.model.text, sx, sy, rotation)
this._paint_text(this.layer.ctx, this.model.text, sx, sy, rotation)
}
}

Expand Down
8 changes: 4 additions & 4 deletions bokehjs/src/lib/models/annotations/html/label_set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class HTMLLabelSetView extends DataAnnotationView {
}

protected override _rerender(): void {
this.render()
this.paint()
}

map_data(): void {
Expand Down Expand Up @@ -74,7 +74,7 @@ export class HTMLLabelSetView extends DataAnnotationView {
})()
}

paint(): void {
_paint_data(): void {
const {ctx} = this.layer

for (let i = 0, end = this.text.length; i < end; i++) {
Expand All @@ -89,11 +89,11 @@ export class HTMLLabelSetView extends DataAnnotationView {
continue
}

this._paint(ctx, i, text_i, sx_i, sy_i, angle_i)
this._paint_text(ctx, i, text_i, sx_i, sy_i, angle_i)
}
}

protected _paint(ctx: Context2d, i: number, text: string, sx: number, sy: number, angle: number): void {
protected _paint_text(ctx: Context2d, i: number, text: string, sx: number, sy: number, angle: number): void {
assert(i in this.els)
const el = this.els[i]

Expand Down
8 changes: 4 additions & 4 deletions bokehjs/src/lib/models/annotations/html/text_annotation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ export abstract class TextAnnotationView extends AnnotationView {

override connect_signals(): void {
super.connect_signals()
this.connect(this.model.change, () => this.render())
this.connect(this.model.change, () => this.paint())
}

override render(): void {
override paint(): void {
if (!this.model.visible) {
undisplay(this.el)
}

super.render()
super.paint()
}

get padding(): LRTB<number> {
Expand All @@ -55,7 +55,7 @@ export abstract class TextAnnotationView extends AnnotationView {
return resolve.border_radius(this.model.border_radius)
}

protected _paint(ctx: Context2d, text: string, sx: number, sy: number, angle: number): void {
protected _paint_text(ctx: Context2d, text: string, sx: number, sy: number, angle: number): void {
const {el} = this
undisplay(el)

Expand Down
4 changes: 2 additions & 2 deletions bokehjs/src/lib/models/annotations/html/title.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class HTMLTitleView extends TextAnnotationView {
return [sx, sy]
}

protected _render(): void {
protected _paint(): void {
const {text} = this.model
if (text.length == 0) {
return
Expand All @@ -79,7 +79,7 @@ export class HTMLTitleView extends TextAnnotationView {
const [sx, sy] = this._get_location()
const angle = this.panel.get_label_angle_heuristic("parallel")

this._paint(this.layer.ctx, text, sx, sy, angle)
this._paint_text(this.layer.ctx, text, sx, sy, angle)
}

// XXX: this needs to use CSS computed styles
Expand Down
6 changes: 3 additions & 3 deletions bokehjs/src/lib/models/annotations/label_set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class LabelSetView extends DataAnnotationView {
})()
}

paint(): void {
_paint_data(): void {
const {ctx} = this.layer

for (let i = 0, end = this.text.length; i < end; i++) {
Expand All @@ -63,11 +63,11 @@ export class LabelSetView extends DataAnnotationView {
continue
}

this._paint(ctx, i, `${text_i}`, sx_i, sy_i, angle_i)
this._paint_text(ctx, i, `${text_i}`, sx_i, sy_i, angle_i)
}
}

protected _paint(ctx: Context2d, i: number, text: string, sx: number, sy: number, angle: number): void {
protected _paint_text(ctx: Context2d, i: number, text: string, sx: number, sy: number, angle: number): void {
const graphics = new TextBox({text})
graphics.angle = angle
graphics.position = {sx, sy}
Expand Down
10 changes: 5 additions & 5 deletions bokehjs/src/lib/models/annotations/legend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ export class LegendView extends AnnotationView {
override connect_signals(): void {
super.connect_signals()

const rerender = () => this.request_render()
this.connect(this.model.change, rerender)
this.connect(this.model.item_change, rerender)
const repaint = () => this.request_paint()
this.connect(this.model.change, repaint)
this.connect(this.model.item_change, repaint)
}

override bbox: BBox = new BBox()
Expand Down Expand Up @@ -320,10 +320,10 @@ export class LegendView extends AnnotationView {
return false
}

protected _render(): void {
protected _paint(): void {
// It would be better to update geometry (the internal layout) only when
// necessary, but conditions for that are not clear, so for now update
// at every render.
// at every paint.
this.update_geometry()
this.compute_geometry()

Expand Down
4 changes: 2 additions & 2 deletions bokehjs/src/lib/models/annotations/poly_annotation.ts
4417
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export class PolyAnnotationView extends AnnotationView implements Pannable, Move

override connect_signals(): void {
super.connect_signals()
this.connect(this.model.change, () => this.request_render())
this.connect(this.model.change, () => this.request_paint())
}

readonly [auto_ranged] = true
Expand Down Expand Up @@ -154,7 +154,7 @@ export class PolyAnnotationView extends AnnotationView implements Pannable, Move
}
}

protected _render(): void {
protected _paint(): void {
const {xs, ys} = this.model
assert(xs.length == ys.length)

Expand Down
Loading
0