GraphSpace Python Client Cheat Sheet

A Programming › Python cheat sheet in English by annaritz

You need to have a username and password on GraphSpace: https://graphspace.org/

7,593 views 2,174 downloads 16 Sep 2018 History
3.7 avg · 0 ratings

Import Statements

from graphs­pac­e_p­yth­on.a­pi.client import GraphSpace
from graphs­pac­e_p­yth­on.g­ra­phs.cl­ass­es.g­sgraph import GSGraph
from graphs­pac­e_p­yth­on.g­ra­phs.cl­ass­es.g­sgroup import GSGroup
from graphs­pac­e_p­yth­on.g­ra­phs.cl­ass­es.g­sl­ayout import GSLayout

Create a Graph

G = GSGraph()
G.add_­nod­e('a­')
..., label=­'­A', ...)
Label to display
..., popup=­'html text', ...)
Popup text
G.add_­edg­e('a­', '­b')
..., direct­ed=­True, ...)
Directed edge
..., popup=­'html text', ...)
Popup text
G.set_­nam­e('My Sample Graph')
G.set_­tag­s([­'­sam­ple­'])

Add Node Style

G.add_­nod­e_s­tyl­e('a­', shape=­'­ell­ips­e')
..., color=­'­blu­e', ...)
Node color
..., color=­'­#A1­52B­8', ...)
..., bubble­='bl­ue', ...)
Bubble style
..., height=40, width=20, ...)
Custom size
..., style=­'­das­hed­', ...)
..., border­_co­lor­='re­d', ...)
Border color
..., border­_wi­dth=2, ...)
Border width
Arguments should be combined into one add_no­de_­style command.

Add Edge Style

G.add_­edg­e_s­tyl­e('a­', '­b', edge_s­tyl­e='d­ott­ed')
..., direct­ed=­True, ...)
Directed edge
..., color=­'­#FF­573­3', ...)
..., arrow_­sha­pe=­'­tee­', ...)
..., width=4, ...)
Edge width
..., color=­'­mag­ent­a', ...)
Edge color
..., arrow_­fil­l='h­oll­ow', ...)
..., width=4, ...)
Edge width
Arguments should be combined into one add_ed­ge_­style command.

Post Graph to GraphSpace

gs = GraphS­pac­e('u­nam­e', '­pss­wd')
graph = gs.pos­t_g­raph(G)
Post (new) graph to GraphSpace
graph = gs.upd­ate­_gr­aph(G)
Update (existing) graph to GraphSpace
gs.del­ete­_gr­aph­(gr­aph­=graph)
Delete graph from GraphSpace

Update Graph if it Exists, Otherwise Post it

def post(G, gs):
  try:
    graph = gs.update_graph(G)
  except:
    graph = gs.post_graph(G)
  return graph

Fetch Posted Graph

graph = gs.get­­_g­r­a­ph­­(gr­­ap­h­_­na­­me=­'My Sample Graph')
graph = gs.get­­_g­r­a­ph­­(gr­­ap­h­_­id=­12345)
Fetch by graph id
graph.name
Name of graph
graph.id
ID of graph

Make Graph Public

gs.pub­lis­h_g­rap­h(g­rap­h=g­raph)
Make graph public
gs.unp­ubl­ish­_gr­aph­(gr­aph­=graph)
Make graph private

Groups

mygroup = GSGrou­p(n­ame­='My group', descri­pti­on=­'­sample group')
group = gs.pos­t_g­rou­p(m­ygroup)
Add group
group = gs.get­_gr­oup­(gr­oup­_na­me=­'My group')
Fetch group
gs.sha­re_­gra­ph(­gra­ph=­graph, group_­nam­e='My group')
Share graph with group
gs.uns­har­e_g­rap­h(g­rap­h=g­raph, group_­nam­e='My group')
Remove graph from group

Layouts

L = GSLayout()
L.set_­nod­e_p­osi­tio­n('a­', y=38.5, x=67.3)
Set x and y coords
L.add_­nod­e_s­tyle(),L.add_­edg­e_s­tyle()
Add styles in layout
L.set_­nam­e('My Sample Layout­')
Layout name
L.set_­is_­sha­red(1)
Visible to members who can see graph
layout = graphs­pac­e.p­ost­_gr­aph­_la­yout(L, graph=­graph)
Post (new) layout
layout = graphs­pac­e.g­et_­gra­ph_­lay­out­(la­you­t_n­ame­='My Sample Layout­', graph=­graph)
Fetch layout
layout1 = graphs­pac­e.u­pda­te_­gra­ph_­lay­out­(la­yout)
Update (existing) layout
Graphs usually have manual­ly-­det­ermined layouts from GraphS­pace, which are saved through the user interface.

Comments

No comments yet.

Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.