@@ -8,6 +8,11 @@ import org.jetbrains.kotlinx.dataframe.RowValueFilter
8
8
import org.jetbrains.kotlinx.dataframe.annotations.AccessApiOverload
9
9
import org.jetbrains.kotlinx.dataframe.columns.ColumnReference
10
10
import org.jetbrains.kotlinx.dataframe.columns.toColumnSet
11
+ import org.jetbrains.kotlinx.dataframe.documentation.DocumentationUrls
12
+ import org.jetbrains.kotlinx.dataframe.documentation.DslGrammarLink
13
+ import org.jetbrains.kotlinx.dataframe.documentation.ExcludeFromSources
14
+ import org.jetbrains.kotlinx.dataframe.documentation.LineBreak
15
+ import org.jetbrains.kotlinx.dataframe.documentation.SelectingColumns
11
16
import org.jetbrains.kotlinx.dataframe.impl.api.MergedAttributes
12
17
import org.jetbrains.kotlinx.dataframe.impl.api.SingleAttribute
13
18
import org.jetbrains.kotlinx.dataframe.impl.api.encode
@@ -22,12 +27,91 @@ import kotlin.reflect.KProperty
22
27
23
28
// region DataFrame
24
29
30
+ /* *
31
+ * Formats the specified [columns\] or cells within the [DataFrame] such that
32
+ * they have specific attributes applied to them when rendering the dataframe to HTML.
33
+ *
34
+ * This function does not immediately produce a [FormattedFrame], but instead it selects the columns to be formatted
35
+ * and returns a [FormatClause] which serves as an intermediate step.
36
+ *
37
+ * @include [SelectingColumns.ColumnGroupsAndNestedColumnsMention]
38
+ *
39
+ * See [Selecting Columns][FormatSelectingColumns].
40
+ *
41
+ * The [FormatClause] allows to further narrow down the selection to individual cells
42
+ * by selecting only certain rows, using [where][FormatClause.where],
43
+ * and then finally specify how to format the cells using
44
+ * [with][FormatClause.with] or [perRowCol][FormatClause.perRowCol].
45
+ *
46
+ * Check out the [Grammar].
47
+ *
48
+ * For more information: {@include [DocumentationUrls.Format]}
49
+ */
50
+ internal interface FormatDocs {
51
+
52
+ /* *
53
+ * {@comment Version of [SelectingColumns] with correctly filled in examples}
54
+ * @include [SelectingColumns] {@include [SetFormatOperationArg]}
55
+ */
56
+ interface FormatSelectingColumns
57
+
58
+ /* *
59
+ * ## Format Operation Grammar
60
+ * {@include [LineBreak]}
61
+ * {@include [DslGrammarLink]}
62
+ * {@include [LineBreak]}
63
+ *
64
+ * TODO
65
+ */
66
+ interface Grammar
67
+ }
68
+
69
+ /* * {@set [SelectingColumns.OPERATION] [format][format]} */
70
+ @ExcludeFromSources
71
+ private interface SetFormatOperationArg
72
+
73
+ /* *
74
+ * @include [FormatDocs]
75
+ * ### This Format Overload
76
+ */
77
+ @ExcludeFromSources
78
+ private interface CommonFormatDocs
79
+
25
80
// region format
26
81
82
+ /* *
83
+ * @include [CommonFormatDocs]
84
+ * @include [SelectingColumns.Dsl] {@include [SetFormatOperationArg]}
85
+ * ### Examples:
86
+ * TODO example
87
+ *
88
+ * @param [columns\] The [columns-selector][ColumnsSelector] used to select the columns to be formatted.
89
+ * If unspecified, all columns will be formatted.
90
+ */
27
91
public fun <T , C > DataFrame<T>.format (columns : ColumnsSelector <T , C >): FormatClause <T , C > = FormatClause (this , columns)
28
92
93
+ /* *
94
+ * @include [CommonFormatDocs]
95
+ * @include [SelectingColumns.ColumnNames] {@include [SetFormatOperationArg]}
96
+ * ### Examples:
97
+ * TODO example
98
+ *
99
+ * @param [columns\] The names of the columns to be formatted.
100
+ * If unspecified, all columns will be formatted.
101
+ */
29
102
public fun <T > DataFrame<T>.format (vararg columns : String ): FormatClause <T , Any ?> = format { columns.toColumnSet() }
30
103
104
+ /* *
105
+ * @include [CommonFormatDocs]
106
+ *
107
+ * This simply formats all columns. Optionally, you can specify which columns to format using a
108
+ * [columns-selector][ColumnsSelector] or by [column names][String].
109
+ *
110
+ * ### Examples:
111
+ * TODO example
112
+ */
113
+ public fun <T > DataFrame<T>.format (): FormatClause <T , Any ?> = FormatClause (this )
114
+
31
115
@Deprecated(DEPRECATED_ACCESS_API )
32
116
@AccessApiOverload
33
117
public fun <T , C > DataFrame<T>.format (vararg columns : ColumnReference <C >): FormatClause <T , C > =
@@ -38,15 +122,14 @@ public fun <T, C> DataFrame<T>.format(vararg columns: ColumnReference<C>): Forma
38
122
public fun <T , C > DataFrame<T>.format (vararg columns : KProperty <C >): FormatClause <T , C > =
39
123
format { columns.toColumnSet() }
40
124
41
- public fun <T > DataFrame<T>.format (): FormatClause <T , Any ?> = FormatClause (this )
42
-
43
125
// endregion
44
126
45
127
public fun <T , C > FormatClause <T , C >.perRowCol (formatter : RowColFormatter <T , C >): FormattedFrame <T > =
46
128
formatImpl(formatter)
47
129
130
+ @Suppress(" UNCHECKED_CAST" )
48
131
public fun <T , C > FormatClause <T , C >.with (formatter : CellFormatter <C >): FormattedFrame <T > =
49
- formatImpl { row, col -> formatter(row[col] ) }
132
+ formatImpl { row, col -> formatter(row[col.name] as C ) }
50
133
51
134
public fun <T , C > FormatClause <T , C >.where (filter : RowValueFilter <T , C >): FormatClause <T , C > =
52
135
FormatClause (filter = filter, df = df, columns = columns, oldFormatter = oldFormatter)
@@ -119,14 +202,19 @@ public object FormattingDSL {
119
202
120
203
public typealias RowColFormatter <T , C > = FormattingDSL .(DataRow <T >, DataColumn <C >) -> CellAttributes ?
121
204
205
+ /* *
206
+ * A wrapper around a [DataFrame][df] with HTML formatting data.
207
+ */
122
208
public class FormattedFrame <T >(internal val df : DataFrame <T >, internal val formatter : RowColFormatter <T , * >? = null ) {
123
209
/* *
210
+ * todo copy from toHtml
124
211
* @return DataFrameHtmlData without additional definitions. Can be rendered in Jupyter kernel environments
125
212
*/
126
213
public fun toHtml (configuration : DisplayConfiguration = DisplayConfiguration .DEFAULT ): DataFrameHtmlData =
127
214
df.toHtml(getDisplayConfiguration(configuration))
128
215
129
216
/* *
217
+ * todo copy from toStandaloneHtml
130
218
* @return DataFrameHtmlData with table script and css definitions. Can be saved as an *.html file and displayed in the browser
131
219
*/
132
220
public fun toStandaloneHtml (configuration : DisplayConfiguration = DisplayConfiguration .DEFAULT ): DataFrameHtmlData =
@@ -136,6 +224,23 @@ public class FormattedFrame<T>(internal val df: DataFrame<T>, internal val forma
136
224
configuration.copy(cellFormatter = formatter as RowColFormatter <* , * >? )
137
225
}
138
226
227
+ /* *
228
+ * An intermediate class used in the [format] operation.
229
+ *
230
+ * This class itself does nothing—it is just a transitional step before specifying
231
+ * how to format the selected columns.
232
+ * It must be followed by one of the positioning methods
233
+ * to produce a new [FormattedFrame]; a [DataFrame] with HTML formatting data.
234
+ *
235
+ * Use the following function to filter the rows to format:
236
+ * - [where][FormatClause.where] – filters the rows to format using a [RowValueFilter].
237
+ *
238
+ * Use the following functions to finalize the formatting:
239
+ * - [with][FormatClause.with] – Specifies how to format the cells using a [CellFormatter].
240
+ * - [perRowCol][FormatClause.perRowCol] – Specifies how to format each cell individually using a [RowColFormatter].
241
+ *
242
+ * See [Grammar][TODO] for more details.
243
+ */
139
244
public class FormatClause <T , C >(
140
245
internal val df : DataFrame <T >,
141
246
internal val columns : ColumnsSelector <T , C >? = null ,
0 commit comments