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
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
|
build_chart_for_resource(settings, resource_id, resource_view_id=None)
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
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
|
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
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
|
get_chart_form_builder(engine, chart_type)
Get form builder for the given engine and chart type.
Source code in ckanext/charts/utils.py
58 59 60 61 62 63 64 65 |
|
get_chart_view_ids(resource_id)
Return a list of chart-related ResourceView IDs for a given resource_id.
Source code in ckanext/charts/utils.py
165 166 167 168 169 170 171 172 173 174 175 |
|
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
17 18 19 20 21 22 23 24 25 26 27 28 |
|
get_datastore_column_names(resource_id)
Retrieve column names from the datastore for the given resource ID.
RETURNS | DESCRIPTION |
---|---|
list[str]
|
Column names from cache if available; otherwise, fetched |
list[str]
|
from the datastore. |
Source code in ckanext/charts/utils.py
155 156 157 158 159 160 161 162 |
|
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
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
|