diff --git a/src/main/kotlin/main/Compare.kt b/src/main/kotlin/main/Compare.kt index 51ab1ab..ad652f0 100644 --- a/src/main/kotlin/main/Compare.kt +++ b/src/main/kotlin/main/Compare.kt @@ -29,6 +29,7 @@ import androidx.compose.ui.graphics.drawscope.drawIntoCanvas import androidx.compose.ui.graphics.toArgb import androidx.compose.ui.text.* import androidx.compose.ui.unit.Constraints +import androidx.compose.ui.unit.sp @Composable @@ -90,7 +91,7 @@ fun compareResults( // Show the Venn diagram only if showTableAndLegend is false if (!showTableAndLegend.value) { IntersectionCircles( - glossaryWords.map { it.name }, + intersectionWords, glossaryWords, codeWords ) @@ -259,8 +260,7 @@ fun IntersectionCircles( val circleRadius = 300f // Fixed radius for both circles val circleDistance = (1 - intersectionSize) * 2 * circleRadius // Distance between the centers of the circles - val textMeasurer = rememberTextMeasurer( - ) + val textMeasurer = rememberTextMeasurer() Row ( modifier = Modifier.fillMaxWidth(), @@ -310,42 +310,68 @@ fun IntersectionCircles( 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) + 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 -> drawIntoCanvas { _ -> - drawText( - textMeasurer, - word, - Offset( - (glossaryCircleCenter.x - circleRadius / 1.5).toFloat(), - glossaryCircleCenter.y - circleRadius / 2 + index * 30f - ), - ) + if (!doNotWrite) { + drawText( + textMeasurer, + word, + Offset( + glossaryCircleCenter.x - circleRadius / 2, + glossaryCircleCenter.y - circleRadius / 2 + index * 30f + ), + ) + } } } codeWordsSubset.forEachIndexed { index, word -> drawIntoCanvas { _ -> - drawText( - textMeasurer, - word, - Offset( - codeCircleCenter.x, - codeCircleCenter.y - circleRadius / 2 + index * 30f - ), - ) + + if (!doNotWrite) { + drawText( + textMeasurer, + word, + Offset( + xOffset, // Subtract half the text width from the x-coordinate + codeCircleCenter.y - circleRadius / 2 + index * 30f + ) + ) + } } } intersectionWords.forEachIndexed { index, word -> drawIntoCanvas { _ -> - drawText( - textMeasurer, - word, - Offset( - size.width / 2 - circleDistance / 2 + circleRadius / 2, - size.height / 2 - circleRadius / 2 + index * 30f - ), - ) + if (!doNotWriteIntersect) { + drawText( + textMeasurer, + word, + Offset( + xOffsetIntersection, + size.height / 2 - circleRadius / 2 + index * 30f + ), + ) + } } } @@ -375,7 +401,7 @@ fun drawLegend(canvasWidth: Float, canvasHeight: Float) { legendItems.forEachIndexed { index, legendItem -> drawRect( color = legendItem.color, - topLeft = legendStartOffset + Offset(x=0f, y = index * legendItemHeight), + topLeft = legendStartOffset + Offset(x=-50f, y = index * legendItemHeight), size = Size(20f, 20f) ) drawIntoCanvas { _ -> @@ -383,7 +409,7 @@ fun drawLegend(canvasWidth: Float, canvasHeight: Float) { textMeasurer, legendItem.label, Offset( - -90f, + -150f, legendStartOffset.y + index * legendItemHeight ), ) diff --git a/src/main/kotlin/main/parser.kt b/src/main/kotlin/main/parser.kt index f2ddf35..333a5dd 100644 --- a/src/main/kotlin/main/parser.kt +++ b/src/main/kotlin/main/parser.kt @@ -1,6 +1,8 @@ package main +import androidx.compose.ui.text.toLowerCase import java.io.File +import java.util.* fun delStrings(line : String) : String { @@ -52,7 +54,7 @@ fun parser(fileName : String) : MutableMap { val regex = "[^a-zA-Z^éà]".toRegex() val array = mutableListOf() - val line = delStrings(takeOnlyJs(fileName)).replace(regex, " ") + val line = delStrings(takeOnlyJs(fileName)).replace(regex, " ").lowercase() line.split(delimiter1).forEach { if (it != "") {