@@ -154,10 +154,10 @@ internal fun AnyFrame.toHtmlData(
154154 }
155155 val body = getResourceText(" /table.html" , " ID" to rootId)
156156 val script = scripts.joinToString(" \n " ) + " \n " + getResourceText(" /renderTable.js" , " ___ID___" to rootId)
157- return HtmlData (" " , body, script)
157+ return HtmlData (" " , body, script, configuration.useDarkColorScheme )
158158}
159159
160- public data class HtmlData (val style : String , val body : String , val script : String ) {
160+ public data class HtmlData (val style : String , val body : String , val script : String , val useDarkColorScheme : Boolean ) {
161161 override fun toString (): String = """
162162 <html>
163163 <head>
@@ -166,27 +166,39 @@ public data class HtmlData(val style: String, val body: String, val script: Stri
166166 </style>
167167 </head>
168168 <body>
169- $body
169+ <div${darkSchemeAttribute()} >
170+ $body
171+ </div>
170172 </body>
171173 <script>
172174 $script
173175 </script>
174176 </html>
175177 """ .trimIndent()
176178
179+ private fun darkSchemeAttribute (): String {
180+ return if (useDarkColorScheme) " class=\" dataframe_dark\" " else " "
181+ }
182+
177183 public fun toJupyter (): MimeTypedResult = HTML (toString())
178184
179185 public operator fun plus (other : HtmlData ): HtmlData =
180- HtmlData (style + " \n " + other.style, body + " \n " + other.body, script + " \n " + other.script)
186+ HtmlData (
187+ style + " \n " + other.style,
188+ body + " \n " + other.body,
189+ script + " \n " + other.script,
190+ useDarkColorScheme || other.useDarkColorScheme
191+ )
181192}
182193
183194internal fun HtmlData.print () = println (this )
184195
185- internal fun initHtml (includeJs : Boolean = true, includeCss : Boolean = true): HtmlData =
196+ internal fun initHtml (includeJs : Boolean = true, includeCss : Boolean = true, useDarkColorScheme : Boolean = false ): HtmlData =
186197 HtmlData (
187198 style = if (includeCss) getResources(" /table.css" ) else " " ,
188199 script = if (includeJs) getResourceText(" /init.js" ) else " " ,
189- body = " "
200+ body = " " ,
201+ useDarkColorScheme = useDarkColorScheme,
190202 )
191203
192204public fun <T > DataFrame<T>.html (): String = toHTML(extraHtml = initHtml()).toString()
@@ -205,7 +217,7 @@ public fun <T> DataFrame<T>.toHTML(
205217 } else " <p>$footer </p>"
206218
207219 val tableHtml = toHtmlData(configuration, cellRenderer)
208- val html = tableHtml + HtmlData (" " , bodyFooter, " " )
220+ val html = tableHtml + HtmlData (" " , bodyFooter, " " , configuration.useDarkColorScheme )
209221
210222 return if (extraHtml != null ) extraHtml + html else html
211223}
@@ -217,6 +229,7 @@ public data class DisplayConfiguration(
217229 var decimalFormat : RendererDecimalFormat = RendererDecimalFormat .DEFAULT ,
218230 var isolatedOutputs : Boolean = flagFromEnv("LETS_PLOT_HTML_ISOLATED_FRAME "),
219231 internal val localTesting : Boolean = flagFromEnv("KOTLIN_DATAFRAME_LOCAL_TESTING "),
232+ var useDarkColorScheme : Boolean = false ,
220233) {
221234 public companion object {
222235 public val DEFAULT : DisplayConfiguration = DisplayConfiguration ()
0 commit comments