Last active
May 28, 2019 17:15
-
-
Save JHawk/ca0015f70d8f97804f299c0a94cbf2a2 to your computer and use it in GitHub Desktop.
Perspective Layout Controls 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 |
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
var BATCH_SIZE = 100000; | |
var MILLIS = 10; | |
var TOTAL_LIMIT = 1000000; | |
// Create random rows of data. | |
function newRows() { | |
var rows = []; | |
for (var x = 0; x < BATCH_SIZE; x++) { | |
rows.push({ | |
lastUpdate: new Date(), | |
chg: Math.random() * 20 - 10, | |
bid: Math.random() * 10 + 90, | |
ask: Math.random() * 10 + 100, | |
vol: Math.random() * 10 + 100 | |
}); | |
} | |
return rows; | |
} | |
window.addEventListener("WebComponentsReady", function() { | |
// Get element from the DOM. | |
var elem = document.getElementsByTagName("perspective-viewer")[0]; | |
// Create a new Perspective WebWorker instance. | |
var worker = perspective.worker(); | |
// Create a new Perspective table in our `worker`. | |
var table = worker.table(newRows()); | |
// Load the `table` in the `<perspective-viewer>` DOM reference. | |
elem.load(table); | |
elem.toggleConfig(); | |
// Add rows, throttled using the `update()` method on the `table` directly and stop at the limit. | |
var count = 0; | |
(function postRow() { | |
if (count < TOTAL_LIMIT) { | |
table.update(newRows()); | |
count += BATCH_SIZE; | |
console.log(count); | |
setTimeout(postRow, MILLIS); | |
} | |
})(); | |
}); |
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
perspective-viewer { | |
position: absolute; | |
top: 0; | |
left: 0; | |
right: 0; | |
bottom: 0; | |
} |
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> | |
<perspective-viewer></perspective-viewer> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment