Skip to content

Instantly share code, notes, and snippets.

@texodus
Last active Nov 23, 2021
Embed
What would you like to do?
Perspective / Movies
license: apache-2.0
height: 800
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
<script src="https://cdn.jsdelivr.net/npm/webfontloader"></script>
<script>WebFont.load({google:{families:["Roboto Mono:200,400","Material Icons","Open Sans:300,400"]}})</script>
<link rel='stylesheet' href="https://unpkg.com/@finos/perspective-workspace/dist/umd/material.dark.css">
<script type="module" src="https://unpkg.com/@finos/perspective-workspace/dist/cdn/perspective-workspace.js"></script>
<script type="module" src="https://unpkg.com/@finos/perspective-viewer-datagrid/dist/cdn/perspective-viewer-datagrid.js"></script>
<script type="module" src="https://unpkg.com/@finos/perspective-viewer-d3fc/dist/cdn/perspective-viewer-d3fc.js"></script>
<script type="module" src="https://unpkg.com/@finos/perspective/dist/cdn/perspective.js"></script>
<style>
body {
display: flex;
flex-direction: column;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: 0;
padding: 0;
overflow: hidden;
}
perspective-viewer {
--d3fc-positive--gradient: linear-gradient(
#94D0FF,
#8795E8,
#966bff,
#AD8CFF,
#C774E8,
#c774a9,
#FF6AD5,
#ff6a8b,
#ff8b8b,
#ffa58b,
#ffde8b,
#cdde8b,
#8bde8b,
#20de8b
) !important;
--d3fc-negative--gradient: linear-gradient(
#94D0FF,
#8795E8,
#966bff,
#AD8CFF,
#C774E8,
#c774a9,
#FF6AD5,
#ff6a8b,
#ff8b8b,
#ffa58b,
#ffde8b,
#cdde8b,
#8bde8b,
#20de8b
) !important;
--d3fc-full--gradient: linear-gradient(
#94D0FF,
#8795E8,
#966bff,
#AD8CFF,
#C774E8,
#c774a9,
#FF6AD5,
#ff6a8b,
#ff8b8b,
#ffa58b,
#ffde8b,
#cdde8b,
#8bde8b,
#20de8b
) !important;
}
</style>
</head>
<body>
<perspective-workspace id="workspace">
<perspective-viewer table="movies"></perspective-viewer>
</perspective-workspace>
<script type="module">
import perspective from "https://unpkg.com/@finos/perspective/dist/cdn/perspective.js";
const SCHEMA = {
"Title": "string",
"US Gross": "float",
"Worldwide Gross": "float",
"US DVD Sales": "float",
"Production Budget": "float",
"Release Date": "date",
"MPAA Rating": "string",
"Running Time min": "integer",
"Distributor": "string",
"Source": "string",
"Major Genre": "string",
"Creative Type": "string",
"Director": "string",
"Rotten Tomatoes Rating": "integer",
"IMDB Rating": "float",
"IMDB Votes": "integer"
};
const MOVIES_URL = "https://vega.github.io/editor/data/movies.json";
const datasource = async () => {
const request = fetch(MOVIES_URL);
const worker = perspective.worker();
const response = await request;
const json = await response.json();
for (const row of json) {
row["Release Date"] = row["Release Date"] ? new Date(row["Release Date"]) || null : null;
}
const table = await worker.table(SCHEMA);
table.update(json);
return table;
};
window.addEventListener("load", async () => {
let req = await fetch("layout.json");
let layout = await req.json();
window.workspace.tables.set("movies", datasource());
window.workspace.restore(layout);
});
</script>
</body>
</html>
{
"sizes": [0.350418410041841, 0.649581589958159],
"detail": {
"main": {
"type": "split-area",
"orientation": "vertical",
"children": [
{
"type": "tab-area",
"widgets": [
"PERSPECTIVE_GENERATED_ID_0",
"PERSPECTIVE_GENERATED_ID_3"
],
"currentIndex": 0
},
{
"type": "tab-area",
"widgets": ["PERSPECTIVE_GENERATED_ID_1"],
"currentIndex": 0
}
],
"sizes": [0.5, 0.5]
}
},
"mode": "globalFilters",
"master": {
"widgets": ["PERSPECTIVE_GENERATED_ID_2"],
"sizes": [1]
},
"viewers": {
"PERSPECTIVE_GENERATED_ID_2": {
"selectable": true,
"plugin": "Datagrid",
"row_pivots": ["Distributor"],
"aggregates": {
"IMDB Rating": "avg"
},
"sort": [["US Gross", "desc"]],
"columns": ["US Gross"],
"expressions": null,
"column_pivots": null,
"filter": null,
"plugin_config": {
"IMDB Rating": {
"color_mode": "gradient",
"pos_color": "#b87ff0",
"neg_color": "#FF9485",
"gradient": 8.1
},
"US Gross": {
"color_mode": "gradient",
"pos_color": "#126e3a",
"neg_color": "#FF9485",
"gradient": 19729862602
}
},
"master": true,
"name": null,
"table": "movies",
"linked": false
},
"PERSPECTIVE_GENERATED_ID_0": {
"plugin": "X/Y Scatter",
"row_pivots": ["Title"],
"aggregates": {
"IMDB Rating": "avg",
"Rotten Tomatoes Rating": "avg",
"Director": "last",
"Release Date": "last",
"MPAA Rating": "last"
},
"sort": [["US Gross", "asc"]],
"columns": [
"Rotten Tomatoes Rating",
"IMDB Rating",
"US Gross",
null,
"Director",
"Release Date",
"MPAA Rating"
],
"selectable": null,
"expressions": null,
"column_pivots": null,
"filter": null,
"plugin_config": {
"realValues": [
"Rotten Tomatoes Rating",
"IMDB Rating",
"US Gross",
null,
"Director",
"Release Date",
"MPAA Rating"
],
"zoom": {
"k": 1,
"x": 0,
"y": 0
}
},
"master": false,
"name": null,
"table": "movies",
"linked": false
},
"PERSPECTIVE_GENERATED_ID_3": {
"plugin": "Y Area",
"expressions": ["bucket(\"Release Date\", 'Y')"],
"row_pivots": ["bucket(\"Release Date\", 'Y')"],
"aggregates": {
"Rotten Tomatoes Rating": "avg"
},
"columns": ["US Gross"],
"column_pivots": ["Major Genre"],
"selectable": null,
"filter": null,
"sort": null,
"plugin_config": {
"realValues": ["US Gross"],
"legend": {
"left": "91px",
"top": "25px"
}
},
"master": false,
"name": "US Gross by Genre",
"table": "movies",
"linked": false
},
"PERSPECTIVE_GENERATED_ID_1": {
"plugin": "Y Line",
"expressions": ["bucket(\"Release Date\", 'Y')"],
"row_pivots": ["bucket(\"Release Date\", 'Y')"],
"aggregates": {
"Rotten Tomatoes Rating": "avg"
},
"columns": [
"US Gross",
"Rotten Tomatoes Rating",
"Production Budget",
"Worldwide Gross",
"US DVD Sales"
],
"selectable": null,
"column_pivots": null,
"filter": null,
"sort": null,
"plugin_config": {
"realValues": [
"US Gross",
"Rotten Tomatoes Rating",
"Production Budget",
"Worldwide Gross",
"US DVD Sales"
],
"splitMainValues": ["Rotten Tomatoes Rating"],
"legend": {
"left": "79px",
"top": "174px"
}
},
"master": false,
"name": "Ratings vs Sales",
"table": "movies",
"linked": false
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment