Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mathieu #2

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
71 changes: 71 additions & 0 deletions css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
*, ::before, ::after {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Roboto', sans-serif;
}

table {
border-collapse: collapse;
margin: auto;
width: 100vw;
}

h1 {
font-weight: 700;
text-align: center;
padding-top: 20px;
}

label {
font-weight: 700;
}


th,
td {
border-bottom: 1px solid black;
padding: 5px;
}

td:last-child {
text-align: center;
font-weight: 700;
color: red;
}

td:nth-child(2),
td:nth-child(3) {
text-align: center;
}

tr th {
background-color: #a6dbf1;
}

.galaxy {
padding-top: 20px;
}

#selector {
margin-bottom: 20px;
height: 30px;
border-radius: 7px;
}

#removeNull {
height: 30px;
margin-left: 10px;
padding: 0 10px;
background-color: wheat;
border-radius: 7px;
}

#removeNull:hover {
color: white;
background-color: #a6dbf1;
}

#treshold {
margin-left: 20px;
}
44 changes: 34 additions & 10 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,36 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>

</body>
</html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<link rel="stylesheet" href="css/style.css" />
</head>

<body>
<h1>Galaxy</h1>
<section class="galaxy">
<label for="selector">Choose a rank/redshift:</label>

<select name="selector" id="selector">
<option value="">--Please choose an option--</option>
</select>
<button id="removeNull">Hidden Null</button>
<label id="treshold" for="myTreshold">Treshold: </label>
<input id="myTreshold" type="range" min="1" max="100" />
<div style="display: inline-block" id="myValue"></div>
<table id="table">
<thead>
<tr>
<th>Nom</th>
<th>Data A</th>
<th>Data B</th>
<th>Seuil</th>
</tr>
</thead>
<tbody></tbody>
</table>
<script src="./js/data.js"></script>
</section>
</body>
</html>
52 changes: 52 additions & 0 deletions js/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
const data = [
{
"ContinuumAmplitude": 4.010331395e-18,
"ContinuumAmplitudeUncertainty": 6.56835958e-20,
"ContinuumIgmIndex": -1.0,
"ContinuumIsmCoeff": 0.3,
"ContinuumName": "ssp_25Myr_z008.dat",
"LeastSquare": 9631.0757555705,
"LinesRatioAmplitudeAbs": null,
"LinesRatioAmplitudeEm": 0.0390514984,
"LinesRatioIsmCoeff": 0.2,
"LinesRatioName": "tpl_COMBINE-ave-Lya-emstr-AND-StarBurst1_TF_catalog",
"Rank": 0,
"Redshift": 0.8182060549,
"RedshiftLogProbaDensity": 8.6124900394,
"RedshiftProba": 1.0,
"RedshiftProbaZmax": 0.8183878846,
"RedshiftProbaZmin": 0.8180242434,
"RedshiftUncertainty": 2.62137e-05,
"StrongEmissionLinesSNR": 155.2225563209,
"SubType": "Lya_em_SB1",
"VelocityAbsorption": 150.0,
"VelocityEmission": 10.0,
"abs_deltaZ": 6.0627e-06,
"lfHa": -15.8362358105,
"lfOII": -16.0158742307,
"snrHa": 34.4355470852,
"snrOII": 24.6779130757
},
// ... Autres objets de données
];

const tableData = Object.entries(data[0]).map(([key, value]) => {
const rowData = { Field: key };
data.forEach((obj, index) => {
rowData[`Object ${index + 1}`] = obj[key];
});
return rowData;
});

const table = new Tabulator("#example-table", {
data: tableData,
layout: "fitColumns",
columns: [
{ title: "Field", field: "Field" },
// Dynamically generate columns for each object in the data array
...data.map((_, index) => ({
title: `Object ${index + 1}`,
field: `Object ${index + 1}`,
})),
],
});
100 changes: 100 additions & 0 deletions js/data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
async function loadJSON(url) {
const response = await fetch(url);
const data = await response.json();
return data;
}

const urlJSONA = './data/221410_A.json';
const urlJSONB = './data/221410_B.json';

const dataA = loadJSON(urlJSONA);
const dataB = loadJSON(urlJSONB);

Promise.all([dataA, dataB])
.then(([arrayA, arrayB]) => {
const arrayT = [];

for (const objectA of arrayA) {
const objectB = arrayB.find((el) => el["Rank"] === objectA["Rank"]);
if (objectB) {
const result = [];
for (const key in objectA) {
if (key == "Redshift" || key == "Rank")
treshold = objectA[key];
else
treshold = (Math.round(Math.abs(objectA[key] - objectB[key]) / objectB[key] * 100 * 100) / 100);

result[key] = [objectA[key], objectB[key], treshold];
}
arrayT.push(result);
}
}
initSelector(arrayT);
})
.catch(error => {
console.error('Une erreur s\'est produite lors du chargement des données JSON :', error);
});

function initSelector(array) {
let selector = document.getElementById('selector');

for (let i = 0; i < array.length; i++) {
let option = document.createElement('option');
option.innerHTML = `${array[i]["Rank"][0]}: ${array[i]["Redshift"][0]}`;
option.setAttribute('id', "rank" + i);
selector.appendChild(option);
}

selector.addEventListener('change', () => {
let index = selector.selectedIndex;

displayArray(index - 1, array);
document.getElementById("removeNull").addEventListener("click", () => {
parseTable();
document.getElementById("removeNull").innerText = (document.getElementById("removeNull").innerText == "Hidden Null") ? "Show Null" : "Hidden Null";
});
document.getElementById("myTreshold").addEventListener('change', (e) => {
document.getElementById('myValue').innerHTML = e.target.value;
parseTreshold(e.target.value);
})
});
}

function displayArray(index, array) {
let table = document.getElementById('table');
table.children[1].innerText = "";
for (key in array[index]) {
let tr = document.createElement('tr');
let td = document.createElement('td');
td.innerHTML = key;
tr.appendChild(td);
for (let j = 0; j < array[index][key].length; j++) {
let td = document.createElement('td');
td.innerHTML = array[index][key][j];
tr.appendChild(td);
}
table.children[1].appendChild(tr);
}
}

function parseTable() {
let tbody = document.getElementById('table').children[1];

for(let i = 0; i < tbody.childElementCount; i++) {
if (tbody.children[i].firstElementChild.innerHTML != "Rank" && (tbody.children[i].lastElementChild.innerHTML == "0" || tbody.children[i].lastElementChild.innerHTML == "NaN")) {
tbody.children[i].style.display = (tbody.children[i].style.display == "none") ? "" : "none";
}
}
}

function parseTreshold(percentage) {
let tbody = document.getElementById('table').children[1];

for(let i = 0; i < tbody.childElementCount; i++) {
let treshold = percentage / 100;
console.log(treshold);
if (tbody.children[i].firstElementChild.innerHTML != "Rank" && (tbody.children[i].lastElementChild.innerHTML > treshold || tbody.children[i].lastElementChild.innerHTML == "NaN")) {
tbody.children[i].style.display = (tbody.children[i].style.display == "none") ? "" : "none";
}
}
}