@@ -24,6 +24,7 @@ import org.jetbrains.kotlinx.jupyter.api.renderHtmlAsIFrameIfNeeded
24
24
/* * Starting from this version, dataframe integration will respond with additional data for rendering in Kotlin Notebooks plugin. */
25
25
private const val MIN_KERNEL_VERSION_FOR_NEW_TABLES_UI = " 0.11.0.311"
26
26
private const val MIN_IDE_VERSION_SUPPORT_JSON_WITH_METADATA = 241
27
+ private const val MIN_IDE_VERSION_SUPPORT_IMAGE_VIEWER = 242
27
28
28
29
internal class JupyterHtmlRenderer (
29
30
val display : DisplayConfiguration ,
@@ -64,8 +65,8 @@ internal inline fun <reified T : Any> JupyterHtmlRenderer.render(
64
65
if (notebook.kernelVersion >= KotlinKernelVersion .from(MIN_KERNEL_VERSION_FOR_NEW_TABLES_UI )!! ) {
65
66
val ideBuildNumber = KotlinNotebookPluginUtils .getKotlinNotebookIDEBuildNumber()
66
67
67
- val jsonEncodedDf =
68
- if ( ideBuildNumber == null || ideBuildNumber.majorVersion < MIN_IDE_VERSION_SUPPORT_JSON_WITH_METADATA ) {
68
+ val jsonEncodedDf = when {
69
+ ! ideBuildNumber.supportsDynamicNestedTables() -> {
69
70
json {
70
71
obj(
71
72
" nrow" to df.size.nrow,
@@ -74,19 +75,32 @@ internal inline fun <reified T : Any> JupyterHtmlRenderer.render(
74
75
" kotlin_dataframe" to encodeFrame(df.take(limit)),
75
76
)
76
77
}.toJsonString()
77
- } else {
78
+ }
79
+
80
+ else -> {
81
+ val imageEncodingOptions =
82
+ if (ideBuildNumber.supportsImageViewer()) Base64ImageEncodingOptions () else null
83
+
78
84
df.toJsonWithMetadata(
79
85
limit,
80
86
reifiedDisplayConfiguration.rowsLimit,
81
- imageEncodingOptions = Base64ImageEncodingOptions ()
87
+ imageEncodingOptions = imageEncodingOptions
82
88
)
83
89
}
90
+ }
91
+
84
92
notebook.renderAsIFrameAsNeeded(html, staticHtml, jsonEncodedDf)
85
93
} else {
86
94
notebook.renderHtmlAsIFrameIfNeeded(html)
87
95
}
88
96
}
89
97
98
+ private fun KotlinNotebookPluginUtils.IdeBuildNumber?.supportsDynamicNestedTables () =
99
+ this != null && majorVersion >= MIN_IDE_VERSION_SUPPORT_JSON_WITH_METADATA
100
+
101
+ private fun KotlinNotebookPluginUtils.IdeBuildNumber?.supportsImageViewer () =
102
+ this != null && majorVersion >= MIN_IDE_VERSION_SUPPORT_IMAGE_VIEWER
103
+
90
104
internal fun Notebook.renderAsIFrameAsNeeded (
91
105
data : HtmlData ,
92
106
staticData : HtmlData ,
0 commit comments