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
Next Next commit
Adds @finos/perspective-viewer-datagrid.
  • Loading branch information
texodus committed Feb 28, 2020
commit 2e2f84e190dcfaa783497943c503dac0d42c286e
158 changes: 158 additions & 0 deletions examples/simple/superstore-custom-grid.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
<!--

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>

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

</head>

<body>

<perspective-viewer plugin="datagrid" columns='["Profit", "Sub-Category",
"State", "Sales", "Category", "Order Date", "Quantity"]'>

</perspective-viewer>

<script>

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

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

const CACHE = {}

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`;
} else if (td.value > 0) {
td.style.color = "#fff";
td.style.backgroundColor = `#00${hue(td.value, 0, 100)}00`;
} else {
td.style.color = "#000";
td.style.backgroundColor = "";
}
} else if (td.classList.contains("integer")) {
td.style.backgroundColor = "";
if (!td.value) {
} else {
td.innerHTML = `<div style="height:15px;width:${td.value || 0}px;background:linear-gradient(90deg, #2bb0af 0, #23a7d7);"><div>`;
}
} else if (states[clean_name]) {
td.style.backgroundColor = "";
if (cache[clean_name] && cache[clean_name].length > 0) {
const name = td.value;
td.innerHTML = "";
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("height", "15");
td.appendChild(img);
CACHE[name] = CACHE[name] || [];
CACHE[name].push(img);
}

} else {
td.style.backgroundColor = "";
td.style.color = "";
}
}
});

const states = {
"Alabama": "AL",
"Alaska": "AK",
"Arizona": "AZ",
"Arkansas": "AR",
"California": "CA",
"Colorado": "CO",
"Connecticut": "CT",
"Delaware": "DE",
"Florida": "FL",
"Georgia": "GA",
"Hawaii": "HI",
"Idaho": "ID",
"Illinois": "IL",
"Indiana": "IN",
"Iowa": "IA",
"Kansas": "KS",
"Kentucky": "KY",
"Louisiana": "LA",
"Maine": "ME",
"Maryland": "MD",
"Massachusetts": "MA",
"Michigan": "MI",
"Minnesota": "MN",
"Mississippi": "MS",
"Missouri": "MO",
"Montana": "MT",
"Nebraska": "NE",
"Nevada": "NV",
"New Hampshire": "NH",
"New Jersey": "NJ",
"New Mexico": "NM",
"New York": "NY",
"North Carolina": "NC",
"North Dakota": "ND",
"Ohio": "OH",
"Oklahoma": "OK",
"Oregon": "OR",
"Pennsylvania": "PA",
"Rhode Island": "RI",
"South Carolina": "SC",
"South Dakota": "SD",
"Tennessee": "TN",
"Texas": "TX",
"Utah": "UT",
"Vermont": "VT",
"Virginia": "VA",
"Washington": "WA",
"West Virginia": "WV",
"Wisconsin": "WI",
"Wyoming": "WY"
};

});
</script>

</body>

</html>



21 changes: 21 additions & 0 deletions packages/perspective-viewer-datagrid/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = {
presets: [
[
"@babel/preset-env",
{
targets: {
chrome: "70",
node: "8",
ios: "12",
safari: "12",
edge: "44"
},
modules: false,
useBuiltIns: "usage",
corejs: 3
}
]
],
sourceType: "unambiguous",
plugins: ["lodash", ["@babel/plugin-proposal-decorators", {legacy: true}], "transform-custom-element-classes", "@babel/plugin-proposal-optional-chaining"]
};
47 changes: 47 additions & 0 deletions packages/perspective-viewer-datagrid/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"name": "@finos/perspective-viewer-datagrid",
"version": "0.4.3",
"description": "Perspective.js",
"main": "dist/cjs/perspective-viewer-datagrid.js",
"module": "dist/cjs/perspective-viewer-datagrid.js",
"browser": "dist/cjs/perspective-viewer-datagrid.js",
"unpkg": "dist/umd/perspective-viewer-datagrid.js",
"files": [
"dist/**/*",
"babel.config.js"
],
"scripts": {
"bench": "npm-run-all bench:build bench:run",
"bench:build": "echo \"No Benchmarks\"",
"bench:run": "echo \"No Benchmarks\"",
"prebuild": "mkdirp dist/esm",
"build:babel": "cpx \"src/**/*\" dist && babel src/js --source-maps --out-dir dist/esm",
"build:webpack:esm": "webpack --color --config src/config/cjs.config.js",
"build:webpack:umd": "webpack --color --config src/config/umd.config.js",
"build": "npm-run-all build:babel build:webpack:esm build:webpack:umd",
"test:build": "cpx \"test/html/*\" dist/umd",
"test:run": "jest --rootDir=. --config=../perspective-test/jest.config.js --silent --color 2>&1",
"test": "npm-run-all test:build test:run",
"clean": "rimraf dist",
"clean:screenshots": "rimraf \"screenshots/**/*.@(failed|diff).png\""
},
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "https://github.com/finos/perspective"
},
"author": "",
"license": "Apache-2.0",
"dependencies": {
"@finos/perspective": "^0.4.2",
"@finos/perspective-viewer": "^0.4.3",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are older versions of "@finos/perspective" and "@finos/perspective-viewer", mind updating to latest @texodus?

"core-js": "^3.6.4",
"superscript-number": "^1.0.0"
},
"devDependencies": {
"@finos/perspective-test": "^0.4.3",
"@finos/perspective-webpack-plugin": "^0.4.1"
}
}
15 changes: 15 additions & 0 deletions packages/perspective-viewer-datagrid/src/config/cjs.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const path = require("path");
const common = require("@finos/perspective/src/config/common.config.js");

module.exports = common({}, config =>
Object.assign(config, {
entry: "./dist/esm/datagrid.js",
externals: [/^[a-z0-9@]/],
output: {
filename: "perspective-viewer-datagrid.js",
library: "perspective-viewer-datagrid",
libraryTarget: "umd",
path: path.resolve(__dirname, "../../dist/cjs")
}
})
);
14 changes: 14 additions & 0 deletions packages/perspective-viewer-datagrid/src/config/umd.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const path = require("path");
const common = require("@finos/perspective/src/config/common.config.js");

module.exports = common({}, config =>
Object.assign(config, {
entry: "./dist/cjs/perspective-viewer-datagrid.js",
output: {
filename: "perspective-viewer-datagrid.js",
library: "perspective-viewer-datagrid",
libraryTarget: "umd",
path: path.resolve(__dirname, "../../dist/umd")
}
})
);
Loading