Went: GoJS diagrams in PureScript by André Muricy

January 4, 2024

In the presentation Went: GoJS diagrams in PureScript, André Muricy discusses his library Went, which enables the use of the GoJS diagrams library in a PureScript setting. GoJS is a powerful and expressive JavaScript library for creating dynamic and interactive diagrams. André provides an overview of GoJS, highlighting its object-oriented structure and TypeScript support. He explains that diagrams in GoJS are built using graph objects, such as nodes and shapes, and that a canvas or div is required to render the diagrams. André then introduces PureScript, a statically-typed programming language, as a solution for adding type safety and preventing runtime errors in GoJS diagrams. He demonstrates the process of adding node data and creating node templates in PureScript, setting the alignment and appearance of graph objects, and making certain nodes and arrows invisible and grouping them together. Despite some challenges, André successfully implements these changes to create interactive and visually appealing diagrams using GoJS and PureScript. He plans to continue improving the library and creating a demo page to showcase its capabilities.

Went: GoJS diagrams in PureScript: A comprehensive overview

In the realm of dynamic and interactive diagram creation, GoJS stands out as a powerful JavaScript library. However, integrating it with statically-typed languages like PureScript can enhance its usability and safety. André Muricy’s presentation, Went: GoJS diagrams in PureScript, explores this integration, showcasing the Went library which brings GoJS diagrams to the PureScript environment. Here, we delve into the core insights and highlights from André’s presentation, offering a comprehensive understanding of this innovative library.

 

Introduction to GoJS and PureScript

André kicks off the presentation with an introduction to GoJS, a JavaScript framework known for its expressiveness in creating dynamic diagrams. GoJS employs an object-oriented structure and supports TypeScript, building diagrams using various graph objects like nodes and shapes. These objects require a canvas or div for rendering.

However, while GoJS is powerful, its complexity and lack of type safety in JavaScript can be daunting. To address these challenges, André introduces PureScript, a statically-typed programming language that offers type safety and helps prevent runtime errors, thereby improving the development experience.

 

The motivation behind Went

The primary motivation behind creating Went was to leverage PureScript’s type system to enhance the GoJS development experience. By creating an interface between GoJS and PureScript, André aims to reduce the need for numerous bindings and simplify the process of creating diagrams. He envisions a scenario where developers can use GoJS features seamlessly within PureScript, combining the best of both worlds.

 

Building diagrams with Went

Throughout the presentation, André demonstrates the process of building interactive diagrams using Went. Here are some of the key steps and concepts he covers:

  1. Node templates and data binding
    • Node templates define the visual representation of nodes.
    • Data for each node comes from the model, following the model-view pattern.
    • Binding properties like color and text to model data ensures dynamic updates.
  2. Creating and modifying nodes
    • Initially, node data is empty. André shows how to add records with keys to node data.
    • Visual representation is achieved by altering node shapes and specifying categories for node templates.
  3. Setting alignment and appearance
    • Alignment and appearance of graph objects are controlled by binding properties and adjusting sizes.
    • Adding links between nodes using keys in the link data enhances the interactivity.
  4. Grouping nodes and links
    • Grouping nodes and links together creates organized units within diagrams.
    • Using group templates and setting properties like layout and appearance helps in maintaining a structured diagram.

 

Enhancing diagram interactivity

One of the highlights of the presentation is the discussion on making diagrams interactive. André demonstrates:

  • Interactive nodes
    • The alignment function determines node positions based on user input.
    • Visibility toggles for ports based on mouse interactions enhance user experience.
  • Curved links and visual enhancements
    • Adjusting link properties, such as curviness, makes diagrams more visually appealing.
    • Adding shapes to links improves clarity and aesthetics.

 

Integration with Halogen and future plans

Towards the end of the presentation, André explains the integration of GoJS diagrams in PureScript using the Halogen library. Halogen, PureScript’s answer to React, manages the DOM, creates the diagram div, sets properties, and initializes the GoJS diagram.

André announces plans to publish the Went library under an open-source license on GitHub. This will allow developers to download, experiment with, and incorporate the library into their PureScript projects. Additionally, he intends to clean up the library and create a demo page to showcase its capabilities.

 

Conclusion and future directions

André Muricy’s presentation provides a thorough exploration of integrating GoJS with PureScript using the Went library. By harnessing PureScript’s type safety, developers can create robust, interactive diagrams with reduced risk of runtime errors.

As the functional programming community grows, tools like Went pave the way for more sophisticated and reliable web development practices. André’s contribution marks a significant step forward, promising a richer, more secure diagramming experience in PureScript.

 

Additional resources

Check out more from the MeetUp Func Prog Sweden. Func Prog Sweden is the community for anyone interested in functional programming. At the MeetUps the community explore different functional languages like Erlang, Elixir, Haskell, Scala, Clojure, OCaml, F# and more.