Added glossary words, code words, intersection words to the Ven Diagram
parent
89c31c5c31
commit
ae6876022c
|
@ -25,7 +25,9 @@ import androidx.compose.ui.geometry.Rect
|
|||
import androidx.compose.ui.geometry.Size
|
||||
import androidx.compose.ui.graphics.Path
|
||||
import androidx.compose.ui.graphics.drawscope.drawIntoCanvas
|
||||
import kotlin.math.max
|
||||
import androidx.compose.ui.text.*
|
||||
import androidx.compose.ui.unit.Constraints
|
||||
|
||||
|
||||
@Composable
|
||||
fun compareResults(
|
||||
|
@ -87,8 +89,8 @@ fun compareResults(
|
|||
if (!showTableAndLegend.value) {
|
||||
IntersectionCircles(
|
||||
glossaryWords.map { it.name },
|
||||
codeWords,
|
||||
intersectionWords
|
||||
glossaryWords,
|
||||
codeWords
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -238,33 +240,111 @@ fun commonWordsDataRow(
|
|||
cellContent(if (isCommon) "Oui" else "Non", modifier)
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalTextApi::class)
|
||||
@Composable
|
||||
fun IntersectionCircles(glossaryWords: List<String>, codeWords: List<String>, glossaryCodeWords: List<String>) {
|
||||
val intersectionSize = glossaryCodeWords.size.coerceIn(0, 10) / 10f // Normalize to [0, 1]
|
||||
fun IntersectionCircles(
|
||||
glossaryCodeWords: List<String>,
|
||||
glossaryWords: List<Word>,
|
||||
codeWords: List<String>
|
||||
) {
|
||||
// Take up to 10 words for each category
|
||||
val glossaryWordsSubset = glossaryWords.take(10).map { it.name }
|
||||
val codeWordsSubset = codeWords.take(10)
|
||||
val intersectionWords = glossaryCodeWords.take(10)
|
||||
|
||||
val circleRadius = 150f // Fixed radius for both circles
|
||||
val intersectionSize = intersectionWords.size / 10f // Normalize to [0, 1]
|
||||
|
||||
val circleRadius = 300f // Fixed radius for both circles
|
||||
val circleDistance = (1 - intersectionSize) * 2 * circleRadius // Distance between the centers of the circles
|
||||
|
||||
Canvas(modifier = Modifier.size(300.dp)) {
|
||||
val textMeasurer = rememberTextMeasurer()
|
||||
|
||||
Canvas(modifier = Modifier.size(500.dp)) {
|
||||
// Draw glossary circle
|
||||
drawCircle(color = Color(0xFFA1C084), center = Offset(x = size.width / 2 - circleDistance / 2, y = size.height / 2), radius = circleRadius)
|
||||
drawCircle(
|
||||
color = Color(0xFFA1C084),
|
||||
center = Offset(x = size.width / 2 - circleDistance / 2, y = size.height / 2),
|
||||
radius = circleRadius
|
||||
)
|
||||
|
||||
// Draw code circle
|
||||
drawCircle(color = Color(0xFFD9B504), center = Offset(x = size.width / 2 + circleDistance / 2, y = size.height / 2), radius = circleRadius)
|
||||
drawCircle(
|
||||
color = Color(0xFFE9C46A),
|
||||
center = Offset(x = size.width / 2 + circleDistance / 2, y = size.height / 2),
|
||||
radius = circleRadius
|
||||
)
|
||||
|
||||
|
||||
|
||||
// Draw intersection with clipping
|
||||
drawIntoCanvas { canvas ->
|
||||
val path = Path().apply {
|
||||
addOval(Rect(center = Offset(x = size.width / 2 - circleDistance / 2, y = size.height / 2), radius = circleRadius))
|
||||
addOval(
|
||||
Rect(
|
||||
center = Offset(x = size.width / 2 - circleDistance / 2, y = size.height / 2),
|
||||
radius = circleRadius
|
||||
)
|
||||
)
|
||||
}
|
||||
canvas.save()
|
||||
canvas.clipPath(path)
|
||||
drawCircle(color = Color(0xFF6E7271), center = Offset(x = size.width / 2 + circleDistance / 2, y = size.height / 2), radius = circleRadius)
|
||||
drawCircle(
|
||||
color = Color(0xFF6E7271),
|
||||
center = Offset(x = size.width / 2 + circleDistance / 2, y = size.height / 2),
|
||||
radius = circleRadius
|
||||
)
|
||||
canvas.restore()
|
||||
}
|
||||
|
||||
// Draw words on the circles
|
||||
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)
|
||||
|
||||
glossaryWordsSubset.forEachIndexed { index, word ->
|
||||
drawIntoCanvas { _ ->
|
||||
drawText(
|
||||
textMeasurer,
|
||||
word,
|
||||
Offset(
|
||||
(glossaryCircleCenter.x - circleRadius / 1.5).toFloat(),
|
||||
glossaryCircleCenter.y - circleRadius / 2 + index * 20f
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
codeWordsSubset.forEachIndexed { index, word ->
|
||||
drawIntoCanvas { _ ->
|
||||
drawText(
|
||||
textMeasurer,
|
||||
word,
|
||||
Offset(
|
||||
codeCircleCenter.x,
|
||||
codeCircleCenter.y - circleRadius / 2 + index * 20f
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
intersectionWords.forEachIndexed { index, word ->
|
||||
drawIntoCanvas { _ ->
|
||||
drawText(
|
||||
textMeasurer,
|
||||
word,
|
||||
Offset(
|
||||
size.width / 2 - circleDistance / 2 + circleRadius / 2,
|
||||
size.height / 2 - circleRadius / 2 + index * 20f
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun vennDiagramLegend() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue