Skip to content

Commit a7d97e8

Browse files
committed
Improve documentation
1 parent 6cb8f1a commit a7d97e8

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

ipycanvas/canvas.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class Canvas(DOMWidget):
2525
2626
Args:
2727
size (tuple): The size (in pixels) of the canvas
28+
caching (boolean): Whether commands should be cached or not
2829
"""
2930

3031
_model_name = Unicode('CanvasModel').tag(sync=True)
@@ -75,6 +76,7 @@ class Canvas(DOMWidget):
7576

7677
def __init__(self, *args, **kwargs):
7778
"""Create a Canvas widget."""
79+
#: Whether commands should be cached or not
7880
self.caching = kwargs.get('caching', False)
7981
self._commands_cache = []
8082
self._buffers_cache = []
@@ -179,9 +181,9 @@ def stroke_text(self, text, x, y, max_width=None):
179181
def put_image_data(self, image_data, dx, dy):
180182
"""Draw an image on the Canvas.
181183
182-
`image_data` being a NumPy array defining the image to draw and `x` and `y` the pixel position where to draw.
183-
Unlike the CanvasRenderingContext2D.putImageData method, this method **is** affected by the canvas transformation matrix,
184-
and supports transparency.
184+
``image_data`` should be a NumPy array containing the image to draw and ``dx`` and ``dy`` the pixel position where to
185+
draw. Unlike the CanvasRenderingContext2D.putImageData method, this method **is** affected by the canvas transformation
186+
matrix, and supports transparency.
185187
"""
186188
shape, image_buffer = array_to_binary(image_data)
187189
self._send_canvas_command('putImageData', ({'shape': shape}, dx, dy), (image_buffer, ))
@@ -207,18 +209,19 @@ def restore(self):
207209
def translate(self, x, y):
208210
"""Move the canvas and its origin on the grid.
209211
210-
x indicates the horizontal distance to move,
211-
and y indicates how far to move the grid vertically.
212+
``x`` indicates the horizontal distance to move,
213+
and ``y`` indicates how far to move the grid vertically.
212214
"""
213215
self._send_canvas_command('translate', (x, y))
214216

215217
def rotate(self, angle):
216-
"""Rotate the canvas clockwise around the current origin by the angle number of radians."""
218+
"""Rotate the canvas clockwise around the current origin by the ``angle`` number of radians."""
217219
self._send_canvas_command('rotate', (angle, ))
218220

219221
def scale(self, x, y=None):
220-
"""Scale the canvas units by x horizontally and by y vertically. Both parameters are real numbers.
222+
"""Scale the canvas units by ``x`` horizontally and by ``y`` vertically. Both parameters are real numbers.
221223
224+
If ``y`` is not provided, it is defaulted to the same value as ``x``.
222225
Values that are smaller than 1.0 reduce the unit size and values above 1.0 increase the unit size.
223226
Values of 1.0 leave the units the same size.
224227
"""
@@ -229,7 +232,8 @@ def scale(self, x, y=None):
229232
def transform(self, a, b, c, d, e, f):
230233
"""Multiply the current transformation matrix with the matrix described by its arguments.
231234
232-
The transformation matrix is described by [[a, c, e], [b, d, f], [0, 0, 1]].
235+
The transformation matrix is described by:
236+
``[[a, c, e], [b, d, f], [0, 0, 1]]``.
233237
"""
234238
self._send_canvas_command('transform', (a, b, c, d, e, f))
235239

@@ -249,11 +253,11 @@ def reset_transform(self):
249253

250254
# Extras
251255
def clear(self):
252-
"""Clear the entire canvas."""
256+
"""Clear the entire canvas. This is the same as calling ``clear_rect(0, 0, canvas.size[0], canvas.size[1])``."""
253257
self._send_command({'name': 'clear'})
254258

255259
def flush(self):
256-
"""Flush all the cached commands."""
260+
"""Flush all the cached commands and clear the cache."""
257261
if not self.caching:
258262
return
259263

0 commit comments

Comments
 (0)