0

我正在使用 Scala 中的 GraphStream 创建图形。

代码的一个小版本如下:

    val graph = new SingleGraph("Tutorial 1")

    graph.addNode("A")
    graph.addNode("B")
    graph.addNode("C")
    graph.addEdge("AB", "A", "B")
    graph.addEdge("BC", "B", "C")
    graph.addEdge("CA", "C", "A")

    System.setProperty("org.graphstream.ui", "swing")
    graph.display

此代码给出以下结果:

图形

我查看了 GraphStream 的官方文档,但找不到如何使节点和边的 ID 出现。所以我的问题是,我怎样才能在我的图表中添加文本?

4

1 回答 1

0

您可以在图形流的 CSS 样式表中指定它。只需使用text-mode: normal. 样式表可以通过graph.setAttribute("ui.stylesheet", myStyleSheet)

我的样式表中的示例:

node{
    size: 10px, 10px;
    shape: circle;
    fill-color: #B1DFF7;
    stroke-mode: plain;
    stroke-color: #B1DFF7;
    stroke-width: 3;
    text-mode: normal; /*normal or hidden*/
    text-background-mode: plain; /*plain or none*/
    text-background-color: rgba(255, 255, 255, 200);
    text-alignment: above;
}
于 2022-02-25T13:29:33.100 回答