Skip to content

Commit 04ac85f

Browse files
committed
modifying nested df rendering
1 parent 81d6c7d commit 04ac85f

File tree

3 files changed

+76
-77
lines changed
  • core
    • generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/io
    • src/main/kotlin/org/jetbrains/kotlinx/dataframe/io
  • examples/notebooks/movies

3 files changed

+76
-77
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ internal fun tableJs(columns: List<ColumnDataForJs>, id: Int, rootId: Int, nrow:
108108
val colName = col.renderHeader().escapeForHtmlInJs()
109109
append("{ name: \"$colName\", children: $children, rightAlign: ${col.rightAlign}, values: $values }, \n")
110110

111-
return colIndex
111+
return@appendColWithChildren colIndex
112112
}
113113
columns.forEach { appendColWithChildren(it) }
114114
append("]")
@@ -243,8 +243,7 @@ public fun AnyFrame.toStaticHtml(
243243
is AnyFrame ->
244244
emitTag("details") {
245245
emitTag("summary") {
246-
append("DataFrame ")
247-
append(cellRenderer.content(cellValue, configuration).truncatedContent)
246+
append("DataFrame [${cellValue.size}]")
248247
}
249248
// add the dataframe as a nested table limiting the number of rows if needed
250249
// CSS will not be included here, as it is already included in the main table
@@ -296,6 +295,7 @@ public fun AnyFrame.toStaticHtml(
296295

297296
return DataFrameHtmlData(
298297
body = buildString { emitTable() },
298+
// will hide the table if JS is enabled
299299
script = """
300300
document.getElementById("$id").style.display = "none";
301301
""".trimIndent(),
@@ -622,7 +622,7 @@ internal class DataFrameFormatter(
622622

623623
private fun RenderedContent.addCss(css: String? = null): RenderedContent {
624624
return if (css != null) {
625-
copy(truncatedContent = "<span class=\"$css\">" + truncatedContent + "</span>", isFormatted = true)
625+
copy(truncatedContent = "<span class=\"$css\">$truncatedContent</span>", isFormatted = true)
626626
} else this
627627
}
628628

@@ -631,7 +631,7 @@ internal class DataFrameFormatter(
631631
val ellipsis = "...".ellipsis(str)
632632
if (limit < 4) ellipsis
633633
else {
634-
val len = Math.max(limit - 3, 1)
634+
val len = (limit - 3).coerceAtLeast(1)
635635
RenderedContent.textWithLength(str.substring(0, len).escapeHTML(), len) + ellipsis
636636
}
637637
} else {
@@ -766,7 +766,7 @@ internal class DataFrameFormatter(
766766
val keyLimit = limit - sizeOfValue
767767
if (key.length > keyLimit) {
768768
if (limit > 3) {
769-
(key + "...").truncate(limit).addCss(structuralClass)
769+
("$key...").truncate(limit).addCss(structuralClass)
770770
} else null
771771
} else {
772772
val renderedValue =

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,7 @@ public fun AnyFrame.toStaticHtml(
243243
is AnyFrame ->
244244
emitTag("details") {
245245
emitTag("summary") {
246-
append("DataFrame ")
247-
append(cellRenderer.content(cellValue, configuration).truncatedContent)
246+
append("DataFrame [${cellValue.size}]")
248247
}
249248
// add the dataframe as a nested table limiting the number of rows if needed
250249
// CSS will not be included here, as it is already included in the main table
@@ -623,7 +622,7 @@ internal class DataFrameFormatter(
623622

624623
private fun RenderedContent.addCss(css: String? = null): RenderedContent {
625624
return if (css != null) {
626-
copy(truncatedContent = "<span class=\"$css\">" + truncatedContent + "</span>", isFormatted = true)
625+
copy(truncatedContent = "<span class=\"$css\">$truncatedContent</span>", isFormatted = true)
627626
} else this
628627
}
629628

@@ -632,7 +631,7 @@ internal class DataFrameFormatter(
632631
val ellipsis = "...".ellipsis(str)
633632
if (limit < 4) ellipsis
634633
else {
635-
val len = Math.max(limit - 3, 1)
634+
val len = (limit - 3).coerceAtLeast(1)
636635
RenderedContent.textWithLength(str.substring(0, len).escapeHTML(), len) + ellipsis
637636
}
638637
} else {
@@ -767,7 +766,7 @@ internal class DataFrameFormatter(
767766
val keyLimit = limit - sizeOfValue
768767
if (key.length > keyLimit) {
769768
if (limit > 3) {
770-
(key + "...").truncate(limit).addCss(structuralClass)
769+
("$key...").truncate(limit).addCss(structuralClass)
771770
} else null
772771
} else {
773772
val renderedValue =

0 commit comments

Comments
 (0)