From b796d18054812d3106c29fd2194028deea9b0247 Mon Sep 17 00:00:00 2001 From: Bining Long Date: Wed, 27 Jul 2022 19:32:17 +0000 Subject: [PATCH 1/2] Style "WrittenQuestion" component --- .../components/WrittenQuestion/styles.scss | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/src/apps/Examinations/components/WrittenQuestion/styles.scss b/app/src/apps/Examinations/components/WrittenQuestion/styles.scss index e69de29b..5a3d8016 100644 --- a/app/src/apps/Examinations/components/WrittenQuestion/styles.scss +++ b/app/src/apps/Examinations/components/WrittenQuestion/styles.scss @@ -0,0 +1,10 @@ +input { + height: 2rem; + width: 66rem; + text-indent: 10px; + border-style: solid; + border-radius: 0.6rem; + border-width: 0.1rem; + border-color: #c0c0c0; + margin: 1rem 0rem; +} From 74db1cb20c1c07deaea859de433fc31001d1ef8f Mon Sep 17 00:00:00 2001 From: Bining Long Date: Thu, 4 Aug 2022 19:51:34 +0000 Subject: [PATCH 2/2] Initial graph class implementation --- app/src/apps/Graphs/Graph.svelte | 25 +++++++++++++++++++++ app/src/apps/Graphs/lib/Edge.js | 8 ++++++- app/src/apps/Graphs/lib/Graph.js | 36 ++++++++++++++++++++++++++++++- app/src/apps/Graphs/lib/Vertex.js | 8 ++++++- 4 files changed, 74 insertions(+), 3 deletions(-) diff --git a/app/src/apps/Graphs/Graph.svelte b/app/src/apps/Graphs/Graph.svelte index 5aac4e38..c77f321f 100644 --- a/app/src/apps/Graphs/Graph.svelte +++ b/app/src/apps/Graphs/Graph.svelte @@ -2,6 +2,7 @@ import { onMount } from "svelte"; import * as d3 from "d3"; import "./styles.scss"; + import Graph from "./lib/Graph"; let element; @@ -13,6 +14,9 @@ { source: 1, target: 2 }, ]; + // initial + let graph = new Graph(nodes, links); + // TODO make this a component take width and height as props? const width = 800; const height = 600; @@ -52,6 +56,11 @@ let coordinates = d3.pointer(e, e.currentTarget); let newNode = { x: coordinates[0], y: coordinates[1], id: ++lastNodeId }; nodes.push(newNode); + + //test-1 + graph.addNode(newNode); + console.log(graph.nodes); + restart(); } }; @@ -71,12 +80,24 @@ }); e.preventDefault(); + + //test-3 + console.log(d); + graph.deleteNode(d); + console.log(graph.nodes, graph.links); + restart(); }; const removeEdge = (e, d) => { links.splice(links.indexOf(d), 1); e.preventDefault(); + + //test-4 + console.log(d); + graph.deleteEdge(d); + console.log(graph.links); + restart(); }; @@ -141,6 +162,10 @@ let newLink = { source: mousedownNode, target: d }; links.push(newLink); + + //test-2 + graph.addEdge(newLink); + console.log(graph.links); }; const keydown = (e) => { diff --git a/app/src/apps/Graphs/lib/Edge.js b/app/src/apps/Graphs/lib/Edge.js index 3b5d83b2..faf4460e 100644 --- a/app/src/apps/Graphs/lib/Edge.js +++ b/app/src/apps/Graphs/lib/Edge.js @@ -1,3 +1,9 @@ -class Edge {} +class Edge { + edge; + + constructor(edge) { + this.edge = edge; + } +} export { Edge as default }; diff --git a/app/src/apps/Graphs/lib/Graph.js b/app/src/apps/Graphs/lib/Graph.js index 321aa393..dacc7bc1 100644 --- a/app/src/apps/Graphs/lib/Graph.js +++ b/app/src/apps/Graphs/lib/Graph.js @@ -1,3 +1,37 @@ -class Graph {} +import Vertex from "./Vertex"; +import Edge from "./Edge"; + +class Graph { + nodes; + links; + + constructor(nodes, links) { + this.nodes = []; + this.links = []; + nodes.forEach((n) => this.nodes.push(new Vertex(n))); + links.forEach((l) => this.links.push(new Edge(l))); + } + + addNode(newNode) { + this.nodes.push(new Vertex(newNode)); + } + + addEdge(newEdge) { + this.links.push(new Edge(newEdge)); + } + + deleteNode(delNode) { + this.nodes = this.nodes.filter((n) => n.vertex.id != delNode.id); + this.links = this.links.filter( + (l) => l.edge.source.id != delNode.id && l.edge.target.id != delNode.id + ); + } + + deleteEdge(delEdge) { + this.links = this.links.filter( + (l) => l.edge.source != delEdge.source || l.edge.target != delEdge.target + ); + } +} export { Graph as default }; diff --git a/app/src/apps/Graphs/lib/Vertex.js b/app/src/apps/Graphs/lib/Vertex.js index da09744b..7afd789b 100644 --- a/app/src/apps/Graphs/lib/Vertex.js +++ b/app/src/apps/Graphs/lib/Vertex.js @@ -1,3 +1,9 @@ -class Vertex {} +class Vertex { + vertex; + + constructor(vertex) { + this.vertex = vertex; + } +} export { Vertex as default };