Skip to content

Commit 40caf4e

Browse files
formatHeader kdocs
1 parent 029a71c commit 40caf4e

File tree

1 file changed

+38
-14
lines changed

1 file changed

+38
-14
lines changed

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/formatHeader.kt

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ public class HeaderFormatClause<T, C>(
5050
// region DataFrame.formatHeader
5151

5252
/**
53+
* **Experimental API. It may be changed in the future.**
54+
*
5355
* Selects [columns] whose headers should be formatted.
5456
*
5557
* This does not immediately produce a [FormattedFrame]; instead it returns a [HeaderFormatClause]
@@ -59,29 +61,37 @@ public fun <T, C> DataFrame<T>.formatHeader(columns: ColumnsSelector<T, C>): Hea
5961
HeaderFormatClause(this, columns)
6062

6163
/**
62-
* Selects headers by [column names][String].
64+
* **Experimental API. It may be changed in the future.**
6365
*
64-
* Equivalent to `formatHeader { columns.toColumnSet() }`.
66+
* Selects [columns] whose headers should be formatted.
6567
*
66-
* Examples:
67-
* ```kt
68-
* // center a single column header
69-
* df.formatHeader("age").with { attr("text-align", "center") }
70-
* ```
68+
* This does not immediately produce a [FormattedFrame]; instead it returns a [HeaderFormatClause]
69+
* which must be finalized using [HeaderFormatClause.with].
7170
*/
7271
public fun <T> DataFrame<T>.formatHeader(vararg columns: String): HeaderFormatClause<T, Any?> =
7372
formatHeader { columns.toColumnSet() }
7473

75-
/** Formats all column headers. */
74+
/**
75+
* **Experimental API. It may be changed in the future.**
76+
*
77+
* Selects all columns for header formatting.
78+
*
79+
* This does not immediately produce a [FormattedFrame]; instead it returns a [HeaderFormatClause]
80+
* which must be finalized using [HeaderFormatClause.with].
81+
*/
7682
public fun <T> DataFrame<T>.formatHeader(): HeaderFormatClause<T, Any?> = HeaderFormatClause(this)
7783

78-
7984
// endregion
8085

8186
// region FormattedFrame.formatHeader
8287

8388
/**
84-
* Continue header formatting on an already [FormattedFrame], preserving existing cell- and header formatting.
89+
* **Experimental API. It may be changed in the future.**
90+
*
91+
* Selects [columns] whose headers should be formatted.
92+
*
93+
* This does not immediately produce a [FormattedFrame]; instead it returns a [HeaderFormatClause]
94+
* which must be finalized using [HeaderFormatClause.with].
8595
*/
8696
public fun <T, C> FormattedFrame<T>.formatHeader(columns: ColumnsSelector<T, C>): HeaderFormatClause<T, C> =
8797
HeaderFormatClause(
@@ -91,11 +101,25 @@ public fun <T, C> FormattedFrame<T>.formatHeader(columns: ColumnsSelector<T, C>)
91101
oldCellFormatter = formatter,
92102
)
93103

94-
/** Selects headers by [column names][String] on an existing [FormattedFrame]. */
104+
/**
105+
* **Experimental API. It may be changed in the future.**
106+
*
107+
* Selects [columns] whose headers should be formatted.
108+
*
109+
* This does not immediately produce a [FormattedFrame]; instead it returns a [HeaderFormatClause]
110+
* which must be finalized using [HeaderFormatClause.with].
111+
*/
95112
public fun <T> FormattedFrame<T>.formatHeader(vararg columns: String): HeaderFormatClause<T, Any?> =
96113
formatHeader { columns.toColumnSet() }
97114

98-
/** Selects all headers on an existing [FormattedFrame]. */
115+
/**
116+
* **Experimental API. It may be changed in the future.**
117+
*
118+
* Selects all columns for header formatting.
119+
*
120+
* This does not immediately produce a [FormattedFrame]; instead it returns a [HeaderFormatClause]
121+
* which must be finalized using [HeaderFormatClause.with].
122+
*/
99123
public fun <T> FormattedFrame<T>.formatHeader(): HeaderFormatClause<T, Any?> =
100124
HeaderFormatClause(
101125
df = df,
@@ -108,6 +132,8 @@ public fun <T> FormattedFrame<T>.formatHeader(): HeaderFormatClause<T, Any?> =
108132
// region terminal operations
109133

110134
/**
135+
* **Experimental API. It may be changed in the future.**
136+
*
111137
* Creates a new [FormattedFrame] that uses the specified [HeaderColFormatter] to format the selected headers.
112138
*
113139
* Header formatting is additive: attributes from already-applied header formatters are combined with the newly
@@ -128,14 +154,12 @@ public fun <T, C> HeaderFormatClause<T, C>.with(formatter: HeaderColFormatter<C>
128154
.map { p -> ColumnWithPath(df[p], p) }
129155
.map { parentCol ->
130156
if (parentCol.path in selectedPaths) {
131-
@Suppress("UNCHECKED_CAST")
132157
oldHeader?.invoke(FormattingDsl, parentCol as ColumnWithPath<C>)
133158
} else null
134159
}
135160
.reduceOrNull(CellAttributes?::and)
136161
} else null
137162

138-
@Suppress("UNCHECKED_CAST")
139163
val typedCol = col as ColumnWithPath<C>
140164

141165
val existingAttr = oldHeader?.invoke(FormattingDsl, typedCol)

0 commit comments

Comments
 (0)