Skip to main content

Module h2o_wave.graphics

Functions

arc

def arc(r1: float, r2: float, a1: float, a2: float, **kwargs) ‑> Expando

Draw circular or annular sector, as in a pie or donut chart, centered at (0, 0).

Args
r1
inner radius.
r2
outer radius.
a1
start angle, in degrees.
a2
end angle, in degrees.
kwargs
Attributes to use for the initial render. SVG attributes, snake-cased.
Returns

Data for the graphical element.

circle

def circle(**kwargs) ‑> Expando

Draw a circle. See https://developer.mozilla.org/en-US/docs/Web/SVG/Element/circle

Args
kwargs
Attributes to use for the initial render. SVG attributes, snake-cased.
Returns

Data for the graphical element.

draw

def draw(element: Ref, **kwargs) ‑> Ref

Schedule a redraw of the specified graphical element using the provided attributes.

Args
element
A reference to a graphical element.
kwargs
Attributes to use while performing a redraw.
Returns

The element reference, without change.

ellipse

def ellipse(**kwargs) ‑> Expando

Draw an ellipse. See https://developer.mozilla.org/en-US/docs/Web/SVG/Element/ellipse

Args
kwargs
Attributes to use for the initial render. SVG attributes, snake-cased.
Returns

Data for the graphical element.

image

def image(**kwargs) ‑> Expando

Draw an image. See https://developer.mozilla.org/en-US/docs/Web/SVG/Element/image

Args
kwargs
Attributes to use for the initial render. SVG attributes, snake-cased.
Returns

Data for the graphical element.

line

def line(**kwargs) ‑> Expando

Draw a line. See https://developer.mozilla.org/en-US/docs/Web/SVG/Element/line

Args
kwargs
Attributes to use for the initial render. SVG attributes, snake-cased.
Returns

Data for the graphical element.

p

def p() ‑> Path

Create a new Path.

Returns

A new Path.

path

def path(**kwargs) ‑> Expando

Draw a path. See https://developer.mozilla.org/en-US/docs/Web/SVG/Element/path

Args
kwargs
Attributes to use for the initial render. SVG attributes, snake-cased.
Returns

Data for the graphical element.

polygon

def polygon(**kwargs) ‑> Expando

Draw a polygon. See https://developer.mozilla.org/en-US/docs/Web/SVG/Element/polygon

Args
kwargs
Attributes to use for the initial render. SVG attributes, snake-cased.
Returns

Data for the graphical element.

polyline

def polyline(**kwargs) ‑> Expando

Draw a polyline. See https://developer.mozilla.org/en-US/docs/Web/SVG/Element/polyline

Args
kwargs
Attributes to use for the initial render. SVG attributes, snake-cased.
Returns

Data for the graphical element.

rect

def rect(**kwargs) ‑> Expando

Draw a rectangle. See https://developer.mozilla.org/en-US/docs/Web/SVG/Element/rect

Args
kwargs
Attributes to use for the initial render. SVG attributes, snake-cased.
Returns

Data for the graphical element.

reset

def reset(element: Ref) ‑> Ref

Schedule a redraw of the specified graphical element using its original attributes. Calling this function clears any changes performed using the draw() function.

Args
element
A reference to a graphical element.
Returns

The element reference, without change.

scene

def scene(**kwargs) ‑> Data

Create a scene. A scene holds graphic elements whose attributes need to be changed dynamically (causing a re-render). The return value must be assigned to the scene() property of a GraphicsCard.

Args
kwargs
Graphical elements to render as part of the scene.
Returns

A Data instance.

spline

def spline(x: Optional[List[Optional[float]]] = None, y: Optional[List[Optional[float]]] = None, x0: Optional[List[Optional[float]]] = None, y0: Optional[List[Optional[float]]] = None, curve: Optional[str] = None, radial: Optional[bool] = None, **kwargs) ‑> Expando

Draw a spline.

If x, y are specified, draws a regular spline.

If x, y, y0 are specified, draws a horizontal area spline. Sets baseline to zero if y0 is an empty list.

If x, x0, y are specified, draws a vertical area spline. Sets baseline to zero if x0 is an empty list

Missing information is rendered as gaps in the spline.

Args
x
x-coordinates.
y
y-coordinates.
x0
base x-coordinates.
y0
base y-coordinates.
curve
Interpolation. One of basis, basis-closed, basis-open, cardinal, cardinal-closed, cardinal-open, smooth, smooth-closed, smooth-open, linear, linear-closed, monotone-x, monotone-y, natural, step, step-after, step-before. Defaults to linear.
radial
Whether (x, y) should be treated as (angle,radius) or (x0, x, y0, y) should be treated as (start-angle, end-angle, inner-radius, outer-radius).
kwargs
Attributes to use for the initial render. SVG attributes, snake-cased.
Returns

Data for the graphical element.

stage

def stage(**kwargs) ‑> str

Create a stage. A stage holds static graphics elements that are rendered as part of the background (behind the scene). The return value must be assigned to the stage() property of a GraphicsCard.

Args
kwargs
Graphical elements to render as part of the stage.
Returns

Packed data.

text

def text(text: str, **kwargs) ‑> Expando

Draw text. See https://developer.mozilla.org/en-US/docs/Web/SVG/Element/text

Args
text
The text content.
kwargs
Attributes to use for the initial render. SVG attributes, snake-cased.
Returns

Data for the graphical element.

turtle

def turtle(x=0.0, y=0.0, degrees=0.0) ‑> Turtle

Create a new Turtle.

Args
x
initial position x
y
initial position y
degrees
initial angle in degrees
Returns

A new Turtle.

type_of

def type_of(element: Expando) ‑> Optional[str]

Get the type of the graphical element.

Args
element
A graphical element.
Returns

A string indicating the type of the element, e.g. 'circle', 'line', etc.

Classes

Path

class Path

A convenience class for drawing SVG paths.

Methods

A

def A(self, rx: float, ry: float, x_axis_rotation: float, large_arc: bool, sweep: bool, x: float, y: float) ‑> Path

Draws an elliptical arc from the current point to (x, y). The size and orientation of the ellipse are defined by two radii (rx, ry) and an x_axis_rotation, which indicates how the ellipse as a whole is rotated, in degrees, relative to the current coordinate system. The center (cx, cy) of the ellipse is calculated automatically to satisfy the constraints imposed by the other parameters. large_arc and sweep_flagcontribute to the automatic calculations and help determine how the arc is drawn. In absolute coordinates.

See https://www.w3.org/TR/SVG/paths.html#PathDataEllipticalArcCommands

Args
rx
x-radius
ry
y-radius
x_axis_rotation
Rotation in degrees.
large_arc
Determines if the arc should be greater than or less than 180 degrees.
sweep
Determines if the arc should begin moving at positive angles or negative ones.
x
x-coordinate
y
y-coordinate
Returns

The current Path instance.

C

def C(self, x1: float, y1: float, x2: float, y2: float, x: float, y: float) ‑> Path

Draws a cubic Bézier curve from the current point to (x,y) using (x1,y1) as the control point at the beginning of the curve and (x2,y2) as the control point at the end of the curve. In absolute coordinates.

See https://www.w3.org/TR/SVG/paths.html#PathDataCubicBezierCommands

Args
x1
x-coordinate of first control point
y1
y-coordinate of first control point
x2
x-coordinate of second control point
y2
y-coordinate of second control point
x
x-coordinate
y
y-coordinate
Returns

The current Path instance.

H

def H(self, x: float) ‑> Path

Draws a horizontal line from the current point. In absolute coordinates.

See https://www.w3.org/TR/SVG/paths.html#PathDataLinetoCommands

Args
x
x-coordinate
Returns

The current Path instance.

L

def L(self, x: float, y: float) ‑> Path

Draw a line from the current point to the given (x,y) coordinate which becomes the new current point. In absolute coordinates.

See https://www.w3.org/TR/SVG/paths.html#PathDataLinetoCommands

Args
x
x-coordinate
y
y-coordinate
Returns

The current Path instance.

M

def M(self, x: float, y: float) ‑> Path

Start a new sub-path at the given (x,y) coordinates. In absolute coordinates.

See https://www.w3.org/TR/SVG/paths.html#PathDataMovetoCommands

Args
x
x-coordinate
y
y-coordinate
Returns

The current Path instance.

Q

def Q(self, x1: float, y1: float, x: float, y: float) ‑> Path

Draws a quadratic Bézier curve from the current point to (x,y) using (x1,y1) as the control point. In absolute coordinates.

See https://www.w3.org/TR/SVG/paths.html#PathDataQuadraticBezierCommands

Args
x1
x-coordinate of first control point
y1
y-coordinate of first control point
x
x-coordinate
y
y-coordinate
Returns

The current Path instance.

S

def S(self, x2: float, y2: float, x: float, y: float) ‑> Path

Draws a cubic Bézier curve from the current point to (x,y). The first control point is assumed to be the reflection of the second control point on the previous command relative to the current point. (x2,y2) is the second control point (i.e., the control point at the end of the curve). In absolute coordinates.

See https://www.w3.org/TR/SVG/paths.html#PathDataCubicBezierCommands

Args
x2
x-coordinate of second control point
y2
y-coordinate of second control point
x
x-coordinate
y
y-coordinate
Returns

The current Path instance.

T

def T(self, x: float, y: float) ‑> Path

Draws a quadratic Bézier curve from the current point to (x,y). The control point is assumed to be the reflection of the control point on the previous command relative to the current point. In absolute coordinates.

See https://www.w3.org/TR/SVG/paths.html#PathDataQuadraticBezierCommands

Args
x
x-coordinate
y
y-coordinate
Returns

The current Path instance.

V

def V(self, y: float) ‑> Path

Draws a vertical line from the current point. In absolute coordinates.

See https://www.w3.org/TR/SVG/paths.html#PathDataLinetoCommands

Args
y
y-coordinate
Returns

The current Path instance.

Z

def Z(self) ‑> Path

Close the current subpath by connecting it back to the current subpath's initial point.

See https://www.w3.org/TR/SVG/paths.html#PathDataClosePathCommand

Returns

The current Path instance.

a

def a(self, rx: float, ry: float, x_axis_rotation: float, large_arc: bool, sweep: bool, x: float, y: float) ‑> Path

Draws an elliptical arc from the current point to (x, y). The size and orientation of the ellipse are defined by two radii (rx, ry) and an x_axis_rotation, which indicates how the ellipse as a whole is rotated, in degrees, relative to the current coordinate system. The center (cx, cy) of the ellipse is calculated automatically to satisfy the constraints imposed by the other parameters. large_arc and sweep_flagcontribute to the automatic calculations and help determine how the arc is drawn. In relative coordinates.

See https://www.w3.org/TR/SVG/paths.html#PathDataEllipticalArcCommands

Args
rx
x-radius
ry
y-radius
x_axis_rotation
Rotation in degrees.
large_arc
Determines if the arc should be greater than or less than 180 degrees.
sweep
Determines if the arc should begin moving at positive angles or negative ones.
x
x-coordinate
y
y-coordinate
Returns

The current Path instance.

c

def c(self, x1: float, y1: float, x2: float, y2: float, x: float, y: float) ‑> Path

Draws a cubic Bézier curve from the current point to (x,y) using (x1,y1) as the control point at the beginning of the curve and (x2,y2) as the control point at the end of the curve. In relative coordinates.

See https://www.w3.org/TR/SVG/paths.html#PathDataCubicBezierCommands

Args
x1
x-coordinate of first control point
y1
y-coordinate of first control point
x2
x-coordinate of second control point
y2
y-coordinate of second control point
x
x-coordinate
y
y-coordinate
Returns

The current Path instance.

d

def d(self) ‑> str

Serialize this path's commands into SVG path data.

Returns

The d attribute for a SVG path.

h

def h(self, x: float) ‑> Path

Draws a horizontal line from the current point. In relative coordinates.

See https://www.w3.org/TR/SVG/paths.html#PathDataLinetoCommands

Args
x
x-coordinate
Returns

The current Path instance.

l

def l(self, x: float, y: float) ‑> Path

Draw a line from the current point to the given (x,y) coordinate which becomes the new current point. In relative coordinates.

See https://www.w3.org/TR/SVG/paths.html#PathDataLinetoCommands

Args
x
x-coordinate
y
y-coordinate
Returns

The current Path instance.

m

def m(self, x: float, y: float) ‑> Path

Start a new sub-path at the given (x,y) coordinates. In relative coordinates.

See https://www.w3.org/TR/SVG/paths.html#PathDataMovetoCommands

Args
x
x-coordinate
y
y-coordinate
Returns

The current Path instance.

path

def path(self, **kwargs) ‑> Expando

A SVG path element representing the commands in this Path instance. Same as calling h2o_wave.graphics.path(d=path.d())

Args
kwargs
Additional attributes for the SVG path element.
Returns

A SVG path element.

q

def q(self, x1: float, y1: float, x: float, y: float) ‑> Path

Draws a quadratic Bézier curve from the current point to (x,y) using (x1,y1) as the control point. In relative coordinates.

See https://www.w3.org/TR/SVG/paths.html#PathDataQuadraticBezierCommands

Args
x1
x-coordinate of first control point
y1
y-coordinate of first control point
x
x-coordinate
y
y-coordinate
Returns

The current Path instance.

s

def s(self, x2: float, y2: float, x: float, y: float) ‑> Path

Draws a cubic Bézier curve from the current point to (x,y). The first control point is assumed to be the reflection of the second control point on the previous command relative to the current point. (x2,y2) is the second control point (i.e., the control point at the end of the curve). In relative coordinates.

See https://www.w3.org/TR/SVG/paths.html#PathDataCubicBezierCommands

Args
x2
x-coordinate of second control point
y2
y-coordinate of second control point
x
x-coordinate
y
y-coordinate
Returns

The current Path instance.

t

def t(self, x: float, y: float) ‑> Path

Draws a quadratic Bézier curve from the current point to (x,y). The control point is assumed to be the reflection of the control point on the previous command relative to the current point. In relative coordinates.

See https://www.w3.org/TR/SVG/paths.html#PathDataQuadraticBezierCommands

Args
x
x-coordinate
y
y-coordinate
Returns

The current Path instance.

v

def v(self, y: float) ‑> Path

Draws a vertical line from the current point. In relative coordinates.

See https://www.w3.org/TR/SVG/paths.html#PathDataLinetoCommands

Args
y
y-coordinate
Returns

The current Path instance.

z

def z(self) ‑> Path

Close the current subpath by connecting it back to the current subpath's initial point.

See https://www.w3.org/TR/SVG/paths.html#PathDataClosePathCommand

Returns

The current Path instance.

Turtle

class Turtle(x=0.0, y=0.0, degrees=0.0)

A Logo-like Turtle implementation for generating SVG paths. This is not a complete Turtle implementation. Contains a useful subset relevant to generating paths without using trigonometry or mental gymnastics.

Create a Turtle.

Args
x
initial position x
y
initial position y
degrees
initial angle in degrees

Methods

a

def a(self, degrees: float = 0) ‑> Turtle

Set the turtle's orientation.

Args
degrees
angle in degrees
Returns

The current turtle instance.

b

def b(self, distance: float) ‑> Turtle

Move backward.

Args
distance
Distance to move by.
Returns

The current turtle instance.

d

def d(self) ‑> str

Serialize this turtle's movements into SVG path data.

Returns

The d attribute for a SVG path.

f

def f(self, distance: float) ‑> Turtle

Move forward.

Args
distance
Distance to move by.
Returns

The current turtle instance.

l

def l(self, degrees: float) ‑> Turtle

Turn left.

Args
degrees
Angle in degrees.
Returns

The current turtle instance.

p

def p(self, x: float = 0.0, y: float = 0.0) ‑> Turtle

Set the turtle's position.

Args
x
x-coordinate
y
y-coordinate
Returns

The current turtle instance.

path

def path(self, **kwargs) ‑> Expando

Create a SVG path element that represents this turtle's movements.

Args
kwargs
Additional attributes for the SVG path element.
Returns

A SVG path element.

pd

def pd(self) ‑> Turtle

Pen down.

Returns

The current turtle instance.

pu

def pu(self, close: bool) ‑> Turtle

Pen up.

Args
close
Whether to close the current subpath.
Returns

The current turtle instance.

r

def r(self, degrees: float) ‑> Turtle

Turn right.

Args
degrees
Angle in degrees.
Returns

The current turtle instance.