A demo of linked <perspective-viewer>
s using superstore.arrow
.
Last active
July 15, 2019 16:45
-
-
Save JHawk/9b20383f042853f27c6e720baf4a19db to your computer and use it in GitHub Desktop.
Perspective Viewers Linked Through Click Events Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
license: apache-2.0 | |
height: 1200 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ARROW = "https://unpkg.com/@jpmorganchase/perspective-examples/build/superstore.arrow"; | |
window.addEventListener('WebComponentsReady', function() { | |
// Fetch and load arrow data. | |
var xhr = new XMLHttpRequest(); | |
xhr.open('GET', ARROW, true); | |
xhr.responseType = "arraybuffer" | |
xhr.onload = function() { | |
// Get `<perspective-viewer>`s from the DOM. | |
var el1 = document.getElementsByTagName('perspective-viewer')[0]; | |
var el2 = document.getElementsByTagName('perspective-viewer')[1]; | |
// Create a `table()` using the arrow response. | |
var table = perspective.shared_worker().table(xhr.response); | |
// Load the table in each of the `<perspective-viewer>`s DOM reference. | |
el1.load(table); | |
el2.load(table); | |
// Add an event listener to the first `<perspective-viewer>`. | |
el1.addEventListener("perspective-click", e => { | |
// Update the second `<perspective-viewer>`, filtering to the row | |
// clicked on in the first `<perspective-viewer>`. | |
el2.restore(e.detail.config) | |
}); | |
} | |
xhr.send(null); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#grid { | |
display: flex; | |
max-width: 600px; | |
max-height: 1200px; | |
margin: auto; | |
flex-direction: column; | |
} | |
#grid perspective-viewer { | |
height: 600px; | |
width: 600px; | |
flex: 1; | |
display: block; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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="https://unpkg.com/@finos/perspective/build/perspective.js"></script> | |
<script src="https://unpkg.com/@finos/perspective-viewer/build/perspective.view.js"></script> | |
<script src="https://unpkg.com/@finos/perspective-viewer-hypergrid/build/hypergrid.plugin.js"></script> | |
<script src="https://unpkg.com/@finos/perspective-viewer-d3fc/build/d3fc.plugin.js"></script> | |
<script src="example.js"></script> | |
<link rel='stylesheet' href="index.css"> | |
<link rel='stylesheet' href="https://unpkg.com/@finos/perspective-viewer/build/material.css" is="custom-style"> | |
</head> | |
<body> | |
<div id="grid"> | |
<perspective-viewer row-pivots='["Region","State","City"]' sort='[["Profit","desc"]]' columns='["Sales", "Profit"]'></perspective-viewer> | |
<perspective-viewer view="d3_sunburst" row-pivots='["Category","Sub-Category","Segment"]' sort='[["Profit","desc"]]' columns='["Sales", "Profit"]'></perspective-viewer> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment