omniJS canvas.layoutInfo.direction - legibility and effects?

Perhaps this is not quite ready for testing yet ?

We can perform equality tests on the members of the HierarchicalDirection enum, but we can’t, I think, derive human-legible strings for them (for the Console etc) so at the moment, to find out which one we are looking at, it seems we would have to run 2-4 tests to find out ? (I may well have missed something)

Setting the direction property of Canvas.layout.Info does realign the axis of Automatic Layout, but not at the moment, as far as I can see, consistently in the direction that is suggested by the docs or the name of the enum key. These results seem unexpected to me (click the expansion triangles to see the result).

Docs: "Root of the hierarchy is at the top and tree extends downwards."


Docs: "Root of the hierarchy is at the right and tree extends leftwards."


Docs: "Root of the hierarchy is at the bottom and tree extends upwards."


Docs: "Root of the hierarchy is at the left and tree extends rightwards."


NOTE: **Reading** the value of Canvas.layoutInfo.direction with something like:
['Top', 'Left', 'Right', 'Bottom']
.map(k => direction === HierarchicalDirection[k])

yields the same pattern of unexpected mappings:

Top -> ‘Bottom’
Left -> ‘Top’
Right -> ‘Left’
Bottom -> ‘Right’

Which suggests, perhaps, a 0 vs 1 indexing problem in the reading of the enum ? ( The value sequence is right, but the specific values are all “off by one” in the same direction).

So the interim fix for reading / setting layout directions is just a translation function which maps one key onto another, along the lines of:

// tmp :: String -> String
const tmp = k => ({
    Left: 'Top',
    Top: 'Bottom',
    Right: 'Left',
    Bottom: 'Right'
})[k];

and the ordering relationships between the enum elements are:

Left < Top < Right < Bottom

So assuming the tmp function above, we can correctly derive the name of a direction (for example, the current layout direction setting) with something like:

// directionName :: OG HierarchicalDirection -> String
const directionName = d =>
    d < HierarchicalDirection[tmp('Right')] ? (
        d < HierarchicalDirection[tmp('Top')] ? (
            'Left'
        ) : 'Top'
    ) : d < HierarchicalDirection[tmp('Bottom')] ? (
        'Right'
    ) : 'Bottom';

Another very minor but conceivably related puzzle in the canvas.layoutinfo enums:

There are four diagram types in the GUI, and the Layout. Just in case its of any significance in the light of the other issue above, I notice that their indexing suddenly goes discontinuous (apparently off by one) at the last moment, so:

[object LayoutType: 0] Hierarchical
[object LayoutType: 1] Force-directed
[object LayoutType: 2] Circular

but, then, rather than finishing in this sequence on [object LayoutType: 3], we get a jump straight to 4

[object LayoutType: 4] Radial

(There is probably some perfectly rational explanation, and it may be quite irrelevant to the other issue :-)

And while still on the omniJS scripting of layouts:

Layout type does seem to be writable (tho the API docs modestly describe it as read-only at the moment), the only limitation seems to be that:

the GUI type-choice widget doesn’t immediately update (until after an omniJS-scripted change) until the next type that a layout is triggered.

(very minor lint - I’m impressed by what can already be scripted)