Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add element_geom(pen, brush, paper) #836

Merged
merged 15 commits into from
Aug 4, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update demo.
  • Loading branch information
OLarionova-HORIS committed Aug 4, 2023
commit 5488813dab92cd617e34765adfc07f7550cda41e
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,70 @@ import demoAndTestShared.parsePlotSpec
class NamedSystemColors {
fun plotSpecList(): List<MutableMap<String, Any>> {
return listOf(
withFlavor(null),
withFlavor("solarized_light"),
withFlavor("solarized_dark"),
withFlavor("solarized_dark", background = "dark_blue"),
pieChart(),
pieChart(flavor = "darcula"),
pieChart(flavor = "solarized_light"),
pieChart(flavor = "solarized_dark"),
pieChart(flavor = "high_contrast_light"),
pieChart(flavor = "high_contrast_dark"),
pieChart(useCustomColors = true),
pieChart(flavor = "darcula", useCustomColors = true)
)
}

private fun withFlavor(flavor: String?, background: String? = null): MutableMap<String, Any> {
private fun pieChart(theme: String = "grey", flavor: String? = null, useCustomColors: Boolean = false ): MutableMap<String, Any> {
val themeSettings = listOf(
"'name': '$theme'",
flavor?.let { "'flavor': '$flavor'" } ?: "",
if (useCustomColors) {
"'geom': { 'pen': 'red', 'brush': 'blue', 'paper': 'green' }"
} else ""
).filter(String::isNotEmpty).joinToString()

val spec = """
{
'data': {
'name': ['pen', 'brush', 'paper']
},
'theme': { $themeSettings },
'ggtitle': { 'text': 'theme=$theme, flavor=$flavor, custom colors=$useCustomColors' },
'kind': 'plot',
'scales': [
{
'aesthetic': 'fill',
'values': ['pen', 'brush', 'paper']
}
],
'layers': [
{
'geom': 'pie',
'stat': 'identity',
'mapping': {
'fill': 'name'
},
'tooltips': 'none',
'labels': {
'lines': ['@name']
},
'color': 'pen'
}
]
}""".trimIndent()
return parsePlotSpec(spec)
}

private fun example(theme: String = "light", flavor: String? = null, background: String? = null): MutableMap<String, Any> {
val themeSettings = listOf(
"'name': '$theme'",
background?.let { "'plot_background': {'fill': '$background', 'blank': false}" } ?: "",
flavor?.let { "'flavor': '$flavor'" } ?: ""
).filter(String::isNotEmpty).joinToString()

val spec = """{
"ggsize": { "width": 400, "height": 200 },
"theme": {
${background?.let { "'plot_background': {'fill': '$background', 'blank': false}" } ?: "" }
${if (background != null && flavor != null) "," else ""}
${flavor?.let { "'flavor': '$flavor'" } ?: ""}
},
"ggtitle": { "text": "theme=$theme, flavor=$flavor
point: \'brush\'+\'paper\'; line: \'pen\'" },
"theme": { $themeSettings },
"kind": "plot",
"layers": [
{
Expand Down