omniJS bug: Copy as JS on subGraphs loses subGraph status+structure

The current build of Edit > Copy As > JavaScript is not yet copying subGraphs successfully.

If we try it on a collapsible subGraph like this:

it generates code which uses the Group constructor rather than the Subgraph constructor,

var g6 = new Group([g1, g2, g3, g4, g5])

so the reconstructed graphic is no longer collapsible:

(It also:

  1. Reverses the order of graphics, so that the background board conceals the subgraph shapes themselves
  2. Loses the horizontal text alignment

(but these latter two bugs, or at least their close relatives, have already been reported in other threads)

A further pair of related bugs with omniJS and subGraphs:

  1. Copy As > JS (unlike Copy As > AS) loses all the subgraph contents if the subGraph is collapsed
  2. The .graphics property fails to return Subgraph contents when .collapsed = true

Bug 1 details:

If we start with a subGraph like:

and then collapse it,

We find that while Edit > Copy As > AppleScript can successfully copy and regenerate a working subgraph, and all its contained graphics, from either its collapsed or expanded states, Copy As > Javascript is, in this build, losing all the contained graphics (in addition to copying the structure as a Group rather than a Subgraph).

Successful AS copy example:
(caveat: line 2 of the AS code currently has to be edited from
tell canvas of front window
to
tell front layer of canvas of front window)

[details=AppleScript copy of collapsed subGraph]```AppleScript
tell application id “com.omnigroup.OmniGraffle7”
–tell canvas of front window – (Edited to following line from output of Edit > Copy As > AS)
tell front layer of canvas of front window
make new shape at end of graphics with properties {size:{131.811025, 104.881891}, text:{alignment:center, color:{0.0, 0.0, 0.0}, font:“HelveticaNeue”, text:“Generate”}, origin:{142.812994, -333.58268}, magnets:{{0, 1}, {0, -1}}}
make new shape at end of graphics with properties {size:{131.811025, 104.881891}, text:{alignment:center, color:{0.0, 0.0, 0.0}, font:“HelveticaNeue”, text:“Minimum -> Graphic”}, origin:{215.503939, -192.559059}, magnets:{{0, 1}, {0, -1}}}
make new shape at end of graphics with properties {size:{131.811025, 104.881891}, text:{alignment:center, color:{0.0, 0.0, 0.0}, font:“HelveticaNeue”, text:“Full -> Minimum”}, origin:{65.692914, -192.559059}, magnets:{{0, 1}, {0, -1}}}
make new line at end of graphics with properties {point list:{{208.71850634118, -228.700789374554}, {131.598426268448, -192.55905972552}}}
make new line at end of graphics with properties {point list:{{208.71850634118, -228.700789374554}, {281.409451086436, -192.55905972552}}}
assemble (graphics -5 through -1) with subgraph
set properties of subgraph -1 to {collapsed:true}
set properties of background of subgraph -1 to {corner radius:5, size:{100.0, 50.0}, text:{alignment:center, text:“Subgraph”}, text placement:top, origin:{56.692914, -358.58268}}
end tell
end tell



Edit > Copy As > **JavaScript** in contrast, loses all of the contents of the subGraph, retaining only its outer frame, if used when the subGraph is collapsed. The following code has failed to copy any of the subGraph contents:

var canvas = document.windows[0].selection.canvas
var g1 = canvas.newShape()
var g2 = new Group([g1])
g1.text = “Subgraph”
g1.cornerRadius = 5
g1.textSize = 12
g1.geometry = new Rect(56.69, -358.58, 100.00, 50.00)
g1.textVerticalPlacement = VerticalTextPlacement.Top
g1.fontName = “Helvetica”
g2.collapsed = true
g2.geometry = new Rect(56.69, -358.58, 100.00, 50.00)


(This is in addition to the other bug in which it uses the wrong constructor, see earlier in the thread).

**Bug 2 details**:

The deeper bug may be that the **.graphics** property of **Subgraphs** (inherited from Group) currently returns only a single-item list [just the containing frame], and loses all of the content graphics, when the subGraph is collapsed.

When **.collapsed === false** the **.graphics** property succeeds:

<img src="/uploads/default/original/2X/8/82df662fa5f87be9c3f93e9052fe9d68f286ae8f.png" width="507" height="334">

but when **.collapsed === true**, **.graphics** fails to find and return the contents of the same Subgraph – only the outer containing shape is successfully returned - contact with and knowledge of the remaining shapes is lost:

<img src="/uploads/default/original/2X/6/64fdf65cfef9a0be0687aa045f0aef760d61990a.png" width="507" height="334">

And if we try to work around this by temporarily expanding the subgraph, in order to read the full array of graphics, in the way that the AppleScript interface is able to, unfortunately:

  1. We run into a 5th bug in current omniJS interactions with Subgraph (the .collapsed setter leaves the property value, and the canvas state, in the opposite of the state that the script requested and the return value claims)
  2. Even if we use a workaround to this fifth bug, and successfully expand the subGraph at run-time, this turns out not, alas, to give us immediate access to the full .graphics array.

UPDATE - there is in fact a workaround here. I just forgot to resample the .graphics property (refire the getter) after forcing the subGraph into a temporarily open state by asking it to be closed (see bug 5)

Thanks for reporting this bug!

With r292846, OmniGraffle 7.5 will emit the correct code to generate subgraphs, including any child objects that might be collapsed. (There is a new .subgraphics property which is used to access child objects whether or not they’re currently visible.)

1 Like

Many thanks for working on this at the weekend – it’s getting much better.

A couple of remaining glitches - if we:

  1. Copy As JS from a collapsed version,
  2. use the code to generate a new copy of the collapsed subgraph
  3. expand the copy in the GUI

Then there seem to be two problems (perhaps related to the code’s shape-build sequence ?)

  1. Link lines scrambled
  2. shadows lost or hidden

Test file sent to support [OG #1805009]

1 Like

In the case of the shadows, perhaps this is a gap in the API, which doesn’t yet let us write or read these shadow options:

If the subgroup shapes are set to Shadow Immediately Below,

then the JS Copy will fall back to the omniJS default, which seems to be Shadow Below Layer