diff --git a/packages/webpage-refactor/README.md b/packages/webpage-refactor/README.md
index 7edb5e5..f5ed7f5 100644
--- a/packages/webpage-refactor/README.md
+++ b/packages/webpage-refactor/README.md
@@ -31,10 +31,10 @@ https://github.com/netlify/netlify-plugin-nextjs/#readme
- [x] Extract merge, findPath and aggregatePath functionality into different repos
- [ ] Add functionality like names, etc.
-- [ ] Send to mongo upon completion
+- [x] Send to mongo upon completion
- [ ] Add paths table
- [ ] warn that the paths table is approximate.
- [ ] Push to github
- [ ] Push to netlify
-- [ ] Don't allow further comparisons after completion
+- [x] Don't allow further comparisons after completion
- [ ] Look back at Amazon thing which has been running
diff --git a/packages/webpage-refactor/components/comparisonActuator.js b/packages/webpage-refactor/components/comparisonActuator.js
index 1e898c7..915c342 100644
--- a/packages/webpage-refactor/components/comparisonActuator.js
+++ b/packages/webpage-refactor/components/comparisonActuator.js
@@ -5,20 +5,26 @@ export function ComparisonActuator({
listOfElements,
pairCurrentlyBeingCompared,
moveToNextStep,
+ isListOrdered,
}) {
const initialComparisonString = "x to y";
const [comparisonString, setComparisonString] = useState("x to y");
- const onChangeComparisonString = async (event) =>
- await setComparisonString(event.target.value);
+ const onChangeComparisonString = async (event) => {
+ if (!isListOrdered) {
+ await setComparisonString(event.target.value);
+ }
+ };
const onClickSubmitEvent = (event) => {
// console.log(event.target.value);
- moveToNextStep({
- listOfElements,
- pairCurrentlyBeingCompared,
- comparisonString,
- });
- setComparisonString(initialComparisonString);
+ if (!isListOrdered) {
+ moveToNextStep({
+ listOfElements,
+ pairCurrentlyBeingCompared,
+ comparisonString,
+ });
+ setComparisonString(initialComparisonString);
+ }
};
return (
@@ -29,6 +35,7 @@ export function ComparisonActuator({
{`... is `}
{
console.log(sparkline);
sparklineConcat =
- sparklineConcat +
- " →" +
- sparkline.sparkline.replace("▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁", "");
+ sparklineConcat + " →" + sparkline.sparkline.replace("▁▁▁▁▁▁▁▁▁▁▁▁▁", "");
//alert("▁▁▁▁▁▁▁▁▁▁▁");
}
if (num.asNum) {
@@ -38,64 +37,139 @@ const getEdgeLabel = async (squiggleString) => {
return squiggleString + sparklineConcat; //sparkline;
};
-export function Graph({ listOfElements, links }) {
+const getColors = (n) => {
+ let colors = colormap({
+ colormap: "viridis",
+ nshades: n,
+ format: "hex",
+ alpha: 1,
+ });
+ return colors;
+};
+
+const cutOffLongNames = (string) => {
+ let maxLength = 40;
+ let result;
+ if (string.length < maxLength) {
+ result = string;
+ } else {
+ result = string.slice(0, maxLength - 4);
+ result = result + "...";
+ }
+ return result;
+};
+
+export function Graph({
+ listOfElements,
+ links,
+ isListOrdered,
+ mergeSortOrder,
+}) {
const containerRef = useRef();
- const [visibility, setVisibility] = useState("invisible");
+ const [visibility, setVisibility] = useState(""); /// useState("invisible");
- const callEffect = async (listOfElements, links) => {
- setVisibility("invisible");
- cytoscape.use(spread); // spread
+ const callEffect = async ({
+ listOfElements,
+ links,
+ isListOrdered,
+ mergeSortOrder,
+ }) => {
+ //setVisibility("invisible");
+ let layoutName = "circle"; //
- let nodeElements = listOfElements.map((element) => {
- return { data: { id: element.name } };
+ // cytoscape.use(circle); // spread, circle,
+ let listOfElementsForGraph = isListOrdered
+ ? mergeSortOrder
+ : listOfElements;
+
+ let colors = new Array(listOfElements.length);
+ if (isListOrdered) {
+ colors = getColors(listOfElements.length);
+ }
+
+ let nodeElements = listOfElements.map((element, i) => {
+ return {
+ data: {
+ id: cutOffLongNames(element.name),
+ color: colors[i] || "darkgreen",
+ },
+ };
});
let linkElements = await Promise.all(
links.map(async (link, i) => {
return {
data: {
id: `link-${i}`,
- source: link.source,
- target: link.target,
+ source: cutOffLongNames(link.source),
+ target: cutOffLongNames(link.target),
label: await getEdgeLabel(link.squiggleString),
},
};
})
);
+
+ const cytoscapeStylesheet = [
+ {
+ selector: "node",
+ style: {
+ padding: "25px",
+ shape: "round-rectangle",
+ content: "data(id)",
+ "background-color": "data(color)",
+ "text-wrap": "wrap",
+ //"text-overflow-wrap": "anywhere",
+ "text-max-width": 70,
+ "z-index": 1,
+ },
+ },
+ {
+ selector: "node[id]",
+ style: {
+ label: "data(id)",
+ "font-size": "11",
+ color: "white",
+ "text-halign": "center",
+ "text-valign": "center",
+ "z-index": 1,
+ },
+ },
+ {
+ selector: "edge",
+ style: {
+ "curve-style": "unbundled-bezier",
+ "target-arrow-shape": "vee",
+ width: 1.5,
+ "target-arrow-color": "green",
+ "arrow-scale": 3,
+ "target-arrow-fill": "filled",
+ "text-rotation": "autorotate",
+ "z-index": 0,
+ },
+ },
+ {
+ selector: "edge[label]",
+ style: {
+ label: "data(label)",
+ "font-size": "12",
+
+ "text-background-color": "#f9f9f9",
+ "text-background-opacity": 1,
+ "text-background-padding": "4px",
+
+ "text-border-color": "black",
+ "text-border-style": "solid",
+ "text-border-width": 0.5,
+ "text-border-opacity": 1,
+ "z-index": 3,
+
+ // "text-rotation": "autorotate"
+ },
+ },
+ ];
+
const config = {
container: containerRef.current,
- style: [
- {
- selector: "node",
- style: {
- content: "data(id)",
- "background-color": "darkgreen",
- "text-wrap": "wrap",
- "text-max-width": 200,
- "source-text-offset": 20,
- //"text-valign": "bottom",
- "text-justification": "auto",
- },
- padding: 2,
- },
- {
- selector: "edge",
- style: {
- label: "data(label)", // maps to data.label
- labelColor: "blue",
- "curve-style": "unbundled-bezier",
- "target-arrow-color": "green",
- "arrow-scale": 3,
- "target-arrow-fill": "filled",
- "font-size": 15,
- "line-color": "green",
- "target-arrow-shape": "vee",
- "text-rotation": "autorotate",
- "text-margin-x": +25,
- "text-margin-y": +25,
- padding: 5,
- },
- },
- ],
+ style: cytoscapeStylesheet,
elements: [
/* Dummy data:
{ data: { id: "n1" } },
@@ -107,7 +181,7 @@ export function Graph({ listOfElements, links }) {
...linkElements,
],
layout: {
- name: "spread", // circle, grid, dagre
+ name: layoutName, // circle, grid, dagre
minDist: 10,
//prelayout: false,
// animate: false, // whether to transition the node positions
@@ -117,21 +191,23 @@ export function Graph({ listOfElements, links }) {
userPanningEnabled: false,
};
cytoscape(config);
- setTimeout(() => setVisibility(""), 700);
+ // setTimeout(() => setVisibility(""), 700);
};
useEffect(async () => {
- await callEffect(listOfElements, links);
+ await callEffect({ listOfElements, links, isListOrdered, mergeSortOrder });
// console.log(JSON.stringify(config, null, 10));
}, [listOfElements, links]);
return (