Cocoa图形库 [英] Graph library for Cocoa
本文介绍了Cocoa图形库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有一些图形应用程序有好的库吗?我想要创建节点,添加加权边等...
EDIT
libguide.pdf> GraphViz文档这样应该做布局工作:
- (void)testGraph {
Agraph_t * G;
GVC_t * gvc;
gvc = gvContext();
char * testGraph =\
digraph G {\
subgraph cluster_c0 {a0 - > a1 - > a2 - > a3;} \
subgraph cluster_c1 {b0 - > b1 - > b2 - > b3;} \
x - > a0; \
x - > b0; \
a1 - > a3; \
a3 - > a0; \
};
G = agmemread((char *)testGraph);
[self dumpGraph:G];
gvLayout(gvc,G,dot);
NSLog(@after layout:);
[self dumpGraph:G];
gvFreeLayout(gvc,G);
gvFreeContext(gvc);
}
- (void)printNode:(Agnode_t *)node {
NSLog(@Node:%s {{%f,%f} {%f,%f}},node-> name,
node-> u.coord.x,
node-> u.coord.y,
ND_width节点),
ND_height(node));
}
- (void)dumpGraph:(Agraph_t *)graph {
if(!graph)
return;
Agnode_t * n = NULL;
Dict_t * dict = graph-> nodes;
for(n = dtfirst(dict); n; n = dtnext(dict,n)){
[self printNode:n]
}
}
而不是使用logNode: 。
日志输出:
GraphTest [32319:303] :a0 {{0.000000,0.000000},{0.000000,0.000000}}
GraphTest [32319:303]节点:a1 {{0.000000,0.000000},{0.000000,0.000000}}
GraphTest [32319:303 ] Node:a2 {{0.000000,0.000000},{0.000000,0.000000}}
GraphTest [32319:303]节点:a3 {{0.000000,0.000000},{0.000000,0.000000}}
GraphTest [32319 :303}节点:b0 {{0.000000,0.000000},{0.000000,0.000000}}
GraphTest [32319:303] [32319:303]节点:b2 {{0.000000,0.000000},{0.000000,0.000000}}
GraphTest [32319:303]节点:b3 {{0.000000,0.000000},{0.000000,0.000000}}
GraphTest [32319:303]节点:x {{0.000000,0.000000},{0.000000,0.000000}}
布局后的GraphTest [32319:303]节点:a0 { {83.000000,250.000000},{0.750000,0.500000}}
GraphTest [32319:303]节点:a1 {{63.000000,178.000000},{0.750000,0.500000}}
GraphTest [32319:303] a2 {{43.000000,106.000000},{0.750000,0.500000}}
GraphTest [32319:303]节点:a3 {{83.000000,34.000000},{0.750000,0.500000}}
GraphTest [32319:303]节点:b1 {{161.000000,178.000000},{0.750000,0.500000}}
GraphTest [32319:303]节点:b1 {{161.000000,250.000000},{0.750000,0.500000}}
GraphTest [节点:b2 {{161.000000,106.000000},{0.750000,0.500000}}
GraphTest [32319:303]节点:b3 {{161.000000,34.000000},{0.750000,0.500000}}
GraphTest [ 32319:303]节点:x {{122.000000,322.000000},{0.750000,0.500000}}
Is there any good library for some graph-app? I want to create nodes, add weighted edges, etc…
EDIT
I need a graph (like on the image below) not a plot.
解决方案
According to the GraphViz documentation something like this should do the layout job:
- (void) testGraph {
Agraph_t* G;
GVC_t* gvc;
gvc = gvContext();
char* testGraph = "\
digraph G {\
subgraph cluster_c0 {a0 -> a1 -> a2 -> a3;}\
subgraph cluster_c1 {b0 -> b1 -> b2 -> b3;}\
x -> a0;\
x -> b0;\
a1 -> a3;\
a3 -> a0;\
}";
G = agmemread((char*)testGraph);
[self dumpGraph:G];
gvLayout (gvc, G, "dot");
NSLog(@"after layout:");
[self dumpGraph:G];
gvFreeLayout(gvc, G);
gvFreeContext(gvc);
}
- (void) printNode:(Agnode_t*) node {
NSLog(@"Node: %s {{%f,%f},{%f,%f}}",node->name,
node->u.coord.x,
node->u.coord.y,
ND_width(node),
ND_height(node));
}
- (void) dumpGraph:(Agraph_t*)graph {
if (!graph)
return;
Agnode_t *n = NULL;
Dict_t *dict = graph->nodes;
for (n= dtfirst(dict); n ; n = dtnext(dict, n)) {
[self printNode:n];
}
}
Instead of using logNode: you should write some drawing code.
Log output:
GraphTest[32319:303] Node: a0 {{0.000000,0.000000},{0.000000,0.000000}}
GraphTest[32319:303] Node: a1 {{0.000000,0.000000},{0.000000,0.000000}}
GraphTest[32319:303] Node: a2 {{0.000000,0.000000},{0.000000,0.000000}}
GraphTest[32319:303] Node: a3 {{0.000000,0.000000},{0.000000,0.000000}}
GraphTest[32319:303] Node: b0 {{0.000000,0.000000},{0.000000,0.000000}}
GraphTest[32319:303] Node: b1 {{0.000000,0.000000},{0.000000,0.000000}}
GraphTest[32319:303] Node: b2 {{0.000000,0.000000},{0.000000,0.000000}}
GraphTest[32319:303] Node: b3 {{0.000000,0.000000},{0.000000,0.000000}}
GraphTest[32319:303] Node: x {{0.000000,0.000000},{0.000000,0.000000}}
GraphTest[32319:303] after layout:
GraphTest[32319:303] Node: a0 {{83.000000,250.000000},{0.750000,0.500000}}
GraphTest[32319:303] Node: a1 {{63.000000,178.000000},{0.750000,0.500000}}
GraphTest[32319:303] Node: a2 {{43.000000,106.000000},{0.750000,0.500000}}
GraphTest[32319:303] Node: a3 {{83.000000,34.000000},{0.750000,0.500000}}
GraphTest[32319:303] Node: b0 {{161.000000,250.000000},{0.750000,0.500000}}
GraphTest[32319:303] Node: b1 {{161.000000,178.000000},{0.750000,0.500000}}
GraphTest[32319:303] Node: b2 {{161.000000,106.000000},{0.750000,0.500000}}
GraphTest[32319:303] Node: b3 {{161.000000,34.000000},{0.750000,0.500000}}
GraphTest[32319:303] Node: x {{122.000000,322.000000},{0.750000,0.500000}}
这篇关于Cocoa图形库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文