简体   繁体   English

基于顶点属性的JUNG塌陷顶点

[英]JUNG collapse vertices based on vertex attribute

I have added to my GUI the collapse vertex function like: 我已经在我的GUI中添加了折叠顶点函数,例如:

private void collapseByVillageButtonActionPerformed(java.awt.event.ActionEvent evt) {                                                        
    // TODO add your handling code here:
    showReligionCheckBox.setEnabled(false);
    showReligionCheckBox.setSelected(false);
    showVillageCheckBox.setEnabled(false);
    showVillageCheckBox.setSelected(false);
    collapseByVillageButton.setEnabled(false);
    collapseByReligionButton.setEnabled(false);
    vv.getRenderContext().setVertexShapeTransformer(religion_none);
    vv.getRenderContext().setVertexFillPaintTransformer(village_none);
    String[] villages = {"a", "b", "c", "d", "e"};
    for (String s : villages) {
        Collection picked = new HashSet();
        for (Potter p : g.getVertices()) {
            if (p.village.equals(s)) {
                picked.add(p);
            }
        }
        if (picked.size() > 1) {
            Graph inGraph = layout.getGraph();
            Graph clusterGraph = collapser.getClusterGraph(inGraph, picked);
            Graph graph = collapser.collapse(layout.getGraph(), clusterGraph);
            double sumx = 0;
            double sumy = 0;
            for (Object v : picked) {
                Point2D p = (Point2D) layout.transform((Potter) v);
                sumx += p.getX();
                sumy += p.getY();
            }
            Point2D cp = new Point2D.Double(sumx / picked.size(), sumy / picked.size());
            vv.getRenderContext().getParallelEdgeIndexFunction().reset();
            layout.setGraph(graph);
            layout.setLocation(clusterGraph, cp);
            vv.getPickedVertexState().clear();
            vv.repaint();
        }
    }

When I press the button, JUNG collapse the vertices according to the value of the property "village". 当我按下按钮时,JUNG根据属性“ village”的值折叠顶点。 This works, although I don't know if this is the right way to do it. 这行得通,尽管我不知道这是否是正确的方法。 One thing that I don't understand is: how do I change the new vertices labels in order to display something nicer that the list of names of the collapsed vertices? 我不明白的一件事是:如何更改新的顶点标签以显示比折叠顶点名称列表更好的东西?

EDIT: 编辑:

I think this could do the trick in my case: 我认为这可以解决我的问题:

vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller() {
        @Override
        public String transform(Object v) {
            if (v instanceof Graph) {
                Collection vertices = ((Graph) v).getVertices();
                Potter next = (Potter) vertices.iterator().next();
                return next.village;
            }
            return super.transform(v);
        }
    });

Any hint more than welcome! 任何提示都值得欢迎!

Best regards, Simone 最好的问候,西蒙妮

You supply the labels for the collapsed vertices, so they can be whatever you like. 您可以提供折叠顶点的标签,因此它们可以随您的喜欢。 By default you are probably using a ToStringLabeller but you can swap it out by providing a different vertex to label transformer to the pluggable renderer context. 默认情况下,您可能使用的是ToStringLabeller,但是您可以通过提供不同的顶点来替换它,以将变换器标记为可插入渲染器上下文。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM