Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show node labels in preview not persisting #52

Open
johngsandiford opened this issue Sep 8, 2023 · 0 comments
Open

show node labels in preview not persisting #52

johngsandiford opened this issue Sep 8, 2023 · 0 comments

Comments

@johngsandiford
Copy link

Hi,

When I set SHOW_NODE_LABELS to true on the preview model, it is not persisted when saved to a gephi file and then opened in the UI. If I export to pdf if works, but not when I save to a gephi file.

Please advise what I am doing wrong, or if this is a bug. Many thanks

var pc = Lookup.getDefault().lookup(ProjectController.class);
        pc.newProject();
        Workspace workspace = pc.getCurrentWorkspace();

        var graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel(workspace);

        var n0 = graphModel.factory().newNode("n0");
        n0.setLabel("Node 0");
        var n1 = graphModel.factory().newNode("n1");
        n1.setLabel("Node 1");

        var e1 = graphModel.factory().newEdge(n1, n0, 1, true);

        var directedGraph = graphModel.getDirectedGraph();
        directedGraph.addNode(n0);
        directedGraph.addNode(n1);
        directedGraph.addEdge(e1);

        System.out.println("Nodes " + directedGraph.getNodeCount());

        var appearanceController = Lookup.getDefault().lookup(AppearanceController.class);
        var appearanceModel = appearanceController.getModel();

        // Rank color by Degree
        Function degreeRanking = appearanceModel.getNodeFunction(graphModel.defaultColumns()
                .degree(), RankingElementColorTransformer.class);
        RankingElementColorTransformer degreeTransformer = degreeRanking.getTransformer();
        degreeTransformer.setColors(new Color[]{new Color(0xFEF0D9), new Color(0xB30000)});
        degreeTransformer.setColorPositions(new float[]{0f, 1f});
        appearanceController.transform(degreeRanking);

        // Get Centrality
        GraphDistance distance = new GraphDistance();
        distance.setDirected(true);
        distance.execute(graphModel);

        // Rank size by centrality
        Column centralityColumn = graphModel.getNodeTable().getColumn(GraphDistance.BETWEENNESS);
        Function centralityRanking = appearanceModel.getNodeFunction(centralityColumn, RankingNodeSizeTransformer.class);
        RankingNodeSizeTransformer centralityTransformer = (RankingNodeSizeTransformer) centralityRanking.getTransformer();
        centralityTransformer.setMinSize(3);
        centralityTransformer.setMaxSize(10);
        appearanceController.transform(centralityRanking);

        // Rank label size - set a multiplier size
        Function centralityRanking2 = appearanceModel.getNodeFunction(centralityColumn, RankingLabelSizeTransformer.class);
        RankingLabelSizeTransformer labelSizeTransformer = (RankingLabelSizeTransformer) centralityRanking2.getTransformer();
        labelSizeTransformer.setMinSize(1);
        labelSizeTransformer.setMaxSize(3);
        appearanceController.transform(centralityRanking2);

        var previewController = Lookup.getDefault().lookup(PreviewController.class);
        var previewModel = previewController.getModel();
        previewModel.getProperties().putValue(PreviewProperty.SHOW_NODE_LABELS, Boolean.TRUE);
        previewController.refreshPreview();

        var file = new File("preview-issue.gephi");

        file.createNewFile();   // to get around a bug in 0.10.1
        pc.saveProject(pc.getCurrentProject(), file);


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant