From f3f48567b06d322b70ef4c0095442d5ac9f058db Mon Sep 17 00:00:00 2001 From: "andrei.kislitsyn" Date: Tue, 13 May 2025 01:42:16 +0400 Subject: [PATCH 1/2] fix snippets iframes --- .../explainer/SamplesRenderingUtils.kt | 65 +++++++++ docs/StardustDocs/cfg/buildprofiles.xml | 2 +- docs/StardustDocs/cfg/google-search.html | 13 ++ docs/StardustDocs/cfg/include-head.html | 3 +- docs/StardustDocs/cfg/resize-iframes.js | 129 ------------------ .../static/{custom.js => iframe-config.js} | 0 ...nx.dataframe.samples.api.Access.byRow.html | 62 +++++++++ ...me.samples.api.Access.columnSelectors.html | 62 +++++++++ ...amples.api.Access.columnSelectorsMisc.html | 62 +++++++++ ...s.api.Access.columnSelectorsModifySet.html | 62 +++++++++ ...ples.api.Access.columnSelectorsUsages.html | 62 +++++++++ ...s.api.Access.columnsSelectorByIndices.html | 62 +++++++++ ...dataframe.samples.api.Access.distinct.html | 62 +++++++++ ...taframe.samples.api.Access.distinctBy.html | 62 +++++++++ ...me.samples.api.Access.distinctColumns.html | 62 +++++++++ ...inx.dataframe.samples.api.Access.drop.html | 62 +++++++++ ...dataframe.samples.api.Access.dropLast.html | 62 +++++++++ ...x.dataframe.samples.api.Access.dropNA.html | 62 +++++++++ ...dataframe.samples.api.Access.dropNaNs.html | 62 +++++++++ ...ataframe.samples.api.Access.dropNulls.html | 62 +++++++++ ...ataframe.samples.api.Access.dropWhere.html | 62 +++++++++ ...ataframe.samples.api.Access.dropWhile.html | 62 +++++++++ ...x.dataframe.samples.api.Access.filter.html | 62 +++++++++ ...dataframe.samples.api.Access.filterBy.html | 62 +++++++++ ...e.samples.api.Access.getColumnsByName.html | 62 +++++++++ ....samples.api.Access.getRowByCondition.html | 62 +++++++++ ...rame.samples.api.Access.getRowByIndex.html | 62 +++++++++ ...es.api.Access.getSeveralRowsByIndices.html | 62 +++++++++ ...les.api.Access.getSeveralRowsByRanges.html | 62 +++++++++ ...x.dataframe.samples.api.Access.select.html | 62 +++++++++ ...inx.dataframe.samples.api.Access.take.html | 62 +++++++++ ...dataframe.samples.api.Access.takeLast.html | 62 +++++++++ ...ataframe.samples.api.Access.takeWhile.html | 62 +++++++++ ...tlinx.dataframe.samples.api.Access.xs.html | 62 +++++++++ ...aframe.samples.api.Analyze.columnsFor.html | 62 +++++++++ ....samples.api.Analyze.countAggregation.html | 62 +++++++++ ...ataframe.samples.api.Analyze.describe.html | 62 +++++++++ ...e.samples.api.Analyze.describeColumns.html | 62 +++++++++ ...dataframe.samples.api.Analyze.groupBy.html | 62 +++++++++ ...i.Analyze.groupByAggregateWithoutInto.html | 62 +++++++++ ...mples.api.Analyze.groupByAggregations.html | 62 +++++++++ ...api.Analyze.groupByDirectAggregations.html | 62 +++++++++ ...frame.samples.api.Analyze.groupByExpr.html | 62 +++++++++ ....samples.api.Analyze.groupByMoveToTop.html | 62 +++++++++ ...les.api.Analyze.groupByMoveToTopFalse.html | 62 +++++++++ ...me.samples.api.Analyze.groupByToFrame.html | 62 +++++++++ ...api.Analyze.groupByWithoutAggregation.html | 62 +++++++++ ...nx.dataframe.samples.api.Analyze.head.html | 62 +++++++++ ...es.api.Analyze.meanAggregationsSkipNA.html | 62 +++++++++ ...x.dataframe.samples.api.Analyze.pivot.html | 62 +++++++++ ....dataframe.samples.api.Analyze.pivot2.html | 62 +++++++++ ...me.samples.api.Analyze.pivotAggregate.html | 62 +++++++++ ...e.samples.api.Analyze.pivotAggregate1.html | 62 +++++++++ ...les.api.Analyze.pivotAsDataRowOrFrame.html | 62 +++++++++ ...s.api.Analyze.pivotCommonAggregations.html | 62 +++++++++ ...frame.samples.api.Analyze.pivotCounts.html | 62 +++++++++ ...rame.samples.api.Analyze.pivotDefault.html | 62 +++++++++ ...ame.samples.api.Analyze.pivotDefault1.html | 62 +++++++++ ...rame.samples.api.Analyze.pivotGroupBy.html | 62 +++++++++ ...samples.api.Analyze.pivotGroupByOther.html | 62 +++++++++ ....samples.api.Analyze.pivotInAggregate.html | 62 +++++++++ ...frame.samples.api.Analyze.pivotInward.html | 62 +++++++++ ...rame.samples.api.Analyze.pivotMatches.html | 62 +++++++++ ...ame.samples.api.Analyze.schemaGroupBy.html | 62 +++++++++ ...ples.api.Analyze.statisticGroupByMany.html | 62 +++++++++ ...es.api.Analyze.statisticGroupBySingle.html | 62 +++++++++ ...i.Analyze.statisticGroupBySingleNamed.html | 62 +++++++++ ...amples.api.Analyze.statisticPivotMany.html | 62 +++++++++ ...pi.Analyze.statisticPivotManySeparate.html | 62 +++++++++ ...ples.api.Analyze.statisticPivotSingle.html | 62 +++++++++ ...frame.samples.api.Analyze.valueCounts.html | 62 +++++++++ ....samples.api.Create.columnAccessorMap.html | 62 +++++++++ ...pi.Create.createDataFrameFromIterable.html | 62 +++++++++ ...les.api.Create.createDataFrameFromMap.html | 62 +++++++++ ....samples.api.Create.duplicatedColumns.html | 62 +++++++++ ....samples.api.Create.toDataFrameColumn.html | 62 +++++++++ ...ame.samples.api.DataRowApi.conditions.html | 62 +++++++++ ...me.samples.api.DataRowApi.expressions.html | 62 +++++++++ ...tlinx.dataframe.samples.api.Join.join.html | 62 +++++++++ ...ataframe.samples.api.Join.joinDefault.html | 62 +++++++++ ...ataframe.samples.api.Join.joinSpecial.html | 62 +++++++++ ...aframe.samples.api.Join.joinWithMatch.html | 62 +++++++++ ...linx.dataframe.samples.api.Modify.add.html | 62 +++++++++ ...rame.samples.api.Modify.addDataFrames.html | 62 +++++++++ ...aframe.samples.api.Modify.addExisting.html | 62 +++++++++ ....dataframe.samples.api.Modify.addMany.html | 62 +++++++++ ...frame.samples.api.Modify.addRecurrent.html | 62 +++++++++ ...rame.samples.api.Modify.concatGroupBy.html | 62 +++++++++ ....dataframe.samples.api.Modify.convert.html | 62 +++++++++ ...me.samples.api.Modify.convertAsColumn.html | 62 +++++++++ ...ame.samples.api.Modify.convertAsFrame.html | 62 +++++++++ ...ataframe.samples.api.Modify.convertTo.html | 62 +++++++++ ...rame.samples.api.Modify.convertToEnum.html | 62 +++++++++ ...amples.api.Modify.convertToValueClass.html | 62 +++++++++ ...x.dataframe.samples.api.Modify.fillNA.html | 62 +++++++++ ...dataframe.samples.api.Modify.fillNaNs.html | 62 +++++++++ ...ataframe.samples.api.Modify.fillNulls.html | 62 +++++++++ ....dataframe.samples.api.Modify.flatten.html | 62 +++++++++ ...taframe.samples.api.Modify.flattenAll.html | 62 +++++++++ ...x.dataframe.samples.api.Modify.gather.html | 62 +++++++++ ...aframe.samples.api.Modify.gatherNames.html | 62 +++++++++ ...nx.dataframe.samples.api.Modify.group.html | 62 +++++++++ ....dataframe.samples.api.Modify.implode.html | 62 +++++++++ ...x.dataframe.samples.api.Modify.insert.html | 62 +++++++++ ...frame.samples.api.Modify.insertColumn.html | 62 +++++++++ ....dataframe.samples.api.Modify.mapMany.html | 62 +++++++++ ...nx.dataframe.samples.api.Modify.merge.html | 62 +++++++++ ...frame.samples.api.Modify.mergeDefault.html | 62 +++++++++ ...samples.api.Modify.mergeDifferentWith.html | 62 +++++++++ ...rame.samples.api.Modify.mergeIntoList.html | 62 +++++++++ ...rame.samples.api.Modify.mergeSameWith.html | 62 +++++++++ ...inx.dataframe.samples.api.Modify.move.html | 62 +++++++++ ...dataframe.samples.api.Modify.parseAll.html | 62 +++++++++ ...ataframe.samples.api.Modify.parseSome.html | 62 +++++++++ ...e.samples.api.Modify.parseWithOptions.html | 62 +++++++++ ...x.dataframe.samples.api.Modify.remove.html | 62 +++++++++ ...x.dataframe.samples.api.Modify.rename.html | 62 +++++++++ ...e.samples.api.Modify.renameExpression.html | 62 +++++++++ ....dataframe.samples.api.Modify.reorder.html | 62 +++++++++ ...ame.samples.api.Modify.reorderInGroup.html | 62 +++++++++ ....dataframe.samples.api.Modify.replace.html | 62 +++++++++ ....dataframe.samples.api.Modify.reverse.html | 62 +++++++++ ....dataframe.samples.api.Modify.shuffle.html | 62 +++++++++ ...x.dataframe.samples.api.Modify.sortBy.html | 62 +++++++++ ...taframe.samples.api.Modify.sortByDesc.html | 62 +++++++++ ...dataframe.samples.api.Modify.sortWith.html | 62 +++++++++ ...nx.dataframe.samples.api.Modify.split.html | 62 +++++++++ ...x.dataframe.samples.api.Modify.split1.html | 62 +++++++++ ...frame.samples.api.Modify.splitInplace.html | 62 +++++++++ ...rame.samples.api.Modify.splitIntoRows.html | 62 +++++++++ ...taframe.samples.api.Modify.splitRegex.html | 62 +++++++++ ...aframe.samples.api.Modify.splitRegex1.html | 62 +++++++++ ....dataframe.samples.api.Modify.ungroup.html | 62 +++++++++ ...x.dataframe.samples.api.Modify.update.html | 62 +++++++++ ...rame.samples.api.Modify.updateAsFrame.html | 62 +++++++++ ...me.samples.api.Modify.updatePerRowCol.html | 62 +++++++++ ...taframe.samples.api.Modify.updateWith.html | 62 +++++++++ ...me.samples.api.Modify.updateWithConst.html | 62 +++++++++ 138 files changed, 8265 insertions(+), 131 deletions(-) create mode 100644 docs/StardustDocs/cfg/google-search.html delete mode 100644 docs/StardustDocs/cfg/resize-iframes.js rename docs/StardustDocs/cfg/static/{custom.js => iframe-config.js} (100%) diff --git a/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/explainer/SamplesRenderingUtils.kt b/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/explainer/SamplesRenderingUtils.kt index 9c4968e1d8..28e7205354 100644 --- a/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/explainer/SamplesRenderingUtils.kt +++ b/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/explainer/SamplesRenderingUtils.kt @@ -32,6 +32,71 @@ val WritersideStyle = DataFrameHtmlData( padding: 6px; } """.trimIndent(), + script = + """ +function sendHeight() { + let totalHeight = 0; + + const detailsElements = document.querySelectorAll('details'); + + detailsElements.forEach(detail => { + + const summary = detail.querySelector('summary'); + if (summary) { + totalHeight += summary.offsetHeight; + } + + + if (detail.open) { + const table = detail.querySelector('table.dataframe'); + if (table) { + totalHeight += table.offsetHeight; + + const styles = getComputedStyle(table); + totalHeight += parseFloat(styles.marginTop) + parseFloat(styles.marginBottom) + 10; + } + + const description = detail.querySelector('.dataframe_description'); + if (description) { + totalHeight += description.offsetHeight; + } + } + }); + + totalHeight = Math.ceil(totalHeight + 16); + + window.parent.postMessage({type: 'iframeHeight', height: totalHeight}, '*'); +} + +function repeatHeightCalculation(maxRetries = 10, interval = 100) { + let retries = 0; + const intervalId = setInterval(() => { + sendHeight(); + retries++; + if (retries >= maxRetries) clearInterval(intervalId); + }, interval); +} + +window.addEventListener('load', () => { + repeatHeightCalculation(); + + document.querySelectorAll('details').forEach(detail => { + detail.addEventListener('toggle', () => { + setTimeout(sendHeight, 30); + }); + }); +}); + +const allObservedTables = document.querySelectorAll('table.dataframe'); +allObservedTables.forEach((table) => { + const observer = new MutationObserver(sendHeight); + observer.observe(table, { + childList: true, + subtree: true, + characterData: true, + }); +}); + """.trimIndent() ) val WritersideFooter: (DataFrame<*>) -> String = { "" } diff --git a/docs/StardustDocs/cfg/buildprofiles.xml b/docs/StardustDocs/cfg/buildprofiles.xml index e2f73e51b7..162860b58f 100644 --- a/docs/StardustDocs/cfg/buildprofiles.xml +++ b/docs/StardustDocs/cfg/buildprofiles.xml @@ -13,7 +13,7 @@ bce9ba6ce7419efe813d671244d3bf6a https://www.jetbrains.com/search/json/ https://kotlin.github.io/dataframe/ - resize-iframes.js + google-search.html true https://github.com/Kotlin/dataframe/edit/master/docs/StardustDocs/ include-head.html diff --git a/docs/StardustDocs/cfg/google-search.html b/docs/StardustDocs/cfg/google-search.html new file mode 100644 index 0000000000..f5846bc860 --- /dev/null +++ b/docs/StardustDocs/cfg/google-search.html @@ -0,0 +1,13 @@ + + + + diff --git a/docs/StardustDocs/cfg/include-head.html b/docs/StardustDocs/cfg/include-head.html index c5c5b30393..1ae29e79a8 100644 --- a/docs/StardustDocs/cfg/include-head.html +++ b/docs/StardustDocs/cfg/include-head.html @@ -1 +1,2 @@ - + + diff --git a/docs/StardustDocs/cfg/resize-iframes.js b/docs/StardustDocs/cfg/resize-iframes.js deleted file mode 100644 index 090b0f686d..0000000000 --- a/docs/StardustDocs/cfg/resize-iframes.js +++ /dev/null @@ -1,129 +0,0 @@ - - - - - diff --git a/docs/StardustDocs/cfg/static/custom.js b/docs/StardustDocs/cfg/static/iframe-config.js similarity index 100% rename from docs/StardustDocs/cfg/static/custom.js rename to docs/StardustDocs/cfg/static/iframe-config.js diff --git a/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.byRow.html b/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.byRow.html index a460e44736..45ea55887c 100644 --- a/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.byRow.html +++ b/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.byRow.html @@ -513,6 +513,68 @@ } })() +function sendHeight() { + let totalHeight = 0; + + const detailsElements = document.querySelectorAll('details'); + + detailsElements.forEach(detail => { + + const summary = detail.querySelector('summary'); + if (summary) { + totalHeight += summary.offsetHeight; + } + + + if (detail.open) { + const table = detail.querySelector('table.dataframe'); + if (table) { + totalHeight += table.offsetHeight; + + const styles = getComputedStyle(table); + totalHeight += parseFloat(styles.marginTop) + parseFloat(styles.marginBottom) + 10; + } + + const description = detail.querySelector('.dataframe_description'); + if (description) { + totalHeight += description.offsetHeight; + } + } + }); + + totalHeight = Math.ceil(totalHeight + 16); + + window.parent.postMessage({type: 'iframeHeight', height: totalHeight}, '*'); +} + +function repeatHeightCalculation(maxRetries = 10, interval = 100) { + let retries = 0; + const intervalId = setInterval(() => { + sendHeight(); + retries++; + if (retries >= maxRetries) clearInterval(intervalId); + }, interval); +} + +window.addEventListener('load', () => { + repeatHeightCalculation(); + + document.querySelectorAll('details').forEach(detail => { + detail.addEventListener('toggle', () => { + setTimeout(sendHeight, 30); + }); + }); +}); + +const allObservedTables = document.querySelectorAll('table.dataframe'); +allObservedTables.forEach((table) => { + const observer = new MutationObserver(sendHeight); + observer.observe(table, { + childList: true, + subtree: true, + characterData: true, + }); +}); /*