commonMain.org.jetbrains.letsPlot.skia.builderLW.MonolithicSkiaLW.kt Maven / Gradle / Ivy
/*
* 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.skia.builderLW
import org.jetbrains.letsPlot.commons.geometry.DoubleVector
import org.jetbrains.letsPlot.core.plot.builder.FigureBuildInfo
import org.jetbrains.letsPlot.core.util.MonolithicCommon
import org.jetbrains.letsPlot.datamodel.svg.dom.SvgSvgElement
import org.jetbrains.letsPlot.datamodel.svg.dom.SvgTextElement
/**
* "lightweight" - no JComponents or Views are created here.
*/
object MonolithicSkiaLW {
fun buildPlotFromProcessedSpecs(
plotSpec: MutableMap,
plotSize: DoubleVector?,
computationMessagesHandler: (List) -> Unit
): ViewModel {
val buildResult = MonolithicCommon.buildPlotsFromProcessedSpecs(plotSpec, plotSize)
if (buildResult is MonolithicCommon.PlotsBuildResult.Error) {
return SimpleModel(createErrorSvgText(buildResult.error))
}
val success = buildResult as MonolithicCommon.PlotsBuildResult.Success
val computationMessages = success.buildInfos.flatMap(FigureBuildInfo::computationMessages)
computationMessagesHandler(computationMessages)
require(success.buildInfos.size == 1) { "GGBunch is not supported." }
val buildInfo = success.buildInfos.single()
return FigureToViewModel.eval(buildInfo)
}
private fun createErrorSvgText(s: String): SvgSvgElement {
return SvgSvgElement().apply {
children().add(
SvgTextElement(s)
)
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy