pyvista_js.Text#
- class pyvista_js.Text(text: str = 'Text', position: tuple[float, float] = (0.5, 0.5), prop: TextProperty | None = None, name: str | None = None)#
ベースクラス:
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).- パラメータ:
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.
サンプル
Create a text overlay:
>>> import pyvista_js 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.
- パラメータ:
idx (int) -- Unique index used to avoid variable name collisions in JavaScript.
- 戻り値:
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.js bundle.- 戻り値の型:
str
- property input: str#
Get or set the text string to be displayed.
- パラメータ:
value (str) -- Text string to display. Newline characters (
"\n") are recognized as line separators. Characters must be UTF-8 encoded.- 戻り値:
The current text string.
- 戻り値の型:
str
サンプル
>>> import pyvista_js 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.
- パラメータ:
value (tuple of float) -- Position as (x, y) in normalized viewport coordinates.
- 戻り値:
Position as (x, y).
- 戻り値の型:
tuple of float
サンプル
>>> import pyvista_js as pv >>> text = pv.Text() >>> text.position = (0.1, 0.9) >>> text.position (0.1, 0.9)