Skip to content

Instantly share code, notes, and snippets.

@dm-p
Last active September 26, 2022 19:54
Embed
What would you like to do?
Hill and Valley Chart Starting Point - A shaded area chart that shows actual vs. target. Includes linear interpolation to ensure that if lines intersect between points on the x-axis, then they are masked accordingly. If Actual does not meet target, then the area is shaded red, if Actual exceeds Target, this is shaded green.
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"usermeta": {
"deneb": {
"build": "1.3.0.0",
"metaVersion": 1,
"provider": "vegaLite",
"providerVersion": "5.2.0"
},
"interactivity": {
"tooltip": false,
"contextMenu": false,
"selection": false,
"highlight": false,
"dataPointLimit": 50
},
"information": {
"name": "Hill and Valley Chart Starting Point",
"description": "A shaded area chart that shows actual vs. target. Includes linear interpolation to ensure that if lines intersect between points on the x-axis, then they are masked accordingly. If Actual does not meet target, then the area is shaded red, if Actual exceeds Target, this is shaded green.",
"author": "Daniel Marsh-Patrick",
"uuid": "c310368f-4a62-40f2-8ebf-653c031d853e",
"generated": "2022-08-23T08:52:56.436Z",
"previewImageBase64PNG": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJYAAABRCAYAAAAw7F/uAAAbrklEQVR4Xu1dCVSURxKuYS6QQ+5DQFFRAQVBREERA4gI4pmY48WY7CaazSJgMMaNMWo0iWZjBAbNZjUmxmTjFROVQ25vQEBRLrkUkfu+5BqGmX01MBzDHP8/M4gR+j2eT+iuqq7+/u76q6rrp8BYG9PAMGiAIoImHQA4AEADAB4AcHv7KPX+i/+n9vbBv4+1MQ0M0YAAWAYAMA4A6gBgGgAwe0GFIKsCAOynBQDdvYDC/2Pfx2M6HdOAKA0IgKXaC6hmABjfuyPhroTtae+uhb/vGECkAQCKx9Q6pgFJwBL8DXetNqGOCDA8FjvHVDimAaIaEGVjER071m9MA2I1MOqBFbJ379dKWloJfn5+0WM4UZwGxoC1fXsMhcn803/v3v8oTq1jlEY1sFgslgY3KzMOlFXStrBY/xyDg+I0MKqBFRoaasGJiopQMjMrbtDTW7Jnzx6Bz05x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Ggo+qDhnYd2gPjDzGGlhJT18qbuDelQEsHCCKDQyRwWmigGWDSY69ioNQYbGPypEXDFYtOXwG4hYpUwAxFK8mCNmEbESIS4O9kdg4a0HnLC4hUel4JeqkA/WKELAYG0kcfRxQfDBwX+xWBYuOH44afD1oH7hUC+YeI4F7RCwKA8uvLi78Sg76gW/G4m6QV64uKLkwcILWIYPeaPcOEcEuThdot6x4h0uPNbixn+TxawTzgAL4mPmIsqBekL94I+wLKgL/MHaAbj2OMdcHKcIYMmycaIycFFx4YsIEECw4I98tYQIMHrBu8iqR1wr3BklVxYeoLz/A3J4pOhngp/+AAAAAElFTkSuQmCC"
},
"dataset": [
{
"key": "__0__",
"name": "Month Start",
"description": "Date field representing the start of each month in the dataset.",
"type": "dateTime",
"kind": "column"
},
{
"key": "__1__",
"name": "Actual",
"description": "The primary measure.",
"type": "numeric",
"kind": "measure"
},
{
"key": "__2__",
"name": "Target",
"description": "Our target measure, that Actual should achieve or exceed in order for the area to be shaded positive.",
"type": "numeric",
"kind": "measure"
}
]
},
"config": {
"view": {"stroke": "transparent"},
"font": "Segoe UI",
"axis": {
"title": null,
"grid": false,
"ticks": false,
"labelPadding": 10,
"labelFontSize": 12
},
"axisY": {"domain": false},
"style": {
"delta_negative": {
"color": "#8D1D1C"
},
"delta_positive": {
"color": "#83C79B"
},
"mask_foreground": {
"color": "#ffffff",
"stroke": "#ffffff"
},
"target_line": {
"color": "#939393",
"strokeWidth": 2
},
"actual_line": {
"color": "#000000",
"strokeWidth": 3
}
}
},
"data": {"name": "dataset"},
"encoding": {
"x": {
"field": "__0__",
"type": "temporal",
"axis": {
"zindex": 1,
"format": "%b"
}
},
"y": {
"type": "quantitative",
"axis": {"tickCount": 5}
}
},
"layer": [
{
"description": "Target area - background",
"mark": {
"type": "area",
"style": "delta_negative"
},
"encoding": {
"y": {"field": "__2__"}
}
},
{
"description": "Actual area - masks out target where necessary",
"mark": {
"type": "area",
"style": "delta_positive"
},
"encoding": {
"y": {"field": "__1__"}
}
},
{
"description": "Masking layer (with interpolated points)",
"transform": [
{
"calculate": "min(datum['__2__'], datum['__1__'])",
"as": "lowest_value"
},
{
"window": [
{
"op": "lead",
"field": "__0__",
"as": "month_following"
},
{
"op": "lead",
"field": "__1__",
"as": "actual_following"
},
{
"op": "lead",
"field": "__2__",
"as": "target_following"
}
]
},
{
"calculate": "(datum['actual_following'] - datum['__1__']) / (datum['month_following'] - datum['__0__'])",
"as": "actual_slope"
},
{
"calculate": "(datum['target_following'] - datum['__2__']) / (datum['month_following'] - datum['__0__'])",
"as": "target_slope"
},
{
"calculate": "datum['__1__'] - (datum['actual_slope'] * datum['__0__'])",
"as": "actual_y_intercept"
},
{
"calculate": "datum['__2__'] - (datum['target_slope'] * datum['__0__'])",
"as": "target_y_intercept"
},
{
"calculate": "(datum['target_y_intercept'] - datum['actual_y_intercept']) / (datum['actual_slope'] - datum['target_slope'])",
"as": "intersect_base"
},
{
"calculate": "datum['intersect_base'] > datum['__0__'] && datum['intersect_base'] < datum['month_following']",
"as": "intersect_before_following"
},
{
"calculate": "datum['intersect_before_following'] ? datetime(datum['intersect_base']) : null",
"as": "intersect_x"
},
{
"calculate": "datum['intersect_before_following'] ? (datum['actual_slope'] * datum['intersect_base']) + datum['actual_y_intercept'] : null",
"as": "intersect_y"
},
{
"fold": [
"__0__",
"intersect_x"
]
},
{
"filter": "datum['value'] !== null"
},
{
"calculate": "datum['key'] === '__0__' ? datum['__0__'] : datum['intersect_x']",
"as": "x"
},
{
"calculate": "datum['key'] === '__0__' ? datum['lowest_value'] : datum['intersect_y']",
"as": "y"
}
],
"mark": {
"type": "area",
"style": "mask_foreground"
},
"encoding": {
"x": {"field": "x"},
"y": {"field": "y"}
}
},
{
"description": "Target line",
"mark": {
"type": "line",
"style": "target_line"
},
"encoding": {
"y": {"field": "__2__"}
}
},
{
"description": "Actual line",
"mark": {
"type": "line",
"style": "actual_line"
},
"encoding": {
"y": {"field": "__1__"}
}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment