Published
Edited
May 9, 2019
1 fork
Importers
13 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
data = fetchData(dataUrl)
Insert cell
html `<div id="grid"></div>`
Insert cell
dataGrid = new Hypergrid(document.querySelector('div#grid'), {data: []});
Insert cell
showData(data, dataGrid)
Insert cell
Insert cell
styles = html`
<style>
input[type="text"] {
width: 700px;
}
#grid {
position: relative;
width: 100%;
height: 600px;
border: 1px solid #666;
}
<style>
`
Insert cell
Insert cell
dataParam = new URLSearchParams(html`<a href>`.search).get('data')
Insert cell
Insert cell
Insert cell
async function fetchData(dataUrl) {
let data = [];
console.log('fetchData:dataUrl:', dataUrl);
if (dataUrl.endsWith('.csv')) {
data = await d3Fetch.csv(dataUrl);
}
else if (dataUrl.endsWith('.json')) {
data = await d3Fetch.json(dataUrl);
}
else if (dataUrl.endsWith('.arrow')) {
data = loadArrowData(dataUrl);
}
return data;
}
Insert cell
async function loadArrowData(dataUrl){
const response = await fetch(dataUrl);
const arrayBuffer = await response.arrayBuffer();
const table = arrow.Table.from(new Uint8Array(arrayBuffer));
const rows = Array(table.length);
const fields = table.schema.fields.map(d => d.name);
for (let i=0, n=rows.length; i<n; ++i) {
const proto = {};
fields.forEach((fieldName, index) => {
const column = table.getColumnAt(index);
proto[fieldName] = column.get(i);
});
rows[i] = proto;
}
return rows;
}
Insert cell
function showData(data, grid) {
grid.reset();
grid.setData({data: data});
grid.behaviorChanged();
grid.repaint();
return grid;
}
Insert cell
Insert cell
Insert cell
d3Fetch = require("d3-fetch@1.1.2")
Insert cell
Hypergrid = require('https://fin-hypergrid.github.io/core/3.2.1/build/fin-hypergrid.js').catch(() => window.fin.Hypergrid)
Insert cell
arrow = require('apache-arrow@0.4.1')
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more