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

New plugin @finos/perspective-viewer-datagrid #954

Merged
merged 4 commits into from
Mar 10, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Styling, examples and refactoring.
  • Loading branch information
texodus committed Feb 28, 2020
commit ea3f0d9642fc839607a1f31e4d953156a297d764
94 changes: 80 additions & 14 deletions examples/simple/superstore-custom-grid.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
<script src="perspective-viewer-datagrid.js"></script>

<link rel='stylesheet' href="index.css">
<link rel='stylesheet' href="material-dense.css" is="custom-style">
<link rel='stylesheet' href="material-dense.dark.css" is="custom-style">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Orbitron">


</head>

Expand All @@ -31,8 +33,9 @@

<script>


function hue(value, min, max) {
const norm = "0" + Math.abs(Math.round(255 * Math.min(Math.max(value, min), max))).toString(16);
const norm = "0" + Math.abs(Math.round(255 * (Math.min(Math.max(value, min), max) / (max - min)))).toString(16);
return norm.slice(norm.length - 2, norm.length);
}

Expand All @@ -44,51 +47,70 @@
viewer.toggleConfig();

const CACHE = {}
let max = -Infinity;

viewer.addEventListener("perspective-config-update", () => {
max = -Infinity;
});

viewer.addEventListener("perspective-datagrid-after-update", () => {

const cache = Object.keys(CACHE).reduce((obj, key) => {
obj[key] = CACHE[key].slice();
return obj;
}, {});



for (const td of document.querySelectorAll("perspective-viewer td")) {

const clean_name = td.value && td.value.trim && td.value.trim();
if (td.classList.contains("float")) {
if (td.value < 0) {
td.style.color = "#fff";
td.style.backgroundColor = `#${hue(td.value, -100, 0)}0000`;
const fg = hue(Math.min(td.value, -50), -100, 0);
td.style.color = `#${fg}${fg}${fg}`;
td.style.background = `radial-gradient(#${hue(Math.min(td.value, -20), -100, 0)}3136, #243136`;;
td.style.border = `1px solid #${hue(Math.min(td.value / 3, -20), -100, 0)}3136`;;
} else if (td.value > 0) {
td.style.color = "#fff";
td.style.backgroundColor = `#00${hue(td.value, 0, 100)}00`;
const fg = hue(Math.max(td.value, 50), 0, 100);
td.style.color = `#${fg}${fg}${fg}`;
td.style.background = `radial-gradient(#24${hue(Math.max(20, td.value), 0, 100)}36, #243136`
td.style.border = `1px solid #24${hue(Math.max(td.value / 3, 20), 0, 100)}36`;;
} else {
td.style.color = "#000";
td.style.backgroundColor = "";
td.style.background = "";
td.style.border = ``;;
}
} else if (td.classList.contains("integer")) {
td.style.backgroundColor = "";
td.style.background = "";
td.style.border = ``;;
if (!td.value) {
} else {
td.innerHTML = `<div style="height:15px;width:${td.value || 0}px;background:linear-gradient(90deg, #2bb0af 0, #23a7d7);"><div>`;
max = Math.max(max, td.value || 0);
console.log(max)
let v = (td.value || 0) / max
td.innerHTML = `<div style="height:15px;width:${v * 100}%;background:linear-gradient(90deg, #2bb0af 0, #23a7d7);"><div>`;
}
} else if (states[clean_name]) {
td.style.backgroundColor = "";
td.style.background = "";
td.style.border = ``;;
if (cache[clean_name] && cache[clean_name].length > 0) {
const name = td.value;
td.innerHTML = "";
td.textContent = "";
td.appendChild(cache[name].pop());
} else {
const name = td.value;
img = document.createElement("img");
img.setAttribute("src", `https://perspective.finos.org/img/flags/${states[clean_name].toLowerCase()}.png`);
img.setAttribute("src", `http://perspective.finos.org/img/flags/${states[clean_name].toLowerCase()}.png`);
img.setAttribute("height", "15");
td.textContent = "";
td.appendChild(img);
CACHE[name] = CACHE[name] || [];
CACHE[name].push(img);
}

} else {
td.style.backgroundColor = "";
td.style.border = ``;;
td.style.background = "";
td.style.color = "";
}
}
Expand All @@ -102,6 +124,7 @@
"California": "CA",
"Colorado": "CO",
"Connecticut": "CT",
"District of Columbia": "DC",
"Delaware": "DE",
"Florida": "FL",
"Georgia": "GA",
Expand Down Expand Up @@ -150,6 +173,49 @@
});
</script>

<style>
td {
height: 24px;
}
tr td.pd-group-header, tr th.pd-group-header {
border-right: 1px solid #666 !important;
}
tbody:hover tr {
opacity: 0.5;
transition: opacity 0.2s ease-in;
}
tbody:hover tr:hover td div {
transform: scaleX(1.3);
transform-origin:0;
transition: transform 0.2s ease-in;
}
tbody:hover tr:hover {
box-shadow: 0px 0px 20px rgba(0,0,0,0.4);
opacity: 1;
transition: none;
}
tr:last-child th {
border-bottom: 1px solid #666;
}
tr th {
border-right: 1px solid #666;
}
tbody:hover tr:hover td {
background: none;
opacity: 1;
}
tbody:hover tr:nth-child(even):hover td, tbody tr:nth-child(even) td {
background: rgba(0,0,0,0.1);
}
td.float {
text-align: center !important;
font-family: Orbitron;
}
th.integer, td.integer {
width: 100px;
}

</style>
</body>

</html>
Expand Down
46 changes: 46 additions & 0 deletions examples/simple/superstore-datagrid.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!--

Copyright (c) 2017, the Perspective Authors.

This file is part of the Perspective library, distributed under the terms of
the Apache License 2.0. The full license can be found in the LICENSE file.

-->

<!DOCTYPE html>
<html>

<head>

<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">

<script src="perspective-viewer.js"></script>
<script src="perspective-viewer-datagrid.js"></script>
<script src="perspective-viewer-d3fc.js"></script>

<script src="perspective.js"></script>

<link rel='stylesheet' href="index.css">
<link rel='stylesheet' href="material-dense.css" is="custom-style">


</head>

<body>

<perspective-viewer plugin="datagrid" >

</perspective-viewer>

<script>
window.addEventListener('WebComponentsReady', async function() {
const viewer = document.getElementsByTagName('perspective-viewer')[0];
const data = await fetch("superstore.arrow");
viewer.load(await data.arrayBuffer());
viewer.toggleConfig();
});
</script>

</body>

</html>
Loading