Conversation
| this.graphVisualizer.geometric.edges.push(new GeometricEdge(edge)); | ||
| this.addEdgeToSVG(new GeometricEdge(edge)); | ||
| this.updateSvg(); | ||
| } |
There was a problem hiding this comment.
вот тут, наверное, нужен else и показать алерт, что что-то не в порядке!
There was a problem hiding this comment.
логично, странно, что не добавили алерт, а просто сделали вывод в консоль
добавлю
| } | ||
| else{ | ||
| console.log('Directed'); | ||
| if (this.numberOfSelectedVertices() ===0 ) { |
There was a problem hiding this comment.
странно, что эта проверка есть для ориентированного графа и её нет для неориентированного.
может, вытащить наверх?
There was a problem hiding this comment.
она есть, там идет проверка - что выбелено две вершины, иначе ошибка
alert('Для добавления ребра необходимо выбрать две вершины!') - строка 116
| // добавление ребра (именование вручную) | ||
| if (this.props.edgeNaming === true) { | ||
| let edgeName = prompt('Введите имя дуги:', ''); | ||
| if (edgeName !== '' && edgeName !== null) { | ||
| edge = new DirectedEdge(new Vertex(this.vertexOne.name), new Vertex(this.vertexTwo.name), edgeName); | ||
| } else { | ||
| return; | ||
| } | ||
| } else { | ||
| // добавление ребра (автоматическое именование) | ||
| console.log('adding'); | ||
| if (this.props.namedEdges == true) { | ||
| if (this.graphVisualizer.geometric.edges.length != 0) { | ||
| let edgeNumbers = []; | ||
| for (let i = 0; i < this.graphVisualizer.geometric.edges.length; i++) { | ||
| edgeNumbers[i] = Number(this.graphVisualizer.geometric.edges[i].edge.name); | ||
| } | ||
| let maxNum = Math.max.apply(null, edgeNumbers); | ||
| edge = new DirectedEdge(new Vertex(this.vertexOne.name), new Vertex(this.vertexTwo.name), (maxNum + 1).toString()); | ||
| } else { | ||
| edge = new DirectedEdge(new Vertex(this.vertexOne.name), new Vertex(this.vertexTwo.name), '0'); | ||
| } | ||
| } else { | ||
| // добавленеи неименованных ребер | ||
| edge = new DirectedEdge(new Vertex(this.vertexOne.name), new Vertex(this.vertexTwo.name)); | ||
| } |
There was a problem hiding this comment.
Есть мнение, что вот этот кусок кода повторяет случай с рефлексивным ребром с точностью до имени второй вершины.
Может, сделать метод, который принимает на вход имяВершины1 и имяВершины2 вместо this.vertexOne/Two.name ?
| this.graphVisualizer.geometric.edges.push(new GeometricEdge(edge)); | ||
| this.addEdgeToSVG(new GeometricEdge(edge)); | ||
| this.updateSvg(); | ||
| else |
There was a problem hiding this comment.
else if this.numberOfSelectedVertices() === 2
{
....
}
else alert(как в случае с неориентированным)
| console.log(edge); | ||
| this.props.graph.addEdge(edge); | ||
| this.graphVisualizer.geometric.edges.push(new GeometricEdge(edge)); | ||
| this.addEdgeToSVG(new GeometricEdge(edge)); | ||
| this.updateSvg();*/ |
There was a problem hiding this comment.
выглядит как дублирующийся кусок кода, который тоже можно вытащить в отдельный метод
изменен метод addEdge для добавление дуги-петли и обратной дуги для орг графа