-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcl_lib.py
133 lines (106 loc) · 3.73 KB
/
cl_lib.py
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# -*- coding: utf-8 -*-
# ----------------------------------------------------------------------------------------------------------------------
# Climate information dashboard.
#
# Class definition: Lib and Libs.
#
# Contributors:
# 1. [email protected]
# (C) 2021-2022 Ouranos Inc., Canada
# ----------------------------------------------------------------------------------------------------------------------
# External libraries.
from typing import Union, List
# Dashboard libraries.
import cl_object
from cl_constant import const as c
from cl_context import cntx
def code_desc(
) -> dict:
"""
--------------------------------------------------------------------------------------------------------------------
Get a dictionary of codes and descriptions.
Returns
-------
dict
Dictionary of codes and descriptions.
--------------------------------------------------------------------------------------------------------------------
"""
return {
c.LIB_ALT: "altair",
c.LIB_HV: "hvplot",
c.LIB_MAT: "matplotlib",
c.LIB_PLY: "plotly"
}
class Lib(cl_object.Obj):
"""
--------------------------------------------------------------------------------------------------------------------
Class defining the object Lib.
--------------------------------------------------------------------------------------------------------------------
"""
def __init__(
self,
code: str
):
"""
----------------------------------------
Constructor.
----------------------------------------
"""
desc = "" if code == "" else dict(code_desc())[code]
super(Lib, self).__init__(code=code, desc=desc)
class Libs(cl_object.Objs):
"""
--------------------------------------------------------------------------------------------------------------------
Class defining the object Libs.
--------------------------------------------------------------------------------------------------------------------
"""
def __init__(
self,
*args
):
"""
----------------------------------------
Constructor.
----------------------------------------
"""
super(Libs, self).__init__()
if (len(args) == 1) and (args[0] == "*"):
code_l = []
if not cntx.opt_lib:
lib_code = c.LIB_HV
if cntx.view.code == c.VIEW_TBL:
lib_code = c.LIB_PLY
code_l = [lib_code]
elif cntx.view.code in [c.VIEW_TS, c.VIEW_TS_BIAS]:
code_l = [c.LIB_ALT, c.LIB_HV, c.LIB_MAT]
elif cntx.view.code == c.VIEW_TBL:
code_l = [c.LIB_PLY]
elif cntx.view.code in [c.VIEW_MAP, c.VIEW_CYCLE]:
code_l = [c.LIB_HV, c.LIB_MAT]
elif cntx.view.code == c.VIEW_CLUSTER:
code_l = [c.LIB_HV, c.LIB_MAT]
self.add(code_l)
def add(
self,
item: Union[str, List[str], Lib],
inplace: bool = True
):
"""
----------------------------------------
Add one or several items.
Paramters
---------
item: Union[str, List[str], Lib]
Item (code, list of codes or instance of Lib).
----------------------------------------
"""
items = []
if isinstance(item, Lib):
items = [item]
else:
code_l = item
if isinstance(item, str):
code_l = [item]
for i in range(len(code_l)):
items.append(Lib(code_l[i]))
return super(Libs, self).add(items, inplace)