License New BSD license
Lines 68
Keywords
dumbell (1) Nodebox (14) primitive (1)
Included in this Library
Permissions
Owner: Theodore Test
Viewable by Everyone
Editable by All Siafoo Users
Hide
Easily highlight source code for your blog with our Syntax Highlighter. Join Siafoo Now or Learn More

Dumbell Nodes Primitive Atom Feed 0

In Brief A straightforward primitive that draws a rectangular header full of text and a connected series of descending circular nodes containing other string data. Auto-adjusts text position to be centered. Number of circular nodes scales to match the size of your sequence of data strings.... more
# 's
 1colors = ximport('colors')
2size(600,600)
3
4def dumbell_nodes(arg_x,arg_y,node_size,arg_text='',arg_data_sequence=('',),\
5 draw_it=True,text_fill=color(0),shapes_fill=color(0.5)):
6
7 # Header Text
8 align(CENTER)
9 t = textpath(arg_text,arg_x,arg_y,width=node_size)
10 tx,ty = t.bounds.origin.x,t.bounds.origin.y
11 tw,th = t.bounds.size.width,t.bounds.size.height
12 all_text = t.copy()
13
14 r = rect(tx-tw*.1,ty-th*.1,tw*1.2,th*1.2,draw=False)
15 all_shapes = r.copy()
16
17
18 for ind,data_chunk in enumerate(arg_data_sequence):
19 tween_space = node_size*.1
20 y_base = arg_y + th + tween_space + ind*(node_size+tween_space)
21
22
23 # Node Data Text
24 nt_th = textheight(data_chunk,width=node_size*.8)
25 nt_tw = textwidth(data_chunk,width=WIDTH)
26 t_y_shift = y_base+0.5*node_size+0.25*nt_th
27
28 if nt_th > node_size*0.5 or nt_tw > node_size*.8:
29 t_y_shift = y_base+0.5*node_size - 0.25*nt_th
30
31 nt = textpath(data_chunk,arg_x+0.1*node_size,t_y_shift,width=node_size*.8)
32 all_text = all_text.union(nt,flatness=0.1)
33
34
35 # Node Shapes
36 o = oval(arg_x,y_base,node_size,node_size,draw=False)
37
38 l_width = min(max(tw*.15,1),node_size*.2)
39 l_height = tween_space*-1.1
40 if ind == 0:
41 l_height -= th
42 l_height = max(l_height,-1*(tween_space+th))
43 l = rect(arg_x+0.5*node_size-0.5*l_width,y_base+tween_space*0.05,l_width,l_height,draw=False)
44
45 all_shapes = all_shapes.union(l,flatness=0.1)
46 all_shapes = all_shapes.union(o,flatness=0.1)
47
48 all_shapes.fill = shapes_fill
49 all_text.fill = text_fill
50
51 if draw_it:
52 fill(shapes_fill)
53 drawpath(all_shapes)
54
55 fill(text_fill)
56 drawpath(all_text)
57
58 return all_shapes,all_text
59
60
61#Example Code
62
63background(.95)
64fontsize(12)
65stroke(0)
66strokewidth(1)
67colormode(HSB)
68dumbell_nodes(56,50,106,'An Example Dumbell Object',arg_data_sequence = ('Data Chunk Number 1','The second circle-node','3.14159'))
69sf = fill(0.6,0.5,0.99)
70tf = fill(0.95)
71dumbell_nodes(235,50,46,'Small',arg_data_sequence = ('A','B','C','D','E','F','G','H','Wee'),shapes_fill=sf,text_fill=tf)
72fontsize(50)
73
74sf = fill(0.4,0.9,0.5)
75tf = fill(0.95)
76strokewidth(0)
77dumbell_nodes(310,130,200,'Short',arg_data_sequence = ('and Sweet',),text_fill=tf,shapes_fill=sf)

A straightforward primitive that draws a rectangular header full of text and a connected series of descending circular nodes containing other string data. Auto-adjusts text position to be centered. Number of circular nodes scales to match the size of your sequence of data strings.

http://www.siafoo.net/image/100