render({
mark: { type: "bar", bar: { size: 40 } },
data: { values: portfolioData },
transform: [
{ calculate: "datum.Shares * datum.Price", as: "Total Value" },
{
window: [{ op: "sum", field: "Total Value", as: "sum" }],
frame: [null, null],
groupby: ["Date", "Investor"]
},
{
calculate: "datum['Total Value'] / datum['sum']",
as: "percent"
},
{
window: [{ op: "rank", as: "rank" }],
sort: [{ field: "Total Value", order: "descending" }],
groupby: ["Date", "Investor"]
},
],
encoding: {
column: { field: "Investor", type: "N" },
row: { field: "Date", type: "T" },
color: { field: "Symbol", type: "N" },
tooltip: [
{ field: "Symbol", type: "N" },
{ field: "Price", type: "Q" },
{ field: "Shares", type: "Q" },
{ field: "Total Value", type: "Q" },
],
x: {
field: "rank",
type: "O",
axis: null
},
y: {
field: "percent",
type: "Q",
axis: { format: ".0%", title: "Percentage" }
},
},
width: 150,
height: 200
});