forked from tableau/document-api-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencoding.py
More file actions
46 lines (37 loc) · 1.36 KB
/
encoding.py
File metadata and controls
46 lines (37 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from tableaudocumentapi.utils import _clean_aggregated_column_names
class Encoding(object):
"""A class representing one mark encoding on a worksheet pane.
Wraps a child element of <pane>/<encodings> (e.g. <color>, <text>,
<tooltip>, <size>, <lod>, <label>, <shape>, <detail>, <path>).
Channel name is pass-through from Tableau, so any tag emitted under
<encodings> is accepted.
"""
def __init__(self, encoding_xml):
self._xml = encoding_xml
self._channel = encoding_xml.tag
self._column = encoding_xml.get('column')
@property
def xml(self):
return self._xml
@property
def channel(self):
"""The visual channel tag name as emitted by Tableau."""
return self._channel
@property
def column(self):
"""The raw column reference (e.g. '[ds].[none:Country:nk]')."""
return self._column
@property
def datasource(self):
"""Datasource name extracted from the column reference, or None."""
if not self._column:
return None
ds, _ = _clean_aggregated_column_names(self._column)
return ds
@property
def field(self):
"""Field name extracted from the column reference, or None."""
if not self._column:
return None
_, field = _clean_aggregated_column_names(self._column)
return field