use of org.gephi.preview.plugin.items.NodeItem in project gephi by gephi.
the class NodeBuilder method getItems.
@Override
public Item[] getItems(Graph graph) {
Item[] items = new NodeItem[graph.getNodeCount()];
int i = 0;
for (Node n : graph.getNodes()) {
NodeItem nodeItem = new NodeItem(n);
nodeItem.setData(NodeItem.X, n.x());
nodeItem.setData(NodeItem.Y, -n.y());
nodeItem.setData(NodeItem.Z, n.z());
nodeItem.setData(NodeItem.SIZE, n.size() * 2f);
nodeItem.setData(NodeItem.COLOR, n.getColor());
items[i++] = nodeItem;
}
return items;
}
use of org.gephi.preview.plugin.items.NodeItem in project gephi by gephi.
the class EdgeLabelRenderer method preProcess.
@Override
public void preProcess(PreviewModel previewModel) {
PreviewProperties properties = previewModel.getProperties();
if (properties.getBooleanValue(PreviewProperty.EDGE_LABEL_SHORTEN)) {
//Shorten labels
Item[] EdgeLabelsItems = previewModel.getItems(Item.EDGE_LABEL);
int maxChars = properties.getIntValue(PreviewProperty.EDGE_LABEL_MAX_CHAR);
for (Item item : EdgeLabelsItems) {
String label = item.getData(EdgeLabelItem.LABEL);
if (label.length() >= maxChars + 3) {
label = label.substring(0, maxChars) + "...";
item.setData(EdgeLabelItem.LABEL, label);
}
}
}
//Put parent color, and calculate position
for (Item item : previewModel.getItems(Item.EDGE_LABEL)) {
Edge edge = (Edge) item.getSource();
Item edgeItem = previewModel.getItem(Item.EDGE, edge);
EdgeColor edgeColor = (EdgeColor) properties.getValue(PreviewProperty.EDGE_COLOR);
NodeItem sourceItem = (NodeItem) edgeItem.getData(EdgeRenderer.SOURCE);
NodeItem targetItem = (NodeItem) edgeItem.getData(EdgeRenderer.TARGET);
Color color = edgeColor.getColor((Color) item.getData(EdgeItem.COLOR), (Color) sourceItem.getData(NodeItem.COLOR), (Color) targetItem.getData(NodeItem.COLOR));
item.setData(EDGE_COLOR, color);
if (edge.isSelfLoop()) {
//Middle
Float x = sourceItem.getData(NodeItem.X);
Float y = sourceItem.getData(NodeItem.Y);
Float size = sourceItem.getData(NodeItem.SIZE);
Vector v1 = new Vector(x, y);
v1.add(size, -size);
Vector v2 = new Vector(x, y);
v2.add(size, size);
Vector middle = bezierPoint(x, y, v1.x, v1.y, v2.x, v2.y, x, y, 0.5f);
item.setData(LABEL_X, middle.x);
item.setData(LABEL_Y, middle.y);
} else if (properties.getBooleanValue(PreviewProperty.EDGE_CURVED)) {
//Middle of the curve
Float x1 = sourceItem.getData(NodeItem.X);
Float x2 = targetItem.getData(NodeItem.X);
Float y1 = sourceItem.getData(NodeItem.Y);
Float y2 = targetItem.getData(NodeItem.Y);
//Curved edgs
Vector direction = new Vector(x2, y2);
direction.sub(new Vector(x1, y1));
float length = direction.mag();
direction.normalize();
float factor = properties.getFloatValue(EdgeRenderer.BEZIER_CURVENESS) * length;
// normal vector to the edge
Vector n = new Vector(direction.y, -direction.x);
n.mult(factor);
// first control point
Vector v1 = new Vector(direction.x, direction.y);
v1.mult(factor);
v1.add(new Vector(x1, y1));
v1.add(n);
// second control point
Vector v2 = new Vector(direction.x, direction.y);
v2.mult(-factor);
v2.add(new Vector(x2, y2));
v2.add(n);
Vector middle = bezierPoint(x1, y1, v1.x, v1.y, v2.x, v2.y, x2, y2, 0.5f);
item.setData(LABEL_X, middle.x);
item.setData(LABEL_Y, middle.y);
} else {
Float x = ((Float) sourceItem.getData(NodeItem.X) + (Float) targetItem.getData(NodeItem.X)) / 2f;
Float y = ((Float) sourceItem.getData(NodeItem.Y) + (Float) targetItem.getData(NodeItem.Y)) / 2f;
item.setData(LABEL_X, x);
item.setData(LABEL_Y, y);
}
}
//Property font
font = properties.getFontValue(PreviewProperty.EDGE_LABEL_FONT);
}
use of org.gephi.preview.plugin.items.NodeItem in project gephi by gephi.
the class NodeLabelRenderer method preProcess.
@Override
public void preProcess(PreviewModel previewModel) {
PreviewProperties properties = previewModel.getProperties();
if (properties.getBooleanValue(PreviewProperty.NODE_LABEL_SHORTEN)) {
//Shorten labels
Item[] nodeLabelsItems = previewModel.getItems(Item.NODE_LABEL);
int maxChars = properties.getIntValue(PreviewProperty.NODE_LABEL_MAX_CHAR);
for (Item item : nodeLabelsItems) {
String label = item.getData(NodeLabelItem.LABEL);
if (label.length() >= maxChars + 3) {
label = label.substring(0, maxChars) + "...";
item.setData(NodeLabelItem.LABEL, label);
}
}
}
//Put parent color, size and position
for (Item item : previewModel.getItems(Item.NODE_LABEL)) {
Node node = (Node) item.getSource();
Item nodeItem = previewModel.getItem(Item.NODE, node);
item.setData(NODE_COLOR, nodeItem.getData(NodeItem.COLOR));
item.setData(NODE_SIZE, nodeItem.getData(NodeItem.SIZE));
item.setData(NODE_X, nodeItem.getData(NodeItem.X));
item.setData(NODE_Y, nodeItem.getData(NodeItem.Y));
}
//Calculate font size and cache fonts
fontCache = new HashMap<>();
Font font = properties.getFontValue(PreviewProperty.NODE_LABEL_FONT);
for (Item item : previewModel.getItems(Item.NODE_LABEL)) {
Float nodeSize = item.getData(NODE_SIZE);
Float fontSize = 1f;
if (item.getData(NodeLabelItem.SIZE) != null) {
fontSize = item.getData(NodeLabelItem.SIZE);
}
if (properties.getBooleanValue(PreviewProperty.NODE_LABEL_PROPORTIONAL_SIZE)) {
fontSize *= nodeSize / 10f;
}
fontSize *= font.getSize();
Font labelFont = font.deriveFont((float) fontSize);
fontCache.put(labelFont.getSize(), labelFont);
item.setData(FONT_SIZE, labelFont.getSize());
}
}
Aggregations