Skip to content

Commit

Permalink
docs: Add density-groups example.
Browse files Browse the repository at this point in the history
  • Loading branch information
jheer committed Dec 4, 2024
1 parent 613ad10 commit 9933d26
Show file tree
Hide file tree
Showing 10 changed files with 435 additions and 0 deletions.
1 change: 1 addition & 0 deletions dev/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<option value="bias">Bias Parameter</option>
<option value="contours">Contours</option>
<option value="crossfilter">Crossfilter</option>
<option value="density-groups">Density Groups</option>
<option value="density1d">Density 1D</option>
<option value="density2d">Density 2D</option>
<option value="driving-shifts">Driving Shifts into Reverse</option>
Expand Down
1 change: 1 addition & 0 deletions docs/.vitepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ export default defineConfig({
collapsed: true,
items: [
{ text: 'Contours', link: '/examples/contours' },
{ text: 'Density Groups', link: '/examples/density-groups' },
{ text: 'Density 1D', link: '/examples/density1d' },
{ text: 'Density 2D', link: '/examples/density2d' },
{ text: 'Flights Density', link: '/examples/flights-density' },
Expand Down
18 changes: 18 additions & 0 deletions docs/examples/density-groups.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<script setup>
import { coordinator } from '@uwdata/vgplot';
coordinator().clear();
</script>

# Density Groups

Density plots of penguin bill depths, grouped by species. The normalize parameter supporting different forms of comparison, controlling if an individual density estimate is scaled by total point mass or normalized by the sum or max of the point mass. The stack and offset parameters control stacking of density areas.

<Example spec="/specs/yaml/density-groups.yaml" />

## Specification

::: code-group
<<< @/public/specs/esm/density-groups.js [JavaScript]
<<< @/public/specs/yaml/density-groups.yaml [YAML]
<<< @/public/specs/json/density-groups.json [JSON]
:::
42 changes: 42 additions & 0 deletions docs/public/specs/esm/density-groups.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import * as vg from "@uwdata/vgplot";

await vg.coordinator().exec([
vg.loadParquet("penguins", "data/penguins.parquet")
]);

const $bandwidth = vg.Param.value(20);
const $normalize = vg.Param.value("none");
const $stack = vg.Param.value(false);
const $offset = vg.Param.value(null);

export default vg.vconcat(
vg.hconcat(
vg.menu({label: "Normalize", as: $normalize, options: ["none", "sum", "max"]}),
vg.menu({label: "Stack", as: $stack, options: [false, true]}),
vg.menu({
label: "Offset",
as: $offset,
options: [
{label: "none", value: null},
{label: "normalize", value: "normalize"},
{label: "center", value: "center"}
]
})
),
vg.plot(
vg.densityY(
vg.from("penguins"),
{
x: "bill_depth",
fill: "species",
fillOpacity: 0.4,
bandwidth: $bandwidth,
normalize: $normalize,
stack: $stack,
offset: $offset
}
),
vg.marginLeft(50),
vg.height(200)
)
);
80 changes: 80 additions & 0 deletions docs/public/specs/json/density-groups.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
"meta": {
"title": "Density Groups",
"description": "Density plots of penguin bill depths, grouped by species. The normalize parameter supporting different forms of comparison, controlling if an individual density estimate is scaled by total point mass or normalized by the sum or max of the point mass. The stack and offset parameters control stacking of density areas.\n"
},
"data": {
"penguins": {
"file": "data/penguins.parquet"
}
},
"params": {
"bandwidth": 20,
"normalize": "none",
"stack": false,
"offset": null
},
"vconcat": [
{
"hconcat": [
{
"input": "menu",
"label": "Normalize",
"as": "$normalize",
"options": [
"none",
"sum",
"max"
]
},
{
"input": "menu",
"label": "Stack",
"as": "$stack",
"options": [
false,
true
]
},
{
"input": "menu",
"label": "Offset",
"as": "$offset",
"options": [
{
"label": "none",
"value": null
},
{
"label": "normalize",
"value": "normalize"
},
{
"label": "center",
"value": "center"
}
]
}
]
},
{
"plot": [
{
"mark": "densityY",
"data": {
"from": "penguins"
},
"x": "bill_depth",
"fill": "species",
"fillOpacity": 0.4,
"bandwidth": "$bandwidth",
"normalize": "$normalize",
"stack": "$stack",
"offset": "$offset"
}
],
"marginLeft": 50,
"height": 200
}
]
}
44 changes: 44 additions & 0 deletions docs/public/specs/yaml/density-groups.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
meta:
title: Density Groups
description: >
Density plots of penguin bill depths, grouped by species.
The normalize parameter supporting different forms of comparison,
controlling if an individual density estimate is scaled by total point
mass or normalized by the sum or max of the point mass.
The stack and offset parameters control stacking of density areas.
data:
penguins: { file: data/penguins.parquet }
params:
bandwidth: 20
normalize: none
stack: false
offset: null
vconcat:
- hconcat:
- input: menu
label: Normalize
as: $normalize
options: [none, sum, max]
- input: menu
label: Stack
as: $stack
options: [false, true]
- input: menu
label: Offset
as: $offset
options:
- { label: none, value: null }
- { label: normalize, value: normalize }
- { label: center, value: center }
- plot:
- mark: densityY
data: { from: penguins }
x: bill_depth
fill: species
fillOpacity: 0.4
bandwidth: $bandwidth
normalize: $normalize
stack: $stack
offset: $offset
marginLeft: 50
height: 200
42 changes: 42 additions & 0 deletions specs/esm/density-groups.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import * as vg from "@uwdata/vgplot";

await vg.coordinator().exec([
vg.loadParquet("penguins", "data/penguins.parquet")
]);

const $bandwidth = vg.Param.value(20);
const $normalize = vg.Param.value("none");
const $stack = vg.Param.value(false);
const $offset = vg.Param.value(null);

export default vg.vconcat(
vg.hconcat(
vg.menu({label: "Normalize", as: $normalize, options: ["none", "sum", "max"]}),
vg.menu({label: "Stack", as: $stack, options: [false, true]}),
vg.menu({
label: "Offset",
as: $offset,
options: [
{label: "none", value: null},
{label: "normalize", value: "normalize"},
{label: "center", value: "center"}
]
})
),
vg.plot(
vg.densityY(
vg.from("penguins"),
{
x: "bill_depth",
fill: "species",
fillOpacity: 0.4,
bandwidth: $bandwidth,
normalize: $normalize,
stack: $stack,
offset: $offset
}
),
vg.marginLeft(50),
vg.height(200)
)
);
81 changes: 81 additions & 0 deletions specs/json/density-groups.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{
"meta": {
"title": "Density Groups",
"description": "Density plots of penguin bill depths, grouped by species. The normalize parameter supporting different forms of comparison, controlling if an individual density estimate is scaled by total point mass or normalized by the sum or max of the point mass. The stack and offset parameters control stacking of density areas.\n"
},
"data": {
"penguins": {
"type": "parquet",
"file": "data/penguins.parquet"
}
},
"params": {
"bandwidth": 20,
"normalize": "none",
"stack": false,
"offset": null
},
"vconcat": [
{
"hconcat": [
{
"input": "menu",
"label": "Normalize",
"as": "$normalize",
"options": [
"none",
"sum",
"max"
]
},
{
"input": "menu",
"label": "Stack",
"as": "$stack",
"options": [
false,
true
]
},
{
"input": "menu",
"label": "Offset",
"as": "$offset",
"options": [
{
"label": "none",
"value": null
},
{
"label": "normalize",
"value": "normalize"
},
{
"label": "center",
"value": "center"
}
]
}
]
},
{
"plot": [
{
"mark": "densityY",
"data": {
"from": "penguins"
},
"x": "bill_depth",
"fill": "species",
"fillOpacity": 0.4,
"bandwidth": "$bandwidth",
"normalize": "$normalize",
"stack": "$stack",
"offset": "$offset"
}
],
"marginLeft": 50,
"height": 200
}
]
}
Loading

0 comments on commit 9933d26

Please sign in to comment.