Published
Edited
May 9, 2019
1 fork
Importers
13 stars
Also listed in…
Vega
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

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more