-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Add support for CSS-based theming on the canvas #13828
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
Merged
Merged
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 4b74d9a
Make RendererView inherit from DOMComponentView
mattpap 717a6c3
Don't use append(), remove() and replaceWith()
mattpap 18f3e08
Move RendererGroup to a separate module
mattpap 8edd1a1
Introduce StyledElement base class
mattpap 346ad21
Attach renderers' elements to the canvas
mattpap 2783f4d
Use CSS variables in canvas visuals
mattpap ef6b1f0
Add styling/visuals/css_variables.py
mattpap ecb85a7
Restore functionality of HTML label annotation
mattpap 084a5ec
Update bokehjs' unit tests
mattpap 6f4193d
Use stylesheet based styling in HTML labels
mattpap 0273ed1
Update cross tests baselines
mattpap 85edc1b
Correctly render the Toolbar in ToolbarPanel
mattpap fc318fc
Add CSS support to Text and Hatch visuals
mattpap cad5ad0
Style text in css_variables example
mattpap 9827484
Migrate styling/visuals/css_variables.py to bokehjs
mattpap 75eee1b
Allow to specific rendering target for canvas renderers
mattpap 80aac1f
Reposition menu after toolbar resize if open
mattpap 3dabe74
Correctly update canvas renderers' elements
mattpap f2d9a79
Allow to recover from invalid gesture state
mattpap be4ad84
Safeguard against disconnected elements
mattpap 67cba1f
Use render_to() to render toolbar's tool buttons
mattpap d4c9030
Add integration tests for HTMLLabel
mattpap 431040a
Add docstrings to models/ui/ui_element.py
mattpap 15d4f4a
Remove deprecated APIs from core/dom.ts
mattpap 22bcd1d
Compute CSS prefix of visual properties once
mattpap 0c4c892
Robustify render() and after_render() logic
mattpap 8a28c2a
Call r_after_render() after updating children
mattpap 980a149
Use computed_renderer_views to avoid race conditions
mattpap c9cd2dc
Display duration in devtools' progress bar
mattpap 5b20522
Robustify is_paused and hold_render logic
mattpap 2d8bfb0
Recompute toolbar buttons after layout
mattpap 3bbb63e
Update integration baseline images
mattpap 77a1459
Robustify ready state in TileRenderer
mattpap 500f55f
Mark _was_build in after_render()
mattpap f22de60
Correctly render contents in Dialog
mattpap 1e4544a
Add a regression test for issue #13787
mattpap 11804cd
Update *.blf baseline files
mattpap cf8dc3e
Update bokeh's examples
mattpap 55d9deb
Add release notes
mattpap File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Introduce StyledElement base class
- Loading branch information
commit 8edd1a1093d08da0e313768cfb8a8c9f3ce16782
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| import {Model} from "../../model" | ||
| import {Node} from "../coordinates/node" | ||
| import {Styles} from "../dom/styles" | ||
| import {StyleSheet as BaseStyleSheet} from "../dom/stylesheets" | ||
| import {DOMComponentView} from "core/dom_view" | ||
| import type {StyleSheet} from "core/dom" | ||
| import {apply_styles} from "core/css" | ||
| import {InlineStyleSheet} from "core/dom" | ||
| import {entries} from "core/util/object" | ||
| import {isNumber} from "core/util/types" | ||
| import type * as p from "core/properties" | ||
| import {List, Or, Ref, Str, Dict, Nullable} from "core/kinds" | ||
|
|
||
| export const StylesLike = Or(Dict(Nullable(Str)), Ref(Styles)) // TODO: add validation for CSSStyles | ||
| export type StylesLike = typeof StylesLike["__type__"] | ||
|
|
||
| export const StyleSheets = List(Or(Ref(BaseStyleSheet), Str, Dict(StylesLike))) | ||
| export type StyleSheets = typeof StyleSheets["__type__"] | ||
|
|
||
| export const CSSVariables = Dict(Ref(Node)) | ||
| export type CSSVariables = typeof CSSVariables["__type__"] | ||
|
|
||
| export abstract class StyledElementView extends DOMComponentView { | ||
| declare model: StyledElement | ||
|
|
||
| readonly style = new InlineStyleSheet() | ||
|
|
||
| override connect_signals(): void { | ||
| super.connect_signals() | ||
|
|
||
| const {styles, css_classes, css_variables, stylesheets} = this.model.properties | ||
| this.on_change(styles, () => this._update_styles()) | ||
| this.on_change(css_classes, () => this._update_css_classes()) | ||
| this.on_transitive_change(css_variables, () => this._update_css_variables()) | ||
| this.on_change(stylesheets, () => this._update_stylesheets()) | ||
| } | ||
|
|
||
| override render(): void { | ||
| super.render() | ||
| this._apply_styles() | ||
| } | ||
|
|
||
| protected override *_css_classes(): Iterable<string> { | ||
| yield* super._css_classes() | ||
| yield* this.model.css_classes | ||
| } | ||
|
|
||
| protected override *_css_variables(): Iterable<[string, string]> { | ||
| yield* super._css_variables() | ||
| for (const [name, node] of entries(this.model.css_variables)) { | ||
| const value = this.resolve_coordinate(node) | ||
| if (isNumber(value)) { | ||
| yield [name, `${value}px`] | ||
| } | ||
| } | ||
| } | ||
|
|
||
| protected override *_stylesheets(): Iterable<StyleSheet> { | ||
| yield* super._stylesheets() | ||
| yield this.style | ||
| yield* this._computed_stylesheets() | ||
| } | ||
|
|
||
| protected *_computed_stylesheets(): Iterable<StyleSheet> { | ||
| for (const stylesheet of this.model.stylesheets) { | ||
| if (stylesheet instanceof BaseStyleSheet) { | ||
| yield stylesheet.underlying() | ||
| } else { | ||
| yield new InlineStyleSheet(stylesheet) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| protected _apply_styles(): void { | ||
| apply_styles(this.el.style, this.model.styles) | ||
| } | ||
|
|
||
| protected _update_styles(): void { | ||
| this.el.removeAttribute("style") // TODO: maintain _applied_styles | ||
| this._apply_styles() | ||
| } | ||
| } | ||
|
|
||
| export namespace StyledElement { | ||
| export type Attrs = p.AttrsOf<Props> | ||
|
|
||
| export type Props = Model.Props & { | ||
| css_classes: p.Property<string[]> | ||
| css_variables: p.Property<CSSVariables> | ||
| styles: p.Property<StylesLike> | ||
| stylesheets: p.Property<StyleSheets> | ||
| } | ||
| } | ||
|
|
||
| export interface StyledElement extends StyledElement.Attrs {} | ||
|
|
||
| export abstract class StyledElement extends Model { | ||
| declare properties: StyledElement.Props | ||
| declare __view_type__: StyledElementView | ||
|
|
||
| constructor(attrs?: Partial<StyledElement.Attrs>) { | ||
| super(attrs) | ||
| } | ||
|
|
||
| static { | ||
| this.define<StyledElement.Props>(({List, Str}) => ({ | ||
| css_classes: [ List(Str), [] ], | ||
| css_variables: [ CSSVariables, {} ], | ||
| styles: [ StylesLike, {} ], | ||
| stylesheets: [ StyleSheets, [] ], | ||
| })) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.