Skip to main content
Version: 13

viktor.views

DataStatus

class viktor.views.DataStatus(value)

Bases: Enum

Enumeration of statuses to annotate a DataItem.

INFO: DataStatus = 'info'
SUCCESS: DataStatus = 'success'
WARNING: DataStatus = 'warning'
ERROR: DataStatus = 'error'

DataItem

class viktor.views.DataItem(label, value, subgroup=None, *, prefix='', suffix='', number_of_decimals=None, status=DataStatus.INFO, status_message='', explanation_label='')

Constructs an entry that can be used as input of a DataGroup, to fill the data view with results.

The data view is dynamic, which means that a DataItem itself can consist of another DataGroup as subgroup. Both examples are demonstrated below.

Example single entry:

result = "I am a great result"
item = DataItem('output 1', result)

Example subgroup:

result = "I am a great result"
item = DataItem('output 1', result, subgroup=DataGroup(
    output11=DataItem('output 1.1', "I can also be a numeric result"),
    output12=DataItem('output 1.2', 123)
))

The prefix / suffix can potentially change with every call. However, when the result is used in the Summary, the prefix / suffix of the DataItem should be equal to the prefix / suffix of the SummaryItem to maintain a consistent database.

Parameters
  • label (str) – Description of the value which is shown. e.g: ‘Uc bending’

  • value (Union[str, float, None]) – Value of the data. e.g: 0.9

  • subgroup (Optional[DataGroup]) – Optional DataItems grouped together in a DataGroup underneath this DataItem. Maximum depth = 3

  • prefix (str) – E.g: €. Should be equal to the prefix of the SummaryItem if linked.

  • suffix (str) – E.g: N. Should be equal to the suffix of the SummaryItem if linked.

  • number_of_decimals (Optional[int]) – Number of decimals with which the value is rounded for display.

  • status (DataStatus) –

    Status of value. This controls the formatting of the status_message:

    • status=DataStatus.INFO: black text

    • status=DataStatus.SUCCESS: green text

    • status=DataStatus.WARNING: orange text

    • status=DataStatus.ERROR: red text

  • status_message (str) – Message which will be shown underneath the value. Color can be formatted with status.

  • explanation_label (str) – Optional text which is placed between the label and the value. Could for instance be used for a calculation.

Raises

TypeError – if number_of_decimals is used on a non-numeric value.

property subgroup: DataGroup
Return type

DataGroup

DataGroup

class viktor.views.DataGroup(*args, **kwargs)

Bases: OrderedDict

Container for DataItems, maximum number = 100. They can be added with or without a keyword argument, but they should be equal for all DataItems in the same DataGroup. Keywords are necessary when you want to use a DataItem in the summary (for lookup).

The following two use cases are valid:

d1 = DataGroup(
    DataItem('item1',0),
    DataItem('item2',1),
)

d2 = DataGroup(
    a=DataItem('item1',0),
    b=DataItem('item2',1),
)
Parameters
  • args (DataItem) – DataItem entries.

  • kwargs (DataItem) – Keyworded DataItem entries.

Raises
  • TypeError when positional- and keyword arguments are used together

  • AttributeError when more than 100 DataItems are used

classmethod from_data_groups(groups)

Constructs a combined DataGroup object from a list of individual DataGroup entries.

Note that is not possible to have multiple DataGroups that share a specific key for a DataItem, e.g. the following will result in an error:

d1 = DataGroup(output_a=DataItem(...))
d2 = DataGroup(output_a=DataItem(...))
d3 = DataGroup.from_data_groups([d1, d2])
Return type

DataGroup

Represents a link between a feature in a MapView and a specific entity.

Example usage:

gef_link = MapEntityLink('GEF x', gef_entity_id)
gef_marker = MapPoint(51.99311570849245, 4.385752379894256, entity_links=[gef_link])
Parameters
  • label (str) – text which is shown to the user.

  • entity_id (int) – id of the linked entity.

MapFeature

class viktor.views.MapFeature(*, title=None, description=None, color=Color(39, 45, 51), entity_links=None, identifier=None)

Bases: ABC

Base class for features that can be shown in a MapView. See the documentation of the subclasses for example implementations.

Parameters
  • title (Optional[str]) – Title of a clickable map feature.

  • description (Optional[str]) – Description of a clickable map feature.

  • color (Color) – Specifies the color of the map feature.

  • entity_links (Optional[List[MapEntityLink]]) – When clicking on the map feature, links towards multiple entities can be shown.

  • identifier (Union[int, str, None]) – feature identifier

    New in v13.2.0

MapPoint

class viktor.views.MapPoint(lat, lon, alt=0, *, icon=None, **kwargs)

Bases: MapFeature

Represents a point on the Earth’s surface described by a latitude/longitude coordinate pair.

Example usage:

marker = MapPoint(51.99311570849245, 4.385752379894256)
Parameters
  • lat (float) – Latitude.

  • lon (float) – Longitude.

  • alt (float) – Altitude.

  • icon (Optional[str]) – icon to be shown (default: “pin”). See below for all possible icons.

  • kwargs (Any) – See MapFeature for possible kwargs.

List of icons:

  • arrow-down: arrow-down

  • arrow-left: arrow-left

  • arrow-right: arrow-right

  • arrow-up: arrow-up

  • chevron-down: chevron-down

  • chevron-left: chevron-left

  • chevron-right: chevron-right

  • chevron-up: chevron-up

  • circle: circle

  • circle-filled: circle-filled

  • cross: cross

  • diamond: diamond

  • diamond-horizontal: diamond-horizontal

  • drop: drop

  • exclamation-circle: exclamation-circle

  • exclamation-circle-filled: exclamation-circle-filled

  • message: message

  • minus: minus

  • minus-circle: minus-circle

  • minus-circle-filled: minus-circle-filled

  • pin: pin

  • pin-add: pin-add

  • pin-edit: pin-edit

  • plus: plus

  • plus-circle: plus-circle

  • plus-circle-filled: plus-circle-filled

  • plus-thick: plus-thick

  • question-circle: question-circle

  • question-circle-filled: question-circle-filled

  • square: square

  • square-filled: square-filled

  • star: star

  • triangle: triangle

  • triangle-down: triangle-down

  • triangle-down-filled: triangle-down-filled

  • triangle-filled: triangle-filled

  • triangle-left: triangle-left

  • triangle-left-filled: triangle-left-filled

  • triangle-right: triangle-right

  • triangle-right-filled: triangle-right-filled

  • viktor: viktor

  • warning: warning

  • warning-filled: warning-filled

  • wye: wye

classmethod from_geo_point(point, *, icon=None, **kwargs)

Instantiates a MapPoint from the provided GeoPoint.

Parameters
  • point (GeoPoint) – GeoPoint.

  • icon (Optional[str]) – icon to be shown (default: “pin”). For a complete list of all available markers, see __init__()

  • kwargs (Any) – See MapFeature for possible kwargs.

Return type

MapPoint

property lat: float
Return type

float

property lon: float
Return type

float

property alt: float
Return type

float

MapPolyline

class viktor.views.MapPolyline(*points, **kwargs)

Bases: MapFeature

Represents a polyline on the earth’s surface between several latitude/longitude pairs.

Example usage:

 line = MapPolyline(
    MapPoint(51.99311570849245, 4.385752379894256),
    MapPoint(52.40912125231122, 5.031738281255681),
    ...
)
Parameters
  • points (MapPoint) – MapPoints with latitude and longitude pair.

  • kwargs (Any) – See MapFeature for possible kwargs.

classmethod from_geo_polyline(polyline, **kwargs)

Instantiates a MapPolyline from the provided GeoPolyline.

Parameters
Return type

MapPolyline

property points: List[MapPoint]
Return type

List[MapPoint]

MapLine

class viktor.views.MapLine(start_point, end_point, **kwargs)

Bases: MapPolyline

Represents a line on the earth’s surface between two latitude/longitude pairs.

In case multiple line segments are to be created, a MapPolyline may be preferred.

Example usage:

 line = MapLine(
    MapPoint(51.99311570849245, 4.385752379894256),
    MapPoint(52.40912125231122, 5.031738281255681)
)
Parameters
  • start_point (MapPoint) – Map point with latitude and longitude pair.

  • end_point (MapPoint) – Map point with latitude and longitude pair.

  • kwargs (Any) – See MapFeature for possible kwargs.

property start_point: MapPoint
Return type

MapPoint

property end_point: MapPoint
Return type

MapPoint

MapPolygon

class viktor.views.MapPolygon(points, *, holes=None, **kwargs)

Bases: MapFeature

Represents a polygon on the earth’s surface formed by a set of latitude/longitude pairs.

Example usage:

polygon = MapPolygon([
    MapPoint(52.373922404495474, 5.2459716796875),
    MapPoint(52.10313118589299, 5.3997802734375),
    MapPoint(52.373922404495474, 5.57281494140625),
])
Parameters
  • points (List[MapPoint]) – Map points with latitude and longitude pair. The profile is automatically closed, so it is not necessary to add the start point at the end.

  • holes (Optional[List[MapPolygon]]) – List of interior polygons which form holes in the exterior polygon.

  • kwargs (Any) – See MapFeature for possible kwargs.

classmethod from_geo_polygon(polygon, **kwargs)

Instantiates a MapPolygon from the provided GeoPolygon.

Parameters
Return type

MapPolygon

property points: List[MapPoint]
Return type

List[MapPoint]

property holes: List[MapPolygon]
Return type

List[MapPolygon]

MapLegend

class viktor.views.MapLegend(entries)

A legend which is placed as an overlay on a map view.

Example usage:

legend = MapLegend([
    (Color.from_hex('#0016FF'), "I'm blue"),
    (Color.from_hex('#FF0000'), "I'm red"),
    ...
])
Parameters

entries (List[Tuple[Color, str]]) – Items in the legend, defined by color and label.

MapLabel

class viktor.views.MapLabel(lat, lon, text, scale, *, fixed_size=False)

Text which is placed as an overlay on the map.

Scale 0-5 is approximately the scale for countries:

/_images/map_label_scale_0_5.png

Scale 6-10 is approximately the scale for cities:

/_images/map_label_scale_6_11.png

Scale 11-15 is approximately the scale for neighborhoods and streets

/_images/map_label_scale_11_15.png

Scale 16-18 is approximately for individual houses.

/_images/map_label_scale_14_19.png
Parameters
  • lat (float) – Latitude of text in degrees.

  • lon (float) – Longitude of text in degrees.

  • text (str) – Text with is displayed on the map.

  • scale (float) – Size of the text on an exponential scale. See example in class docstring for estimate.

  • fixed_size (bool) – When True, the size of the text is fixed regardless of zoom level (default: False).

Label

class viktor.views.Label(point, *text, size_factor=1, color=Color(0, 0, 0))

Text label

Parameters
  • point (Point) – Position of the label.

  • text (str) – Text to show; multiple text arguments will each be shown on a new line.

  • size_factor (float) – Factor to be applied to the font size (0 < size_factor <= 10).

  • color (Color) – Color of the text.

property point: Point
Return type

Point

property text: Union[str, Tuple[str, ...]]
Return type

Union[str, Tuple[str, ...]]

serialize()
Return type

dict

GeometryResult

class viktor.views.GeometryResult(geometry, labels=None)

Bases: _ViewResult

Container with the results that should be visualized in a GeometryView. This consists of three-dimensional geometry object(s) and optional text labels.

Example viktor.geometry TransformableObject(s):

geometry = Sphere(Point(0, 0), 10)
GeometryResult(geometry)  # or [obj1, obj2, ...] in case of multiple objects

Example glTF/GLB file:

geometry = File.from_path(Path(__file__).parent / "my_model.gltf")  # or .glb
GeometryResult(geometry)

Example glTF/GLB file from the internet:

geometry = File.from_url("https://github.com/KhronosGroup/glTF-Sample-Models/raw/master/2.0/CesiumMilkTruck/glTF-Binary/CesiumMilkTruck.glb")
GeometryResult(geometry)

Example trimesh package:

sphere = trimesh.creation.uv_sphere(10)
scene = trimesh.Scene(geometry={'sphere': sphere})
geometry = File()
with geometry.open_binary() as w:
    w.write(trimesh.exchange.gltf.export_glb(scene))
GeometryResult(geometry)
Parameters

GeometryAndDataResult

class viktor.views.GeometryAndDataResult(geometry, data, labels=None)

Bases: _ViewResult

Container with the results that should be visualized in a GeometryAndDataView. This consists of three-dimensional geometry object(s) with optional text labels and data.

Please have a look at GeometryResult for examples.

Parameters

DataResult

class viktor.views.DataResult(data)

Bases: _ViewResult

Container with the data that should be shown in a DataView. This data can be nested up to three levels deep.

Parameters

data (DataGroup) – Result data.

ImageResult

class viktor.views.ImageResult(image)

Bases: _ViewResult

New in v13.7.0

Image to be visualized in an ImageView.

Supported image types are ‘svg’, ‘jpeg’, ‘png’, ‘gif’.

Parameters

image (Union[StringIO, BytesIO, File]) – image file.

classmethod from_path(file_path)

Use file path to construct the image result.

Parameters

file_path (Union[str, bytes, PathLike]) – Path to the image.

Return type

ImageResult

ImageAndDataResult

class viktor.views.ImageAndDataResult(image, data)

Bases: _ViewResult

New in v13.7.0

Container with the image and result data that should be visualized in a ImageAndDataView.

Supported image types are ‘svg’, ‘jpeg’, ‘png’, ‘gif’.

Parameters
  • image (Union[StringIO, BytesIO, File]) – image file.

  • data (DataGroup) – Result data.

PNGResult

class viktor.views.PNGResult(image)

Bases: _ImageResult

Container with the PNG data that should be visualized in a PNGView.

Parameters

image (Union[BytesIO, File]) – PNG image.

classmethod from_path(file_path)

Use file path to construct the image result.

Parameters

file_path (Union[str, bytes, PathLike]) – Path to the image.

Return type

PNGResult

property image: Union[BytesIO, File]
Return type

Union[BytesIO, File]

PNGAndDataResult

class viktor.views.PNGAndDataResult(image, data)

Bases: _ImageAndDataResult

Container with the PNG data that should be visualized in a PNGAndDataView, along with the result data.

Parameters
  • image (Union[BytesIO, File]) – PNG image.

  • data (DataGroup) – Result data.

property image: Union[BytesIO, File]
Return type

Union[BytesIO, File]

JPGResult

class viktor.views.JPGResult(image)

Bases: _ImageResult

Container with the JPG data that should be visualized in a JPGView.

Parameters

image (Union[BytesIO, File]) – JPG image.

classmethod from_path(file_path)

Use file path to construct the image result.

Parameters

file_path (Union[str, bytes, PathLike]) – Path to the image.

Return type

JPGResult

property image: Union[BytesIO, File]
Return type

Union[BytesIO, File]

JPGAndDataResult

class viktor.views.JPGAndDataResult(image, data)

Bases: _ImageAndDataResult

Container with the JPG data that should be visualized in a JPGAndDataView, along with the result data.

Parameters
  • image (Union[BytesIO, File]) – JPG image.

  • data (DataGroup) – Result data.

property image: Union[BytesIO, File]
Return type

Union[BytesIO, File]

SVGResult

class viktor.views.SVGResult(image)

Bases: _ImageResult

Container with the SVG data that should be visualized in a SVGView.

Parameters

image (Union[StringIO, File]) – SVG image.

classmethod from_path(file_path)

Use file path to construct the image result.

Parameters

file_path (Union[str, bytes, PathLike]) – Path to the image.

Return type

SVGResult

property image: Union[StringIO, File]
Return type

Union[StringIO, File]

SVGAndDataResult

class viktor.views.SVGAndDataResult(image, data)

Bases: _ImageAndDataResult

Container with the SVG data that should be visualized in a SVGAndDataView, along with the result data.

Parameters
  • image (Union[StringIO, File]) – SVG image.

  • data (DataGroup) – Result data.

property image: Union[StringIO, File]
Return type

Union[StringIO, File]

GeoJSONResult

class viktor.views.GeoJSONResult(geojson, labels=None, legend=None, *, interaction_groups=None)

Bases: _ViewResult

Container with the GeoJSON data that should be visualized in a GeoJSONView. Optionally a legend and map labels can be included.

The following geojson properties are supported that can be used for styling of the map elements:

  • icon (geometry type ‘Point’ only): icon to be shown (default: “pin”). For a complete list of all available markers, see MapPoint

  • marker-color: the color of a marker *

  • description: text to show when this item is clicked

  • stroke: the color of a line as part of a polygon, polyline, or multigeometry *

  • fill: the color of the interior of a polygon *

*

color rules: Colors can be in short form “#ace” or long form “#aaccee”, and should contain the # prefix. Colors are interpreted the same as in CSS, in #RRGGBB and #RGB order.

To enable interaction, the map feature identifiers can be defined within the geojson dict by adding an “id” attribute to a feature as follows:

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": ...,
      "geometry": ...
      "id": "my identifier",
      ...
Parameters
  • geojson (dict) – GeoJSON dictionary.

  • labels (Optional[List[MapLabel]]) – Labels that should be placed on the map.

  • legend (Optional[MapLegend]) – Map legend.

  • interaction_groups (Optional[Dict[str, Sequence[Union[int, str, MapFeature]]]]) – create named groups that can be referred to in a map interaction

    New in v13.2.0

property geojson: dict
Return type

dict

GeoJSONAndDataResult

class viktor.views.GeoJSONAndDataResult(geojson, data, labels=None, legend=None, *, interaction_groups=None)

Bases: _ViewResult

Container with the GeoJSON data and result data that should be visualized in a GeoJSONAndDataView. Optionally a legend and map labels can be included.

Parameters
  • geojson (dict) – GeoJSON dictionary.

  • data (DataGroup) – Result data.

  • labels (Optional[List[MapLabel]]) – Labels that should be placed on the map.

  • legend (Optional[MapLegend]) – Map legend.

  • interaction_groups (Optional[Dict[str, Sequence[Union[int, str, MapFeature]]]]) – create named groups that can be referred to in a map interaction

    New in v13.2.0

property geojson: dict
Return type

dict

MapResult

class viktor.views.MapResult(features, labels=None, legend=None, *, interaction_groups=None)

Bases: GeoJSONResult

Container with the Map data that should be visualized in a MapView. Optionally a legend and map labels can be included.

Parameters
  • features (List[MapFeature]) – List that contains the map objects.

  • labels (Optional[List[MapLabel]]) – Labels that should be placed on the map.

  • legend (Optional[MapLegend]) – Map legend.

  • interaction_groups (Optional[Dict[str, Sequence[Union[int, str, MapFeature]]]]) – create named groups that can be referred to in a map interaction

    New in v13.2.0

property features: List[MapFeature]
Return type

List[MapFeature]

property geojson: dict
Return type

dict

MapAndDataResult

class viktor.views.MapAndDataResult(features, data, labels=None, legend=None, *, interaction_groups=None)

Bases: GeoJSONAndDataResult

Container with the Map data and result data that should be visualized in a MapAndDataView. Optionally a legend and map labels can be included.

Parameters
  • features (List[MapFeature]) – List that contains the map objects.

  • data (DataGroup) – Result data.

  • labels (Optional[List[MapLabel]]) – Labels that should be placed on the map.

  • legend (Optional[MapLegend]) – Map legend.

  • interaction_groups (Optional[Dict[str, Sequence[Union[int, str, MapFeature]]]]) – create named groups that can be referred to in a map interaction

    New in v13.2.0

property features: List[MapFeature]
Return type

List[MapFeature]

property geojson: dict
Return type

dict

WebResult

class viktor.views.WebResult(*, html=None, url=None)

Bases: _ViewResult

Container with the data that should be visualized in a WebView. There are two options, which should not be used together:

  • url: to serve a URL (takes precedence if both are defined)

  • html: for serving a single html page

Parameters
  • html (Union[StringIO, File, str, None]) – HTML formatted content.

  • url (Optional[str]) – Direct URL.

classmethod from_path(file_path)
Return type

WebResult

WebAndDataResult

class viktor.views.WebAndDataResult(*, html=None, url=None, data=None)

Bases: _ViewResult

Container with the web data and result data that should be visualized in a WebAndDataView.

The Web part can be constructed in two ways, which should not be used together:

  • url: to serve a URL (takes precedence if both are defined)

  • html: for serving a single html page

Parameters
  • html (Union[StringIO, File, str, None]) – HTML formatted content.

  • url (Optional[str]) – Direct URL.

  • data (Optional[DataGroup]) – Result data.

PlotlyResult

class viktor.views.PlotlyResult(figure)

Bases: _ViewResult

Plotly figure to be visualized in a PlotlyView. The figure can be provided in json-string or dict format.

Example usages:

@PlotlyView("Plotly view", duration_guess=1)
def get_plotly_view(self, params, **kwargs):
    fig = go.Figure(
        data=[go.Bar(x=[1, 2, 3], y=[1, 3, 2])],
        layout=go.Layout(title=go.layout.Title(text="A Figure Specified By A Graph Object"))
    )
    return PlotlyResult(fig.to_json())
@PlotlyView("Plotly view", duration_guess=1)
def get_plotly_view(self, params, **kwargs):
    fig = {
        "data": [{"type": "bar", "x": [1, 2, 3], "y": [1, 3, 2]}],
        "layout": {"title": {"text": "A Figure Specified By Python Dictionary"}}
    }
    return PlotlyResult(fig)
Parameters

figure (Union[str, dict]) – Plotly figure in str (json) or dict format

PlotlyAndDataResult

class viktor.views.PlotlyAndDataResult(figure, data)

Bases: _ViewResult

Plotly figure to be visualized in a PlotlyAndDataView. The figure can be provided in json-string or dict format.

Example usage:

@PlotlyAndDataView("Plotly and data view", duration_guess=1)
def get_plotly_and_data_view(self, params, **kwargs):
    data_group = ...

    fig = go.Figure(
        data=[go.Bar(x=[1, 2, 3], y=[1, 3, 2])],
        layout=go.Layout(title=go.layout.Title(text="A Figure Specified By A Graph Object"))
    )
    return PlotlyAndDataResult(fig.to_json(), data_group)
Parameters
  • figure (Union[str, dict]) – Plotly figure in json-str or dict format

  • data (DataGroup) – result data

PDFResult

class viktor.views.PDFResult(*, file=None, url=None)

Bases: _ViewResult

PDF document to be visualized in a PDFView. Can be defined from a File object or from a URL (direct-sharing). If both file and url are defined, url takes precedence.

In case of URL: the hosting website must allow for direct accessing for the document to be shown. If this is forbidden (undefined CORS-headers), the document can alternatively be shown via the file argument with a File.from_url(…), in which it is downloaded first and viewed subsequently (indirect-sharing).

Example usages:

From URL (direct-sharing):

PDFResult(url="https://www...")

From URL (indirect-sharing):

f = File.from_url("https://www...")
PDFResult(file=f)

From path:

file_path = Path(__file__).parent / 'sample.pdf'
PDFResult.from_path(file_path)  # or ...
PDFResult(File.from_path(file_path))
Parameters
  • file (Optional[File]) – PDF document to view

  • url (Optional[str]) – URL of PDF document to view. If accessing the PDF directly from the URL is not allowed by the host website (undefined CORS-headers), this will result in the document not showing up in the view (as an alternative one can use File.from_url).

classmethod from_path(file_path)

Create the PDFResult from a path to the PDF file.

Parameters

file_path (Union[str, bytes, PathLike]) – file path to a PDF file

Return type

PDFResult

SummaryItem

class viktor.views.SummaryItem(label, item_type, source, value_path, *, suffix='', prefix='')

A summary consists of SummaryItem objects, that define which input / result values should be displayed.

Suppose we have a data view with a controller method ‘data_view’, which returns a DataItem with key ‘output_item_1’. The following summary item can be constructed to refer to this result:

item_1 = SummaryItem('Label', float, 'data_view', 'output_item_1', suffix='N')

Suppose we have a parametrization with a certain parameter defined as geometry.input.length, this can be converted to a summary item by doing:

item_2 = SummaryItem('Length', float, 'parametrization', 'geometry.input.length', suffix='m')
Parameters
  • label (str) – Text label of the item.

  • item_type (Type[Union[str, float]]) – Type of value, options are ‘str’ | ‘float’.

  • source (str) – Source from which the input / output should be extracted.

  • value_path (str) – Dotted path of value in parametrization / data structure of view. e.g: level1.level2.value

  • suffix (str) – A prefix will be put behind the value to provide additional information such as units.

  • prefix (str) – A prefix will be put in front of the value to provide info such as a dollar sign.

Summary

class viktor.views.Summary(**items)

Bases: OrderedDict

Summary of resulting data items, which can be used in the summary view of an entity.

Example usage:

class Controller:
    ...
    summary = Summary(
        item_1=SummaryItem(...),
        item_2=SummaryItem(...),
        item_3=SummaryItem(...)
    )
Parameters

items (SummaryItem) – Items that are shown in the summary, with a maximum of 6 items per summary.

View

class viktor.views.View(label, duration_guess, *, description=None, update_label=None, **kwargs)

Bases: ABC

Warning

Do not use this class directly in an application.

Base-class of a function decorator that can be used to specify the desired view to be returned. See the subclasses for specific examples of each type of view.

Parameters
  • label (str) – Name which is shown on tab in interface. e.g: ‘3D Representation’

  • duration_guess (int) – Estimation of view calculation in seconds. This will be used to add a manual refresh button for long-running tasks (larger than 3s). This estimation does not need to be very precise, but the performance will be better if this is close to the real maximum computation time.

  • description (Optional[str]) – Show more information to the user through a tooltip on hover (max. 200 characters).

  • update_label (Optional[str]) – Name which is shown on the update button in case of a slow view (max. 30 characters).

GeometryView

class viktor.views.GeometryView(label, duration_guess, *, description=None, update_label=None, view_mode='3D', default_shadow=False, up_axis='Z')

Bases: View

Function decorator to instruct the controller method to return a geometry view (2D / 3D).

Example usage:

@GeometryView("3D model", duration_guess=2)
def get_geometry_view(self, params, **kwargs):
    ...
    return GeometryResult(...)

@GeometryView("2D model", duration_guess=2, view_mode='2D')
def get_geometry_view_2d(self, params, **kwargs):
    ...
    return GeometryResult(...)
Parameters
  • label (str) – See View.

  • duration_guess (int) – See View.

  • description (Optional[str]) – See View.

  • update_label (Optional[str]) – See View.

  • view_mode (str) –

    Sets the view mode:

    • ’3D’: Camera is free to move and user can choose between orthographic and perspective view.

    • ’2D’: Camera is fixed on the xy-plane and view is orthographic.

  • default_shadow (bool) – Show shadow when editor is opened. User can still switch it off.

  • up_axis (str) – Upwards pointing axis. Possible options: ‘Y’, ‘Z’ (default: ‘Z’)

DataView

class viktor.views.DataView(label, duration_guess, *, description=None, update_label=None, **kwargs)

Bases: View

Function decorator to instruct the controller method to return a data view that contains calculation result.

Example usage:

@DataView("Cost breakdown", duration_guess=2)
def get_data_view(self, params, **kwargs):
    # calculate data
    ...
    return DataResult(data_group)
Parameters
  • label (str) – Name which is shown on tab in interface. e.g: ‘3D Representation’

  • duration_guess (int) – Estimation of view calculation in seconds. This will be used to add a manual refresh button for long-running tasks (larger than 3s). This estimation does not need to be very precise, but the performance will be better if this is close to the real maximum computation time.

  • description (Optional[str]) – Show more information to the user through a tooltip on hover (max. 200 characters).

  • update_label (Optional[str]) – Name which is shown on the update button in case of a slow view (max. 30 characters).

GeometryAndDataView

class viktor.views.GeometryAndDataView(label, duration_guess, *, description=None, update_label=None, view_mode='3D', default_shadow=False, up_axis='Z')

Bases: View

Function decorator to instruct the controller method to return a combined view consisting of geometries and data.

Example usage:

@GeometryAndDataView("Model / Cost", duration_guess=2)
def get_geometry_data_view(self, params, **kwargs):
    ...
    return GeometryAndDataResult(...)
Parameters
  • label (str) – See View.

  • duration_guess (int) – See View.

  • description (Optional[str]) – See View.

  • update_label (Optional[str]) – See View.

  • view_mode (str) –

    Sets the view mode:

    • ’3D’: Camera is free to move and user can choose between orthographic and perspective view.

    • ’2D’: Camera is fixed on the xy-plane and view is orthographic.

  • default_shadow (bool) – Show shadow when editor is opened. User can still switch it off.

  • up_axis (str) – Upwards pointing axis. Possible options: ‘Y’, ‘Z’ (default: ‘Z’)

SVGView

class viktor.views.SVGView(*args, **kwargs)

Bases: View

Function decorator to instruct the controller method to return an SVG view.

Example usage:

@SVGView("SVG plot", duration_guess=2)
def get_svg_view(self, params, **kwargs):
    # create svg image
    ...
    return SVGResult(svg_image)
Parameters
  • label – Name which is shown on tab in interface. e.g: ‘3D Representation’

  • duration_guess – Estimation of view calculation in seconds. This will be used to add a manual refresh button for long-running tasks (larger than 3s). This estimation does not need to be very precise, but the performance will be better if this is close to the real maximum computation time.

  • description – Show more information to the user through a tooltip on hover (max. 200 characters).

  • update_label – Name which is shown on the update button in case of a slow view (max. 30 characters).

SVGAndDataView

class viktor.views.SVGAndDataView(*args, **kwargs)

Bases: View

Function decorator to instruct the controller method to return a combined view consisting of an SVG and data.

Example usage:

@SVGAndDataView("Plot / Cost", duration_guess=2)
def get_svg_data_view(self, params, **kwargs):
    # create svg image
    ...
    # calculate data
    ...
    return SVGAndDataResult(svg_image, data_group)
Parameters
  • label – Name which is shown on tab in interface. e.g: ‘3D Representation’

  • duration_guess – Estimation of view calculation in seconds. This will be used to add a manual refresh button for long-running tasks (larger than 3s). This estimation does not need to be very precise, but the performance will be better if this is close to the real maximum computation time.

  • description – Show more information to the user through a tooltip on hover (max. 200 characters).

  • update_label – Name which is shown on the update button in case of a slow view (max. 30 characters).

GeoJSONView

class viktor.views.GeoJSONView(label, duration_guess, *, description=None, update_label=None, **kwargs)

Bases: View

Function decorator to instruct the controller method to return a GeoJSON (geographic data) view.

Example usage:

@GeoJSONView("Map", duration_guess=2)
def get_geojson_view(self, params, **kwargs):
    ...
    return GeoJSONResult(...)
Parameters
  • label (str) – Name which is shown on tab in interface. e.g: ‘3D Representation’

  • duration_guess (int) – Estimation of view calculation in seconds. This will be used to add a manual refresh button for long-running tasks (larger than 3s). This estimation does not need to be very precise, but the performance will be better if this is close to the real maximum computation time.

  • description (Optional[str]) – Show more information to the user through a tooltip on hover (max. 200 characters).

  • update_label (Optional[str]) – Name which is shown on the update button in case of a slow view (max. 30 characters).

GeoJSONAndDataView

class viktor.views.GeoJSONAndDataView(label, duration_guess, *, description=None, update_label=None, **kwargs)

Bases: View

Function decorator to instruct the controller method to return a combined view consisting of a GeoJSON and data.

Example usage:

@SVGAndDataView("Map / Data", duration_guess=2)
def get_geojson_data_view(self, params, **kwargs):
    ...
    return GeoJSONAndDataResult(...)
Parameters
  • label (str) – Name which is shown on tab in interface. e.g: ‘3D Representation’

  • duration_guess (int) – Estimation of view calculation in seconds. This will be used to add a manual refresh button for long-running tasks (larger than 3s). This estimation does not need to be very precise, but the performance will be better if this is close to the real maximum computation time.

  • description (Optional[str]) – Show more information to the user through a tooltip on hover (max. 200 characters).

  • update_label (Optional[str]) – Name which is shown on the update button in case of a slow view (max. 30 characters).

MapView

class viktor.views.MapView(label, duration_guess, *, description=None, update_label=None, **kwargs)

Bases: View

Function decorator to instruct the controller method to return a Map (geographic data) view.

Example usage:

@MapView("Map", duration_guess=2)
def get_map_view(self, params, **kwargs):
    ...
    return MapResult(...)
Parameters
  • label (str) – Name which is shown on tab in interface. e.g: ‘3D Representation’

  • duration_guess (int) – Estimation of view calculation in seconds. This will be used to add a manual refresh button for long-running tasks (larger than 3s). This estimation does not need to be very precise, but the performance will be better if this is close to the real maximum computation time.

  • description (Optional[str]) – Show more information to the user through a tooltip on hover (max. 200 characters).

  • update_label (Optional[str]) – Name which is shown on the update button in case of a slow view (max. 30 characters).

MapAndDataView

class viktor.views.MapAndDataView(label, duration_guess, *, description=None, update_label=None, **kwargs)

Bases: View

Function decorator to instruct the controller method to return a combined view consisting of a Map and data.

Example usage:

@MapAndDataView("Map / Data", duration_guess=2)
def get_map_data_view(self, params, **kwargs):
    ...
    return MapAndDataResult(...)
Parameters
  • label (str) – Name which is shown on tab in interface. e.g: ‘3D Representation’

  • duration_guess (int) – Estimation of view calculation in seconds. This will be used to add a manual refresh button for long-running tasks (larger than 3s). This estimation does not need to be very precise, but the performance will be better if this is close to the real maximum computation time.

  • description (Optional[str]) – Show more information to the user through a tooltip on hover (max. 200 characters).

  • update_label (Optional[str]) – Name which is shown on the update button in case of a slow view (max. 30 characters).

ImageView

class viktor.views.ImageView(label, duration_guess, *, description=None, update_label=None, **kwargs)

Bases: View

New in v13.7.0

Function decorator to instruct the controller method to return an ImageView.

Supported image types are ‘svg’, ‘jpeg’, ‘png’, ‘gif’.

Example usage:

@ImageView("Image View", duration_guess=1)
def get_image_view(self, params, **kwargs):
    file_path = Path(__file__).parent / 'sample.png'
    return ImageResult(File.from_path(file_path))  # or `ImageResult.from_path(file_path)`
Parameters
  • label (str) – Name which is shown on tab in interface. e.g: ‘3D Representation’

  • duration_guess (int) – Estimation of view calculation in seconds. This will be used to add a manual refresh button for long-running tasks (larger than 3s). This estimation does not need to be very precise, but the performance will be better if this is close to the real maximum computation time.

  • description (Optional[str]) – Show more information to the user through a tooltip on hover (max. 200 characters).

  • update_label (Optional[str]) – Name which is shown on the update button in case of a slow view (max. 30 characters).

ImageAndDataView

class viktor.views.ImageAndDataView(label, duration_guess, *, description=None, update_label=None, **kwargs)

Bases: View

New in v13.7.0

Function decorator to instruct the controller method to return a combined view consisting of an image and data.

Supported image types are ‘svg’, ‘jpeg’, ‘png’, ‘gif’.

Example usage:

@ImageAndDataView("Image View", duration_guess=1)
def get_image_data_view(self, params, **kwargs):
    ...
    return ImageAndDataResult(image, data_group)
Parameters
  • label (str) – Name which is shown on tab in interface. e.g: ‘3D Representation’

  • duration_guess (int) – Estimation of view calculation in seconds. This will be used to add a manual refresh button for long-running tasks (larger than 3s). This estimation does not need to be very precise, but the performance will be better if this is close to the real maximum computation time.

  • description (Optional[str]) – Show more information to the user through a tooltip on hover (max. 200 characters).

  • update_label (Optional[str]) – Name which is shown on the update button in case of a slow view (max. 30 characters).

PNGView

class viktor.views.PNGView(*args, **kwargs)

Bases: View

Function decorator to instruct the controller method to return a PNG view.

Example usage:

@PNGView("PNG image", duration_guess=1)
def get_png_view(self, params, **kwargs):
    # get png image
    ...
    return PNGResult(image)
Parameters
  • label – Name which is shown on tab in interface. e.g: ‘3D Representation’

  • duration_guess – Estimation of view calculation in seconds. This will be used to add a manual refresh button for long-running tasks (larger than 3s). This estimation does not need to be very precise, but the performance will be better if this is close to the real maximum computation time.

  • description – Show more information to the user through a tooltip on hover (max. 200 characters).

  • update_label – Name which is shown on the update button in case of a slow view (max. 30 characters).

PNGAndDataView

class viktor.views.PNGAndDataView(*args, **kwargs)

Bases: View

Function decorator to instruct the controller method to return a combined view consisting of a PNG and data.

Example usage:

@PNGAndDataView("PNG / Data", duration_guess=1)
def get_png_data_view(self, params, **kwargs):
    # get png image
    ...
    # calculate data
    ...
    return PNGAndDataResult(image, data_group)
Parameters
  • label – Name which is shown on tab in interface. e.g: ‘3D Representation’

  • duration_guess – Estimation of view calculation in seconds. This will be used to add a manual refresh button for long-running tasks (larger than 3s). This estimation does not need to be very precise, but the performance will be better if this is close to the real maximum computation time.

  • description – Show more information to the user through a tooltip on hover (max. 200 characters).

  • update_label – Name which is shown on the update button in case of a slow view (max. 30 characters).

JPGView

class viktor.views.JPGView(*args, **kwargs)

Bases: View

Function decorator to instruct the controller method to return a JPG view.

Example usage:

@JPGView("JPG image", duration_guess=1)
def get_jpg_view(self, params, **kwargs):
    # get jpg image
    ...
    return JPGResult(image)
Parameters
  • label – Name which is shown on tab in interface. e.g: ‘3D Representation’

  • duration_guess – Estimation of view calculation in seconds. This will be used to add a manual refresh button for long-running tasks (larger than 3s). This estimation does not need to be very precise, but the performance will be better if this is close to the real maximum computation time.

  • description – Show more information to the user through a tooltip on hover (max. 200 characters).

  • update_label – Name which is shown on the update button in case of a slow view (max. 30 characters).

JPGAndDataView

class viktor.views.JPGAndDataView(*args, **kwargs)

Bases: View

Function decorator to instruct the controller method to return a combined view consisting of a JPG and data.

Example usage:

@JPGAndDataView("JPG / Data", duration_guess=1)
def get_jpg_data_view(self, params, **kwargs):
    # get jpg image
    ...
    # calculate data
    ...
    return JPGAndDataResult(image, data_group)
Parameters
  • label – Name which is shown on tab in interface. e.g: ‘3D Representation’

  • duration_guess – Estimation of view calculation in seconds. This will be used to add a manual refresh button for long-running tasks (larger than 3s). This estimation does not need to be very precise, but the performance will be better if this is close to the real maximum computation time.

  • description – Show more information to the user through a tooltip on hover (max. 200 characters).

  • update_label – Name which is shown on the update button in case of a slow view (max. 30 characters).

WebView

class viktor.views.WebView(label, duration_guess, *, description=None, update_label=None, **kwargs)

Bases: View

Function decorator to instruct the controller method to return a web-content view.

Example usage:

@WebView("Hello world", duration_guess=1)
def get_web_view(self, params, **kwargs):
    return WebResult(html="<html>Hello world</html>")
Parameters
  • label (str) – Name which is shown on tab in interface. e.g: ‘3D Representation’

  • duration_guess (int) – Estimation of view calculation in seconds. This will be used to add a manual refresh button for long-running tasks (larger than 3s). This estimation does not need to be very precise, but the performance will be better if this is close to the real maximum computation time.

  • description (Optional[str]) – Show more information to the user through a tooltip on hover (max. 200 characters).

  • update_label (Optional[str]) – Name which is shown on the update button in case of a slow view (max. 30 characters).

WebAndDataView

class viktor.views.WebAndDataView(label, duration_guess, *, description=None, update_label=None, **kwargs)

Bases: View

Function decorator to instruct the controller method to return a combined view consisting of web-content and data.

Example usage:

@WebAndDataView("Web / Data", duration_guess=1)
def get_web_data_view(self, params, **kwargs):
    # calculate data
    ...
    return WebAndDataResult(html="<html>Hello world</html>", data=data_group)
Parameters
  • label (str) – Name which is shown on tab in interface. e.g: ‘3D Representation’

  • duration_guess (int) – Estimation of view calculation in seconds. This will be used to add a manual refresh button for long-running tasks (larger than 3s). This estimation does not need to be very precise, but the performance will be better if this is close to the real maximum computation time.

  • description (Optional[str]) – Show more information to the user through a tooltip on hover (max. 200 characters).

  • update_label (Optional[str]) – Name which is shown on the update button in case of a slow view (max. 30 characters).

PlotlyView

class viktor.views.PlotlyView(label, duration_guess, *, description=None, update_label=None, **kwargs)

Bases: View

Function decorator to instruct the controller method to return a PlotlyView.

Example usage:

@PlotlyView("Plotly view", duration_guess=1)
def get_plotly_view(self, params, **kwargs):
    ...
    return PlotlyResult(figure)
Parameters
  • label (str) – Name which is shown on tab in interface. e.g: ‘3D Representation’

  • duration_guess (int) – Estimation of view calculation in seconds. This will be used to add a manual refresh button for long-running tasks (larger than 3s). This estimation does not need to be very precise, but the performance will be better if this is close to the real maximum computation time.

  • description (Optional[str]) – Show more information to the user through a tooltip on hover (max. 200 characters).

  • update_label (Optional[str]) – Name which is shown on the update button in case of a slow view (max. 30 characters).

PlotlyAndDataView

class viktor.views.PlotlyAndDataView(label, duration_guess, *, description=None, update_label=None, **kwargs)

Bases: View

Function decorator to instruct the controller method to return a combined view consisting of a PlotlyView and a DataView.

Example usage:

@PlotlyAndDataView("Plotly and data view", duration_guess=1)
def get_plotly_and_data_view(self, params, **kwargs):
    ...
    return PlotlyAndDataResult(figure, data_group)
Parameters
  • label (str) – Name which is shown on tab in interface. e.g: ‘3D Representation’

  • duration_guess (int) – Estimation of view calculation in seconds. This will be used to add a manual refresh button for long-running tasks (larger than 3s). This estimation does not need to be very precise, but the performance will be better if this is close to the real maximum computation time.

  • description (Optional[str]) – Show more information to the user through a tooltip on hover (max. 200 characters).

  • update_label (Optional[str]) – Name which is shown on the update button in case of a slow view (max. 30 characters).

PDFView

class viktor.views.PDFView(label, duration_guess, *, description=None, update_label=None, **kwargs)

Bases: View

Function decorator to instruct the controller method to return a PDFView.

Example usage:

@PDFView("PDF View", duration_guess=1)
def get_pdf_view(self, params, **kwargs):
    file_path = Path(__file__).parent / 'sample.pdf'
    return PDFResult(File.from_path(file_path))  # or `PDFResult.from_path(file_path)`
Parameters
  • label (str) – Name which is shown on tab in interface. e.g: ‘3D Representation’

  • duration_guess (int) – Estimation of view calculation in seconds. This will be used to add a manual refresh button for long-running tasks (larger than 3s). This estimation does not need to be very precise, but the performance will be better if this is close to the real maximum computation time.

  • description (Optional[str]) – Show more information to the user through a tooltip on hover (max. 200 characters).

  • update_label (Optional[str]) – Name which is shown on the update button in case of a slow view (max. 30 characters).

InteractionEvent

class viktor.views.InteractionEvent(event_type, value)

Event triggered by the user as a consequence of an viktor.parametrization.Interaction.

Warning

Do not instantiate this class directly, it is returned as ‘event’ in the method of the button with the corresponding interaction.

Parameters
  • event_type (str) – type of the event (‘map_select’)

  • value (Any) –

    value of the user performed interaction. Type depends on event_type:

    • map_select: List[Union[str, int]] = identifier of selected features