diff --git a/docs/js/stitch-gallery.js b/docs/js/stitch-gallery.js index fc00544f..b98f5853 100644 --- a/docs/js/stitch-gallery.js +++ b/docs/js/stitch-gallery.js @@ -239,8 +239,8 @@ const GF_Random = { // make sure that max(lengthL, lengthR) = lengthAll // The simplified version: if lengthL < lengthAll then lengthR = lengthAll doesn't work well. It generates more R's than L's. // Because: chance(lengthL == lengthAll) = 1/lengthAll and chance(lengthL < lengthAll) = ((lengthAll-1)/lenghtAll). - if (Math.max(lengthL, lengthR ) !== lengthAll) { - if ( Math.floor(Math.random() * 2) === 0) { + if (Math.max(lengthL, lengthR) !== lengthAll) { + if (Math.floor(Math.random() * 2) === 0) { lengthL = lengthAll; } else { lengthR = lengthAll; @@ -312,11 +312,14 @@ const GF_Random = { // I want to keep genRandomStitchList and genRandomStitch as flexible as is. Therefore, construct as below. // Why this display-function, as
also displays stitchArray = genRandomStitchList?
// We want to add the colorcode and the threaddiagram to the list. See p2t.newlegendStitch.
+
+ // Functionality taken from P2T.newLegendStitch, GF_stitches.setcolorcode().
+ // NewLegendStitch does not clean up previous result (document.body.appendChild(figure).
displayRandomStitchList() {
let displayStitch;
let displayElement;
- let threadSvg, colorCodeSvg, figure;
+ let threadSvg, colorCodeWithTwistsSvg;
displayElement = document.getElementById("displayRandomArray");
displayElement.innerHTML = "";
@@ -325,35 +328,87 @@ const GF_Random = {
displayStitch = GF_Random.stitchArray[i];
- // copied from newLegendStitch, as "document.body.appendChild(figure)" does not clean up previous result, and picts to large
- // without "figcaption"
+ // Create picture with thread-diagram.
+
+ let containerWidth = 60;
+ let containerHeight = Math.max(60, displayStitch.length * 10);
- threadSvg = GF_svgP2T.newSVG(40,60);
- GF_svgP2T.newStitch(displayStitch, 0,0, threadSvg,40,60);
+ threadSvg = GF_svgP2T.newSVG(containerWidth, containerHeight);
+ // Overrule viewbox settings from newSVG. Also necessary to line out on bottom of colorcode-element.
+ threadSvg.setAttribute("viewBox", "-10 -10 " + (containerWidth + 12) + " " + (containerHeight + 12));
+ GF_svgP2T.newStitch(displayStitch, 0, 0, threadSvg, containerWidth, containerHeight);
GF_svgP2T.addThreadClasses(threadSvg); // this gives the lines their color
- // copied from GF_stitches.setcolorcode()
- colorCodeSvg = document.createElement("colorCodeSvg");
- colorCodeSvg.innerHTML = `
- `
+ // Create picture with colorCode, extended with twistMarks before and after.
- figure = document.createElement("figure");
- figure.append(threadSvg);
+ colorCodeWithTwistsSvg = GF_svgP2T.newSVG(50, 50);
+ colorCodeWithTwistsSvg = GF_Random.colorCodeWithTwistMarks(displayStitch,colorCodeWithTwistsSvg );
- displayElement.appendChild(figure);
- displayElement.appendChild(colorCodeSvg);
- displayElement.innerHTML += " " + " " + displayStitch;
+ // To display the elements, we have to group them in one element. (If put in separate ID's, we get first the thread-svg's, followed by the CCWT-svg's, followed by the texts.)
+ displayElement.appendChild(threadSvg);
+ displayElement.innerHTML += " ".repeat(5);
+ displayElement.appendChild(colorCodeWithTwistsSvg);
+ displayElement.innerHTML += " ".repeat(5);
+ displayElement.innerHTML += displayStitch;
displayElement.innerHTML += "
";
-
}
},
+ colorCodeWithTwistMarks(randomStitch, colorCodeWithTwistsSvg) {
+
+ function twistMarkerBase(path, swne) {
+ return `