Skip to content

Commit 3d42f16

Browse files
authored
Allow adding custom viz (#90)
1 parent 2e83187 commit 3d42f16

7 files changed

Lines changed: 61 additions & 16 deletions

File tree

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ repos:
88
- id: end-of-file-fixer
99
- id: check-ast
1010
- repo: https://github.com/astral-sh/ruff-pre-commit
11-
rev: v0.9.10
11+
rev: v0.12.0
1212
hooks:
1313
# Run the linter.
14-
- id: ruff
14+
- id: ruff-check
1515
args: [ --fix ]
1616
# Run the formatter.
1717
- id: ruff-format
1818
- repo: https://github.com/astral-sh/uv-pre-commit
19-
rev: 0.6.5
19+
rev: 0.7.14
2020
hooks:
2121
# Run the pip compile
2222
- id: pip-compile

documentation/index.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ upload your datasets to HDX.
2727
- [Tags](#tags)
2828
- [Maintainer](#maintainer)
2929
- [Organization](#organization)
30+
- [Custom Visualization](#customviz)
3031
- [Resource Generation](#resource-generation)
3132
- [QuickCharts Generation](#quickcharts-generation)
3233
- [Resource Specific Operations](#resource-specific-operations)
@@ -790,7 +791,22 @@ If you want to set the organization, you do it like this:
790791
ORGANIZATION is either a string id, dictionary or an Organization
791792
object.
792793

793-
### Resource generation
794+
### Custom Visualization
795+
796+
If you want to add a custom visualization to a dataset, you can do this:
797+
798+
dataset.set_custom_viz(URL)
799+
800+
URL is a string containing the url of your visualization.
801+
802+
You can get any existing visualization like this:
803+
804+
url = dataset.get_custom_viz()
805+
806+
The return value is a string if a visualization has been set on the dataset,
807+
otherwise it is None.
808+
809+
### Resource Generation
794810

795811
There are a range of helpful functions to generate resources. In the following
796812
examples, RESOURCE DATA takes the form {"name": NAME, "description":

hatch.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ run = """
3434

3535
[envs.hatch-static-analysis]
3636
config-path = "none"
37-
dependencies = ["ruff==0.9.10"]
37+
dependencies = ["ruff==0.12.0"]

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ dependencies = [
3838
"defopt>=7.0.0",
3939
"email_validator",
4040
"hdx-python-country>=3.9.6",
41-
"hdx-python-utilities>=3.8.8",
41+
"hdx-python-utilities>=3.9.0",
4242
"libhxl>=5.2.2",
4343
"makefun",
4444
"quantulum3",

requirements.txt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# uv pip compile pyproject.toml --resolver=backtracking --all-extras -o requirements.txt
33
annotated-types==0.7.0
44
# via pydantic
5-
astdoc==1.3.0
5+
astdoc==1.3.1
66
# via mkapi
77
attrs==25.3.0
88
# via
@@ -16,7 +16,7 @@ backrefs==5.9
1616
# via mkdocs-material
1717
cachetools==5.5.2
1818
# via google-auth
19-
certifi==2025.7.14
19+
certifi==2025.8.3
2020
# via requests
2121
cfgv==3.4.0
2222
# via pre-commit
@@ -32,7 +32,7 @@ click==8.2.1
3232
# typer
3333
colorama==0.4.6
3434
# via mkdocs-material
35-
coverage==7.9.2
35+
coverage==7.10.2
3636
# via pytest-cov
3737
defopt==7.0.0
3838
# via hdx-python-api (pyproject.toml)
@@ -44,7 +44,7 @@ docopt==0.6.2
4444
# via
4545
# ckanapi
4646
# num2words
47-
docutils==0.21.2
47+
docutils==0.22
4848
# via defopt
4949
email-validator==2.2.0
5050
# via hdx-python-api (pyproject.toml)
@@ -66,7 +66,7 @@ gspread==6.2.1
6666
# via hdx-python-api (pyproject.toml)
6767
hdx-python-country==3.9.6
6868
# via hdx-python-api (pyproject.toml)
69-
hdx-python-utilities==3.8.8
69+
hdx-python-utilities==3.9.0
7070
# via
7171
# hdx-python-api (pyproject.toml)
7272
# hdx-python-country
@@ -129,15 +129,15 @@ mergedeep==1.3.4
129129
# via
130130
# mkdocs
131131
# mkdocs-get-deps
132-
mkapi==4.4.4
132+
mkapi==4.4.5
133133
# via hdx-python-api (pyproject.toml)
134134
mkdocs==1.6.1
135135
# via
136136
# mkapi
137137
# mkdocs-material
138138
mkdocs-get-deps==0.2.0
139139
# via mkdocs
140-
mkdocs-material==9.6.15
140+
mkdocs-material==9.6.16
141141
# via mkapi
142142
mkdocs-material-extensions==1.3.1
143143
# via mkdocs-material
@@ -192,7 +192,7 @@ pygments==2.19.2
192192
# mkdocs-material
193193
# pytest
194194
# rich
195-
pymdown-extensions==10.16
195+
pymdown-extensions==10.16.1
196196
# via mkdocs-material
197197
pyphonetics==0.5.3
198198
# via hdx-python-utilities
@@ -251,7 +251,7 @@ requests-oauthlib==2.0.0
251251
# via google-auth-oauthlib
252252
rfc3986==2.0.0
253253
# via frictionless
254-
rich==14.0.0
254+
rich==14.1.0
255255
# via typer
256256
rpds-py==0.26.0
257257
# via
@@ -313,7 +313,7 @@ urllib3==2.5.0
313313
# requests
314314
validators==0.35.0
315315
# via frictionless
316-
virtualenv==20.32.0
316+
virtualenv==20.33.1
317317
# via pre-commit
318318
watchdog==6.0.0
319319
# via mkdocs

src/hdx/data/dataset.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2141,6 +2141,28 @@ def remove_filetype(self, filetype: str) -> bool:
21412141
)
21422142
return self._remove_string_from_commastring("file_types", filetype)
21432143

2144+
def set_custom_viz(self, url: str) -> None:
2145+
"""Set custom visualization url for dataset
2146+
2147+
Args:
2148+
url (str): Custom visualization url
2149+
2150+
Returns:
2151+
None
2152+
"""
2153+
self.data["customviz"] = [{"url": url}]
2154+
2155+
def get_custom_viz(self) -> Optional[str]:
2156+
"""Get custom visualization url for dataset
2157+
2158+
Returns:
2159+
Optional[str]: Custom visualization url or None:
2160+
"""
2161+
viz = self.data.get("customviz")
2162+
if not isinstance(viz, list):
2163+
return None
2164+
return viz[0].get("url")
2165+
21442166
def preview_off(self) -> None:
21452167
"""Set dataset preview off
21462168

tests/hdx/data/test_dataset_noncore.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,3 +1010,10 @@ def test_load_save_to_json(self, vocabulary_read):
10101010
save_text("null", path)
10111011
dataset = Dataset.load_from_json(path)
10121012
assert dataset is None
1013+
1014+
def test_custom_viz(self):
1015+
dataset = Dataset({"name": "lala", "title": "title", "notes": "description"})
1016+
url = "http://lala"
1017+
dataset.set_custom_viz(url)
1018+
assert dataset.get_custom_viz() == url
1019+
assert dataset["customviz"] == [{"url": "http://lala"}]

0 commit comments

Comments
 (0)