Skip to content

Commit

Permalink
Merge branch 'develop' into revert-6-revert-5-develop
Browse files Browse the repository at this point in the history
  • Loading branch information
MigunovaAnastasia1 committed Oct 31, 2024
2 parents 41886ce + 418f071 commit 0d724f1
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/main/kotlin/view/MainScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ fun MainScreen(viewModel: MainScreenViewModel) {
}) {
Text(text = "CycleSearch", color = MaterialTheme.colorScheme.onSecondary)
}
DropdownMenuItem(onClick = {
expandedAlgorithmsMenu = false
viewModel.runHarmonicCentralityAlgorithm()
}) {
Text(text = "HarmonicCentrality", color = MaterialTheme.colorScheme.onSecondary)
}
}
}
Row(modifier = Modifier.padding(horizontal = 10.dp), horizontalArrangement = Arrangement.SpaceBetween) {
Expand Down
22 changes: 21 additions & 1 deletion src/main/kotlin/viewmodel/MainScreenViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package viewmodel

import androidx.compose.runtime.mutableStateOf
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import databases.FileSystem
import databases.Neo4jRepository
import model.graph.Graph
Expand All @@ -15,6 +16,7 @@ import model.graph.Vertex
var defaultColorLine: Color = Color.Black
var defaultColorVertex: Color = Color.Gray
var defaultStrokeWidth: Float = 4f
var defaultRadius = 25.0.dp

class MainScreenViewModel(private val graph: Graph, private val representationStrategy: RepresentationStrategy) {
val showVerticesLabels = mutableStateOf(false)
Expand All @@ -28,7 +30,10 @@ class MainScreenViewModel(private val graph: Graph, private val representationSt

fun resetGraphView() {
representationStrategy.place(800.0, 600.0, graphViewModel.verticesView.values)
graphViewModel.verticesView.values.forEach { v -> v.color = defaultColorVertex }
graphViewModel.verticesView.values.forEach { v ->
v.color = defaultColorVertex
v.radius = defaultRadius
}
graphViewModel.edgesView.values.forEach { e ->
e.color = defaultColorLine
e.strokeWidth = defaultStrokeWidth
Expand Down Expand Up @@ -194,4 +199,19 @@ class MainScreenViewModel(private val graph: Graph, private val representationSt
return "The vertex with id = $vertexId doesn't have a cycle around it. "
}

fun runHarmonicCentralityAlgorithm(): HashMap<Int, Double> {

val graphForAlgorithm = HarmonicCentrality(graph)
val vertexIdAndIndex: HashMap<Int, Double> = graphForAlgorithm.harmonicCentrality()

resetGraphView()
for(vertex in vertexIdAndIndex) {
graphViewModel.verticesView[vertex.key]?.radius = ((17.0 + vertex.value*30).toInt()).dp
graphViewModel.verticesView[vertex.key]?.color =
Color( red = 255 - (vertex.value*190).toInt(), green = 0, blue = 154 - (vertex.value*110).toInt() )
}
return vertexIdAndIndex

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class CircularPlacementStrategy : RepresentationStrategy {
if (vertices.isEmpty()) {
return
}
val center = Pair(width / 2, height * (3.0/5) )
val center = Pair(width * (4.0/5), height * (3.0/5) )
val angle = 2 * Math.PI / vertices.size

val sorted = vertices.sortedBy { it.label }
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/viewmodel/graph/VertexViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import model.graph.Vertex
import viewmodel.defaultRadius

class VertexViewModel(
x: Dp = 0.dp,
Expand All @@ -15,7 +16,7 @@ class VertexViewModel(
private val v: Vertex,
private val _labelVisible: State<Boolean>,
private val _idVisible: State<Boolean>,
val radius: Dp = 25.dp
var radius: Dp = defaultRadius
) {
private var _x = mutableStateOf(x)
var x: Dp
Expand Down

0 comments on commit 0d724f1

Please sign in to comment.