Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Result is malformed and not what was expected #42

Open
MarkNahabedian opened this issue Oct 20, 2022 · 0 comments
Open

Result is malformed and not what was expected #42

MarkNahabedian opened this issue Oct 20, 2022 · 0 comments

Comments

@MarkNahabedian
Copy link

I'm having a problem with HyperScript.jl.

This function

function pretty_stitches(image_stitches, flip_right_to_left::Bool)
    # image_stitches should be the top_image_stitches or bottom_image_stitches
    # of a TabletWeavingPattern.
    stitch_width = 5
    stitch_length = 10
    stitch_diameter = 1
    uses = []
    function use(row, col, color, slant)
	push!(uses,
	      m("use",
		href = slant == '/' ? "#stitch1" : "#stitch2",
		x="$(col * stitch_width)mm",
		y="$(row * stitch_length)mm",
		width="$(stitch_width)mm",
		height="$(stitch_length)mm",
		style="stroke: none; fill: $(color)"))
    end
    for (rownum, row) in enumerate(image_stitches)
	for (colnum, stitch) in enumerate(row)
	    (color, slant) = stitch
	    use(rownum, colnum, color, slant)
	end
    end
    println(length(uses))
    m("svg", 
      viewBox="0 0 $(stitch_width * length(image_stitches[1])) $(stitch_length * length(image_stitches))",
      m("g",
        m("symbol", id="stitch1",
    	  preserveAspectRatio="xMinYMin",
    	  viewBox="0 0 $(stitch_width) $(stitch_length)",
    	  refX="0", refY="0",
    	  svg_stitch(stitch_width, stitch_length, stitch_diameter, '/';)),
        m("symbol", id="stitch2",
    	  preserveAspectRatio="xMinYMin",
    	  viewBox="0 0 $(stitch_width) $(stitch_length)",
    	  refX="0", refY="0",
    	  svg_stitch(stitch_width, stitch_length, stitch_diameter, '\\';)),
        uses...)
      )
end

(you can focus on the Hyperscript calls to generate SVG at the end) produces this SVG:

<svg viewBox="0 0 80 1360">
  <g>
    <symbol refX="0" viewBox="0 0 5 10" refY="0" id="stitch1" preserveAspectRatio="xMinYMin">
      <g>
        <path style="stroke-width: 1px; vector-effect: non-scaling-stroke" d="M 0.9569057743101286 9.703069233026724 L 4.956905774310129 0.7030692330267239 A 0.5 0.5 0 0 0 4.043094225" ⋯ 259507 bytes ⋯ "B{N0f8}(1.0,0.0,0.0)" width="5mm" y="1360mm" />
        <use height="10mm" href="#stitch1" x="75mm" style="stroke: none; fill: RGB{N0f8}(1.0,0.0,0.0)" width="5mm" y="1360mm" />
        <use height="10mm" href="#stitch1" x="80mm" style="stroke: none; fill: RGB{N0f8}(1.0,0.0,0.0)" width="5mm" y="1360mm" />
      </g>
    </svg>

(which has been stringified and reformatted for readability).

Note that it also genrates the printed output

`uses` has 2176 elements.

The call

string(svg_stitch(5, 10, 1, '/';))

returns

"<path style="stroke-width: 1px; vector-effect: non-scaling-stroke" d="M 0.9569057743101286 9.703069233026724 L 4.956905774310129 0.7030692330267239 A 0.5 0.5 0 0 0 4.043094225689871 0.29693076697327614 L 0.04309422568987137 9.296930766973276 A 0.5 0.5 0 0 0 0.9569057743101286 9.703069233026724" />"

or more readably

<g>
  <path style="stroke-width: 1px; vector-effect: non-scaling-stroke"
        d="M 0.9569057743101286 9.703069233026724 L 4.956905774310129 0.7030692330267239 A 0.5 0.5 0 0 0 4.043094225689871 0.29693076697327614 L 0.04309422568987137 9.296930766973276 A 0.5 0.5 0 0 0 0.9569057743101286 9.703069233026724" />
</g>

That is what the content of each of the symbols should look like.

Why do the close tags in the output of pretty_stitches not balance?

Where is the second symbol element?

Why are the use elements nested within the symbol's group rather
than after the symbol?

Why are there only two use elements when there should be 2176?

Why do the attributes of an element appear in a different order in the SVG than in the source code? Maybe use OrderedDict?

Perhaps I'm misusing the m function? My use is consistent with the examplesin the README file, but not with its function signature.

I prefer the do syntax that the NativeSVG package allows for, but that package is apparently no longer maintained.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant