Utility Functions
build_chart_for_data(settings, data)
Build chart for the given dataframe and settings.
PARAMETER | DESCRIPTION |
---|---|
settings
|
Chart settings
TYPE:
|
data
|
Dataframe with data
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str | None
|
Chart config as JSON string |
Source code in ckanext/charts/utils.py
66 67 68 69 70 71 72 73 74 75 76 |
|
build_chart_for_resource(settings, resource_id)
Build chart for the given resource ID.
Uses a DatastoreDataFetcher to fetch data from the resource.
PARAMETER | DESCRIPTION |
---|---|
settings
|
Chart settings
TYPE:
|
resource_id
|
Resource ID
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str | None
|
str | None: Chart config as JSON string or None if the chart can't be built |
Source code in ckanext/charts/utils.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
|
can_view(data_dict)
Check if the resource can be viewed as a chart.
For now, we work only with resources stored with the DataStore.
PARAMETER | DESCRIPTION |
---|---|
data_dict
|
Resource data dictionary
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
True if the resource can be viewed as a chart, False otherwise
TYPE:
|
Source code in ckanext/charts/utils.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
|
get_chart_form_builder(engine, chart_type)
Get form builder for the given engine and chart type.
Source code in ckanext/charts/utils.py
56 57 58 59 60 61 62 63 |
|
get_column_options(resource_id)
Get column options for the given resource.
PARAMETER | DESCRIPTION |
---|---|
resource_id
|
Resource ID
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
list[dict[str, str]]
|
List of column options |
Source code in ckanext/charts/utils.py
15 16 17 18 19 20 21 22 23 24 25 26 |
|
printable_file_size(size_bytes)
Convert file size in bytes to human-readable format.
PARAMETER | DESCRIPTION |
---|---|
size_bytes
|
File size in bytes
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
Human-readable file size
TYPE:
|
Examples:
>>> printable_file_size(123456789)
'117.7 MB'
>>> printable_file_size(7777)
'7.6 KB'
Source code in ckanext/charts/utils.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
|