use of org.gephi.graph.api.TextProperties in project gephi by gephi.
the class LabelAdjust method repulse.
private boolean repulse(Node n1, Node n2) {
boolean collision = false;
float n1x = n1.x();
float n1y = n1.y();
float n2x = n2.x();
float n2y = n2.y();
TextProperties t1 = n1.getTextProperties();
TextProperties t2 = n2.getTextProperties();
float n1w = t1.getWidth();
float n2w = t2.getWidth();
float n1h = t1.getHeight();
float n2h = t2.getHeight();
LabelAdjustLayoutData n2Data = n2.getLayoutData();
double n1xmin = n1x - 0.5 * n1w;
double n2xmin = n2x - 0.5 * n2w;
double n1ymin = n1y - 0.5 * n1h;
double n2ymin = n2y - 0.5 * n2h;
double n1xmax = n1x + 0.5 * n1w;
double n2xmax = n2x + 0.5 * n2w;
double n1ymax = n1y + 0.5 * n1h;
double n2ymax = n2y + 0.5 * n2h;
//Sphere repulsion
if (adjustBySize) {
double xDist = n2x - n1x;
double yDist = n2y - n1y;
double dist = Math.sqrt(xDist * xDist + yDist * yDist);
boolean sphereCollision = dist < radiusScale * (n1.size() + n2.size());
if (sphereCollision) {
double f = 0.1 * n1.size() / dist;
if (dist > 0) {
n2Data.dx = (float) (n2Data.dx + xDist / dist * f);
n2Data.dy = (float) (n2Data.dy + yDist / dist * f);
} else {
n2Data.dx = (float) (n2Data.dx + 0.01 * (0.5 - Math.random()));
n2Data.dy = (float) (n2Data.dy + 0.01 * (0.5 - Math.random()));
}
collision = true;
}
}
double upDifferential = n1ymax - n2ymin;
double downDifferential = n2ymax - n1ymin;
double labelCollisionXleft = n2xmax - n1xmin;
double labelCollisionXright = n1xmax - n2xmin;
if (upDifferential > 0 && downDifferential > 0) {
// Potential collision
if (labelCollisionXleft > 0 && labelCollisionXright > 0) {
// Collision
if (upDifferential > downDifferential) {
// N1 pushes N2 up
n2Data.dy = (float) (n2Data.dy - 0.02 * n1h * (0.8 + 0.4 * Math.random()));
collision = true;
} else {
// N1 pushes N2 down
n2Data.dy = (float) (n2Data.dy + 0.02 * n1h * (0.8 + 0.4 * Math.random()));
collision = true;
}
if (labelCollisionXleft > labelCollisionXright) {
// N1 pushes N2 right
n2Data.dx = (float) (n2Data.dx + 0.01 * (n1h * 2) * (0.8 + 0.4 * Math.random()));
collision = true;
} else {
// N1 pushes N2 left
n2Data.dx = (float) (n2Data.dx - 0.01 * (n1h * 2) * (0.8 + 0.4 * Math.random()));
collision = true;
}
}
}
return collision;
}
use of org.gephi.graph.api.TextProperties in project gephi by gephi.
the class TextManager method refreshEdge.
public boolean refreshEdge(Graph graph, EdgeModel edge, TextModelImpl modelImpl) {
TextProperties textData = edge.getEdge().getTextProperties();
if (textData != null) {
String txt = textData.getText();
String newTxt = buildText(graph, edge.getEdge(), modelImpl.getEdgeTextColumns());
if ((txt == null && newTxt != null) || (txt != null && newTxt == null) || (txt != null && newTxt != null && !txt.equals(newTxt))) {
edge.setText(newTxt);
return true;
}
}
edgeRefresh = true;
return false;
}
use of org.gephi.graph.api.TextProperties in project gephi by gephi.
the class EditEdges method prepareEdgesProperties.
/**
* Prepare set of editable properties of the node(s): size, position.
*
* @return Set of these properties
*/
private Sheet.Set prepareEdgesProperties() {
try {
if (multipleEdges) {
Sheet.Set set = new Sheet.Set();
set.setName("properties");
set.setDisplayName(NbBundle.getMessage(EditEdges.class, "EditEdges.properties.text.multiple"));
Property p;
//Color:
MultipleEdgesPropertiesWrapper edgesWrapper = new MultipleEdgesPropertiesWrapper(edges);
p = new PropertySupport.Reflection(edgesWrapper, Color.class, "getEdgesColor", "setEdgesColor");
p.setDisplayName(NbBundle.getMessage(EditEdges.class, "EditEdges.color.text"));
p.setName("color");
set.put(p);
//Label color:
p = new PropertySupport.Reflection(edgesWrapper, Color.class, "getLabelsColor", "setLabelsColor");
p.setDisplayName(NbBundle.getMessage(EditEdges.class, "EditEdges.label.color.text"));
p.setName("labelcolor");
set.put(p);
//Label size:
p = new PropertySupport.Reflection(edgesWrapper, Float.class, "getLabelsSize", "setLabelsSize");
p.setDisplayName(NbBundle.getMessage(EditEdges.class, "EditEdges.label.size.text"));
p.setName("labelsize");
set.put(p);
//Label visible:
p = new PropertySupport.Reflection(edgesWrapper, Boolean.class, "getLabelsVisible", "setLabelsVisible");
p.setDisplayName(NbBundle.getMessage(EditEdges.class, "EditEdges.label.visible.text"));
p.setName("labelvisible");
set.put(p);
return set;
} else {
Edge edge = edges[0];
Sheet.Set set = new Sheet.Set();
set.setName("properties");
set.setDisplayName(NbBundle.getMessage(EditEdges.class, "EditEdges.properties.text", edge.getLabel()));
Property p;
//Color:
SingleEdgePropertiesWrapper edgeWrapper = new SingleEdgePropertiesWrapper(edge);
p = new PropertySupport.Reflection(edgeWrapper, Color.class, "getEdgeColor", "setEdgeColor");
p.setDisplayName(NbBundle.getMessage(EditEdges.class, "EditEdges.color.text"));
p.setName("color");
set.put(p);
TextProperties textProperties = edge.getTextProperties();
//Label size:
p = new PropertySupport.Reflection(textProperties, Float.TYPE, "getSize", "setSize");
p.setDisplayName(NbBundle.getMessage(EditEdges.class, "EditEdges.label.size.text"));
p.setName("labelsize");
set.put(p);
//Label color:
p = new PropertySupport.Reflection(edgeWrapper, Color.class, "getLabelColor", "setLabelColor");
p.setDisplayName(NbBundle.getMessage(EditEdges.class, "EditEdges.label.color.text"));
p.setName("labelcolor");
set.put(p);
//Label visible:
p = new PropertySupport.Reflection(textProperties, Boolean.TYPE, "isVisible", "setVisible");
p.setDisplayName(NbBundle.getMessage(EditEdges.class, "EditEdges.label.visible.text"));
p.setName("labelvisible");
set.put(p);
return set;
}
} catch (Exception ex) {
Exceptions.printStackTrace(ex);
return null;
}
}
use of org.gephi.graph.api.TextProperties in project gephi by gephi.
the class EditNodes method prepareNodesProperties.
/**
* Prepare set of editable properties of the node(s): size, position.
*
* @return Set of these properties
*/
private Sheet.Set prepareNodesProperties() {
try {
if (multipleNodes) {
MultipleNodesPropertiesWrapper nodesWrapper = new MultipleNodesPropertiesWrapper(nodes);
Sheet.Set set = new Sheet.Set();
set.setName("properties");
set.setDisplayName(NbBundle.getMessage(EditNodes.class, "EditNodes.properties.text.multiple"));
Property p;
//Size:
p = new PropertySupport.Reflection(nodesWrapper, Float.class, "getNodesSize", "setNodesSize");
p.setDisplayName(NbBundle.getMessage(EditNodes.class, "EditNodes.size.text"));
p.setName("size");
set.put(p);
//All position coordinates:
set.put(buildMultipleNodesGeneralPositionProperty(nodesWrapper, "x"));
set.put(buildMultipleNodesGeneralPositionProperty(nodesWrapper, "y"));
set.put(buildMultipleNodesGeneralPositionProperty(nodesWrapper, "z"));
//Color:
p = new PropertySupport.Reflection(nodesWrapper, Color.class, "getNodesColor", "setNodesColor");
p.setDisplayName(NbBundle.getMessage(EditNodes.class, "EditNodes.color.text"));
p.setName("color");
set.put(p);
//Label color:
p = new PropertySupport.Reflection(nodesWrapper, Color.class, "getLabelsColor", "setLabelsColor");
p.setDisplayName(NbBundle.getMessage(EditNodes.class, "EditNodes.label.color.text"));
p.setName("labelcolor");
set.put(p);
//Label size:
p = new PropertySupport.Reflection(nodesWrapper, Float.class, "getLabelsSize", "setLabelsSize");
p.setDisplayName(NbBundle.getMessage(EditNodes.class, "EditNodes.label.size.text"));
p.setName("labelsize");
set.put(p);
//Label visible:
p = new PropertySupport.Reflection(nodesWrapper, Boolean.class, "getLabelsVisible", "setLabelsVisible");
p.setDisplayName(NbBundle.getMessage(EditNodes.class, "EditNodes.label.visible.text"));
p.setName("labelvisible");
set.put(p);
return set;
} else {
Node node = nodes[0];
Sheet.Set set = new Sheet.Set();
set.setName("properties");
set.setDisplayName(NbBundle.getMessage(EditNodes.class, "EditNodes.properties.text", node.getLabel()));
Property p;
//Size:
p = new PropertySupport.Reflection(node, Float.TYPE, "size", "setSize");
p.setDisplayName(NbBundle.getMessage(EditNodes.class, "EditNodes.size.text"));
p.setName("size");
set.put(p);
//All position coordinates:
set.put(buildGeneralPositionProperty(node, "x"));
set.put(buildGeneralPositionProperty(node, "y"));
set.put(buildGeneralPositionProperty(node, "z"));
//Color:
SingleNodePropertiesWrapper nodeWrapper = new SingleNodePropertiesWrapper(node);
p = new PropertySupport.Reflection(nodeWrapper, Color.class, "getNodeColor", "setNodeColor");
p.setDisplayName(NbBundle.getMessage(EditNodes.class, "EditNodes.color.text"));
p.setName("color");
set.put(p);
TextProperties textProperties = node.getTextProperties();
//Label size:
p = new PropertySupport.Reflection(textProperties, Float.TYPE, "getSize", "setSize");
p.setDisplayName(NbBundle.getMessage(EditNodes.class, "EditNodes.label.size.text"));
p.setName("labelsize");
set.put(p);
//Label color:
p = new PropertySupport.Reflection(nodeWrapper, Color.class, "getLabelColor", "setLabelColor");
p.setDisplayName(NbBundle.getMessage(EditNodes.class, "EditNodes.label.color.text"));
p.setName("labelcolor");
set.put(p);
//Label visible:
p = new PropertySupport.Reflection(textProperties, Boolean.TYPE, "isVisible", "setVisible");
p.setDisplayName(NbBundle.getMessage(EditNodes.class, "EditNodes.label.visible.text"));
p.setName("labelvisible");
set.put(p);
return set;
}
} catch (Exception ex) {
Exceptions.printStackTrace(ex);
return null;
}
}
use of org.gephi.graph.api.TextProperties in project gephi by gephi.
the class NodeLabelBuilder method getItems.
@Override
public Item[] getItems(Graph graph) {
boolean useTextData = false;
for (Node n : graph.getNodes()) {
TextProperties textData = n.getTextProperties();
if (textData != null && textData.getText() != null && !textData.getText().isEmpty()) {
useTextData = true;
}
}
//Build text
VisualizationController vizController = Lookup.getDefault().lookup(VisualizationController.class);
Column[] nodeColumns = vizController != null ? vizController.getNodeTextColumns() : null;
List<Item> items = new ArrayList<>();
for (Node n : graph.getNodes()) {
NodeLabelItem labelItem = new NodeLabelItem(n);
String label = getLabel(n, nodeColumns, graph.getView());
labelItem.setData(NodeLabelItem.LABEL, label);
TextProperties textData = n.getTextProperties();
if (textData != null && useTextData) {
if (textData.getR() != -1) {
labelItem.setData(NodeLabelItem.COLOR, new Color((int) (textData.getR() * 255), (int) (textData.getG() * 255), (int) (textData.getB() * 255), (int) (textData.getAlpha() * 255)));
}
// labelItem.setData(NodeLabelItem.WIDTH, textData.getWidth());
// labelItem.setData(NodeLabelItem.HEIGHT, textData.getHeight());
labelItem.setData(NodeLabelItem.SIZE, textData.getSize());
labelItem.setData(NodeLabelItem.VISIBLE, textData.isVisible());
labelItem.setData(NodeLabelItem.LABEL, textData.getText());
if (textData.isVisible() && label != null && !label.isEmpty()) {
items.add(labelItem);
}
} else if (label != null && !label.isEmpty()) {
items.add(labelItem);
}
}
return items.toArray(new Item[0]);
}
Aggregations