From 4fff45801ef74a3cd3ca35919f1f37cb6543a0a3 Mon Sep 17 00:00:00 2001 From: Adam Novak Date: Mon, 16 Sep 2024 10:56:14 -0400 Subject: [PATCH 1/3] Make curves going the same way use a consistent Z order --- src/util/tubemap.js | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/util/tubemap.js b/src/util/tubemap.js index 471d041..a52fc91 100644 --- a/src/util/tubemap.js +++ b/src/util/tubemap.js @@ -4027,7 +4027,9 @@ function drawTrackCurves(type, groupTrack) { // Group track curves based on if they have the same start and end node myTrackCurves.forEach((curve) => { - const key = `${curve.nodeStart}-${curve.nodeEnd}`; + // We're going to split this back into numbers so we should not use - as a separator. + // TODO: Do we actually get negative oriented node numbers in here? + const key = `${curve.nodeStart},${curve.nodeEnd}`; if (!groupedCurves[key]) { groupedCurves[key] = []; } @@ -4074,9 +4076,36 @@ function drawTrackCurves(type, groupTrack) { }) }); + // Rebuild one flat list of curves ordered by group and then using the within-group sort. + let groupKeys = []; + for (let key in groupedCurves) { + groupKeys.push(key); + } + groupKeys.sort(function(a, b) { + let aParts = a.split(",").map(parseInt); + let bParts = b.split(",").map(parseInt); + if (aParts[0] < bParts[0]) { + return -1; + } else if (aParts[0] > bParts[0]) { + return 1; + } else { + if (aParts[1] < bParts[1]) { + return -1; + } else if (aParts[1] > bParts[1]) { + return 1; + } else { + return 0; + } + } + }) + let flattenedGroups = []; + for (let key of groupKeys) { + flattenedGroups = flattenedGroups.concat(groupedCurves[key]); + } + groupTrack .selectAll("trackCurves") - .data(trackCurves) + .data(flattenedGroups) .enter() .append("path") .attr("d", (d) => d.path) From dce95982896c0c083253b0461e88b3498d9442b1 Mon Sep 17 00:00:00 2001 From: Adam Novak Date: Mon, 16 Sep 2024 11:17:54 -0400 Subject: [PATCH 2/3] Adapt tests to new deduplicated SVGs --- src/end-to-end.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/end-to-end.test.js b/src/end-to-end.test.js index 2ac04be..ce6b55e 100644 --- a/src/end-to-end.test.js +++ b/src/end-to-end.test.js @@ -294,7 +294,7 @@ describe("When we wait for it to load", () => { // See if correct svg rendered let svg = document.getElementById("svg"); expect(svg).toBeTruthy(); - expect(svg.getElementsByTagName("title").length).toEqual(65); + expect(svg.getElementsByTagName("title").length).toEqual(50); }); it("draws the right SVG for cactus multiple reads", async () => { @@ -332,7 +332,7 @@ describe("When we wait for it to load", () => { // See if correct svg rendered let svg = document.getElementById("svg"); expect(svg).toBeTruthy(); - expect(svg.getElementsByTagName("title").length).toEqual(23); + expect(svg.getElementsByTagName("title").length).toEqual(22); }); }); From 2f852957084a1fb4a1a637c28e8d1d80613a9bca Mon Sep 17 00:00:00 2001 From: Adam Novak Date: Mon, 16 Sep 2024 11:18:47 -0400 Subject: [PATCH 3/3] Make variable name more descriptive --- src/util/tubemap.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/util/tubemap.js b/src/util/tubemap.js index a52fc91..304dc61 100644 --- a/src/util/tubemap.js +++ b/src/util/tubemap.js @@ -4019,14 +4019,14 @@ function defineSVGPatterns() { function drawTrackCurves(type, groupTrack) { - const myTrackCurves = trackCurves.filter( + const filteredTrackCurves = trackCurves.filter( filterObjectByAttribute("type", type) ); const groupedCurves = {}; // Group track curves based on if they have the same start and end node - myTrackCurves.forEach((curve) => { + filteredTrackCurves.forEach((curve) => { // We're going to split this back into numbers so we should not use - as a separator. // TODO: Do we actually get negative oriented node numbers in here? const key = `${curve.nodeStart},${curve.nodeEnd}`;