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
Add ThemeConfigTest.
  • Loading branch information
OLarionova-HORIS committed Aug 4, 2023
commit ab0c57509d221f9266ffc44a7bf6608d8e5a4b3f
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* Copyright (c) 2023. JetBrains s.r.o.
* Use of this source code is governed by the MIT license that can be found in the LICENSE file.
*/

package org.jetbrains.letsPlot.core.spec.config

import org.jetbrains.letsPlot.commons.values.Color
import kotlin.test.Test
import kotlin.test.assertEquals

class ThemeConfigTest {

@Test
fun default() {
val spec = plotSpec()
val colors = transformToClientPlotConfig(spec).theme.colors()

assertEquals(Color.parseHex("#474747"), colors.pen())
assertEquals(Color.WHITE, colors.paper())
assertEquals(Color.PACIFIC_BLUE, colors.brush())
}

@Test
fun withThemeName() {
val spec = plotSpec(themeName = "none")
val colors = transformToClientPlotConfig(spec).theme.colors()

assertEquals(Color.parseHex("#474747"), colors.pen())
assertEquals(Color.WHITE, colors.paper())
assertEquals(Color.PACIFIC_BLUE, colors.brush())
}

@Test
fun withFlavor() {
val spec = plotSpec(flavorName = "darcula")
val colors = transformToClientPlotConfig(spec).theme.colors()

assertEquals(Color.parseHex("#BBBBBB"), colors.pen())
assertEquals(Color.parseHex("#303030"), colors.paper())
assertEquals(Color.PACIFIC_BLUE, colors.brush())
}

@Test
fun withCustomColors() {
val customColors = "'geom': { 'pen': 'red', 'paper': 'green', 'brush': 'blue' }"
val spec = plotSpec(customColors = customColors)
val colors = transformToClientPlotConfig(spec).theme.colors()

assertEquals(Color.RED, colors.pen())
assertEquals(Color.GREEN, colors.paper())
assertEquals(Color.BLUE, colors.brush())
}

@Test
fun `theme(geom) + flavor = use flavor colors`() {
val customColors = "'geom': { 'pen': 'red', 'paper': 'green', 'brush': 'blue' }"
val spec = plotSpec(flavorName = "darcula", customColors = customColors, flavorOverCustomColors = true)
val colors = transformToClientPlotConfig(spec).theme.colors()

assertEquals(Color.parseHex("#BBBBBB"), colors.pen())
assertEquals(Color.parseHex("#303030"), colors.paper())
assertEquals(Color.PACIFIC_BLUE, colors.brush())
}

@Test
fun `flavor + theme(geom) = use custom colors`() {
val customColors = "'geom': { 'pen': 'red', 'paper': 'green', 'brush': 'blue' }"
val spec = plotSpec(flavorName = "darcula", customColors = customColors, flavorOverCustomColors = false)
val colors = transformToClientPlotConfig(spec).theme.colors()

assertEquals(Color.RED, colors.pen())
assertEquals(Color.GREEN, colors.paper())
assertEquals(Color.BLUE, colors.brush())
}

private fun plotSpec(
themeName: String? = null,
flavorName: String? = null,
customColors: String? = null,
flavorOverCustomColors: Boolean = true
): String {
val themeNameOpts = themeName?.let { "'name': '$themeName'" } ?: ""
val flavorOpts = flavorName?.let { "'flavor': '$flavorName'" } ?: ""

val themeSettings = (listOf(
themeNameOpts
) + if (flavorOverCustomColors) {
listOf(customColors, flavorOpts)
} else {
listOf(flavorOpts, customColors)
}
).filterNot(String?::isNullOrEmpty).joinToString()

return """
{
'theme': { $themeSettings },
'kind': 'plot',
'layers': []
}""".trimIndent()
}
}