Skip to content

Commit 40c0962

Browse files
committed
removed copying cellFormatter to DisplayConfiguration of nested dataframes in conversion to HTML
1 parent 97c4ec2 commit 40c0962

File tree

2 files changed

+21
-19
lines changed
  • core/src
    • main/kotlin/org/jetbrains/kotlinx/dataframe/io
    • test/kotlin/org/jetbrains/kotlinx/dataframe/api

2 files changed

+21
-19
lines changed

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/io/html.kt

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -179,17 +179,17 @@ internal fun AnyFrame.toHtmlData(
179179
val renderConfig = configuration.copy(decimalFormat = format)
180180
val contents = values.map { row ->
181181
val value = col[row]
182-
// val dfLikeContent = value.toDataFrameLikeOrNull()
183-
// if (dfLikeContent != null) {
184-
// val df = dfLikeContent.df()
185-
// if (df.isEmpty()) {
186-
// HtmlContent("", null)
187-
// } else {
188-
// val id = nextTableId()
189-
// queue += RenderingQueueItem(df, id, dfLikeContent.configuration(defaultConfiguration))
190-
// DataFrameReference(id, df.size)
191-
// }
192-
// } else {
182+
val dfLikeContent = value.toDataFrameLikeOrNull()
183+
if (dfLikeContent != null) {
184+
val df = dfLikeContent.df()
185+
if (df.isEmpty()) {
186+
HtmlContent("", null)
187+
} else {
188+
val id = nextTableId()
189+
queue += RenderingQueueItem(df, id, dfLikeContent.configuration(defaultConfiguration))
190+
DataFrameReference(id, df.size)
191+
}
192+
} else {
193193
val html = formatter.format(
194194
value = downsizeBufferedImageIfNeeded(value, renderConfig),
195195
renderer = cellRenderer,
@@ -232,7 +232,7 @@ internal fun AnyFrame.toHtmlData(
232232
?.entries
233233
?.joinToString(";") { "${it.key}:${it.value}" }
234234
HtmlContent(html, style)
235-
// }
235+
}
236236
}
237237
val nested = if (col is ColumnGroup<*>) {
238238
col.columns().map {
@@ -275,7 +275,7 @@ private fun Any?.toDataFrameLikeOrNull(): DataFrameLike? =
275275
when (this) {
276276
is AnyFrame -> {
277277
object : DataFrameLike {
278-
override fun configuration(default: DisplayConfiguration) = default
278+
override fun configuration(default: DisplayConfiguration) = default.copy(cellFormatter = null)
279279

280280
override fun df(): AnyFrame = this@toDataFrameLikeOrNull
281281
}

core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/format.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ package org.jetbrains.kotlinx.dataframe.api
22

33
import io.kotest.matchers.shouldBe
44
import io.kotest.matchers.shouldNotBe
5-
import org.jetbrains.kotlinx.dataframe.alsoDebug
65
import org.jetbrains.kotlinx.dataframe.api.FormattingDsl.blue
76
import org.jetbrains.kotlinx.dataframe.api.FormattingDsl.red
87
import org.jetbrains.kotlinx.dataframe.api.FormattingDsl.rgb
8+
import org.jetbrains.kotlinx.dataframe.io.DataFrameHtmlData
99
import org.jetbrains.kotlinx.dataframe.io.DisplayConfiguration
1010
import org.jetbrains.kotlinx.dataframe.samples.api.TestBase
1111
import org.jetbrains.kotlinx.dataframe.samples.api.age
@@ -314,6 +314,7 @@ class FormatTests : TestBase() {
314314
formatted::class.simpleName shouldBe "FormattedFrame"
315315
}
316316

317+
// Issue #982
317318
@Suppress("ktlint:standard:argument-list-wrapping")
318319
@Test
319320
fun `formatting a column shouldn't affect nested columns with the same name`() {
@@ -331,11 +332,12 @@ class FormatTests : TestBase() {
331332
.group("city").into("cityGroup")
332333
.rename("cityCopy").into("city")
333334

334-
df.alsoDebug()
335+
val formatted = df.format("city").with { bold and italic and textColor(green) }
336+
val html =
337+
formatted.toStandaloneHtml() + // expand the nested dataframes so we can see the difference
338+
DataFrameHtmlData(script = "document.querySelectorAll('a.expander').forEach(a => a.click());")
335339

336-
df.format().with { background(black) }.toStandaloneHtml().openInBrowser()
337-
338-
// affects city, cityGroup.city, and group[*].city
339-
df.format("city").with { bold and italic and textColor(green) }.toStandaloneHtml().openInBrowser()
340+
html.toString().split("color:#00ff00").size - 1 shouldBe 12
341+
html.toString().split("font-style:italic").size - 1 shouldBe 6
340342
}
341343
}

0 commit comments

Comments
 (0)