Skip to content

Commit 6b2ca7b

Browse files
committed
Fix for not being able to provide text color for .null, .structure, and .numbers #251
1 parent 9af7421 commit 6b2ca7b

File tree

1 file changed

+18
-3
lines changed
  • core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/io

1 file changed

+18
-3
lines changed

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,15 @@ internal fun AnyFrame.toHtmlData(
171171
}
172172
val renderConfig = configuration.copy(decimalFormat = format)
173173
val contents = values.map {
174-
val value = it[col]
174+
val value = col[it]
175175
val content = value.toDataFrameLikeOrNull()
176176
if (content != null) {
177177
val df = content.df()
178178
if (df.isEmpty()) {
179179
HtmlContent("", null)
180180
} else {
181181
val id = nextTableId()
182-
queue.add(RenderingQueueItem(df, id, content.configuration(defaultConfiguration)))
182+
queue += RenderingQueueItem(df, id, content.configuration(defaultConfiguration))
183183
DataFrameReference(id, df.size)
184184
}
185185
} else {
@@ -189,6 +189,21 @@ internal fun AnyFrame.toHtmlData(
189189
?.invoke(FormattingDsl, it, col)
190190
?.attributes()
191191
?.ifEmpty { null }
192+
?.flatMap {
193+
if (it.first == "color") {
194+
// override all --text-color* variables that
195+
// are used to color text of .numbers, .null, etc., inside DataFrame
196+
listOf(
197+
it,
198+
"--text-color" to "${it.second} !important",
199+
"--text-color-dark" to "${it.second} !important",
200+
"--text-color-pale" to "${it.second} !important",
201+
"--text-color-medium" to "${it.second} !important",
202+
)
203+
} else {
204+
listOf(it)
205+
}
206+
}
192207
?.joinToString(";") { "${it.first}:${it.second}" }
193208
HtmlContent(html, style)
194209
}
@@ -207,7 +222,7 @@ internal fun AnyFrame.toHtmlData(
207222
}
208223

209224
val rootId = nextTableId()
210-
queue.add(RenderingQueueItem(this, rootId, defaultConfiguration))
225+
queue += RenderingQueueItem(this, rootId, defaultConfiguration)
211226
while (!queue.isEmpty()) {
212227
val (nextDf, nextId, configuration) = queue.pop()
213228
val rowsLimit = if (nextId == rootId) configuration.rowsLimit else configuration.nestedRowsLimit

0 commit comments

Comments
 (0)