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.geometry.Size
|
||||||
import androidx.compose.ui.graphics.Path
|
import androidx.compose.ui.graphics.Path
|
||||||
import androidx.compose.ui.graphics.drawscope.drawIntoCanvas
|
import androidx.compose.ui.graphics.drawscope.drawIntoCanvas
|
||||||
import kotlin.math.max
|
import androidx.compose.ui.text.*
|
||||||
|
import androidx.compose.ui.unit.Constraints
|
||||||
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun compareResults(
|
fun compareResults(
|
||||||
|
@ -87,8 +89,8 @@ fun compareResults(
|
||||||
if (!showTableAndLegend.value) {
|
if (!showTableAndLegend.value) {
|
||||||
IntersectionCircles(
|
IntersectionCircles(
|
||||||
glossaryWords.map { it.name },
|
glossaryWords.map { it.name },
|
||||||
codeWords,
|
glossaryWords,
|
||||||
intersectionWords
|
codeWords
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -238,33 +240,111 @@ fun commonWordsDataRow(
|
||||||
cellContent(if (isCommon) "Oui" else "Non", modifier)
|
cellContent(if (isCommon) "Oui" else "Non", modifier)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@OptIn(ExperimentalTextApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun IntersectionCircles(glossaryWords: List<String>, codeWords: List<String>, glossaryCodeWords: List<String>) {
|
fun IntersectionCircles(
|
||||||
val intersectionSize = glossaryCodeWords.size.coerceIn(0, 10) / 10f // Normalize to [0, 1]
|
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
|
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
|
// 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
|
// 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
|
// Draw intersection with clipping
|
||||||
drawIntoCanvas { canvas ->
|
drawIntoCanvas { canvas ->
|
||||||
val path = Path().apply {
|
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.save()
|
||||||
canvas.clipPath(path)
|
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()
|
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