WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions core/api/core.api
Original file line number Diff line number Diff line change
Expand Up @@ -6530,11 +6530,14 @@ public final class org/jetbrains/kotlinx/dataframe/jupyter/DefaultCellRenderer :
}

public final class org/jetbrains/kotlinx/dataframe/jupyter/DisableRowsLimitWrapper {
public fun <init> (Lorg/jetbrains/kotlinx/dataframe/DataFrame;)V
public fun <init> (Lorg/jetbrains/kotlinx/dataframe/DataFrame;Z)V
public synthetic fun <init> (Lorg/jetbrains/kotlinx/dataframe/DataFrame;ZILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun component1 ()Lorg/jetbrains/kotlinx/dataframe/DataFrame;
public final fun copy (Lorg/jetbrains/kotlinx/dataframe/DataFrame;)Lorg/jetbrains/kotlinx/dataframe/jupyter/DisableRowsLimitWrapper;
public static synthetic fun copy$default (Lorg/jetbrains/kotlinx/dataframe/jupyter/DisableRowsLimitWrapper;Lorg/jetbrains/kotlinx/dataframe/DataFrame;ILjava/lang/Object;)Lorg/jetbrains/kotlinx/dataframe/jupyter/DisableRowsLimitWrapper;
public final fun component2 ()Z
public final fun copy (Lorg/jetbrains/kotlinx/dataframe/DataFrame;Z)Lorg/jetbrains/kotlinx/dataframe/jupyter/DisableRowsLimitWrapper;
public static synthetic fun copy$default (Lorg/jetbrains/kotlinx/dataframe/jupyter/DisableRowsLimitWrapper;Lorg/jetbrains/kotlinx/dataframe/DataFrame;ZILjava/lang/Object;)Lorg/jetbrains/kotlinx/dataframe/jupyter/DisableRowsLimitWrapper;
public fun equals (Ljava/lang/Object;)Z
public final fun getAddHtml ()Z
public final fun getValue ()Lorg/jetbrains/kotlinx/dataframe/DataFrame;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import org.jetbrains.kotlinx.dataframe.annotations.RequiredByIntellijPlugin

/**
* Allows for disabling the rows limit when generating a DISPLAY output in Jupyter.
* Used in code that Kotlin Notebook sends to Jupyter Kernel / KotlinNotebookPluginUtils
* @param [addHtml] needed to avoid sending HTML in these internal requests, because they won't be displayed anyway, only JSON part of these payloads is used to update "live" state of the widget
*/
@RequiredByIntellijPlugin
public data class DisableRowsLimitWrapper(public val value: AnyFrame)
public data class DisableRowsLimitWrapper(public val value: AnyFrame, public val addHtml: Boolean = true)
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public object KotlinNotebookPluginUtils {
* It's used for example for dynamic pagination in Kotlin Notebook Plugin.
*/
public fun getRowsSubsetForRendering(df: AnyFrame, startIdx: Int, endIdx: Int): DisableRowsLimitWrapper =
DisableRowsLimitWrapper(df[startIdx..<endIdx])
DisableRowsLimitWrapper(df[startIdx..<endIdx], addHtml = false)

/**
* Sorts a dataframe-like object by multiple columns.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.jetbrains.kotlinx.dataframe.jupyter

import kotlinx.serialization.ExperimentalSerializationApi
import org.jetbrains.kotlinx.dataframe.AnyFrame
import org.jetbrains.kotlinx.dataframe.api.FormattedFrame
import org.jetbrains.kotlinx.dataframe.api.allNulls
Expand Down Expand Up @@ -32,12 +31,12 @@ private const val MIN_IDE_VERSION_SUPPORT_DATAFRAME_CONVERTABLE = 243

internal class JupyterHtmlRenderer(val display: DisplayConfiguration, val builder: JupyterIntegration.Builder)

@OptIn(ExperimentalSerializationApi::class)
internal inline fun <reified T : Any> JupyterHtmlRenderer.render(
noinline getFooter: (T) -> String,
crossinline modifyConfig: T.(DisplayConfiguration) -> DisplayConfiguration = { it },
applyRowsLimit: Boolean = true,
) = builder.renderWithHost<T> { host, value ->
val addHtml = (value as? DisableRowsLimitWrapper)?.addHtml ?: true
val contextRenderer = JupyterCellRenderer(this.notebook, host)
val reifiedDisplayConfiguration = value.modifyConfig(display)
val footer = getFooter(value)
Expand All @@ -53,20 +52,22 @@ internal inline fun <reified T : Any> JupyterHtmlRenderer.render(
df.rowsCount()
}

val html = DataFrameHtmlData
.tableDefinitions(
includeJs = reifiedDisplayConfiguration.isolatedOutputs,
includeCss = true,
).plus(
df.toHtml(
// is added later to make sure it's put outside of potential iFrames
configuration = reifiedDisplayConfiguration.copy(enableFallbackStaticTables = false),
cellRenderer = contextRenderer,
) { footer },
).toJupyterHtmlData()
val html by lazy {
DataFrameHtmlData
.tableDefinitions(
includeJs = reifiedDisplayConfiguration.isolatedOutputs,
includeCss = true,
).plus(
df.toHtml(
// is added later to make sure it's put outside of potential iFrames
configuration = reifiedDisplayConfiguration.copy(enableFallbackStaticTables = false),
cellRenderer = contextRenderer,
) { footer },
).toJupyterHtmlData()
}

// Generates a static version of the table which can be displayed in GitHub previews etc.
val staticHtml = df.toStaticHtml(reifiedDisplayConfiguration, DefaultCellRenderer).toJupyterHtmlData()
val staticHtml by lazy { df.toStaticHtml(reifiedDisplayConfiguration, DefaultCellRenderer).toJupyterHtmlData() }

if (notebook.kernelVersion >= KotlinKernelVersion.from(MIN_KERNEL_VERSION_FOR_NEW_TABLES_UI)!!) {
val ideBuildNumber = KotlinNotebookPluginUtils.getKotlinNotebookIDEBuildNumber()
Expand Down Expand Up @@ -94,8 +95,13 @@ internal inline fun <reified T : Any> JupyterHtmlRenderer.render(
)
}
}

notebook.renderAsIFrameAsNeeded(data = html, staticData = staticHtml, jsonEncodedDf = jsonEncodedDf)
if (!addHtml) {
mimeResult(
"application/kotlindataframe+json" to jsonEncodedDf,
)
} else {
notebook.renderAsIFrameAsNeeded(data = html, staticData = staticHtml, jsonEncodedDf = jsonEncodedDf)
}
} else {
notebook.renderHtmlAsIFrameIfNeeded(data = html)
}
Expand Down