pyvista_wasm.Text#
- class pyvista_wasm.Text(text: str = 'Text', position: tuple[float, float] = (0.5, 0.5), prop: TextProperty | None = None, name: str | None = None)#
Bases:
objectA text annotation actor for 3D rendering.
Wraps
vtk.Rendering.Core.vtkTextActorto display 2D text overlays on 3D scenes. Text is positioned in normalized viewport coordinates (0 to 1 in both x and y).- Parameters:
text (str, optional) – Text string to be displayed.
"\n"is recognized as a line separator. Characters must be UTF-8 encoded. Default is"Text".position (tuple of float, optional) – Position coordinate in normalized viewport space (x, y) where (0, 0) is bottom-left and (1, 1) is top-right. Default is
(0.5, 0.5).prop (TextProperty, optional) – The property of this text actor controlling appearance. If
None, creates a default TextProperty. Default isNone.name (str, optional) – The name of this actor used when tracking on a plotter. Default is
None.
Examples
Create a text overlay:
>>> import pyvista_wasm as pv >>> plotter = pv.Plotter() >>> _ = plotter.add_mesh(pv.Sphere(), color='white') >>> text = pv.Text("Hello World", position=(0.5, 0.9)) >>> plotter.add_text(text) >>> plotter.show()
Customize text appearance:
>>> text = pv.Text( ... "Custom Text", ... position=(0.1, 0.1), ... prop=pv.TextProperty(font_size=24, color="red", bold=True), ... )
- __init__(text: str = 'Text', position: tuple[float, float] = (0.5, 0.5), prop: TextProperty | None = None, name: str | None = None) None#
Initialize a Text instance.
Methods
__init__([text, position, prop, name])Initialize a Text instance.
generate_vtk_js_code(idx)Generate JavaScript code for this text actor as an HTML overlay div.
Attributes
Get or set the text string to be displayed.
Get or set the text position in normalized viewport coordinates.
- generate_vtk_js_code(idx: int) str#
Generate JavaScript code for this text actor as an HTML overlay div.
- Parameters:
idx (int) – Unique index used to avoid variable name collisions in JavaScript.
- Returns:
JavaScript code that creates and configures the text overlay div. Uses an absolutely positioned div over the rendering container because
vtkTextActoris not available in the VTK.wasm bundle.- Return type:
str
- property input: str#
Get or set the text string to be displayed.
- Parameters:
value (str) – Text string to display. Newline characters (
"\n") are recognized as line separators. Characters must be UTF-8 encoded.- Returns:
The current text string.
- Return type:
str
Examples
>>> import pyvista_wasm as pv >>> text = pv.Text() >>> text.input = "Hello\nWorld" >>> text.input 'Hello\nWorld'
- property position: tuple[float, float]#
Get or set the text position in normalized viewport coordinates.
Position is specified in normalized viewport coordinates where (0, 0) is the bottom-left corner and (1, 1) is the top-right corner.
- Parameters:
value (tuple of float) – Position as (x, y) in normalized viewport coordinates.
- Returns:
Position as (x, y).
- Return type:
tuple of float
Examples
>>> import pyvista_wasm as pv >>> text = pv.Text() >>> text.position = (0.1, 0.9) >>> text.position (0.1, 0.9)