@@ -5,10 +5,21 @@ import org.jetbrains.kotlinx.dataframe.AnyCol
5
5
import org.jetbrains.kotlinx.dataframe.AnyFrame
6
6
import org.jetbrains.kotlinx.dataframe.AnyRow
7
7
import org.jetbrains.kotlinx.dataframe.DataFrame
8
- import org.jetbrains.kotlinx.dataframe.api.*
8
+ import org.jetbrains.kotlinx.dataframe.api.FormattingDSL
9
+ import org.jetbrains.kotlinx.dataframe.api.RowColFormatter
10
+ import org.jetbrains.kotlinx.dataframe.api.asColumnGroup
11
+ import org.jetbrains.kotlinx.dataframe.api.asNumbers
12
+ import org.jetbrains.kotlinx.dataframe.api.getColumnsWithPaths
13
+ import org.jetbrains.kotlinx.dataframe.api.isColumnGroup
14
+ import org.jetbrains.kotlinx.dataframe.api.isEmpty
15
+ import org.jetbrains.kotlinx.dataframe.api.isNumber
16
+ import org.jetbrains.kotlinx.dataframe.api.isSubtypeOf
17
+ import org.jetbrains.kotlinx.dataframe.api.rows
18
+ import org.jetbrains.kotlinx.dataframe.api.take
9
19
import org.jetbrains.kotlinx.dataframe.columns.BaseColumn
10
20
import org.jetbrains.kotlinx.dataframe.columns.ColumnGroup
11
21
import org.jetbrains.kotlinx.dataframe.columns.ColumnWithPath
22
+ import org.jetbrains.kotlinx.dataframe.columns.depth
12
23
import org.jetbrains.kotlinx.dataframe.impl.DataFrameSize
13
24
import org.jetbrains.kotlinx.dataframe.impl.columns.addPath
14
25
import org.jetbrains.kotlinx.dataframe.impl.renderType
@@ -27,8 +38,7 @@ import java.io.File
27
38
import java.io.InputStreamReader
28
39
import java.net.URL
29
40
import java.nio.file.Path
30
- import java.util.LinkedList
31
- import java.util.Random
41
+ import java.util.*
32
42
import kotlin.io.path.writeText
33
43
34
44
internal val tooltipLimit = 1000
@@ -185,7 +195,7 @@ public fun AnyFrame.toStaticHtml(
185
195
val id = " static_df_${nextTableId()} "
186
196
val flattenedCols = getColumnsWithPaths { cols { ! it.isColumnGroup() }.recursively() }
187
197
val colGrid = getColumnsHeaderGrid()
188
- val borders = colGrid.last().map { it.borders }
198
+ val borders = colGrid.last().map { it.borders - Border . BOTTOM }
189
199
val nestedRowsLimit = configuration.nestedRowsLimit
190
200
191
201
fun StringBuilder.emitTag (tag : String , attributes : String = "", tagContents : StringBuilder .() -> Unit ) {
@@ -282,24 +292,27 @@ private enum class Border(val className: String) {
282
292
BOTTOM (" bottomBorder" );
283
293
}
284
294
285
- private fun Set<Border>.toClass (): String = " class=\" ${joinToString(" " ) { it.className }} \" "
295
+ private fun Set<Border>.toClass (): String =
296
+ if (isEmpty()) " "
297
+ else " class=\" ${joinToString(" " ) { it.className }} \" "
286
298
287
299
private data class ColumnWithPathWithBorder <T >(
288
300
val columnWithPath : ColumnWithPath <T >? = null ,
289
301
val borders : Set <Border > = emptySet(),
290
302
)
291
303
292
- /* * Returns the depth of the most-nested column in this group, starting at 0 */
293
- private fun ColumnGroup <* >.maxDepth (): Int = getColumnsWithPaths { all().recursively() }.maxOf { it.depth() }
304
+ /* * Returns the depth of the most-nested column in this df/group, starting at 0 */
305
+ internal fun AnyFrame.maxDepth (): Int =
306
+ getColumnsWithPaths { all().rec() }.maxOfOrNull { it.depth } ? : 0
294
307
295
308
/* * Returns the max number of columns needed to display this column flattened */
296
- private fun BaseColumn <* >.maxWidth (): Int =
309
+ internal fun BaseColumn <* >.maxWidth (): Int =
297
310
if (this is ColumnGroup <* >) columns().sumOf { it.maxWidth() }.coerceAtLeast(1 )
298
311
else 1
299
312
300
313
/* *
301
314
* Given a [DataFrame], this function returns a depth-first "matrix" containing all columns
302
- * layed out in such a way that they can be used to render the header of a table. The
315
+ * laid out in such a way that they can be used to render the header of a table. The
303
316
* [ColumnWithPathWithBorder.columnWithPath] is `null` when nothing should be rendered in that cell.
304
317
* Borders are included too, also for `null` cells.
305
318
*
@@ -311,8 +324,8 @@ private fun BaseColumn<*>.maxWidth(): Int =
311
324
* ```
312
325
*/
313
326
private fun AnyFrame.getColumnsHeaderGrid (): List <List <ColumnWithPathWithBorder <* >>> {
314
- val colGroup = asColumnGroup(" " )
315
- val maxDepth = colGroup. maxDepth()
327
+ val colGroup = asColumnGroup()
328
+ val maxDepth = maxDepth()
316
329
val maxWidth = colGroup.maxWidth()
317
330
val map =
318
331
MutableList (maxDepth + 1 ) { MutableList (maxWidth) { ColumnWithPathWithBorder <Any ?>() } }
0 commit comments