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
Show file tree
Hide file tree
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
Use ColorTheme colors as default in NamedSystemColors.
  • Loading branch information
OLarionova-HORIS committed Aug 4, 2023
commit 80b80680dd11f207127d6f52042a8c7483b65deb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@

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

import org.jetbrains.letsPlot.commons.intern.json.getString
import org.jetbrains.letsPlot.core.plot.base.Aes
import org.jetbrains.letsPlot.core.plot.base.DataFrame
import org.jetbrains.letsPlot.core.plot.base.GeomKind
import org.jetbrains.letsPlot.core.plot.base.Transform
import org.jetbrains.letsPlot.core.plot.base.data.DataFrameUtil
import org.jetbrains.letsPlot.core.plot.builder.assemble.PlotFacets
import org.jetbrains.letsPlot.core.plot.builder.data.OrderOptionUtil
import org.jetbrains.letsPlot.core.plot.builder.defaultTheme.ThemeFlavor
import org.jetbrains.letsPlot.core.plot.builder.presentation.DefaultFontFamilyRegistry
import org.jetbrains.letsPlot.core.plot.builder.scale.MapperProvider
import org.jetbrains.letsPlot.core.plot.builder.scale.ScaleProvider
import org.jetbrains.letsPlot.core.spec.*
Expand Down Expand Up @@ -62,9 +63,16 @@ abstract class PlotConfig(
sharedData = ConfigUtil.createDataFrame(get(DATA))

// update the color option converter with system named colors including flavors
val flavorTheme = getMap(Option.Plot.THEME).getString(Option.Theme.FLAVOR)?.let(ThemeFlavor.Companion::forName)
val colorConverter = NamedSystemColorOptionConverter(NamedSystemColors(flavorTheme))
AesOptionConversion.updateWith(colorConverter)
run {
val themeConfig = ThemeConfig(getMap(Option.Plot.THEME), DefaultFontFamilyRegistry())
val colorConverter = NamedSystemColorOptionConverter(
NamedSystemColors(
colorTheme = themeConfig.theme.colors(),
themeFlavor = themeConfig.themeFlavor
)
)
AesOptionConversion.updateWith(colorConverter)
}

layerConfigs = createLayerConfigs(sharedData, isClientSide)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class ThemeConfig constructor(
) {

val theme: Theme
val themeFlavor: ThemeFlavor?

init {

Expand All @@ -35,13 +36,9 @@ class ThemeConfig constructor(
LegendThemeConfig.convertValue(key, value)
}

val themeFlavorOptions = baselineValues.values.let {
val flavorName = themeSettings.getString(Option.Theme.FLAVOR)
if (flavorName != null) {
ThemeFlavor.forName(flavorName).updateColors(it)
} else {
it
}
val themeFlavorOptions = baselineValues.values.let { baseOptions ->
themeFlavor = themeSettings.getString(Option.Theme.FLAVOR)?.let(ThemeFlavor.Companion::forName)
themeFlavor?.updateColors(baseOptions) ?: baseOptions
}

theme = DefaultTheme(themeFlavorOptions, fontFamilyRegistry, userOptions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@
package org.jetbrains.letsPlot.core.spec.conversion

import org.jetbrains.letsPlot.commons.values.Color
import org.jetbrains.letsPlot.core.plot.base.theme.ColorTheme
import org.jetbrains.letsPlot.core.plot.builder.defaultTheme.ThemeFlavor

class NamedSystemColors(private val themeFlavor: ThemeFlavor?) {

class NamedSystemColors(
private val colorTheme: ColorTheme,
private val themeFlavor: ThemeFlavor?
) {
fun getColor(id: String): Color? {
val systemColor = toSystemColor(id) ?: return null
return when (systemColor) {
SystemColor.PEN -> themeFlavor?.color ?: Color.BLACK
SystemColor.PAPER -> themeFlavor?.fill ?: Color.WHITE
SystemColor.BRUSH -> Color.PACIFIC_BLUE
SystemColor.PEN -> themeFlavor?.color ?: colorTheme.pen()
SystemColor.PAPER -> themeFlavor?.fill ?: colorTheme.paper()
SystemColor.BRUSH -> colorTheme.brush()
}
}

Expand Down