From 8395390a222ee7faf3388aa485b643cbf729fe74 Mon Sep 17 00:00:00 2001 From: Nikita Klimenko Date: Wed, 3 Dec 2025 17:03:14 +0200 Subject: [PATCH] Expand HTML rendering documentation --- .../kotlinx/dataframe/samples/api/Render.kt | 48 --- docs/StardustDocs/topics/toHTML.md | 231 ++++++++++++++- samples/build.gradle.kts | 1 + .../kotlinx/dataframe/samples/api/Render.kt | 273 ++++++++++++++++++ 4 files changed, 502 insertions(+), 51 deletions(-) delete mode 100644 core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/api/Render.kt create mode 100644 samples/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/api/Render.kt diff --git a/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/api/Render.kt b/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/api/Render.kt deleted file mode 100644 index 61e10476f1..0000000000 --- a/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/api/Render.kt +++ /dev/null @@ -1,48 +0,0 @@ -@file:Suppress("ktlint") - -package org.jetbrains.kotlinx.dataframe.samples.api - -import org.jetbrains.kotlinx.dataframe.api.reorderColumnsByName -import org.jetbrains.kotlinx.dataframe.api.sortBy -import org.jetbrains.kotlinx.dataframe.api.sortByDesc -import org.jetbrains.kotlinx.dataframe.explainer.TransformDataFrameExpressions -import org.jetbrains.kotlinx.dataframe.io.DataFrameHtmlData -import org.jetbrains.kotlinx.dataframe.io.DisplayConfiguration -import org.jetbrains.kotlinx.dataframe.io.toHtml -import org.jetbrains.kotlinx.dataframe.io.toStandaloneHtml -import org.junit.Ignore -import org.junit.Test -import java.io.File -import kotlin.io.path.Path - -class Render : TestBase() { - @Test - @TransformDataFrameExpressions - @Ignore - fun useRenderingResult() { - // SampleStart - df.toStandaloneHtml(DisplayConfiguration(rowsLimit = null)).openInBrowser() - df.toStandaloneHtml(DisplayConfiguration(rowsLimit = null)).writeHtml(File("/path/to/file")) - df.toStandaloneHtml(DisplayConfiguration(rowsLimit = null)).writeHtml(Path("/path/to/file")) - // SampleEnd - } - - @Test - fun composeTables() { - // SampleStart - val df1 = df.reorderColumnsByName() - val df2 = df.sortBy { age } - val df3 = df.sortByDesc { age } - - listOf(df1, df2, df3).fold(DataFrameHtmlData.tableDefinitions()) { acc, df -> acc + df.toHtml() } - // SampleEnd - } - - @Test - @TransformDataFrameExpressions - fun configureCellOutput() { - // SampleStart - df.toHtml(DisplayConfiguration(cellContentLimit = -1)) - // SampleEnd - } -} diff --git a/docs/StardustDocs/topics/toHTML.md b/docs/StardustDocs/topics/toHTML.md index 89baa91269..e83fbb4813 100644 --- a/docs/StardustDocs/topics/toHTML.md +++ b/docs/StardustDocs/topics/toHTML.md @@ -2,6 +2,8 @@ +## HTML rendering + `DataFrame` instances can be rendered to HTML. Rendering of hierarchical tables in HTML is supported by JS and CSS definitions that can be found in project resources. @@ -9,6 +11,212 @@ that can be found in project resources. Dataframes can also be formatted before being converted to HTML. See [](format.md) for how to do this. +Besides that, DataFrame provides multiple APIs to customize HTML output. + +### Display images +Values of the `org.jetbrains.kotlinx.dataframe.datatypes.IMG` class are rendered as an `` tag + + + +```kotlin +val htmlData = dataFrameOf( + "kotlinLogo" to columnOf( + IMG("https://kotlin.github.io/dataframe/images/kotlin-logo.svg"), + ), +).toStandaloneHtml() +``` + + + +### Embed pages + +Values of the `org.jetbrains.kotlinx.dataframe.datatypes.IFRAME` class are rendered as an `