Skip to content

Commit 97fe729

Browse files
committed
Add line_width parameter
1 parent 57ff737 commit 97fe729

File tree

2 files changed

+76
-1
lines changed

2 files changed

+76
-1
lines changed

examples/lines.ipynb

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"from ipycanvas import Canvas"
10+
]
11+
},
12+
{
13+
"cell_type": "markdown",
14+
"metadata": {},
15+
"source": [
16+
"# Line width"
17+
]
18+
},
19+
{
20+
"cell_type": "code",
21+
"execution_count": null,
22+
"metadata": {},
23+
"outputs": [],
24+
"source": [
25+
"size = (200, 140)\n",
26+
"\n",
27+
"canvas = Canvas(size=size)\n",
28+
"for i in range(10):\n",
29+
" width = 1 + i\n",
30+
" x = 5 + i * 20\n",
31+
" canvas.line_width = width\n",
32+
"\n",
33+
" canvas.fill_text(str(width), x - 5, 15)\n",
34+
"\n",
35+
" canvas.begin_path()\n",
36+
" canvas.move_to(x, 20)\n",
37+
" canvas.line_to(x, 140)\n",
38+
" canvas.stroke()\n",
39+
"canvas"
40+
]
41+
},
42+
{
43+
"cell_type": "code",
44+
"execution_count": null,
45+
"metadata": {},
46+
"outputs": [],
47+
"source": []
48+
}
49+
],
50+
"metadata": {
51+
"kernelspec": {
52+
"display_name": "Python 3",
53+
"language": "python",
54+
"name": "python3"
55+
},
56+
"language_info": {
57+
"codemirror_mode": {
58+
"name": "ipython",
59+
"version": 3
60+
},
61+
"file_extension": ".py",
62+
"mimetype": "text/x-python",
63+
"name": "python",
64+
"nbconvert_exporter": "python",
65+
"pygments_lexer": "ipython3",
66+
"version": "3.7.3"
67+
}
68+
},
69+
"nbformat": 4,
70+
"nbformat_minor": 4
71+
}

ipycanvas/canvas.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ class Canvas(DOMWidget):
7474
default_value='source-over'
7575
)
7676

77+
#: (float) Sets the width of lines drawn in the future, must be a positive number. Default to ``1.0``.
78+
line_width = Float(1.0)
79+
7780
def __init__(self, *args, **kwargs):
7881
"""Create a Canvas widget."""
7982
#: Whether commands should be cached or not
@@ -268,7 +271,8 @@ def flush(self):
268271
self._buffers_cache = []
269272

270273
@observe('fill_style', 'stroke_style', 'global_alpha', 'font', 'text_align',
271-
'text_baseline', 'direction', 'global_composite_operation')
274+
'text_baseline', 'direction', 'global_composite_operation',
275+
'line_width')
272276
def _on_set_attr(self, change):
273277
command = {
274278
'name': 'set',

0 commit comments

Comments
 (0)