public int getNameWidth(Graphics2D g, boolean includeNonLeafs) { int width = 0; if (includeNonLeafs || cluster.isLeaf()) { Rectangle2D rect = g.getFontMetrics().getStringBounds(cluster.getName(), g); width = (int)rect.getWidth(); } return width; }
public int getNameWidth(Graphics2D g, boolean includeNonLeafs) { int width = 0; if (includeNonLeafs || cluster.isLeaf()) { Rectangle2D rect = g.getFontMetrics().getStringBounds(cluster.getName().toString(), g); width = (int)rect.getWidth(); } return width; }
public int getNameWidth(Graphics2D g, boolean includeNonLeafs) { int width = 0; if (includeNonLeafs || cluster.isLeaf()) { Rectangle2D rect = g.getFontMetrics().getStringBounds(cluster.getName(), g); width = (int)rect.getWidth(); } return width; }
public void toConsole(int indent) { for (int i = 0; i < indent; i++) { System.out.print(" "); } String name = getName() + (isLeaf() ? " (leaf)" : "") + (distance != null ? " distance: " + distance : ""); System.out.println(name); for (Cluster child : getChildren()) { child.toConsole(indent + 1); } }
public int countLeafs(Cluster node, int count) { if (node.isLeaf()) count++; for (Cluster child : node.getChildren()) { count += child.countLeafs(); } return count; }
public int countLeafs(Cluster<T> node, int count) { if (node.isLeaf()) count++; for (Cluster child : node.getChildren()) { count += child.countLeafs(); } return count; }
public int countLeafs(Cluster node, int count) { if (node.isLeaf()) count++; for (Cluster child : node.getChildren()) { count += child.countLeafs(); } return count; }
public void toConsole(int indent) { for (int i = 0; i < indent; i++) { System.out.print(" "); } String name = getName() + (isLeaf() ? " (leaf)" : "") + (distance != null ? " distance: " + distance : ""); System.out.println(name); for (Cluster child : getChildren()) { child.toConsole(indent + 1); } }
public void toConsole(int indent) { for (int i = 0; i < indent; i++) { System.out.print(" "); } String name = getName() + (isLeaf() ? " (leaf)" : "") + (distance != null ? " distance: " + distance : ""); System.out.println(name); for (Cluster child : getChildren()) { child.toConsole(indent + 1); } }
private ArrayList<String> getNameInCluster(Cluster cluster) { ArrayList<String> itemsInCluster = new ArrayList<String>(); String nodeName; if (cluster.isLeaf()) { nodeName = cluster.getName(); itemsInCluster.add(nodeName); } else { // String[] clusterName = cluster.getName().split("#"); // nodeName = clusterName[1]; } for (Cluster child : cluster.getChildren()) { ArrayList<String> childrenNames = getNameInCluster(child); itemsInCluster.addAll(childrenNames); } return itemsInCluster; }
@Override public void paint(Graphics2D g, int xDisplayOffset, int yDisplayOffset, double xDisplayFactor, double yDisplayFactor, boolean decorated) { int x1, y1, x2, y2; FontMetrics fontMetrics = g.getFontMetrics(); x1 = (int)(initPoint.getX() * xDisplayFactor + xDisplayOffset); y1 = (int)(initPoint.getY() * yDisplayFactor + yDisplayOffset); x2 = (int)(linkPoint.getX() * xDisplayFactor + xDisplayOffset); y2 = y1; g.fillOval(x1-dotRadius, y1-dotRadius, dotRadius * 2, dotRadius * 2); g.drawLine(x1, y1, x2, y2); if (cluster.isLeaf()) { g.drawString(cluster.getName().toString(), x1 + namePadding, y1 + (fontMetrics.getHeight()/2) - 2); } if (decorated && cluster.getDistance() != null && !cluster.getDistance().isNaN() && cluster.getDistance() > 0) { String s = String.format("%.2f", cluster.getDistance()); Rectangle2D rect = fontMetrics.getStringBounds(s, g); g.drawString(s, x1 - (int)rect.getWidth() , y1 - 2); } x1 = x2; y1 = y2; y2 = (int)(linkPoint.getY() * yDisplayFactor + yDisplayOffset); g.drawLine(x1, y1, x2, y2); for (ClusterComponent child : children) { child.paint(g, xDisplayOffset, yDisplayOffset, xDisplayFactor, yDisplayFactor, decorated); } }
@Override public void paint(Graphics2D g, int xDisplayOffset, int yDisplayOffset, double xDisplayFactor, double yDisplayFactor, boolean decorated) { int x1, y1, x2, y2; FontMetrics fontMetrics = g.getFontMetrics(); x1 = (int)(initPoint.getX() * xDisplayFactor + xDisplayOffset); y1 = (int)(initPoint.getY() * yDisplayFactor + yDisplayOffset); x2 = (int)(linkPoint.getX() * xDisplayFactor + xDisplayOffset); y2 = y1; g.fillOval(x1-dotRadius, y1-dotRadius, dotRadius * 2, dotRadius * 2); g.drawLine(x1, y1, x2, y2); if (cluster.isLeaf()) { g.drawString(cluster.getName(), x1 + namePadding, y1 + (fontMetrics.getHeight()/2) - 2); } if (decorated && cluster.getDistance() != null && !cluster.getDistance().isNaN() && cluster.getDistance().getDistance() > 0) { String s = String.format("%.2f", cluster.getDistance()); Rectangle2D rect = fontMetrics.getStringBounds(s, g); g.drawString(s, x1 - (int)rect.getWidth() , y1 - 2); } x1 = x2; y1 = y2; y2 = (int)(linkPoint.getY() * yDisplayFactor + yDisplayOffset); g.drawLine(x1, y1, x2, y2); for (ClusterComponent child : children) { child.paint(g, xDisplayOffset, yDisplayOffset, xDisplayFactor, yDisplayFactor, decorated); } }
@Override public void paint(Graphics2D g, int xDisplayOffset, int yDisplayOffset, double xDisplayFactor, double yDisplayFactor, boolean decorated) { int x1, y1, x2, y2; FontMetrics fontMetrics = g.getFontMetrics(); x1 = (int)(initPoint.getX() * xDisplayFactor + xDisplayOffset); y1 = (int)(initPoint.getY() * yDisplayFactor + yDisplayOffset); x2 = (int)(linkPoint.getX() * xDisplayFactor + xDisplayOffset); y2 = y1; g.fillOval(x1-dotRadius, y1-dotRadius, dotRadius * 2, dotRadius * 2); g.drawLine(x1, y1, x2, y2); if (cluster.isLeaf()) { g.drawString(cluster.getName(), x1 + namePadding, y1 + (fontMetrics.getHeight()/2) - 2); } if (decorated && cluster.getDistance() != null && !cluster.getDistance().isNaN() && cluster.getDistance().getDistance() > 0) { String s = String.format("%.2f", cluster.getDistance()); Rectangle2D rect = fontMetrics.getStringBounds(s, g); g.drawString(s, x1 - (int)rect.getWidth() , y1 - 2); } x1 = x2; y1 = y2; y2 = (int)(linkPoint.getY() * yDisplayFactor + yDisplayOffset); g.drawLine(x1, y1, x2, y2); for (ClusterComponent child : children) { child.paint(g, xDisplayOffset, yDisplayOffset, xDisplayFactor, yDisplayFactor, decorated); } }
private ClusterComponent createComponent(Cluster cluster, VCoord initCoord, double clusterHeight) { ClusterComponent comp = null; if (cluster != null) { comp = new ClusterComponent(cluster, cluster.isLeaf(), initCoord); double leafHeight = clusterHeight / cluster.countLeafs(); double yChild = initCoord.getY() - (clusterHeight / 2); double distance = cluster.getDistanceValue() == null ? 0 : cluster.getDistanceValue(); for (Cluster child : cluster.getChildren()) { int childLeafCount = child.countLeafs(); double childHeight = childLeafCount * leafHeight; double childDistance = child.getDistanceValue() == null ? 0 : child.getDistanceValue(); VCoord childInitCoord = new VCoord(initCoord.getX() + (distance - childDistance), yChild + childHeight / 2.0); yChild += childHeight; /* Traverse cluster node tree */ ClusterComponent childComp = createComponent(child, childInitCoord, childHeight); childComp.setLinkPoint(initCoord); comp.getChildren().add(childComp); } } return comp; }
private ClusterComponent createComponent(Cluster cluster, VCoord initCoord, double clusterHeight) { ClusterComponent comp = null; if (cluster != null) { comp = new ClusterComponent(cluster, cluster.isLeaf(), initCoord); double leafHeight = clusterHeight / cluster.countLeafs(); double yChild = initCoord.getY() - (clusterHeight / 2); double distance = cluster.getDistanceValue() == null ? 0 : cluster.getDistanceValue(); for (Cluster child : cluster.getChildren()) { int childLeafCount = child.countLeafs(); double childHeight = childLeafCount * leafHeight; double childDistance = child.getDistanceValue() == null ? 0 : child.getDistanceValue(); VCoord childInitCoord = new VCoord(initCoord.getX() + (distance - childDistance), yChild + childHeight / 2.0); yChild += childHeight; /* Traverse cluster node tree */ ClusterComponent childComp = createComponent(child, childInitCoord, childHeight); childComp.setLinkPoint(initCoord); comp.getChildren().add(childComp); } } return comp; }
private ClusterComponent createComponent(Cluster<T> cluster, VCoord initCoord, double clusterHeight) { ClusterComponent comp = null; if (cluster != null) { comp = new ClusterComponent(cluster, cluster.isLeaf(), initCoord); double leafHeight = clusterHeight / cluster.countLeafs(); double yChild = initCoord.getY() - (clusterHeight / 2); double distance = cluster.getDistance() == null ? 0 : cluster.getDistance(); for (Cluster<T> child : cluster.getChildren()) { int childLeafCount = child.countLeafs(); double childHeight = childLeafCount * leafHeight; double childDistance = child.getDistance() == null ? 0 : child.getDistance(); VCoord childInitCoord = new VCoord(initCoord.getX() + (distance - childDistance), yChild + childHeight / 2.0); yChild += childHeight; /* Traverse cluster node tree */ ClusterComponent childComp = createComponent(child, childInitCoord, childHeight); childComp.setLinkPoint(initCoord); comp.getChildren().add(childComp); } } return comp; }