mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Removed units functionality and Pint dependency
Closes #2400, unblocks #2320
This commit is contained in:
parent
d444b6aad5
commit
39dfc7d7d7
14 changed files with 14 additions and 182 deletions
|
|
@ -205,100 +205,6 @@ These will be displayed at the top of the table page, and will also show in the
|
|||
|
||||
You can see an example of how these look at `latest.datasette.io/fixtures/roadside_attractions <https://latest.datasette.io/fixtures/roadside_attractions>`__.
|
||||
|
||||
Specifying units for a column
|
||||
-----------------------------
|
||||
|
||||
Datasette supports attaching units to a column, which will be used when displaying
|
||||
values from that column. SI prefixes will be used where appropriate.
|
||||
|
||||
Column units are configured in the metadata like so:
|
||||
|
||||
.. [[[cog
|
||||
metadata_example(cog, {
|
||||
"databases": {
|
||||
"database1": {
|
||||
"tables": {
|
||||
"example_table": {
|
||||
"units": {
|
||||
"column1": "metres",
|
||||
"column2": "Hz"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.. ]]]
|
||||
|
||||
.. tab:: metadata.yaml
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
databases:
|
||||
database1:
|
||||
tables:
|
||||
example_table:
|
||||
units:
|
||||
column1: metres
|
||||
column2: Hz
|
||||
|
||||
|
||||
.. tab:: metadata.json
|
||||
|
||||
.. code-block:: json
|
||||
|
||||
{
|
||||
"databases": {
|
||||
"database1": {
|
||||
"tables": {
|
||||
"example_table": {
|
||||
"units": {
|
||||
"column1": "metres",
|
||||
"column2": "Hz"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.. [[[end]]]
|
||||
|
||||
|
||||
Units are interpreted using Pint_, and you can see the full list of available units in
|
||||
Pint's `unit registry`_. You can also add `custom units`_ to the metadata, which will be
|
||||
registered with Pint:
|
||||
|
||||
.. [[[cog
|
||||
metadata_example(cog, {
|
||||
"custom_units": [
|
||||
"decibel = [] = dB"
|
||||
]
|
||||
})
|
||||
.. ]]]
|
||||
|
||||
.. tab:: metadata.yaml
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
custom_units:
|
||||
- decibel = [] = dB
|
||||
|
||||
|
||||
.. tab:: metadata.json
|
||||
|
||||
.. code-block:: json
|
||||
|
||||
{
|
||||
"custom_units": [
|
||||
"decibel = [] = dB"
|
||||
]
|
||||
}
|
||||
.. [[[end]]]
|
||||
|
||||
.. _Pint: https://pint.readthedocs.io/
|
||||
.. _unit registry: https://github.com/hgrecco/pint/blob/master/pint/default_en.txt
|
||||
.. _custom units: http://pint.readthedocs.io/en/latest/defining.html
|
||||
|
||||
.. _metadata_default_sort:
|
||||
|
||||
Setting a default sort order
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue