objective-c – Cocoa的图形库

前端之家收集整理的这篇文章主要介绍了objective-c – Cocoa的图形库前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
某些图形应用程序有什么好的库吗?我想创建节点,添加加权边等…

编辑

我需要一个图表(如下图所示)而不是图表.

解决方法

根据 GraphViz documentation这样的事情应该做布局工作:
- (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];
    }
}

而不是使用logNode:你应该写一些绘图代码.

日志输出

GraphTest[32319:303] Node: a0 {{0.000000,0.000000},{0.000000,0.000000}}
GraphTest[32319:303] Node: a1 {{0.000000,0.000000}}
GraphTest[32319:303] Node: a2 {{0.000000,0.000000}}
GraphTest[32319:303] Node: a3 {{0.000000,0.000000}}
GraphTest[32319:303] Node: b0 {{0.000000,0.000000}}
GraphTest[32319:303] Node: b1 {{0.000000,0.000000}}
GraphTest[32319:303] Node: b2 {{0.000000,0.000000}}
GraphTest[32319:303] Node: b3 {{0.000000,0.000000}}
GraphTest[32319:303] Node: x {{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.500000}}
GraphTest[32319:303] Node: a2 {{43.000000,106.000000},0.500000}}
GraphTest[32319:303] Node: a3 {{83.000000,34.000000},0.500000}}
GraphTest[32319:303] Node: b0 {{161.000000,0.500000}}
GraphTest[32319:303] Node: b1 {{161.000000,0.500000}}
GraphTest[32319:303] Node: b2 {{161.000000,0.500000}}
GraphTest[32319:303] Node: b3 {{161.000000,0.500000}}
GraphTest[32319:303] Node: x {{122.000000,322.000000},0.500000}}

猜你在找的C&C++相关文章