Skip to content

Path Graph is a library with all the tools necessary to create and work both path and walk graphs in a stable and simple way.

License

GPL-3.0 and 2 other licenses found

Licenses found

GPL-3.0
LICENSE.txt
Unknown
LICENSE-JavaFXSmartGraph.txt
MIT
LICENSE_Bootstrap.txt
Notifications You must be signed in to change notification settings

vittorioPiotti/PathGraph-JavaFX

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

(Java FX) PathGraph

Icona

What is PathGraph

Path Graph is a library with all the tools necessary to create and work both path and walk graphs in a stable and simple way.

Why PathGraph

If you need a ready-to-use library for user-side representing path graphs in which there are nodes, edges, and associated costs, which offers a user-friendly to represent, manage, and interact graphs, then this it's the right solution.

Fork-Based Project

This library is a fork based on the source code of the SmartGraph v2.0.0. It is modified to suite in specific path graphs features in a stable interface.


Note

Read the Javadoc for more details: PathGraph-JavaFX-1.0.9-javadoc

Note

Library available on Maven Central: PathGraph-JavaFX-1.0.9

<dependency>
  <groupId>io.github.vittoriopiotti</groupId>
  <artifactId>PathGraph-JavaFX</artifactId>
  <version>1.0.9</version>
</dependency>

Index

  1. Features
  2. Graph Logic
  3. Get Started
  4. Ready to Code
  5. Examples
  6. Callbacks
  7. DTO · Data Transfer Object
  8. JSON · Data Management
  9. Configuration and Styling
  10. Licenses

Fork-Based On SmartGraph


1. Features

Icona Icona Icona
Icona Icona Icona

2. Graph Logic

  • Limit of 26 Nodes nameable only with uppercase characters
  • Limit of two edges with opposite directions beetween two nodes
  • Loop creation is not allowed
  • Edge cost is an integer number
  • Edge directions can be: Bidirectional, Natural Direction, Opposite Direction

3. Get Started

Requirements

Java-21, JavaFX-22

Forward-compatible

Dependencies

Import External Dependencies

JavaFX-Swing-22, ​JavaFX-Controls-22, ​ JavaFX-FXML-22

Import Library

PathGraph-JavaFX-1.0.9

Able to:

  • POM configuration:

    <dependency>
        <groupId>io.github.vittoriopiotti</groupId>
        <artifactId>PathGraph-JavaFX</artifactId>
        <version>1.0.9</version>
    </dependency>
  • Manual configuration:

    Download and import jar in your module dependencies: PathGraph-JavaFX-1.0.9.jar

Show POM.xml dependencies
<dependency>
    <groupId>io.github.vittoriopiotti</groupId>
    <artifactId>PathGraph-JavaFX</artifactId>
    <version>1.0.9</version>
</dependency>
<dependency>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-swing</artifactId>
    <version>22</version>
</dependency>
<dependency>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-controls</artifactId>
    <version>22</version>
</dependency>
<dependency>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-fxml</artifactId>
    <version>22</version>
</dependency>

4. Ready to Code

Import Component

import com.vittoriopiotti.pathgraph.app.*;

Instance Object

Note

  • PathGraph to create your custom interface
  • PathGraphUIfor ready-to-use interface

PathGraph

Vanilla configurations to use in your project in which create your custom UI.

Handles the graph's display and logic independently of the user interface, acting as a standalone component without any user interface restrictions, provifind all necessary features.

PathGraph pg = new PathGraph();

Empty callbacks

or

PathGraph pg = new PathGraph(
    (ContextMenuCallback) ()->{},
    (EdgeCallback) (MouseEvent e, Character c1, Character c2)->{},
    (NodeCallback) (MouseEvent e, Character c1, Character c2)->{},
    (BackgroundCallback) (MouseEvent e)->{}, 
    (ZoomCallback) (Double n)->{},
    (AdjustPositionCallback) ()->{}
);

With callbacks

PathGraphUI

Ready-to-use configuration with default UI.

Extends PathGraph to provide a layer on top of the graph management functionalities. It allows for the interaction with the graph through a visual interface over the underlying graph logic.

PathGraphUI pg = new PathGraphUI(
    (Stage) stage,
    (Scene) scene
);

With default UI

or

PathGraphUI pg = new PathGraphUI(
    (Stage) stage,
    (Scene) scene,
    
    /* is enabled top-left menu */
    true,
    
    /* is enabled bot-left menu */
    true,
    
    /* is enabled bot-mid menu */
    true,
    
    /* is enabled right-mid menu */
    true,
    
    /* is enabled top-right menu */
    true,
    
    /* is hide UI */
    false

);

With custom UI

In both cases are customizable the visibility of the UI and its components only with an instance of PathGraphUI:

Hide UI, Show UI, Toggle UI, Set UI

Setup

Note

To enable the use of library setup must be called only one time after making stage visible with (Stage) stage.show()

Before calling setup, no operations of any kind can be performed on the graph

pg.setup();

or

pg.setup().thenRun(() -> {

  /* actions to perform on first load */
  /* e.g. put here components, callbacks setting, graph configurations */

});

Graph operations are limited to these contexts:

  • Setup: ensures execution post-initialization in pg.setup().thenRun(()->{}).
  • Event Handlers: Safe within JavaFX event actions.
  • JavaFX Timers: Use for delayed, thread-safe execution.

5. Examples

PathGraph

Vanilla configurations to use in your project in which create your custom UI.

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.scene.layout.BorderPane;
import com.vittoriopiotti.pathgraph.app.PathGraph;

public class ExampleOfPathGraph extends Application {

    @Override
    public void start(Stage primaryStage) {

        /* 1. Create javafx window */
        BorderPane root = new BorderPane();
        Scene scene = new Scene(root,500,300);
        primaryStage.setScene(scene);

        /* 2. Show primary stage */
        primaryStage.show();

        /* 3. Instance object */
        PathGraph pg = new PathGraph();

        /* 4. Add PathGraph in a container */
        root.setCenter(pg);

        /* 6. Setup */
        pg.setup().thenRun(() -> {

            /* 5. Custom configurations  */
            pg.enableListenersGraph(true);
            pg.enableListenersPane(true);
            pg.setAutomaticLayout(true);

            /* Set callbacks */
            pg.setBackgroundCallback(event -> {
                pg.newNode();
                event.consume();
            });
            pg.setNodeCallback((event,label) -> {
                pg.newEdge(label);
                event.consume();
            });
            pg.setEdgeCallback((event,start,end) -> {
                pg.deleteEdge(start,end);
                event.consume();
            });
            
            /* 7. Make Graphs */
            pg.newNode('A');
            pg.newNode('B');
            pg.newNode('C');
            pg.newEdge('A', 'B', 1);
            pg.newEdge('C', 'A', 2, false);

        });

    }

    public static void main(String[] args) {
        launch();
    }

}

PathGraphUI

Ready-to-use configuration with default UI.

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.scene.layout.BorderPane;
import com.vittoriopiotti.pathgraph.app.PathGraphUI;

public class ExampleOfPathGraphUI extends Application {

    @Override
    public void start(Stage primaryStage) {

        /* 1. Create javafx window */
        BorderPane root = new BorderPane();
        Scene scene = new Scene(root,500,300);
        primaryStage.setScene(scene);

        /* 2. Show primary stage */
        primaryStage.show();

        /* 3. Instance object */
        PathGraphUI pg = new PathGraphUI(primaryStage,scene);

        /* 4. Add PathGraph in a container */
        root.setCenter(pg);

        /* 5. Setup */
        pg.setup().thenRun(() -> {

            /* 6. Make Graphs */
            pg.newNode('A');
            pg.newNode('B');
            pg.newNode('C');
            pg.newEdge('A', 'B', 1);
            pg.newEdge('C', 'A', 2, false);

        });

    }

    public static void main(String[] args) {
        launch();
    }

}

6. Callbacks

Note

Customizable callbacks only with an instance of PathGraph (PathGraphUIis a ready-to-use configuration).

Usage:

  1. Import package to use callback objects:

    import com.vittoriopiotti.pathgraph.callbacks.*;
  2. Call setter methods to apply new callbacks passing callback objects:

    Set All Callbacks, Set Context Menu Callback, Set Edge Callback, Set Node Callback, Set Background Callback, Set Zoom Callback, Set Adjust Position Callback

Snippet:

EdgeCallback ec = (event,start,end) ->{
    if (event.getButton() == MouseButton.SECONDARY) {
        System.out.println(
                pg.rotateEdge(start,end) ?
                        "rotate edge successfully" :
                        "rotate edge  error"
        );
    }else if (event.getButton() == MouseButton.PRIMARY) {
        System.out.println(
                pg.deleteEdge(start,end) ?
                        "delete edge successfully" :
                        "delete edge error"
        );
    }
    event.consume();
};

(PathGraph) pg.setEdgeCallback(ec);

Tip

  • Use of a ContextMenu with custom MenuItem or Button to perform the actions

  • Use event.consume() to prevent the propagation of the event

  • Use the return status to feedback errors with a Modal Dialog

7. DTO · Data Transfer Objects

Note

Read the Javadoc for more details: (see)

Providing to rappresent graph components in a simple and serializable structure.

Import package:

import com.vittoriopiotti.pathgraph.dto.*;

Usage:

  • Converting graph data into JSON format
  • Reconstructing graph data from JSON
  • Support structure for graph operations

8. JSON · Data Management

Methods

Get Nodes Json, Get Edges Json, Get Connections Json, Get Graph Json, Upload Json, Download Json

Structure

Graph

{
  "nodes": ["A", "B","C"],
  "edges": [
    {
      "from": "A",
      "to": "B",
      "cost": 1,
      "isArrowed": true
    },
    {
      "from": "B",
      "to": "A",
      "cost": 10,
      "isArrowed": true
    },
    {
      "from": "B",
      "to": "C",
      "cost": 2,
      "isArrowed": false
    }
  ]
}
Nodes
{
  "nodes": [
    "A",
    "C",
    "B"
  ]
}
Edges
{
  "edges": [
    {
      "from": "A",
      "to": "B",
      "cost": 1,
      "isArrowed": true
    },
    {
      "from": "C",
      "to": "A",
      "cost": 2,
      "isArrowed": false
    }
  ]
}
Connections
{
  "connections": [
    {
      "node": "B",
      "edges": [
      ]
    },
    {
      "node": "A",
      "edges": [
        {
          "to": "B",
          "cost": 1
        },
        {
          "to": "C",
          "cost": 2
        }
      ]
    },
    {
      "node": "C",
      "edges": [
        {
          "to": "A",
          "cost": 2
        }
      ]
    }
  ]
}

9. Configuration and Styling

In future versions will be optimized the management of configurations and styles similar to the original project of the fork (see).

Currently, the styles and configurations are preset and cannot be modified.

10. Licenses

Note

SVG icons from Bootstrap


PathGraph

Copyright 2024 Vittorio Piotti (GitHub page) (Personal page)

Version v1.0.4

License GPL-3.0


SmartGraph

Copyright 2019 - 2024 Bruno Silva (GitHub page) (Personal page)

Version v2.0.0

License MIT


Bootstrap Icons

Copyright 2011-2018 The Bootstrap Authors

Version v1.11.0

License MIT


Fork-Based On SmartGraph

This library is a fork based on the source code of the SmartGraph v2.0.0 library on which existing classes have been modified and new ones have been added. PathGraph is therefore the adaptation of SmartGraph to specific path graphs features in a stable user interface.

See SmartGraph