Chart Library for Cocoa

Is there a good library for some kind of graphical application? I want to create nodes, add weighted edges, etc.

EDIT

I need a graph (for example, in the image below), not a graph.

enter image description here

+6
source share
3 answers

According to 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 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}} 
+7
source

This is not super Cocoa -friedly, but Graphviz can either do a lot of what you need, or provide a good foundation for your own efforts. (That is, the graphviz library can handle all the graph layout logic and tell you where to put the shapes that you then draw using your favorite graphical API. For example, this is how OmniGraffle's automatic layout function works.)

+4
source

If you can limit yourself to Mountain Lion and above, SceneKit seems like a promising place to start. You will need to control the geometry of the layout yourself (the actual positions of the nodes / edges), but you will get free testing and geometric primitives. Properties and textures are animated: you can enlarge the node, darken the edge, change the number or color, all with your favorite Core Animation-style calls.

0
source

Source: https://habr.com/ru/post/910069/


All Articles