本文整理汇总了Java中prefuse.data.Graph.addEdge方法的典型用法代码示例。如果您正苦于以下问题:Java Graph.addEdge方法的具体用法?Java Graph.addEdge怎么用?Java Graph.addEdge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类prefuse.data.Graph
的用法示例。
在下文中一共展示了Graph.addEdge方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initDataGroups
import prefuse.data.Graph; //导入方法依赖的package包/类
private void initDataGroups() {
// create sample graph
g = new Graph(true);
for (int i = 0; i < 3; ++i) {
Node n1 = g.addNode();
Node n2 = g.addNode();
Node n3 = g.addNode();
g.addEdge(n1, n2);
g.addEdge(n1, n3);
// g.addEdge(n2, n3);
}
g.addEdge(0, 3);
// g.addEdge(3, 6);
g.addEdge(6, 0);
// add labels for nodes and edges
g.addColumn(VisualItem.LABEL, String.class);
for (int i = 0; i < 9; i++) {
g.getNode(i).setString(VisualItem.LABEL, "Node " + i);
}
}
示例2: getClique
import prefuse.data.Graph; //导入方法依赖的package包/类
/**
* Returns a clique of given size. A clique is a graph in which every node
* is a neighbor of every other node.
* @param n the number of nodes in the graph
* @return a clique of size n
*/
public static Graph getClique(int n) {
Graph g = new Graph();
g.getNodeTable().addColumns(LABEL_SCHEMA);
Node nodes[] = new Node[n];
for ( int i = 0; i < n; ++i ) {
nodes[i] = g.addNode();
nodes[i].setString(LABEL, String.valueOf(i));
}
for ( int i = 0; i < n; ++i ) {
for ( int j = i; j < n; ++j )
if ( i != j )
g.addEdge(nodes[i], nodes[j]);
}
return g;
}
示例3: getGrid
import prefuse.data.Graph; //导入方法依赖的package包/类
/**
* Returns a graph structured as an m-by-n grid.
* @param m the number of rows of the grid
* @param n the number of columns of the grid
* @return an m-by-n grid structured graph
*/
public static Graph getGrid(int m, int n) {
Graph g = new Graph();
g.getNodeTable().addColumns(LABEL_SCHEMA);
Node[] nodes = new Node[m*n];
for ( int i = 0; i < m*n; ++i ) {
nodes[i] = g.addNode();
nodes[i].setString(LABEL, String.valueOf(i));
if ( i >= n )
g.addEdge(nodes[i-n], nodes[i]);
if ( i % n != 0 )
g.addEdge(nodes[i-1], nodes[i]);
}
return g;
}
示例4: initDataGroups
import prefuse.data.Graph; //导入方法依赖的package包/类
private void initDataGroups() {
// create sample graph
// 9 nodes broken up into 3 interconnected cliques
Graph g = new Graph();
for ( int i=0; i<3; ++i ) {
Node n1 = g.addNode();
Node n2 = g.addNode();
Node n3 = g.addNode();
g.addEdge(n1, n2);
g.addEdge(n1, n3);
g.addEdge(n2, n3);
}
g.addEdge(0, 3);
g.addEdge(3, 6);
g.addEdge(6, 0);
// add visual data groups
VisualGraph vg = m_vis.addGraph(GRAPH, g);
m_vis.setInteractive(EDGES, null, false);
m_vis.setValue(NODES, null, VisualItem.SHAPE,
new Integer(Constants.SHAPE_ELLIPSE));
AggregateTable at = m_vis.addAggregates(AGGR);
at.addColumn(VisualItem.POLYGON, float[].class);
at.addColumn("id", int.class);
// add nodes to aggregates
// create an aggregate for each 3-clique of nodes
Iterator nodes = vg.nodes();
for ( int i=0; i<3; ++i ) {
AggregateItem aitem = (AggregateItem)at.addItem();
aitem.setInt("id", i);
for ( int j=0; j<3; ++j ) {
aitem.addItem((VisualItem)nodes.next());
}
}
}
示例5: initDataGroups
import prefuse.data.Graph; //导入方法依赖的package包/类
private void initDataGroups() {
// create sample graph
// 9 nodes broken up into 3 interconnected cliques
Graph g = new Graph();
for ( int i=0; i<3; ++i ) {
Node n1 = g.addNode();
Node n2 = g.addNode();
Node n3 = g.addNode();
g.addEdge(n1, n2);
g.addEdge(n1, n3);
g.addEdge(n2, n3);
}
g.addEdge(0, 3);
g.addEdge(3, 6);
g.addEdge(6, 0);
// add visual data groups
VisualGraph vg = m_vis.addGraph(GRAPH, g);
m_vis.setInteractive(EDGES, null, false);
m_vis.setValue(NODES, null, VisualItem.SHAPE,
new Integer(Constants.SHAPE_ELLIPSE));
AggregateTable at = m_vis.addAggregates(AGGR);
at.addColumn(VisualItem.POLYGON, float[].class);
at.addColumn("id", int.class);
// add nodes to aggregates
// create an aggregate for each 3-clique of nodes
Iterator<?> nodes = vg.nodes();
for ( int i=0; i<3; ++i ) {
AggregateItem aitem = (AggregateItem)at.addItem();
aitem.setInt("id", i);
for ( int j=0; j<3; ++j ) {
aitem.addItem((VisualItem)nodes.next());
}
}
}
示例6: initDataGroups
import prefuse.data.Graph; //导入方法依赖的package包/类
private void initDataGroups() {
// create sample graph
// 9 nodes broken up into 3 interconnected cliques
Graph g = new Graph();
for ( int i=0; i<3; ++i ) {
Node n1 = g.addNode();
Node n2 = g.addNode();
Node n3 = g.addNode();
g.addEdge(n1, n2);
g.addEdge(n1, n3);
g.addEdge(n2, n3);
}
g.addEdge(0, 3);
g.addEdge(3, 6);
g.addEdge(6, 0);
// add labels for nodes and edges
g.addColumn(VisualItem.LABEL, String.class);
for (int i = 0; i < 9; i++) {
g.getNode(i).setString(VisualItem.LABEL, ""+i);
g.getEdge(i).setString(VisualItem.LABEL, ""+i);
}
// add visual data groups
VisualGraph vg = m_vis.addGraph(GRAPH, g);
m_vis.setInteractive(EDGES, null, false);
m_vis.setValue(NODES, null, VisualItem.SHAPE,
new Integer(Constants.SHAPE_ELLIPSE));
AggregateTable at = m_vis.addAggregates(AGGR);
at.addColumn(VisualItem.POLYGON, float[].class);
at.addColumn("id", int.class);
// add nodes to aggregates
// create an aggregate for each 3-clique of nodes
Iterator nodes = vg.nodes();
for ( int i=0; i<3; ++i ) {
AggregateItem aitem = (AggregateItem)at.addItem();
aitem.setInt("id", i);
for ( int j=0; j<3; ++j ) {
aitem.addItem((VisualItem)nodes.next());
}
}
}
示例7: getStar
import prefuse.data.Graph; //导入方法依赖的package包/类
/**
* Builds a "star" graph with one central hub connected to the given
* number of satellite nodes.
* @param n the number of points of the star
* @return a "star" graph with n points, for a total of n+1 nodes
*/
public static Graph getStar(int n) {
Graph g = new Graph();
g.getNodeTable().addColumns(LABEL_SCHEMA);
Node r = g.addNode();
r.setString(LABEL, "0");
for ( int i=1; i <= n; ++i ) {
Node nn = g.addNode();
nn.setString(LABEL, String.valueOf(i));
g.addEdge(r, nn);
}
return g;
}
示例8: getHoneycomb
import prefuse.data.Graph; //导入方法依赖的package包/类
public static Graph getHoneycomb(int levels) {
Graph g = new Graph();
g.getNodeTable().addColumns(LABEL_SCHEMA);
ArrayList<Node> layer1 = halfcomb(g, levels);
ArrayList<Node> layer2 = halfcomb(g, levels);
for ( int i=0; i<(levels<<1); ++i ) {
Node n1 = layer1.get(i);
Node n2 = layer2.get(i);
g.addEdge(n1, n2);
}
return g;
}
示例9: addEdges
import prefuse.data.Graph; //导入方法依赖的package包/类
/**
* Adds edges for all associations of a table.
*
* @param table the table
* @param toRender is not null, the only association to make visible
*
* @return list of newly rendered tables
*/
private List<Table> addEdges(Graph g, Table table, Association toRender, List<Table> toCheck, boolean visibleDestinationRequired) {
List<Table> result = new ArrayList<Table>();
toCheck.add(table);
for (Association a: table.associations) {
if (toRender != null && toRender != a) {
continue;
}
if (!isVisualizable(a) && (toRender == null || a != toRender)) {
continue;
}
if (visibleDestinationRequired && !tableNodes.containsKey(a.destination)) {
continue;
}
if (!renderedAssociations.containsKey(a) && !renderedAssociations.containsKey(a.reversalAssociation)) {
toCheck.add(a.destination);
toCheck.add(a.source);
if (showTable(g, a.source)) {
result.add(a.source);
}
if (showTable(g, a.destination)) {
result.add(a.destination);
}
String tooltip = a.getJoinCondition();
if (!associationIsUnique(a)) {
Node an = g.addNode();
an.set("association", a);
an.setString("label", a.getName() + "#");
an.setString("tooltip", tooltip);
renderedAssociationsAsNode.put(a, an);
Edge ae = g.addEdge(an, tableNodes.get(a.source));
ae.set("association", a.reversalAssociation);
ae.set("full", Boolean.FALSE);
ae.setString("tooltip", tooltip);
renderedAssociations.put(a.reversalAssociation, ae);
Edge be = g.addEdge(an, tableNodes.get(a.destination));
be.set("association", a);
be.set("full", Boolean.FALSE);
be.setString("tooltip", tooltip);
renderedAssociations.put(a, be);
} else {
Edge e = g.addEdge(tableNodes.get(a.source), tableNodes.get(a.destination));
e.set("association", a);
e.set("full", Boolean.TRUE);
e.setString("tooltip", tooltip);
renderedAssociations.put(a, e);
}
}
}
return result;
}
示例10: create
import prefuse.data.Graph; //导入方法依赖的package包/类
/**
* adds random data (nodes & connections) to a given GraphDataModifier
*
* @param graph (PrefuseGraph)
* @return GraphDataModifier (PrefuseGraph) with random nodes and connections
*/
public Graph create(Graph graph) {
graph = GraphAddColumnDefinition.addColumnDefinition(graph);
Random rnd = new Random();
// GraphDataModifier random Nodes with random data
for (int i = 0; i <= COUNT_NODES; i++) {
Node n = graph.addNode();
// add random data (later use protege data)
n.set(ColumnNames.ID, rnd.nextInt(25000));
n.set(ColumnNames.NODE_HEIGHT, rnd.nextInt(35));
n.set(ColumnNames.NODE_WIDTH, rnd.nextInt(35));
n.set(ColumnNames.TEXT_SIZE, rnd.nextInt(12));
n.set(ColumnNames.COLOR_RED, rnd.nextInt(250));
n.set(ColumnNames.COLOR_GREEN, rnd.nextInt(250));
n.set(ColumnNames.COLOR_BLUE, rnd.nextInt(250));
n.set(ColumnNames.TEXT_COLOR_RED, rnd.nextInt(250));
n.set(ColumnNames.TEXT_COLOR_GREEN, rnd.nextInt(250));
n.set(ColumnNames.TEXT_COLOR_BLUE, rnd.nextInt(250));
n.set(ColumnNames.TEXT_BACKGROUND_COLOR_RED, rnd.nextInt(250));
n.set(ColumnNames.TEXT_BACKGROUND_COLOR_BLUE, rnd.nextInt(250));
n.set(ColumnNames.TEXT_BACKGROUND_COLOR_GREEN, rnd.nextInt(250));
n.set(ColumnNames.TEXT_BACKGROUND_STROKE_COLOR_RED, rnd.nextInt(250));
n.set(ColumnNames.TEXT_BACKGROUND_STROKE_COLOR_BLUE, rnd.nextInt(250));
n.set(ColumnNames.TEXT_BACKGROUND_STROKE_COLOR_GREEN, rnd.nextInt(250));
n.setString(ColumnNames.NAME, "Node" + rnd.nextInt(100));
n.setString(ColumnNames.FULL_NAME, "Node" + rnd.nextInt(100));
n.set(ColumnNames.NODE_FORM, Nodetype.nodetype[rnd.nextInt(3)]);
n.set(ColumnNames.NODE_VOWL_TYPE, Nodetype.vowltype[rnd.nextInt(3)]);
n.set(ColumnNames.CLASS_INSTANCE_COUNT, rnd.nextInt(20));
}
// GraphDataModifier random connections
for (int i = 0; i <= COUNT_CONNECTIONS; i++) {
int a = rnd.nextInt(COUNT_NODES);
int b = rnd.nextInt(COUNT_NODES);
int edgeID = graph.addEdge(a, b);
Edge edge = graph.getEdge(edgeID);
edge.setString(ColumnNames.NAME, "Edge" + rnd.nextInt(100));
edge.setString(ColumnNames.FULL_NAME, "Edge" + rnd.nextInt(100));
edge.set(ColumnNames.TEXT_SIZE, rnd.nextInt(8));
edge.set(ColumnNames.TEXT_COLOR_RED, rnd.nextInt(250));
edge.set(ColumnNames.TEXT_COLOR_GREEN, rnd.nextInt(250));
edge.set(ColumnNames.TEXT_COLOR_BLUE, rnd.nextInt(250));
edge.set(ColumnNames.TEXT_BACKGROUND_COLOR_RED, rnd.nextInt(250));
edge.set(ColumnNames.TEXT_BACKGROUND_COLOR_BLUE, rnd.nextInt(250));
edge.set(ColumnNames.TEXT_BACKGROUND_COLOR_GREEN, rnd.nextInt(250));
edge.set(ColumnNames.TEXT_BACKGROUND_STROKE_COLOR_RED, rnd.nextInt(250));
edge.set(ColumnNames.TEXT_BACKGROUND_STROKE_COLOR_BLUE, rnd.nextInt(250));
edge.set(ColumnNames.TEXT_BACKGROUND_STROKE_COLOR_GREEN, rnd.nextInt(250));
edge.set(ColumnNames.COLOR_RED, rnd.nextInt(250));
edge.set(ColumnNames.COLOR_GREEN, rnd.nextInt(250));
edge.set(ColumnNames.COLOR_BLUE, rnd.nextInt(250));
edge.set(ColumnNames.EDGE_ARROW_TYPE, EdgesType.arrowtype[rnd.nextInt(3)]);
edge.set(ColumnNames.EDGE_LINE_TYPE, EdgesType.linetype[rnd.nextInt(3)]);
edge.set(ColumnNames.ID, rnd.nextInt(25000));
edge.set(ColumnNames.EDGE_LENGTH, rnd.nextInt(100));
}
return graph;
}
示例11: addEdge
import prefuse.data.Graph; //导入方法依赖的package包/类
private static Edge addEdge(Graph g, Node nic, Node n, String type) {
Edge e = g.addEdge(nic, n);
e.set("type", type);
return(e);
}
示例12: getPrefuseGraphFromGamaGraphForVisu
import prefuse.data.Graph; //导入方法依赖的package包/类
public static Graph getPrefuseGraphFromGamaGraphForVisu(final IScope scope, final GamaGraph<?, ?> graph) {
System.err.println("translation of the graph to a prefuse graph...");
final Graph g = new Graph();
g.addColumn(PREFUSE_ATTRIBUTE_GAMA_OBJECT, IShape.class);
// g.addColumn(VisualItem.VISIBLE, Boolean.class, Boolean.TRUE);
final Map<Object, Node> gamaVertex2prefuseNode = new HashMap<Object, Node>(graph._internalVertexMap().size());
// retrieve nodes
for (final Object content : graph._internalVertexMap().keySet()) {
// Object vertex = graph._internalVertexMap().get(content);
if (content instanceof IShape) {
final IShape shContent = (IShape) content;
// ILocation loc = shContent.getLocation();
final Node prefuseNode = g.addNode();
prefuseNode.set(PREFUSE_ATTRIBUTE_GAMA_OBJECT, shContent);
gamaVertex2prefuseNode.put(content, prefuseNode);
} else {
System.err.println("Warning, not using " + content);
}
}
// retrieve edges
for (final Object o : graph._internalEdgeSet()) {
final _Edge<?, ?> edge = (_Edge) o;
final Edge prefuseEdge = g.addEdge(gamaVertex2prefuseNode.get(edge.getSource()),
gamaVertex2prefuseNode.get(edge.getTarget()));
}
// basic verification
if (graph._internalVertexMap()
.size() != g.getNodeCount()) { throw GamaRuntimeException.error(
"error during the translation of a Gama graph to a prefuse graph: the number of nodes is not the same.",
scope); }
return g;
}