BugFix Venn Diagram

main
Cemal Odabasioglu 2024-02-20 10:55:25 +01:00
parent 244f5a7e80
commit a5069545bc
2 changed files with 58 additions and 30 deletions

View File

@ -29,6 +29,7 @@ import androidx.compose.ui.graphics.drawscope.drawIntoCanvas
import androidx.compose.ui.graphics.toArgb import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.text.* import androidx.compose.ui.text.*
import androidx.compose.ui.unit.Constraints import androidx.compose.ui.unit.Constraints
import androidx.compose.ui.unit.sp
@Composable @Composable
@ -90,7 +91,7 @@ fun compareResults(
// Show the Venn diagram only if showTableAndLegend is false // Show the Venn diagram only if showTableAndLegend is false
if (!showTableAndLegend.value) { if (!showTableAndLegend.value) {
IntersectionCircles( IntersectionCircles(
glossaryWords.map { it.name }, intersectionWords,
glossaryWords, glossaryWords,
codeWords codeWords
) )
@ -259,8 +260,7 @@ fun IntersectionCircles(
val circleRadius = 300f // Fixed radius for both circles val circleRadius = 300f // Fixed radius for both circles
val circleDistance = (1 - intersectionSize) * 2 * circleRadius // Distance between the centers of the circles val circleDistance = (1 - intersectionSize) * 2 * circleRadius // Distance between the centers of the circles
val textMeasurer = rememberTextMeasurer( val textMeasurer = rememberTextMeasurer()
)
Row ( Row (
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth(),
@ -310,42 +310,68 @@ fun IntersectionCircles(
val glossaryCircleCenter = Offset(x = size.width / 2 - circleDistance / 2, y = size.height / 2) val glossaryCircleCenter = Offset(x = size.width / 2 - circleDistance / 2, y = size.height / 2)
val codeCircleCenter = Offset(x = size.width / 2 + circleDistance / 2, y = size.height / 2) val codeCircleCenter = Offset(x = size.width / 2 + circleDistance / 2, y = size.height / 2)
var xOffset = 0f
var xOffsetIntersection = 0f
var doNotWrite = false
var doNotWriteIntersect = false
if (intersectionWords.size > 6) {
doNotWrite = true
xOffsetIntersection = size.width / 2 - circleDistance / 2
} else if (intersectionWords.size > 4) {
xOffset = codeCircleCenter.x + 80f
xOffsetIntersection = size.width / 2 - circleDistance / 2
} else if(intersectionWords.size > 1) {
xOffset = codeCircleCenter.x -20f
xOffsetIntersection = size.width / 2 - circleDistance / 2 + circleRadius / 1.5f
} else {
doNotWriteIntersect = true
xOffset = codeCircleCenter.x - 80f
xOffsetIntersection = size.width / 2 - circleDistance / 2 + circleRadius / 2
}
glossaryWordsSubset.forEachIndexed { index, word -> glossaryWordsSubset.forEachIndexed { index, word ->
drawIntoCanvas { _ -> drawIntoCanvas { _ ->
drawText( if (!doNotWrite) {
textMeasurer, drawText(
word, textMeasurer,
Offset( word,
(glossaryCircleCenter.x - circleRadius / 1.5).toFloat(), Offset(
glossaryCircleCenter.y - circleRadius / 2 + index * 30f glossaryCircleCenter.x - circleRadius / 2,
), glossaryCircleCenter.y - circleRadius / 2 + index * 30f
) ),
)
}
} }
} }
codeWordsSubset.forEachIndexed { index, word -> codeWordsSubset.forEachIndexed { index, word ->
drawIntoCanvas { _ -> drawIntoCanvas { _ ->
drawText(
textMeasurer, if (!doNotWrite) {
word, drawText(
Offset( textMeasurer,
codeCircleCenter.x, word,
codeCircleCenter.y - circleRadius / 2 + index * 30f Offset(
), xOffset, // Subtract half the text width from the x-coordinate
) codeCircleCenter.y - circleRadius / 2 + index * 30f
)
)
}
} }
} }
intersectionWords.forEachIndexed { index, word -> intersectionWords.forEachIndexed { index, word ->
drawIntoCanvas { _ -> drawIntoCanvas { _ ->
drawText( if (!doNotWriteIntersect) {
textMeasurer, drawText(
word, textMeasurer,
Offset( word,
size.width / 2 - circleDistance / 2 + circleRadius / 2, Offset(
size.height / 2 - circleRadius / 2 + index * 30f xOffsetIntersection,
), size.height / 2 - circleRadius / 2 + index * 30f
) ),
)
}
} }
} }
@ -375,7 +401,7 @@ fun drawLegend(canvasWidth: Float, canvasHeight: Float) {
legendItems.forEachIndexed { index, legendItem -> legendItems.forEachIndexed { index, legendItem ->
drawRect( drawRect(
color = legendItem.color, color = legendItem.color,
topLeft = legendStartOffset + Offset(x=0f, y = index * legendItemHeight), topLeft = legendStartOffset + Offset(x=-50f, y = index * legendItemHeight),
size = Size(20f, 20f) size = Size(20f, 20f)
) )
drawIntoCanvas { _ -> drawIntoCanvas { _ ->
@ -383,7 +409,7 @@ fun drawLegend(canvasWidth: Float, canvasHeight: Float) {
textMeasurer, textMeasurer,
legendItem.label, legendItem.label,
Offset( Offset(
-90f, -150f,
legendStartOffset.y + index * legendItemHeight legendStartOffset.y + index * legendItemHeight
), ),
) )

View File

@ -1,6 +1,8 @@
package main package main
import androidx.compose.ui.text.toLowerCase
import java.io.File import java.io.File
import java.util.*
fun delStrings(line : String) : String { fun delStrings(line : String) : String {
@ -52,7 +54,7 @@ fun parser(fileName : String) : MutableMap<String, Int> {
val regex = "[^a-zA-Z^éà]".toRegex() val regex = "[^a-zA-Z^éà]".toRegex()
val array = mutableListOf<String>() val array = mutableListOf<String>()
val line = delStrings(takeOnlyJs(fileName)).replace(regex, " ") val line = delStrings(takeOnlyJs(fileName)).replace(regex, " ").lowercase()
line.split(delimiter1).forEach { line.split(delimiter1).forEach {
if (it != "") { if (it != "") {