10
0
mirror of https://github.com/LCPQ/QUESTDB_website.git synced 2024-07-22 18:57:38 +02:00
This commit is contained in:
scemama 2020-12-07 15:47:34 +00:00
parent d2db09eb1d
commit 577a844191
2 changed files with 76 additions and 2 deletions

View File

@ -59,7 +59,7 @@
"headline": "Dataset",
"description" : "function adjustSticky() { const height = $(\u0022nav\u0022).height() $(\u0022thead.sticky tr th \u0022).css(\u0022top\u0022, height) } window.onload = async () = { window.browser = bowser.getParser(window.navigator.userAgent); $(\u0022input[type=\u0027checkbox\u0027]\u0022).trigger(\u0022change\u0022) $(\u0022input[type=\u0027number\u0027].range\u0022).trigger(\u0022change\u0022) adjustSticky(); $(window).resize(adjustSticky) var slist = $(\u0022#SelectList\u0022) getAllSelect().each(function () { $(\u0022\u0022).text($(\u0027label[for=\u0022\u0027 \u002b $(this).attr(\u0027id\u0027) \u002b \u0027\u0022]\u0027).text()).appendTo(slist) }) $(\u0027[data-needbrowser],[data-neednotbrowser]\u0027).each(function () { function test(key, value) { switch (key) { case \u0022",
"inLanguage" : "en",
"wordCount": 2159 ,
"wordCount": 2207 ,
"datePublished" : "0001-01-01T00:00:00",
"dateModified" : "0001-01-01T00:00:00",
"image" : "https:\/\/lcpq.github.io\/QUESTDB_website\/img\/TOC_JPCL.png",
@ -302,6 +302,7 @@ MathJax.Hub.Config({
<script src="https://lcpq.github.io/QUESTDB_website/js/Geometry.js"></script>
<script src="https://lcpq.github.io/QUESTDB_website/js/GeometriesLoader.js"></script>
<script src="https://lcpq.github.io/QUESTDB_website/js/GeometryParseMetadataExtension.js"></script>
<script src="https://lcpq.github.io/QUESTDB_website/js/tableToCSV.js"></script>
<script>
function adjustSticky() {
const height = $("nav").height()
@ -853,6 +854,7 @@ MathJax.Hub.Config({
$("<h2/>").append($("<a>",{href:publiDat.URL,target:"_blank"}).text(publiDat.title)).appendTo(div)
}
var table = $("<table/>").addClass("datatable").appendTo(div)
$(table).before($("#stat_table").prevAll("button:first").clone())
var head = $("<tr/>")
$("<thead/>").addClass("sticky").append(head).appendTo(table)
var tbody = $("<tbody/>").appendTo(table)
@ -922,7 +924,7 @@ MathJax.Hub.Config({
if (kv !== undefined) {
const [val, unsafe] = kv[1]
if (unsafe) {
td.append($("<span/>", { title: "unsafe value", role: "img", "aria-label": "Warning" }).addClass("emoji").text('⚠'))
td.append($("<span/>", { title: "unsafe value", role: "img", "aria-label": "Warning", "data-csvtext":"(Unsafe)"}).addClass("emoji").text('⚠'))
}
if (unsafe && !filterParams.unsafe) {
td.append($("<s/>").append(val.toString()))
@ -965,11 +967,26 @@ MathJax.Hub.Config({
await reloadContent();
}
function exportTableToCSV(table,title = null,allowTitleOverride = false) {
const tableCaption = $(table).find('caption').text()
if (tableCaption !== "" && (title === null || allowTitleOverride)) {
title = tableCaption
}
const csv = tableToCSV(table)
const blob = new Blob([csv],{type:"text/csv"})
saveAs(blob,`${title}.csv`)
}
function OnExportTable(event) {
const table=$(event.target).nextAll('table:first')
exportTableToCSV(table,"table")
}
function refreshExportGeoms() {
const vals=$("#mol_select").val()
const disable = vals === null || vals.length===0
$("#btn_export_geoms").prop("disabled",disable)
}
async function moleculeSelectionChanged(event) {
refreshExportGeoms()
await reloadNextSelect(event)
@ -1152,6 +1169,7 @@ function getFluoFilesName(){
<section id="data">
</section>
<section>
<button onclick="OnExportTable(event)">Export as CSV</button>
<table id="stat_table" class="datatable">
<thead class="sticky">
<th scope="col">Method</th>

56
js/tableToCSV.js Normal file
View File

@ -0,0 +1,56 @@
function tableToCSV(table) {
var csv = [];
var caption = $(table).find('caption').text()
if (caption) {
csv.push([`# ${caption}`])
}
const csvtextKey="csvtext"
for (const row of Array.from(table[0].rows)) {
const rowArray=[]
for (const cell of Array.from(row.cells)) {
var copycell=$(cell).clone()
if (MathJax) {
for (const jax of MathJax.Hub.getAllJax(cell)) {
const sourceId = jax.SourceElement().id
const txt = jax.originalText
const frame = $(copycell).find(`#${sourceId}-Frame`)
$(frame).remove()
const script = $(copycell).find(`#${sourceId}`)
$(script).replaceWith($("<span/>").text(`$${txt}$`))
}
}
for (const replace of Array.from(copycell.find(`[data-${csvtextKey}]`))) {
$(replace).replaceWith($("<span/>").text($(replace).data(csvtextKey)))
}
var text = copycell.text()
var text = copycell.text()
if (text !== "" && !checkNumber(text)) {
text = text.split('\u2011').join('-')
text = `"${text}"`
}
rowArray.push(text)
}
csv.push(rowArray)
}
for (const row of Array.from(table[0].rows)) {
for (const cell of Array.from(row.cells)) {
const rowspan = cell.rowSpan
const columnspan = cell.colSpan
const colindex = cell.cellIndex
const rowIndex = cell.parentNode.rowIndex
if (columnspan>1) {
for (let i = 1; i < rowspan; i++) {
csv[rowIndex].splice(colindex,0,"")
}
}
if (rowspan>1) {
for (let i = 0; i < columnspan; i++) {
for (let j = 1; j < rowspan; j++) {
csv[rowIndex+j].splice(colindex,0,"")
}
}
}
}
}
return csv.map(row=>row.join(",")).join("\n")
}