graph drawing tool
Go to file
Kartik K. Agaram bd74e26d0b bugfix: draw edges after nodes they connect
The crash wasn't actually on the second node, it was just
indeterministic.
2023-04-18 22:52:29 -07:00
assets
0000-freewheeling-start
0001-on
0002-vx
0003-scale render a single node 2023-04-17 22:19:28 -07:00
0004-vy
0005-Cursor_node
0006-on.mouse_press keep edges short 2023-04-18 22:16:49 -07:00
0008-Viewport
0009-on.code_change
0010-initialize_editor render a single node 2023-04-17 22:19:28 -07:00
0011-box_height
0012-on.initialize
0013-font
0014-y_of_schema1
0015-line_height
0016-schema1_of_y
0017-on.mouse_release keep edges short 2023-04-18 22:16:49 -07:00
0018-on.update keep edges short 2023-04-18 22:16:49 -07:00
0019-B mock up affordances for moving and resizing 2023-04-17 23:22:01 -07:00
0021-compute_layout keep edges short 2023-04-18 22:16:49 -07:00
0022-on.text_input
0023-on.keychord_press don't crash when zooming out forever 2023-04-17 22:34:50 -07:00
0024-copy_shape
0025-add_thick_line
0026-on.draw keep edges short 2023-04-18 22:16:49 -07:00
0027-Surface baby steps 2023-04-17 21:17:27 -07:00
0028-A bugfix: draw edges after nodes they connect 2023-04-18 22:52:29 -07:00
0030-update_editor_box resize handler seems to be working 2023-04-17 23:55:35 -07:00
0031-Nodes keep edges short 2023-04-18 22:16:49 -07:00
0032-set_mouse_cursor mock up affordances for moving and resizing 2023-04-17 23:22:01 -07:00
0034-sx mock up affordances for moving and resizing 2023-04-17 23:22:01 -07:00
0035-sy mock up affordances for moving and resizing 2023-04-17 23:22:01 -07:00
0036-on_move_bar switch Nodes from array to table 2023-04-18 17:52:19 -07:00
0037-on_resize keep edges short 2023-04-18 22:16:49 -07:00
0039-on_node keep edges short 2023-04-18 22:16:49 -07:00
0040-A1 make move/resize more polished+performant 2023-04-18 00:48:24 -07:00
0041-on_border keep edges short 2023-04-18 22:16:49 -07:00
0044-First_available_id switch Nodes from array to table 2023-04-18 17:52:19 -07:00
0045-next_key switch Nodes from array to table 2023-04-18 17:52:19 -07:00
0046-to_key switch Nodes from array to table 2023-04-18 17:52:19 -07:00
0047-test_to_key switch Nodes from array to table 2023-04-18 17:52:19 -07:00
0049-table.length keep edges short 2023-04-18 22:16:49 -07:00
0050-node_height keep edges short 2023-04-18 22:16:49 -07:00
0051-intersect_with_centroid start drawing edges 2023-04-18 22:43:22 -07:00
0055-y_at_x keep edges short 2023-04-18 22:16:49 -07:00
0056-x_at_y keep edges short 2023-04-18 22:16:49 -07:00
0057-distance_sq keep edges short 2023-04-18 22:16:49 -07:00
0058-centroid start drawing edges 2023-04-18 22:43:22 -07:00
0059-compute_layout_for_edge start drawing edges 2023-04-18 22:43:22 -07:00
LICENSE.txt
Manual_tests.md
MemoryReferenceInfo.lua.0
MemoryReferenceInfo.lua.unused
README.md
app.lua
button.lua
conf.lua
default_map
edit.lua
file.lua
json.lua
keychord.lua
live.lua
main.lua
reference.md
search.lua
select.lua
test.lua
text.lua
text_tests.lua
undo.lua

README.md

LuaML: An experimental markup language and 'browser' for it

Demo of a simple structured editor for formatted text atop an infinite 2D surface that can be panned and zoomed.

For ease of implementation, LuaML documents are always legal Lua objects rather than a first-class language like HTML. A simple example:

{ type='text', data={'hello, world!',} }

Text object data consists of an array of strings, one for each line. No newlines at the moment. (Everything is subject to change.)

You can draw various shapes on the surface:

{type='line', data={0,0, 0,600}},
{type='line', data={0,0, 800,0}},
{type='text', data={'0'}, x=-20,y=-20},
{type='rectangle', x=50,y=50, w=20,h=80, r=1,g=0,b=0},
{type='text', data={'abc', 'def'}, x=150, y=50, w=50,h=50, fg={r=0,g=0.4, b=0.9}},
{type='circle', x=300,y=200, radius=40, r=1,g=0,b=1},
{type='arc', x=0,y=0, radius=50, angle1=0, angle2=math.pi*2/3},
{type='ellipse', x=100,y=100, radiusx=10, radiusy=50},
{type='bezier', data={25,25, 25,125, 75,25, 125,25}},

But most of the design effort so far has focused on the 3 text types:

  • text for runs of text to be line-wrapped over the given width.
  • rows and cols, the only hierarchical types, ways to compose text nodes into various grid layouts.

Some more examples.

Adjust foreground/background color (akin to a div with inline style):

{ type='text', fg={r=1,g=0,b=0}, bg={r=1,g=1,b=0},
  data={'hello, world!'}
}

Two-column text:

{ type='cols', data={
  {type='text', data={'first column'}},
  {type='text', data={'second column'}},
}}

A table with two rows and two columns:

{ type='cols', data={
  { type='rows', data={
    {type='text', data={'abc'}},
    {type='text', data={'def'}},
  }},
  { type='rows', data={
    {type='text', data={'ghi'}},
    {type='text', data={'jkl'}},
  }},
}}

(With the current design, cols of rows seem strictly superior to rows of cols. Column boundaries line up consistently across rows.)

This is still quite incomplete. Come help figure out its future. Currently supported "attributes":

  • fg, bg for color (no blink tag yet)
  • margin (used as margin-left or margin-top depending on whether the parent node has cols or rows respectively)
  • width in pixels (I'd like to add '%' units here.)

Since this is all Lua, unrecognized attributes are silently ignored. In the app itself you'll see attributes like name and doc. (This is a nightmare if you imagine this turning into some sort of long-lived standard with versions and compatibility guarantees. I don't. I just want an app-internal format for creating UIs with very little code.)

LuaML.love is a fork of lines.love, an editor for plain text where you can also seamlessly insert line drawings. Designed above all to be easy to modify and give you early warning if your modifications break something.

Getting started

Install LÖVE. It's just a 5MB download, open-source and extremely well-behaved. I'll assume below that you can invoke it using the love command, but that might vary depending on your OS.

Run this app from the terminal, passing its directory to LÖVE

You'll see a page that's currently hard-coded in the app.

initial view

All text is currently editable. There's a table on the right that will grow and shrink as you add and delete text.

Changes you make are currently not saved. This is just a demo.

To pan, drag the surface around. To increase/decrease zoom, press ctrl+=, ctrl+- respectively. To reset zoom press ctrl+0.

Hacking

To edit formatting you'll need to modify the code for the app. To do this live without restarting the app each time, download the driver app. Here's an example session using a fork of this repo:

making changes without restarting the app

To publish your changes:

  • delete all files with a numeric prefix from the repo, and then
  • move all files with a numeric prefix from the save dir to the repo

Keyboard shortcuts

While editing text:

  • ctrl+f to find patterns within a file
  • ctrl+c to copy, ctrl+x to cut, ctrl+v to paste
  • ctrl+z to undo, ctrl+y to redo
  • ctrl+= to zoom in, ctrl+- to zoom out, ctrl+0 to reset zoom
  • alt+right/alt+left to jump to the next/previous word, respectively
  • mouse drag or shift + movement to select text, ctrl+a to select all

Exclusively tested so far with a US keyboard layout. If you use a different layout, please let me know if things worked, or if you found anything amiss: http://akkartik.name/contact

When cursor is not in an editor:

  • arrow keys pan the surface
  • shift+arrow keys pan faster
    • pagedown and pageup are aliases for shift+down and shift+up respectively

Known issues

  • Both freewheeling apps and the driver for them currently benefit from being launched in terminal windows rather than by being clicked on in a desktop OS. See the driver app for details.

  • No support yet for Unicode graphemes spanning multiple codepoints.

  • No support yet for right-to-left languages.

  • Undo/redo may be sluggish in large files. Large files may grow sluggish in other ways. Works well in all circumstances with files under 50KB.

  • If you kill the process, say by force-quitting because things things get sluggish, you can lose data.

  • Long wrapping lines can't yet distinguish between the cursor at end of one screen line and start of the next, so clicking the mouse to position the cursor can very occasionally do the wrong thing.

  • Can't scroll while selecting text with mouse.

  • No scrollbars yet. That stuff is hard.

Mirrors and Forks

This repo is a fork of lines.love, an editor for plain text where you can also seamlessly insert line drawings. Its immediate upstream is the template repo for freewheeling apps. Updates to it can be downloaded from the following mirrors:

Further forks are encouraged. If you show me your fork, I'll link to it here.

Feedback

Most appreciated.