|
const SCHEMA = { |
|
athlete: "string", |
|
age: "integer", |
|
country: "string", |
|
year: "string", |
|
date: "date", |
|
sport: "string", |
|
gold: "integer", |
|
silver: "integer", |
|
bronze: "integer", |
|
total: "integer", |
|
|
|
} |
|
|
|
// Define the perspective-viewer configs |
|
const viewers = { |
|
One: { |
|
"row-pivots": ["country"], |
|
sort: [["gold", "desc"]], |
|
columns: ["gold", "silver", "bronze"], |
|
table: "olympics" |
|
}, |
|
Two:{ |
|
"row-pivots": ["athlete"], |
|
"column-pivots": ["year"], |
|
aggregates: { |
|
age: "avg", |
|
sport: "dominant" |
|
}, |
|
sort: [["total", "desc"]], |
|
columns: ["gold", "silver", "bronze", "total"], |
|
name: "Athletes by Year", |
|
table: "olympics" |
|
}, |
|
Three:{ |
|
plugin: "xy_scatter", |
|
"row-pivots": ["athlete"], |
|
aggregates: { |
|
age: "avg", |
|
sport: "dominant" |
|
}, |
|
columns: ["age", "sport", "total", null, null], |
|
name: "Sports by Age", |
|
table: "olympics" |
|
}, |
|
Four: { |
|
plugin: "y_bar", |
|
"row-pivots": ["year"], |
|
filters: [ |
|
["country", "==", "Great Britain"], |
|
["year", "in", ["2000", "2004", "2008", "2012", ""]] |
|
], |
|
columns: ["gold", "total"], |
|
name: "Medals by Year (Summer)", |
|
table: "olympics" |
|
}, |
|
Five: { |
|
plugin: "y_bar", |
|
"row-pivots": ["year"], |
|
filters: [ |
|
["country", "==", "Great Britain"], |
|
["year", "in", ["2002", "2006", "2010"]] |
|
], |
|
columns: ["gold", "total"], |
|
name: "Medals by Year (Winter)", |
|
table: "olympics" |
|
} |
|
} |
|
|
|
const detail = { |
|
main: { |
|
type: "split-area", |
|
orientation: "vertical", |
|
children: [ |
|
{ |
|
type: "tab-area", |
|
widgets: ["Two"], |
|
currentIndex: 0 |
|
}, |
|
{ |
|
type: "split-area", |
|
orientation: "horizontal", |
|
children: [ |
|
{ |
|
type: "tab-area", |
|
widgets: ["Three"], |
|
currentIndex: 0 |
|
}, |
|
{ |
|
type: "tab-area", |
|
widgets: ["Four","Five"], |
|
currentIndex: 0 |
|
} |
|
], |
|
sizes: [0.7,0.3] |
|
} |
|
], |
|
sizes: [0.5,0.5] |
|
} |
|
} |
|
|
|
window.addEventListener("load", function() { |
|
//request data and initialise table |
|
const request = fetch("https://raw.githubusercontent.com/ag-grid/ag-grid/master/packages/ag-grid-docs/src/olympicWinnersSmall.json") |
|
const worker = perspective.worker(); |
|
const table = worker.table(SCHEMA); |
|
|
|
request |
|
.then(response => response.json() |
|
.then(data => { |
|
table.update(data) |
|
})) |
|
|
|
|
|
const workspace = this.document.getElementById("workspace") |
|
window.workspace.tables.set("olympics", table); |
|
|
|
const config = { |
|
master: { |
|
widgets: ["One"] |
|
}, |
|
detail, |
|
viewers |
|
}; |
|
|
|
workspace.restore(config) |
|
}); |