visualdynamics.report¶
report
¶
Render a Report to one self-contained HTML file.
The reader opens the file in the browser they already have, with
nothing to install, no network, and no third-party code inside the file.
Everything interactive is JavaScript written for this package (about
2,200 lines, in page.py): an orthographic 3-D scene the reader can
turn, which animates mode shapes with the same phase arithmetic as the
desktop animator, and zoomable plots with the app's own axis labels.
The data is carried as one JSON payload, already converted to the
display unit system, so the file shows what the screen showed.
Functions:
| Name | Description |
|---|---|
render_html |
The report as one HTML document string. |
resolve_references |
Replace each {{Object Name.field}} in report text with the |
block_caption |
The caption block a plot block's first figure carries, or None. |
scalogram_channel_options |
The DOF names a scalogram block can draw, for the editor's |
export_html |
Write one interactive figure as a single self-contained HTML file. |
export_figure |
Write one interactive figure as a JSON data file, and optionally |
Classes¶
Functions:¶
render_html
¶
render_html(report: Report, objects: Mapping[str, Any], unit_system: UnitSystem | None = None, edit: bool = False, channel_js: str | None = None, object_groups: Sequence[Mapping[str, Any]] | None = None, selected: int | None = None, labels: list[tuple[str, str]] | None = None, fill: bool = False, theme: str | None = None) -> str
The report as one HTML document string.
objects maps names to the project's objects, and unit_system is
the display unit system (the default system when None).
object_groups is the project's object groups: symbolic bindings
such as '@basis:Frf' are resolved against them, so a report depends
on how the project is linked, not on what its objects are named.
The reading page (edit False) leaves out blocks whose references
cannot be resolved, since an unbound block in a template is a place
to fill, not an error to show a reader. The edit page (edit True)
shows them as cards to bind again, tags every block with its index,
frames the block at selected, and sends one message to the app over
Qt's web channel: which block was clicked. channel_js is the text
of Qt's qwebchannel.js to put inline in the edit page; without it the
page loads it from qrc:. All editing is done from the app's bar and
pane, and the page has no insert bars, block toolbars or editors.
Only the app loads the edit page; an exported file has none of it.
labels, when given, is filled with (label, caption) for every
numbered figure and table, in order: what the editor's Reference
menu offers, with the same numbering the page shows.
The report features enabled on report (report.features) act
here, each only as its description says; with none enabled the
document is the one this function has always written, byte for
byte.
fill makes the page one figure filling its frame, without a title,
marking or theme toggle (export_html). theme, 'light' or 'dark',
fixes the page's theme, which otherwise follows the reader's.
Source code in src/visualdynamics/report/__init__.py
resolve_references
¶
resolve_references(text: str, objects: Mapping[str, Any], us: UnitSystem, object_groups: Sequence[Mapping[str, Any]] | None = None) -> str
Replace each {{Object Name.field}} in report text with the
object's current value, formatted in the unit system us.
This is what makes templates work: a summary that says how the data
was sampled fills itself in, in whatever project the template is
used. The name may be a symbolic selector, such as
{{@basis:TimeHistory.sample_rate}}, resolved against object_groups,
so the text does not depend on the objects' names either. A
reference that cannot be resolved (no such object, or a field the
object does not have) is left in the text as written, the same way
an unbound block is left as a place to fill.
Source code in src/visualdynamics/report/__init__.py
block_caption
¶
block_caption(block: Mapping[str, Any], objects: Mapping[str, Any], object_groups: Sequence[Mapping[str, Any]] | None = None, unit_system: UnitSystem | None = None) -> Any
The caption block a plot block's first figure carries, or None.
What the report editor reads out beside a plot block: the caption
Project.caption_of reads for the records the figure opens on: the
channel the block names, else the first channel the block's
requirement names, else the records its filter keeps that the
first figure draws. None when the block draws no measured record a
caption reads (report_caption.caption_kind), draws a grid, or the
objects are not a project.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
block
|
mapping
|
The plot block. |
required |
objects
|
Project
|
The project the report reads. |
required |
object_groups
|
sequence of mapping
|
The project's object groups, for symbolic bindings. |
None
|
unit_system
|
UnitSystem
|
The display units. |
None
|
Returns:
| Type | Description |
|---|---|
(RecordCaption, SrsCaption, SineCaption, TimeCaption or None)
|
|
Source code in src/visualdynamics/report/__init__.py
926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 | |
scalogram_channel_options
¶
The DOF names a scalogram block can draw, for the editor's drop-down list. The figure shows one channel, so the person editing the report chooses which.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
block
|
dict
|
The scalogram plot block. |
required |
objects
|
mapping
|
The report's objects, name to object. |
required |
object_groups
|
sequence
|
The project's object groups, for symbolic source bindings. |
()
|
Returns:
| Type | Description |
|---|---|
list of str
|
The response DOFs the block's |
Source code in src/visualdynamics/report/__init__.py
export_html
¶
export_html(path: str | PathLike, data: Any = None, *, specification: Any = None, channel: str | None = None, mode: str = 'curves', geometry: Any = None, shapes: Any = None, dofs: tuple[str, Any] | None = None, name: str | None = None, caption: str = '', theme: str | None = None, unit_system: UnitSystem | None = None, fill: bool = True, channels: Sequence[str] | None = None, max_points: int | None = None, component: str = 'magnitude') -> str
Write one interactive figure as a single self-contained HTML file.
visualdynamics.export_html('spec.html', psd, specification=spec,
channel='101Z+', theme='light')
visualdynamics.export_html('modes.html', geometry=g, shapes=modes)
The figure is the one a report draws, with zoom, pan and the readout
on a plot, and turning and animation on a scene, and nothing else:
no title and no marking. With fill the figure fills whatever frame
holds it, such as an iframe or a box on a slide, and redraws when the
frame changes size. Everything the page needs is in the file, so it
opens offline.
Given a geometry, the figure is a scene of it, with its shapes
animating or, with dofs, the DOFs one object measures as a
quantity, ('acceleration', frf), drawn as labeled arrows.
Otherwise it is a plot of data, against specification and its
zones when one is given, of one channel when named, in mode
('curves', 'stage', 'cmif', 'mac' or 'map').
channels and max_points make the file smaller: the first keeps
only those records of data (and of specification), the second
thins every curve of a plot to that many points, keeping every
peak and dip, and says so under the figure. export_figure writes
the same figure as a data file and a script, for a page that cannot
carry an inline script.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str or path - like
|
Where the .html goes. |
required |
data
|
DataArray or ShapeSet
|
What a plot draws. |
None
|
specification
|
Specification
|
What |
None
|
channel
|
str
|
The one control channel of a comparison to draw. |
None
|
mode
|
str
|
The plot's reading. |
'curves'
|
geometry
|
Geometry
|
Makes the figure a scene. |
None
|
shapes
|
ShapeSet
|
What the scene animates. |
None
|
dofs
|
(str, object)
|
A quantity and an object: its DOFs of that quantity, as arrows. |
None
|
name
|
str
|
What the legend calls |
None
|
caption
|
str
|
A line under the figure. |
''
|
theme
|
('light', 'dark')
|
Fixes the figure's theme; unset, it follows the reader's. |
'light'
|
unit_system
|
UnitSystem
|
The units it is drawn in. |
None
|
fill
|
bool
|
Fill the frame; False lays it out as the report page does. |
True
|
channels
|
sequence of str
|
The records of |
None
|
max_points
|
int
|
The most points a plot's curve keeps; at least 16. |
None
|
component
|
('magnitude', 'phase', 'real', 'imag')
|
How a plot of complex data reads, as the app's drop-down reads it. |
'magnitude'
|
Returns:
| Type | Description |
|---|---|
str
|
The path written. |
Raises:
| Type | Description |
|---|---|
ValueError
|
When neither |
Source code in src/visualdynamics/report/__init__.py
3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 | |
export_figure
¶
export_figure(path: str | PathLike, data: Any = None, *, renderer: str | PathLike | None = None, specification: Any = None, channel: str | None = None, mode: str = 'curves', geometry: Any = None, shapes: Any = None, dofs: tuple[str, Any] | None = None, name: str | None = None, caption: str = '', theme: str | None = None, unit_system: UnitSystem | None = None, fill: bool = False, channels: Sequence[str] | None = None, max_points: int | None = None, component: str = 'magnitude') -> str
Write one interactive figure as a JSON data file, and optionally the script that draws it, for a page that mounts the figure itself.
visualdynamics.export_figure('spec.json', psd, specification=spec,
channel='101Z+', theme='light',
renderer='visualdynamics-figure.js')
The figure is the one export_html writes, split in two. The data
file holds this figure alone. The renderer is one script for every
figure, the same viewers the HTML file carries; a page loads it from
its own site and draws a figure into an element of its own:
<div id="spec"></div>
<script src="visualdynamics-figure.js"></script>
<script src="page.js"></script> // VisualDynamicsFigure.load(
// element, 'spec.json')
So a page whose Content-Security-Policy allows no inline script and
no frames can still show the figure. VisualDynamicsFigure.mount(
element, data, options) draws data already fetched, and load(
element, url, options) fetches it first; with {pageScroll:
true} the figure leaves the wheel and a vertical swipe to the
page and zooms on Ctrl or Cmd with the wheel. The figure's styles
are scoped to that element. The renderer refuses data written for
another format (FIGURE_FORMAT), so a page never draws a figure it
would misread.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str or path - like
|
Where the .json goes. |
required |
data
|
DataArray or ShapeSet
|
What a plot draws. |
None
|
renderer
|
str or path - like
|
Where to write the renderer script as well. It is the same for every figure this version writes, so a page needs it once. |
None
|
specification
|
Specification
|
What |
None
|
channel
|
str
|
The one control channel of a comparison to draw. |
None
|
mode
|
str
|
The plot's reading. |
'curves'
|
geometry
|
Geometry
|
Makes the figure a scene. |
None
|
shapes
|
ShapeSet
|
What the scene animates. |
None
|
dofs
|
(str, object)
|
A quantity and an object: its DOFs of that quantity, as arrows. |
None
|
name
|
str
|
What the legend calls |
None
|
caption
|
str
|
A line under the figure. |
''
|
theme
|
('light', 'dark')
|
Fixes the figure's theme; unset, it follows the reader's. |
'light'
|
unit_system
|
UnitSystem
|
The units it is drawn in. |
None
|
fill
|
bool
|
Lay the figure out as the report page does, at its own height; True fills the element, which must then have a height. |
False
|
channels
|
sequence of str
|
The records of |
None
|
max_points
|
int
|
The most points a plot's curve keeps; at least 16. |
None
|
component
|
('magnitude', 'phase', 'real', 'imag')
|
How a plot of complex data reads, as the app's drop-down reads it. |
'magnitude'
|
Returns:
| Type | Description |
|---|---|
str
|
The data file's path. |
Raises:
| Type | Description |
|---|---|
ValueError
|
As |
Source code in src/visualdynamics/report/__init__.py
4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 | |