Result is malformed and not what was expected

Open
#42 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
30/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
julia
Domain
frontend

Research direction

Start with the README examples and the signature and behavior of the m function, then reproduce the pretty_stitches call alongside the standalone svg_stitch(5, 10, 1, '/') result. Trace how nested arguments and the uses... splat are serialized; done means the generated SVG contains both symbols, all 2176 use elements in the intended location, balanced tags, and correct attribute values.

Written by the indexing model from the issue text.

Description

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.

Dominant language
Julia
Stars
105
Forks
12
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from JuliaWeb/Hyperscript.jl

All issues in JuliaWeb/Hyperscript.jl

Similar issues

More Julia issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.