Skip to content

Commit

Permalink
feat (cli): Introduce new 'gen gexf' CLI sub-command
Browse files Browse the repository at this point in the history
  • Loading branch information
vorburger committed Oct 6, 2024
1 parent 262240c commit 2d53827
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 5 deletions.
2 changes: 1 addition & 1 deletion java/dev/enola/cli/GenCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
description = "Generates output from Things",
subcommands = {
GenGraphvizCommand.class,
GenGexfCommand.class,
// TODO GenMarkdownCommand.class,
// TODO GenGexfCommand.class,
// TODO GenTimelineHTMLCommand.class,
})
public class GenCommand {}
49 changes: 49 additions & 0 deletions java/dev/enola/cli/GenGexfCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2023-2024 The Enola <https://enola.dev> Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dev.enola.cli;

import static dev.enola.core.thing.ListThingService.ENOLA_ROOT_LIST_THINGS;

import dev.enola.core.proto.EnolaServiceGrpc.EnolaServiceBlockingStub;
import dev.enola.core.proto.GetThingRequest;
import dev.enola.thing.gen.gexf.GexfGenerator;
import dev.enola.thing.message.MoreThings;
import dev.enola.thing.message.ProtoThings;
import dev.enola.web.EnolaThingProvider;

import picocli.CommandLine;

@CommandLine.Command(name = "gexf", description = "Generate GEXF Graph from Things")
public class GenGexfCommand extends CommandWithModelAndOutput {

@Override
protected void run(EnolaServiceBlockingStub service) throws Exception {
var thingMetadataProvider = getMetadataProvider(new EnolaThingProvider(service));
var gexfGenerator = new GexfGenerator(thingMetadataProvider);

var request = GetThingRequest.newBuilder().setIri(ENOLA_ROOT_LIST_THINGS).build();
var response = service.getThing(request);
var protoThings = MoreThings.fromAny(response.getThing());
var javaThings = ProtoThings.proto2java(protoThings);

var base = Output.get(output);
var graphviz = base.resolve("graph.gexf");

gexfGenerator.convertIntoOrThrow(javaThings, rp.getWritableResource(graphviz));
}
}
11 changes: 7 additions & 4 deletions java/dev/enola/thing/gen/gexf/GexfGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,15 @@

public class GexfGenerator implements ThingsIntoAppendableConverter {

// TODO Treat blank nodes, same as in GraphvizGenerator
// TODO Write Attributes? https://gexf.net/data.html
// - Does this clutter the graph? Or not... too much, all, really?
// - Can it be used as Hierarchy Attribute for Circle Layout on https://gephi.org/gephi-lite/?

// TODO Custom Node color, shape & size; re-using logic from GraphvizGenerator
// TODO Custom Edge color, thickness, shape; re-using logic from GraphvizGenerator
// TODO Treat blank nodes same as in GraphvizGenerator

// TODO Write Attributes? Or not... too much?
// TODO Colors, see https://gexf.net/viz.html
// - Custom Node color, shape & size; re-using logic from GraphvizGenerator
// - Custom Edge color, thickness, shape; re-using logic from GraphvizGenerator

// NB: RosettaTest#testGraphviz() is the test coverage for this code

Expand Down

0 comments on commit 2d53827

Please sign in to comment.