Created
May 7, 2020 11:49
-
-
Save hawleylin/58235d6ff548a47161fafa3b18cfa5f8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"$schema": "https://vega.github.io/schema/vega/v5.json", | |
"background": "white", | |
"padding": 5, | |
"width": 1000, | |
"height": 500, | |
"title": { | |
"text": "The political history reflected by 120 years of Summer Olympics", | |
"frame": "group" | |
}, | |
"style": "cell", | |
"data": [ | |
{ | |
"name": "industry_store" | |
}, | |
{ | |
"name": "source_0", | |
"url": "https://gist.githubusercontent.com/hawleylin/ee91d5ac3b354fb8c2b86dc23ec1ba46/raw/e40571b90b09469a1ca7e771bb8dcbe1b3373156/medal_country&continent.csv", | |
"format": { | |
"type": "csv", | |
"parse": { | |
"year": "date" | |
}, | |
"delimiter": "," | |
}, | |
"transform": [ | |
{ | |
"field": "year", | |
"type": "timeunit", | |
"units": [ | |
"year" | |
], | |
"step": 4, | |
"as": [ | |
"year_step_4_year", | |
"year_step_4_year_end" | |
] | |
}, | |
{ | |
"type": "formula", | |
"expr": "datum[\"country\"]===\"USA\" ? 0 : datum[\"country\"]===\"Soviet Union\" ? 1 : datum[\"country\"]===\"Russia\" ? 2 : datum[\"country\"]===\"China\" ? 3 : datum[\"country\"]===\"Japan\" ? 4 : datum[\"country\"]===\"West Germany\" ? 5 : datum[\"country\"]===\"East Germany\" ? 6 : datum[\"country\"]===\"Germany\" ? 7 : datum[\"country\"]===\"Australia\" ? 8 : datum[\"country\"]===\"France\" ? 9 : datum[\"country\"]===\"Italy\" ? 10 : datum[\"country\"]===\"UK\" ? 11 : datum[\"country\"]===\"Other Countries in Americas\" ? 12 : datum[\"country\"]===\"Other Countries in Asia\" ? 13 : datum[\"country\"]===\"Other Countries in Europe\" ? 14 : datum[\"country\"]===\"Other Countries in Oceania\" ? 15 : datum[\"country\"]===\"Africa\" ? 16 : 17", | |
"as": "color_country_sort_index" | |
} | |
] | |
}, | |
{ | |
"name": "data_0", | |
"source": "source_0", | |
"transform": [ | |
{ | |
"type": "aggregate", | |
"groupby": [ | |
"year_step_4_year", | |
"country" | |
], | |
"ops": [ | |
"sum" | |
], | |
"fields": [ | |
"medal" | |
], | |
"as": [ | |
"sum_medal" | |
] | |
}, | |
{ | |
"type": "impute", | |
"field": "sum_medal", | |
"groupby": [ | |
"country" | |
], | |
"key": "year_step_4_year", | |
"method": "value", | |
"value": 0 | |
}, | |
{ | |
"type": "stack", | |
"groupby": [ | |
"year_step_4_year" | |
], | |
"field": "sum_medal", | |
"sort": { | |
"field": [ | |
"country" | |
], | |
"order": [ | |
"descending" | |
] | |
}, | |
"as": [ | |
"sum_medal_start", | |
"sum_medal_end" | |
], | |
"offset": "center" | |
} | |
] | |
} | |
], | |
"signals": [ | |
{ | |
"name": "unit", | |
"value": {}, | |
"on": [ | |
{ | |
"events": "mousemove", | |
"update": "isTuple(group()) ? group() : unit" | |
} | |
] | |
}, | |
{ | |
"name": "industry_country_legend", | |
"value": null, | |
"on": [ | |
{ | |
"events": [ | |
{ | |
"source": "view", | |
"type": "click", | |
"markname": "country_legend_symbols" | |
}, | |
{ | |
"source": "view", | |
"type": "click", | |
"markname": "country_legend_labels" | |
}, | |
{ | |
"source": "view", | |
"type": "click", | |
"markname": "country_legend_entries" | |
} | |
], | |
"update": "datum.value || item().items[0].items[0].datum.value", | |
"force": true | |
}, | |
{ | |
"events": [ | |
{ | |
"source": "view", | |
"type": "click" | |
} | |
], | |
"update": "!event.item || !datum ? null : industry_country_legend", | |
"force": true | |
} | |
] | |
}, | |
{ | |
"name": "industry", | |
"update": "vlSelectionResolve(\"industry_store\", \"union\", true)" | |
}, | |
{ | |
"name": "industry_tuple", | |
"update": "industry_country_legend !== null ? {fields: industry_tuple_fields, values: [industry_country_legend]} : null" | |
}, | |
{ | |
"name": "industry_tuple_fields", | |
"value": [ | |
{ | |
"type": "E", | |
"field": "country" | |
} | |
] | |
}, | |
{ | |
"name": "industry_toggle", | |
"value": false, | |
"on": [ | |
{ | |
"events": { | |
"merge": [ | |
{ | |
"source": "view", | |
"type": "click" | |
} | |
] | |
}, | |
"update": "event.shiftKey" | |
} | |
] | |
}, | |
{ | |
"name": "industry_modify", | |
"on": [ | |
{ | |
"events": { | |
"signal": "industry_tuple" | |
}, | |
"update": "modify(\"industry_store\", industry_toggle ? null : industry_tuple, industry_toggle ? null : true, industry_toggle ? industry_tuple : null)" | |
} | |
] | |
} | |
], | |
"marks": [ | |
{ | |
"name": "pathgroup", | |
"type": "group", | |
"from": { | |
"facet": { | |
"name": "faceted_path_main", | |
"data": "data_0", | |
"groupby": [ | |
"country" | |
] | |
} | |
}, | |
"encode": { | |
"update": { | |
"width": { | |
"field": { | |
"group": "width" | |
} | |
}, | |
"height": { | |
"field": { | |
"group": "height" | |
} | |
} | |
} | |
}, | |
"marks": [ | |
{ | |
"name": "marks", | |
"type": "area", | |
"style": [ | |
"area" | |
], | |
"sort": { | |
"field": "datum[\"year_step_4_year\"]" | |
}, | |
"interactive": true, | |
"from": { | |
"data": "faceted_path_main" | |
}, | |
"encode": { | |
"update": { | |
"orient": { | |
"value": "vertical" | |
}, | |
"fill": { | |
"scale": "color", | |
"field": "country" | |
}, | |
"opacity": [ | |
{ | |
"test": "!(length(data(\"industry_store\"))) || (vlSelectionTest(\"industry_store\", datum))", | |
"value": 1 | |
}, | |
{ | |
"value": 0.2 | |
} | |
], | |
"description": { | |
"signal": "\"Year\" + \": \" + (timeFormat(datum[\"year_step_4_year\"], timeUnitSpecifier([\"year\"], {\"year-month\":\"%b %Y \",\"year-month-date\":\"%b %d, %Y \"}))) + \"; \" + \"Sum of medal\" + \": \" + (format(datum[\"sum_medal\"], \"\")) + \"; \" + \"Country&Continent\" + \": \" + (isValid(datum[\"country\"]) ? datum[\"country\"] : \"\"+datum[\"country\"])" | |
}, | |
"x": { | |
"scale": "x", | |
"field": "year_step_4_year" | |
}, | |
"y": { | |
"scale": "y", | |
"field": "sum_medal_end" | |
}, | |
"y2": { | |
"scale": "y", | |
"field": "sum_medal_start" | |
}, | |
"defined": { | |
"signal": "isValid(datum[\"year_step_4_year\"]) && isFinite(+datum[\"year_step_4_year\"]) && isValid(datum[\"sum_medal\"]) && isFinite(+datum[\"sum_medal\"])" | |
} | |
} | |
} | |
} | |
] | |
} | |
], | |
"scales": [ | |
{ | |
"name": "x", | |
"type": "time", | |
"domain": { | |
"data": "data_0", | |
"field": "year_step_4_year" | |
}, | |
"range": [ | |
0, | |
{ | |
"signal": "width" | |
} | |
] | |
}, | |
{ | |
"name": "y", | |
"type": "linear", | |
"domain": { | |
"data": "data_0", | |
"fields": [ | |
"sum_medal_start", | |
"sum_medal_end" | |
] | |
}, | |
"range": [ | |
{ | |
"signal": "height" | |
}, | |
0 | |
], | |
"nice": true, | |
"zero": true | |
}, | |
{ | |
"name": "color", | |
"type": "ordinal", | |
"domain": { | |
"data": "source_0", | |
"field": "country", | |
"sort": { | |
"op": "min", | |
"field": "color_country_sort_index" | |
} | |
}, | |
"range": { | |
"scheme": "category20b" | |
} | |
} | |
], | |
"axes": [ | |
{ | |
"scale": "x", | |
"orient": "bottom", | |
"grid": false, | |
"title": "Year", | |
"domain": true, | |
"tickCount": { | |
"interval": "year", | |
"step": 4 | |
}, | |
"tickSize": 8, | |
"format": { | |
"signal": "timeUnitSpecifier([\"year\"], {\"year-month\":\"%b %Y \",\"year-month-date\":\"%b %d, %Y \"})" | |
}, | |
"labelFlush": true, | |
"labelOverlap": true, | |
"zindex": 0 | |
} | |
], | |
"legends": [ | |
{ | |
"title": "Country&Continent", | |
"fill": "color", | |
"symbolType": "circle", | |
"encode": { | |
"labels": { | |
"name": "country_legend_labels", | |
"interactive": true, | |
"update": { | |
"opacity": [ | |
{ | |
"test": "(!length(data(\"industry_store\")) || (industry[\"country\"] && indexof(industry[\"country\"], datum.value) >= 0))", | |
"value": 1 | |
}, | |
{ | |
"value": 0.35 | |
} | |
] | |
} | |
}, | |
"symbols": { | |
"name": "country_legend_symbols", | |
"interactive": true, | |
"update": { | |
"opacity": [ | |
{ | |
"test": "(!length(data(\"industry_store\")) || (industry[\"country\"] && indexof(industry[\"country\"], datum.value) >= 0))", | |
"value": 1 | |
}, | |
{ | |
"value": 0.35 | |
} | |
] | |
} | |
}, | |
"entries": { | |
"name": "country_legend_entries", | |
"interactive": true, | |
"update": { | |
"fill": { | |
"value": "transparent" | |
} | |
} | |
} | |
} | |
} | |
], | |
"config": {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment