August 25th, 2024

From Datalog to SVG

The article addresses challenges in exporting generative algorithm results, introducing a method using Datalog queries and a domain-specific language to create smaller, efficient .grph files that retain graph data.

Read original articleLink Icon
From Datalog to SVG

The article discusses the challenges of exporting generative algorithm results, particularly in the context of vector drawings in SVG format. The author notes that while SVG files are commonly used, they often lose the underlying graph topology, making it difficult to modify the drawing logic later. To address this, the author has developed a method to export graph data using Datalog queries, which allows for a more efficient representation of graph properties and edges. The article details the creation of a graph instance and the use of Datalog to query and export edge properties. Additionally, a domain-specific language (DSL) is introduced for generating SVGs directly from Datalog queries, which retains both the graph data and the drawing logic in a .grph file. This approach results in significantly smaller file sizes compared to SVGs while preserving the necessary information to recreate the drawings. The author emphasizes the utility of using Lisp macros for these tasks, suggesting that this method may be more cumbersome in other programming languages. The article concludes with a note on the experimental nature of the Datalog implementation and hints at future posts that will simplify the DSL.

- The author explores the limitations of SVG files in preserving graph topology.

- A new method for exporting graph data using Datalog queries is introduced.

- A domain-specific language (DSL) is created for generating SVGs from Datalog queries.

- The .grph files are significantly smaller than the corresponding SVG files while retaining essential information.

- The article highlights the advantages of using Lisp macros for generative drawing tasks.

Link Icon 2 comments
By @nabla9 - 3 months
That whole site is a interesting read.
By @tracker1 - 3 months
Nice... a few years ago I worked on a project that needed overlays on a scanned image. There was a huge effort to edit images via server-client calls. I didn't like the approach and when I had some time was able to replace this with SVG in about a day. The scaling to fit the viewport was effectively "free" and so much easier in the end.

This was a React front end, and can't speak highly enough of how well it works with relatively simple dynamic svg rendering.