Pikchr

Possible bug: truncated arc under side-by-side boxes
Login

Possible bug: truncated arc under side-by-side boxes

(1) By Stephan Beal (stephan) on 2020-09-14 06:04:48 [source]

Given:

CW: box "cwal"
line <-
S2: box "s2"
line <-
CL: box "client"
arc -> color red cw from CL.s to CW.s

The arc line is truncated, in that is appears to run off of the image and arrive back into it near the end:

cwal s2 client
CW: box "cwal"
line <-
S2: box "s2"
line <-
CL: box "client"
arc -> color red cw from CL.s to CW.s

Feature or bug? My expectation was that the canvas would expand to encompass the arc.

Sidebar: we definitely need to come up with a way to allow us to click a pikchr to toggle between source and image view, but doing so requires that we somehow embed the original source into the SVG so that JS has access to it, otherwise it's lost when the server converts the pikchr to SVG. That might be as simple as adding something like the following to the svg (untested):

https://developer.mozilla.org/en-US/docs/Web/SVG/Element/metadata

<metadata>
  <pikchr:PIKCHR xmlns:pikchr="https://pikchr.org/svg-metadata-v1">
    <pikchr:src><![CDATA[ ... the script ... ]]></pikchr:src>
  </pikchr:PIKCHR>
</metadata>

i will experiment with that later on.

(2) By Stephan Beal (stephan) on 2020-09-14 06:59:26 in reply to 1 [link] [source]

i will experiment with that [pik src in a metadata tag] later on.

"Works for me":

https://pikchr.org/home/timeline?r=pikchr-src-in-metadata

The original pikchr source survives loading and saving in inkscape, so it's retained in the newly-saved file. There doesn't seem to be a way to see that data directly in inkscape, though, but it does allow setting of its own custom metadata.

But... it's currently always on but should only be emitted if a certain Pik::mFlags bit is set, but how to add such flags to the public API in this tree isn't clear to me. pikchr() already has the param (unused before this branch) for such flags.

(3.1) By Stephan Beal (stephan) on 2020-09-14 07:23:27 edited from 3.0 in reply to 2 [link] [source]

"Works for me":

Finding the proper child element this way in JS is a bit funky, as using CSS-style namespace selectors is always finding nothing via the JS selector API, but it works. To make it less fidgety i had to add an otherwise extraneous CSS class to the pikchr:src metadata node, so accessing the original source looks like the following from the dev console in pikchrshow:

> var s = document.querySelector('svg.pikchr'), m = s.querySelector('metadata')
undefined
> var src = m.querySelector('.pikchr-src')
undefined
> src.textContent
"C: circle fill yellow
down; L: line 0.4
left; arc cw from L.w
right; arc from L.e"

==>

C: circle fill yellow
down; L: line 0.4
left; arc cw from L.w
right; arc from L.e

With this in place, we're just a hop, skip, and a jump away from being able to tap on a pikchr (or adjacent mini-button) to toggle between rendered and source views :).

Edit: it turns out there is a way to select these from JS, but it's funky because HTML5 does not recognize namespaces on nodes, so treats the ":" as part of the name. Selecting them thus requires backslash-escaping the colon:

> document.querySelector('pikchr\\:src').textContent
"C: circle fill yellow
down; L: line 0.4
left; arc cw from L.w
right; arc from L.e"

(4) By Andreas Kupries (akupries) on 2020-09-15 23:06:15 in reply to 1 [link] [source]

From my look at the code arcs are currently not very good with respect to bounding boxes. In other words, they may not yet be taking into account for the overall bounding box of the whole image.

(5) By Stephan Beal (stephan) on 2020-09-15 23:11:07 in reply to 4 [link] [source]

From my look at the code arcs are currently not very good with respect to bounding boxes.

After the above was fixed i did see one arc line in a separate pikchr which was truncated by a few pixels (about half the line width) along the bottom edge, but it wasn't enough to inspire me to bother reporting it :/. i unfortunately don't have the pikchr which demonstrated it anymore.

That's just to say that there may indeed be some room (as it were) to adjust the bounding box.