Loading graphapi.module +0 −207 Changes for graphapi.module: 0 added lines, 207 removed lines. Original line number Diff line number Diff line Loading @@ -35,189 +35,6 @@ function _graphapi_remove_views_defaults($values = array()) { return $result; } /** * Creates a new Graph structure. * * @return \Fhaculty\Graph\Graph */ function graphapi_new_graph() { return new Graph(); } /** * Adds a graph node to an existing graph array. * * @param \Fhaculty\Graph\Graph $graph * @param type $id * Id of the node to add. * @return \Fhaculty\Graph\Graph\Vertex */ function graphapi_add_node(Graph $graph, $id) { if (!$graph->hasVertex($id)) { $vertex = $graph->createVertex($id); graphapi_set_node_title($graph, $id, $id); return $vertex; } return $graph->getVertex($id); } /** * Merge a graph into the current one. * * @param \Fhaculty\Graph\Graph $graph * @param \Fhaculty\Graph\Graph $sub */ function graphapi_merge_graph(\Fhaculty\Graph\Graph $graph, \Fhaculty\Graph\Graph $sub) { // foreach ($sub as $id => $node) { // graphapi_add_node($graph, $id); // if (count($graph[$id]['data']) > 1) { // watchdog('graphapi', 'Adding data while already available', NULL, WATCHDOG_NOTICE); // } // $graph[$id]['data'] = $node['data']; // foreach ($node['edges'] as $to => $data) { // graphapi_set_link_data($graph, $id, $to, $data); // } // } } /** * A subgraph is simply a node with a special data value _subgraph. * * The _subgraph value contains an array of child node IDs. * The render engine decides what to do with it. * * @param \Fhaculty\Graph\Graph $graph * @param type $id * @param \Fhaculty\Graph\Graph $sub * @return type */ function graphapi_add_sub_graph(Graph $graph, $id, Graph $sub) { $vertex = graphapi_add_node($graph, $id); // TODO: make this work // graphapi_merge_graph($graph, $sub); // $graph[$id]['_subgraph'] = array_keys($sub); return $vertex; } /** * Calculate the tree of subgraphs. * @return array tree structure of sub graphs */ function graphapi_get_graph_tree() { // TODO: provide a result return array(); } /** * Adds data to a graph node. * * @param \Fhaculty\Graph\Graph $graph * @param type $id * @param array $data * * @return \Fhaculty\Graph\Graph\Vertex */ function graphapi_set_node_data(Graph $graph, $id, array $data) { $vertex = $graph->createVertex($id, TRUE); $current_data = $vertex->hasLayoutAttribute('data') ? $vertex->getLayoutAttribute('data') : array(); // Merge with current data. if (is_array($data)) { // Latest data is more important $data = $data + $current_data; } $vertex->setLayoutAttribute('data', $data); return $vertex; } /** * Sets the title of a graph node. * * @param \Fhaculty\Graph\Graph $graph * @param $id * Id of the node for which to set the title. * @param $title * Title string. * * @return \Fhaculty\Graph\Graph\Vertex */ function graphapi_set_node_title(Graph $graph, $id, $title) { $vertex = $graph->createVertex($id, TRUE); $vertex->setLayoutAttribute('title', $title); return $vertex; } /** * Sets the uri of a graph node, to which the graph will link. * * @param \Fhaculty\Graph\Graph $graph * @param $id * Id of the node for which to set the title. * @param $uri * URI used to create a link. * * @return \Fhaculty\Graph\Graph\Vertex */ function graphapi_set_node_uri(Graph $graph, $id, $uri) { $vertex = $graph->createVertex($id, TRUE); $vertex->setLayoutAttribute('uri', $uri); return $vertex; } /** * Sets the content of a graph node. * * @param \Fhaculty\Graph\Graph $graph * @param type $id * Id of the node for which to set the title. * @param $content * HTML string of body content. */ function graphapi_set_node_content(Graph $graph, $id, $content) { $vertex = $graph->createVertex($id, TRUE); $vertex->setLayoutAttribute('content', $content); } /** * Adds a directed edge to the graph. * * @param \Fhaculty\Graph\Graph $graph * @param $from_id * Id of the source graph node for the edge. * @param $to_id * Id of the target graph not for the edge. * @return EdgeDirected */ function graphapi_add_link(Graph $graph, $from_id, $to_id) { graphapi_add_node($graph, $from_id); graphapi_add_node($graph, $to_id); $to = $graph->getVertex($to_id); return $graph->getVertex($from_id)->createEdgeTo($to); } /** * Adds a title to an existing edge in the graph. * * @param \Fhaculty\Graph\Edge\Base $edge * @param $title * Title string. */ function graphapi_set_link_title(\Fhaculty\Graph\Edge\Base $edge, $title) { $edge->setLayoutAttribute('title', $title); } /** * Adds data to a graph link. * * @param \Fhaculty\Graph\Vertex $edge * @param array $data * Graph node data associative array, containing: * - 'title': title of the graph edge. */ function graphapi_set_link_data(\Fhaculty\Graph\Edge\Base $edge, array $data) { $edge->setLayoutAttribute('data', $data); } /** * Returns default graph settings. */ Loading Loading @@ -370,30 +187,6 @@ function _graphapi_uniform_id($config, $id) { return $config['id'] . '-' . md5($id); } /** * Reverses all edges on a graph. * * @param $graph * Graph array. * @param $keep_link_data * boolean: whether to keep the old link data (not yet implemented). * * @return * $graph array with edges in opposite direction to original. */ function graphapi_reverse($graph, $keep_link_data = FALSE) { $result = $graph; foreach ($result as $key => $value) { $result[$key]['edges'] = array(); } foreach ($graph as $key => $value) { foreach ($graph[$key]['edges'] as $link => $link_data) { $result[$link]['edges'][$key] = 1; } } return $result; } function graphapi_views_api() { return array( 'api' => 3.0, Loading Loading
graphapi.module +0 −207 Changes for graphapi.module: 0 added lines, 207 removed lines. Original line number Diff line number Diff line Loading @@ -35,189 +35,6 @@ function _graphapi_remove_views_defaults($values = array()) { return $result; } /** * Creates a new Graph structure. * * @return \Fhaculty\Graph\Graph */ function graphapi_new_graph() { return new Graph(); } /** * Adds a graph node to an existing graph array. * * @param \Fhaculty\Graph\Graph $graph * @param type $id * Id of the node to add. * @return \Fhaculty\Graph\Graph\Vertex */ function graphapi_add_node(Graph $graph, $id) { if (!$graph->hasVertex($id)) { $vertex = $graph->createVertex($id); graphapi_set_node_title($graph, $id, $id); return $vertex; } return $graph->getVertex($id); } /** * Merge a graph into the current one. * * @param \Fhaculty\Graph\Graph $graph * @param \Fhaculty\Graph\Graph $sub */ function graphapi_merge_graph(\Fhaculty\Graph\Graph $graph, \Fhaculty\Graph\Graph $sub) { // foreach ($sub as $id => $node) { // graphapi_add_node($graph, $id); // if (count($graph[$id]['data']) > 1) { // watchdog('graphapi', 'Adding data while already available', NULL, WATCHDOG_NOTICE); // } // $graph[$id]['data'] = $node['data']; // foreach ($node['edges'] as $to => $data) { // graphapi_set_link_data($graph, $id, $to, $data); // } // } } /** * A subgraph is simply a node with a special data value _subgraph. * * The _subgraph value contains an array of child node IDs. * The render engine decides what to do with it. * * @param \Fhaculty\Graph\Graph $graph * @param type $id * @param \Fhaculty\Graph\Graph $sub * @return type */ function graphapi_add_sub_graph(Graph $graph, $id, Graph $sub) { $vertex = graphapi_add_node($graph, $id); // TODO: make this work // graphapi_merge_graph($graph, $sub); // $graph[$id]['_subgraph'] = array_keys($sub); return $vertex; } /** * Calculate the tree of subgraphs. * @return array tree structure of sub graphs */ function graphapi_get_graph_tree() { // TODO: provide a result return array(); } /** * Adds data to a graph node. * * @param \Fhaculty\Graph\Graph $graph * @param type $id * @param array $data * * @return \Fhaculty\Graph\Graph\Vertex */ function graphapi_set_node_data(Graph $graph, $id, array $data) { $vertex = $graph->createVertex($id, TRUE); $current_data = $vertex->hasLayoutAttribute('data') ? $vertex->getLayoutAttribute('data') : array(); // Merge with current data. if (is_array($data)) { // Latest data is more important $data = $data + $current_data; } $vertex->setLayoutAttribute('data', $data); return $vertex; } /** * Sets the title of a graph node. * * @param \Fhaculty\Graph\Graph $graph * @param $id * Id of the node for which to set the title. * @param $title * Title string. * * @return \Fhaculty\Graph\Graph\Vertex */ function graphapi_set_node_title(Graph $graph, $id, $title) { $vertex = $graph->createVertex($id, TRUE); $vertex->setLayoutAttribute('title', $title); return $vertex; } /** * Sets the uri of a graph node, to which the graph will link. * * @param \Fhaculty\Graph\Graph $graph * @param $id * Id of the node for which to set the title. * @param $uri * URI used to create a link. * * @return \Fhaculty\Graph\Graph\Vertex */ function graphapi_set_node_uri(Graph $graph, $id, $uri) { $vertex = $graph->createVertex($id, TRUE); $vertex->setLayoutAttribute('uri', $uri); return $vertex; } /** * Sets the content of a graph node. * * @param \Fhaculty\Graph\Graph $graph * @param type $id * Id of the node for which to set the title. * @param $content * HTML string of body content. */ function graphapi_set_node_content(Graph $graph, $id, $content) { $vertex = $graph->createVertex($id, TRUE); $vertex->setLayoutAttribute('content', $content); } /** * Adds a directed edge to the graph. * * @param \Fhaculty\Graph\Graph $graph * @param $from_id * Id of the source graph node for the edge. * @param $to_id * Id of the target graph not for the edge. * @return EdgeDirected */ function graphapi_add_link(Graph $graph, $from_id, $to_id) { graphapi_add_node($graph, $from_id); graphapi_add_node($graph, $to_id); $to = $graph->getVertex($to_id); return $graph->getVertex($from_id)->createEdgeTo($to); } /** * Adds a title to an existing edge in the graph. * * @param \Fhaculty\Graph\Edge\Base $edge * @param $title * Title string. */ function graphapi_set_link_title(\Fhaculty\Graph\Edge\Base $edge, $title) { $edge->setLayoutAttribute('title', $title); } /** * Adds data to a graph link. * * @param \Fhaculty\Graph\Vertex $edge * @param array $data * Graph node data associative array, containing: * - 'title': title of the graph edge. */ function graphapi_set_link_data(\Fhaculty\Graph\Edge\Base $edge, array $data) { $edge->setLayoutAttribute('data', $data); } /** * Returns default graph settings. */ Loading Loading @@ -370,30 +187,6 @@ function _graphapi_uniform_id($config, $id) { return $config['id'] . '-' . md5($id); } /** * Reverses all edges on a graph. * * @param $graph * Graph array. * @param $keep_link_data * boolean: whether to keep the old link data (not yet implemented). * * @return * $graph array with edges in opposite direction to original. */ function graphapi_reverse($graph, $keep_link_data = FALSE) { $result = $graph; foreach ($result as $key => $value) { $result[$key]['edges'] = array(); } foreach ($graph as $key => $value) { foreach ($graph[$key]['edges'] as $link => $link_data) { $result[$link]['edges'][$key] = 1; } } return $result; } function graphapi_views_api() { return array( 'api' => 3.0, Loading