Skip to content

Commit

Permalink
style: bar chart display in observatory
Browse files Browse the repository at this point in the history
  • Loading branch information
gilesdring committed Jan 10, 2025
1 parent acc9453 commit 59bdbf6
Show file tree
Hide file tree
Showing 12 changed files with 589 additions and 402 deletions.
9 changes: 5 additions & 4 deletions oi-lume-viz-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,23 @@ const names = await getColourVariables(
);

const series = [
"yellow",
"pink",
"green",
"lightyellow",
"yellow",
"lightpink",
"lightgreen",
"lightyellow",
"deeppink",
"darkgreen",
"darkpink",
"deepyellow",
"midgrey",
"notquitedarkgrey",
"darkgrey",
].map((n) => names[n]);

export default {
colour: {
names,
names: names,
series,
},
font: {
Expand Down
46 changes: 31 additions & 15 deletions pipelines/observatory/census.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,28 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 38,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 38,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import sys, os\n",
"os.path.abspath('..') in sys.path or sys.path.append(os.path.abspath('..'))"
]
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 39,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -23,7 +34,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 40,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -33,7 +44,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 41,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -42,24 +53,24 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 46,
"metadata": {},
"outputs": [],
"source": [
"categories = etl.lookup(\n",
" etl.fromcsv(OPEN_DATA / 'census_categories.csv').sort('sortorder'),\n",
" etl.fromcsv(OPEN_DATA / 'census_categories.csv').convertnumbers().sort('sortorder'),\n",
" key='variable',\n",
" value='category'\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 50,
"metadata": {},
"outputs": [],
"source": [
"def prepare_data(variable, folder):\n",
"def prepare_data(variable, folder, ward_sorter=None):\n",
" folder.mkdir(exist_ok=True, parents=True)\n",
" data = (\n",
" census\n",
Expand All @@ -70,17 +81,22 @@
" .cut('geography_code', 'geography_name', *categories.get(variable))\n",
" )\n",
" data.tocsv(folder / 'by_geography.csv')\n",
" (\n",
" data\n",
" .select(lambda r: r.geography_code.startswith('E05'))\n",
" .addfield('order', ward_sorter)\n",
" .sort('order')\n",
" .tocsv(folder / 'by_ward.csv')\n",
" )\n",
"\n",
"prepare_data('Age', BRADFORD_DG / 'age')\n",
"prepare_data('Sex', BRADFORD_DG / 'sex')\n",
"prepare_data('Ethnic group', BRADFORD_DG / 'ethnic_group')"
"prepare_data('Age', BRADFORD_DG / 'age', ward_sorter=lambda r: -sum(r[f] for f in categories.get('Age')[:5]))\n",
"prepare_data('Sex', BRADFORD_DG / 'sex', ward_sorter=lambda r: r.Female)\n",
"prepare_data('Ethnic group', BRADFORD_DG / 'ethnic_group', ward_sorter=lambda r: -r['Asian, Asian British or Asian Welsh'])"
]
},
{
"cell_type": "code",
"execution_count": null,
"cell_type": "markdown",
"metadata": {},
"outputs": [],
"source": []
},
{
Expand Down
2 changes: 2 additions & 0 deletions src/_includes/css/colour.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
--color-pink: #F4ACCD;
--color-lightpink: #F8D9E7;
--color-darkpink: #C9AFBB;
--color-deeppink: #e1699f;
--color-green: #45D108;
--color-lightgreen: #ACE892;
--color-darkgreen: #437e2a;
--color-yellow: #E0B942;
--color-deepyellow: #be9006;
--color-lightyellow: #EAD79F;
--color-grey: #c7c7c7;
--color-midgrey: #d5d3d0;
Expand Down
53 changes: 53 additions & 0 deletions src/observatory/demographics/_data.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
chart_config:
bar:
category: geography_name
stacked: true
width: 600
legend:
show: true
position: bottom
colours:
4 and under: '#F8D9E7'
5 to 9: '#F4ACCD'
10 to 15: '#e1699f'
16 to 19: '#ACE892'
20 to 24: '#45D108'
25 to 34: '#437e2a'
35 to 49: '#EAD79F'
50 to 64: '#E0B942'
65 to 74: '#be9006'
# 75 to 84: '#717171'
# TODO Raise issue against OI Lume Viz - if the last category is specified, all seem to get the same colour
# 85 and over': '#d5d3d0'

Asian or Asian British/Welsh: '#F4ACCD'
Black, Black British/Welsh, Caribbean or African: '#45D108'
Mixed or Multiple: '#e1699f'
White: '#E0B942'
# Other: '#aaa'


axis:
y:
ticks: []
grid:
show: false
x:
grid:
show: false
min: 0
max: 100
ticks:
- value: 0
label: 0%
- value: 25
label: 25%
- value: 50
label: 50%
- value: 75
label: 75%
- value: 100
label: 100%



Loading

0 comments on commit 59bdbf6

Please sign in to comment.